https://mooseframework.inl.gov
SingleRankPartitioner.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "SingleRankPartitioner.h"
11 
12 #include "MooseApp.h"
13 
14 #include "libmesh/elem.h"
15 
17 
20 {
22 
23  params.addParam<processor_id_type>("rank", 0, "The MPI rank to assign all elements to.");
24 
25  params.addClassDescription("Assigns element processor ids to a single MPI rank.");
26 
27  return params;
28 }
29 
31  : MoosePartitioner(params), _rank(getParam<processor_id_type>("rank"))
32 {
33  if (_rank >= _communicator.size())
34  paramError("rank", "Cannot be larger than the available number of MPI ranks");
35 }
36 
37 std::unique_ptr<Partitioner>
39 {
40  return _app.getFactory().clone(*this);
41 }
42 
43 void
44 SingleRankPartitioner::_do_partition(MeshBase & mesh, const unsigned int /*n*/)
45 {
46  for (auto & elem_ptr : mesh.active_element_ptr_range())
47  elem_ptr->processor_id() = _rank;
48 }
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
static InputParameters validParams()
registerMooseObject("MooseApp", SingleRankPartitioner)
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Parallel::Communicator & _communicator
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition: MooseApp.h:394
processor_id_type size() const
uint8_t processor_id_type
const processor_id_type _rank
Rank to assign every element to.
static InputParameters validParams()
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:353
SingleRankPartitioner(const InputParameters &params)
Base class for MOOSE partitioner.
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
Partitions a mesh to one MPI rank.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
std::unique_ptr< T > clone(const T &object)
Clones the object object.
Definition: Factory.h:275
virtual std::unique_ptr< Partitioner > clone() const override