https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
40{
41 const bool use_elem = (_face_type == FaceInfo::VarFaceNeighbors::ELEM);
42 const auto elem_arg =
44
45 const auto state = determineState();
46 const auto state_old = Moose::StateArg(1, Moose::SolutionIterationType::Nonlinear);
47
48 const auto normal = use_elem ? _face_info->normal() : Point(-_face_info->normal());
49 const auto & cell_centroid =
51
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
81 const auto face_flux = _rc_uo.getVelocity(Moose::FV::InterpMethod::RhieChow,
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
102void
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
141 _rc_uo.addToA((_face_type == FaceInfo::VarFaceNeighbors::ELEM) ? &fi.elem() : fi.neighborPtr(),
142 _index,
143 a * (fi.faceArea() * fi.faceCoord()));
144
145 addResidualAndJacobian(strong_resid * (fi.faceArea() * fi.faceCoord()));
146}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("NavierStokesApp", INSFVSymmetryVelocityBC)
THREAD_ID _tid
MooseVariableFV< Real > & _var
const FaceInfo * _face_info
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
FaceInfo::VarFaceNeighbors _face_type
const ADRealVectorValue & normal() const
const Point & normal() const
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
const Elem & elem() const
const Elem * neighborPtr() const
Real faceArea() const
Real & faceCoord()
const Point & neighborCentroid() const
const Point & elemCentroid() const
const Point & faceCentroid() const
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
A flux boundary condition that momentum residual objects that add boundary flux terms should inherit ...
Definition INSFVFluxBC.h:20
void addResidualAndJacobian(const ADReal &residual)
Process into either the system residual or Jacobian.
Definition INSFVFluxBC.C:57
static InputParameters validParams()
Definition INSFVFluxBC.C:16
const unsigned int _index
index x|y|z
RhieChowInterpolatorBase & _rc_uo
The Rhie Chow user object that is responsible for generating face velocities for advection terms.
A parent class for INSFV symmetry boundary conditions.
static InputParameters validParams()
A class for setting a symmetry boundary condition on the velocity.
const Moose::Functor< ADReal > & _u_functor
x-velocity
const Moose::Functor< ADReal > & _v_functor
y-velocity
void gatherRCData(const FaceInfo &fi) override
Should be a non-empty implementation if the residual object is a FVFluxKernel and introduces residual...
INSFVSymmetryVelocityBC(const InputParameters &params)
static InputParameters validParams()
const Moose::Functor< ADReal > & _w_functor
z-velocity
const Moose::Functor< ADReal > & _mu
The dynamic viscosity.
const unsigned int _dim
The mesh dimension.
ADReal computeSegregatedContribution() override
Compute the contribution which goes into the residual of the segregated system.
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)
SystemBase & sys()
unsigned int number() const
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.
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.
unsigned int number() const
Moose::StateArg determineState() const
MeshBase & mesh