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 "RndBoundingBoxIC.h" 11 : #include "MooseRandom.h" 12 : 13 : registerMooseObject("PhaseFieldApp", RndBoundingBoxIC); 14 : 15 : InputParameters 16 8 : RndBoundingBoxIC::validParams() 17 : { 18 8 : InputParameters params = InitialCondition::validParams(); 19 8 : params.addClassDescription( 20 : "Random noise with different min/max inside/outside of a bounding box"); 21 : 22 16 : params.addRequiredParam<Real>("x1", "The x coordinate of the lower left-hand corner of the box"); 23 16 : params.addRequiredParam<Real>("y1", "The y coordinate of the lower left-hand corner of the box"); 24 16 : params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box"); 25 : 26 16 : params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box"); 27 16 : params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box"); 28 16 : params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box"); 29 : 30 16 : params.addRequiredParam<Real>("mx_invalue", "The max value of the variable invalue the box"); 31 16 : params.addRequiredParam<Real>("mx_outvalue", "The max value of the variable outvalue the box"); 32 : 33 16 : params.addParam<Real>("mn_invalue", 0.0, "The min value of the variable invalue the box"); 34 16 : params.addParam<Real>("mn_outvalue", 0.0, "The min value of the variable outvalue the box"); 35 8 : return params; 36 0 : } 37 : 38 4 : RndBoundingBoxIC::RndBoundingBoxIC(const InputParameters & parameters) 39 : : InitialCondition(parameters), 40 4 : _x1(parameters.get<Real>("x1")), 41 4 : _y1(parameters.get<Real>("y1")), 42 4 : _z1(parameters.get<Real>("z1")), 43 4 : _x2(parameters.get<Real>("x2")), 44 4 : _y2(parameters.get<Real>("y2")), 45 4 : _z2(parameters.get<Real>("z2")), 46 4 : _mx_invalue(parameters.get<Real>("mx_invalue")), 47 4 : _mx_outvalue(parameters.get<Real>("mx_outvalue")), 48 4 : _mn_invalue(parameters.get<Real>("mn_invalue")), 49 4 : _mn_outvalue(parameters.get<Real>("mn_outvalue")), 50 4 : _range_invalue(_mx_invalue - _mn_invalue), 51 4 : _range_outvalue(_mx_outvalue - _mn_outvalue), 52 4 : _bottom_left(_x1, _y1, _z1), 53 4 : _top_right(_x2, _y2, _z2) 54 : { 55 : mooseAssert(_range_invalue >= 0.0, "Inside Min > Inside Max for RandomIC!"); 56 : mooseAssert(_range_outvalue >= 0.0, "Outside Min > Outside Max for RandomIC!"); 57 4 : } 58 : 59 : Real 60 5120 : RndBoundingBoxIC::value(const Point & p) 61 : { 62 : // Random number between 0 and 1 63 : Real rand_num = MooseRandom::rand(); 64 : 65 11648 : for (const auto i : make_range(Moose::dim)) 66 9472 : if (p(i) < _bottom_left(i) || p(i) > _top_right(i)) 67 2944 : return rand_num * _range_outvalue + _mn_outvalue; 68 : 69 2176 : return rand_num * _range_invalue + _mn_invalue; 70 : }