45 #include <PanzerAdaptersSTK_config.hpp>
53 namespace panzer_stk {
68 PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::buildMesh()");
73 mesh->initialize(parallelMach);
86 PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::buildUncomittedMesh()");
90 machRank_ = stk::parallel_machine_rank(parallelMach);
91 machSize_ = stk::parallel_machine_size(parallelMach);
98 char diatom_file[1000];
122 strcpy( diatom_file, stl_path.c_str() );
123 strcat( diatom_file,
"stl.diatom" );
124 FILE *fp = fopen( diatom_file,
"w" );
127 printf(
"ERROR: Unable to open %s for writing\n", diatom_file );
131 char stl_fullfile[1000];
132 strcpy( stl_fullfile, stl_path.c_str() );
133 strcat( stl_fullfile, stl_filename.c_str() );
135 fprintf( fp,
" diatom\n" );
136 fprintf( fp,
" package \'box\'\n" );
137 fprintf( fp,
" material 1\n" );
138 fprintf( fp,
" insert stl\n" );
139 fprintf( fp,
" FILE = \'%s\'\n", stl_fullfile );
140 fprintf( fp,
" endinsert\n" );
141 fprintf( fp,
" endpackage\n" );
142 fprintf( fp,
" enddiatom\n" );
151 char * base_exodus_file_name = NULL;
152 char * base_vfrac_file_name = NULL;
153 int nelx, nely, nelz;
173 int smooth_iterations = 7;
175 int gen_sidesets = 4;
176 int adaptive_grid = 0;
180 printf(
"\n Sculpt BBox Min ( %lf, %lf, %lf )\n",
xMin_,
yMin_,
zMin_ );
181 printf(
"\n Sculpt BBox Max ( %lf, %lf, %lf )\n",
xMax_,
yMax_,
zMax_ );
183 int cr_result = Create_Sculptor_Mesh(diatom_file_name,
184 base_exodus_file_name,
185 base_vfrac_file_name,
224 printf(
"Error Generating Sculptor Mesh\n");
233 PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::completeMeshConstruction()");
265 xMin_ = paramList->
get<
double>(
"xMin");
266 yMin_ = paramList->
get<
double>(
"yMin");
267 zMin_ = paramList->
get<
double>(
"zMin");
269 xMax_ = paramList->
get<
double>(
"xMax");
270 yMax_ = paramList->
get<
double>(
"yMax");
271 zMax_ = paramList->
get<
double>(
"zMax");
286 if(defaultParams == Teuchos::null) {
289 defaultParams->
set<
int>(
"xInterval",10);
290 defaultParams->
set<
int>(
"yInterval",10);
291 defaultParams->
set<
int>(
"zInterval",10);
293 defaultParams->
set<
double>(
"xMin",0.0);
294 defaultParams->
set<
double>(
"yMin",0.0);
295 defaultParams->
set<
double>(
"zMin",0.0);
297 defaultParams->
set<
double>(
"xMax",1.0);
298 defaultParams->
set<
double>(
"yMax",1.0);
299 defaultParams->
set<
double>(
"zMax",1.0);
301 defaultParams->
set<std::string>(
"stlFileDir",
"NULL");
302 defaultParams->
set<std::string>(
"stlFileName",
"NULL");
305 bcs.
set<
int>(
"Count",0);
309 return defaultParams;
324 struct MeshStorageStruct *mss = get_sculpt_mesh();
326 int nBlocks_ = mss->num_elem_blk;
327 int nSidesets_ = mss->num_side_sets;
328 int nNodesets_ = mss->num_node_sets;
331 typedef shards::Hexahedron<8> HexTopo;
332 const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
333 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
335 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
336 const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
341 for(
int b = 0; b < nBlocks_; b++){
342 std::stringstream ebPostfix;
343 ebPostfix <<
"-" << mss->block_id[b];
350 machRank_ = stk::parallel_machine_rank(parallelMach);
351 for(
int ict = 0;ict < nSidesets_;ict ++){
352 std::stringstream sPostfix;
353 sPostfix <<
"-" << mss->side_set_id[ict];
354 mesh.
addSideset(
"Sideset"+sPostfix.str(),side_ctd);
358 for(
int nx=0;nx<nNodesets_;nx++) {
359 std::stringstream nPostfix;
360 nPostfix <<
"-" << nx;
370 struct MeshStorageStruct *mss = get_sculpt_mesh();
371 int num_nodes = mss->num_nodes;
374 int dimensionality = 3;
377 int global_node_numbers;
378 for(
int ict = 0; ict < num_nodes; ict ++){
379 global_node_numbers = mss->global_node_numbers[ict];
380 std::vector<double> coord(3, 0.0);
381 coord[0] = mss->coord[0*num_nodes+ict];
382 coord[1] = mss->coord[1*num_nodes+ict];
383 coord[2] = mss->coord[2*num_nodes+ict];
384 mesh.
addNode(global_node_numbers, coord );
396 struct MeshStorageStruct *mss = get_sculpt_mesh();
397 int num_blocks = mss->num_elem_blk;
400 int *block_id =
new int[num_blocks];
402 int *elements =
new int[num_blocks];
403 int *nodes_per_element =
new int[num_blocks];
404 int *element_attributes =
new int[num_blocks];
405 int **elmt_node_linkage =
new int*[num_blocks];
407 for(
int b = 0; b < num_blocks; b++){
408 block_id[b] = mss->block_id[b];
410 elements[b] = mss->elements[b];
411 nodes_per_element[b] = mss->nodes_per_element[b];
412 element_attributes[b] = mss->element_attributes[b];
419 for(
int ib=0;ib<num_blocks;ib++) {
420 buildBlock(parallelMach,mesh, ib, block_id, elm_start, elements, nodes_per_element, element_attributes, elmt_node_linkage );
421 elm_start += elements[ib];
426 void SculptMeshFactory::buildBlock(stk::ParallelMachine parallelMach,
STK_Interface & mesh,
int block_index,
int *block_id,
int elm_start,
int *elements,
int *nodes_per_element,
int *elem_attributes,
int **elmt_node_linkage )
const
429 struct MeshStorageStruct *mss = get_sculpt_mesh();
432 std::stringstream blockName;
433 blockName <<
"eblock-" << block_id[block_index];
442 if(elements[block_index]) {
443 int maximum_nodes = elements[block_index] * nodes_per_element[block_index];
444 elmt_node_linkage[block_index] =
new int[maximum_nodes];
445 for(
int ict = 0;ict < elements[block_index]; ict ++){
446 std::vector<stk::mesh::EntityId> nodes(nodes_per_element[block_index]);
449 for(
int nct = 0; nct < nodes_per_element[block_index]; nct++){
450 elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct] = mss->elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct];
451 nodes[nct] = mss->global_node_numbers[elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct]-1];
456 stk::mesh::EntityId gid = mss->global_element_numbers[elm_start+ ict-1];
462 elmt_node_linkage[block_index] = NULL;
468 for(std::size_t i=0;i<relations.size();i++)
469 if(relations[i].identifier()==ID)
470 return &relations[i];
481 struct MeshStorageStruct *mss = get_sculpt_mesh();
482 int num_side_sets = mss->num_side_sets;
484 int *side_set_id =
new int[num_side_sets];
485 int *num_elements_in_side_set =
new int[num_side_sets];
486 int *num_nodes_in_side_set =
new int[num_side_sets];
487 int *num_df_in_side_set =
new int[num_side_sets];
488 int **side_set_elements =
new int*[num_side_sets];
489 int **side_set_faces =
new int*[num_side_sets];
491 int **side_set_node_counter =
new int*[num_side_sets];
492 int **side_set_nodes =
new int*[num_side_sets];
493 double **side_set_df =
new double*[num_side_sets];
495 for(
int ict = 0;ict < num_side_sets;ict ++){
496 side_set_id[ict] = mss->side_set_id[ict];
499 for(
int i = 0; i < num_side_sets; i++) {
501 std::stringstream sidesetName;
502 sidesetName <<
"Sideset-" << mss->side_set_id[i];
503 stk::mesh::Part * sideset = mesh.
getSideset(sidesetName.str());
506 num_elements_in_side_set[i] = mss->num_elements_in_side_set[i];
507 num_df_in_side_set[i] = mss->num_df_in_side_set[i];
509 int ne = num_elements_in_side_set[i];
510 side_set_elements[i] =
new int[ne];
511 side_set_faces[i] =
new int[ne];
513 side_set_node_counter[i] =
new int[ne];
514 side_set_df[i] =
new double[num_df_in_side_set[i]];
519 for(
int nct = 0; nct < ne; nct ++){
521 std::vector<stk::mesh::EntityId> nodes(4);
523 int sculpt_elem_id = mss->global_element_numbers[ mss->side_set_elements[i][nct]-1 ];
524 int sculpt_face_id = -1 ;
526 std::vector<stk::mesh::Entity> localElmts;
529 std::vector<stk::mesh::Entity>::const_iterator itr;
530 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
531 stk::mesh::Entity element = (*itr);
533 if( element->identifier() == sculpt_elem_id )
535 sculpt_face_id = mss->side_set_faces[i][nct];
537 stk::mesh::EntityId gid = element->identifier();
539 stk::mesh::PairIterRelation relations = element->relations(mesh.
getSideRank());
541 stk::mesh::Entity side =
getRelationByID(sculpt_face_id-1,relations)->entity();
551 if( sculpt_face_id == -1 )
552 printf(
" ERROR: Could not find the element id for a sideset face \n");
563 struct MeshStorageStruct *mss = get_sculpt_mesh();
564 int num_node_sets = mss->num_node_sets;
568 int *node_set_id =
new int[num_node_sets];
569 int *num_nodes_in_node_set =
new int[num_node_sets];
570 int *num_df_in_node_set =
new int[num_node_sets];
571 int **node_set_nodes =
new int*[num_node_sets];
572 double **node_set_df =
new double*[num_node_sets];
574 for(
int ict = 0; ict < num_node_sets; ict ++){
575 node_set_id[ict] = mss->node_set_id[ict];
576 num_nodes_in_node_set[ict] = mss->num_nodes_in_node_set[ict];
577 num_df_in_node_set[ict] = mss->num_df_in_node_set[ict];
580 for(
int i = 0; i < num_node_sets; i++) {
581 node_set_nodes[i] =
new int[num_nodes_in_node_set[i]];
582 node_set_df[i] = NULL;
583 if(num_nodes_in_node_set[i]) {
584 for(
int nct = 0; nct < num_nodes_in_node_set[i];nct ++){
585 node_set_nodes[i][nct] = mss->node_set_nodes[i][nct];
591 for(
int i = 0; i < num_node_sets; i++) {
593 std::stringstream nodesetName;
594 nodesetName <<
"Nodeset-" << mss->node_set_id[i];
595 stk::mesh::Part * nodeset = mesh.
getNodeset(nodesetName.str());
597 for(
int j = 0; j < num_nodes_in_node_set[i]; j++ )
599 int node_id = node_set_nodes[i][j];
603 stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),node_id);
613 void ScupltMeshFactory::addEdgeBlocks(
STK_Interface & mesh)
const
622 std::vector<stk::mesh::Entity> edges;
623 bulkData->get_entities(mesh.
getEdgeRank(),metaData->locally_owned_part(),edges);
624 for(
auto edge : edges) {
631 void ScupltMeshFactory::addFaceBlocks(STK_Interface & mesh)
const
633 mesh.beginModification();
640 std::vector<stk::mesh::Entity> faces;
641 bulkData->get_entities(mesh.getFaceRank(),metaData->locally_owned_part(),faces);
642 for(
auto face : faces) {
643 mesh.addEntityToFaceBlock(face, face_block);
646 mesh.endModification();
658 return Teuchos::tuple(i,j);
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
void addFaceBlocks(STK_Interface &mesh) const
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
void addNodeset(const std::string &name)
int callSculptor(stk::ParallelMachine parallelMach, char *diatom_file) const
void addEntityToNodeset(stk::mesh::Entity entity, stk::mesh::Part *nodeset)
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC, bool &useBBoxSearch)
T & get(const std::string &name, T def_value)
stk::mesh::Part * getElementBlockPart(const std::string &name) const
get the block part
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
stk::mesh::Part * getNodeset(const std::string &name) const
void addEdgeBlock(const std::string &elemBlockName, const std::string &edgeBlockName, const stk::topology &topology)
stk::mesh::Part * getSideset(const std::string &name) const
Teuchos::Tuple< std::size_t, 2 > procRankToProcTuple(std::size_t procRank) const
what is the 2D tuple describe this processor distribution
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
stk::mesh::EntityRank getSideRank() const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true, const bool buildRefinementSupport=false)
void rebalance(STK_Interface &mesh) const
Teuchos::Tuple< std::size_t, 2 > procTuple_
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
void setMyParamList(const RCP< ParameterList > ¶mList)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
static const std::string edgeBlockString
~SculptMeshFactory()
Destructor.
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void buildNodes(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
void buildSubcells()
force the mesh to build subcells: edges and faces
void initializeWithDefaults()
const stk::mesh::Relation * getRelationByID(unsigned ID, stk::mesh::PairIterRelation edges) const
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
void addNodeSets(STK_Interface &mesh) const
bool isInitialized() const
Has initialize been called on this mesh object?
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
void buildBlock(stk::ParallelMachine parallelMach, STK_Interface &mesh, int block_index, int *block_id, int elem_start, int *elements, int *nodes_per_elem, int *elem_attributes, int **elm_node_linkage) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
void addSideset(const std::string &name, const CellTopologyData *ctData)
static const std::string faceBlockString
void addEntityToEdgeBlock(stk::mesh::Entity entity, stk::mesh::Part *edgeblock)
stk::mesh::Part * getEdgeBlock(const std::string &name) const
get the block part
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
stk::mesh::EntityRank getEdgeRank() const
int writeDiatomFile(std::string stl_path, std::string stl_filename, char *diatom_file) const
void buildLocalElementIDs()
void addFaceBlock(const std::string &elemBlockName, const std::string &faceBlockName, const stk::topology &topology)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
stk::mesh::EntityRank getNodeRank() const
SculptMeshFactory()
Constructor.
void addEdgeBlocks(STK_Interface &mesh) const
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
void addSideSets(STK_Interface &mesh) const