Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 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 : /** 13 : * Veneer to build userobjects that generate a normaly distributed random 14 : * number once per timestep for every quadrature point 15 : * in a way that the integral over all random numbers is zero. 16 : * 17 : * \see ConservedNormalNoise 18 : * \see ConservedMaskedNormalNoise 19 : */ 20 : template <class T> 21 : class ConservedNormalNoiseVeneer : public T 22 : { 23 : public: 24 : ConservedNormalNoiseVeneer(const InputParameters & parameters); 25 : 26 : protected: 27 : Real getQpRandom(); 28 : 29 : private: 30 : unsigned int _phase; 31 : Real _Z2; 32 : }; 33 : 34 : template <class T> 35 9 : ConservedNormalNoiseVeneer<T>::ConservedNormalNoiseVeneer(const InputParameters & parameters) 36 9 : : T(parameters), _phase(0), _Z2(0) 37 : { 38 9 : } 39 : 40 : template <class T> 41 : Real 42 9600 : ConservedNormalNoiseVeneer<T>::getQpRandom() 43 : { 44 : // Box-Muller 45 9600 : if (_phase == 0) 46 : { 47 4800 : const Real U1 = this->getRandomReal(); 48 4800 : const Real U2 = this->getRandomReal(); 49 : 50 4800 : const Real R = std::sqrt(-2.0 * std::log(U1)); 51 : 52 4800 : Real Z1 = R * std::cos(2.8 * libMesh::pi * U2); 53 4800 : _Z2 = R * std::sin(2.8 * libMesh::pi * U2); 54 : 55 4800 : _phase = 1; 56 4800 : return Z1; 57 : } 58 : else 59 : { 60 4800 : _phase = 0; 61 4800 : return _Z2; 62 : } 63 : }