Skip to content

Commit

Permalink
Add user-requested partitioners to MeshGenerators
Browse files Browse the repository at this point in the history
Previously user-requested partitioners would go completely ignored by
`MeshGenerators`, e.g. any simulation that used `MeshGenerators` to
construct their mesh probably wasn't getting the partition it wanted. We
solve this by moving the `add_partitioner` task earlier and attaching
the partitioner every time we use the `MooseMesh` to build a `MeshBase`
object.

Closes idaholab#16776
  • Loading branch information
lindsayad authored and jain651 committed Apr 19, 2021
1 parent 58c5a52 commit af68f02
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
16 changes: 15 additions & 1 deletion framework/include/mesh/MooseMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "libmesh/nanoflann.hpp"
#include "libmesh/vector_value.h"
#include "libmesh/point.h"
#include "libmesh/partitioner.h"

// forward declaration
class MooseMesh;
Expand Down Expand Up @@ -1245,7 +1246,7 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf
void cacheInfo();
void freeBndNodes();
void freeBndElems();
void setPartitionerHelper();
void setPartitionerHelper(MeshBase * mesh = nullptr);

private:
// true if the _face_info member needs to be rebuilt/updated.
Expand Down Expand Up @@ -1567,5 +1568,18 @@ MooseMesh::buildTypedMesh(unsigned int dim)
mesh->allow_remote_element_removal(_allow_remote_element_removal);
_app.attachRelationshipManagers(*mesh, *this);

if (_custom_partitioner_requested)
{
// Check of partitioner is supplied (not allowed if custom partitioner is used)
if (!parameters().isParamSetByAddParam("partitioner"))
mooseError("If partitioner block is provided, partitioner keyword cannot be used!");
// Set custom partitioner
if (!_custom_partitioner.get())
mooseError("Custom partitioner requested but not set!");
mesh->partitioner().reset(_custom_partitioner.release());
}
else
setPartitionerHelper(mesh.get());

return mesh;
}
2 changes: 1 addition & 1 deletion framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ addActionTypes(Syntax & syntax)
"(check_copy_nodal_vars)"
"(setup_mesh)"
"(add_geometric_rm)"
"(add_partitioner)"
"(add_mesh_generator)"
"(append_mesh_generator)"
"(execute_mesh_generators)"
"(recover_meta_data)"
"(set_mesh_base)"
"(add_partitioner)"
"(attach_geometric_rm)"
"(init_mesh)"
"(prepare_mesh)"
Expand Down
30 changes: 8 additions & 22 deletions framework/src/mesh/MooseMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -2247,14 +2247,7 @@ MooseMesh::buildMeshBaseObject(unsigned int dim)

std::unique_ptr<MeshBase> mesh;
if (_use_distributed_mesh)
{
mesh = buildTypedMesh<DistributedMesh>(dim);
if (_partitioner_name != "default" && _partitioner_name != "parmetis")
{
_partitioner_name = "parmetis";
_partitioner_overridden = true;
}
}
else
mesh = buildTypedMesh<ReplicatedMesh>(dim);

Expand Down Expand Up @@ -2285,19 +2278,6 @@ MooseMesh::init()

TIME_SECTION(_init_timer);

if (_custom_partitioner_requested)
{
// Check of partitioner is supplied (not allowed if custom partitioner is used)
if (!parameters().isParamSetByAddParam("partitioner"))
mooseError("If partitioner block is provided, partitioner keyword cannot be used!");
// Set custom partitioner
if (!_custom_partitioner.get())
mooseError("Custom partitioner requested but not set!");
getMesh().partitioner().reset(_custom_partitioner.release());
}
else
setPartitionerHelper();

if (_app.isRecovering() && _allow_recovery && _app.isUltimateMaster())
{
// Some partitioners are not idempotent. Some recovery data
Expand Down Expand Up @@ -2971,9 +2951,15 @@ MooseMesh::errorIfDistributedMesh(std::string name) const
}

void
MooseMesh::setPartitionerHelper()
MooseMesh::setPartitionerHelper(MeshBase * const mesh)
{
setPartitioner(getMesh(), _partitioner_name, _use_distributed_mesh, _pars, *this);
if (_use_distributed_mesh && (_partitioner_name != "default" && _partitioner_name != "parmetis"))
{
_partitioner_name = "parmetis";
_partitioner_overridden = true;
}

setPartitioner(mesh ? *mesh : getMesh(), _partitioner_name, _use_distributed_mesh, _pars, *this);
}

void
Expand Down
19 changes: 10 additions & 9 deletions framework/src/partitioner/HierarchicalGridPartitioner.C
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ HierarchicalGridPartitioner::HierarchicalGridPartitioner(const InputParameters &
_ny_procs(getParam<unsigned int>("ny_procs")),
_nz_procs(getParam<unsigned int>("nz_procs"))
{
const auto dim = _mesh.getMesh().spatial_dimension();
if (_ny_procs == 0 && dim > 1)
paramError("ny_procs", "Required for ", dim, "D meshes");
if (_ny_nodes == 0 && dim > 1)
paramError("ny_nodes", "Required for ", dim, "D meshes");
if (_nz_procs == 0 && dim == 3)
paramError("nz_procs", "Required for 3D meshes");
if (_nz_nodes == 0 && dim == 3)
paramError("nz_nodes", "Required for 3D meshes");
}

HierarchicalGridPartitioner::~HierarchicalGridPartitioner() {}
Expand All @@ -80,6 +71,16 @@ HierarchicalGridPartitioner::clone() const
void
HierarchicalGridPartitioner::_do_partition(MeshBase & mesh, const unsigned int /*n*/)
{
const auto dim = mesh.spatial_dimension();
if (_ny_procs == 0 && dim > 1)
paramError("ny_procs", "Required for ", dim, "D meshes");
if (_ny_nodes == 0 && dim > 1)
paramError("ny_nodes", "Required for ", dim, "D meshes");
if (_nz_procs == 0 && dim == 3)
paramError("nz_procs", "Required for 3D meshes");
if (_nz_nodes == 0 && dim == 3)
paramError("nz_nodes", "Required for 3D meshes");

auto total_nodes = _nx_nodes;

if (mesh.spatial_dimension() >= 2)
Expand Down

0 comments on commit af68f02

Please sign in to comment.