15#include "libmesh/mesh_tools.h"
16#include "libmesh/elem.h"
27 MooseEnum method(
"manual automatic",
"manual");
31 "Whether to determine the grid manually (using nx, ny and nz) or automatically. When using "
32 "the automatic mode, the user can impose a certain value for nx, ny or nz, and the automatic "
33 "factorization will adjust the number of processors in the other directions.");
37 "nx",
"Number of processors in the X direction. Defaults to 1 in manual mode");
39 "ny",
"Number of processors in the Y direction. Defaults to 1 in manual mode");
41 "nz",
"Number of processors in the Z direction. Defaults to 1 in manual mode");
43 params.
addClassDescription(
"Create a uniform grid that overlays the mesh to be partitioned. "
44 "Assign all elements within each cell of the grid to the same "
57std::unique_ptr<Partitioner>
70 unsigned int nx = 1, ny = 1, nz = 1;
74 const auto & min = bounding_box.min();
75 const auto & max = bounding_box.max();
77 auto dim =
mesh.mesh_dimension();
80 nx =
isParamValid(
"nx") ? getParam<unsigned int>(
"nx") : nx;
82 ny =
isParamValid(
"ny") ? getParam<unsigned int>(
"ny") : ny;
84 nz =
isParamValid(
"nz") ? getParam<unsigned int>(
"nz") : nz;
89 paramInfo(
"ny",
"Parameter ignored as mesh is currently of dimension less than 2.");
91 paramInfo(
"nz",
"Parameter ignored as mesh is currently of dimension less than 3.");
94 if (getParam<MooseEnum>(
"grid_computation") ==
"manual")
97 if ((nx * ny * nz) !=
mesh.n_partitions())
98 mooseError(
"Number of grid cells (" + std::to_string(nx * ny * nz) +
99 ") does not match the number of MPI processes (" +
100 std::to_string(
mesh.n_partitions()) +
")");
103 else if (getParam<MooseEnum>(
"grid_computation") ==
"automatic")
106 if (nx * ny * nz >
mesh.n_partitions())
112 "User specified (nx,ny,nz) grid exceeded number of partitions, these parameters "
120 if ((dims[0] > 0 &&
dim == 1 && dims[0] !=
int(
mesh.n_partitions())) ||
121 (dims[0] > 0 && dims[1] > 0 &&
dim == 2 && dims[0] * dims[1] !=
int(
mesh.n_partitions())) ||
122 (dims[0] > 0 && dims[1] > 0 && dims[2] > 0 &&
dim == 3 &&
123 dims[0] * dims[1] * dims[2] !=
int(
mesh.n_partitions())))
129 "User specified grid for the current dimension of the mesh (" +
130 std::to_string(
dim) +
") does not fit the number of partitions (" +
131 std::to_string(
mesh.n_partitions()) +
132 ") and constrain the grid partitioner in every direction, these parameters "
137 MPI_Dims_create(
mesh.n_partitions(),
dim, dims);
152 Real hx = 1., hy = 1., hz = 1., Lx = 1., Ly = 1., Lz = 1.;
153 Lx = max(0) - min(0);
157 Ly = max(1) - min(1);
163 Lz = max(2) - min(2);
168 unsigned int k = 0, j = 0, i = 0;
170 Real coordx = 0, coordy = 0, coordz = 0;
173 for (
auto & elem_ptr :
mesh.active_element_ptr_range())
176 auto centroid = elem_ptr->vertex_average();
178 coordx = centroid(0);
179 mooseAssert(coordx >= min(0) && coordy <= max(0),
180 "element is outside of bounding box along x direction");
183 coordy = centroid(1);
184 mooseAssert(coordy >= min(1) && coordy <= max(1),
185 "element is outside of bounding box along y direction");
189 coordz = centroid(2);
190 mooseAssert(coordz >= min(2) && coordz <= max(2),
191 "element is outside of bounding box along z direction");
196 i = (coordx - min(0)) / hx;
198 j = (coordy - min(1)) / hy;
200 k = (coordz - min(2)) / hz;
202 mooseAssert(i < nx,
"Index calculation is wrong along x direction");
203 mooseAssert(j < ny || ny == 0,
"Index calculation is wrong along y direction");
204 mooseAssert(k < nz || nz == 0,
"Index calculation is wrong along z direction");
206 elem_ptr->processor_id() = k * nx * ny + j * nx + i;
registerMooseObject("MooseApp", GridPartitioner)
void ErrorVector unsigned int
std::unique_ptr< T > clone(const T &object)
Clones the object object.
Partitions a mesh using a regular grid.
virtual ~GridPartitioner()
virtual std::unique_ptr< Partitioner > clone() const override
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
static InputParameters validParams()
GridPartitioner(const InputParameters ¶ms)
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
void paramInfo(const std::string ¶m, Args... args) const
Emits an informational message prefixed with the file and line number of the given param (from the in...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
MooseApp & _app
The MOOSE application this is associated with.
Base class for MOOSE partitioner.
static InputParameters validParams()
void paramWarning(const std::string ¶m, Args... args) const