https://mooseframework.inl.gov
WCNSFV2PSlipVelocityFunctorMaterial.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 "INSFVVelocityVariable.h"
12 #include "MooseLinearVariableFV.h"
13 #include "Function.h"
14 #include "NS.h"
15 #include "FVKernel.h"
16 
18 
21 {
23  params.addClassDescription("Computes the slip velocity for two-phase mixture model.");
24  params.addRequiredCoupledVar("u", "The velocity in the x direction.");
25  params.addCoupledVar("v", "The velocity in the y direction.");
26  params.addCoupledVar("w", "The velocity in the z direction.");
27  params.addRequiredParam<MooseFunctorName>(NS::density, "Continuous phase density.");
28  params.addRequiredParam<MooseFunctorName>("rho_d", "Dispersed phase density.");
29  params.addRequiredParam<MooseFunctorName>(NS::mu, "Mixture Density");
30  params.addParam<RealVectorValue>(
31  "gravity", RealVectorValue(0, 0, 0), "Gravity acceleration vector");
32  params.addParam<Real>("force_value", 0.0, "Coefficient to multiply by the body force term");
33  params.addParam<FunctionName>("force_function", "0", "A function that describes the body force");
34  params.addParam<PostprocessorName>(
35  "force_postprocessor", 0, "A postprocessor whose value is multiplied by the body force");
36  params.addParam<RealVectorValue>(
37  "force_direction", RealVectorValue(1, 0, 0), "Gravitational acceleration vector");
38  params.addParam<MooseFunctorName>(
39  "linear_coef_name", 0.44, "Linear friction coefficient name as a material property");
40  params.addParam<MooseFunctorName>(
41  "particle_diameter", 1.0, "Diameter of particles in the dispersed phase.");
42  params.addParam<MooseFunctorName>("fd", 0.0, "Fraction dispersed phase.");
43  MooseEnum momentum_component("x=0 y=1 z=2");
45  "momentum_component",
46  momentum_component,
47  "The component of the momentum equation that this kernel applies to.");
48  params.addRequiredParam<MooseFunctorName>("slip_velocity_name", "the name of the slip velocity");
49  params.addParam<unsigned short>("ghost_layers",
50  3,
51  "The number of layers of elements to ghost. With Rhie-Chow and "
52  "the velocity gradient calculation below, we need 3");
54  "ElementSideNeighborLayers",
57  [](const InputParameters & obj_params, InputParameters & rm_params) {
58  rm_params.set<unsigned short>("layers") = obj_params.get<unsigned short>("ghost_layers");
59  });
60  return params;
61 }
62 
64  const InputParameters & params)
65  : FunctorMaterial(params),
66  _dim(_subproblem.mesh().dimension()),
67  _u_var(dynamic_cast<MooseVariableField<Real> *>(getFieldVar("u", 0))),
68  _v_var(params.isParamValid("v") ? dynamic_cast<MooseVariableField<Real> *>(getFieldVar("v", 0))
69  : nullptr),
70  _w_var(params.isParamValid("w") ? dynamic_cast<MooseVariableField<Real> *>(getFieldVar("w", 0))
71  : nullptr),
72  _rho_mixture(getFunctor<ADReal>(NS::density)),
73  _rho_d(getFunctor<ADReal>("rho_d")),
74  _mu_mixture(getFunctor<ADReal>(NS::mu)),
75  _gravity(getParam<RealVectorValue>("gravity")),
76  _force_scale(getParam<Real>("force_value")),
77  _force_function(getFunction("force_function")),
78  _force_postprocessor(getPostprocessorValue("force_postprocessor")),
79  _force_direction(getParam<RealVectorValue>("force_direction")),
80  _linear_friction(getFunctor<ADReal>("linear_coef_name")),
81  _particle_diameter(getFunctor<ADReal>("particle_diameter")),
82  _index(getParam<MooseEnum>("momentum_component"))
83 {
84  if (!dynamic_cast<const INSFVVelocityVariable *>(_u_var) &&
85  !dynamic_cast<const MooseLinearVariableFV<Real> *>(_u_var))
86  paramError("u",
87  "the u velocity must be an INSFVVelocityVariable or a MooseLinearVariableFVReal");
88 
89  if (_dim >= 2 && (!dynamic_cast<const INSFVVelocityVariable *>(_v_var) &&
90  !dynamic_cast<const MooseLinearVariableFV<Real> *>(_v_var)))
91  paramError("v",
92  "In two or more dimensions, the v velocity must be supplied and it must be an "
93  "INSFVVelocityVariable or a MooseLinearVariableFVReal.");
94 
95  if (_dim >= 3 && (!dynamic_cast<const INSFVVelocityVariable *>(_w_var) &&
96  !dynamic_cast<const MooseLinearVariableFV<Real> *>(_w_var)))
97  paramError("w",
98  "In three-dimensions, the w velocity must be supplied and it must be an "
99  "INSFVVelocityVariable or a MooseLinearVariableFVReal.");
100 
101  // Slip velocity advection term requires gradients
102  // TODO: this could be set less often, keeping it false until the two phase mixture system is
103  // solved
104  if (auto u = dynamic_cast<MooseLinearVariableFV<Real> *>(_u_var))
105  u->computeCellGradients();
106  if (auto v = dynamic_cast<MooseLinearVariableFV<Real> *>(_v_var))
107  v->computeCellGradients();
108  if (auto w = dynamic_cast<MooseLinearVariableFV<Real> *>(_w_var))
109  w->computeCellGradients();
110 
111  addFunctorProperty<ADReal>(
112  getParam<MooseFunctorName>("slip_velocity_name"),
113  [this](const auto & r, const auto & t)
114  {
115  constexpr Real offset = 1e-15;
116 
117  const bool is_transient = _subproblem.isTransient();
118  ADRealVectorValue term_advection(0, 0, 0);
119  ADRealVectorValue term_transient(0, 0, 0);
120  const ADRealVectorValue term_force(
122  _force_function.value(_t, _current_elem->vertex_average()) * _force_direction);
123 
124  // Adding transient term
125  // TODO: add time derivative term to lienar FV variable
126  if (is_transient && !dynamic_cast<MooseLinearVariableFV<Real> *>(_u_var))
127  {
128  term_transient(0) += _u_var->dot(r, t);
129  if (_dim > 1)
130  term_transient(1) += _v_var->dot(r, t);
131  if (_dim > 2)
132  term_transient(2) += _w_var->dot(r, t);
133  }
134 
135  // Adding advection term
136  const auto u_velocity = (*_u_var)(r, t);
137  const auto u_grad = _u_var->gradient(r, t);
138  term_advection(0) += u_velocity * u_grad(0);
139  if (_dim > 1)
140  {
141  const auto v_velocity = (*_v_var)(r, t);
142  const auto v_grad = _v_var->gradient(r, t);
143  term_advection(0) += v_velocity * u_grad(1);
144  term_advection(1) += u_velocity * v_grad(0) + v_velocity * v_grad(1);
145  if (_dim > 2)
146  {
147  const auto w_velocity = (*_w_var)(r, t);
148  const auto w_grad = _w_var->gradient(r, t);
149  term_advection(0) += w_velocity * u_grad(2);
150  term_advection(1) += w_velocity * v_grad(2);
151  term_advection(2) +=
152  u_velocity * w_grad(0) + v_velocity * w_grad(1) + w_velocity * w_grad(2);
153  }
154  }
155 
156  const ADReal density_scaling = (_rho_d(r, t) - _rho_mixture(r, t)) / _rho_d(r, t);
157  const ADReal flux_residual =
158  density_scaling * (-term_transient - term_advection + _gravity + term_force)(_index);
159 
160  const ADReal relaxation_time =
161  _rho_d(r, t) * Utility::pow<2>(_particle_diameter(r, t)) / (18.0 * _mu_mixture(r, t));
162 
163  const ADReal linear_friction_factor = _linear_friction(r, t) + offset;
164 
165  return relaxation_time / linear_friction_factor * flux_residual;
166  });
167 }
const Moose::Functor< ADReal > & _rho_mixture
Continuous phase density.
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
SubProblem & _subproblem
T & set(const std::string &name, bool quiet_mode=false)
RealVectorValue _force_direction
Force direction vector.
MeshBase & mesh
const Moose::Functor< ADReal > & _linear_friction
The linear friction factor, for laminar flow.
static const std::string density
Definition: NS.h:33
registerMooseObject("NavierStokesApp", WCNSFV2PSlipVelocityFunctorMaterial)
MooseVariableField< Real > *const _w_var
z-velocity
WCNSFV2PSlipVelocityFunctorMaterial(const InputParameters &parameters)
void addRelationshipManager(const std::string &name, Moose::RelationshipManagerType rm_type, Moose::RelationshipManagerInputParameterCallback input_parameter_callback=nullptr)
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
const PostprocessorValue & _force_postprocessor
Optional Force Postprocessor value.
MooseVariableField< Real > *const _u_var
x-velocity
Computes the value of slip velocity for the two phase mixture model.
static const std::string mu
Definition: NS.h:123
virtual bool isTransient() const=0
unsigned int _index
index of the velocity component x|y|z
const unsigned int _dim
the dimension of the simulation
void paramError(const std::string &param, Args... args) const
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const Function & _force_function
Force optional function value.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const std::string v
Definition: NS.h:84
DotType dot(const ElemArg &elem, const StateArg &state) const
const Moose::Functor< ADReal > & _rho_d
Dispersed Phase Density.
GradientType gradient(const ElemArg &elem, const StateArg &state) const
void addClassDescription(const std::string &doc_string)
const Moose::Functor< ADReal > & _mu_mixture
Mixture density.
virtual Real value(Real t, const Point &p) const
const Moose::Functor< ADReal > & _particle_diameter
Particle diameter in the dispersed phase.
const Elem *const & _current_elem
MooseVariableField< Real > *const _v_var
y-velocity