13 #include <PanzerAdaptersSTK_config.hpp>
18 namespace panzer_stk {
33 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareTriMeshFactory::buildMesh()");
39 mesh->initialize(parallelMach);
49 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareTriMeshFactory::buildUncomittedMesh()");
53 machRank_ = stk::parallel_machine_rank(parallelMach);
54 machSize_ = stk::parallel_machine_size(parallelMach);
66 const int maxFactor = 100;
69 int factors[maxFactor];
70 for (
int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
71 for (
int jj = 2; jj < maxFactor; jj++) {
74 int temp = ProcTemp/jj;
75 if (temp*jj == ProcTemp) {
85 for (
int jj = maxFactor-1; jj > 0; jj--) {
86 while (factors[jj] != 0) {
100 "Cannot build SquareTriMeshFactory, the product of \"X Procs\" and \"Y Procs\""
101 " must equal the number of processors.");
115 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareTriMeshFactory::completeMeshConstruction()");
151 x0_ = paramList->
get<
double>(
"X0");
152 y0_ = paramList->
get<
double>(
"Y0");
154 xf_ = paramList->
get<
double>(
"Xf");
155 yf_ = paramList->
get<
double>(
"Yf");
178 if(defaultParams == Teuchos::null) {
181 defaultParams->
set<
double>(
"X0",0.0);
182 defaultParams->
set<
double>(
"Y0",0.0);
184 defaultParams->
set<
double>(
"Xf",1.0);
185 defaultParams->
set<
double>(
"Yf",1.0);
187 defaultParams->
set<
int>(
"X Blocks",1);
188 defaultParams->
set<
int>(
"Y Blocks",1);
190 defaultParams->
set<
int>(
"X Procs",-1);
191 defaultParams->
set<
int>(
"Y Procs",1);
193 defaultParams->
set<
int>(
"X Elements",5);
194 defaultParams->
set<
int>(
"Y Elements",5);
197 defaultParams->
set<
bool>(
"Create Edge Blocks",
false,
"Create edge blocks in the mesh");
200 bcs.
set<
int>(
"Count",0);
203 return defaultParams;
223 typedef shards::Triangle<> TriTopo;
224 const CellTopologyData * ctd = shards::getCellTopologyData<TriTopo>();
225 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
226 const CellTopologyData * edge_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
235 std::stringstream ebPostfix;
236 ebPostfix <<
"-" << bx <<
"_" << by;
264 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
265 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
278 int myXElems_start = sizeAndStartX.first;
279 int myXElems_end = myXElems_start+sizeAndStartX.second;
280 int myYElems_start = sizeAndStartY.first;
281 int myYElems_end = myYElems_start+sizeAndStartY.second;
285 double deltaX = (
xf_-
x0_)/
double(totalXElems);
286 double deltaY = (
yf_-
y0_)/
double(totalYElems);
288 std::vector<double> coord(2,0.0);
291 for(
int nx=myXElems_start;nx<myXElems_end+1;++nx) {
293 for(
int ny=myYElems_start;ny<myYElems_end+1;++ny) {
296 mesh.
addNode(ny*(totalXElems+1)+nx+1,coord);
300 std::stringstream blockName;
301 blockName <<
"eblock-" << xBlock <<
"_" << yBlock;
305 for(
int nx=myXElems_start;nx<myXElems_end;++nx) {
306 for(
int ny=myYElems_start;ny<myYElems_end;++ny) {
307 stk::mesh::EntityId gid_a = 2*(totalXElems*ny+nx+1)-1;
308 stk::mesh::EntityId gid_b = gid_a+1;
309 std::vector<stk::mesh::EntityId> nodes(3);
310 stk::mesh::EntityId sw,se,ne,nw;
311 sw = nx+1+ny*(totalXElems+1);
313 ne = se+(totalXElems+1);
332 unsigned int minElements =
nXElems_/size;
333 unsigned int extra =
nXElems_ - minElements*size;
341 nume = minElements+1;
342 start = xProcLoc*(minElements+1);
346 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
349 return std::make_pair(start+
nXElems_*xBlock,nume);
355 unsigned int minElements =
nYElems_/size;
356 unsigned int extra =
nYElems_ - minElements*size;
364 nume = minElements+1;
365 start = yProcLoc*(minElements+1);
369 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
372 return std::make_pair(start+
nYElems_*yBlock,nume);
383 stk::mesh::Part * left = mesh.
getSideset(
"left");
384 stk::mesh::Part * right = mesh.
getSideset(
"right");
385 stk::mesh::Part * top = mesh.
getSideset(
"top");
386 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
388 std::vector<stk::mesh::Entity> localElmts;
392 std::vector<stk::mesh::Entity>::const_iterator itr;
393 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
394 stk::mesh::Entity element = (*itr);
397 bool lower = (gid%2 != 0);
398 std::size_t block = lower ? (gid+1)/2 : gid/2;
400 ny = (block-1) / totalXElems;
401 nx = block-ny*totalXElems-1;
406 if(nx+1==totalXElems && lower) {
414 if(nx==0 && !lower) {
433 if(ny+1==totalYElems && !lower) {
450 stk::mesh::Part * origin = mesh.
getNodeset(
"origin");
455 stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),1);
473 stk::mesh::Selector owned_block = metaData->locally_owned_part();
475 std::vector<stk::mesh::Entity> edges;
476 bulkData->get_entities(mesh.
getEdgeRank(), owned_block, edges);
491 return Teuchos::tuple(i,j);
virtual Teuchos::RCP< STK_Interface > buildUncommitedMesh(stk::ParallelMachine parallelMach) const
std::pair< int, int > determineYElemSizeAndStart(int yBlock, unsigned int size, unsigned int rank) const
void addNodeset(const std::string &name)
unsigned entityOwnerRank(stk::mesh::Entity entity) const
Teuchos::Tuple< std::size_t, 2 > procTuple_
void addEntityToNodeset(stk::mesh::Entity entity, stk::mesh::Part *nodeset)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
From ParameterListAcceptor.
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
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
std::string edgeBlockName_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void addEntityToSideset(stk::mesh::Entity entity, stk::mesh::Part *sideset)
void addNodeSets(STK_Interface &mesh) const
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)
Teuchos::RCP< STK_Interface > buildMesh(stk::ParallelMachine parallelMach) const
Build the mesh object.
void buildBlock(stk::ParallelMachine machRank, int xBlock, int yBlock, STK_Interface &mesh) const
stk::mesh::Part * getSideset(const std::string &name) const
void buildMetaData(stk::ParallelMachine parallelMach, STK_Interface &mesh) const
~SquareTriMeshFactory()
Destructor.
void addElement(const Teuchos::RCP< ElementDescriptor > &ed, stk::mesh::Part *block)
void addEdgeBlocks(STK_Interface &mesh) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
SquareTriMeshFactory()
Constructor.
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true, const bool buildRefinementSupport=false)
void rebalance(STK_Interface &mesh) const
void addSideSets(STK_Interface &mesh) const
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
void buildElements(stk::ParallelMachine parallelMach, 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 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
std::pair< int, int > determineXElemSizeAndStart(int xBlock, unsigned int size, unsigned int rank) const
bool isInitialized() const
Has initialize been called on this mesh object?
Teuchos::Tuple< std::size_t, 2 > procRankToProcTuple(std::size_t procRank) const
what is the 2D tuple describe this processor distribution
stk::mesh::Entity findConnectivityById(stk::mesh::Entity src, stk::mesh::EntityRank tgt_rank, unsigned rel_id) const
virtual void completeMeshConstruction(STK_Interface &mesh, stk::ParallelMachine parallelMach) 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
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
stk::mesh::EntityRank getEdgeRank() 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
#define TEUCHOS_ASSERT(assertion_test)
stk::mesh::EntityRank getNodeRank() const
void addElementBlock(const std::string &name, const CellTopologyData *ctData)
void initializeWithDefaults()