https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVScalarAdvection.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
13#include "NS.h"
14
16
19{
21 params.addClassDescription("Represents the matrix and right hand side contributions of an "
22 "advection term for a passive scalar.");
23 params.addRequiredParam<UserObjectName>(
24 "rhie_chow_user_object",
25 "The rhie-chow user-object which is used to determine the face velocity.");
26 params.addRequiredParam<InterpolationMethodName>(
27 "advected_interp_method_name",
28 "Name of the FVInterpolationMethod to use for the advected quantity.");
29 params.addParam<MooseFunctorName>("u_slip", "The slip-velocity in the x direction.");
30 params.addParam<MooseFunctorName>("v_slip", "The slip-velocity in the y direction.");
31 params.addParam<MooseFunctorName>("w_slip", "The slip-velocity in the z direction.");
32 return params;
33}
34
36 : LinearFVFluxKernel(params),
38 _mass_flux_provider(getUserObject<RhieChowMassFlux>("rhie_chow_user_object")),
39 _adv_interp_method(getFVAdvectedInterpolationMethod(
40 getParam<InterpolationMethodName>("advected_interp_method_name"))),
41 _gradient_field(_adv_interp_method.needsGradients()
42 ? &_var.requestCellGradients(_adv_interp_method.gradientMethodName())
43 : nullptr),
44 _volumetric_face_flux(0.0),
45 _u_slip(isParamValid("u_slip") ? &getFunctor<ADReal>("u_slip") : nullptr),
46 _v_slip(isParamValid("v_slip") ? &getFunctor<ADReal>("v_slip") : nullptr),
47 _w_slip(isParamValid("w_slip") ? &getFunctor<ADReal>("w_slip") : nullptr),
48 _add_slip_model(isParamValid("u_slip") ? true : false)
49{
50}
51
52Real
58
59Real
65
66Real
71
72Real
77
78Real
80{
81 const auto * const adv_bc = cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
82 mooseAssert(adv_bc, "This should be a valid BC!");
83
84 const auto boundary_value_matrix_contrib = adv_bc->computeBoundaryValueMatrixContribution();
85
86 // We support internal boundaries too so we have to make sure the normal points always outward
87 const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM) ? 1.0 : -1.0;
88
89 return boundary_value_matrix_contrib * factor * _volumetric_face_flux * _current_face_area;
90}
91
92Real
94{
95 const auto * const adv_bc = cast_ptr<const LinearFVAdvectionDiffusionBC *>(&bc);
96 mooseAssert(adv_bc, "This should be a valid BC!");
97
98 // We support internal boundaries too so we have to make sure the normal points always outward
99 const auto factor = (_current_face_type == FaceInfo::VarFaceNeighbors::ELEM ? 1.0 : -1.0);
100
101 const auto boundary_value_rhs_contrib = adv_bc->computeBoundaryValueRHSContribution();
102 return -boundary_value_rhs_contrib * factor * _volumetric_face_flux * _current_face_area;
103}
104
105void
107{
109
110 // Caching the velocity on the face which will be reused in the advection term's matrix and right
111 // hand side contributions
113
114 // Adjust volumetric face flux using the slip velocity
115 // TODO: add boundaries
116 if (_u_slip && face_info->neighborPtr())
117 {
118 const auto state = determineState();
119 Moose::FaceArg face_arg;
120 // TODO Add boundary treatment to be able select two-term expansion if desired
121 face_arg = Moose::FaceArg{face_info,
122 Moose::FV::LimiterType::CentralDifference,
123 true,
124 false,
125 face_info->neighborPtr(),
126 nullptr};
127
128 RealVectorValue velocity_slip_vel_vec;
129 if (_u_slip)
130 velocity_slip_vel_vec(0) = (*_u_slip)(face_arg, state).value();
131 if (_v_slip)
132 velocity_slip_vel_vec(1) = (*_v_slip)(face_arg, state).value();
133 if (_w_slip)
134 velocity_slip_vel_vec(2) = (*_w_slip)(face_arg, state).value();
135 _volumetric_face_flux += velocity_slip_vel_vec * face_info->normal();
136 }
137
138 // Only internal faces need advected interpolation results; boundary contributions are handled
139 // through the linear FV boundary conditions.
140 if (_current_face_type != FaceInfo::VarFaceNeighbors::BOTH)
141 return;
142
143 const auto state = determineState();
144 const auto & elem_info = *_current_face_info->elemInfo();
145 const auto & neighbor_info = *_current_face_info->neighborInfo();
146
147 const Real elem_value = _var.getElemValue(elem_info, state);
148 const Real neighbor_value = _var.getElemValue(neighbor_info, state);
150 {
151 mooseAssert(_gradient_field, "Gradient field should be registered when gradients are needed.");
154 }
155
157 elem_value,
158 neighbor_value,
162}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("NavierStokesApp", LinearFVScalarAdvection)
virtual AdvectedSystemContribution advectedInterpolate(const FaceInfo &face, Real elem_value, Real neighbor_value, const VectorValue< Real > *elem_grad, const VectorValue< Real > *neighbor_grad, Real mass_flux) const=0
virtual bool needsGradients() const
const Point & normal() const
const Elem * neighborPtr() const
const ElemInfo * elemInfo() const
const ElemInfo * neighborInfo() 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)
FaceInfo::VarFaceNeighbors _current_face_type
virtual void setupFaceData(const FaceInfo *face_info)
const FaceInfo * _current_face_info
static InputParameters validParams()
RealVectorValue gradient(const ElemInfo &elem_info) const
MooseLinearVariableFV< Real > & _var
An advection kernel that implements the advection term for the passive scalar transport equation.
virtual Real computeNeighborMatrixContribution() override
virtual Real computeNeighborRightHandSideContribution() override
virtual Real computeElemRightHandSideContribution() override
const RhieChowMassFlux & _mass_flux_provider
The Rhie-Chow user object that provides us with the face velocity.
LinearFVScalarAdvection(const InputParameters &params)
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
virtual void setupFaceData(const FaceInfo *face_info) override
const FVAdvectedInterpolationMethod & _adv_interp_method
The interpolation method to use for the advected quantity.
const Moose::Functor< ADReal > *const _v_slip
slip velocity in direction y
const Moose::Functor< ADReal > *const _u_slip
slip velocity in direction x
const Moose::Functor< ADReal > *const _w_slip
slip velocity in direction z
FVAdvectedInterpolationMethod::AdvectedSystemContribution _adv_interp_result
Cached weights/correction for the current face (refreshed in setupFaceData)
VectorValue< Real > _elem_grad_storage
Reusable gradient storage used when advected interpolation requires gradients.
VectorValue< Real > _neighbor_grad_storage
virtual Real computeElemMatrixContribution() override
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
Real _volumetric_face_flux
Container for the velocity on the face which will be reused in the advection term's matrix and right ...
const LinearFVGradientReader *const _gradient_field
Gradient field used by advected interpolations that require gradients.
static InputParameters validParams()
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
virtual const OutputTools< Real >::VariableValue & value()
User object responsible for determining the face fluxes using the Rhie-Chow interpolation in a segreg...
Real getVolumetricFaceFlux(const FaceInfo &fi) const
Get the volumetric face flux (used in advection terms)
Moose::StateArg determineState() const