45 #include <PanzerAdaptersSTK_config.hpp>
50 namespace panzer_stk {
65 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareTriMeshFactory::buildMesh()");
71 mesh->initialize(parallelMach);
81 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareTriMeshFactory::buildUncomittedMesh()");
85 machRank_ = stk::parallel_machine_rank(parallelMach);
86 machSize_ = stk::parallel_machine_size(parallelMach);
98 const int maxFactor = 100;
101 int factors[maxFactor];
102 for (
int jj = 0; jj < maxFactor; jj++) factors[jj] = 0;
103 for (
int jj = 2; jj < maxFactor; jj++) {
106 int temp = ProcTemp/jj;
107 if (temp*jj == ProcTemp) {
117 for (
int jj = maxFactor-1; jj > 0; jj--) {
118 while (factors[jj] != 0) {
132 "Cannot build SquareTriMeshFactory, the product of \"X Procs\" and \"Y Procs\""
133 " must equal the number of processors.");
146 PANZER_FUNC_TIME_MONITOR(
"panzer::SquareTriMeshFactory::completeMeshConstruction()");
175 x0_ = paramList->
get<
double>(
"X0");
176 y0_ = paramList->
get<
double>(
"Y0");
178 xf_ = paramList->
get<
double>(
"Xf");
179 yf_ = paramList->
get<
double>(
"Yf");
200 if(defaultParams == Teuchos::null) {
203 defaultParams->
set<
double>(
"X0",0.0);
204 defaultParams->
set<
double>(
"Y0",0.0);
206 defaultParams->
set<
double>(
"Xf",1.0);
207 defaultParams->
set<
double>(
"Yf",1.0);
209 defaultParams->
set<
int>(
"X Blocks",1);
210 defaultParams->
set<
int>(
"Y Blocks",1);
212 defaultParams->
set<
int>(
"X Procs",-1);
213 defaultParams->
set<
int>(
"Y Procs",1);
215 defaultParams->
set<
int>(
"X Elements",5);
216 defaultParams->
set<
int>(
"Y Elements",5);
219 bcs.
set<
int>(
"Count",0);
222 return defaultParams;
236 typedef shards::Triangle<> TriTopo;
237 const CellTopologyData * ctd = shards::getCellTopologyData<TriTopo>();
238 const CellTopologyData * side_ctd = shards::CellTopology(ctd).getBaseCellTopologyData(1,0);
247 std::stringstream ebPostfix;
248 ebPostfix <<
"-" << bx <<
"_" << by;
271 for(
int xBlock=0;xBlock<
xBlocks_;xBlock++) {
272 for(
int yBlock=0;yBlock<
yBlocks_;yBlock++) {
285 int myXElems_start = sizeAndStartX.first;
286 int myXElems_end = myXElems_start+sizeAndStartX.second;
287 int myYElems_start = sizeAndStartY.first;
288 int myYElems_end = myYElems_start+sizeAndStartY.second;
292 double deltaX = (
xf_-
x0_)/
double(totalXElems);
293 double deltaY = (
yf_-
y0_)/
double(totalYElems);
295 std::vector<double> coord(2,0.0);
298 for(
int nx=myXElems_start;nx<myXElems_end+1;++nx) {
299 coord[0] = double(nx)*deltaX+
x0_;
300 for(
int ny=myYElems_start;ny<myYElems_end+1;++ny) {
301 coord[1] = double(ny)*deltaY+
y0_;
303 mesh.
addNode(ny*(totalXElems+1)+nx+1,coord);
307 std::stringstream blockName;
308 blockName <<
"eblock-" << xBlock <<
"_" << yBlock;
312 for(
int nx=myXElems_start;nx<myXElems_end;++nx) {
313 for(
int ny=myYElems_start;ny<myYElems_end;++ny) {
314 stk::mesh::EntityId gid_a = 2*(totalXElems*ny+nx+1)-1;
315 stk::mesh::EntityId gid_b = gid_a+1;
316 std::vector<stk::mesh::EntityId> nodes(3);
317 stk::mesh::EntityId sw,se,ne,nw;
318 sw = nx+1+ny*(totalXElems+1);
320 ne = se+(totalXElems+1);
339 unsigned int minElements =
nXElems_/size;
340 unsigned int extra =
nXElems_ - minElements*size;
348 nume = minElements+1;
349 start = xProcLoc*(minElements+1);
353 start = extra*(minElements+1)+(xProcLoc-extra)*minElements;
356 return std::make_pair(start+
nXElems_*xBlock,nume);
362 unsigned int minElements =
nYElems_/size;
363 unsigned int extra =
nYElems_ - minElements*size;
371 nume = minElements+1;
372 start = yProcLoc*(minElements+1);
376 start = extra*(minElements+1)+(yProcLoc-extra)*minElements;
379 return std::make_pair(start+
nYElems_*yBlock,nume);
390 stk::mesh::Part * left = mesh.
getSideset(
"left");
391 stk::mesh::Part * right = mesh.
getSideset(
"right");
392 stk::mesh::Part * top = mesh.
getSideset(
"top");
393 stk::mesh::Part * bottom = mesh.
getSideset(
"bottom");
395 std::vector<stk::mesh::Entity> localElmts;
399 std::vector<stk::mesh::Entity>::const_iterator itr;
400 for(itr=localElmts.begin();itr!=localElmts.end();++itr) {
401 stk::mesh::Entity element = (*itr);
404 bool lower = (gid%2 != 0);
405 std::size_t block = lower ? (gid+1)/2 : gid/2;
407 ny = (block-1) / totalXElems;
408 nx = block-ny*totalXElems-1;
413 if(nx+1==totalXElems && lower) {
421 if(nx==0 && !lower) {
440 if(ny+1==totalYElems && !lower) {
457 stk::mesh::Part * origin = mesh.
getNodeset(
"origin");
462 stk::mesh::Entity node = bulkData->get_entity(mesh.
getNodeRank(),1);
480 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.
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)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > ¶mList)
From ParameterListAcceptor.
#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
stk::mesh::Part * getNodeset(const std::string &name) const
void initialize(stk::ParallelMachine parallelMach, bool setupIO=true)
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)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
SquareTriMeshFactory()
Constructor.
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)
void addNode(stk::mesh::EntityId gid, const std::vector< double > &coord)
void buildSubcells()
force the mesh to build subcells: edges and faces
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)
std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > periodicBCVec_
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)
static void parsePeriodicBCList(const Teuchos::RCP< Teuchos::ParameterList > &pl, std::vector< Teuchos::RCP< const PeriodicBC_MatcherBase > > &periodicBC)
void initializeWithDefaults()