13 #include <PanzerAdaptersSTK_config.hpp>
14 #include "Teuchos_StandardParameterEntryValidators.hpp"
21 namespace panzer_stk {
36 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareQuadMeshFactory::buildMesh()");
42 mesh->initialize(parallelMach);
52 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareQuadMeshFactory::buildUncomittedMesh()");
56 machRank_ = stk::parallel_machine_rank(parallelMach);
57 machSize_ = stk::parallel_machine_size(parallelMach);
69 const int maxFactor = 100;
72 int factors[maxFactor];
73 for (
int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
74 for (
int jj = 2; jj < maxFactor; jj++) {
77 int temp = ProcTemp/jj;
78 if (temp*jj == ProcTemp) {
88 for (
int jj = maxFactor-1; jj > 0; jj--) {
89 while (factors[jj] != 0) {
103 "Cannot build SquareQuadMeshFactory. The product of 'X Procs * Y Procs = " <<
xProcs_ <<
"*" << yProcs_ <<
" = " <<
xProcs_*yProcs_
104 <<
"' must equal the number of processors = " <<
machSize_
105 <<
"\n\n\t==> Run the simulation with an appropriate number of processors, i.e. #procs = " <<
xProcs_*yProcs_ <<
".\n");
119 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareQuadMeshFactory::completeMeshConstruction()");
128 #ifndef ENABLE_UNIFORM
137 #ifndef ENABLE_UNIFORM
159 x0_ = paramList->
get<
double>(
"X0");
160 y0_ = paramList->
get<
double>(
"Y0");
162 xf_ = paramList->
get<
double>(
"Xf");
163 yf_ = paramList->
get<
double>(
"Yf");
174 offsetGIDs_ = (paramList->
get<std::string>(
"Offset mesh GIDs above 32-bit int limit") ==
"ON") ?
true :
false;
188 if(defaultParams == Teuchos::null) {
191 defaultParams->
set<
double>(
"X0",0.0);
192 defaultParams->
set<
double>(
"Y0",0.0);
194 defaultParams->
set<
double>(
"Xf",1.0);
195 defaultParams->
set<
double>(
"Yf",1.0);
197 defaultParams->
set<
int>(
"X Blocks",1);
198 defaultParams->
set<
int>(
"Y Blocks",1);
200 defaultParams->
set<
int>(
"X Procs",-1);
201 defaultParams->
set<
int>(
"Y Procs",1);
203 defaultParams->
set<
int>(
"X Elements",5);
204 defaultParams->
set<
int>(
"Y Elements",5);
207 defaultParams->
set<
bool>(
"Create Edge Blocks",
false,
"Create edge blocks in the mesh");
209 defaultParams->
set<std::string>(
"Offset mesh GIDs above 32-bit int limit",
"OFF",
210 "If 64-bit GIDs are supported, the mesh element and node global indices will start at a value greater than 32-bit limit.",
214 bcs.
set<
int>(
"Count",0);
217 return defaultParams;
237 typedef shards::Quadrilateral<4> QuadTopo;
238 const CellTopologyData * ctd = shards::getCellTopologyData<QuadTopo>();
239 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
240 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
249 std::stringstream ebPostfix;
250 ebPostfix <<
"-" << bx <<
"_" << by;
265 #ifndef ENABLE_UNIFORM
272 std::stringstream ss;
273 ss <<
"vertical_" << bx-1;
277 std::stringstream ss;
278 ss <<
"horizontal_" << by-1;
292 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
293 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
306 int myXElems_start = sizeAndStartX.first;
307 int myXElems_end = myXElems_start+sizeAndStartX.second;
308 int myYElems_start = sizeAndStartY.first;
309 int myYElems_end = myYElems_start+sizeAndStartY.second;
313 double deltaX = (
xf_-
x0_)/
double(totalXElems);
314 double deltaY = (
yf_-
y0_)/
double(totalYElems);
316 std::vector<double> coord(2,0.0);
320 if (std::numeric_limits<panzer::GlobalOrdinal>::max() > std::numeric_limits<unsigned int>::max())
321 offset_ = panzer::GlobalOrdinal(std::numeric_limits<unsigned int>::max()) + 1;
325 for(
int nx=myXElems_start;nx<myXElems_end+1;++nx) {
327 for(
int ny=myYElems_start;ny<myYElems_end+1;++ny) {
334 std::stringstream blockName;
335 blockName <<
"eblock-" << xBlock <<
"_" << yBlock;
339 for(
int nx=myXElems_start;nx<myXElems_end;++nx) {
340 for(
int ny=myYElems_start;ny<myYElems_end;++ny) {
341 stk::mesh::EntityId gid = totalXElems*ny+nx+1 +
offset_;
342 std::vector<stk::mesh::EntityId> nodes(4);
343 nodes[0] = nx+1+ny*(totalXElems+1);
344 nodes[1] = nodes[0]+1;
345 nodes[2] = nodes[1]+(totalXElems+1);
346 nodes[3] = nodes[2]-1;
348 for (
int i=0; i < 4; ++i)
360 unsigned int minElements =
nXElems_/size;
361 unsigned int extra =
nXElems_ - minElements*size;
369 nume = minElements+1;
370 start = xProcLoc*(minElements+1);
374 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
377 return std::make_pair(start+
nXElems_*xBlock,nume);
383 unsigned int minElements =
nYElems_/size;
384 unsigned int extra =
nYElems_ - minElements*size;
392 nume = minElements+1;
393 start = yProcLoc*(minElements+1);
397 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
400 return std::make_pair(start+
nYElems_*yBlock,nume);
411 stk::mesh::Part * left = mesh.
getSideset(
"left");
412 stk::mesh::Part * right = mesh.
getSideset(
"right");
413 stk::mesh::Part * top = mesh.
getSideset(
"top");
414 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
416 std::vector<stk::mesh::Part*> vertical;
417 std::vector<stk::mesh::Part*> horizontal;
419 std::stringstream ss;
420 ss <<
"vertical_" << bx-1;
421 vertical.push_back(mesh.
getSideset(ss.str()));
424 std::stringstream ss;
425 ss <<
"horizontal_" << by-1;
426 horizontal.push_back(mesh.
getSideset(ss.str()));
429 std::vector<stk::mesh::Entity> localElmts;
433 std::vector<stk::mesh::Entity>::const_iterator itr;
434 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
435 stk::mesh::Entity element = (*itr);
442 ny = (gid-1) / totalXElems;
443 nx = gid-ny*totalXElems-1;
448 if(nx+1==totalXElems) {
464 if(nx+1!=totalXElems && ((nx+1) %
nXElems_==0)) {
495 if(ny+1==totalYElems) {
513 if(ny+1!=totalYElems && ((ny+1) %
nYElems_==0)) {
532 stk::mesh::Part * lower_left = mesh.
getNodeset(
"lower_left");
533 stk::mesh::Part * origin = mesh.
getNodeset(
"origin");
561 stk::mesh::Selector owned_block = metaData->locally_owned_part();
563 std::vector<stk::mesh::Entity> edges;
564 bulkData->get_entities(mesh.
getEdgeRank(), owned_block, edges);
579 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
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_
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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)