https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RandomPartitioner.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 "RandomPartitioner.h"
11
12#include "MooseApp.h"
13#include "MooseMesh.h"
14#include "MooseRandom.h"
15
16#include "libmesh/elem.h"
17
19
22{
24
25 params.addParam<unsigned int>("seed", 0, "Seed for the random generator");
26
27 params.addClassDescription("Assigns element processor ids randomly with a given seed.");
28
29 return params;
30}
31
33 : MoosePartitioner(params), _num_procs(_app.getCommunicator()->size())
34{
35 MooseRandom::seed(getParam<unsigned int>("seed"));
36}
37
39
40std::unique_ptr<Partitioner>
42{
43 return _app.getFactory().clone(*this);
44}
45
46void
47RandomPartitioner::_do_partition(MeshBase & mesh, const unsigned int /*n*/)
48{
49 // Random number is on [0, 1]: scale to number of procs and round down
50 for (auto & elem_ptr : mesh.active_element_ptr_range())
51 elem_ptr->processor_id() = std::floor(MooseRandom::rand() * _num_procs);
52}
registerMooseObject("MooseApp", RandomPartitioner)
std::unique_ptr< T > clone(const T &object)
Clones the object object.
Definition Factory.h:323
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
Base class for MOOSE partitioner.
static InputParameters validParams()
static Real rand()
This method returns the next random number (Real format) from the generator.
Definition MooseRandom.h:50
static void seed(unsigned int seed)
The method seeds the random number generator.
Definition MooseRandom.h:44
Partitions a mesh randomly using element ids as the seed for the generator.
virtual void _do_partition(MeshBase &mesh, const unsigned int n) override
virtual std::unique_ptr< Partitioner > clone() const override
RandomPartitioner(const InputParameters &params)
static InputParameters validParams()
const unsigned int _num_procs
Total number of processors.
MeshBase & mesh