43#include "PanzerAdaptersSTK_config.hpp"
47#include "Teuchos_TimeMonitor.hpp"
48#include "Teuchos_StandardParameterEntryValidators.hpp"
49#include <stk_mesh/base/FieldBase.hpp>
57 stk::ParallelMachine mpi_comm,
58 const bool print_debug)
59 : createEdgeBlocks_(false),
60 print_debug_(print_debug)
62 panzer_stk::STK_ExodusReaderFactory factory;
63 RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList);
64 pl->set(
"File Name",quadMeshFileName);
65 factory.setParameterList(pl);
78 const bool print_debug)
79 : quadMesh_(quadMesh),
80 createEdgeBlocks_(false),
81 print_debug_(print_debug)
95 PANZER_FUNC_TIME_MONITOR(
"panzer::QuadraticToLinearMeshFactory::buildMesh()");
100 MPI_Comm_compare(parallelMach,
quadMesh_->getBulkData()->parallel(), &
result);
101 TEUCHOS_ASSERT(
result != MPI_UNEQUAL);
108 mesh->initialize(parallelMach);
118 bool errFlag =
false;
120 std::vector<std::string> eblock_names;
121 quadMesh_->getElementBlockNames(eblock_names);
124 auto inputTopo =
quadMesh_->getCellTopology(eblock_names[0]);
127 TEUCHOS_TEST_FOR_EXCEPTION(errFlag,std::logic_error,
128 "ERROR :: Input topology " << inputTopo->getName() <<
" currently unsupported by QuadraticToLinearMeshFactory!");
132 for (
auto & eblock : eblock_names) {
133 auto cellTopo =
quadMesh_->getCellTopology(eblock);
134 if (*cellTopo != *inputTopo) errFlag =
true;
137 TEUCHOS_TEST_FOR_EXCEPTION(errFlag, std::logic_error,
138 "ERROR :: The mesh has different topologies on different blocks!");
150 PANZER_FUNC_TIME_MONITOR(
"panzer::QuadraticToLinearMeshFactory::buildUncomittedMesh()");
154 machRank_ = stk::parallel_machine_rank(parallelMach);
155 machSize_ = stk::parallel_machine_size(parallelMach);
168 PANZER_FUNC_TIME_MONITOR(
"panzer::QuadraticToLinearMeshFactory::completeMeshConstruction()");
177#ifndef ENABLE_UNIFORM
186#ifndef ENABLE_UNIFORM
210 setMyParamList(paramList);
223 static RCP<Teuchos::ParameterList> defaultParams;
226 if(defaultParams == Teuchos::null) {
227 defaultParams = rcp(
new Teuchos::ParameterList);
229 Teuchos::setStringToIntegralParameter<int>(
230 "Offset mesh GIDs above 32-bit int limit",
232 "If 64-bit GIDs are supported, the mesh element and node global indices will start at a value greater than 32-bit limit.",
233 Teuchos::tuple<std::string>(
"OFF",
"ON"),
234 defaultParams.get());
237 defaultParams->set<
bool>(
"Create Edge Blocks",
false,
"Create edge blocks in the mesh");
239 Teuchos::ParameterList & bcs = defaultParams->sublist(
"Periodic BCs");
240 bcs.set<
int>(
"Count",0);
243 return defaultParams;
249 std::cout <<
"\n\n**** DEBUG: begin printing source quad mesh exodus file metadata ****\n";
250 quadMesh_->getMetaData()->dump_all_meta_info(std::cout);
251 std::cout <<
"\n\n**** DEBUG: end printing source quad mesh exodus file metadata ****\n";
257 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(
nDim_-1,0);
260 std::vector<std::string> element_block_names;
261 quadMesh_->getElementBlockNames(element_block_names);
263 for (
const auto& n : element_block_names)
269 std::vector<std::string> sideset_names;
270 quadMesh_->getSidesetNames(sideset_names);
271 for (
const auto& n : sideset_names)
277 std::vector<std::string> nodeset_names;
278 quadMesh_->getNodesetNames(nodeset_names);
279 for (
const auto& n : nodeset_names)
284 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
285 std::vector<std::string> element_block_names;
286 quadMesh_->getElementBlockNames(element_block_names);
287 for (
const auto& block_name : element_block_names)
294 for (
const auto& f : fields) {
296 std::cout <<
"Field=" << f->name() <<
", rank=" << f->entity_rank() << std::endl;
300 if (f->name() !=
"coordinates") {
301 for (
const auto& n : element_block_names)
310 for (
const auto& f : fields) {
312 std::cout <<
"Add Cell Field=" << f->name() <<
", rank=" << f->entity_rank() << std::endl;
314 for (
const auto& n : element_block_names)
326 std::cout <<
"\n\n**** DEBUG: begin printing source linear mesh exodus file metadata ****\n";
328 std::cout <<
"\n\n**** DEBUG: end printing source linear mesh exodus file metadata ****\n";
340 std::vector<std::string> block_names;
341 quadMesh_->getElementBlockNames(block_names);
342 for (
const auto& block_name : block_names) {
345 std::vector<stk::mesh::Entity> elements;
346 quadMesh_->getMyElements(block_name,elements);
349 std::cout <<
"*************************************************" << std::endl;
350 std::cout <<
"block_name=" << block_name <<
", num_my_elements=" << elements.size() << std::endl;
351 std::cout <<
"*************************************************" << std::endl;
354 for (
const auto& element : elements) {
356 const auto element_gid =
quadMesh_->getBulkData()->identifier(element);
360 <<
", block=" << block_name
361 <<
", element entity_id=" << element
362 <<
", gid=" << element_gid << std::endl;
366 std::vector<stk::mesh::EntityId> nodes(
nNodes_);
367 for (
size_t i=0; i <
nNodes_; ++i) {
374 TEUCHOS_ASSERT(node_entity.is_local_offset_valid());
375 const auto node_gid =
quadMesh_->getBulkData()->identifier(node_entity);
376 const double* node_coords =
quadMesh_->getNodeCoordinates(node_entity);
377 std::vector<double> coords_vec(
nDim_);
378 for (
size_t j=0; j <
nDim_; ++j) coords_vec[j] = node_coords[j];
379 mesh.
addNode(node_gid,coords_vec);
383 std::cout <<
"elem gid=" <<
quadMesh_->getBulkData()->identifier(element)
384 <<
", node_gid=" << node_gid <<
", ("
385 << coords_vec[0] <<
"," << coords_vec[1] <<
")\n";
387 std::cout <<
"elem gid=" <<
quadMesh_->getBulkData()->identifier(element)
388 <<
", node_gid=" << node_gid <<
", ("
389 << coords_vec[0] <<
"," << coords_vec[1] <<
"," << coords_vec[2] <<
")\n";
396 auto element_block_part = mesh.
getMetaData()->get_part(block_name);
397 mesh.
addElement(element_descriptor,element_block_part);
408 std::vector<std::string> sideset_names;
409 quadMesh_->getSidesetNames(sideset_names);
410 for (
const auto& sideset_name : sideset_names) {
412 stk::mesh::Part* sideset_part = mesh.
getSideset(sideset_name);
414 std::vector<stk::mesh::Entity> q_sides;
415 quadMesh_->getMySides(sideset_name,q_sides);
418 for (
const auto q_ent : q_sides) {
423 stk::mesh::EntityId ent_gid =
quadMesh_->getBulkData()->identifier(q_ent);
439 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.
getBulkData();
440 Teuchos::RCP<stk::mesh::MetaData> metaData = mesh.
getMetaData();
444 stk::mesh::Selector owned_block = metaData->locally_owned_part();
446 std::vector<stk::mesh::Entity> edges;
447 bulkData->get_entities(mesh.
getEdgeRank(), owned_block, edges);
459 for (
const auto&
field : fields) {
462 std::cout <<
"Adding field values for \"" << *
field <<
"\" to the linear mesh!\n";
464 auto field_name =
field->name();
468 if (
field->type_is<
double>() &&
469 field_name !=
"coordinates" &&
470 field_name !=
"PROC_ID" &&
471 field_name !=
"LOAD_BAL") {
474 std::vector<std::string> block_names;
475 quadMesh_->getElementBlockNames(block_names);
476 for (
const auto& block : block_names) {
478 auto* lin_field = lin_mesh.
getCellField(field_name,block);
479 TEUCHOS_ASSERT(lin_field !=
nullptr);
482 auto* q_field =
quadMesh_->getMetaData()->get_field(
quadMesh_->getElementRank(),field_name);
484 TEUCHOS_ASSERT(q_field !=
nullptr);
488 std::vector<stk::mesh::Entity> lin_elements;
490 std::vector<stk::mesh::Entity> q_elements;
491 quadMesh_->getMyElements(block,q_elements);
492 TEUCHOS_ASSERT(lin_elements.size() == q_elements.size());
494 for (
size_t i=0; i < lin_elements.size(); ++i) {
496 TEUCHOS_ASSERT(lin_mesh.
getBulkData()->identifier(lin_elements[i]) ==
497 quadMesh_->getBulkData()->identifier(q_elements[i]));
500 double*
const lin_val =
static_cast<double*
>(stk::mesh::field_data(*lin_field,lin_elements[i]));
501 const double*
const q_val =
static_cast<double*
>(stk::mesh::field_data(*q_field,q_elements[i]));
505 std::cout <<
"field=" << field_name <<
", block=" << block
506 <<
", lin_e(" << lin_mesh.
getBulkData()->identifier(lin_elements[i]) <<
") = " << *lin_val
507 <<
", q_e(" <<
quadMesh_->getBulkData()->identifier(q_elements[i]) <<
") = " << *q_val
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral.
unsigned int nNodes_
Dimension of the mesh.
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
const CellTopologyData * outputTopoData_
std::map< const std::string, const CellTopologyData * > outputTopoMap_
unsigned int nDim_
Output mesh topology data.
QuadraticToLinearMeshFactory(const std::string &quadMeshFileName, stk::ParallelMachine mpi_comm=MPI_COMM_WORLD, const bool print_debug=false)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Derived from ParameterListAcceptor.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
Derived from ParameterListAcceptor.
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
void addEdgeBlocks(STK_Interface &mesh) const
void addNodeSets(STK_Interface &mesh) const
unsigned int machRank_
Second order mesh.
Teuchos::RCP< panzer_stk::STK_Interface > quadMesh_
void addSideSets(STK_Interface &mesh) const
std::string edgeBlockName_
std::vector< shards::CellTopology > supportedInputTopos_
Nodes in one element of the linear basis.
void copyCellFieldData(STK_Interface &mesh) const
void buildLocalElementIDs()
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true, const bool buildRefinementSupport=false)
static const std::string edgeBlockString
stk::mesh::Part * getEdgeBlock(const std::string &name) const
get the block part
bool isInitialized() const
Has initialize been called on this mesh object?
stk::mesh::EntityRank getNodeRank() const
void addEdgeBlock(const std::string &elemBlockName, const std::string &edgeBlockName, const stk::topology &topology)
void buildSubcells()
force the mesh to build subcells: edges and faces
stk::mesh::EntityRank getElementRank() const
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void addCellField(const std::string &fieldName, const std::string &blockId)
void addNodeset(const std::string &name)
void addSideset(const std::string &name, const CellTopologyData *ctData)
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
stk::mesh::Field< double > * getCellField(const std::string &fieldName, const std::string &blockId) const
void addEntitiesToEdgeBlock(std::vector< stk::mesh::Entity > entities, stk::mesh::Part *edgeblock)
void addSolutionField(const std::string &fieldName, const std::string &blockId)
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
stk::mesh::EntityRank getSideRank() const
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
stk::mesh::EntityRank getEdgeRank() const
stk::mesh::Part * getSideset(const std::string &name) const
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC, bool &useBBoxSearch)
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
Teuchos::RCP< ElementDescriptor > buildElementDescriptor(stk::mesh::EntityId elmtId, std::vector< stk::mesh::EntityId > &nodes)