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 "RandomIC.h" 11 : 12 : #include "libmesh/point.h" 13 : #include "Distribution.h" 14 : 15 : registerMooseObject("MooseApp", RandomIC); 16 : 17 : InputParameters 18 15207 : RandomIC::validParams() 19 : { 20 15207 : InputParameters params = RandomICBase::validParams(); 21 15207 : params += DistributionInterface::validParams(); 22 45621 : params.addParam<Real>( 23 30414 : "min", 0.0, "Lower bound of uniformly distributed randomly generated values"); 24 45621 : params.addParam<Real>( 25 30414 : "max", 1.0, "Upper bound of uniformly distributed randomly generated values"); 26 15207 : params.addParam<DistributionName>( 27 : "distribution", "Name of distribution defining distribution of randomly generated values"); 28 : 29 15207 : params.addClassDescription("Initialize a variable with randomly generated numbers following " 30 : "either a uniform distribution or a user-defined distribution"); 31 15207 : return params; 32 0 : } 33 : 34 496 : RandomIC::RandomIC(const InputParameters & parameters) 35 : : RandomICBase(parameters), 36 : DistributionInterface(this), 37 496 : _min(getParam<Real>("min")), 38 496 : _max(getParam<Real>("max")), 39 496 : _distribution(nullptr) 40 : { 41 496 : if (_min >= _max) 42 0 : paramError("min", "Min >= Max for RandomIC!"); 43 : 44 496 : if (parameters.isParamSetByUser("distribution")) 45 : { 46 0 : _distribution = &getDistributionByName(getParam<DistributionName>("distribution")); 47 0 : if (parameters.isParamSetByUser("min") || parameters.isParamSetByUser("max")) 48 0 : paramError("distribution", "Cannot use together with 'min' or 'max' parameter"); 49 : } 50 496 : } 51 : 52 : Real 53 306188 : RandomIC::value(const Point & /*p*/) 54 : { 55 306188 : if (_distribution) 56 0 : return _distribution->quantile(generateRandom()); 57 : else 58 306188 : return generateRandom() * (_max - _min) + _min; 59 : }