45 #include <PanzerAdaptersSTK_config.hpp>
46 #include "Teuchos_StandardParameterEntryValidators.hpp"
53 namespace panzer_stk {
68 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareQuadMeshFactory::buildMesh()");
74 mesh->initialize(parallelMach);
84 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareQuadMeshFactory::buildUncomittedMesh()");
88 machRank_ = stk::parallel_machine_rank(parallelMach);
89 machSize_ = stk::parallel_machine_size(parallelMach);
101 const int maxFactor = 100;
104 int factors[maxFactor];
105 for (
int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
106 for (
int jj = 2; jj < maxFactor; jj++) {
109 int temp = ProcTemp/jj;
110 if (temp*jj == ProcTemp) {
120 for (
int jj = maxFactor-1; jj > 0; jj--) {
121 while (factors[jj] != 0) {
135 "Cannot build SquareQuadMeshFactory. The product of 'X Procs * Y Procs = " <<
xProcs_ <<
"*" << yProcs_ <<
" = " <<
xProcs_*yProcs_
136 <<
"' must equal the number of processors = " <<
machSize_
137 <<
"\n\n\t==> Run the simulation with an appropriate number of processors, i.e. #procs = " <<
xProcs_*yProcs_ <<
".\n");
151 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareQuadMeshFactory::completeMeshConstruction()");
160 #ifndef ENABLE_UNIFORM
169 #ifndef ENABLE_UNIFORM
191 x0_ = paramList->
get<
double>(
"X0");
192 y0_ = paramList->
get<
double>(
"Y0");
194 xf_ = paramList->
get<
double>(
"Xf");
195 yf_ = paramList->
get<
double>(
"Yf");
206 offsetGIDs_ = (paramList->
get<std::string>(
"Offset mesh GIDs above 32-bit int limit") ==
"ON") ?
true :
false;
220 if(defaultParams == Teuchos::null) {
223 defaultParams->
set<
double>(
"X0",0.0);
224 defaultParams->
set<
double>(
"Y0",0.0);
226 defaultParams->
set<
double>(
"Xf",1.0);
227 defaultParams->
set<
double>(
"Yf",1.0);
229 defaultParams->
set<
int>(
"X Blocks",1);
230 defaultParams->
set<
int>(
"Y Blocks",1);
232 defaultParams->
set<
int>(
"X Procs",-1);
233 defaultParams->
set<
int>(
"Y Procs",1);
235 defaultParams->
set<
int>(
"X Elements",5);
236 defaultParams->
set<
int>(
"Y Elements",5);
239 defaultParams->
set<
bool>(
"Create Edge Blocks",
false,
"Create edge blocks in the mesh");
241 defaultParams->
set<std::string>(
"Offset mesh GIDs above 32-bit int limit",
"OFF",
242 "If 64-bit GIDs are supported, the mesh element and node global indices will start at a value greater than 32-bit limit.",
246 bcs.
set<
int>(
"Count",0);
249 return defaultParams;
269 typedef shards::Quadrilateral<4> QuadTopo;
270 const CellTopologyData * ctd = shards::getCellTopologyData<QuadTopo>();
271 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
272 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
281 std::stringstream ebPostfix;
282 ebPostfix <<
"-" << bx <<
"_" << by;
297 #ifndef ENABLE_UNIFORM
304 std::stringstream ss;
305 ss <<
"vertical_" << bx-1;
309 std::stringstream ss;
310 ss <<
"horizontal_" << by-1;
324 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
325 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
338 int myXElems_start = sizeAndStartX.first;
339 int myXElems_end = myXElems_start+sizeAndStartX.second;
340 int myYElems_start = sizeAndStartY.first;
341 int myYElems_end = myYElems_start+sizeAndStartY.second;
345 double deltaX = (
xf_-
x0_)/
double(totalXElems);
346 double deltaY = (
yf_-
y0_)/
double(totalYElems);
348 std::vector<double> coord(2,0.0);
352 if (std::numeric_limits<panzer::GlobalOrdinal>::max() > std::numeric_limits<unsigned int>::max())
353 offset_ = panzer::GlobalOrdinal(std::numeric_limits<unsigned int>::max()) + 1;
357 for(
int nx=myXElems_start;nx<myXElems_end+1;++nx) {
359 for(
int ny=myYElems_start;ny<myYElems_end+1;++ny) {
366 std::stringstream blockName;
367 blockName <<
"eblock-" << xBlock <<
"_" << yBlock;
371 for(
int nx=myXElems_start;nx<myXElems_end;++nx) {
372 for(
int ny=myYElems_start;ny<myYElems_end;++ny) {
373 stk::mesh::EntityId gid = totalXElems*ny+nx+1 +
offset_;
374 std::vector<stk::mesh::EntityId> nodes(4);
375 nodes[0] = nx+1+ny*(totalXElems+1);
376 nodes[1] = nodes[0]+1;
377 nodes[2] = nodes[1]+(totalXElems+1);
378 nodes[3] = nodes[2]-1;
380 for (
int i=0; i < 4; ++i)
392 unsigned int minElements =
nXElems_/size;
393 unsigned int extra =
nXElems_ - minElements*size;
401 nume = minElements+1;
402 start = xProcLoc*(minElements+1);
406 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
409 return std::make_pair(start+
nXElems_*xBlock,nume);
415 unsigned int minElements =
nYElems_/size;
416 unsigned int extra =
nYElems_ - minElements*size;
424 nume = minElements+1;
425 start = yProcLoc*(minElements+1);
429 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
432 return std::make_pair(start+
nYElems_*yBlock,nume);
443 stk::mesh::Part * left = mesh.
getSideset(
"left");
444 stk::mesh::Part * right = mesh.
getSideset(
"right");
445 stk::mesh::Part * top = mesh.
getSideset(
"top");
446 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
448 std::vector<stk::mesh::Part*> vertical;
449 std::vector<stk::mesh::Part*> horizontal;
451 std::stringstream ss;
452 ss <<
"vertical_" << bx-1;
453 vertical.push_back(mesh.
getSideset(ss.str()));
456 std::stringstream ss;
457 ss <<
"horizontal_" << by-1;
458 horizontal.push_back(mesh.
getSideset(ss.str()));
461 std::vector<stk::mesh::Entity> localElmts;
465 std::vector<stk::mesh::Entity>::const_iterator itr;
466 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
467 stk::mesh::Entity element = (*itr);
474 ny = (gid-1) / totalXElems;
475 nx = gid-ny*totalXElems-1;
480 if(nx+1==totalXElems) {
496 if(nx+1!=totalXElems && ((nx+1) %
nXElems_==0)) {
527 if(ny+1==totalYElems) {
545 if(ny+1!=totalYElems && ((ny+1) %
nYElems_==0)) {
564 stk::mesh::Part * lower_left = mesh.
getNodeset(
"lower_left");
565 stk::mesh::Part * origin = mesh.
getNodeset(
"origin");
593 stk::mesh::Selector owned_block = metaData->locally_owned_part();
595 std::vector<stk::mesh::Entity> edges;
596 bulkData->get_entities(mesh.
getEdgeRank(), owned_block, edges);
611 return Teuchos::tuple(i,j);
void addNodeset(const std::string &name)
void initializeWithDefaults()
unsigned entityOwnerRank(stk::mesh::Entity entity) const
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) 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)
void addEdgeBlocks(STK_Interface &mesh) const
Teuchos::Tuple< std::size_t, 2 > procTuple_
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)
std::pair< int, int > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
void buildElements(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
stk::mesh::EntityId offset_
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
bool offsetGIDs_
If true, offset mesh GIDs to exercise 32-bit limits.
void addNodeSets(STK_Interface &mesh) const
std::pair< int, int > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true, const bool buildRefinementSupport=false)
SquareQuadMeshFactory(bool enableRebalance=false)
Constructor.
void rebalance(STK_Interface &mesh) const
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
void addSideSets(STK_Interface &mesh) const
stk::mesh::EntityId elementGlobalId(std::size_t lid) const
void setMyParamList(const RCP< ParameterList > ¶mList)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
static const std::string edgeBlockString
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, STK_Interface &mesh) const
Teuchos::Tuple< std::size_t, 2 > procRankToProcTuple(std::size_t procRank) const
what is the 2D tuple describe this processor distribution
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void addEntitiesToEdgeBlock(std::vector< stk::mesh::Entity > entities, stk::mesh::Part *edgeblock)
void buildSubcells()
force the mesh to build subcells: edges and faces
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
bool isInitialized() const
Has initialize been called on this mesh object?
stk::mesh::Entity findConnectivityById(stk::mesh::Entity src, stk::mesh::EntityRank tgt_rank, unsigned rel_id) const
void addSideset(const std::string &name, const CellTopologyData *ctData)
double getMeshCoord(const int nx, const double deltaX, const double x0) const
stk::mesh::Part * getEdgeBlock(const std::string &name) const
get the block part
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
stk::mesh::EntityRank getEdgeRank() const
~SquareQuadMeshFactory()
Destructor.
void buildLocalElementIDs()
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
std::string edgeBlockName_
void getMyElements(std::vector< stk::mesh::Entity > &elements) const
#define TEUCHOS_ASSERT(assertion_test)
stk::mesh::EntityRank getNodeRank() const
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
void addElementBlock(const std::string &name, const CellTopologyData *ctData)