https://mooseframework.inl.gov
MultiBoundingBoxIC.C
Go to the documentation of this file.
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 sizeVector(std::vector<Real> v, std::size_t size)
21 {
22  if (v.size() == 1)
23  return std::vector<Real>(size, v[0]);
24  else
25  return v;
26 }
27 }
28 
31 {
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 
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 {
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 }
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
MeshBase & mesh
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
static InputParameters validParams()
const unsigned int _dim
dimensionality of the mesh
MultiBoundingBoxIC(const InputParameters &parameters)
const std::vector< Real > _inside
values inside the boxes
const std::vector< Point > _c2
const unsigned int _nbox
number of boxes
registerMooseObject("PhaseFieldApp", MultiBoundingBoxIC)
virtual Real value(const Point &p) override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
const Real _outside
values outside the boxes
const std::vector< Point > _c1
lists of opposite corners
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
MultiBoundingBoxIC allows setting the initial condition of a value of a field inside and outside mult...