diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeHexMeshFactory.cpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeHexMeshFactory.cpp index 2fe7d75302cc..ce7b12f6e53e 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeHexMeshFactory.cpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeHexMeshFactory.cpp @@ -171,8 +171,10 @@ void CubeHexMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::Para } mesh.buildLocalElementIDs(); - if(buildSubcells_) { + if(createEdgeBlocks_) { mesh.buildLocalEdgeIDs(); + } + if(createFaceBlocks_) { mesh.buildLocalFaceIDs(); } @@ -181,8 +183,10 @@ void CubeHexMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::Para // now that edges are built, side and node sets can be added addSideSets(mesh); addNodeSets(mesh); - if(buildSubcells_) { + if(createEdgeBlocks_) { addEdgeBlocks(mesh); + } + if(createFaceBlocks_) { addFaceBlocks(mesh); } @@ -223,6 +227,25 @@ void CubeHexMeshFactory::setParameterList(const Teuchos::RCPget("Build Subcells"); + createEdgeBlocks_ = paramList->get("Create Edge Blocks"); + createFaceBlocks_ = paramList->get("Create Face Blocks"); + if (not buildSubcells_ && createEdgeBlocks_) { + Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout)); + out.setOutputToRootOnly(0); + out.setShowProcRank(true); + + out << "CubeHexMesh: NOT creating edge blocks because building sub cells disabled" << std::endl; + createEdgeBlocks_ = false; + } + if (not buildSubcells_ && createFaceBlocks_) { + Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout)); + out.setOutputToRootOnly(0); + out.setShowProcRank(true); + + out << "CubeHexMesh: NOT creating face blocks because building sub cells disabled" << std::endl; + createFaceBlocks_ = false; + } + // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); } @@ -260,6 +283,10 @@ Teuchos::RCP CubeHexMeshFactory::getValidParameter defaultParams->set("Build Subcells",true); + // default to false for backward compatibility + defaultParams->set("Create Edge Blocks",false,"Create edge blocks in the mesh"); + defaultParams->set("Create Face Blocks",false,"Create face blocks in the mesh"); + Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs"); bcs.set("Count",0); // no default periodic boundary conditions } @@ -282,9 +309,6 @@ void CubeHexMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach */, const CellTopologyData * ctd = shards::getCellTopologyData(); const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0); - const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0); - const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0); - // build meta data //mesh.setDimension(2); for(int bx=0;bx procTuple_; }; diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.cpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.cpp index d4bcd8eda513..03049a82597f 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.cpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.cpp @@ -156,14 +156,25 @@ void CubeTetMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::Para // finish up the edges and faces mesh.buildSubcells(); mesh.buildLocalElementIDs(); - mesh.buildLocalEdgeIDs(); - mesh.buildLocalFaceIDs(); + if(createEdgeBlocks_) { + mesh.buildLocalEdgeIDs(); + } + if(createFaceBlocks_) { + mesh.buildLocalFaceIDs(); + } // now that edges are built, sidets can be added addSideSets(mesh); addNodeSets(mesh); - addEdgeBlocks(mesh); - addFaceBlocks(mesh); + + mesh.beginModification(); + if(createEdgeBlocks_) { + addEdgeBlocks(mesh); + } + if(createFaceBlocks_) { + addFaceBlocks(mesh); + } + mesh.endModification(); // calls Stk_MeshFactory::rebalance this->rebalance(mesh); @@ -196,6 +207,9 @@ void CubeTetMeshFactory::setParameterList(const Teuchos::RCPget("Y Elements"); nZElems_ = paramList->get("Z Elements"); + createEdgeBlocks_ = paramList->get("Create Edge Blocks"); + createFaceBlocks_ = paramList->get("Create Face Blocks"); + // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); } @@ -229,6 +243,10 @@ Teuchos::RCP CubeTetMeshFactory::getValidParameter defaultParams->set("Y Elements",5); defaultParams->set("Z Elements",5); + // default to false for backward compatibility + defaultParams->set("Create Edge Blocks",false,"Create edge blocks in the mesh"); + defaultParams->set("Create Face Blocks",false,"Create face blocks in the mesh"); + Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs"); bcs.set("Count",0); // no default periodic boundary conditions } @@ -251,9 +269,6 @@ void CubeTetMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach */, const CellTopologyData * ctd = shards::getCellTopologyData(); const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0); - const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0); - const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0); - // build meta data //mesh.setDimension(2); for(int bx=0;bx bulkData = mesh.getBulkData(); @@ -614,17 +635,13 @@ void CubeTetMeshFactory::addEdgeBlocks(STK_Interface & mesh) const std::vector edges; bulkData->get_entities(mesh.getEdgeRank(),metaData->locally_owned_part(),edges); - for(auto edge : edges) { - mesh.addEntityToEdgeBlock(edge, edge_block); - } - - mesh.endModification(); + mesh.addEntitiesToEdgeBlock(edges, edge_block); } +// Pre-Condition: call beginModification() before entry +// Post-Condition: call endModification() after exit void CubeTetMeshFactory::addFaceBlocks(STK_Interface & mesh) const { - mesh.beginModification(); - stk::mesh::Part * face_block = mesh.getFaceBlock(panzer_stk::STK_Interface::faceBlockString); Teuchos::RCP bulkData = mesh.getBulkData(); @@ -632,11 +649,7 @@ void CubeTetMeshFactory::addFaceBlocks(STK_Interface & mesh) const std::vector faces; bulkData->get_entities(mesh.getFaceRank(),metaData->locally_owned_part(),faces); - for(auto face : faces) { - mesh.addEntityToFaceBlock(face, face_block); - } - - mesh.endModification(); + mesh.addEntitiesToFaceBlock(faces, face_block); } //! Convert processor rank to a tuple diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.hpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.hpp index d74fd8134355..83536e610409 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.hpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_CubeTetMeshFactory.hpp @@ -112,6 +112,9 @@ class CubeTetMeshFactory : public STK_MeshFactory { mutable unsigned int machRank_, machSize_; mutable Teuchos::Tuple procTuple_; + + bool createEdgeBlocks_; + bool createFaceBlocks_; }; } diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_ExodusReaderFactory.cpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_ExodusReaderFactory.cpp index 1e9c219d9155..7c717b0daf05 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_ExodusReaderFactory.cpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_ExodusReaderFactory.cpp @@ -363,7 +363,6 @@ void STK_ExodusReaderFactory::setParameterList(const Teuchos::RCPget("Levels of Uniform Refinement"); createEdgeBlocks_ = paramList->get("Create Edge Blocks"); - createFaceBlocks_ = paramList->get("Create Face Blocks"); } @@ -401,10 +400,8 @@ Teuchos::RCP STK_ExodusReaderFactory::getValidPara validParams->set("Rebalancing","default","The type of rebalancing to be performed on the mesh after creation (default, none)"); - // default to false to prevent massive exodiff test failures + // default to false for backward compatibility validParams->set("Create Edge Blocks",false,"Create or copy edge blocks in the mesh"); - - // default to false to prevent massive exodiff test failures validParams->set("Create Face Blocks",false,"Create or copy face blocks in the mesh"); } diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.cpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.cpp index 7dd28d789ed5..2c913652831f 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.cpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.cpp @@ -160,6 +160,9 @@ void SquareQuadMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::P mesh.buildSubcells(); #endif mesh.buildLocalElementIDs(); + if(createEdgeBlocks_) { + mesh.buildLocalEdgeIDs(); + } // now that edges are built, sidsets can be added #ifndef ENABLE_UNIFORM @@ -169,6 +172,10 @@ void SquareQuadMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::P // add nodesets addNodeSets(mesh); + if(createEdgeBlocks_) { + addEdgeBlocks(mesh); + } + // calls Stk_MeshFactory::rebalance this->rebalance(mesh); } @@ -197,6 +204,8 @@ void SquareQuadMeshFactory::setParameterList(const Teuchos::RCPget("Offset mesh GIDs above 32-bit int limit") == "ON") ? true : false; + createEdgeBlocks_ = paramList->get("Create Edge Blocks"); + // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); } @@ -225,6 +234,9 @@ Teuchos::RCP SquareQuadMeshFactory::getValidParame defaultParams->set("X Elements",5); defaultParams->set("Y Elements",5); + // default to false for backward compatibility + defaultParams->set("Create Edge Blocks",false,"Create edge blocks in the mesh"); + Teuchos::setStringToIntegralParameter( "Offset mesh GIDs above 32-bit int limit", "OFF", @@ -293,6 +305,11 @@ void SquareQuadMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach * // add nodesets mesh.addNodeset("lower_left"); mesh.addNodeset("origin"); + + if(createEdgeBlocks_) { + const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0); + mesh.addEdgeBlock(panzer_stk::STK_Interface::edgeBlockString, edge_ctd); + } } void SquareQuadMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const @@ -559,6 +576,22 @@ void SquareQuadMeshFactory::addNodeSets(STK_Interface & mesh) const mesh.endModification(); } +void SquareQuadMeshFactory::addEdgeBlocks(STK_Interface & mesh) const +{ + mesh.beginModification(); + + stk::mesh::Part * edge_block = mesh.getEdgeBlock(panzer_stk::STK_Interface::edgeBlockString); + + Teuchos::RCP bulkData = mesh.getBulkData(); + Teuchos::RCP metaData = mesh.getMetaData(); + + std::vector edges; + bulkData->get_entities(mesh.getEdgeRank(),metaData->locally_owned_part(),edges); + mesh.addEntitiesToEdgeBlock(edges, edge_block); + + mesh.endModification(); +} + //! Convert processor rank to a tuple Teuchos::Tuple SquareQuadMeshFactory::procRankToProcTuple(std::size_t procRank) const { diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.hpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.hpp index 8f7e9c8d5751..a66535b3ace8 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.hpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareQuadMeshFactory.hpp @@ -96,6 +96,7 @@ class SquareQuadMeshFactory : public STK_MeshFactory { void addSideSets(STK_Interface & mesh) const; void addNodeSets(STK_Interface & mesh) const; + void addEdgeBlocks(STK_Interface & mesh) const; double x0_, y0_; double xf_, yf_; @@ -108,6 +109,8 @@ class SquareQuadMeshFactory : public STK_MeshFactory { mutable unsigned int machRank_, machSize_; mutable Teuchos::Tuple procTuple_; + bool createEdgeBlocks_; + /// If true, offset mesh GIDs to exercise 32-bit limits. bool offsetGIDs_; mutable stk::mesh::EntityId offset_; diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.cpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.cpp index 44118f1cbdb6..60379414dad8 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.cpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.cpp @@ -154,6 +154,9 @@ void SquareTriMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::Pa // finish up the edges mesh.buildSubcells(); mesh.buildLocalElementIDs(); + if(createEdgeBlocks_) { + mesh.buildLocalEdgeIDs(); + } // now that edges are built, sidets can be added addSideSets(mesh); @@ -161,6 +164,10 @@ void SquareTriMeshFactory::completeMeshConstruction(STK_Interface & mesh,stk::Pa // add nodesets addNodeSets(mesh); + if(createEdgeBlocks_) { + addEdgeBlocks(mesh); + } + // calls Stk_MeshFactory::rebalance this->rebalance(mesh); } @@ -187,6 +194,8 @@ void SquareTriMeshFactory::setParameterList(const Teuchos::RCPget("X Procs"); yProcs_ = paramList->get("Y Procs"); + createEdgeBlocks_ = paramList->get("Create Edge Blocks"); + // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); } @@ -215,6 +224,9 @@ Teuchos::RCP SquareTriMeshFactory::getValidParamet defaultParams->set("X Elements",5); defaultParams->set("Y Elements",5); + // default to false for backward compatibility + defaultParams->set("Create Edge Blocks",false,"Create edge blocks in the mesh"); + Teuchos::ParameterList & bcs = defaultParams->sublist("Periodic BCs"); bcs.set("Count",0); // no default periodic boundary conditions } @@ -262,6 +274,11 @@ void SquareTriMeshFactory::buildMetaData(stk::ParallelMachine /* parallelMach */ // add nodesets mesh.addNodeset("origin"); + + if(createEdgeBlocks_) { + const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0); + mesh.addEdgeBlock(panzer_stk::STK_Interface::edgeBlockString, edge_ctd); + } } void SquareTriMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const @@ -468,6 +485,22 @@ void SquareTriMeshFactory::addNodeSets(STK_Interface & mesh) const mesh.endModification(); } +void SquareTriMeshFactory::addEdgeBlocks(STK_Interface & mesh) const +{ + mesh.beginModification(); + + stk::mesh::Part * edge_block = mesh.getEdgeBlock(panzer_stk::STK_Interface::edgeBlockString); + + Teuchos::RCP bulkData = mesh.getBulkData(); + Teuchos::RCP metaData = mesh.getMetaData(); + + std::vector edges; + bulkData->get_entities(mesh.getEdgeRank(),metaData->locally_owned_part(),edges); + mesh.addEntitiesToEdgeBlock(edges, edge_block); + + mesh.endModification(); +} + //! Convert processor rank to a tuple Teuchos::Tuple SquareTriMeshFactory::procRankToProcTuple(std::size_t procRank) const { diff --git a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.hpp b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.hpp index 4dca72a1df62..038cd029e636 100644 --- a/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.hpp +++ b/packages/panzer/adapters-stk/src/stk_interface/Panzer_STK_SquareTriMeshFactory.hpp @@ -96,6 +96,7 @@ class SquareTriMeshFactory : public STK_MeshFactory { void addSideSets(STK_Interface & mesh) const; void addNodeSets(STK_Interface & mesh) const; + void addEdgeBlocks(STK_Interface & mesh) const; double x0_, y0_; double xf_, yf_; @@ -107,6 +108,8 @@ class SquareTriMeshFactory : public STK_MeshFactory { mutable unsigned int machRank_, machSize_; mutable Teuchos::Tuple procTuple_; + + bool createEdgeBlocks_; }; } diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tCubeHexMeshFactory.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tCubeHexMeshFactory.cpp index 295ac7c9c0a8..394dc463b1e3 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tCubeHexMeshFactory.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tCubeHexMeshFactory.cpp @@ -60,8 +60,45 @@ #include "Epetra_SerialComm.h" #endif +#include "Ioss_DatabaseIO.h" +#include "Ioss_IOFactory.h" +#include "Ioss_Region.h" +#include "Ioss_EdgeBlock.h" +#include "Ioss_FaceBlock.h" + namespace panzer_stk { +void edge_face_block_test_helper(Teuchos::FancyOStream &out, + bool &success, + Teuchos::RCP pl, + std::string exodus_filename, + uint32_t expected_edge_block_count, + uint32_t expected_face_block_count) +{ + CubeHexMeshFactory factory; + factory.setParameterList(pl); + Teuchos::RCP mesh = factory.buildMesh(MPI_COMM_WORLD); + TEST_ASSERT(mesh!=Teuchos::null); + + if(mesh->isWritable()) + mesh->writeToExodus(exodus_filename.c_str()); + + { + Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("exodus", + exodus_filename.c_str(), + Ioss::READ_MODEL); + TEST_ASSERT(db_io); + + Ioss::Region region(db_io); + TEST_ASSERT(db_io->ok() == true); + + auto all_edge_blocks = region.get_edge_blocks(); + TEST_ASSERT(all_edge_blocks.size() == expected_edge_block_count); + auto all_face_blocks = region.get_face_blocks(); + TEST_ASSERT(all_face_blocks.size() == expected_face_block_count); + } +} + TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, defaults) { using Teuchos::RCP; @@ -185,6 +222,91 @@ TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, disable_subcells) TEST_EQUALITY(mesh->getEntityCounts(mesh->getNodeRank()),(4+1)*(2+1)*(5+1)); } +TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, default_edge_face_blocks) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + + edge_face_block_test_helper(out, success, pl, "CubeHex_default_edge_face_blocks.exo", 0, 0); +} + +TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, create_edge_blocks_pl) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + pl->set("Create Edge Blocks",true); + + edge_face_block_test_helper(out, success, pl, "CubeHex_create_edge_blocks_pl.exo", 1, 0); +} + +TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, create_face_blocks_pl) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + pl->set("Create Face Blocks",true); + + edge_face_block_test_helper(out, success, pl, "CubeHex_create_face_blocks_pl.exo", 0, 1); +} + + +TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, create_edge_face_blocks_pl) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + pl->set("Create Edge Blocks",true); + pl->set("Create Face Blocks",true); + + edge_face_block_test_helper(out, success, pl, "CubeHex_create_edge_face_blocks_pl.exo", 1, 1); +} + TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, allblock) { using Teuchos::RCP; diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tCubeTetMeshFactory.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tCubeTetMeshFactory.cpp index 8f727275a9d4..07bbb71f2c09 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tCubeTetMeshFactory.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tCubeTetMeshFactory.cpp @@ -59,8 +59,45 @@ #include "Epetra_SerialComm.h" #endif +#include "Ioss_DatabaseIO.h" +#include "Ioss_IOFactory.h" +#include "Ioss_Region.h" +#include "Ioss_EdgeBlock.h" +#include "Ioss_FaceBlock.h" + namespace panzer_stk { +void edge_face_block_test_helper(Teuchos::FancyOStream &out, + bool &success, + Teuchos::RCP pl, + std::string exodus_filename, + uint32_t expected_edge_block_count, + uint32_t expected_face_block_count) +{ + CubeTetMeshFactory factory; + factory.setParameterList(pl); + Teuchos::RCP mesh = factory.buildMesh(MPI_COMM_WORLD); + TEST_ASSERT(mesh!=Teuchos::null); + + if(mesh->isWritable()) + mesh->writeToExodus(exodus_filename.c_str()); + + { + Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("exodus", + exodus_filename.c_str(), + Ioss::READ_MODEL); + TEST_ASSERT(db_io); + + Ioss::Region region(db_io); + TEST_ASSERT(db_io->ok() == true); + + auto all_edge_blocks = region.get_edge_blocks(); + TEST_ASSERT(all_edge_blocks.size() == expected_edge_block_count); + auto all_face_blocks = region.get_face_blocks(); + TEST_ASSERT(all_face_blocks.size() == expected_face_block_count); + } +} + TEUCHOS_UNIT_TEST(tCubeTetMeshFactory, defaults) { using Teuchos::RCP; @@ -104,4 +141,89 @@ TEUCHOS_UNIT_TEST(tCubeTetMeshFactory, defaults) TEST_EQUALITY(nodesets[0],"origin"); } +TEUCHOS_UNIT_TEST(tCubeHexMeshFactory, default_edge_face_blocks) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + + edge_face_block_test_helper(out, success, pl, "CubeTet_default_edge_face_blocks.exo", 0, 0); +} + +TEUCHOS_UNIT_TEST(tCubeTetMeshFactory, create_edge_blocks_pl) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + pl->set("Create Edge Blocks",true); + + edge_face_block_test_helper(out, success, pl, "CubeTet_create_edge_blocks_pl.exo", 1, 0); +} + +TEUCHOS_UNIT_TEST(tCubeTetMeshFactory, create_face_blocks_pl) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + pl->set("Create Face Blocks",true); + + edge_face_block_test_helper(out, success, pl, "CubeTet_create_face_blocks_pl.exo", 0, 1); +} + + +TEUCHOS_UNIT_TEST(tCubeTetMeshFactory, create_edge_face_blocks_pl) +{ + using Teuchos::RCP; + using Teuchos::rcp; + using Teuchos::rcpFromRef; + + int xe = 2, ye = 2, ze = 2; + int bx = 1, by = 1, bz = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("Z Blocks",bz); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Z Elements",ze); + pl->set("Create Edge Blocks",true); + pl->set("Create Face Blocks",true); + + edge_face_block_test_helper(out, success, pl, "CubeTet_create_edge_face_blocks_pl.exo", 1, 1); +} + } diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tExodusEdgeBlock.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tExodusEdgeBlock.cpp index 848e70d1aa14..5affb708f498 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tExodusEdgeBlock.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tExodusEdgeBlock.cpp @@ -84,6 +84,7 @@ TEUCHOS_UNIT_TEST(tExodusEdgeBlock, edge_count) pl->set("X Elements",(int)xelems); pl->set("Y Elements",(int)yelems); pl->set("Z Elements",(int)zelems); + pl->set("Create Edge Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); @@ -168,6 +169,7 @@ TEUCHOS_UNIT_TEST(tExodusEdgeBlock, is_edge_local) pl->set("X Elements",(int)xelems); pl->set("Y Elements",(int)yelems); pl->set("Z Elements",(int)zelems); + pl->set("Create Edge Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); @@ -218,6 +220,7 @@ TEUCHOS_UNIT_TEST(tExodusEdgeBlock, add_edge_field) pl->set("X Elements",2); pl->set("Y Elements",4); pl->set("Z Elements",5); + pl->set("Create Edge Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); @@ -274,6 +277,7 @@ TEUCHOS_UNIT_TEST(tExodusEdgeBlock, set_edge_field_data) pl->set("X Elements",2); pl->set("Y Elements",4); pl->set("Z Elements",5); + pl->set("Create Edge Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tExodusFaceBlock.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tExodusFaceBlock.cpp index 52aad557508b..1aa170b93d98 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tExodusFaceBlock.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tExodusFaceBlock.cpp @@ -84,6 +84,7 @@ TEUCHOS_UNIT_TEST(tExodusFaceBlock, face_count) pl->set("X Elements",(int)xelems); pl->set("Y Elements",(int)yelems); pl->set("Z Elements",(int)zelems); + pl->set("Create Face Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); @@ -167,6 +168,7 @@ TEUCHOS_UNIT_TEST(tExodusFaceBlock, is_face_local) pl->set("X Elements",(int)xelems); pl->set("Y Elements",(int)yelems); pl->set("Z Elements",(int)zelems); + pl->set("Create Face Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); @@ -217,6 +219,7 @@ TEUCHOS_UNIT_TEST(tExodusFaceBlock, add_face_field) pl->set("X Elements",2); pl->set("Y Elements",4); pl->set("Z Elements",5); + pl->set("Create Face Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); @@ -273,6 +276,7 @@ TEUCHOS_UNIT_TEST(tExodusFaceBlock, set_face_field_data) pl->set("X Elements",2); pl->set("Y Elements",4); pl->set("Z Elements",5); + pl->set("Create Face Blocks",true); CubeHexMeshFactory factory; factory.setParameterList(pl); diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tExodusReaderFactory.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tExodusReaderFactory.cpp index 98e5e96e1eee..52cdd115b71e 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tExodusReaderFactory.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tExodusReaderFactory.cpp @@ -62,9 +62,36 @@ #include "Epetra_SerialComm.h" #endif +#include "Ioss_DatabaseIO.h" +#include "Ioss_IOFactory.h" +#include "Ioss_Region.h" +#include "Ioss_EdgeBlock.h" +#include "Ioss_FaceBlock.h" + #ifdef PANZER_HAVE_IOSS namespace panzer_stk { + +void edge_face_block_test_helper(Teuchos::FancyOStream &out, + bool &success, + std::string exodus_filename, + uint32_t expected_edge_block_count, + uint32_t expected_face_block_count) +{ + Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("exodus", + exodus_filename.c_str(), + Ioss::READ_MODEL); + TEST_ASSERT(db_io); + + Ioss::Region region(db_io); + TEST_ASSERT(db_io->ok() == true); + + auto all_edge_blocks = region.get_edge_blocks(); + TEST_ASSERT(all_edge_blocks.size() == expected_edge_block_count); + auto all_face_blocks = region.get_face_blocks(); + TEST_ASSERT(all_face_blocks.size() == expected_face_block_count); +} + TEUCHOS_UNIT_TEST(tExodusReaderFactory, basic_test) { @@ -173,16 +200,54 @@ TEUCHOS_UNIT_TEST(tExodusReaderFactory, basic_test) } /* - * This is basically the same as "basic_test" except - * that it will confirm that the edge block is created in + * This is a much simplified copy of the "basic_test" + * which confirms that by default the edge and face + * blocks are NOT created when reading in an Exodus + * file that doesn't already have edge or face blocks. +*/ +TEUCHOS_UNIT_TEST(tExodusReaderFactory, default_edge_face_block_test) +{ + auto erf = Teuchos::rcp(new STK_ExodusReaderFactory()); + + Teuchos::RCP pl = Teuchos::rcp(new Teuchos::ParameterList); + pl->set("File Name","meshes/basic3d.gen"); + erf->setParameterList(pl); + + // read from file and build mesh + Teuchos::RCP mesh = erf->buildUncommitedMesh(MPI_COMM_WORLD); + erf->completeMeshConstruction(*mesh,MPI_COMM_WORLD); + + TEST_ASSERT(mesh!=Teuchos::null); + TEST_ASSERT(mesh->getDimension()==3); + TEST_ASSERT(mesh->isWritable()); + TEST_ASSERT(not mesh->isModifiable()); + + mesh->writeToExodus("meshes/default_edge_face_block_check.gen"); + + // check edge blocks + std::vector edgeblocks; + mesh->getEdgeBlockNames(edgeblocks); + TEST_EQUALITY((int) edgeblocks.size(),0); + + // check face blocks + std::vector faceblocks; + mesh->getFaceBlockNames(faceblocks); + TEST_EQUALITY((int) faceblocks.size(),0); + + edge_face_block_test_helper(out, + success, + "meshes/default_edge_face_block_check.gen", + 0, + 0); +} + +/* + * This is a much simplified copy of the "basic_test" + * which confirms that the edge block is created in * step 1 and copied in step 2. */ TEUCHOS_UNIT_TEST(tExodusReaderFactory, edge_block_test) { - int numprocs = stk::parallel_machine_size(MPI_COMM_WORLD); - int rank = stk::parallel_machine_rank(MPI_COMM_WORLD); - out << "Running numprocs = " << numprocs << " rank = " << rank << std::endl; - { auto erf = Teuchos::rcp(new STK_ExodusReaderFactory()); @@ -191,7 +256,6 @@ TEUCHOS_UNIT_TEST(tExodusReaderFactory, edge_block_test) pl->set("Create Edge Blocks",true); erf->setParameterList(pl); - out << "\n***reading from meshes/basic.gen ... writes to meshes/edge_block_check.gen" << std::endl; // read from file and build mesh Teuchos::RCP mesh = erf->buildUncommitedMesh(MPI_COMM_WORLD); erf->completeMeshConstruction(*mesh,MPI_COMM_WORLD); @@ -201,64 +265,22 @@ TEUCHOS_UNIT_TEST(tExodusReaderFactory, edge_block_test) TEST_ASSERT(mesh->isWritable()); TEST_ASSERT(not mesh->isModifiable()); - out << "Begin writing to meshes/edge_block_check.gen" << std::endl; mesh->writeToExodus("meshes/edge_block_check.gen"); - out << "Finished writing to meshes/edge_block_check.gen" << std::endl; - - // check element blocks - std::vector eBlocks; - mesh->getElementBlockNames(eBlocks); - TEST_EQUALITY((int) eBlocks.size(),2); - out << "E-Blocks: "; - for(std::size_t j=0;j sidesets; - mesh->getSidesetNames(sidesets); - TEST_EQUALITY((int) sidesets.size(),7); - out << "Sides: "; - for(std::size_t j=0;j nodesets; - mesh->getNodesetNames(nodesets); - TEST_EQUALITY((int) nodesets.size(),2); - out << "Nodesets: "; - for(std::size_t j=0;j edgeblocks; mesh->getEdgeBlockNames(edgeblocks); TEST_EQUALITY((int) edgeblocks.size(),1); - out << "Edge Blocks: "; - for(std::size_t j=0;j faceblocks; - mesh->getFaceBlockNames(faceblocks); - TEST_EQUALITY((int) faceblocks.size(),0); - out << "Edge Blocks: "; - for(std::size_t j=0;jgetSideRank(),mesh->getEdgeRank()); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getElementRank()),8); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getSideRank()),22); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getNodeRank()),15); + edge_face_block_test_helper(out, + success, + "meshes/edge_block_check.gen", + 1, + 0); } { // in an effort to be as cerebral as possible I read in the // outputed mesh and then re-output it - out << "\n***reading from meshes/edge_block_check.gen ... writes to meshes/edge_block_check2.gen" << std::endl; // read from file and build mesh auto erf = Teuchos::rcp(new STK_ExodusReaderFactory()); @@ -270,80 +292,36 @@ TEUCHOS_UNIT_TEST(tExodusReaderFactory, edge_block_test) Teuchos::RCP mesh = erf->buildMesh(MPI_COMM_WORLD); - // check element blocks - std::vector eBlocks; - mesh->getElementBlockNames(eBlocks); - TEST_EQUALITY((int) eBlocks.size(),2); - out << "E-Blocks: "; - for(std::size_t j=0;j sidesets; - mesh->getSidesetNames(sidesets); - TEST_EQUALITY((int) sidesets.size(),7); - out << "Sides: "; - for(std::size_t j=0;j nodesets; - mesh->getNodesetNames(nodesets); - TEST_EQUALITY((int) nodesets.size(),2); - out << "Nodesets: "; - for(std::size_t j=0;j edgeblocks; mesh->getEdgeBlockNames(edgeblocks); TEST_EQUALITY((int) edgeblocks.size(),1); - out << "Edge Blocks: "; - for(std::size_t j=0;j faceblocks; - mesh->getFaceBlockNames(faceblocks); - TEST_EQUALITY((int) faceblocks.size(),0); - out << "Edge Blocks: "; - for(std::size_t j=0;jwriteToExodus("meshes/edge_block_check2.gen"); - TEST_EQUALITY(mesh->getSideRank(),mesh->getEdgeRank()); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getElementRank()),8); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getSideRank()),22); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getNodeRank()),15); + + edge_face_block_test_helper(out, + success, + "meshes/edge_block_check2.gen", + 1, + 0); } } /* - * This is basically the same as "edge_block_test" except - * that it will confirm that the face block is created in + * This is a much simplified copy of the "basic_test" + * which confirms that the face block is created in * step 1 and copied in step 2. */ TEUCHOS_UNIT_TEST(tExodusReaderFactory, face_block_test) { - int numprocs = stk::parallel_machine_size(MPI_COMM_WORLD); - int rank = stk::parallel_machine_rank(MPI_COMM_WORLD); - out << "Running numprocs = " << numprocs << " rank = " << rank << std::endl; - { auto erf = Teuchos::rcp(new STK_ExodusReaderFactory()); Teuchos::RCP pl = Teuchos::rcp(new Teuchos::ParameterList); pl->set("File Name","meshes/basic3d.gen"); - pl->set("Create Edge Blocks",true); pl->set("Create Face Blocks",true); erf->setParameterList(pl); - out << "\n***reading from meshes/basic3d.gen ... writes to meshes/face_block_check.gen" << std::endl; // read from file and build mesh Teuchos::RCP mesh = erf->buildUncommitedMesh(MPI_COMM_WORLD); erf->completeMeshConstruction(*mesh,MPI_COMM_WORLD); @@ -353,126 +331,45 @@ TEUCHOS_UNIT_TEST(tExodusReaderFactory, face_block_test) TEST_ASSERT(mesh->isWritable()); TEST_ASSERT(not mesh->isModifiable()); - out << "Begin writing to meshes/face_block_check.gen" << std::endl; mesh->writeToExodus("meshes/face_block_check.gen"); - out << "Finished writing to meshes/face_block_check.gen" << std::endl; - - // check element blocks - std::vector eBlocks; - mesh->getElementBlockNames(eBlocks); - TEST_EQUALITY((int) eBlocks.size(),1); - out << "E-Blocks: "; - for(std::size_t j=0;j sidesets; - mesh->getSidesetNames(sidesets); - TEST_EQUALITY((int) sidesets.size(),6); - out << "Sides: "; - for(std::size_t j=0;j nodesets; - mesh->getNodesetNames(nodesets); - TEST_EQUALITY((int) nodesets.size(),1); - out << "Nodesets: "; - for(std::size_t j=0;j edgeblocks; - mesh->getEdgeBlockNames(edgeblocks); - TEST_EQUALITY((int) edgeblocks.size(),1); - out << "Edge Blocks: "; - for(std::size_t j=0;j faceblocks; mesh->getFaceBlockNames(faceblocks); TEST_EQUALITY((int) faceblocks.size(),1); - out << "Edge Blocks: "; - for(std::size_t j=0;jgetSideRank(),mesh->getFaceRank()); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getElementRank()),40); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getSideRank()),158); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getNodeRank()),90); + + edge_face_block_test_helper(out, + success, + "meshes/face_block_check.gen", + 0, + 1); } { // in an effort to be as cerebral as possible I read in the // outputed mesh and then re-output it - out << "\n***reading from meshes/face_block_check.gen ... writes to meshes/face_block_check2.gen" << std::endl; // read from file and build mesh auto erf = Teuchos::rcp(new STK_ExodusReaderFactory()); Teuchos::RCP pl = Teuchos::rcp(new Teuchos::ParameterList); pl->set("File Name","meshes/face_block_check.gen"); - pl->set("Create Edge Blocks",true); pl->set("Create Face Blocks",true); erf->setParameterList(pl); Teuchos::RCP mesh = erf->buildMesh(MPI_COMM_WORLD); - // check element blocks - std::vector eBlocks; - mesh->getElementBlockNames(eBlocks); - TEST_EQUALITY((int) eBlocks.size(),1); - out << "E-Blocks: "; - for(std::size_t j=0;j sidesets; - mesh->getSidesetNames(sidesets); - TEST_EQUALITY((int) sidesets.size(),6); - out << "Sides: "; - for(std::size_t j=0;j nodesets; - mesh->getNodesetNames(nodesets); - TEST_EQUALITY((int) nodesets.size(),1); - out << "Nodesets: "; - for(std::size_t j=0;j edgeblocks; - mesh->getEdgeBlockNames(edgeblocks); - TEST_EQUALITY((int) edgeblocks.size(),1); - out << "Edge Blocks: "; - for(std::size_t j=0;j faceblocks; mesh->getFaceBlockNames(faceblocks); TEST_EQUALITY((int) faceblocks.size(),1); - out << "Edge Blocks: "; - for(std::size_t j=0;jwriteToExodus("meshes/face_block_check2.gen"); - TEST_EQUALITY(mesh->getSideRank(),mesh->getFaceRank()); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getElementRank()),40); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getSideRank()),158); - TEST_EQUALITY(mesh->getEntityCounts(mesh->getNodeRank()),90); + + edge_face_block_test_helper(out, + success, + "meshes/face_block_check2.gen", + 0, + 1); } } diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tSquareQuadMeshFactory.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tSquareQuadMeshFactory.cpp index 2488a5a9a141..2348b6bfccae 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tSquareQuadMeshFactory.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tSquareQuadMeshFactory.cpp @@ -63,6 +63,11 @@ #include "stk_mesh/base/GetEntities.hpp" #include "stk_mesh/base/Selector.hpp" +#include "Ioss_DatabaseIO.h" +#include "Ioss_IOFactory.h" +#include "Ioss_Region.h" +#include "Ioss_EdgeBlock.h" + namespace panzer_stk { inline bool XOR(bool A,bool B) @@ -88,6 +93,34 @@ static const double * getNode(const Teuchos::RCP & mesh, st } */ +void edge_block_test_helper(Teuchos::FancyOStream &out, + bool &success, + Teuchos::RCP pl, + std::string exodus_filename, + uint32_t expected_edge_block_count) +{ + SquareQuadMeshFactory factory; + factory.setParameterList(pl); + Teuchos::RCP mesh = factory.buildMesh(MPI_COMM_WORLD); + TEST_ASSERT(mesh!=Teuchos::null); + + if(mesh->isWritable()) + mesh->writeToExodus(exodus_filename.c_str()); + + { + Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("exodus", + exodus_filename.c_str(), + Ioss::READ_MODEL); + TEST_ASSERT(db_io); + + Ioss::Region region(db_io); + TEST_ASSERT(db_io->ok() == true); + + auto all_edge_blocks = region.get_edge_blocks(); + TEST_ASSERT(all_edge_blocks.size() == expected_edge_block_count); + } +} + TEUCHOS_UNIT_TEST(tSquareQuadMeshFactory, periodic_input) { using Teuchos::RCP; @@ -895,4 +928,36 @@ void test4(Teuchos::FancyOStream &out, bool &success,MPI_Comm & comm) else TEST_ASSERT(false); } +TEUCHOS_UNIT_TEST(tSquareQuadMeshFactory, default_edge_blocks) +{ + using Teuchos::RCP; + + int xe = 2, ye = 2; + int bx = 1, by = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + + edge_block_test_helper(out, success, pl, "SquareQuad_default_edge_blocks.exo", 0); +} + +TEUCHOS_UNIT_TEST(tSquareQuadMeshFactory, create_edge_blocks_pl) +{ + using Teuchos::RCP; + + int xe = 2, ye = 2; + int bx = 1, by = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Create Edge Blocks",true); + + edge_block_test_helper(out, success, pl, "SquareQuad_create_edge_blocks_pl.exo", 1); +} } diff --git a/packages/panzer/adapters-stk/test/stk_interface_test/tSquareTriMeshFactory.cpp b/packages/panzer/adapters-stk/test/stk_interface_test/tSquareTriMeshFactory.cpp index e1a9bb0e6087..78cb07823da3 100644 --- a/packages/panzer/adapters-stk/test/stk_interface_test/tSquareTriMeshFactory.cpp +++ b/packages/panzer/adapters-stk/test/stk_interface_test/tSquareTriMeshFactory.cpp @@ -56,8 +56,41 @@ #include "stk_mesh/base/GetEntities.hpp" #include "stk_mesh/base/Selector.hpp" +#include "Ioss_DatabaseIO.h" +#include "Ioss_IOFactory.h" +#include "Ioss_Region.h" +#include "Ioss_EdgeBlock.h" + namespace panzer_stk { +void edge_block_test_helper(Teuchos::FancyOStream &out, + bool &success, + Teuchos::RCP pl, + std::string exodus_filename, + uint32_t expected_edge_block_count) +{ + SquareTriMeshFactory factory; + factory.setParameterList(pl); + Teuchos::RCP mesh = factory.buildMesh(MPI_COMM_WORLD); + TEST_ASSERT(mesh!=Teuchos::null); + + if(mesh->isWritable()) + mesh->writeToExodus(exodus_filename.c_str()); + + { + Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("exodus", + exodus_filename.c_str(), + Ioss::READ_MODEL); + TEST_ASSERT(db_io); + + Ioss::Region region(db_io); + TEST_ASSERT(db_io->ok() == true); + + auto all_edge_blocks = region.get_edge_blocks(); + TEST_ASSERT(all_edge_blocks.size() == expected_edge_block_count); + } +} + TEUCHOS_UNIT_TEST(tSquareTriMeshFactory, defaults) { using Teuchos::RCP; @@ -98,4 +131,37 @@ TEUCHOS_UNIT_TEST(tSquareTriMeshFactory, defaults) TEST_EQUALITY(nodesets[0],"origin"); } +TEUCHOS_UNIT_TEST(tSquareTriMeshFactory, default_edge_face_blocks) +{ + using Teuchos::RCP; + + int xe = 2, ye = 2; + int bx = 1, by = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + + edge_block_test_helper(out, success, pl, "SquareTri_default_edge_blocks.exo", 0); +} + +TEUCHOS_UNIT_TEST(tSquareTriMeshFactory, create_edge_blocks_pl) +{ + using Teuchos::RCP; + + int xe = 2, ye = 2; + int bx = 1, by = 1; + + RCP pl = rcp(new Teuchos::ParameterList); + pl->set("X Blocks",bx); + pl->set("Y Blocks",by); + pl->set("X Elements",xe); + pl->set("Y Elements",ye); + pl->set("Create Edge Blocks",true); + + edge_block_test_helper(out, success, pl, "SquareTri_create_edge_blocks_pl.exo", 1); +} + } diff --git a/packages/piro/src/Piro_PerformAnalysis.cpp b/packages/piro/src/Piro_PerformAnalysis.cpp index f565ba63b125..fa5e9ed07edc 100644 --- a/packages/piro/src/Piro_PerformAnalysis.cpp +++ b/packages/piro/src/Piro_PerformAnalysis.cpp @@ -493,8 +493,6 @@ Piro::PerformROLAnalysis( } bool useFullSpace = rolParams.get("Full Space",false); - bool useHessianDotProduct = rolParams.get("Hessian Dot Product",false); - bool removeMeanOfTheRHS = rolParams.get("Remove Mean Of The Right-hand Side",false); *out << "\nROL options:" << std::endl; rolParams.sublist("ROL Options").print(*out); @@ -510,16 +508,37 @@ Piro::PerformROLAnalysis( ROL::Ptr > algo; algo = ROL::makePtr>(step, status, true); -#ifdef HAVE_PIRO_TEKO + bool useHessianDotProduct = false; + Teuchos::ParameterList hessianDotProductList; + if(rolParams.isSublist("Matrix Based Dot Product")) { + const Teuchos::ParameterList& matrixDotProductList = rolParams.sublist("Matrix Based Dot Product"); + auto matrixType = matrixDotProductList.get("Matrix Type"); + if(matrixType == "Hessian Of Response") { + useHessianDotProduct = true; + hessianDotProductList = matrixDotProductList.sublist("Matrix Types").sublist("Hessian Of Response"); + } + else if (matrixType == "Identity") + useHessianDotProduct = false; + else { + TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter, + std::endl << "Error in Piro::PerformROLAnalysis: " << + "Matrix Type not recognized. Available options are: \n" << + "\"Identity\" and \"Hessian Of Response\""<("Response Index"); *out << "\nStart the computation of H_pp" << std::endl; Teko::BlockedLinearOp bH = Teko::createBlockedOp(); - obj.hessian_22(bH, rol_x, rol_p); + obj.hessian_22(bH, rol_x, rol_p, hessianResponseIndex); *out << "End of the computation of H_pp" << std::endl; int numBlocks = bH->productRange()->numBlocks(); + /* Not using defaults to increase user awareness Teuchos::ParameterList defaultParamList; string defaultSolverType = "Belos"; defaultParamList.set("Linear Solver Type", "Belos"); @@ -532,22 +551,14 @@ Piro::PerformROLAnalysis( belosList.sublist("Solver Types").sublist("Pseudo Block CG").set("Output Frequency", 100); belosList.sublist("VerboseObject").set("Verbosity Level", "medium"); defaultParamList.set("Preconditioner Type", "None"); + */ - Teuchos::ParameterList dHess; - if(rolParams.isSublist("Hessian Diagonal Inverse")) - dHess = rolParams.sublist("Hessian Diagonal Inverse"); - + Teuchos::ParameterList dHess = hessianDotProductList.sublist("Block Diagonal Solver"); std::vector diag(numBlocks); - for (int i=0; i(blockSolverType, defaultSolverType); + Teuchos::ParameterList pl = dHess.sublist(blockName); + std::string solverType = pl.get("Linear Solver Type"); diag[i] = Teko::buildInverse(*Teko::invFactoryFromParamList(pl, solverType), Teko::getBlock(i, i, bH)); } @@ -558,6 +569,10 @@ Piro::PerformROLAnalysis( H = Teuchos::null; invH = Teuchos::null; } +#else + TEUCHOS_TEST_FOR_EXCEPTION(useHessianDotProduct, Teuchos::Exceptions::InvalidParameter, + std::endl << "Error in Piro::PerformROLAnalysis: " << + "Teko is required for computing the Hessian based dot Product"<( 0.5, 2.0, scaling_vector_x.ptr()); ROL::PrimalScaledThyraVector rol_x_primal(x, scaling_vector_x); #ifdef HAVE_PIRO_TEKO + bool removeMeanOfTheRHS = hessianDotProductList.get("Remove Mean Of The Right-hand Side",false); ROL::PrimalHessianScaledThyraVector rol_p_primal(p, H, invH, removeMeanOfTheRHS); #else Teuchos::RCP > scaling_vector_p = p->clone_v(); diff --git a/packages/piro/src/Piro_ThyraProductME_Objective_SimOpt.hpp b/packages/piro/src/Piro_ThyraProductME_Objective_SimOpt.hpp index baf29fca39cb..b91def8482d7 100644 --- a/packages/piro/src/Piro_ThyraProductME_Objective_SimOpt.hpp +++ b/packages/piro/src/Piro_ThyraProductME_Objective_SimOpt.hpp @@ -268,14 +268,15 @@ class ThyraProductME_Objective_SimOpt : public ROL::Objective_SimOpt { void hessian_22(const Teuchos::RCP> H, const ROL::Vector &u, - const ROL::Vector &z) { + const ROL::Vector &z, + const int g_idx) { if(verbosityLevel >= Teuchos::VERB_MEDIUM) *out << "ROL::ThyraProductME_Objective_SimOpt::hessian_22" << std::endl; Thyra::ModelEvaluatorBase::OutArgs outArgs = thyra_model.createOutArgs(); bool supports_deriv = true; for(std::size_t i=0; i & thyra_p = dynamic_cast&>(z); @@ -294,18 +295,18 @@ class ThyraProductME_Objective_SimOpt : public ROL::Objective_SimOpt { } inArgs.set_x(thyra_x.getVector()); - Teuchos::RCP< Thyra::VectorBase > multiplier_g = Thyra::createMember(thyra_model.get_g_multiplier_space(g_index)); + Teuchos::RCP< Thyra::VectorBase > multiplier_g = Thyra::createMember(thyra_model.get_g_multiplier_space(g_idx)); Thyra::put_scalar(1.0, multiplier_g.ptr()); - inArgs.set_g_multiplier(g_index, multiplier_g); + inArgs.set_g_multiplier(g_idx, multiplier_g); Thyra::ModelEvaluatorBase::OutArgs outArgs = thyra_model.createOutArgs(); for(std::size_t i=0; i> hess_g_pp = thyra_model.create_hess_g_pp(g_index, p_indices[i], p_indices[i]); - outArgs.set_hess_g_pp(g_index, p_indices[i], p_indices[i], hess_g_pp); + Teuchos::RCP> hess_g_pp = thyra_model.create_hess_g_pp(g_idx, p_indices[i], p_indices[i]); + outArgs.set_hess_g_pp(g_idx, p_indices[i], p_indices[i], hess_g_pp); H->setBlock(p_indices[i], p_indices[i], hess_g_pp); } H->endBlockFill(); diff --git a/packages/piro/test/_input_Analysis_ROL_Tpetra.xml b/packages/piro/test/_input_Analysis_ROL_Tpetra.xml index e415ab18e8e7..9c109ddc3265 100644 --- a/packages/piro/test/_input_Analysis_ROL_Tpetra.xml +++ b/packages/piro/test/_input_Analysis_ROL_Tpetra.xml @@ -181,7 +181,40 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/xpetra/src/CrsGraph/Xpetra_EpetraCrsGraph.hpp b/packages/xpetra/src/CrsGraph/Xpetra_EpetraCrsGraph.hpp index 00e49175ff3f..0f5400542c94 100644 --- a/packages/xpetra/src/CrsGraph/Xpetra_EpetraCrsGraph.hpp +++ b/packages/xpetra/src/CrsGraph/Xpetra_EpetraCrsGraph.hpp @@ -302,7 +302,7 @@ class EpetraCrsGraphT #ifdef HAVE_XPETRA_KOKKOS_REFACTOR #ifdef HAVE_XPETRA_TPETRA - local_graph_type getLocalGraphHost () const { + typename local_graph_type::HostMirror getLocalGraphHost () const { TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::NotImplemented, "Xpetra::EpetraCrsGraph only available for GO=int or GO=long long with EpetraNode (Serial or OpenMP depending on configuration)"); TEUCHOS_UNREACHABLE_RETURN((local_graph_type()));