// @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 Tetrahedral elements The test considers two tetrahedra in the physical space sharing a common face. In order to test significant configurations, we consider 4 mappings of the reference tetrahedron to the first (physical) tetrahedron, so that the common face is mapped from all the 4 faces of the reference tetrahedron. Then, for each of the mappings, the global ids of the vertices of the common faces are permuted. This gives a total of 24 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 physical faces/edges or to the normals (for HDIV) of physical 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 one the first and second tetrahedron. 4. that a function, belonging to the considered H-space, is exactly 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_TRI_C1_FEM.hpp" #include "Intrepid2_HGRAD_TET_C1_FEM.hpp" #include "Intrepid2_HGRAD_TET_Cn_FEM.hpp" #include "Intrepid2_HCURL_TET_In_FEM.hpp" #include "Intrepid2_HCURL_TRI_In_FEM.hpp" #include "Intrepid2_HVOL_LINE_Cn_FEM.hpp" #include "Intrepid2_HVOL_TRI_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 OrientationTet(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 = 4; constexpr ordinal_type numElemEdges = 6; constexpr ordinal_type numElemFaces = 4; constexpr ordinal_type numTotalVertexes = 5; ValueType vertices_orig[numTotalVertexes][dim] = {{0,0,0},{1,0,0},{0,1,0},{0,0,1},{1,1,1}}; ordinal_type tets_orig[numCells][numElemVertexes] = {{0,1,2,3},{1,2,3,4}}; //common face is {1,2,3} ordinal_type tets_rotated[numCells][numElemVertexes]; faceType common_face = {{1,2,3}}; std::set common_edges; common_edges.insert(edgeType({{1,2}})); common_edges.insert(edgeType({{1,3}})); common_edges.insert(edgeType({{2,3}})); *outStream << "===============================================================================\n" << "| |\n" << "| Test 1 (Orientation - HGRAD) |\n" << "| |\n" << "===============================================================================\n"; try { const ordinal_type order = 4; ordinal_type reorder[numTotalVertexes] = {0,1,2,3,4}; do { ordinal_type orderback[numTotalVertexes]; for(ordinal_type i=0;i >()); shards::CellTopology tri(shards::getCellTopologyData >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, tet.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(&tets[0][0], numCells, numElemVertexes); Kokkos::DynRankView elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, tet); Basis_HGRAD_TET_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 triBasis(order); ordinal_type triBasisCardinality = triBasis.getCardinality(); ordinal_type numInternalDofs = triBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(triDofCoords, triBasisCardinality, dim-1); DynRankView ConstructWithLabel(triInternalDofCoords, numInternalDofs, dim-1); triBasis.getDofCoords(triDofCoords); for(ordinal_type i=0; i tetLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(tetLinearBasisValuesAtRefCoords, tet.getNodeCount(), numRefCoords); tetLinearBasis.getValues(tetLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(tetLinearBasisValuesAtDofCoords, numCells, tet.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 reproducbility 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 Tet 0 basis functions are not consistent with those computed using Tet 1\n"; *outStream << "Function DOFs for Tet 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 Tet 0 basis functions are not consistent with those computed using Tet 1\n"; *outStream << "Function DOFs for Tet 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 Tet " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j >()); shards::CellTopology tri(shards::getCellTopologyData >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, tet.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(&tets[0][0], numCells, numElemVertexes); Kokkos::DynRankView elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, tet); Basis_HCURL_TET_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); 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 triBasis(order); ordinal_type triBasisCardinality = triBasis.getCardinality(); ordinal_type numInternalDofs = triBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(triDofCoords, triBasisCardinality, dim-1); DynRankView ConstructWithLabel(triInternalDofCoords, numInternalDofs, dim-1); triBasis.getDofCoords(triDofCoords); for(ordinal_type i=0; i tetLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(tetLinearBasisValuesAtRefCoords, tet.getNodeCount(), numRefCoords); tetLinearBasis.getValues(tetLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(tetLinearBasisValuesAtDofCoords, numCells, tet.getNodeCount(), basisCardinality); for(ordinal_type i=0; i triBasis(order); DynRankView ConstructWithLabel(triDofCoeffs, triBasis.getCardinality(), dim-1); triBasis.getDofCoeffs(triDofCoeffs); 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 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 Tet 0 basis functions are not consistent with those computed using Tet 1\n"; *outStream << "Function DOFs for Tet 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 Tet 0 basis functions are not consistent with those computed using Tet 1\n"; *outStream << "Function DOFs for Tet 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 tri(shards::getCellTopologyData >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, tet.getNodeCount(), dim); for(ordinal_type i=0; i elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, tet); //compute reference points Basis_HGRAD_TET_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_TET_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_TRI_Cn_FEM triBasis(order-1); ordinal_type triBasisCardinality = triBasis.getCardinality(); ordinal_type numInternalDofs = triBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(triDofCoords, triBasisCardinality, dim-1); DynRankView ConstructWithLabel(triInternalDofCoords, numInternalDofs, dim-1); triBasis.getDofCoords(triDofCoords); for(ordinal_type i=0; i tetLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(tetLinearBasisValuesAtRefCoords, tet.getNodeCount(), numRefCoords); tetLinearBasis.getValues(tetLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(tetLinearBasisValuesAtDofCoords, numCells, tet.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 << " 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 Tet 0 basis functions are not consistent with those computed using Tet 1\n"; *outStream << "Function DOFs for Tet 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 Tet 0 basis functions are not consistent with those computed using Tet 1\n"; *outStream << "Function DOFs for Tet 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