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 "MultiBoundingBoxIC.h" 11 : #include "MooseMesh.h" 12 : #include "FEProblemBase.h" 13 : 14 : registerMooseObject("PhaseFieldApp", MultiBoundingBoxIC); 15 : 16 : namespace 17 : { 18 : // Convenience function for sizing a vector to "n" given a vector with size 1 or "n" 19 : std::vector<Real> 20 174 : sizeVector(std::vector<Real> v, std::size_t size) 21 : { 22 174 : if (v.size() == 1) 23 150 : return std::vector<Real>(size, v[0]); 24 : else 25 : return v; 26 : } 27 : } 28 : 29 : InputParameters 30 324 : MultiBoundingBoxIC::validParams() 31 : { 32 324 : InputParameters params = InitialCondition::validParams(); 33 324 : params.addClassDescription("Specify variable values inside and outside a list of box shaped " 34 : "axis-aligned regions defined by pairs of opposing corners"); 35 648 : params.addRequiredParam<std::vector<Point>>("corners", "The corner coordinates boxes"); 36 648 : params.addRequiredParam<std::vector<Point>>( 37 : "opposite_corners", "The coordinates of the opposite corners of the boxes"); 38 648 : params.addRequiredParam<std::vector<Real>>("inside", 39 : "The value of the variable inside each box " 40 : "(one value per box or a single value for " 41 : "all boxes)"); 42 648 : params.addParam<Real>("outside", 0.0, "The value of the variable outside the box"); 43 : 44 324 : params.addClassDescription("Allows setting the initial condition of a value of a field inside " 45 : "and outside multiple bounding boxes."); 46 324 : return params; 47 0 : } 48 : 49 174 : MultiBoundingBoxIC::MultiBoundingBoxIC(const InputParameters & parameters) 50 : : InitialCondition(parameters), 51 174 : _c1(getParam<std::vector<Point>>("corners")), 52 522 : _c2(getParam<std::vector<Point>>("opposite_corners")), 53 174 : _nbox(_c1.size()), 54 174 : _dim(_fe_problem.mesh().dimension()), 55 348 : _inside(sizeVector(getParam<std::vector<Real>>("inside"), _nbox)), 56 522 : _outside(getParam<Real>("outside")) 57 : { 58 : // make sure inputs are the same length 59 174 : if (_c2.size() != _nbox || _inside.size() != _nbox) 60 0 : mooseError("vector inputs must all be the same size"); 61 174 : } 62 : 63 : Real 64 1103440 : MultiBoundingBoxIC::value(const Point & p) 65 : { 66 1103440 : Real value = _outside; 67 : 68 3035065 : for (unsigned int b = 0; b < _nbox; ++b) 69 : { 70 2188680 : if ((_c1[b](0) < _c2[b](0) && p(0) >= _c1[b](0) && p(0) <= _c2[b](0)) || 71 78580 : (_c1[b](0) >= _c2[b](0) && p(0) <= _c1[b](0) && p(0) >= _c2[b](0))) 72 672050 : if (_dim <= 1 || (_c1[b](1) < _c2[b](1) && p(1) >= _c1[b](1) && p(1) <= _c2[b](1)) || 73 11700 : (_c1[b](1) >= _c2[b](1) && p(1) <= _c1[b](1) && p(1) >= _c2[b](1))) 74 284470 : if (_dim <= 2 || (_c1[b](2) < _c2[b](2) && p(2) >= _c1[b](2) && p(2) <= _c2[b](2)) || 75 0 : (_c1[b](2) >= _c2[b](2) && p(2) <= _c1[b](2) && p(2) >= _c2[b](2))) 76 : { 77 257055 : value = _inside[b]; 78 257055 : break; 79 : } 80 : } 81 : 82 1103440 : return value; 83 : }