https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
13#include "NS.h"
14
15#include "libmesh/utility.h"
16
18
21{
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
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
53 paramError("momentum_component", "LinearFVRZViscousSource must act on the radial component.");
54
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
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
85Real
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
95Real
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 double mu
registerMooseObject("NavierStokesApp", LinearFVRZViscousSource)
const Elem * elem() const
const Point & centroid() const
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
const ElemInfo * _current_elem_info
static InputParameters validParams()
MooseLinearVariableFV< Real > & _var
Adds the axisymmetric viscous source term that appears in the vector Laplacian of cylindrical coordi...
const unsigned int _dim
Spatial dimension of the mesh.
Real computeRightHandSideContribution() override
const Real _stress_multiplier
Precomputed factor (1 or 2) multiplying the implicit hoop term.
const MooseLinearVariableFVReal & velocityVar(unsigned int dir) const
Helper to access the velocity variable for a given direction.
const unsigned int _rz_radial_coord
Index of the radial coordinate for the current mesh (0 -> x, 1 -> y, ...)
Real computeMatrixContribution() override
LinearFVRZViscousSource(const InputParameters &params)
std::array< MooseLinearVariableFVReal *, 2 > _velocity_vars
Cached pointers to the velocity components required to build divergence.
const Moose::Functor< Real > & _mu
Dynamic viscosity functor evaluated at each element.
const Moose::CoordinateSystemType _coord_type
Coordinate system of the active blocks (must be COORD_RZ)
static InputParameters validParams()
const bool _use_deviatoric_terms
Whether the deviatoric correction (-2/3 div u) is requested.
const unsigned int _component
Momentum component this source acts on (should equal the radial direction)
const THREAD_ID _tid
FEProblemBase & _fe_problem
void paramError(const std::string &param, Args... args) const
bool isParamValid(const std::string &name) const
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
VectorValue< Real > gradSln(const ElemInfo &elem_info, const StateArg &state) const
Moose::StateArg determineState() const
MeshBase & mesh
static const std::string mu
Definition NS.h:127