// @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 triangular elements The test considers two triangles in the physical space sharing a common edge. In order to test significant configurations, we consider 3 mappings of the reference triangle to the first (physical) triangle, so that the common edge is mapped from all the 3 edges of the reference triangule. Then, for each of the mappings, the global ids of the vertices of the common edge are permuted. This gives a total of 6 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 edges are proportional to the tangents (for HCURL) of edges or to the normals (for HDIV) of the edges. 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 edge are the same when computed on the first and second triangle. 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_TRI_C1_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 OrientationTri(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) { 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 int comp=0) { ValueType a = 2*x*y+x*x; ValueType f0 = 5+y+x*x; ValueType f1 = -7-2*x+y*y; //fun = f + a x switch (comp) { case 0: return f0 + a*x; case 1: return f1 + a*y; default: return 0; } } }; struct FunCurl { ValueType KOKKOS_INLINE_FUNCTION operator()(const ValueType& x, const ValueType& y, const int comp=0) { ValueType a2 = y-7+y*y; ValueType f0 = 2+x+x*y; ValueType f1 = 3-3*x; //fun = f + a \times x switch (comp) { case 0: return f0 - a2*y; case 1: return f1 + a2*x; default: return 0; } } }; typedef std::array edgeType; typedef CellTools ct; typedef OrientationTools ots; typedef Impl::OrientationTools iots; typedef RealSpaceTools rst; typedef FunctionSpaceTools fst; typedef ArrayTools at; constexpr ordinal_type dim = 2; constexpr ordinal_type numCells = 2; constexpr ordinal_type numElemVertexes = 3; constexpr ordinal_type numElemEdges = 3; constexpr ordinal_type numTotalVertexes = 4; ValueType vertices_orig[numTotalVertexes][dim] = {{0,0},{0,1},{1,0},{1,1}}; ordinal_type tris_orig[numCells][numElemVertexes] = {{0,1,2},{1,2,3}}; edgeType common_edge = {{1,2}}; ordinal_type tris_rotated[numCells][numElemVertexes]; *outStream << "===============================================================================\n" << "| |\n" << "| Test 1 (Orientation - HGRAD) |\n" << "| |\n" << "===============================================================================\n"; try { const ordinal_type order = 3; ordinal_type reorder[numTotalVertexes] = {0,1,2,3}; do { ordinal_type orderback[numTotalVertexes]; for(ordinal_type i=0;i >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, tri.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(&tris[0][0], numCells, numElemVertexes); Kokkos::DynRankView elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, tri); Basis_HGRAD_TRI_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-1); lineBasis.getDofCoords(lineDofCoords); DynRankView ConstructWithLabel(lineDofCoordsOriented, lineBasisCardinality, dim-1); DynRankView ConstructWithLabel(lineDofCoordsOriented2d, lineBasisCardinality, dim); auto numEdgeDOFs = basis.getDofCount(1,0); for(ordinal_type i=0; i triLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(triLinearBasisValuesAtRefCoords, tri.getNodeCount(), numRefCoords); triLinearBasis.getValues(triLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(triLinearBasisValuesAtDofCoords, numCells, tri.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 edge computed using Tri 0 basis functions are not consistent with those computed using Tri 1\n"; *outStream << "Function DOFs for Tri 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 Tri " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, tri.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(&tris[0][0], numCells, numElemVertexes); Kokkos::DynRankView elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, tri); Basis_HCURL_TRI_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-1); lineBasis.getDofCoords(lineDofCoords); DynRankView ConstructWithLabel(lineDofCoordsOriented, lineBasisCardinality, dim-1); DynRankView ConstructWithLabel(lineDofCoordsOriented2d, lineBasisCardinality, dim); auto numEdgeDOFs = basis.getDofCount(1,0); for(ordinal_type i=0; i triLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(triLinearBasisValuesAtRefCoords, tri.getNodeCount(), numRefCoords); triLinearBasis.getValues(triLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(triLinearBasisValuesAtDofCoords, numCells, tri.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 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 the common edge computed using Tri 0 basis functions are not consistent with those computed using Tri 1\n"; *outStream << "Function DOFs for Tri 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 Tri " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j >()); shards::CellTopology line(shards::getCellTopologyData >()); //computing vertices coords DynRankView ConstructWithLabel(physVertexes, numCells, tri.getNodeCount(), dim); for(ordinal_type i=0; i elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, tri); //compute reference points Basis_HGRAD_TRI_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_TRI_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 sideBasis(order-1); ordinal_type sideBasisCardinality = sideBasis.getCardinality(); ordinal_type numInternalDofs = sideBasis.getDofCount(dim-1,0); DynRankView ConstructWithLabel(sideDofCoords, sideBasisCardinality, dim-1); DynRankView ConstructWithLabel(sideInternalDofCoords, numInternalDofs, dim-1); sideBasis.getDofCoords(sideDofCoords); for(ordinal_type i=0; i triLinearBasis; //used for computing physical coordinates DynRankView ConstructWithLabel(triLinearBasisValuesAtRefCoords, tri.getNodeCount(), numRefCoords); triLinearBasis.getValues(triLinearBasisValuesAtRefCoords, refPoints); DynRankView ConstructWithLabel(triLinearBasisValuesAtDofCoords, numCells, tri.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 proportional to the normal of edge " << iedge << "\n"; *outStream << "Dof Coefficients are: (" << dofCoeffsPhys(i,idof,0) << ", " << dofCoeffsPhys(i,idof,1) << ")\n"; *outStream << "Edge normal is: (" << normal[0] << ", " << normal[1] << ")\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 edge computed using Tri 0 basis functions are not consistent with those computed using Tri 1\n"; *outStream << "Function DOFs for Tri 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 Tri " << i << "\n"; *outStream << "Function values at reference points are:\n"; for(ordinal_type j=0; j