https://mooseframework.inl.gov
LinearFVRZViscousSource.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 #include "FEProblemBase.h"
12 #include "MooseLinearVariableFV.h"
13 #include "NS.h"
14 
15 #include "libmesh/utility.h"
16 
18 
21 {
23  params.addClassDescription(
24  "Adds the axisymmetric viscous source term mu * u_r / r^2 to the FV momentum equations.");
25  params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity functor.");
26  MooseEnum component("x=0 y=1 z=2");
28  "momentum_component", component, "Momentum component this kernel contributes to.");
29  params.addParam<SolverVariableName>("u", "The velocity in the x direction.");
30  params.addParam<SolverVariableName>("v", "The velocity in the y direction.");
31  params.addParam<bool>(
32  "use_deviatoric_terms",
33  false,
34  "Include the deviatoric correction (-2/3 div(u)) in the axisymmetric term.");
35  return params;
36 }
37 
39  : LinearFVElementalKernel(params),
40  _mu(getFunctor<Real>(NS::mu)),
41  _component(getParam<MooseEnum>("momentum_component")),
42  _rz_radial_coord(_subproblem.getAxisymmetricRadialCoord()),
43  _dim(_subproblem.mesh().dimension()),
44  _use_deviatoric_terms(getParam<bool>("use_deviatoric_terms")),
45  _coord_type(getBlockCoordSystem()),
46  _stress_multiplier(_use_deviatoric_terms ? 2.0 : 1.0),
47  _velocity_vars{nullptr, nullptr}
48 {
49  if (_coord_type != Moose::CoordinateSystemType::COORD_RZ)
50  paramError("block", "LinearFVRZViscousSource is only valid on RZ coordinate systems.");
51 
52  if (_component != _rz_radial_coord)
53  paramError("momentum_component", "LinearFVRZViscousSource must act on the radial component.");
54 
55  if (_use_deviatoric_terms)
56  _var.computeCellGradients();
57 
58  const auto get_velocity_var =
59  [this](const std::string & param_name) -> MooseLinearVariableFVReal *
60  {
61  auto & var = _fe_problem.getVariable(_tid, getParam<SolverVariableName>(param_name));
62  auto ptr = dynamic_cast<MooseLinearVariableFVReal *>(&var);
63  if (!ptr)
64  paramError(param_name, "The supplied variable must be a MooseLinearVariableFVReal.");
65  return ptr;
66  };
67 
68  if (_use_deviatoric_terms)
69  {
70  if (isParamValid("u"))
71  _velocity_vars[0] = get_velocity_var("u");
72  if (isParamValid("v"))
73  _velocity_vars[1] = get_velocity_var("v");
74 
75  if (!_velocity_vars[0])
76  paramError("u", "The x-velocity must be provided when using deviatoric terms.");
77  if (!_velocity_vars[1])
78  paramError("v", "The y-velocity must be provided when using deviatoric terms.");
79 
80  for (const auto dir : make_range(_dim))
81  _velocity_vars[dir]->computeCellGradients();
82  }
83 }
84 
85 Real
87 {
89  mooseAssert(r > 0, "Axisymmetric control volumes should not sit on the axis (r = 0).");
90 
92  return mu * _stress_multiplier * _current_elem_volume / (r * r);
93 }
94 
95 Real
97 {
99  return 0.0;
100 
101  const auto state = determineState();
102  Real divergence = 0.0;
103  for (const auto dir : make_range(_dim))
104  divergence += velocityVar(dir).gradSln(*_current_elem_info, state)(dir);
105 
107  mooseAssert(r > 0, "Axisymmetric control volumes should not sit on the axis (r = 0).");
108 
109  const Real radial_value = velocityVar(_rz_radial_coord).getElemValue(*_current_elem_info, state);
110  divergence += radial_value / r;
111 
112  const auto elem_arg = makeElemArg(_current_elem_info->elem());
113  const Real mu = _mu(elem_arg, state);
114 
115  return (2.0 / 3.0) * mu * divergence * _current_elem_volume / r;
116 }
117 
120 {
121  mooseAssert(dir < _velocity_vars.size() && _velocity_vars[dir],
122  "Velocity variable for requested direction is not available.");
123  return *_velocity_vars[dir];
124 }
const ElemInfo * _current_elem_info
const bool _use_deviatoric_terms
Whether the deviatoric correction (-2/3 div u) is requested.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
T divergence(const TensorValue< T > &gradient, const VectorType &value, const PointType &point, const Moose::CoordinateSystemType &coord_sys, const unsigned int rz_radial_coord)
Compute the divergence of a vector given its matrix of derivatives.
const Moose::Functor< Real > & _mu
Dynamic viscosity functor evaluated at each element.
static const std::string component
Definition: NS.h:157
Real computeMatrixContribution() override
std::array< MooseLinearVariableFVReal *, 2 > _velocity_vars
Cached pointers to the velocity components required to build divergence.
Moose::StateArg determineState() const
const Elem * elem() const
static InputParameters validParams()
const MooseLinearVariableFVReal & velocityVar(unsigned int dir) const
Helper to access the velocity variable for a given direction.
MeshBase & mesh
Adds the axisymmetric viscous source term that appears in the vector Laplacian of cylindrical coordi...
const unsigned int _rz_radial_coord
Index of the radial coordinate for the current mesh (0 -> x, 1 -> y, ...)
void addRequiredParam(const std::string &name, const std::string &doc_string)
VectorValue< Real > gradSln(const ElemInfo &elem_info, const StateArg &state) const
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
const Point & centroid() const
static const std::string mu
Definition: NS.h:127
static InputParameters validParams()
registerMooseObject("NavierStokesApp", LinearFVRZViscousSource)
Real computeRightHandSideContribution() override
const unsigned int _dim
Spatial dimension of the mesh.
LinearFVRZViscousSource(const InputParameters &params)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
IntRange< T > make_range(T beg, T end)
void addClassDescription(const std::string &doc_string)
const Real _stress_multiplier
Precomputed factor (1 or 2) multiplying the implicit hoop term.
const double mu