int HCURL_TET_I1_FEM_Test01(const bool verbose) { Teuchos::RCP<std::ostream> 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); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (Basis_HCURL_TET_I1_FEM) |\n" << "| |\n" << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" << "| 2) Basis values for VALUE and CURL operators |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]) or |\n" << "| Denis Ridzal ([email protected]). |\n" << "| Kara Peterson ([email protected]). |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; typedef Kokkos::DynRankView<ValueType,HostSpaceType> DynRankViewHost; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) const ValueType tol = tolerence(); int errorFlag = 0; // for virtual function, value and point types are declared in the class typedef ValueType outputValueType; typedef ValueType pointValueType; Basis_HCURL_TET_I1_FEM<DeviceSpaceType,outputValueType,pointValueType> tetBasis; *outStream << "\n" << "===============================================================================\n" << "| TEST 1: Basis creation, exception testing |\n" << "===============================================================================\n"; try{ ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG DynRankView ConstructWithLabel( tetNodes, 10, 3 ); // Generic array for the output values; needs to be properly resized depending on the operator type const ordinal_type cardinality = tetBasis.getCardinality(); const ordinal_type numPoints = tetNodes.dimension(0); DynRankView vals; vals = DynRankView("vals", cardinality, numPoints); { // exception #1: GRAD cannot be applied to HCURL functions // resize vals to rank-3 container with dimensions (num. basis functions, num. points, arbitrary) INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, tetNodes, OPERATOR_GRAD) ); } { // exception #2: DIV cannot be applied to HCURL functions // resize vals to rank-2 container with dimensions (num. basis functions, num. points) INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, tetNodes, OPERATOR_DIV) ); } { // Exceptions 3-7: all bf tags/bf Ids below are wrong and should cause getDofOrdinal() and // getDofTag() to access invalid array elements thereby causing bounds check exception // exception #3 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(3,0,0) ); // exception #4 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(1,1,1) ); // exception #5 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(0,4,1) ); // exception #6 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofTag(cardinality) ); // exception #7 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofTag(-1) ); } { // Exceptions 8-15 test exception handling with incorrectly dimensioned input/output arrays // exception #8: input points array must be of rank-2 DynRankView ConstructWithLabel(badPoints1, 4, 5, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals,badPoints1,OPERATOR_VALUE) ); } { // exception #9 dimension 1 in the input point array must equal space dimension of the cell DynRankView ConstructWithLabel(badPoints2, 4, 2); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals,badPoints2,OPERATOR_VALUE) ); } { // exception #10 output values must be of rank-3 for OPERATOR_VALUE DynRankView ConstructWithLabel(badVals1, 4, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals1,tetNodes,OPERATOR_VALUE) ); // exception #11 output values must be of rank-3 for OPERATOR_CURL INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals1,tetNodes,OPERATOR_CURL) ); } { // exception #12 incorrect 0th dimension of output array (must equal number of basis functions) DynRankView ConstructWithLabel(badVals2, cardinality+1, numPoints, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals2,tetNodes,OPERATOR_VALUE) ); } { // exception #13 incorrect 1st dimension of output array (must equal number of points) DynRankView ConstructWithLabel(badVals3, cardinality, numPoints+1, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals3,tetNodes,OPERATOR_VALUE) ); } { // exception #14: incorrect 2nd dimension of output array (must equal the space dimension) DynRankView ConstructWithLabel(badVals4, cardinality, numPoints, 4); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals4,tetNodes,OPERATOR_VALUE) ); // exception #15: incorrect 2nd dimension of output array (must equal the space dimension) INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals4,tetNodes,OPERATOR_CURL) ); } #endif // Check if number of thrown exceptions matches the one we expect if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << nthrow << ")\n"; } } catch (std::logic_error err) { *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n"; *outStream << err.what() << '\n'; *outStream << "-------------------------------------------------------------------------------" << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n" << "===============================================================================\n"; // all tags are on host space try{ const auto allTags = tetBasis.getAllDofTags(); // Loop over all tags, lookup the associated dof enumeration and then lookup the tag again const ordinal_type dofTagSize = allTags.dimension(0); for (ordinal_type i = 0; i < dofTagSize; ++i) { auto bfOrd = tetBasis.getDofOrdinal(allTags(i,0), allTags(i,1), allTags(i,2)); const auto myTag = tetBasis.getDofTag(bfOrd); if( !( (myTag(0) == allTags(i,0)) && (myTag(1) == allTags(i,1)) && (myTag(2) == allTags(i,2)) && (myTag(3) == allTags(i,3)) ) ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofOrdinal( {" << allTags(i,0) << ", " << allTags(i,1) << ", " << allTags(i,2) << ", " << allTags(i,3) << "}) = " << bfOrd <<" but \n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "}\n"; } } // Now do the same but loop over basis functions for( ordinal_type bfOrd = 0; bfOrd < tetBasis.getCardinality(); bfOrd++) { const auto myTag = tetBasis.getDofTag(bfOrd); const auto myBfOrd = tetBasis.getDofOrdinal(myTag(0), myTag(1), myTag(2)); if( bfOrd != myBfOrd) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} but getDofOrdinal({" << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} ) = " << myBfOrd << "\n"; } } } catch (std::logic_error err){ *outStream << err.what() << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 3: correctness of basis function values |\n" << "===============================================================================\n"; outStream -> precision(20); // VALUE: Each row pair gives the 6x3 correct basis set values at an evaluation point: (P,F,D) layout const ValueType basisValues[] = { // 4 vertices 1.0,0.,0., 0.,0.,0., 0.,-1.0,0., 0.,0.,1.0, 0.,0.,0., 0.,0.,0., 1.0,1.0,1.0, 0.,1.,0., 0.,0.,0., 0.,0.,0., 0.,0.,1., 0.,0.,0., 0.,0.,0., -1.,0.,0., -1.0,-1.0,-1.0, 0.,0.,0., 0.,0.,0., 0.,0.,1., 0.,0.,0., 0.,0.,0., 0.,0.,0., 1.0,1.0,1.0, -1.,0.,0., 0.,-1.,0., // 6 edge centers 1.0,0.5,0.5, 0.,0.5,0., 0.,-0.5,0., 0.,0.,0.5, 0.,0.,0.5, 0.,0.,0., 0.5,0.5,0.5, -0.5,0.5,0., -0.5,-0.5,-0.5, 0.,0.,0., 0.,0.,0.5, 0.,0.,0.5, 0.5,0.,0., -0.5,0.,0., -0.5,-1.0,-0.5, 0.,0.,0.5, 0.,0.,0., 0.,0.,0.5, 0.5,0.,0., 0.,0.,0., 0.,-0.5,0., 0.5,0.5,1.0, -0.5,0.,0., 0.,-0.5,0., 0.5,0.5,0.5, 0.,0.5,0., 0.,0.,0., 0.5,0.5,0.5, -0.5,0.,0.5, 0.,-0.5,0., 0.,0.,0., -0.5,0.,0., -0.5,-0.5,-0.5, 0.5,0.5,0.5, -0.5,0.,0., 0.,-0.5,0.5 }; // CURL: each row pair gives the 3x12 correct values of the curls of the 12 basis functions: (P,F,D) layout const ValueType basisCurls[] = { // 4 vertices 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., // 6 edge centers 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, -2.0,2.0,0., 0.,-2.0,0., 2.0,0.,0., }; try{ // Define array containing the 4 vertices of the reference TET and its 6 edge centers. DynRankViewHost ConstructWithLabel(tetNodesHost, 10, 3); tetNodesHost(0,0) = 0.0; tetNodesHost(0,1) = 0.0; tetNodesHost(0,2) = 0.0; tetNodesHost(1,0) = 1.0; tetNodesHost(1,1) = 0.0; tetNodesHost(1,2) = 0.0; tetNodesHost(2,0) = 0.0; tetNodesHost(2,1) = 1.0; tetNodesHost(2,2) = 0.0; tetNodesHost(3,0) = 0.0; tetNodesHost(3,1) = 0.0; tetNodesHost(3,2) = 1.0; tetNodesHost(4,0) = 0.5; tetNodesHost(4,1) = 0.0; tetNodesHost(4,2) = 0.0; tetNodesHost(5,0) = 0.5; tetNodesHost(5,1) = 0.5; tetNodesHost(5,2) = 0.0; tetNodesHost(6,0) = 0.0; tetNodesHost(6,1) = 0.5; tetNodesHost(6,2) = 0.0; tetNodesHost(7,0) = 0.0; tetNodesHost(7,1) = 0.0; tetNodesHost(7,2) = 0.5; tetNodesHost(8,0) = 0.5; tetNodesHost(8,1) = 0.0; tetNodesHost(8,2) = 0.5; tetNodesHost(9,0) = 0.0; tetNodesHost(9,1) = 0.5; tetNodesHost(9,2) = 0.5; auto tetNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetNodesHost); Kokkos::deep_copy(tetNodes, tetNodesHost); // Dimensions for the output arrays: const ordinal_type cardinality = tetBasis.getCardinality(); const ordinal_type numPoints = tetNodes.dimension(0); const ordinal_type spaceDim = tetBasis.getBaseCellTopology().getDimension(); { // Check VALUE of basis functions: resize vals to rank-3 container: DynRankView ConstructWithLabel(vals, cardinality, numPoints, spaceDim); tetBasis.getValues(vals, tetNodes, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < cardinality; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < spaceDim; ++k) { // compute offset for (P,F,D) data layout: indices are P->j, F->i, D->k const ordinal_type l = k + i * spaceDim + j * spaceDim * cardinality; if (std::abs(vals_host(i,j,k) - basisValues[l]) > tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed value: " << vals_host(i,j,k) << " but reference value: " << basisValues[l] << "\n"; } } } } } { // Check CURL of basis function: resize vals to rank-3 container DynRankView ConstructWithLabel(vals, cardinality, numPoints, spaceDim); tetBasis.getValues(vals, tetNodes, OPERATOR_CURL); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (ordinal_type i = 0; i < cardinality; ++i) { for (ordinal_type j = 0; j < numPoints; ++j) { for (ordinal_type k = 0; k < spaceDim; ++k) { // compute offset for (P,F,D) data layout: indices are P->j, F->i, D->k const ordinal_type l = k + i * spaceDim + j * spaceDim * cardinality; if (std::abs(vals_host(i,j,k) - basisCurls[l]) > tol ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed curl component: " << vals_host(i,j,k) << " but reference curl component: " << basisCurls[l] << "\n"; } } } } } } // Catch unexpected errors catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 4: correctness of DoF locations |\n" << "===============================================================================\n"; try{ const ordinal_type cardinality = tetBasis.getCardinality(); const ordinal_type spaceDim = tetBasis.getBaseCellTopology().getDimension(); // Check exceptions. ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG { DynRankView ConstructWithLabel(badVals, 1, 2, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofCoords(badVals) ); } { DynRankView ConstructWithLabel(badVals, 3, 2); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofCoords(badVals) ); } { DynRankView ConstructWithLabel(badVals, 4, 2); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofCoords(badVals) ); } #endif // Check if number of thrown exceptions matches the one we expect if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << ncatch << ")\n"; } // Check mathematical correctness DynRankView ConstructWithLabel(bvals, cardinality, cardinality, spaceDim); DynRankView ConstructWithLabel(cvals, cardinality, spaceDim); DynRankView ConstructWithLabel(dofCoeffs, cardinality, spaceDim); tetBasis.getDofCoords(cvals); tetBasis.getDofCoeffs(dofCoeffs); tetBasis.getValues(bvals, cvals, OPERATOR_VALUE); auto cvals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), cvals); Kokkos::deep_copy(cvals_host, cvals); auto dofCoeffs_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), dofCoeffs); Kokkos::deep_copy(dofCoeffs_host, dofCoeffs); auto bvals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), bvals); Kokkos::deep_copy(bvals_host, bvals); char buffer[120]; for (ordinal_type i=0; i<cardinality; ++i) { for (ordinal_type j=0; j<cardinality; ++j) { double dofValue = 0.0; for(ordinal_type d=0;d<spaceDim;++d) dofValue += bvals_host(i,j,d)*dofCoeffs_host(j,d); if ((i != j) && (std::abs(dofValue - 0.0) > tol )) { errorFlag++; sprintf(buffer, "\nValue of basis function %d at (%6.4e, %6.4e, %6.4e) is %6.4e but should be %6.4e!\n", i, cvals_host(i,0), cvals_host(i,1), cvals_host(i,2), dofValue, 0.0); *outStream << buffer; } else if ((i == j) && (std::abs(dofValue - 1.0) > tol )) { errorFlag++; sprintf(buffer, "\nValue of basis function %d at (%6.4e, %6.4e, %6.4e) is %6.4e but should be %6.4e!\n", i, cvals_host(i,0), cvals_host(i,1), cvals_host(i,2), dofValue, 1.0); *outStream << buffer; } } } } catch (std::logic_error err){ *outStream << err.what() << "\n\n"; errorFlag = -1000; }; if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
int HGRAD_TET_COMP12_FEM_Test01(const bool verbose) { Teuchos::RCP<std::ostream> 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); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (Basis_HGRAD_TET_COMP12_FEM) |\n" << "| |\n" << "| 1) Evaluation of Basis Function Values |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]), |\n" << "| Denis Ridzal ([email protected]), |\n" << "| Kara Peterson ([email protected]), |\n" << "| Jake Ostien ([email protected]), |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; typedef Kokkos::DynRankView<ValueType,HostSpaceType> DynRankViewHost; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) const ValueType tol = tolerence(); int errorFlag = 0; // for virtual function, value and point types are declared in the class typedef ValueType outputValueType; typedef ValueType pointValueType; Basis_HGRAD_TET_COMP12_FEM<DeviceSpaceType,outputValueType,pointValueType> tetBasis; *outStream << "\n" << "===============================================================================\n" << "| TEST 1: correctness of basis function values |\n" << "===============================================================================\n"; // output precision outStream -> precision(20); // VALUE: Each row gives the 10 correct basis set values at an evaluation point const ValueType nodalBasisValues[] = { // first 4 vertices 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, // second 6 vertices 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; const ValueType pointBasisValues[] = { // pt 0 {0.25, 0.25, 0.25} 0.0, 0.0, 0.0, 0.0, 1./6., 1./6., 1./6., 1./6., 1./6., 1./6., // pt 1 {0.5, 1/6, 1/6} 0.0, 0.0, 0.0, 0.0, 1./3., 1./3., 0.0, 0.0, 1./3., 0.0, // pt 2 {1/6, 0.5, 0.1/6} 0.0, 0.0, 0.0, 0.0, 0.0, 1./3., 1./3., 0.0, 0.0, 1./3., // pt 3 {1/6, 1/6, 0.5} 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1./3., 1./3., 1./3., // pt 4 {1/6, 1/6, 1/6} 0.0, 0.0, 0.0, 0.0, 1./3., 0.0, 1./3., 1./3., 0.0, 0.0, // pt 5 0.170820393249936908922752100619382870632, 0.0, 0.0, 0.0, 0.276393202250021030359082633126872376456, 0.0, 0.276393202250021030359082633126872376456, 0.276393202250021030359082633126872376456, 0.0, 0.0, // pt 6 0.0, 0.170820393249936908922752100619382870632, 0.0, 0.0, 0.276393202250021030359082633126872376456, 0.276393202250021030359082633126872376456, 0.0, 0.0, 0.276393202250021030359082633126872376456, 0.0, // pt 7 0.0, 0.0, 0.170820393249936908922752100619382870632, 0.0, 0.0, 0.276393202250021030359082633126872376456, 0.276393202250021030359082633126872376456, 0.0, 0.0, 0.276393202250021030359082633126872376456, // pt 8 0.0, 0.0, 0.0, 0.170820393249936908922752100619382870632, 0.0, 0.0, 0.0, 0.276393202250021030359082633126872376456, 0.276393202250021030359082633126872376456, 0.276393202250021030359082633126872376456, }; // GRAD and D1: each row gives the 3x10 correct values of the gradients of the 10 basis functions const ValueType pointBasisGrads[] = { // point 0 -1./4., -1./4., -1./4., 1./4., 0.0, 0.0, 0.0, 1./4., 0.0, 0.0, 0.0, 1./4., 0.0, -3./4., -3./4., 3./4., 3./4., 0.0, -3./4., 0.0, -3./4., -3./4., -3./4., 0.0, 3./4., 0.0, 3./4., 0.0, 3./4., 3./4., // point 1 -1./24., -1./24., -1./24., 7./8., 0.0, 0.0, 0.0, 1./24., 0.0, 0.0, 0.0, 1./24., -35./36., -19./12., -19./12., 11./18., 19./12., 0.0, -17./36., 0.0, -1./3., -17./36., -1./3., 0.0, 11./18., 0.0, 19./12., -5./36., 1./3., 1./3., // point 2 -1./24., -1./24., -1./24., 1./24., 0.0, 0.0, 0.0, 7./8., 0.0, 0.0, 0.0, 1./24., 0.0, -17./36., -1./3., 19./12., 11./18., 0.0, -19./12., -35./36., -19./12., -1./3., -17./36., 0.0, 1./3., -5./36., 1./3., 0.0, 11./18., 19./12., // point 3 -1./24., -1./24., -1./24., 1./24., 0.0, 0.0, 0.0, 1./24., 0.0, 0.0, 0.0, 7./8., 0.0, -1./3., -17./36., 1./3., 1./3., -5./36., -1./3., 0.0, -17./36., -19./12., -19./12., -35./36., 19./12., 0.0, 11./18., 0.0, 19./12., 11./18., // point 4 -7./8., -7./8., -7./8., 1./24., 0.0, 0.0, 0.0, 1./24., 0.0, 0.0, 0.0, 1./24., 35./36., -11./18., -11./18., 17./36., 17./36., 5./36., -11./18., 35./36., -11./18., -11./18., -11./18., 35./36., 17./36., 5./36., 17./36., 5./36., 17./36., 17./36., // point 5 -1.088525491562421136153440125774228588290, -1.088525491562421136153440125774228588290, -1.088525491562421136153440125774228588290, -0.029508497187473712051146708591409529430, 0.0, 0.0, 0.0, -0.029508497187473712051146708591409529430, 0.0, 0.0, 0.0, -0.029508497187473712051146708591409529430, 1.30437298687487732290535130675991113734, -0.563661001875017525299235527605726980380, -0.563661001875017525299235527605726980380, 0.377322003750035050598471055211453960760, 0.377322003750035050598471055211453960760, 0.186338998124982474700764472394273019620, -0.563661001875017525299235527605726980380, 1.30437298687487732290535130675991113734, -0.563661001875017525299235527605726980380, -0.563661001875017525299235527605726980380, -0.563661001875017525299235527605726980380, 1.30437298687487732290535130675991113734, 0.377322003750035050598471055211453960760, 0.186338998124982474700764472394273019620, 0.377322003750035050598471055211453960760, 0.186338998124982474700764472394273019620, 0.377322003750035050598471055211453960760, 0.377322003750035050598471055211453960760, // point 6 0.029508497187473712051146708591409529430, 0.029508497187473712051146708591409529430, 0.029508497187473712051146708591409529430, 1.088525491562421136153440125774228588290, 0.0, 0.0, 0.0, -0.029508497187473712051146708591409529430, 0.0, 0.0, 0.0, -0.029508497187473712051146708591409529430, -1.30437298687487732290535130675991113734, -1.868033988749894848204586834365638117720, -1.868033988749894848204586834365638117720, 0.563661001875017525299235527605726980380, 1.868033988749894848204586834365638117720, 0.0, -0.377322003750035050598471055211453960760, 0.0, -0.190983005625052575897706582817180941140, -0.377322003750035050598471055211453960760, -0.190983005625052575897706582817180941140, 0.0, 0.563661001875017525299235527605726980380, 0.0, 1.868033988749894848204586834365638117720, -0.186338998124982474700764472394273019620, 0.190983005625052575897706582817180941140, 0.19098300562505257589770658281718094114, // point 7 0.029508497187473712051146708591409529430, 0.029508497187473712051146708591409529430, 0.029508497187473712051146708591409529430, -0.029508497187473712051146708591409529430, 0.0, 0.0, 0.0, 1.088525491562421136153440125774228588290, 0.0, 0.0, 0.0, -0.029508497187473712051146708591409529430, 0.0, -0.377322003750035050598471055211453960760, -0.190983005625052575897706582817180941140, 1.868033988749894848204586834365638117720, 0.563661001875017525299235527605726980380, 0.0, -1.868033988749894848204586834365638117720, -1.30437298687487732290535130675991113734, -1.868033988749894848204586834365638117720, -0.190983005625052575897706582817180941140, -0.377322003750035050598471055211453960760, 0.0, 0.190983005625052575897706582817180941140, -0.186338998124982474700764472394273019620, 0.190983005625052575897706582817180941140, 0.0, 0.563661001875017525299235527605726980380, 1.868033988749894848204586834365638117720, // point 8 0.029508497187473712051146708591409529430, 0.029508497187473712051146708591409529430, 0.029508497187473712051146708591409529430, -0.029508497187473712051146708591409529430, 0.0, 0.0, 0.0, -0.029508497187473712051146708591409529430, 0.0, 0.0, 0.0, 1.088525491562421136153440125774228588290, 0.0, -0.190983005625052575897706582817180941140, -0.377322003750035050598471055211453960760, 0.190983005625052575897706582817180941140, 0.190983005625052575897706582817180941140, -0.186338998124982474700764472394273019620, -0.190983005625052575897706582817180941140, 0.0, -0.377322003750035050598471055211453960760, -1.868033988749894848204586834365638117720, -1.868033988749894848204586834365638117720, -1.30437298687487732290535130675991113734, 1.868033988749894848204586834365638117720, 0.0, 0.563661001875017525299235527605726980380, 0.0, 1.868033988749894848204586834365638117720, 0.563661001875017525299235527605726980380, }; try{ DynRankViewHost ConstructWithLabel(tetNodesHost, 10, 3); tetNodesHost(0,0) = 0.0; tetNodesHost(0,1) = 0.0; tetNodesHost(0,2) = 0.0; tetNodesHost(1,0) = 1.0; tetNodesHost(1,1) = 0.0; tetNodesHost(1,2) = 0.0; tetNodesHost(2,0) = 0.0; tetNodesHost(2,1) = 1.0; tetNodesHost(2,2) = 0.0; tetNodesHost(3,0) = 0.0; tetNodesHost(3,1) = 0.0; tetNodesHost(3,2) = 1.0; tetNodesHost(4,0) = 0.5; tetNodesHost(4,1) = 0.0; tetNodesHost(4,2) = 0.0; tetNodesHost(5,0) = 0.5; tetNodesHost(5,1) = 0.5; tetNodesHost(5,2) = 0.0; tetNodesHost(6,0) = 0.0; tetNodesHost(6,1) = 0.5; tetNodesHost(6,2) = 0.0; tetNodesHost(7,0) = 0.0; tetNodesHost(7,1) = 0.0; tetNodesHost(7,2) = 0.5; tetNodesHost(8,0) = 0.5; tetNodesHost(8,1) = 0.0; tetNodesHost(8,2) = 0.5; tetNodesHost(9,0) = 0.0; tetNodesHost(9,1) = 0.5; tetNodesHost(9,2) = 0.5; auto tetNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetNodesHost); Kokkos::deep_copy(tetNodes, tetNodesHost); DynRankViewHost ConstructWithLabel(tetPointsHost, 9, 3); // from the 5 point integration tetPointsHost(0,0) = 0.25; tetPointsHost(0,1) = 0.25; tetPointsHost(0,2) = 0.25; tetPointsHost(1,0) = 0.5; tetPointsHost(1,1) = (1./6.); tetPointsHost(1,2) = (1./6.); tetPointsHost(2,0) = (1./6.); tetPointsHost(2,1) = 0.5; tetPointsHost(2,2) = (1./6.); tetPointsHost(3,0) = (1./6.); tetPointsHost(3,1) = (1./6.); tetPointsHost(3,2) = 0.5; tetPointsHost(4,0) = (1./6.); tetPointsHost(4,1) = (1./6.); tetPointsHost(4,2) = (1./6.); // from the 4 point integration tetPointsHost(5,0) = 0.1381966011250105151795413165634361882280; tetPointsHost(5,1) = 0.1381966011250105151795413165634361882280; tetPointsHost(5,2) = 0.1381966011250105151795413165634361882280; tetPointsHost(6,0) = 0.5854101966249684544613760503096914353161; tetPointsHost(6,1) = 0.1381966011250105151795413165634361882280; tetPointsHost(6,2) = 0.1381966011250105151795413165634361882280; tetPointsHost(7,0) = 0.1381966011250105151795413165634361882280; tetPointsHost(7,1) = 0.5854101966249684544613760503096914353161; tetPointsHost(7,2) = 0.1381966011250105151795413165634361882280; tetPointsHost(8,0) = 0.1381966011250105151795413165634361882280; tetPointsHost(8,1) = 0.1381966011250105151795413165634361882280; tetPointsHost(8,2) = 0.5854101966249684544613760503096914353161; auto tetPoints = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetPointsHost); Kokkos::deep_copy(tetPoints, tetPointsHost); // Dimensions for the output arrays: const auto numFields = tetBasis.getCardinality(); const auto numNodes = tetNodes.dimension(0); const auto spaceDim = tetBasis.getBaseCellTopology().getDimension(); // Check VALUE of basis functions at nodes: resize vals to rank-2 container:\n"; { *outStream << " check VALUE of basis functions at nodes\n"; DynRankView vals = DynRankView("vals", numFields, numNodes); tetBasis.getValues(vals, tetNodes, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i=0;i<numFields;++i) { for (auto j=0;j<numNodes;++j) { const auto l = i + j * numFields; if (std::abs(vals_host(i,j) - nodalBasisValues[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " "; *outStream << "} computed value: " << vals_host(i,j) << " but reference value: " << nodalBasisValues[l] << "\n"; } } } } const auto numPoints = tetPoints.dimension(0); // Check VALUE of basis functions at points: resize vals to rank-2 container:\n"; { *outStream << " check VALUE of basis functions at points\n"; DynRankView vals = DynRankView("vals", numFields, numPoints); tetBasis.getValues(vals, tetPoints, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i=0;i<numFields;++i) { for (auto j=0;j<numPoints;++j) { const auto l = i + j * numFields; if (std::abs(vals_host(i,j) - pointBasisValues[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " "; *outStream << "} computed value: " << vals_host(i,j) << " but reference value: " << pointBasisValues[l] << "\n"; } } } } // Check VALUE of basis functions at random points: resize vals to rank-2 container:\n"; { *outStream << " check VALUE of basis functions at random points\n"; const auto numRandomPoints = 16384; DynRankViewHost tetRandomPointsHost = DynRankViewHost("tetRandomPointsHost", numRandomPoints, 3); { ordinal_type point = 0; std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> dis(0, 1); while (point < numRandomPoints) { const ValueType r = dis(gen), s = dis(gen), t = dis(gen); if (r + s + t > 1.0) { // do nothing } else { tetRandomPointsHost(point, 0) = r; tetRandomPointsHost(point, 1) = s; tetRandomPointsHost(point, 2) = t; ++point; } } } auto tetRandomPoints = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetRandomPointsHost); Kokkos::deep_copy(tetRandomPoints, tetRandomPointsHost); DynRankView vals = DynRankView("vals", numFields, numRandomPoints); tetBasis.getValues(vals, tetRandomPoints, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto j=0;j<numRandomPoints;++j) { ValueType sum = 0.0; for (auto i=0;i<numFields;++i) sum += vals_host(i,j); if (std::abs(sum - 1.0) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Just indicate something bad happened *outStream << " Composite tet basis functions"; *outStream << " are not summing to 1.0\n"; *outStream << " sum : " << sum << "\n"; } } } // Check GRAD of basis functions at points: resize vals to rank-3 container:\n"; { DynRankView vals = DynRankView("vals", numFields, numPoints, spaceDim); tetBasis.getValues(vals, tetPoints, OPERATOR_GRAD); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i=0;i<numFields;++i) { for (auto j=0;j<numPoints;++j) { for (auto k=0;k<spaceDim;++k) { const auto l = k + i * spaceDim + j * spaceDim * numFields; if (std::abs(vals_host(i,j,k) - pointBasisGrads[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed grad component: " << vals_host(i,j,k) << " but reference grad component: " << pointBasisGrads[l] << "\n"; } } } } } } catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; } if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
int HGRAD_TET_C2_FEM_Test01(const bool verbose) { Teuchos::RCP<std::ostream> 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); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "\n" << "===============================================================================\n" << "| |\n" << "| Unit Test (Basis_HGRAD_TET_C2_FEM) |\n" << "| |\n" << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" << "| 2) Basis values for VALUE, GRAD, and Dk operators |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]), |\n" << "| Denis Ridzal ([email protected]), |\n" << "| Kara Peterson ([email protected]). |\n" << "| Kyungjoo Kim ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; typedef Kokkos::DynRankView<ValueType,HostSpaceType> DynRankViewHost; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) const ValueType tol = tolerence(); int errorFlag = 0; // for virtual function, value and point types are declared in the class typedef ValueType outputValueType; typedef ValueType pointValueType; Basis_HGRAD_TET_C2_FEM<DeviceSpaceType,outputValueType,pointValueType> tetBasis; *outStream << "\n" << "===============================================================================\n" << "| TEST 1: Basis creation, exception testing |\n" << "===============================================================================\n"; try{ ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG DynRankView ConstructWithLabel(tetNodes, 10, 3); const auto numFields = tetBasis.getCardinality(); const auto numPoints = tetNodes.dimension(0); const auto spaceDim = tetBasis.getBaseCellTopology().getDimension(); DynRankView ConstructWithLabel(vals, numFields, numPoints); DynRankView ConstructWithLabel(vals_vec, numFields, numPoints, 4); { // exception #1: CURL cannot be applied to scalar functions // resize vals to rank-3 container with dimensions (num. points, num. basis functions, arbitrary) INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals_vec, tetNodes, OPERATOR_CURL) ); } { // exception #2: DIV cannot be applied to scalar functions // resize vals to rank-2 container with dimensions (num. points, num. basis functions) INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, tetNodes, OPERATOR_DIV) ); } // Exceptions 3-7: all bf tags/bf Ids below are wrong and should cause getDofOrdinal() and // getDofTag() to access invalid array elements thereby causing bounds check exception { // exception #3 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(3,0,0) ); // exception #4 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(1,1,1) ); // exception #5 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(0,4,0) ); // exception #6 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofTag(10) ); // exception #7 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofTag(-1) ); } // Exceptions 8-18 test exception handling with incorrectly dimensioned input/output arrays { // exception #8: input points array must be of rank-2 DynRankView ConstructWithLabel(badPoints1, 4, 5, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, badPoints1, OPERATOR_VALUE) ); } { // exception #9 dimension 1 in the input point array must equal space dimension of the cell DynRankView ConstructWithLabel(badPoints2, 4, spaceDim - 1); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, badPoints2, OPERATOR_VALUE) ); } { // exception #10 output values must be of rank-2 for OPERATOR_VALUE DynRankView ConstructWithLabel(badVals1, 4, 3, 1); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals1, tetNodes, OPERATOR_VALUE) ); } { // exception #11 output values must be of rank-3 for OPERATOR_GRAD DynRankView ConstructWithLabel(badVals2, 4, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals2, tetNodes, OPERATOR_GRAD) ); // exception #12 output values must be of rank-3 for OPERATOR_D1 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals2, tetNodes, OPERATOR_D1) ); // exception #13 output values must be of rank-3 for OPERATOR_D2 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals2, tetNodes, OPERATOR_D2) ); } { // exception #14 incorrect 0th dimension of output array (must equal number of basis functions) DynRankView ConstructWithLabel(badVals3, numFields + 1, numPoints); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals3, tetNodes, OPERATOR_VALUE) ); } { // exception #15 incorrect 1st dimension of output array (must equal number of points) DynRankView ConstructWithLabel(badVals4, numFields, numPoints + 1); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals4, tetNodes, OPERATOR_VALUE) ); } { // exception #16: incorrect 2nd dimension of output array (must equal the space dimension) DynRankView ConstructWithLabel(badVals5, numFields, numPoints, spaceDim + 1); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals5, tetNodes, OPERATOR_GRAD) ); } { // exception #17: incorrect 2nd dimension of output array (must equal D2 cardinality in 2D) DynRankView ConstructWithLabel(badVals6, numFields, numPoints, 40); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals6, tetNodes, OPERATOR_D1) ); // exception #18: incorrect 2nd dimension of output array (must equal D3 cardinality in 2D) INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals6, tetNodes, OPERATOR_D2) ); } #endif // Check if number of thrown exceptions matches the one we expect if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << nthrow << ")\n"; } } catch (std::logic_error err) { *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n"; *outStream << err.what() << '\n'; *outStream << "-------------------------------------------------------------------------------" << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n" << "===============================================================================\n"; try{ const auto numFields = tetBasis.getCardinality(); const auto allTags = tetBasis.getAllDofTags(); // Loop over all tags, lookup the associated dof enumeration and then lookup the tag again const auto dofTagSize = allTags.dimension(0); for (auto i = 0; i < dofTagSize; ++i) { const auto bfOrd = tetBasis.getDofOrdinal(allTags(i,0), allTags(i,1), allTags(i,2)); const auto myTag = tetBasis.getDofTag(bfOrd); if( !( (myTag(0) == allTags(i,0)) && (myTag(1) == allTags(i,1)) && (myTag(2) == allTags(i,2)) && (myTag(3) == allTags(i,3)) ) ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofOrdinal( {" << allTags(i,0) << ", " << allTags(i,1) << ", " << allTags(i,2) << ", " << allTags(i,3) << "}) = " << bfOrd <<" but \n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "}\n"; } } // Now do the same but loop over basis functions for( auto bfOrd = 0; bfOrd < numFields; bfOrd++) { const auto myTag = tetBasis.getDofTag(bfOrd); const auto myBfOrd = tetBasis.getDofOrdinal(myTag(0), myTag(1), myTag(2)); if( bfOrd != myBfOrd) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} but getDofOrdinal({" << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} ) = " << myBfOrd << "\n"; } } } catch (std::logic_error err){ *outStream << err.what() << "\n\n"; errorFlag = -1000; }; *outStream << "\n" << "===============================================================================\n" << "| TEST 3: correctness of basis function values |\n" << "===============================================================================\n"; outStream -> precision(20); // VALUE: in (F,P) format const ValueType basisValues[] = { 1.00000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00000, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 1.00000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00000, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 1.00000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00000, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 1.00000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.00000, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 1.00000 }; // GRAD and D1: in (F,P,D) format const ValueType basisGrads[] = { -3.00000, -3.00000, -3.00000, 1.00000, 1.00000, 1.00000, 1.00000, \ 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, -1.00000, -1.00000, \ -1.00000, 1.00000, 1.00000, 1.00000, -1.00000, -1.00000, -1.00000, \ -1.00000, -1.00000, -1.00000, 1.00000, 1.00000, 1.00000, 1.00000, \ 1.00000, 1.00000, -1.00000, 0, 0, 3.00000, 0, 0, -1.00000, 0, 0, \ -1.00000, 0, 0, 1.00000, 0, 0, 1.00000, 0, 0, -1.00000, 0, 0, \ -1.00000, 0, 0, 1.00000, 0, 0, -1.00000, 0, 0, 0, -1.00000, 0, 0, \ -1.00000, 0, 0, 3.00000, 0, 0, -1.00000, 0, 0, -1.00000, 0, 0, \ 1.00000, 0, 0, 1.00000, 0, 0, -1.00000, 0, 0, -1.00000, 0, 0, \ 1.00000, 0, 0, 0, -1.00000, 0, 0, -1.00000, 0, 0, -1.00000, 0, 0, \ 3.00000, 0, 0, -1.00000, 0, 0, -1.00000, 0, 0, -1.00000, 0, 0, \ 1.00000, 0, 0, 1.00000, 0, 0, 1.00000, 4.00000, 0, 0, -4.00000, \ -4.00000, -4.00000, 0, 0, 0, 0, 0, 0, 0, -2.00000, -2.00000, \ -2.00000, -2.00000, -2.00000, 2.00000, 0, 0, 2.00000, 0, 0, -2.00000, \ -2.00000, -2.00000, 0, 0, 0, 0, 0, 0, 0, 4.00000, 0, 4.00000, 0, 0, \ 0, 0, 0, 0, 2.00000, 0, 2.00000, 2.00000, 0, 2.00000, 0, 0, 0, 0, 0, \ 0, 2.00000, 0, 2.00000, 0, 0, 0, 4.00000, 0, 0, 0, 0, -4.00000, \ -4.00000, -4.00000, 0, 0, 0, 0, 2.00000, 0, -2.00000, -2.00000, \ -2.00000, -2.00000, 0, -2.00000, 0, 2.00000, 0, 0, 0, 0, -2.00000, \ -2.00000, -2.00000, 0, 0, 4.00000, 0, 0, 0, 0, 0, 0, -4.00000, \ -4.00000, -4.00000, 0, 0, 2.00000, 0, 0, 0, 0, 0, 2.00000, -2.00000, \ -2.00000, 0, -2.00000, -2.00000, -2.00000, -2.00000, -2.00000, \ -2.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 4.00000, 0, 0, 0, 0, \ 2.00000, 0, 0, 2.00000, 0, 0, 0, 2.00000, 0, 0, 2.00000, 0, 2.00000, \ 2.00000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.00000, 0, 4.00000, 0, 0, 0, \ 0, 0, 0, 2.00000, 0, 0, 2.00000, 0, 2.00000, 0, 0, 2.00000, 0, 0, \ 2.00000, 2.00000}; // D2 values in (F,P, Dk) format const ValueType basisD2[]={ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, \ 4.00000, 4.00000, 4.00000, 4.00000, 4.00000, 0, 0, 0, 0, 0, 4.00000, \ 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, \ 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, \ 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, \ 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, \ 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, \ 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, \ 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 0, 0, 4.00000, \ 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, \ 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, \ 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, \ 0, 0, 4.00000, -8.00000, -4.00000, -4.00000, 0, 0, 0, -8.00000, \ -4.00000, -4.00000, 0, 0, 0, -8.00000, -4.00000, -4.00000, 0, 0, 0, \ -8.00000, -4.00000, -4.00000, 0, 0, 0, -8.00000, -4.00000, -4.00000, \ 0, 0, 0, -8.00000, -4.00000, -4.00000, 0, 0, 0, -8.00000, -4.00000, \ -4.00000, 0, 0, 0, -8.00000, -4.00000, -4.00000, 0, 0, 0, -8.00000, \ -4.00000, -4.00000, 0, 0, 0, -8.00000, -4.00000, -4.00000, 0, 0, 0, \ 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, \ 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, \ 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, \ 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, -4.00000, 0, -8.00000, -4.00000, \ 0, 0, -4.00000, 0, -8.00000, -4.00000, 0, 0, -4.00000, 0, -8.00000, \ -4.00000, 0, 0, -4.00000, 0, -8.00000, -4.00000, 0, 0, -4.00000, 0, \ -8.00000, -4.00000, 0, 0, -4.00000, 0, -8.00000, -4.00000, 0, 0, \ -4.00000, 0, -8.00000, -4.00000, 0, 0, -4.00000, 0, -8.00000, \ -4.00000, 0, 0, -4.00000, 0, -8.00000, -4.00000, 0, 0, -4.00000, 0, \ -8.00000, -4.00000, 0, 0, 0, -4.00000, 0, -4.00000, -8.00000, 0, 0, \ -4.00000, 0, -4.00000, -8.00000, 0, 0, -4.00000, 0, -4.00000, \ -8.00000, 0, 0, -4.00000, 0, -4.00000, -8.00000, 0, 0, -4.00000, 0, \ -4.00000, -8.00000, 0, 0, -4.00000, 0, -4.00000, -8.00000, 0, 0, \ -4.00000, 0, -4.00000, -8.00000, 0, 0, -4.00000, 0, -4.00000, \ -8.00000, 0, 0, -4.00000, 0, -4.00000, -8.00000, 0, 0, -4.00000, 0, \ -4.00000, -8.00000, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, \ 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, \ 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, \ 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 0, 0, \ 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, \ 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, \ 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, 0, 0, 0, 4.00000, 0, 0, \ 0, 0, 0, 4.00000, 0 }; try{ ordinal_type nthrow = 0, ncatch = 0; DynRankViewHost ConstructWithLabel(tetNodesHost, 10, 3); tetNodesHost(0,0) = 0.0; tetNodesHost(0,1) = 0.0; tetNodesHost(0,2) = 0.0; tetNodesHost(1,0) = 1.0; tetNodesHost(1,1) = 0.0; tetNodesHost(1,2) = 0.0; tetNodesHost(2,0) = 0.0; tetNodesHost(2,1) = 1.0; tetNodesHost(2,2) = 0.0; tetNodesHost(3,0) = 0.0; tetNodesHost(3,1) = 0.0; tetNodesHost(3,2) = 1.0; tetNodesHost(4,0) = 0.5; tetNodesHost(4,1) = 0.0; tetNodesHost(4,2) = 0.0; tetNodesHost(5,0) = 0.5; tetNodesHost(5,1) = 0.5; tetNodesHost(5,2) = 0.0; tetNodesHost(6,0) = 0.0; tetNodesHost(6,1) = 0.5; tetNodesHost(6,2) = 0.0; tetNodesHost(7,0) = 0.0; tetNodesHost(7,1) = 0.0; tetNodesHost(7,2) = 0.5; tetNodesHost(8,0) = 0.5; tetNodesHost(8,1) = 0.0; tetNodesHost(8,2) = 0.5; tetNodesHost(9,0) = 0.0; tetNodesHost(9,1) = 0.5; tetNodesHost(9,2) = 0.5; auto tetNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetNodesHost); Kokkos::deep_copy(tetNodes, tetNodesHost); // Dimensions for the output arrays: const auto numFields = tetBasis.getCardinality(); const auto numPoints = tetNodes.dimension(0); const auto spaceDim = tetBasis.getBaseCellTopology().getDimension(); const auto D2cardinality = getDkCardinality(OPERATOR_D2, spaceDim); { // Check VALUE of basis functions: resize vals to rank-2 container: DynRankView ConstructWithLabel(vals, numFields, numPoints); tetBasis.getValues(vals, tetNodes, OPERATOR_VALUE); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i = 0; i < numFields; ++i) { for (auto j = 0; j < numPoints; ++j) { const auto l = i + j * numFields; if (std::abs(vals_host(i,j) - basisValues[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " "; *outStream << "} computed value: " << vals_host(i,j) << " but reference value: " << basisValues[l] << "\n"; } } } } { // Check GRAD of basis function: resize vals to rank-3 container DynRankView ConstructWithLabel(vals, numFields, numPoints, spaceDim); tetBasis.getValues(vals, tetNodes, OPERATOR_GRAD); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i = 0; i < numFields; ++i) { for (auto j = 0; j < numPoints; ++j) { for (auto k = 0; k < spaceDim; ++k) { // basisGrads is (F,P,D), compute offset: const auto l = k + j * spaceDim + i * spaceDim * numPoints; if (std::abs(vals_host(i,j,k) - basisGrads[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed grad component: " << vals_host(i,j,k) << " but reference grad component: " << basisGrads[l] << "\n"; } } } } // Check D1 of basis function (do not resize vals because it has the correct size: D1 = GRAD) tetBasis.getValues(vals, tetNodes, OPERATOR_D1); Kokkos::deep_copy(vals_host, vals); for (auto i = 0; i < numFields; ++i) { for (auto j = 0; j < numPoints; ++j) { for (auto k = 0; k < spaceDim; ++k) { // basisGrads is (F,P,D), compute offset: const auto l = k + j * spaceDim + i * spaceDim * numPoints; if (std::abs(vals_host(i,j,k) - basisGrads[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed D1 component: " << vals_host(i,j,k) << " but reference D1 component: " << basisGrads[l] << "\n"; } } } } } { // Check D2 of basis function DynRankView ConstructWithLabel(vals, numFields, numPoints, D2cardinality); tetBasis.getValues(vals, tetNodes, OPERATOR_D2); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i = 0; i < numFields; ++i) { for (auto j = 0; j < numPoints; ++j) { for (auto k = 0; k < D2cardinality; ++k) { // basisD2 is (F,P,Dk), compute offset: const auto l = k + j * D2cardinality + i * D2cardinality * numPoints; if (std::abs(vals_host(i,j,k) - basisD2[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed D2 component: " << vals_host(i,j,k) << " but reference D2 component: " << basisD2[l] << "\n"; } } } } } { // Check all higher derivatives - must be zero. const EOperator ops[] = { OPERATOR_D3, OPERATOR_D4, OPERATOR_D5, OPERATOR_D6, OPERATOR_D7, OPERATOR_D8, OPERATOR_D9, OPERATOR_D10, OPERATOR_MAX }; for (auto h=0;ops[h]!=OPERATOR_MAX;++h) { const auto op = ops[h]; // The last dimension is the number of kth derivatives and needs to be resized for every Dk const auto DkCardin = getDkCardinality(op, spaceDim); DynRankView vals("vals", numFields, numPoints, DkCardin); tetBasis.getValues(vals, tetNodes, op); auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (auto i1 = 0; i1 < numFields; ++i1) for (auto i2 = 0; i2 < numPoints; ++i2) for (auto i3 = 0; i3 < DkCardin; ++i3) { if (std::abs(vals_host(i1,i2,i3)) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Get the multi-index of the value where the error is and the operator order int ord = Intrepid2::getOperatorOrder(op); *outStream << " At multi-index { "<<i1<<" "<<i2 <<" "<<i3; *outStream << "} computed D"<< ord <<" component: " << vals_host(i1,i2,i3) << " but reference D" << ord << " component: 0 \n"; } } } } } catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; }; if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
int HDIV_TET_I1_FEM_Test01(const bool verbose) { Teuchos::RCP<std::ostream> 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); typedef typename Kokkos::Impl::is_space<DeviceSpaceType>::host_mirror_space::execution_space HostSpaceType ; *outStream << "DeviceSpace:: "; DeviceSpaceType::print_configuration(*outStream, false); *outStream << "HostSpace:: "; HostSpaceType::print_configuration(*outStream, false); *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (Basis_HDIV_TET_I1_FEM) |\n" << "| |\n" << "| 1) Conversion of Dof tags into Dof ordinals and back |\n" << "| 2) Basis values for VALUE and HDIV operators |\n" << "| |\n" << "| Questions? Contact Pavel Bochev ([email protected]), |\n" << "| Denis Ridzal ([email protected]), |\n" << "| Kara Peterson ([email protected]). |\n" << "| |\n" << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" << "| Trilinos website: http://trilinos.sandia.gov |\n" << "| |\n" << "===============================================================================\n"; typedef Kokkos::DynRankView<ValueType,DeviceSpaceType> DynRankView; typedef Kokkos::DynRankView<ValueType,HostSpaceType> DynRankViewHost; #define ConstructWithLabel(obj, ...) obj(#obj, __VA_ARGS__) const ValueType tol = tolerence(); int errorFlag = 0; // for virtual function, value and point types are declared in the class typedef ValueType outputValueType; typedef ValueType pointValueType; Basis_HDIV_TET_I1_FEM<DeviceSpaceType,outputValueType,pointValueType> tetBasis; try { ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG // Define array containing the 4 vertices of the reference TET and its center. DynRankView ConstructWithLabel(tetNodes, 10, 3); const auto numFields = tetBasis.getCardinality(); const auto numPoints = tetNodes.dimension(0); const auto spaceDim = tetBasis.getBaseCellTopology().getDimension(); DynRankView vals("vals", numFields, numPoints, spaceDim); // exception #1: GRAD cannot be applied to HDIV functions INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, tetNodes, OPERATOR_GRAD)); // exception #2: CURL cannot be applied to HDIV functions INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, tetNodes, OPERATOR_CURL)); // Exceptions 3-7: all bf tags/bf Ids below are wrong and should cause getDofOrdinal() and // getDofTag() to access invalid array elements thereby causing bounds check exception // exception #3 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(3,0,0)); // exception #4 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(1,1,1)); // exception #5 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofOrdinal(0,4,1)); // exception #6 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofTag(numFields)); // exception #7 INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofTag(-1)); // Exceptions 8-15 test exception handling with incorrectly dimensioned input/output arrays // exception #8: input points array must be of rank-2 DynRankView ConstructWithLabel(badPoints1, 4, 5, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, badPoints1, OPERATOR_VALUE)); // exception #9 dimension 1 in the input point array must equal space dimension of the cell DynRankView ConstructWithLabel(badPoints2, 4, 2); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(vals, badPoints2, OPERATOR_VALUE)); // exception #10 output values must be of rank-3 for OPERATOR_VALUE DynRankView ConstructWithLabel(badVals1, 4, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals1, tetNodes, OPERATOR_VALUE)); // exception #11 output values must be of rank-2 for OPERATOR_DIV DynRankView ConstructWithLabel(badVals2, 4, 3, 1); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals2, tetNodes, OPERATOR_VALUE)); // exception #12 incorrect 0th dimension of output array (must equal number of basis functions) DynRankView ConstructWithLabel(badVals3, tetBasis.getCardinality() + 1, tetNodes.dimension(0), 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals3, tetNodes, OPERATOR_VALUE)); // exception #13 incorrect 0th dimension of output array (must equal number of basis functions) DynRankView ConstructWithLabel(badVals4, tetBasis.getCardinality() + 1, tetNodes.dimension(0)); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals4, tetNodes, OPERATOR_DIV)); // exception #14 incorrect 1st dimension of output array (must equal number of points) DynRankView ConstructWithLabel(badVals5, tetBasis.getCardinality(), tetNodes.dimension(0) + 1, 3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals5, tetNodes, OPERATOR_VALUE)); // exception #15 incorrect 1st dimension of output array (must equal number of points) DynRankView ConstructWithLabel(badVals6, tetBasis.getCardinality(), tetNodes.dimension(0) + 1); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals6, tetNodes, OPERATOR_DIV)); // exception #16: incorrect 2nd dimension of output array (must equal the space dimension) DynRankView ConstructWithLabel(badVals7, tetBasis.getCardinality(), tetNodes.dimension(0), 4); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getValues(badVals7, tetNodes, OPERATOR_VALUE)); #endif } catch (std::logic_error err) { *outStream << "UNEXPECTED ERROR !!! ----------------------------------------------------------\n"; *outStream << err.what() << '\n'; *outStream << "-------------------------------------------------------------------------------" << "\n\n"; errorFlag = -1000; } *outStream << "\n" << "===============================================================================\n" << "| TEST 2: correctness of tag to enum and enum to tag lookups |\n" << "===============================================================================\n"; try { const auto allTags = tetBasis.getAllDofTags(); // Loop over all tags, lookup the associated dof enumeration and then lookup the tag again const auto dofTagSize = allTags.dimension(0); for (unsigned i = 0; i < dofTagSize; i++) { int bfOrd = tetBasis.getDofOrdinal(allTags(i,0), allTags(i,1), allTags(i,2)); auto myTag = tetBasis.getDofTag(bfOrd); if( !( (myTag(0) == allTags(i,0)) && (myTag(1) == allTags(i,1)) && (myTag(2) == allTags(i,2)) && (myTag(3) == allTags(i,3)) ) ) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofOrdinal( {" << allTags(i,0) << ", " << allTags(i,1) << ", " << allTags(i,2) << ", " << allTags(i,3) << "}) = " << bfOrd <<" but \n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "}\n"; } } // Now do the same but loop over basis functions for( int bfOrd = 0; bfOrd < tetBasis.getCardinality(); bfOrd++) { auto myTag = tetBasis.getDofTag(bfOrd); int myBfOrd = tetBasis.getDofOrdinal(myTag(0), myTag(1), myTag(2)); if( bfOrd != myBfOrd) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << " getDofTag(" << bfOrd << ") = { " << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} but getDofOrdinal({" << myTag(0) << ", " << myTag(1) << ", " << myTag(2) << ", " << myTag(3) << "} ) = " << myBfOrd << "\n"; } } } catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; } *outStream << "\n" << "===============================================================================\n" << "| TEST 3: correctness of basis function values |\n" << "===============================================================================\n"; outStream -> precision(20); // VALUE: Correct basis values in (P,F,D) format: each row gives the 4x3 correct basis set values // at an evaluation point. Note that getValues returns results as an (F,P,D) array. double basisValues[] = { // 4 vertices 0.,-2.0,0., 0.,0.,0., -2.0,0.,0., 0.,0.,-2.0, 2.0,-2.0,0., 2.0,0.,0., 0.,0.,0., 2.0,0.,-2.0, 0.,0.,0., 0.,2.0,0., -2.0,2.0,0., 0,2.0,-2.0, 0.,-2.0,2.0, 0.,0.,2.0, -2.0,0.,2.0, 0.,0.,0., // 6 edge midpoints 1.0,-2.0,0., 1.0,0.,0., -1.0,0.,0., 1.0,0.,-2.0, 1.0,-1.0,0., 1.0,1.0,0., -1.0,1.0,0., 1.0,1.0,-2.0, 0.,-1.0,0., 0.,1.0,0., -2.0,1.0,0., 0.,1.0,-2.0, 0.,-2.0,1.0, 0.,0.,1.0, -2.0,0.,1.0, 0.,0.,-1.0, 1.0,-2.0,1.0, 1.0,0.,1.0, -1.0,0.,1.0, 1.0,0.,-1.0, 0.,-1.0,1.0, 0.,1.0,1.0, -2.0,1.0,1.0, 0.,1.0,-1.0 // bf0 bf1 bf2 bf3 }; // DIV: each row gives the 4 correct values of the divergence of the 4 basis functions double basisDivs[] = { // 4 vertices 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, // 6 edge midpoints 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0 }; try { // Define array containing the 4 vertices of the reference TET and its 6 edge midpoints. DynRankViewHost ConstructWithLabel(tetNodesHost, 10, 3); tetNodesHost(0,0) = 0.0; tetNodesHost(0,1) = 0.0; tetNodesHost(0,2) = 0.0; tetNodesHost(1,0) = 1.0; tetNodesHost(1,1) = 0.0; tetNodesHost(1,2) = 0.0; tetNodesHost(2,0) = 0.0; tetNodesHost(2,1) = 1.0; tetNodesHost(2,2) = 0.0; tetNodesHost(3,0) = 0.0; tetNodesHost(3,1) = 0.0; tetNodesHost(3,2) = 1.0; tetNodesHost(4,0) = 0.5; tetNodesHost(4,1) = 0.0; tetNodesHost(4,2) = 0.0; tetNodesHost(5,0) = 0.5; tetNodesHost(5,1) = 0.5; tetNodesHost(5,2) = 0.0; tetNodesHost(6,0) = 0.0; tetNodesHost(6,1) = 0.5; tetNodesHost(6,2) = 0.0; tetNodesHost(7,0) = 0.0; tetNodesHost(7,1) = 0.0; tetNodesHost(7,2) = 0.5; tetNodesHost(8,0) = 0.5; tetNodesHost(8,1) = 0.0; tetNodesHost(8,2) = 0.5; tetNodesHost(9,0) = 0.0; tetNodesHost(9,1) = 0.5; tetNodesHost(9,2) = 0.5; const auto tetNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), tetNodesHost); Kokkos::deep_copy(tetNodes, tetNodesHost); // Dimensions for the output arrays: const auto numFields = tetBasis.getCardinality(); const auto numPoints = tetNodes.dimension(0); const auto spaceDim = tetBasis.getBaseCellTopology().getDimension(); { // Check VALUE of basis functions: DynRankView ConstructWithLabel(vals, numFields, numPoints, spaceDim); tetBasis.getValues(vals, tetNodes, OPERATOR_VALUE); const auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (int i = 0; i < numFields; i++) { for (size_type j = 0; j < numPoints; j++) { for (size_type k = 0; k < spaceDim; k++) { // basisValues is (P,F,D) array so its multiindex is (j,i,k) and not (i,j,k)! int l = k + i * spaceDim + j * spaceDim * numFields; if (std::abs(vals_host(i,j,k) - basisValues[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At (Field,Point,Dim) multi-index { "; *outStream << i << " ";*outStream << j << " ";*outStream << k << " "; *outStream << "} computed value: " << vals_host(i,j,k) << " but reference value: " << basisValues[l] << "\n"; } } } } } { // Check DIV of basis function: DynRankView ConstructWithLabel(vals, numFields, numPoints); tetBasis.getValues(vals, tetNodes, OPERATOR_DIV); const auto vals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), vals); Kokkos::deep_copy(vals_host, vals); for (int i = 0; i < numFields; i++) { for (size_type j = 0; j < numPoints; j++) { int l = i + j * numFields; if (std::abs(vals_host(i,j) - basisDivs[l]) > tol) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; // Output the multi-index of the value where the error is: *outStream << " At multi-index { "; *outStream << i << " ";*outStream << j << " "; *outStream << "} computed divergence component: " << vals_host(i,j) << " but reference divergence component: " << basisDivs[l] << "\n"; } } } } } catch (std::logic_error err) { *outStream << err.what() << "\n\n"; errorFlag = -1000; } *outStream << "\n" << "===============================================================================\n" << "| TEST 4: correctness of DoF locations |\n" << "===============================================================================\n"; try { const auto numFields = tetBasis.getCardinality(); const auto spaceDim = tetBasis.getBaseCellTopology().getDimension(); // Check exceptions. ordinal_type nthrow = 0, ncatch = 0; #ifdef HAVE_INTREPID2_DEBUG { DynRankView ConstructWithLabel(badVals, 1,2,3); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofCoords(badVals)); } { DynRankView ConstructWithLabel(badVals, 3,2); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofCoords(badVals)); } { DynRankView ConstructWithLabel(badVals, 4,2); INTREPID2_TEST_ERROR_EXPECTED( tetBasis.getDofCoords(badVals)); } #endif if (nthrow != ncatch) { errorFlag++; *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n"; *outStream << "# of catch ("<< ncatch << ") is different from # of throw (" << ncatch << ")\n"; } DynRankView ConstructWithLabel(bvals, numFields, numFields, spaceDim); DynRankView ConstructWithLabel(cvals, numFields, spaceDim); // Check mathematical correctness. tetBasis.getDofCoords(cvals); tetBasis.getValues(bvals, cvals, OPERATOR_VALUE); // Check mathematical correctness DynRankViewHost ConstructWithLabel(normals, numFields,spaceDim); // normals at each point basis point normals(0,0) = 0.0; normals(0,1) = -0.5; normals(0,2) = 0.0; normals(1,0) = 0.5; normals(1,1) = 0.5; normals(1,2) = 0.5; normals(2,0) = -0.5; normals(2,1) = 0.0; normals(2,2) = 0.0; normals(3,0) = 0.0; normals(3,1) = 0.0; normals(3,2) = -0.5; auto cvals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), cvals); Kokkos::deep_copy(cvals_host, cvals); auto bvals_host = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), bvals); Kokkos::deep_copy(bvals_host, bvals); for (ordinal_type i=0;i<numFields;++i) { for (ordinal_type j=0;j<numFields;++j) { ValueType normal = 0.0; for(size_type d=0;d<spaceDim;++d) { normal += bvals_host(i,j,d)*normals(j,d); } const ValueType expected_normal = (i == j); if (std::abs(normal - expected_normal) > tol || std::isnan(normal)) { errorFlag++; std::stringstream ss; ss << "\nNormal component of basis function " << i << " at (" << cvals_host(j,0) << ", " << cvals_host(j,1)<< ", " << cvals_host(j,2) << ") is " << normal << " but should be " << expected_normal << "\n"; *outStream << ss.str(); } } } } catch (std::logic_error err){ *outStream << err.what() << "\n\n"; errorFlag = -1000; }; if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }