13 #include <PanzerAdaptersSTK_config.hpp>
21 namespace panzer_stk {
36 PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::buildMesh()");
41 mesh->initialize(parallelMach);
54 PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::buildUncomittedMesh()");
58 machRank_ = stk::parallel_machine_rank(parallelMach);
59 machSize_ = stk::parallel_machine_size(parallelMach);
66 char diatom_file[1000];
90 strcpy( diatom_file, stl_path.c_str() );
91 strcat( diatom_file,
"stl.diatom" );
92 FILE *fp = fopen( diatom_file,
"w" );
95 printf(
"ERROR: Unable to open %s for writing\n", diatom_file );
99 char stl_fullfile[1000];
100 strcpy( stl_fullfile, stl_path.c_str() );
101 strcat( stl_fullfile, stl_filename.c_str() );
103 fprintf( fp,
" diatom\n" );
104 fprintf( fp,
" package \'box\'\n" );
105 fprintf( fp,
" material 1\n" );
106 fprintf( fp,
" insert stl\n" );
107 fprintf( fp,
" FILE = \'%s\'\n", stl_fullfile );
108 fprintf( fp,
" endinsert\n" );
109 fprintf( fp,
" endpackage\n" );
110 fprintf( fp,
" enddiatom\n" );
119 char * base_exodus_file_name = NULL;
120 char * base_vfrac_file_name = NULL;
121 int nelx, nely, nelz;
141 int smooth_iterations = 7;
143 int gen_sidesets = 4;
144 int adaptive_grid = 0;
148 printf(
"\n Sculpt BBox Min ( %lf, %lf, %lf )\n",
xMin_,
yMin_,
zMin_ );
149 printf(
"\n Sculpt BBox Max ( %lf, %lf, %lf )\n",
xMax_,
yMax_,
zMax_ );
151 int cr_result = Create_Sculptor_Mesh(diatom_file_name,
152 base_exodus_file_name,
153 base_vfrac_file_name,
192 printf(
"Error Generating Sculptor Mesh\n");
201 PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::completeMeshConstruction()");
233 xMin_ = paramList->
get<
double>(
"xMin");
234 yMin_ = paramList->
get<
double>(
"yMin");
235 zMin_ = paramList->
get<
double>(
"zMin");
237 xMax_ = paramList->
get<
double>(
"xMax");
238 yMax_ = paramList->
get<
double>(
"yMax");
239 zMax_ = paramList->
get<
double>(
"zMax");
254 if(defaultParams == Teuchos::null) {
257 defaultParams->
set<
int>(
"xInterval",10);
258 defaultParams->
set<
int>(
"yInterval",10);
259 defaultParams->
set<
int>(
"zInterval",10);
261 defaultParams->
set<
double>(
"xMin",0.0);
262 defaultParams->
set<
double>(
"yMin",0.0);
263 defaultParams->
set<
double>(
"zMin",0.0);
265 defaultParams->
set<
double>(
"xMax",1.0);
266 defaultParams->
set<
double>(
"yMax",1.0);
267 defaultParams->
set<
double>(
"zMax",1.0);
269 defaultParams->
set<std::string>(
"stlFileDir",
"NULL");
270 defaultParams->
set<std::string>(
"stlFileName",
"NULL");
273 bcs.
set<
int>(
"Count",0);
277 return defaultParams;
292 struct MeshStorageStruct *mss = get_sculpt_mesh();
294 int nBlocks_ = mss->num_elem_blk;
295 int nSidesets_ = mss->num_side_sets;
296 int nNodesets_ = mss->num_node_sets;
299 typedef shards::Hexahedron<8> HexTopo;
300 const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
301 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
303 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
304 const CellTopologyData * face_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
309 for(
int b = 0; b < nBlocks_; b++){
310 std::stringstream ebPostfix;
311 ebPostfix <<
"-" << mss->block_id[b];
318 machRank_ = stk::parallel_machine_rank(parallelMach);
319 for(
int ict = 0;ict < nSidesets_;ict ++){
320 std::stringstream sPostfix;
321 sPostfix <<
"-" << mss->side_set_id[ict];
322 mesh.
addSideset(
"Sideset"+sPostfix.str(),side_ctd);
326 for(
int nx=0;nx<nNodesets_;nx++) {
327 std::stringstream nPostfix;
328 nPostfix <<
"-" << nx;
338 struct MeshStorageStruct *mss = get_sculpt_mesh();
339 int num_nodes = mss->num_nodes;
342 int dimensionality = 3;
345 int global_node_numbers;
346 for(
int ict = 0; ict < num_nodes; ict ++){
347 global_node_numbers = mss->global_node_numbers[ict];
348 std::vector<double> coord(3, 0.0);
349 coord[0] = mss->coord[0*num_nodes+ict];
350 coord[1] = mss->coord[1*num_nodes+ict];
351 coord[2] = mss->coord[2*num_nodes+ict];
352 mesh.
addNode(global_node_numbers, coord );
364 struct MeshStorageStruct *mss = get_sculpt_mesh();
365 int num_blocks = mss->num_elem_blk;
368 int *block_id =
new int[num_blocks];
370 int *elements =
new int[num_blocks];
371 int *nodes_per_element =
new int[num_blocks];
372 int *element_attributes =
new int[num_blocks];
373 int **elmt_node_linkage =
new int*[num_blocks];
375 for(
int b = 0; b < num_blocks; b++){
376 block_id[b] = mss->block_id[b];
378 elements[b] = mss->elements[b];
379 nodes_per_element[b] = mss->nodes_per_element[b];
380 element_attributes[b] = mss->element_attributes[b];
387 for(
int ib=0;ib<num_blocks;ib++) {
388 buildBlock(parallelMach,mesh, ib, block_id, elm_start, elements, nodes_per_element, element_attributes, elmt_node_linkage );
389 elm_start += elements[ib];
394 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
397 struct MeshStorageStruct *mss = get_sculpt_mesh();
400 std::stringstream blockName;
401 blockName <<
"eblock-" << block_id[block_index];
410 if(elements[block_index]) {
411 int maximum_nodes = elements[block_index] * nodes_per_element[block_index];
412 elmt_node_linkage[block_index] =
new int[maximum_nodes];
413 for(
int ict = 0;ict < elements[block_index]; ict ++){
414 std::vector<stk::mesh::EntityId> nodes(nodes_per_element[block_index]);
417 for(
int nct = 0; nct < nodes_per_element[block_index]; nct++){
418 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];
419 nodes[nct] = mss->global_node_numbers[elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct]-1];
424 stk::mesh::EntityId gid = mss->global_element_numbers[elm_start+ ict-1];
430 elmt_node_linkage[block_index] = NULL;
436 for(std::size_t i=0;i<relations.size();i++)
437 if(relations[i].identifier()==ID)
438 return &relations[i];
449 struct MeshStorageStruct *mss = get_sculpt_mesh();
450 int num_side_sets = mss->num_side_sets;
452 int *side_set_id =
new int[num_side_sets];
453 int *num_elements_in_side_set =
new int[num_side_sets];
454 int *num_nodes_in_side_set =
new int[num_side_sets];
455 int *num_df_in_side_set =
new int[num_side_sets];
456 int **side_set_elements =
new int*[num_side_sets];
457 int **side_set_faces =
new int*[num_side_sets];
459 int **side_set_node_counter =
new int*[num_side_sets];
460 int **side_set_nodes =
new int*[num_side_sets];
461 double **side_set_df =
new double*[num_side_sets];
463 for(
int ict = 0;ict < num_side_sets;ict ++){
464 side_set_id[ict] = mss->side_set_id[ict];
467 for(
int i = 0; i < num_side_sets; i++) {
469 std::stringstream sidesetName;
470 sidesetName <<
"Sideset-" << mss->side_set_id[i];
471 stk::mesh::Part * sideset = mesh.
getSideset(sidesetName.str());
474 num_elements_in_side_set[i] = mss->num_elements_in_side_set[i];
475 num_df_in_side_set[i] = mss->num_df_in_side_set[i];
477 int ne = num_elements_in_side_set[i];
478 side_set_elements[i] =
new int[ne];
479 side_set_faces[i] =
new int[ne];
481 side_set_node_counter[i] =
new int[ne];
482 side_set_df[i] =
new double[num_df_in_side_set[i]];
487 for(
int nct = 0; nct < ne; nct ++){
489 std::vector<stk::mesh::EntityId> nodes(4);
491 int sculpt_elem_id = mss->global_element_numbers[ mss->side_set_elements[i][nct]-1 ];
492 int sculpt_face_id = -1 ;
494 std::vector<stk::mesh::Entity> localElmts;
497 std::vector<stk::mesh::Entity>::const_iterator itr;
498 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
499 stk::mesh::Entity element = (*itr);
501 if( element->identifier() == sculpt_elem_id )
503 sculpt_face_id = mss->side_set_faces[i][nct];
505 stk::mesh::EntityId gid = element->identifier();
507 stk::mesh::PairIterRelation relations = element->relations(mesh.
getSideRank());
509 stk::mesh::Entity side =
getRelationByID(sculpt_face_id-1,relations)->entity();
519 if( sculpt_face_id == -1 )
520 printf(
" ERROR: Could not find the element id for a sideset face \n");
531 struct MeshStorageStruct *mss = get_sculpt_mesh();
532 int num_node_sets = mss->num_node_sets;
536 int *node_set_id =
new int[num_node_sets];
537 int *num_nodes_in_node_set =
new int[num_node_sets];
538 int *num_df_in_node_set =
new int[num_node_sets];
539 int **node_set_nodes =
new int*[num_node_sets];
540 double **node_set_df =
new double*[num_node_sets];
542 for(
int ict = 0; ict < num_node_sets; ict ++){
543 node_set_id[ict] = mss->node_set_id[ict];
544 num_nodes_in_node_set[ict] = mss->num_nodes_in_node_set[ict];
545 num_df_in_node_set[ict] = mss->num_df_in_node_set[ict];
548 for(
int i = 0; i < num_node_sets; i++) {
549 node_set_nodes[i] =
new int[num_nodes_in_node_set[i]];
550 node_set_df[i] = NULL;
551 if(num_nodes_in_node_set[i]) {
552 for(
int nct = 0; nct < num_nodes_in_node_set[i];nct ++){
553 node_set_nodes[i][nct] = mss->node_set_nodes[i][nct];
559 for(
int i = 0; i < num_node_sets; i++) {
561 std::stringstream nodesetName;
562 nodesetName <<
"Nodeset-" << mss->node_set_id[i];
563 stk::mesh::Part * nodeset = mesh.
getNodeset(nodesetName.str());
565 for(
int j = 0; j < num_nodes_in_node_set[i]; j++ )
567 int node_id = node_set_nodes[i][j];
571 stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),node_id);
581 void ScupltMeshFactory::addEdgeBlocks(
STK_Interface & mesh)
const
590 std::vector<stk::mesh::Entity> edges;
591 bulkData->get_entities(mesh.
getEdgeRank(),metaData->locally_owned_part(),edges);
592 for(
auto edge : edges) {
599 void ScupltMeshFactory::addFaceBlocks(STK_Interface & mesh)
const
601 mesh.beginModification();
608 std::vector<stk::mesh::Entity> faces;
609 bulkData->get_entities(mesh.getFaceRank(),metaData->locally_owned_part(),faces);
610 for(
auto face : faces) {
611 mesh.addEntityToFaceBlock(face, face_block);
614 mesh.endModification();
626 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
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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