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 : #ifdef MOOSE_KOKKOS_ENABLED 37 : /** 38 : * Special constructor used for Kokkos functor copy during parallel dispatch 39 : */ 40 : RandomInterface(const RandomInterface & object, const Moose::Kokkos::FunctorCopy & key); 41 : #endif 42 : 43 : ~RandomInterface(); 44 : 45 : static InputParameters validParams(); 46 : 47 : /** 48 : * This interface should be called from a derived class to enable random number 49 : * generation in this object. 50 : */ 51 : void setRandomResetFrequency(ExecFlagType exec_flag); 52 : 53 : /** 54 : * Returns the next random number (long) from the generator tied to this object (elem/node). 55 : */ 56 : unsigned long getRandomLong() const; 57 : 58 : /** 59 : * Returns the next random number (Real) from the generator tied to this object (elem/node). 60 : */ 61 : Real getRandomReal() const; 62 : 63 : /** 64 : * Get the seed for the passed in elem/node id. 65 : * @param id - dof object id 66 : * @return current seed for this id 67 : */ 68 : unsigned int getSeed(std::size_t id); 69 : 70 : /************************************************** 71 : * Data Accessors * 72 : **************************************************/ 73 456 : unsigned int getMasterSeed() const { return _master_seed; } 74 456 : bool isNodal() const { return _is_nodal; } 75 456 : ExecFlagType getResetOnTime() const { return _reset_on; } 76 : 77 : void setRandomDataPointer(RandomData * random_data); 78 : 79 : private: 80 : RandomData * _random_data; 81 : mutable MooseRandom * _generator; 82 : 83 : FEProblemBase & _ri_problem; 84 : const std::string _ri_name; 85 : 86 : unsigned int _master_seed; 87 : bool _is_nodal; 88 : ExecFlagType _reset_on; 89 : 90 : const Node * const & _curr_node; 91 : const Elem * const & _curr_element; 92 : 93 : // friend void FEProblemBase::registerRandomInterface(RandomInterface *random_interface, const 94 : // std::string & name, ExecFlagType exec_flag); 95 : };