15 #include "libmesh/mesh_tools.h" 16 #include "libmesh/elem.h" 30 params.
addParam<
unsigned int>(
"nx", 1,
"Number of processors in the X direction");
31 params.
addParam<
unsigned int>(
"ny", 1,
"Number of processors in the Y direction");
32 params.
addParam<
unsigned int>(
"nz", 1,
"Number of processors in the Z direction");
34 params.
addClassDescription(
"Create a uniform grid that overlays the mesh to be partitioned. " 35 "Assign all elements within each cell of the grid to the same " 48 std::unique_ptr<Partitioner>
51 return std::make_unique<GridPartitioner>(
_pars);
61 unsigned int nx = 1, ny = 1, nz = 1;
64 auto bounding_box = MeshTools::create_bounding_box(
mesh);
65 const auto &
min = bounding_box.min();
66 const auto &
max = bounding_box.max();
68 auto dim =
mesh.mesh_dimension();
70 nx = getParam<unsigned int>(
"nx");
73 ny = getParam<unsigned int>(
"ny");
76 nz = getParam<unsigned int>(
"nz");
81 if ((nx * ny * nz) !=
mesh.n_partitions())
84 int dims[] = {0, 0, 0};
85 MPI_Dims_create(
mesh.n_partitions(),
dim, dims);
100 Real hx = 1., hy = 1., hz = 1., Lx = 1., Ly = 1., Lz = 1.;
116 unsigned int k = 0, j = 0, i = 0;
118 Real coordx = 0, coordy = 0, coordz = 0;
121 for (
auto & elem_ptr :
mesh.active_element_ptr_range())
124 auto centroid = elem_ptr->vertex_average();
126 coordx = centroid(0);
127 mooseAssert(coordx >=
min(0) && coordy <=
max(0),
128 "element is outside of bounding box along x direction");
131 coordy = centroid(1);
132 mooseAssert(coordy >=
min(1) && coordy <=
max(1),
133 "element is outside of bounding box along y direction");
137 coordz = centroid(2);
138 mooseAssert(coordz >=
min(2) && coordz <=
max(2),
139 "element is outside of bounding box along z direction");
144 i = (coordx -
min(0)) / hx;
146 j = (coordy -
min(1)) / hy;
148 k = (coordz -
min(2)) / hz;
150 mooseAssert(i < nx,
"Index caculation is wrong along x direction");
151 mooseAssert(j < ny,
"Index caculation is wrong along y direction");
152 mooseAssert(k < nz,
"Index caculation is wrong along z direction");
154 elem_ptr->processor_id() = k * nx * ny + j * nx + i;
static InputParameters validParams()
static InputParameters validParams()
virtual ~GridPartitioner()
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
auto max(const L &left, const R &right)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
registerMooseObject("MooseApp", GridPartitioner)
Partitions a mesh using a regular grid.
virtual std::unique_ptr< Partitioner > clone() const override
GridPartitioner(const InputParameters ¶ms)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Base class for MOOSE partitioner.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
auto min(const L &left, const R &right)