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 : #pragma once 11 : 12 : #include "MooseTypes.h" 13 : #include "MooseEnumItem.h" 14 : 15 : // Forward declarations 16 : class Assembly; 17 : class FEProblemBase; 18 : class InputParameters; 19 : class MooseRandom; 20 : class RandomData; 21 : template <typename T> 22 : InputParameters validParams(); 23 : 24 : /** 25 : * Interface for objects that need parallel consistent random numbers without patterns over 26 : * the course of multiple runs. 27 : */ 28 : class RandomInterface 29 : { 30 : public: 31 : RandomInterface(const InputParameters & parameters, 32 : FEProblemBase & problem, 33 : THREAD_ID tid, 34 : bool is_nodal); 35 : 36 : ~RandomInterface(); 37 : 38 : static InputParameters validParams(); 39 : 40 : /** 41 : * This interface should be called from a derived class to enable random number 42 : * generation in this object. 43 : */ 44 : void setRandomResetFrequency(ExecFlagType exec_flag); 45 : 46 : /** 47 : * Returns the next random number (long) from the generator tied to this object (elem/node). 48 : */ 49 : unsigned long getRandomLong() const; 50 : 51 : /** 52 : * Returns the next random number (Real) from the generator tied to this object (elem/node). 53 : */ 54 : Real getRandomReal() const; 55 : 56 : /** 57 : * Get the seed for the passed in elem/node id. 58 : * @param id - dof object id 59 : * @return current seed for this id 60 : */ 61 : unsigned int getSeed(std::size_t id); 62 : 63 : /************************************************** 64 : * Data Accessors * 65 : **************************************************/ 66 419 : unsigned int getMasterSeed() const { return _master_seed; } 67 419 : bool isNodal() const { return _is_nodal; } 68 419 : ExecFlagType getResetOnTime() const { return _reset_on; } 69 : 70 : void setRandomDataPointer(RandomData * random_data); 71 : 72 : private: 73 : RandomData * _random_data; 74 : mutable MooseRandom * _generator; 75 : 76 : FEProblemBase & _ri_problem; 77 : const std::string _ri_name; 78 : 79 : unsigned int _master_seed; 80 : bool _is_nodal; 81 : ExecFlagType _reset_on; 82 : 83 : const Node * const & _curr_node; 84 : const Elem * const & _curr_element; 85 : 86 : // friend void FEProblemBase::registerRandomInterface(RandomInterface *random_interface, const 87 : // std::string & name, ExecFlagType exec_flag); 88 : };