diff --git a/framework/include/mesh/MooseMesh.h b/framework/include/mesh/MooseMesh.h index 6a067158f40d..b959b7b358a8 100644 --- a/framework/include/mesh/MooseMesh.h +++ b/framework/include/mesh/MooseMesh.h @@ -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; @@ -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. @@ -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; } diff --git a/framework/src/base/Moose.C b/framework/src/base/Moose.C index 93e6775e4684..3a66e1edc986 100644 --- a/framework/src/base/Moose.C +++ b/framework/src/base/Moose.C @@ -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)" diff --git a/framework/src/mesh/MooseMesh.C b/framework/src/mesh/MooseMesh.C index 50654681099e..856550a3de75 100644 --- a/framework/src/mesh/MooseMesh.C +++ b/framework/src/mesh/MooseMesh.C @@ -2247,14 +2247,7 @@ MooseMesh::buildMeshBaseObject(unsigned int dim) std::unique_ptr mesh; if (_use_distributed_mesh) - { mesh = buildTypedMesh(dim); - if (_partitioner_name != "default" && _partitioner_name != "parmetis") - { - _partitioner_name = "parmetis"; - _partitioner_overridden = true; - } - } else mesh = buildTypedMesh(dim); @@ -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 @@ -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 diff --git a/framework/src/partitioner/HierarchicalGridPartitioner.C b/framework/src/partitioner/HierarchicalGridPartitioner.C index 9db225460797..3f93fa72bbe4 100644 --- a/framework/src/partitioner/HierarchicalGridPartitioner.C +++ b/framework/src/partitioner/HierarchicalGridPartitioner.C @@ -58,15 +58,6 @@ HierarchicalGridPartitioner::HierarchicalGridPartitioner(const InputParameters & _ny_procs(getParam("ny_procs")), _nz_procs(getParam("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() {} @@ -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)