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_info->faceType(std::make_pair(_var.number(), _var.sys().number())) ==
43  const auto elem_arg =
45 
46  const auto state = determineState();
48 
49  const auto normal = use_elem ? _face_info->normal() : Point(-_face_info->normal());
50  const auto & cell_centroid =
52 
53  ADRealVectorValue vel_C;
54  vel_C(0) = _u_functor(elem_arg, state);
55  if (_dim > 1)
56  {
57  vel_C(1) = _v_functor(elem_arg, state);
58  if (_dim > 2)
59  vel_C(2) = _w_functor(elem_arg, state);
60  }
61 
62  ADRealVectorValue vel_C_old;
63  vel_C_old(0) = _u_functor(elem_arg, state_old);
64  if (_dim > 1)
65  {
66  vel_C_old(1) = _v_functor(elem_arg, state_old);
67  if (_dim > 2)
68  vel_C_old(2) = _w_functor(elem_arg, state_old);
69  }
70 
71  const auto d_perpendicular = std::abs((_face_info->faceCentroid() - cell_centroid) * normal);
72 
73  const auto face = singleSidedFaceArg();
74  const auto mu_b = _mu(face, state);
75 
76  auto normal_x_normal = outer_product(normal, normal);
77  for (const auto dim_i : make_range(_dim))
78  normal_x_normal(dim_i, dim_i) = 0.0;
79 
80  const auto normal_squared = normal(_index) * normal(_index);
81 
83  *_face_info,
84  state,
85  _tid,
86  /*subtract_mesh_velocity=*/true) *
87  normal;
88 
89  ADReal matrix_contribution;
90  ADReal rhs_contribution;
91 
92  // First, add the advective flux
93  matrix_contribution = face_flux * (1 - normal_squared) * vel_C(_index);
94  rhs_contribution = face_flux * (normal_x_normal * vel_C_old)(_index);
95 
96  // Second, add the diffusive flux
97  matrix_contribution += mu_b / d_perpendicular * normal_squared * vel_C(_index);
98  rhs_contribution += mu_b / d_perpendicular * (normal_x_normal * vel_C_old)(_index);
99 
100  return matrix_contribution - rhs_contribution;
101 }
102 
103 void
105 {
106  _face_info = &fi;
107  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
108 
109  const bool use_elem = _face_type == FaceInfo::VarFaceNeighbors::ELEM;
110  const auto elem_arg =
112  const auto state = determineState();
113  const auto normal = use_elem ? _face_info->normal() : Point(-_face_info->normal());
114  const Point & cell_centroid =
116  const auto u_C = _u_functor(elem_arg, state);
117  const auto v_C = _v_functor(elem_arg, state);
118  const auto w_C = _w_functor(elem_arg, state);
119 
120  const auto d_perpendicular = std::abs((_face_info->faceCentroid() - cell_centroid) * normal);
121 
122  // See Moukalled 15.150. Recall that we multiply by the area in the base class, so S_b ->
123  // normal.norm() -> 1 here.
124 
125  const auto face = singleSidedFaceArg();
126  const auto mu_b = _mu(face, state);
127 
128  ADReal v_dot_n = u_C * normal(0);
129  if (_dim > 1)
130  v_dot_n += v_C * normal(1);
131  if (_dim > 2)
132  v_dot_n += w_C * normal(2);
133 
134  const auto strong_resid = mu_b / d_perpendicular * normal(_index) * v_dot_n;
135 
136  // The strong residual for this object is a superposition of all the velocity components, however,
137  // for the on-diagonal 'a' coefficient, we only care about the coefficient multiplying the
138  // velocity component corresponding to _index, hence v_dot_n -> normal(_index) when moving from
139  // strong_resid -> a
140  const auto a = mu_b / d_perpendicular * normal(_index) * normal(_index);
141 
143  _index,
144  a * (fi.faceArea() * fi.faceCoord()));
145 
146  addResidualAndJacobian(strong_resid * (fi.faceArea() * fi.faceCoord()));
147 }
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