https://mooseframework.inl.gov
BoundingBoxIC.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 "BoundingBoxIC.h"
11 #include "libmesh/point.h"
12 
14 
17 {
19  params.addRequiredParam<Real>("x1", "The x coordinate of the lower left-hand corner of the box");
20  params.addRequiredParam<Real>("y1", "The y coordinate of the lower left-hand corner of the box");
21  params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
22 
23  params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
24  params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
25  params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
26 
27  params.addParam<Real>("inside", 0.0, "The value of the variable inside the box");
28  params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
29 
30  params.addParam<Real>(
31  "int_width", 0.0, "The width of the diffuse interface. Set to 0 for sharp interface.");
32 
33  params.addClassDescription("BoundingBoxIC allows setting the initial condition of a value inside "
34  "and outside of a specified box. The box is aligned with the x, y, z "
35  "axes");
36 
37  return params;
38 }
39 
41  : InitialCondition(parameters),
42  _x1(getParam<Real>("x1")),
43  _y1(getParam<Real>("y1")),
44  _z1(getParam<Real>("z1")),
45  _x2(getParam<Real>("x2")),
46  _y2(getParam<Real>("y2")),
47  _z2(getParam<Real>("z2")),
48  _inside(getParam<Real>("inside")),
49  _outside(getParam<Real>("outside")),
50  _bottom_left(_x1, _y1, _z1),
51  _top_right(_x2, _y2, _z2),
52  _int_width(getParam<Real>("int_width"))
53 {
54 }
55 
56 Real
57 BoundingBoxIC::value(const Point & p)
58 {
59  if (_int_width < 0.0)
60  mooseError("'int_width' should be non-negative");
61 
62  if (_int_width == 0.0)
63  {
64  for (const auto i : make_range(Moose::dim))
65  if (p(i) < _bottom_left(i) || p(i) > _top_right(i))
66  return _outside;
67 
68  return _inside;
69  }
70  else
71  {
72  Real f_in = 1.0;
73  for (const auto i : make_range(Moose::dim))
74  if (_bottom_left(i) != _top_right(i))
75  f_in *= 0.5 * (std::tanh(2.0 * (p(i) - _bottom_left(i)) / _int_width) -
76  std::tanh(2.0 * (p(i) - _top_right(i)) / _int_width));
77 
78  return _outside + (_inside - _outside) * f_in;
79  }
80 }
This is a template class that implements the workhorse compute and computeNodal methods.
registerMooseObject("MooseApp", BoundingBoxIC)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:154
static InputParameters validParams()
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
BoundingBoxIC allows setting the initial condition of a value inside and outside of a specified box...
Definition: BoundingBoxIC.h:22
const Real _inside
The constant value to assign within the bounding box.
Definition: BoundingBoxIC.h:47
const Real _int_width
Interfacial width.
Definition: BoundingBoxIC.h:59
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: BoundingBoxIC.C:57
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const Point _top_right
The Point object constructed from the x2, y2, z2 components for the bottom left BB corner...
Definition: BoundingBoxIC.h:56
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const Point _bottom_left
The Point object constructed from the x1, y1, z1 components for the bottom left BB corner...
Definition: BoundingBoxIC.h:53
const Real _outside
The constant value to assign outside of the bounding box.
Definition: BoundingBoxIC.h:50
BoundingBoxIC(const InputParameters &parameters)
Definition: BoundingBoxIC.C:40
static InputParameters validParams()
Definition: BoundingBoxIC.C:16