Skip to content

Commit

Permalink
Add an option for a single subdomain ID for the entire GMG
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud authored and pbehne committed Jun 12, 2024
1 parent 347e774 commit ea59b15
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions framework/src/meshgenerators/GeneratedMeshGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ GeneratedMeshGenerator::validParams()
"The type of element from libMesh to "
"generate (default: linear element for "
"requested dimension)");
params.addParam<std::vector<SubdomainID>>("subdomain_ids",
"Subdomain IDs for each element, default to all zero");
params.addParam<std::vector<SubdomainID>>(
"subdomain_ids",
"Subdomain IDs for each element, default to all zero. If a single number is specified, that "
"subdomain id is used for all element.");
params.addParam<SubdomainName>("subdomain_name",
"If specified, single subdomain name for all elements");

Expand Down Expand Up @@ -189,17 +191,20 @@ GeneratedMeshGenerator::generate()
if (_has_subdomain_ids)
{
auto & bids = getParam<std::vector<SubdomainID>>("subdomain_ids");
if (bids.size() != _nx * _ny * _nz)
if (bids.size() != _nx * _ny * _nz && bids.size() != 1)
paramError("subdomain_ids",
"Size must equal to the product of number of elements in all directions");
"Size must equal to the product of number of elements in all directions, or one.");
for (auto & elem : mesh->element_ptr_range())
{
const Point p = elem->vertex_average();
unsigned int ix = std::floor((p(0) - _xmin) / (_xmax - _xmin) * _nx);
unsigned int iy = std::floor((p(1) - _ymin) / (_ymax - _ymin) * _ny);
unsigned int iz = std::floor((p(2) - _zmin) / (_zmax - _zmin) * _nz);
unsigned int i = iz * _nx * _ny + iy * _nx + ix;
elem->subdomain_id() = bids[i];
if (bids.size() == 1)
elem->subdomain_id() = bids[0];
else
elem->subdomain_id() = bids[i];
}
}

Expand Down

0 comments on commit ea59b15

Please sign in to comment.