https://mooseframework.inl.gov
INSFVSymmetryVelocityBC.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 += INSFVSymmetryBC::validParams();
19  params.addClassDescription("Implements a symmetry boundary condition for the velocity.");
20  params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
21  params.addParam<MooseFunctorName>("v", 0, "The velocity in the y direction.");
22  params.addParam<MooseFunctorName>("w", 0, "The velocity in the z direction.");
23  params.addRequiredParam<MooseFunctorName>("mu", "The viscosity");
24  return params;
25 }
26 
28  : INSFVFluxBC(params),
29  INSFVSymmetryBC(params),
30  _u_functor(getFunctor<ADReal>("u")),
31  _v_functor(getFunctor<ADReal>("v")),
32  _w_functor(getFunctor<ADReal>("w")),
33  _mu(getFunctor<ADReal>("mu")),
34  _dim(_subproblem.mesh().dimension())
35 {
36 }
37 
38 ADReal
40 {
41  const bool use_elem = (_face_type == FaceInfo::VarFaceNeighbors::ELEM);
42  const auto elem_arg =
44 
45  const auto state = determineState();
47 
48  const auto normal = use_elem ? _face_info->normal() : Point(-_face_info->normal());
49  const auto & cell_centroid =
51 
52  ADRealVectorValue vel_C;
53  vel_C(0) = _u_functor(elem_arg, state);
54  if (_dim > 1)
55  {
56  vel_C(1) = _v_functor(elem_arg, state);
57  if (_dim > 2)
58  vel_C(2) = _w_functor(elem_arg, state);
59  }
60 
61  ADRealVectorValue vel_C_old;
62  vel_C_old(0) = _u_functor(elem_arg, state_old);
63  if (_dim > 1)
64  {
65  vel_C_old(1) = _v_functor(elem_arg, state_old);
66  if (_dim > 2)
67  vel_C_old(2) = _w_functor(elem_arg, state_old);
68  }
69 
70  const auto d_perpendicular = std::abs((_face_info->faceCentroid() - cell_centroid) * normal);
71 
72  const auto face = singleSidedFaceArg();
73  const auto mu_b = _mu(face, state);
74 
75  auto normal_x_normal = outer_product(normal, normal);
76  for (const auto dim_i : make_range(_dim))
77  normal_x_normal(dim_i, dim_i) = 0.0;
78 
79  const auto normal_squared = normal(_index) * normal(_index);
80 
82  *_face_info,
83  state,
84  _tid,
85  /*subtract_mesh_velocity=*/true) *
86  normal;
87 
88  ADReal matrix_contribution;
89  ADReal rhs_contribution;
90 
91  // First, add the advective flux
92  matrix_contribution = face_flux * (1 - normal_squared) * vel_C(_index);
93  rhs_contribution = face_flux * (normal_x_normal * vel_C_old)(_index);
94 
95  // Second, add the diffusive flux
96  matrix_contribution += mu_b / d_perpendicular * normal_squared * vel_C(_index);
97  rhs_contribution += mu_b / d_perpendicular * (normal_x_normal * vel_C_old)(_index);
98 
99  return matrix_contribution - rhs_contribution;
100 }
101 
102 void
104 {
105  _face_info = &fi;
106  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
107 
108  const bool use_elem = _face_type == FaceInfo::VarFaceNeighbors::ELEM;
109  const auto elem_arg =
111  const auto state = determineState();
112  const auto normal = use_elem ? _face_info->normal() : Point(-_face_info->normal());
113  const Point & cell_centroid =
115  const auto u_C = _u_functor(elem_arg, state);
116  const auto v_C = _v_functor(elem_arg, state);
117  const auto w_C = _w_functor(elem_arg, state);
118 
119  const auto d_perpendicular = std::abs((_face_info->faceCentroid() - cell_centroid) * normal);
120 
121  // See Moukalled 15.150. Recall that we multiply by the area in the base class, so S_b ->
122  // normal.norm() -> 1 here.
123 
124  const auto face = singleSidedFaceArg();
125  const auto mu_b = _mu(face, state);
126 
127  ADReal v_dot_n = u_C * normal(0);
128  if (_dim > 1)
129  v_dot_n += v_C * normal(1);
130  if (_dim > 2)
131  v_dot_n += w_C * normal(2);
132 
133  const auto strong_resid = mu_b / d_perpendicular * normal(_index) * v_dot_n;
134 
135  // The strong residual for this object is a superposition of all the velocity components, however,
136  // for the on-diagonal 'a' coefficient, we only care about the coefficient multiplying the
137  // velocity component corresponding to _index, hence v_dot_n -> normal(_index) when moving from
138  // strong_resid -> a
139  const auto a = mu_b / d_perpendicular * normal(_index) * normal(_index);
140 
142  _index,
143  a * (fi.faceArea() * fi.faceCoord()));
144 
145  addResidualAndJacobian(strong_resid * (fi.faceArea() * fi.faceCoord()));
146 }
const FaceInfo * _face_info
FaceInfo::VarFaceNeighbors _face_type
registerMooseObject("NavierStokesApp", INSFVSymmetryVelocityBC)
void gatherRCData(const FaceInfo &fi) override
Should be a non-empty implementation if the residual object is a FVFluxKernel and introduces residual...
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int number() const
A flux boundary condition that momentum residual objects that add boundary flux terms should inherit ...
Definition: INSFVFluxBC.h:19
const Elem & elem() const
Moose::StateArg determineState() const
const Point & faceCentroid() const
const unsigned int _index
index x|y|z
MeshBase & mesh
const Moose::Functor< ADReal > & _v_functor
y-velocity
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi=nullptr, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false, const Moose::StateArg *state_limiter=nullptr) const
TypeVector< typename CompareTypes< T, T2 >::supertype > outer_product(const T &a, const TypeVector< T2 > &b)
MooseVariableFV< Real > & _var
Real & faceCoord()
const Point & neighborCentroid() const
DualNumber< Real, DNDerivativeType, true > ADReal
Real faceArea() const
const Moose::Functor< ADReal > & _mu
The dynamic viscosity.
void addRequiredParam(const std::string &name, const std::string &doc_string)
RhieChowInterpolatorBase & _rc_uo
The Rhie Chow user object that is responsible for generating face velocities for advection terms...
virtual VectorValue< ADReal > getVelocity(const Moose::FV::InterpMethod m, const FaceInfo &fi, const Moose::StateArg &time, const THREAD_ID tid, bool subtract_mesh_velocity) const =0
Retrieve a face velocity.
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
const Elem * neighborPtr() const
const Point & elemCentroid() const
ADReal computeSegregatedContribution() override
Compute the contribution which goes into the residual of the segregated system.
INSFVSymmetryVelocityBC(const InputParameters &params)
const Point & normal() const
unsigned int number() const
void addResidualAndJacobian(const ADReal &residual)
Process into either the system residual or Jacobian.
Definition: INSFVFluxBC.C:57
const Moose::Functor< ADReal > & _w_functor
z-velocity
THREAD_ID _tid
const unsigned int _dim
The mesh dimension.
virtual void addToA(const libMesh::Elem *elem, unsigned int component, const ADReal &value)=0
API for momentum residual objects that have on-diagonals for velocity call.
static InputParameters validParams()
Definition: INSFVFluxBC.C:16
IntRange< T > make_range(T beg, T end)
const Moose::Functor< ADReal > & _u_functor
x-velocity
const ADRealVectorValue & normal() const
void addClassDescription(const std::string &doc_string)
A parent class for INSFV symmetry boundary conditions.
static InputParameters validParams()
A class for setting a symmetry boundary condition on the velocity.
static InputParameters validParams()
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const