www.mooseframework.org
MultiBoundingBoxIC.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "MultiBoundingBoxIC.h"
9 #include "MooseMesh.h"
10 
11 template <>
12 InputParameters
14 {
15  InputParameters params = validParams<InitialCondition>();
16  params.addClassDescription("Specify variable values inside and outside a list of box shaped "
17  "axis-aligned regions defined by pairs of opposing corners");
18  params.addRequiredParam<std::vector<Point>>("corners", "The corner coordinates boxes");
19  params.addRequiredParam<std::vector<Point>>(
20  "opposite_corners", "The coordinates of the opposite corners of the boxes");
21  params.addRequiredParam<std::vector<Real>>("inside",
22  "The value of the variable inside each box "
23  "(one value per box or a single value for "
24  "all boxes)");
25  params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
26  return params;
27 }
28 
29 MultiBoundingBoxIC::MultiBoundingBoxIC(const InputParameters & parameters)
30  : InitialCondition(parameters),
31  _c1(getParam<std::vector<Point>>("corners")),
32  _c2(getParam<std::vector<Point>>("opposite_corners")),
33  _nbox(_c1.size()),
34  _dim(_fe_problem.mesh().dimension()),
35  _inside(getParam<std::vector<Real>>("inside")),
36  _outside(getParam<Real>("outside"))
37 {
38  // we allow passing in a single value used on the inside of all boxes
39  if (_inside.size() == 1)
40  _inside.assign(_nbox, _inside[0]);
41 
42  // make sure inputs are the same length
43  if (_c2.size() != _nbox || _inside.size() != _nbox)
44  mooseError("vector inputs must all be the same size");
45 }
46 
47 Real
48 MultiBoundingBoxIC::value(const Point & p)
49 {
50  Real value = _outside;
51 
52  for (unsigned int b = 0; b < _nbox; ++b)
53  {
54  if ((_c1[b](0) < _c2[b](0) && p(0) >= _c1[b](0) && p(0) <= _c2[b](0)) ||
55  (_c1[b](0) >= _c2[b](0) && p(0) <= _c1[b](0) && p(0) >= _c2[b](0)))
56  if (_dim <= 1 || (_c1[b](1) < _c2[b](1) && p(1) >= _c1[b](1) && p(1) <= _c2[b](1)) ||
57  (_c1[b](1) >= _c2[b](1) && p(1) <= _c1[b](1) && p(1) >= _c2[b](1)))
58  if (_dim <= 2 || (_c1[b](2) < _c2[b](2) && p(2) >= _c1[b](2) && p(2) <= _c2[b](2)) ||
59  (_c1[b](2) >= _c2[b](2) && p(2) <= _c1[b](2) && p(2) >= _c2[b](2)))
60  {
61  value = _inside[b];
62  break;
63  }
64  }
65 
66  return value;
67 }
std::vector< Real > _inside
values inside the boxes
virtual Real value(const Point &p)
InputParameters validParams< MultiBoundingBoxIC >()
const unsigned int _dim
dimensionality of the mesh
MultiBoundingBoxIC(const InputParameters &parameters)
std::vector< Point > _c1
lists of opposite corners
const unsigned int _nbox
number of boxes
const Real _outside
values outside the boxes
std::vector< Point > _c2