Line data Source code
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 : 18 : registerMooseObject("MooseApp", RandomPartitioner); 19 : 20 : InputParameters 21 14409 : RandomPartitioner::validParams() 22 : { 23 14409 : InputParameters params = MoosePartitioner::validParams(); 24 : 25 14409 : params.addParam<unsigned int>("seed", 0, "Seed for the random generator"); 26 : 27 14409 : params.addClassDescription("Assigns element processor ids randomly with a given seed."); 28 : 29 14409 : return params; 30 0 : } 31 : 32 108 : RandomPartitioner::RandomPartitioner(const InputParameters & params) 33 108 : : MoosePartitioner(params), _num_procs(_app.getCommunicator()->size()) 34 : { 35 108 : MooseRandom::seed(getParam<unsigned int>("seed")); 36 108 : } 37 : 38 216 : RandomPartitioner::~RandomPartitioner() {} 39 : 40 : std::unique_ptr<Partitioner> 41 72 : RandomPartitioner::clone() const 42 : { 43 72 : return _app.getFactory().clone(*this); 44 : } 45 : 46 : void 47 32 : RandomPartitioner::_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 3232 : for (auto & elem_ptr : mesh.active_element_ptr_range()) 51 3232 : elem_ptr->processor_id() = std::floor(MooseRandom::rand() * _num_procs); 52 32 : }