// @HEADER // ***************************************************************************** // Intrepid2 Package // // Copyright 2007 NTESS and the Intrepid2 contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /** \file \brief Test for checking orientation tools for Hexahedral elements The test considers two hexahedra in the physical space sharing a common face. In order to test significant configurations, we consider 6 mappings of the reference hexahedron to the first (physical) hexahedron, so that the common face is mapped from all the 6 faces of the reference hexahedron. Then, for each of the mappings, the global ids of the vertices of the common face are permuted. This gives a total of 144 combinations The test considers HGRAD, HCURL and HDIV elements and for each of them checks the following: 1. that the physical (oriented) dof coefficients related to faces and edges are proportional to the tangents (for HCURL) of the faces/edges or to the normals (for HDIV) of the faces. 2. that the Kronecker property of the oriented basis evaluated at the physiscal dof coordinates holds. 3. that given a function, the dofs of the function located at the common faces/edges are the same when computed on the first and second hexahedron. 4. that a function, belonging to the considered H-space, is exactly reproduced at given points using the oriented basis functions and the degrees of freedom of the function. \author Created by Mauro Perego */ #include "Intrepid2_config.h" #ifdef HAVE_INTREPID2_DEBUG #define INTREPID2_TEST_FOR_DEBUG_ABORT_OVERRIDE_TO_CONTINUE #endif #include "Intrepid2_Orientation.hpp" #include "Intrepid2_OrientationTools.hpp" #include "Intrepid2_HGRAD_LINE_C1_FEM.hpp" #include "Intrepid2_HGRAD_QUAD_C1_FEM.hpp" #include "Intrepid2_HGRAD_HEX_C1_FEM.hpp" #include "Intrepid2_HGRAD_HEX_Cn_FEM.hpp" #include "Intrepid2_HCURL_HEX_In_FEM.hpp" #include "Intrepid2_HCURL_QUAD_In_FEM.hpp" #include "Intrepid2_HVOL_LINE_Cn_FEM.hpp" #include "Intrepid2_HVOL_QUAD_Cn_FEM.hpp" #include "Intrepid2_PointTools.hpp" #include "Intrepid2_CellTools.hpp" #include "Intrepid2_FunctionSpaceTools.hpp" #include "Teuchos_oblackholestream.hpp" #include "Teuchos_RCP.hpp" #include #include #include #include namespace Intrepid2 { namespace Test { #define INTREPID2_TEST_ERROR_EXPECTED( S ) \ try { \ ++nthrow; \ S ; \ } \ catch (std::exception &err) { \ ++ncatch; \ *outStream << "Expected Error ----------------------------------------------------------------\n"; \ *outStream << err.what() << '\n'; \ *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \ } template int OrientationHex(const bool verbose) { typedef Kokkos::DynRankView DynRankView; typedef Kokkos::DynRankView DynRankViewInt; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) Teuchos::RCP outStream; Teuchos::oblackholestream bhs; // outputs nothing if (verbose) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); Teuchos::oblackholestream oldFormatState; oldFormatState.copyfmt(std::cout); int errorFlag = 0; const ValueType tol = tolerence(); struct Fun { ValueType KOKKOS_INLINE_FUNCTION operator()(const ValueType& x, const ValueType& y, const ValueType& z) { return (x+1)*(y-2);//*(z+3)*(x + 2*y +5*z+ 1.0/3.0); } }; struct FunDiv { ValueType KOKKOS_INLINE_FUNCTION operator()(const ValueType& x, const ValueType& y, const ValueType& z, const int comp=0) { ValueType a = 2*x*y+x*x; ValueType f0 = 5+y+x*x+z*z; ValueType f1 = -7-2*z+x+y*y+z*z; ValueType f2 = 0.5+z*z+x*x; //fun = f + a x switch (comp) { case 0: return f0 + a*x; case 1: return f1 + a*y; case 2: return f2 + a*z; default: return 0; } } }; struct FunCurl { ValueType KOKKOS_INLINE_FUNCTION operator()(const ValueType& x, const ValueType& y, const ValueType& z, const int comp=0) { ValueType a0 = y-7+z*z; ValueType a1 = 2*z-1+z*x; ValueType a2 = z-2+x*x; ValueType f0 = 2+x+z+x*y; ValueType f1 = 3-3*z; ValueType f2 = -5+x; //fun = f + a \times x switch (comp) { case 0: return f0 + (a1*z-a2*y);//2*x+y-z + (x+2*(y+z); case 1: return f1 + (a2*x-a0*z);//y+2*(z+x); case 2: return f2 + (a0*y-a1*x);//z+2*(x+y); default: return 0; } } }; typedef std::array edgeType; typedef std::array faceType; typedef CellTools ct; typedef OrientationTools ots; typedef Impl::OrientationTools iots; typedef RealSpaceTools rst; typedef FunctionSpaceTools fst; typedef ArrayTools at; constexpr ordinal_type dim = 3; constexpr ordinal_type numCells = 2; constexpr ordinal_type numElemVertexes = 8; constexpr ordinal_type numElemEdges = 12; constexpr ordinal_type numElemFaces = 6; constexpr ordinal_type numTotalVertexes = 12; ValueType vertices_orig[numTotalVertexes][dim] = {{-1,-1,-1},{1,-1,-1},{1,1,-1},{-1,1,-1},{-1,-1,1},{1,-1,1},{1,1,1},{-1,1,1}, {-1,-1,2},{1,-1,2},{1,1,2},{-1,1,2}}; ordinal_type hexas_orig[numCells][numElemVertexes] = {{0,1,2,3,4,5,6,7},{4,5,6,7,8,9,10,11}}; //common face is {4,5,6,7} faceType common_face = {{4,5,6,7}}; faceType faceLeft = {{0, 3, 7, 4}}; faceType faceRight = {{1, 2, 6, 5}}; faceType faceFront = {{0, 4, 5, 1}}; faceType faceBack = {{2, 3, 7, 6}}; ordinal_type hexas_rotated[numCells][numElemVertexes]; faceType faceLeftOriented, faceRightOriented, faceBackOriented, faceFrontOriented; std::set common_edges; common_edges.insert(edgeType({{4,5}})); common_edges.insert(edgeType({{5,6}})); common_edges.insert(edgeType({{6,7}})); common_edges.insert(edgeType({{4,7}})); *outStream << "===============================================================================\n" << "| |\n" << "| Test 1 (Orientation - HGRAD) |\n" << "| |\n" << "===============================================================================\n"; try { const ordinal_type order = 3; ordinal_type reorder[numTotalVertexes] = {0,1,2,3,4,5,6,7,8,9,10,11}; do { ordinal_type orderback[numTotalVertexes]; for(ordinal_type i=0;i >()); shards::CellTopology quad(shards::getCellTopologyData >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, hexa.getNodeCount(), dim); for(ordinal_type i=0; i warpBasis(order,POINTTYPE_WARPBLEND); //used only for computing reference points ordinal_type numRefCoords = warpBasis.getCardinality(); DynRankView ConstructWithLabel(refPoints, numRefCoords, dim); warpBasis.getDofCoords(refPoints); // compute orientations for cells (one time computation) DynRankViewInt elemNodes(&hexas[0][0], 2, numElemVertexes); Kokkos::DynRankView elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, hexa); Basis_HGRAD_HEX_Cn_FEM basis(order); ordinal_type basisCardinality = basis.getCardinality(); //compute DofCoords Oriented DynRankView ConstructWithLabel(dofCoords, basisCardinality, dim); DynRankView ConstructWithLabel(dofCoordsOriented, numCells, basisCardinality, dim); basis.getDofCoords(dofCoords); { for(ordinal_type i=0; i lineBasis(order); ordinal_type lineBasisCardinality = lineBasis.getCardinality(); DynRankView ConstructWithLabel(lineDofCoords, lineBasisCardinality, dim-2); lineBasis.getDofCoords(lineDofCoords); DynRankView ConstructWithLabel(lineDofCoordsOriented, lineBasisCardinality, dim-2); DynRankView ConstructWithLabel(lineDofCoordsOriented3d, lineBasisCardinality, dim); auto numEdgeDOFs = basis.getDofCount(1,0); for(ordinal_type i=0; i quadBasis(order); ordinal_type quadBasisCardinality = quadBasis.getCardinality(); ordinal_type numInternalDofs = quadBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(quadDofCoords, quadBasisCardinality, dim-1); DynRankView ConstructWithLabel(quadInternalDofCoords, numInternalDofs, dim-1); quadBasis.getDofCoords(quadDofCoords); for(ordinal_type i=0; i hexaLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(hexaLinearBasisValuesAtRefCoords, hexa.getNodeCount(), numRefCoords); hexaLinearBasis.getValues(hexaLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(hexaLinearBasisValuesAtDofCoords, numCells, hexa.getNodeCount(), basisCardinality); for(ordinal_type i=0; i 100*tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " Basis function " << k << " of cell " << i << " does not have unit value at its node (" << dofValue <<")\n"; } if ( k!=j && std::abs( dofValue ) > tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " Basis function " << k << " of cell " << i << " does not vanish at node " << j << "(" << dofValue <<")\n"; } } } } } //check function reproducibility Fun fun; DynRankView ConstructWithLabel(funDofs, numCells, basisCardinality); DynRankView ConstructWithLabel(funAtPhysRefCoords, numCells, numRefCoords); for(ordinal_type i=0; i 10*tol; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function DOFs on common face computed using Hex 0 basis functions are not consistent with those computed using Hex 1\n"; *outStream << "Function DOFs for Hex 0 are:"; for(ordinal_type j=0;j 10*tol; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function DOFs on common edge " << iEdge << " computed using Hex 0 basis functions are not consistent with those computed using Hex 1\n"; *outStream << "Function DOFs for Hex 0 are:"; for(ordinal_type j=0;j100*tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function values at reference points differ from those computed using basis functions of Hex " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j >()); shards::CellTopology quad(shards::getCellTopologyData >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, hexa.getNodeCount(), dim); for(ordinal_type i=0; i warpBasis(order,POINTTYPE_WARPBLEND); //used only for computing reference points ordinal_type numRefCoords = warpBasis.getCardinality(); DynRankView ConstructWithLabel(refPoints, numRefCoords, dim); warpBasis.getDofCoords(refPoints); // compute orientations for cells (one time computation) DynRankViewInt elemNodes(&hexas[0][0], 2, numElemVertexes); Kokkos::DynRankView elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, hexa); Basis_HCURL_HEX_In_FEM basis(order); ordinal_type basisCardinality = basis.getCardinality(); //compute DofCoords Oriented DynRankView ConstructWithLabel(dofCoords, basisCardinality, dim); DynRankView ConstructWithLabel(dofCoordsOriented, numCells, basisCardinality, dim); basis.getDofCoords(dofCoords); { Basis_HVOL_LINE_Cn_FEM lineBasis(order-1,POINTTYPE_GAUSS); ordinal_type lineBasisCardinality = lineBasis.getCardinality(); DynRankView ConstructWithLabel(lineDofCoords, lineBasisCardinality, dim-2); lineBasis.getDofCoords(lineDofCoords); DynRankView ConstructWithLabel(lineDofCoordsOriented, lineBasisCardinality, dim-2); DynRankView ConstructWithLabel(lineDofCoordsOriented3d, lineBasisCardinality, dim); auto numEdgeDOFs = basis.getDofCount(1,0); for(ordinal_type i=0; i quadBasis(order); ordinal_type quadBasisCardinality = quadBasis.getCardinality(); ordinal_type numInternalDofs = quadBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(quadDofCoords, quadBasisCardinality, dim-1); DynRankView ConstructWithLabel(quadInternalDofCoords, numInternalDofs, dim-1); quadBasis.getDofCoords(quadDofCoords); for(ordinal_type i=0; i hexaLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(hexaLinearBasisValuesAtRefCoords, hexa.getNodeCount(), numRefCoords); hexaLinearBasis.getValues(hexaLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(hexaLinearBasisValuesAtDofCoords, numCells, hexa.getNodeCount(), basisCardinality); for(ordinal_type i=0; i quadBasis(order); DynRankView ConstructWithLabel(quadDofCoeffs, quadBasis.getCardinality(), dim-1); quadBasis.getDofCoeffs(quadDofCoeffs); for(ordinal_type i=0; itol) areDifferent = true; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Coefficients of Dof " << idof << " at cell " << i << ", scaled by the reference edge length, are NOT equivalent to tangent " << itan << " of face " << iface << "\n"; *outStream << "Dof Coefficients are: (" << dofCoeffsPhys(i,idof,0) << ", " << dofCoeffsPhys(i,idof,1) << ", " << dofCoeffsPhys(i,idof,2) << ")\n"; *outStream << "Face tangent is: (" << tangent[0] << ", " << tangent[1] << ", " << tangent[2] << ")\n"; } } for(ordinal_type iedge=0; iedgetol) areDifferent = true; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Coefficients of Dof " << idof << " at cell " << i << ", scaled by the reference edge length, are NOT equivalent to the tangent of edge " << iedge << "\n"; *outStream << "Dof Coefficients are: (" << dofCoeffsPhys(i,idof,0) << ", " << dofCoeffsPhys(i,idof,1) << ", " << dofCoeffsPhys(i,idof,2) << ")\n"; *outStream << "Face tangent is: (" << tangent[0] << ", " << tangent[1] << ", " << tangent[2] << ")\n"; } } } } //Testing Kronecker property of basis functions { DynRankView ConstructWithLabel(basisValuesAtDofCoords, numCells, basisCardinality, basisCardinality, dim); DynRankView ConstructWithLabel(basisValuesAtDofCoordsOriented, numCells, basisCardinality, basisCardinality, dim); DynRankView ConstructWithLabel(transformedBasisValuesAtDofCoordsOriented, numCells, basisCardinality, basisCardinality, dim); for(ordinal_type i=0; i 100*tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " Basis function " << k << " of cell " << i << " does not have unit value at its node (" << dofValue <<")\n"; *outStream << " Fist tag: " << basis.getDofTag(k)[0] << " " << basis.getDofTag(k)[1]<< " " << basis.getDofTag(k)[2] << " Second tag: " << basis.getDofTag(i)[0] << " " << basis.getDofTag(i)[1]<< " " << basis.getDofTag(i)[2] <<")\n"; } if ( k!=j && std::abs( dofValue ) > tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " Basis function " << k << " of cell " << i << " does not vanish at node " << j << "(" << dofValue <<")\n"; } } } } } //check function reproducibility FunCurl fun; DynRankView ConstructWithLabel(funDofs, numCells, basisCardinality); DynRankView ConstructWithLabel(funAtPhysRefCoords, numCells, numRefCoords, dim); for(ordinal_type i=0; i 10*tol; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function DOFs on common edge " << iEdge << " computed using Hex 0 basis functions are not consistent with those computed using Hex 1\n"; *outStream << "Function DOFs for Hex 0 are:"; for(ordinal_type j=0;j 10*tol; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function DOFs on common face computed using Hex 0 basis functions are not consistent with those computed using Hex 1\n"; *outStream << "Function DOFs for Hex 0 are:"; for(ordinal_type j=0;j100*tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function values at reference points differ from those computed using basis functions of Hex " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j >()); shards::CellTopology quad(shards::getCellTopologyData >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, hexa.getNodeCount(), dim); for(ordinal_type i=0; i elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, hexa); //compute reference points Basis_HGRAD_HEX_Cn_FEM warpBasis(order,POINTTYPE_WARPBLEND); //used only for computing reference points ordinal_type numRefCoords = warpBasis.getCardinality(); DynRankView ConstructWithLabel(refPoints, numRefCoords, dim); warpBasis.getDofCoords(refPoints); Basis_HDIV_HEX_In_FEM basis(order); ordinal_type basisCardinality = basis.getCardinality(); //compute DofCoords Oriented DynRankView ConstructWithLabel(dofCoords, basisCardinality, dim); DynRankView ConstructWithLabel(dofCoordsOriented, numCells, basisCardinality, dim); basis.getDofCoords(dofCoords); { //Basis_HVOL_QUAD_Cn_FEM quadBasis(order-1); Basis_HVOL_QUAD_Cn_FEM quadBasis(order-1, POINTTYPE_GAUSS); ordinal_type quadBasisCardinality = quadBasis.getCardinality(); ordinal_type numInternalDofs = quadBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(quadDofCoords, quadBasisCardinality, dim-1); DynRankView ConstructWithLabel(quadInternalDofCoords, numInternalDofs, dim-1); quadBasis.getDofCoords(quadDofCoords); for(ordinal_type i=0; i hexaLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(hexaLinearBasisValuesAtRefCoords, hexa.getNodeCount(), numRefCoords); hexaLinearBasis.getValues(hexaLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(hexaLinearBasisValuesAtDofCoords, numCells, hexa.getNodeCount(), basisCardinality); for(ordinal_type i=0; itol) areDifferent = true; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Coefficients of Dof " << idof << " at cell " << i << ", scaled by the area of the reference Quad, are NOT equivalent to the normal of face " << iface << "\n"; *outStream << "Dof Coefficients are: (" << dofCoeffsPhys(i,idof,0) << ", " << dofCoeffsPhys(i,idof,1) << ", " << dofCoeffsPhys(i,idof,2) << ")\n"; *outStream << "Face normal is: (" << normal[0] << ", " << normal[1] << ", " << normal[2] << ")\n"; } } } } //Testing Kronecker property of basis functions { for(ordinal_type i=0; i 100*tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " Basis function " << k << " of cell " << i << " does not have unit value at its node (" << dofValue <<")\n"; } if ( k!=j && std::abs( dofValue ) > tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " Basis function " << k << " of cell " << i << " does not vanish at node " << j << "(" << dofValue <<")\n"; } } } } } //check function reproducibility FunDiv fun; DynRankView ConstructWithLabel(funDofs, numCells, basisCardinality); DynRankView ConstructWithLabel(funAtPhysRefCoords, numCells, numRefCoords, dim); for(ordinal_type i=0; i 10*tol; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function DOFs on common face computed using Hex 0 basis functions are not consistent with those computed using Hex 1\n"; *outStream << "Function DOFs for Hex 0 are:"; for(ordinal_type j=0;j 10*tol; } if(areDifferent) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function DOFs on common face computed using Hex 0 basis functions are not consistent with those computed using Hex 1\n"; *outStream << "Function DOFs for Hex 0 are:"; for(ordinal_type j=0;j100*tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "Function values at reference points differ from those computed using basis functions of Hex " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j