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];
 
  121   strcpy( diatom_file, stl_path.c_str() );
 
  122   strcat( diatom_file, 
"stl.diatom" );
 
  123   FILE *fp = fopen( diatom_file, 
"w" );
 
  126     printf( 
"ERROR: Unable to open %s for writing\n", diatom_file );
 
  130   char stl_fullfile[1000];
 
  131   strcpy( stl_fullfile, stl_path.c_str() );
 
  132   strcat( stl_fullfile, stl_filename.c_str() );
 
  134   fprintf( fp, 
"  diatom\n" );
 
  135   fprintf( fp, 
"    package \'box\'\n" );
 
  136   fprintf( fp, 
"      material 1\n" );
 
  137   fprintf( fp, 
"      insert stl\n" );
 
  138   fprintf( fp, 
"        FILE = \'%s\'\n", stl_fullfile );
 
  139   fprintf( fp, 
"      endinsert\n" );
 
  140   fprintf( fp, 
"    endpackage\n" );
 
  141   fprintf( fp, 
"  enddiatom\n" );
 
  150   char * base_exodus_file_name = NULL;
 
  151   char * base_vfrac_file_name = NULL;
 
  152   int nelx, nely, nelz; 
 
  172   int smooth_iterations = 7;
 
  174   int gen_sidesets = 4; 
 
  175   int adaptive_grid = 0;  
 
  179   printf(
"\n Sculpt BBox Min ( %lf, %lf, %lf )\n", 
xMin_, 
yMin_, 
zMin_ );
 
  180   printf(
"\n Sculpt BBox Max ( %lf, %lf, %lf )\n", 
xMax_, 
yMax_, 
zMax_ );
 
  182   int cr_result = Create_Sculptor_Mesh(diatom_file_name,
 
  183                base_exodus_file_name,
 
  184                                        base_vfrac_file_name,
 
  223   printf(
"Error Generating Sculptor Mesh\n");
 
  232    PANZER_FUNC_TIME_MONITOR(
"panzer::SculptMeshFactory::completeMeshConstruction()");
 
  260    xMin_ = paramList->
get<
double>(
"xMin");
 
  261    yMin_ = paramList->
get<
double>(
"yMin");
 
  262    zMin_ = paramList->
get<
double>(
"zMin");
 
  264    xMax_ = paramList->
get<
double>(
"xMax");
 
  265    yMax_ = paramList->
get<
double>(
"yMax");
 
  266    zMax_ = paramList->
get<
double>(
"zMax");
 
  281    if(defaultParams == Teuchos::null) {
 
  284       defaultParams->
set<
int>(
"xInterval",10);
 
  285       defaultParams->
set<
int>(
"yInterval",10);
 
  286       defaultParams->
set<
int>(
"zInterval",10);
 
  288       defaultParams->
set<
double>(
"xMin",0.0);
 
  289       defaultParams->
set<
double>(
"yMin",0.0);
 
  290       defaultParams->
set<
double>(
"zMin",0.0);
 
  292       defaultParams->
set<
double>(
"xMax",1.0);
 
  293       defaultParams->
set<
double>(
"yMax",1.0);
 
  294       defaultParams->
set<
double>(
"zMax",1.0);
 
  296       defaultParams->
set<std::string>(
"stlFileDir", 
"NULL");
 
  297       defaultParams->
set<std::string>(
"stlFileName", 
"NULL");
 
  300       bcs.
set<
int>(
"Count",0); 
 
  304    return defaultParams;
 
  319    struct MeshStorageStruct *mss = get_sculpt_mesh();
 
  321    int nBlocks_ = mss->num_elem_blk;
 
  322    int nSidesets_ = mss->num_side_sets;
 
  323    int nNodesets_ = mss->num_node_sets;
 
  326    typedef shards::Hexahedron<8> HexTopo;
 
  327    const CellTopologyData * ctd = shards::getCellTopologyData<HexTopo>();
 
  328    const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(2,0);
 
  333    for( 
int b = 0; b < nBlocks_; b++){
 
  334       std::stringstream ebPostfix;
 
  335       ebPostfix << 
"-" << mss->block_id[b];
 
  342      machRank_ = stk::parallel_machine_rank(parallelMach); 
 
  343      for(
int ict = 0;ict < nSidesets_;ict ++){
 
  344         std::stringstream sPostfix;
 
  345         sPostfix << 
"-" << mss->side_set_id[ict];
 
  346         mesh.
addSideset(
"Sideset"+sPostfix.str(),side_ctd);
 
  350    for(
int nx=0;nx<nNodesets_;nx++) {
 
  351      std::stringstream nPostfix;
 
  352      nPostfix << 
"-" << nx;
 
  360    struct MeshStorageStruct *mss = get_sculpt_mesh();
 
  361    int num_nodes = mss->num_nodes;
 
  364   int dimensionality = 3;
 
  367     int global_node_numbers;
 
  368     for(
int ict = 0; ict < num_nodes; ict ++){
 
  369       global_node_numbers = mss->global_node_numbers[ict];
 
  370       std::vector<double> coord(3, 0.0);
 
  371       coord[0] = mss->coord[0*num_nodes+ict];
 
  372       coord[1] = mss->coord[1*num_nodes+ict];
 
  373       coord[2] = mss->coord[2*num_nodes+ict];
 
  374       mesh.
addNode(global_node_numbers, coord );
 
  386    struct MeshStorageStruct *mss = get_sculpt_mesh();
 
  387    int num_blocks  = mss->num_elem_blk;
 
  390    int *block_id = 
new int[num_blocks];
 
  392    int *elements = 
new int[num_blocks];
 
  393    int *nodes_per_element = 
new int[num_blocks];
 
  394    int *element_attributes = 
new int[num_blocks];
 
  395    int **elmt_node_linkage = 
new int*[num_blocks];
 
  397    for(
int b = 0; b < num_blocks; b++){
 
  398       block_id[b] = mss->block_id[b];
 
  400       elements[b] = mss->elements[b];
 
  401       nodes_per_element[b] = mss->nodes_per_element[b];
 
  402       element_attributes[b] = mss->element_attributes[b];
 
  409    for(
int ib=0;ib<num_blocks;ib++) {
 
  410      buildBlock(parallelMach,mesh, ib, block_id, elm_start, elements, nodes_per_element, element_attributes, elmt_node_linkage );
 
  411      elm_start += elements[ib];
 
  416 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 
  419   struct MeshStorageStruct *mss = get_sculpt_mesh();
 
  422    std::stringstream blockName;
 
  423    blockName << 
"eblock-" << block_id[block_index];
 
  432       if(elements[block_index]) {
 
  433        int maximum_nodes = elements[block_index] * nodes_per_element[block_index];
 
  434        elmt_node_linkage[block_index]        = 
new int[maximum_nodes];
 
  435        for(
int ict = 0;ict < elements[block_index]; ict ++){
 
  436          std::vector<stk::mesh::EntityId> nodes(nodes_per_element[block_index]);
 
  439          for(
int nct = 0; nct < nodes_per_element[block_index]; nct++){
 
  440             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];
 
  441             nodes[nct] =  mss->global_node_numbers[elmt_node_linkage[block_index][(ict*nodes_per_element[block_index])+nct]-1];
 
  446          stk::mesh::EntityId gid = mss->global_element_numbers[elm_start+ ict-1];
 
  452         elmt_node_linkage[block_index] = NULL;
 
  458    for(std::size_t i=0;i<relations.size();i++) 
 
  459       if(relations[i].identifier()==ID)
 
  460          return &relations[i];
 
  471     struct MeshStorageStruct *mss = get_sculpt_mesh();
 
  472     int num_side_sets  = mss->num_side_sets;
 
  474     int *side_set_id = 
new int[num_side_sets];
 
  475     int *num_elements_in_side_set = 
new int[num_side_sets];
 
  476     int *num_nodes_in_side_set = 
new int[num_side_sets];
 
  477     int *num_df_in_side_set = 
new int[num_side_sets];
 
  478     int **side_set_elements = 
new int*[num_side_sets];
 
  479     int **side_set_faces = 
new int*[num_side_sets];
 
  481     int **side_set_node_counter = 
new int*[num_side_sets];
 
  482     int **side_set_nodes = 
new int*[num_side_sets];
 
  483     double **side_set_df = 
new double*[num_side_sets];
 
  485     for(
int ict = 0;ict < num_side_sets;ict ++){
 
  486         side_set_id[ict] = mss->side_set_id[ict];
 
  489    for(
int i = 0; i < num_side_sets; i++) {
 
  491       std::stringstream sidesetName;
 
  492       sidesetName << 
"Sideset-" << mss->side_set_id[i];
 
  493       stk::mesh::Part * sideset = mesh.
getSideset(sidesetName.str());
 
  496       num_elements_in_side_set[i] = mss->num_elements_in_side_set[i];
 
  497       num_df_in_side_set[i] = mss->num_df_in_side_set[i];
 
  499       int ne = num_elements_in_side_set[i];
 
  500       side_set_elements[i] = 
new int[ne];
 
  501       side_set_faces[i] = 
new int[ne];
 
  503       side_set_node_counter[i] = 
new int[ne];
 
  504       side_set_df[i] = 
new double[num_df_in_side_set[i]];
 
  509         for(
int nct = 0; nct < ne; nct ++){
 
  511           std::vector<stk::mesh::EntityId> nodes(4);
 
  513           int sculpt_elem_id =  mss->global_element_numbers[ mss->side_set_elements[i][nct]-1 ]; 
 
  514           int sculpt_face_id = -1 ;
 
  516           std::vector<stk::mesh::Entity> localElmts;
 
  519           std::vector<stk::mesh::Entity>::const_iterator itr;
 
  520           for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
 
  521             stk::mesh::Entity element = (*itr);
 
  523             if( element->identifier() == sculpt_elem_id )
 
  525               sculpt_face_id =  mss->side_set_faces[i][nct];
 
  527               stk::mesh::EntityId gid = element->identifier();
 
  529               stk::mesh::PairIterRelation relations = element->relations(mesh.
getSideRank());
 
  531               stk::mesh::Entity side = 
getRelationByID(sculpt_face_id-1,relations)->entity();
 
  541          if( sculpt_face_id == -1 )
 
  542             printf(
" ERROR:  Could not find the element id for a sideset face \n");
 
  553     struct MeshStorageStruct *mss = get_sculpt_mesh();
 
  554     int num_node_sets  = mss->num_node_sets;
 
  558       int *node_set_id = 
new int[num_node_sets];
 
  559       int *num_nodes_in_node_set = 
new int[num_node_sets];
 
  560       int *num_df_in_node_set = 
new int[num_node_sets];
 
  561       int **node_set_nodes = 
new int*[num_node_sets];
 
  562       double **node_set_df = 
new double*[num_node_sets];
 
  564       for(
int ict = 0; ict < num_node_sets; ict ++){
 
  565         node_set_id[ict] = mss->node_set_id[ict];
 
  566         num_nodes_in_node_set[ict] = mss->num_nodes_in_node_set[ict];
 
  567         num_df_in_node_set[ict] = mss->num_df_in_node_set[ict];
 
  570       for(
int i = 0; i < num_node_sets; i++) {
 
  571         node_set_nodes[i] = 
new int[num_nodes_in_node_set[i]];
 
  572         node_set_df[i] = NULL;
 
  573         if(num_nodes_in_node_set[i]) {
 
  574           for(
int nct = 0; nct < num_nodes_in_node_set[i];nct ++){
 
  575             node_set_nodes[i][nct] = mss->node_set_nodes[i][nct];
 
  581       for(
int i = 0; i < num_node_sets; i++) {
 
  583         std::stringstream nodesetName;
 
  584         nodesetName << 
"Nodeset-" << mss->node_set_id[i];
 
  585         stk::mesh::Part * nodeset = mesh.
getNodeset(nodesetName.str());
 
  587         for( 
int j = 0; j < num_nodes_in_node_set[i]; j++ )
 
  589            int node_id = node_set_nodes[i][j];
 
  593               stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),node_id);
 
  614    return Teuchos::tuple(i,j);
 
void buildMetaData(stk::ParallelMachine parallelMach, 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)
T & get(const std::string &name, T def_value)
stk::mesh::Part * getElementBlockPart(const std::string &name) const 
get the block count 
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 initialize(stk::ParallelMachine parallelMach, bool setupIO=true)
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 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)
~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 
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)
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor. 
int writeDiatomFile(std::string stl_path, std::string stl_filename, char *diatom_file) const 
void buildLocalElementIDs()
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 addElementBlock(const std::string &name, const CellTopologyData *ctData)
void addSideSets(STK_Interface &mesh) const 
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC)