https://mooseframework.inl.gov
LinearFVAdvectionDiffusionFunctorRobinBC.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 
11 
13 
16 {
18  params.addClassDescription(
19  "Adds a Robin BC of the form \\alpha * \\nabla \\phi*n + \\beta * \\phi = \\gamma, "
20  "which can be used for the assembly of linear "
21  "finite volume system and whose face values are determined using "
22  "three functors. This kernel is "
23  "only designed to work with advection-diffusion problems.");
24  params.addRequiredParam<MooseFunctorName>(
25  "alpha", "The functor which is the coefficient of the normal gradient term.");
26  params.addRequiredParam<MooseFunctorName>(
27  "beta", "The functor which is the coefficient of the scalar term.");
28  params.addRequiredParam<MooseFunctorName>(
29  "gamma", "The functor which is the constant term on the RHS of the Robin BC expression.");
30  return params;
31 }
32 
34  const InputParameters & parameters)
35  : LinearFVAdvectionDiffusionBC(parameters),
36  _alpha(getFunctor<Real>("alpha")),
37  _beta(getFunctor<Real>("beta")),
38  _gamma(getFunctor<Real>("gamma"))
39 {
41 
42  if (_alpha.isConstant())
43  {
44  // We check if we can parse the value to a number and if yes, we throw an error if it is 0
45  std::istringstream ss(getParam<MooseFunctorName>("alpha"));
46  Real real_value;
47  if (ss >> real_value && ss.eof())
48  if (MooseUtils::isZero(real_value))
49  paramError("alpha",
50  "This value shall not be 0. Use a Dirichlet boundary condition instead!");
51  }
52 }
53 
54 Real
56 {
57  const auto face = singleSidedFaceArg(_current_face_info);
59  "This should not be assigned on an internal face!");
60  const auto & elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM
63  const auto state = determineState();
64 
65  const auto alpha = _alpha(face, state);
66  const auto beta = _beta(face, state);
67  const auto gamma = _gamma(face, state);
68 
69  const auto phi = _var.getElemValue(*elem_info, state);
70  const auto grad_phi = _var.gradSln(*elem_info);
71 
72  const auto & nhat = _current_face_info->normal();
73 
74  const auto d_cf = computeCellToFaceVector(); // vector from boundary cell centre to boundary face
75  const auto projection = d_cf * nhat;
76  const auto vc = d_cf - (projection * nhat);
77  return ((alpha * phi) + (alpha * grad_phi * vc) + (gamma * projection)) /
78  (alpha + (beta * projection));
79 }
80 
81 Real
83 {
84  const auto face = singleSidedFaceArg(_current_face_info);
85  const auto state = determineState();
86  const auto alpha = _alpha(face, state);
87  mooseAssert(!MooseUtils::isZero(alpha), "Alpha should not be 0!");
88  const auto beta = _beta(face, state);
89  const auto gamma = _gamma(face, state);
90  return (gamma - beta * computeBoundaryValue()) / alpha;
91 }
92 
93 // implicit terms for advection kernel
94 Real
96 {
97  const auto face = singleSidedFaceArg(_current_face_info);
98  const auto state = determineState();
99  const auto alpha = _alpha(face, state);
100  const auto beta = _beta(face, state);
101  const auto & nhat = _current_face_info->normal();
102 
103  return alpha / (alpha + (beta * computeCellToFaceVector() * nhat));
104 }
105 
106 // explicit terms for advection kernel
107 Real
109 {
110  const auto face = singleSidedFaceArg(_current_face_info);
111  const auto state = determineState();
113  "This should not be assigned on an internal face!");
114  const auto & elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM
117  const auto alpha = _alpha(face, state);
118  const auto beta = _beta(face, state);
119  const auto gamma = _gamma(face, state);
120  const auto & grad_phi = _var.gradSln(*elem_info);
121 
122  const auto & nhat = _current_face_info->normal();
123 
124  const auto d_cf = computeCellToFaceVector(); // vector from boundary cell centre to boundary face
125  const auto projection = d_cf * nhat;
126  const auto vc = d_cf - (projection * nhat); // correction vector for non-orthogonal cells
127 
128  return (gamma * projection / (alpha + (beta * projection))) +
129  (alpha * grad_phi * vc / (alpha + (beta * projection)));
130 }
131 
132 // implicit terms for diffusion kernel
133 Real
135 {
136  const auto face = singleSidedFaceArg(_current_face_info);
137  const auto state = determineState();
138 
139  const auto alpha = _alpha(face, state);
140  const auto beta = _beta(face, state);
141  const auto & nhat = _current_face_info->normal();
142 
143  return beta / (alpha + (beta * computeCellToFaceVector() * nhat));
144 }
145 
146 // explicit terms for diffusion kernel
147 Real
149 {
151  "This should not be assigned on an internal face!");
152  const auto & elem_info = _current_face_type == FaceInfo::VarFaceNeighbors::ELEM
155  const auto face = singleSidedFaceArg(_current_face_info);
156  const auto state = determineState();
157  const auto & grad_phi = _var.gradSln(*elem_info);
158 
159  const auto alpha = _alpha(face, state);
160  const auto beta = _beta(face, state);
161  const auto gamma = _gamma(face, state);
162 
163  const auto & nhat = _current_face_info->normal();
164 
165  const auto d_cf = computeCellToFaceVector(); // vector from boundary cell centre to boundary face
166  const auto projection = d_cf * nhat;
167  const auto vc = d_cf - (projection * nhat); // correction vector for non-orthogonal cells
168 
169  return (gamma / alpha) + (-beta * gamma * projection / alpha / (alpha + (beta * projection))) +
170  (-beta * grad_phi * vc / (alpha + (beta * projection)));
171 }
const Moose::Functor< Real > & _gamma
Functor giving the gamma coefficient (on right hand side, treated explicitly)
RealVectorValue computeCellToFaceVector() const
Computes the vector connecting the cell and boundary face centers.
virtual Real computeBoundaryGradientRHSContribution() const override
Computes the boundary gradient&#39;s contribution to the linear system right hand side.
const Moose::Functor< Real > & _beta
Functor giving the beta coefficient (multiplying value)
virtual Real computeBoundaryValueRHSContribution() const override
Computes the boundary value&#39;s contribution to the linear system right hand side.
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:691
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
Class implementing a Robin boundary condition for linear finite volume variables. ...
const ElemInfo * neighborInfo() const
Definition: FaceInfo.h:86
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const ElemInfo * elemInfo() const
Definition: FaceInfo.h:85
virtual Real computeBoundaryNormalGradient() const override
Computes the normal gradient (often used in diffusion terms) on the boundary.
LinearFVAdvectionDiffusionFunctorRobinBC(const InputParameters &parameters)
Class constructor.
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...
Base class for boundary conditions that are valid for advection diffusion problems.
FaceInfo::VarFaceNeighbors _current_face_type
Face ownership information for the current face.
virtual Real computeBoundaryValueMatrixContribution() const override
Computes the boundary value&#39;s contribution to the linear system matrix.
const Moose::Functor< Real > & _alpha
Functor giving the alpha coefficient (multiplying normal gradient)
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face&#39;s elem element...
Definition: FaceInfo.h:68
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
MooseLinearVariableFV< Real > & _var
Reference to the linear finite volume variable object.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const FaceInfo * _current_face_info
Pointer to the face info we are operating on right now.
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
Get the solution value for the provided element and seed the derivative for the corresponding dof ind...
const VectorValue< Real > gradSln(const ElemInfo &elem_info) const
Get the variable gradient at a cell center.
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...
virtual Real computeBoundaryValue() const override
Computes the boundary value of this object.
virtual Real computeBoundaryGradientMatrixContribution() const override
Computes the boundary gradient&#39;s contribution to the linear system matrix.
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false) const
Determine the single sided face argument when evaluating a functor on a face.
void computeCellGradients()
Switch to request cell gradient computations.
registerMooseObject("MooseApp", LinearFVAdvectionDiffusionFunctorRobinBC)