www.mooseframework.org
BoundingBoxIC.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 "BoundingBoxIC.h"
11 #include "libmesh/point.h"
12 
14 
16 
19 {
21  params.addRequiredParam<Real>("x1", "The x coordinate of the lower left-hand corner of the box");
22  params.addRequiredParam<Real>("y1", "The y coordinate of the lower left-hand corner of the box");
23  params.addParam<Real>("z1", 0.0, "The z coordinate of the lower left-hand corner of the box");
24 
25  params.addRequiredParam<Real>("x2", "The x coordinate of the upper right-hand corner of the box");
26  params.addRequiredParam<Real>("y2", "The y coordinate of the upper right-hand corner of the box");
27  params.addParam<Real>("z2", 0.0, "The z coordinate of the upper right-hand corner of the box");
28 
29  params.addParam<Real>("inside", 0.0, "The value of the variable inside the box");
30  params.addParam<Real>("outside", 0.0, "The value of the variable outside the box");
31 
32  params.addParam<Real>(
33  "int_width", 0.0, "The width of the diffuse interface. Set to 0 for sharp interface.");
34 
35  params.addClassDescription("BoundingBoxIC allows setting the initial condition of a value inside "
36  "and outside of a specified box. The box is aligned with the x, y, z "
37  "axes");
38 
39  return params;
40 }
41 
43  : InitialCondition(parameters),
44  _x1(getParam<Real>("x1")),
45  _y1(getParam<Real>("y1")),
46  _z1(getParam<Real>("z1")),
47  _x2(getParam<Real>("x2")),
48  _y2(getParam<Real>("y2")),
49  _z2(getParam<Real>("z2")),
50  _inside(getParam<Real>("inside")),
51  _outside(getParam<Real>("outside")),
52  _bottom_left(_x1, _y1, _z1),
53  _top_right(_x2, _y2, _z2),
54  _int_width(getParam<Real>("int_width"))
55 {
56 }
57 
58 Real
59 BoundingBoxIC::value(const Point & p)
60 {
61  if (_int_width < 0.0)
62  mooseError("'int_width' should be non-negative");
63 
64  if (_int_width == 0.0)
65  {
66  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
67  if (p(i) < _bottom_left(i) || p(i) > _top_right(i))
68  return _outside;
69 
70  return _inside;
71  }
72  else
73  {
74  Real f_in = 1.0;
75  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
76  if (_bottom_left(i) != _top_right(i))
77  f_in *= 0.5 * (std::tanh(2.0 * (p(i) - _bottom_left(i)) / _int_width) -
78  std::tanh(2.0 * (p(i) - _top_right(i)) / _int_width));
79 
80  return _outside + (_inside - _outside) * f_in;
81  }
82 }
BoundingBoxIC::BoundingBoxIC
BoundingBoxIC(const InputParameters &parameters)
Definition: BoundingBoxIC.C:42
BoundingBoxIC::_top_right
const Point _top_right
The Point object constructed from the x2, y2, z2 components for the bottom left BB corner.
Definition: BoundingBoxIC.h:65
defineLegacyParams
defineLegacyParams(BoundingBoxIC)
registerMooseObject
registerMooseObject("MooseApp", BoundingBoxIC)
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
BoundingBoxIC::validParams
static InputParameters validParams()
Definition: BoundingBoxIC.C:18
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
BoundingBoxIC::_outside
const Real _outside
The constant value to assign outside of the bounding box.
Definition: BoundingBoxIC.h:59
BoundingBoxIC.h
InitialConditionTempl
This is a template class that implements the workhorse compute and computeNodal methods.
Definition: InitialConditionTempl.h:21
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
BoundingBoxIC::value
virtual Real value(const Point &p) override
The value of the variable at a point.
Definition: BoundingBoxIC.C:59
InputParameters::addClassDescription
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.
Definition: InputParameters.C:70
BoundingBoxIC::_int_width
const Real _int_width
Interfacial width.
Definition: BoundingBoxIC.h:68
InitialConditionTempl::validParams
static InputParameters validParams()
Definition: InitialConditionTempl.C:41
BoundingBoxIC::_bottom_left
const Point _bottom_left
The Point object constructed from the x1, y1, z1 components for the bottom left BB corner.
Definition: BoundingBoxIC.h:62
BoundingBoxIC
BoundingBoxIC allows setting the initial condition of a value inside and outside of a specified box.
Definition: BoundingBoxIC.h:31
BoundingBoxIC::_inside
const Real _inside
The constant value to assign within the bounding box.
Definition: BoundingBoxIC.h:56
InputParameters::addRequiredParam
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...
Definition: InputParameters.h:1176