int Orientation_Test05(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"; *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (OrientationTools, getModifiedHcurl_I1_Basis) |\n" << "| |\n" << "===============================================================================\n"; int errorFlag = 0; const double tol = tolerence(); typedef OrientationTools<DeviceSpaceType> ots; try { { *outStream << "\n -- Testing Quadrilateral \n\n"; Basis_HCURL_QUAD_I1_FEM<DeviceSpaceType> cellBasis; const auto cellTopo = cellBasis.getBaseCellTopology(); const ordinal_type ndofBasis = cellBasis.getCardinality(); // // 9 12 13 16 // 4 3 11 15 // 5 2 8 14 // 1 6 7 10 ordinal_type refMesh[9][4] = { { 1, 6, 2, 5 }, { 6, 7, 8, 2 }, { 7,10,14, 8 }, { 5, 2, 3, 4 }, { 2, 8,11, 3 }, { 8,14,15,11 }, { 4, 3,12, 9 }, { 3,11,13,12 }, {11,15,16,13 } }; const ordinal_type numCells = 9, numVerts = 4, numEdges = 4; // view to import refMesh from host Kokkos::DynRankView<ordinal_type,Kokkos::LayoutRight,HostSpaceType> elemNodesHost(&refMesh[0][0], numCells, numVerts); auto elemNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), elemNodesHost); Kokkos::deep_copy(elemNodes, elemNodesHost); // compute orientations for cells (one time computation) Kokkos::DynRankView<Orientation,DeviceSpaceType> elemOrts("elemOrts", numCells); ots::getOrientation(elemOrts, elemNodes, cellTopo); auto elemOrtsHost = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), elemOrts); Kokkos::deep_copy(elemOrtsHost, elemOrts); // cell specific modified basis Kokkos::DynRankView<double,DeviceSpaceType> outValues("outValues", numCells, ndofBasis); Kokkos::DynRankView<double,DeviceSpaceType> refValues("refValues", numCells, ndofBasis); auto refValuesHost = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), refValues); for (auto cell=0;cell<numCells;++cell) for (auto bf=0;bf<ndofBasis;++bf) refValuesHost(cell, bf) = bf; Kokkos::deep_copy(refValues, refValuesHost); // modify refValues accounting for orientations ots::modifyBasisByOrientation(outValues, refValues, elemOrts, &cellBasis); auto outValuesHost = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), outValues); Kokkos::deep_copy(outValuesHost, outValues); for (auto cell=0;cell<numCells;++cell) { int flag = 0 ; std::stringstream s1, s2; ordinal_type orts[numEdges]; elemOrtsHost(cell).getEdgeOrientation(orts, numEdges); const double ortVal[2] = { 1.0 , - 1.0 }; s1 << " :: edge(0000) = " ; s2 << " :: edge(" << orts[0] << orts[1] << orts[2] << orts[3] << ") = "; for (auto edgeId=0;edgeId<numEdges;++edgeId) { const auto ndof = cellBasis.getDofTag(cellBasis.getDofOrdinal(1, edgeId, 0))(3); for (auto i=0;i<ndof;++i) { const auto refOrd = cellBasis.getDofOrdinal(1, edgeId, i); const auto outOrd = cellBasis.getDofOrdinal(1, edgeId, i); s1 << std::setw(4) << refValuesHost(cell, outOrd); s2 << std::setw(4) << outValuesHost(cell, outOrd); flag += (std::abs(ortVal[orts[edgeId]]*outValuesHost(cell, outOrd) - refValuesHost(cell, refOrd)) > tol); } s1 << " // "; s2 << " // "; } *outStream << "\n cell = " << cell << "\n" << " - refValues = " << s1.str() << "\n" << " - outValues = " << s2.str() << "\n"; if (flag) { *outStream << " ^^^^^^^^^^^^ FAILURE\n"; errorFlag += flag; } } ots::clearCoeffMatrix(); } } catch (std::exception err) { std::cout << " Exeption\n"; *outStream << err.what() << "\n\n"; errorFlag = -1000; } if (errorFlag != 0) std::cout << "End Result: TEST FAILED = " << errorFlag << "\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }
int OrientationToolsHexMesh(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"; *outStream << "===============================================================================\n" << "| |\n" << "| Unit Test (OrientationTools, Hex, getOrientation) |\n" << "| |\n" << "===============================================================================\n"; int errorFlag = 0; //const double tol = tolerence(); typedef OrientationTools<DeviceSpaceType> ots; try { { *outStream << "\n -- Testing Hexahedron \n\n"; ordinal_type refMesh[27][8] = { { 8 , 33 , 45 , 10 , 11 , 37 , 57 , 15 }, { 33 , 34 , 46 , 45 , 37 , 38 , 58 , 57 }, { 34 , 21 , 25 , 46 , 38 , 23 , 32 , 58 }, { 10 , 45 , 43 , 9 , 15 , 57 , 59 , 16 }, { 45 , 46 , 44 , 43 , 57 , 58 , 60 , 59 }, { 46 , 25 , 26 , 44 , 58 , 32 , 31 , 60 }, { 9 , 43 , 41 , 5 , 16 , 59 , 51 , 7 }, { 43 , 44 , 42 , 41 , 59 , 60 , 52 , 51 }, { 44 , 26 , 24 , 42 , 60 , 31 , 27 , 52 }, { 11 , 37 , 57 , 15 , 12 , 39 , 61 , 13 }, { 37 , 38 , 58 , 57 , 39 , 40 , 62 , 61 }, { 38 , 23 , 32 , 58 , 40 , 22 , 30 , 62 }, { 15 , 57 , 59 , 16 , 13 , 61 , 63 , 14 }, { 57 , 58 , 60 , 59 , 61 , 62 , 64 , 63 }, { 58 , 32 , 31 , 60 , 62 , 30 , 29 , 64 }, { 16 , 59 , 51 , 7 , 14 , 63 , 49 , 6 }, { 59 , 60 , 52 , 51 , 63 , 64 , 50 , 49 }, { 60 , 31 , 27 , 52 , 64 , 29 , 28 , 50 }, { 12 , 39 , 61 , 13 , 1 , 35 , 53 , 3 }, { 39 , 40 , 62 , 61 , 35 , 36 , 54 , 53 }, { 40 , 22 , 30 , 62 , 36 , 18 , 20 , 54 }, { 13 , 61 , 63 , 14 , 3 , 53 , 55 , 4 }, { 61 , 62 , 64 , 63 , 53 , 54 , 56 , 55 }, { 62 , 30 , 29 , 64 , 54 , 20 , 19 , 56 }, { 14 , 63 , 49 , 6 , 4 , 55 , 47 , 2 }, { 63 , 64 , 50 , 49 , 55 , 56 , 48 , 47 }, { 64 , 29 , 28 , 50 , 56 , 19 , 17 , 48 } }; //const ordinal_type refOrts[27][6]; const ordinal_type numCells = 27, numVerts = 8, numEdges = 12, numFaces = 6; const auto cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Hexahedron<8> >() ); // view to store orientation Kokkos::DynRankView<Orientation,DeviceSpaceType> elemOrts("elemOrts", numCells); // view to import refMesh from host Kokkos::DynRankView<ordinal_type,Kokkos::LayoutRight,HostSpaceType> elemNodesHost(&refMesh[0][0], numCells, numVerts); auto elemNodes = Kokkos::create_mirror_view(typename DeviceSpaceType::memory_space(), elemNodesHost); Kokkos::deep_copy(elemNodes, elemNodesHost); ots::getOrientation(elemOrts, elemNodes, cellTopo); // for comparison move data to host auto elemOrtsHost = Kokkos::create_mirror_view(typename HostSpaceType::memory_space(), elemOrts); for (auto cell=0;cell<numCells;++cell) { // decode edge orientations ordinal_type ortEdges[12], ortFaces[6]; elemOrtsHost(cell).getEdgeOrientation(ortEdges, numEdges); elemOrtsHost(cell).getFaceOrientation(ortFaces, numFaces); //int flag = 0; std::stringstream s1; //, s2; s1 << "edge "; for (auto edgeId=0;edgeId<numEdges;++edgeId) { s1 << ortEdges[edgeId] << " "; //s2 << refOrts[cell][edgeId] << " "; //flag += (orts[edgeId] != refOrts[cell][edgeId]); } s1 << "face "; for (auto faceId=0;faceId<numFaces;++faceId) { s1 << ortFaces[faceId] << " "; //s2 << refOrts[cell][edgeId] << " "; //flag += (orts[edgeId] != refOrts[cell][edgeId]); } *outStream << " cell id = " << std::setw(3) << cell << " orts = " << s1.str() //<< " :: ref = " << s2.str() << " \n"; // if (flag) { // errorFlag += flag; // *outStream << " ^^^^^^^^^^^^^^ FAILURE\n "; // } } } } catch (std::exception err) { std::cout << " Exeption\n"; *outStream << err.what() << "\n\n"; errorFlag = -1000; } if (errorFlag != 0) std::cout << "End Result: TEST FAILED = " << errorFlag << "\n"; else std::cout << "End Result: TEST PASSED\n"; // reset format state of std::cout std::cout.copyfmt(oldFormatState); return errorFlag; }