11#include "PanzerAdaptersSTK_config.hpp"
15#include "Teuchos_TimeMonitor.hpp"
16#include "Teuchos_StandardParameterEntryValidators.hpp"
17#include <stk_mesh/base/FieldBase.hpp>
18#include <stk_mesh/base/DumpMeshInfo.hpp>
26 stk::ParallelMachine mpi_comm,
27 const bool print_debug)
28 : createEdgeBlocks_(false),
29 print_debug_(print_debug)
31 panzer_stk::STK_ExodusReaderFactory factory;
32 RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList);
33 pl->set(
"File Name",quadMeshFileName);
34 factory.setParameterList(pl);
47 const bool print_debug)
48 : quadMesh_(quadMesh),
49 createEdgeBlocks_(false),
50 print_debug_(print_debug)
64 PANZER_FUNC_TIME_MONITOR(
"panzer::QuadraticToLinearMeshFactory::buildMesh()");
69 MPI_Comm_compare(parallelMach,
quadMesh_->getBulkData()->parallel(), &
result);
70 TEUCHOS_ASSERT(
result != MPI_UNEQUAL);
77 mesh->initialize(parallelMach);
89 std::vector<std::string> eblock_names;
90 quadMesh_->getElementBlockNames(eblock_names);
93 auto inputTopo =
quadMesh_->getCellTopology(eblock_names[0]);
96 TEUCHOS_TEST_FOR_EXCEPTION(errFlag,std::logic_error,
97 "ERROR :: Input topology " << inputTopo->getName() <<
" currently unsupported by QuadraticToLinearMeshFactory!");
101 for (
auto & eblock : eblock_names) {
102 auto cellTopo =
quadMesh_->getCellTopology(eblock);
103 if (*cellTopo != *inputTopo) errFlag =
true;
106 TEUCHOS_TEST_FOR_EXCEPTION(errFlag, std::logic_error,
107 "ERROR :: The mesh has different topologies on different blocks!");
119 PANZER_FUNC_TIME_MONITOR(
"panzer::QuadraticToLinearMeshFactory::buildUncomittedMesh()");
123 machRank_ = stk::parallel_machine_rank(parallelMach);
124 machSize_ = stk::parallel_machine_size(parallelMach);
137 PANZER_FUNC_TIME_MONITOR(
"panzer::QuadraticToLinearMeshFactory::completeMeshConstruction()");
146#ifndef ENABLE_UNIFORM
155#ifndef ENABLE_UNIFORM
179 setMyParamList(paramList);
192 static RCP<Teuchos::ParameterList> defaultParams;
195 if(defaultParams == Teuchos::null) {
196 defaultParams = rcp(
new Teuchos::ParameterList);
198 defaultParams->set<std::string>(
"Offset mesh GIDs above 32-bit int limit",
"OFF",
199 "If 64-bit GIDs are supported, the mesh element and node global indices will start at a value greater than 32-bit limit.",
200 rcp(
new Teuchos::StringValidator(Teuchos::tuple<std::string>(
"OFF",
"ON"))));
203 defaultParams->set<
bool>(
"Create Edge Blocks",
false,
"Create edge blocks in the mesh");
205 Teuchos::ParameterList & bcs = defaultParams->sublist(
"Periodic BCs");
206 bcs.set<
int>(
"Count",0);
209 return defaultParams;
215 std::cout <<
"\n\n**** DEBUG: begin printing source quad mesh exodus file metadata ****\n";
216 stk::mesh::impl::dump_all_meta_info(*(
quadMesh_->getMetaData()), std::cout);
217 std::cout <<
"\n\n**** DEBUG: end printing source quad mesh exodus file metadata ****\n";
223 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(
nDim_-1,0);
226 std::vector<std::string> element_block_names;
227 quadMesh_->getElementBlockNames(element_block_names);
229 for (
const auto& n : element_block_names)
235 std::vector<std::string> sideset_names;
236 quadMesh_->getSidesetNames(sideset_names);
237 for (
const auto& n : sideset_names)
243 std::vector<std::string> nodeset_names;
244 quadMesh_->getNodesetNames(nodeset_names);
245 for (
const auto& n : nodeset_names)
250 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
251 std::vector<std::string> element_block_names2;
252 quadMesh_->getElementBlockNames(element_block_names2);
253 for (
const auto& block_name : element_block_names2)
260 for (
const auto& f : fields) {
262 std::cout <<
"Field=" << f->name() <<
", rank=" << f->entity_rank() << std::endl;
266 if (f->name() !=
"coordinates") {
267 for (
const auto& n : element_block_names)
276 for (
const auto& f : fields) {
278 std::cout <<
"Add Cell Field=" << f->name() <<
", rank=" << f->entity_rank() << std::endl;
280 for (
const auto& n : element_block_names)
292 std::cout <<
"\n\n**** DEBUG: begin printing source linear mesh exodus file metadata ****\n";
293 stk::mesh::impl::dump_all_meta_info(*(mesh.
getMetaData()), std::cout);
294 std::cout <<
"\n\n**** DEBUG: end printing source linear mesh exodus file metadata ****\n";
306 std::vector<std::string> block_names;
307 quadMesh_->getElementBlockNames(block_names);
308 for (
const auto& block_name : block_names) {
311 std::vector<stk::mesh::Entity> elements;
312 quadMesh_->getMyElements(block_name,elements);
315 std::cout <<
"*************************************************" << std::endl;
316 std::cout <<
"block_name=" << block_name <<
", num_my_elements=" << elements.size() << std::endl;
317 std::cout <<
"*************************************************" << std::endl;
320 for (
const auto& element : elements) {
322 const auto element_gid =
quadMesh_->getBulkData()->identifier(element);
326 <<
", block=" << block_name
327 <<
", element entity_id=" << element
328 <<
", gid=" << element_gid << std::endl;
332 std::vector<stk::mesh::EntityId> nodes(
nNodes_);
333 for (
size_t i=0; i <
nNodes_; ++i) {
340 TEUCHOS_ASSERT(node_entity.is_local_offset_valid());
341 const auto node_gid =
quadMesh_->getBulkData()->identifier(node_entity);
342 const double* node_coords =
quadMesh_->getNodeCoordinates(node_entity);
343 std::vector<double> coords_vec(
nDim_);
344 for (
size_t j=0; j <
nDim_; ++j) coords_vec[j] = node_coords[j];
345 mesh.
addNode(node_gid,coords_vec);
349 std::cout <<
"elem gid=" <<
quadMesh_->getBulkData()->identifier(element)
350 <<
", node_gid=" << node_gid <<
", ("
351 << coords_vec[0] <<
"," << coords_vec[1] <<
")\n";
353 std::cout <<
"elem gid=" <<
quadMesh_->getBulkData()->identifier(element)
354 <<
", node_gid=" << node_gid <<
", ("
355 << coords_vec[0] <<
"," << coords_vec[1] <<
"," << coords_vec[2] <<
")\n";
362 auto element_block_part = mesh.
getMetaData()->get_part(block_name);
363 mesh.
addElement(element_descriptor,element_block_part);
374 std::vector<std::string> sideset_names;
375 quadMesh_->getSidesetNames(sideset_names);
376 for (
const auto& sideset_name : sideset_names) {
378 stk::mesh::Part* sideset_part = mesh.
getSideset(sideset_name);
380 std::vector<stk::mesh::Entity> q_sides;
381 quadMesh_->getMySides(sideset_name,q_sides);
384 for (
const auto q_ent : q_sides) {
389 stk::mesh::EntityId ent_gid =
quadMesh_->getBulkData()->identifier(q_ent);
405 Teuchos::RCP<stk::mesh::BulkData> bulkData = mesh.
getBulkData();
406 Teuchos::RCP<stk::mesh::MetaData> metaData = mesh.
getMetaData();
410 stk::mesh::Selector owned_block = metaData->locally_owned_part();
412 std::vector<stk::mesh::Entity> edges;
413 bulkData->get_entities(mesh.
getEdgeRank(), owned_block, edges);
425 for (
const auto&
field : fields) {
428 std::cout <<
"Adding field values for \"" << *
field <<
"\" to the linear mesh!\n";
430 auto field_name =
field->name();
434 if (
field->type_is<
double>() &&
435 field_name !=
"coordinates" &&
436 field_name !=
"PROC_ID" &&
437 field_name !=
"LOAD_BAL") {
440 std::vector<std::string> block_names;
441 quadMesh_->getElementBlockNames(block_names);
442 for (
const auto& block : block_names) {
444 auto* lin_field = lin_mesh.
getCellField(field_name,block);
445 TEUCHOS_ASSERT(lin_field !=
nullptr);
448 auto* q_field =
quadMesh_->getMetaData()->get_field(
quadMesh_->getElementRank(),field_name);
450 TEUCHOS_ASSERT(q_field !=
nullptr);
454 std::vector<stk::mesh::Entity> lin_elements;
456 std::vector<stk::mesh::Entity> q_elements;
457 quadMesh_->getMyElements(block,q_elements);
458 TEUCHOS_ASSERT(lin_elements.size() == q_elements.size());
460 for (
size_t i=0; i < lin_elements.size(); ++i) {
462 TEUCHOS_ASSERT(lin_mesh.
getBulkData()->identifier(lin_elements[i]) ==
463 quadMesh_->getBulkData()->identifier(q_elements[i]));
466 double*
const lin_val =
static_cast<double*
>(stk::mesh::field_data(*lin_field,lin_elements[i]));
467 const double*
const q_val =
static_cast<double*
>(stk::mesh::field_data(*q_field,q_elements[i]));
471 std::cout <<
"field=" << field_name <<
", block=" << block
472 <<
", lin_e(" << lin_mesh.
getBulkData()->identifier(lin_elements[i]) <<
") = " << *lin_val
473 <<
", 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 endModification(const bool find_and_set_shared_nodes_in_stk=true)
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)