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