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 
30 {
32  params.addClassDescription("Specify variable values inside and outside a list of box shaped "
33  "axis-aligned regions defined by pairs of opposing corners");
34  params.addRequiredParam<std::vector<Point>>("corners", "The corner coordinates boxes");
35  params.addRequiredParam<std::vector<Point>>(
36  "opposite_corners", "The coordinates of the opposite corners of the boxes");
37  params.addRequiredParam<std::vector<Real>>("inside",
38  "The value of the variable inside each box "
39  "(one value per box or a single value for "
40  "all boxes)");
41  params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
42 
43  params.addClassDescription("Allows setting the initial condition of a value of a field inside "
44  "and outside multiple bounding boxes.");
45  return params;
46 }
47 
49  : InitialCondition(parameters),
50  _c1(getParam<std::vector<Point>>("corners")),
51  _c2(getParam<std::vector<Point>>("opposite_corners")),
52  _nbox(_c1.size()),
53  _dim(_fe_problem.mesh().dimension()),
54  _inside(sizeVector(getParam<std::vector<Real>>("inside"), _nbox)),
55  _outside(getParam<Real>("outside"))
56 {
57  // make sure inputs are the same length
58  if (_c2.size() != _nbox || _inside.size() != _nbox)
59  mooseError("vector inputs must all be the same size");
60 }
61 
62 Real
63 MultiBoundingBoxIC::value(const Point & p)
64 {
66 
67  for (unsigned int b = 0; b < _nbox; ++b)
68  {
69  if ((_c1[b](0) < _c2[b](0) && p(0) >= _c1[b](0) && p(0) <= _c2[b](0)) ||
70  (_c1[b](0) >= _c2[b](0) && p(0) <= _c1[b](0) && p(0) >= _c2[b](0)))
71  if (_dim <= 1 || (_c1[b](1) < _c2[b](1) && p(1) >= _c1[b](1) && p(1) <= _c2[b](1)) ||
72  (_c1[b](1) >= _c2[b](1) && p(1) <= _c1[b](1) && p(1) >= _c2[b](1)))
73  if (_dim <= 2 || (_c1[b](2) < _c2[b](2) && p(2) >= _c1[b](2) && p(2) <= _c2[b](2)) ||
74  (_c1[b](2) >= _c2[b](2) && p(2) <= _c1[b](2) && p(2) >= _c2[b](2)))
75  {
76  value = _inside[b];
77  break;
78  }
79  }
80 
81  return value;
82 }
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:82
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...