https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SideAdvectiveFluxIntegral.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 "MathFVUtils.h"
12
13#include "metaphysicl/raw_type.h"
14
17
18template <bool is_ad>
21{
23 MooseEnum component("x y z normal");
24
25 params.addRequiredParam<MooseEnum>("component", component, "The desired component of flux.");
26 params.addRequiredParam<MooseFunctorName>("vel_x", "x-component of the velocity vector");
27 params.addParam<MooseFunctorName>("vel_y", "y-component of the velocity vector");
28 params.addParam<MooseFunctorName>("vel_z", "z-component of the velocity vector");
29 params.addCoupledVar(
30 "advected_variable",
31 "The advected variable quantity of which to compute advection flux; useful for "
32 "finite element simulations");
33 params.addParam<MaterialPropertyName>(
34 "advected_mat_prop",
35 0,
36 "The advected material property of which to compute advection flux; "
37 "useful for finite element simulations");
38 params.addParam<MooseFunctorName>("advected_quantity",
39 "The quantity to advect. This is the canonical parameter to "
40 "set the advected quantity when finite volume is being used.");
41
42 params.addClassDescription("Computes the volumetric advected quantity through a sideset.");
43
44 return params;
45}
46
47template <bool is_ad>
49 const InputParameters & parameters)
50 : SideIntegralPostprocessor(parameters),
51 _use_normal(getParam<MooseEnum>("component") == "normal"),
52 _component(getParam<MooseEnum>("component")),
53 _advected_variable_supplied(isParamValid("advected_variable")),
54 _advected_variable(_advected_variable_supplied ? coupledValue("advected_variable") : _zero),
55 _advected_mat_prop_supplied(parameters.isParamSetByUser("advected_mat_prop")),
56 _advected_material_property(getGenericMaterialProperty<Real, is_ad>("advected_mat_prop")),
57 _adv_quant(isParamValid("advected_quantity") ? &getFunctor<Real>("advected_quantity")
58 : nullptr),
59 _vel_x(getFunctor<Real>("vel_x")),
60 _vel_y(_mesh.dimension() >= 2 ? &getFunctor<Real>("vel_y") : nullptr),
61 _vel_z(_mesh.dimension() == 3 ? &getFunctor<Real>("vel_z") : nullptr)
62{
63 // Check that at most one advected quantity has been provided
65 {
68 "SideAdvectiveFluxIntegralPostprocessor should be provided either an advected quantity "
69 "or an advected material property");
70 }
71
72 // Check whether a finite element or finite volume variable is provide
74
75 checkFunctorSupportsSideIntegration<Real>("vel_x", _qp_integration);
76 if (_vel_y)
77 checkFunctorSupportsSideIntegration<Real>("vel_y", _qp_integration);
78 if (_vel_z)
79 checkFunctorSupportsSideIntegration<Real>("vel_z", _qp_integration);
80}
81
82template <bool is_ad>
83Real
85{
86 mooseAssert(fi, "We should have a face info in " + name());
87 mooseAssert(_adv_quant, "We should have an advected quantity in " + name());
88
89 const auto state = determineState();
90
91 // Get face value for velocity
92 const auto vel_x =
93 (_vel_x)(Moose::FaceArg(
94 {fi, Moose::FV::LimiterType::CentralDifference, true, false, nullptr, nullptr}),
95 state);
96 const auto vel_y =
97 _vel_y
98 ? ((*_vel_y)(
100 {fi, Moose::FV::LimiterType::CentralDifference, true, false, nullptr, nullptr}),
101 state))
102 : 0;
103 const auto vel_z =
104 _vel_z
105 ? ((*_vel_z)(
107 {fi, Moose::FV::LimiterType::CentralDifference, true, false, nullptr, nullptr}),
108 state))
109 : 0;
110
111 auto fi_normal = _current_elem == fi->elemPtr() ? fi->normal() : Point(-fi->normal());
112 const bool elem_is_upwind = RealVectorValue(vel_x, vel_y, vel_z) * fi_normal >= 0;
113
114 const auto adv_quant_face = (*_adv_quant)(
116 {fi, Moose::FV::LimiterType::CentralDifference, elem_is_upwind, false, nullptr, nullptr}),
117 state);
118
119 return fi_normal * adv_quant_face * RealVectorValue(vel_x, vel_y, vel_z);
120}
121
122template <bool is_ad>
123Real
125{
127
128 const auto state = determineState();
129 const Moose::ElemSideQpArg side_arg = {_current_elem, _current_side, _qp, _qrule, _q_point[_qp]};
130 const auto vel_x = raw_value(_vel_x(side_arg, state));
131 const auto vel_y = _vel_y ? raw_value((*_vel_y)(side_arg, state)) : 0;
132 const auto vel_z = _vel_z ? raw_value((*_vel_z)(side_arg, state)) : 0;
133
134 if (_advected_variable_supplied)
135 {
136
137 auto & variable = getCoupledMooseVars();
138 if (std::any_of(variable.begin(), variable.end(), [](auto & var) { return !var->isNodal(); }))
139 mooseError("Trying to use a non-nodal variable 'advected_variable' for side advection "
140 "integral calculation, which is currently not supported.");
141
142 return (_use_normal
143 ? _advected_variable[_qp] * RealVectorValue(vel_x, vel_y, vel_z) * _normals[_qp]
144 : _advected_variable[_qp] * RealVectorValue(vel_x, vel_y, vel_z)(_component));
145 }
146 else if (_advected_mat_prop_supplied)
147 return (_use_normal ? raw_value(_advected_material_property[_qp]) *
148 RealVectorValue(vel_x, vel_y, vel_z) * _normals[_qp]
149 : raw_value(_advected_material_property[_qp]) *
150 RealVectorValue(vel_x, vel_y, vel_z)(_component));
151 else
152 return (_use_normal ? RealVectorValue(vel_x, vel_y, vel_z) * _normals[_qp]
153 : RealVectorValue(vel_x, vel_y, vel_z)(_component));
154}
155
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
registerMooseObject("MooseApp", SideAdvectiveFluxIntegral)
This data structure is used to store geometric and variable related metadata about each cell face in ...
Definition FaceInfo.h:38
const Point & normal() const
Returns the unit normal vector for the face oriented outward from the face's elem element.
Definition FaceInfo.h:72
const Elem * elemPtr() const
Definition FaceInfo.h:86
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
void addCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
This postprocessor computes a side integral of the mass flux.
const bool _advected_variable_supplied
Whether an advected variable was supplied in the input.
SideAdvectiveFluxIntegralTempl(const InputParameters &parameters)
const Moose::Functor< Real > *const _vel_y
const Moose::Functor< Real > *const _vel_z
const bool _advected_mat_prop_supplied
Whether an advected material property was supplied in the input.
Real computeFaceInfoIntegral(const FaceInfo *fi) override
const Moose::Functor< Real > *const _adv_quant
The functor representing the advected quantity for finite volume.
This postprocessor computes a surface integral of the specified variable on a sideset on the boundary...
bool _qp_integration
Whether to integrate over quadrature points or FaceInfos.
static InputParameters validParams()
auto raw_value(const Eigen::Map< T > &in)
Argument for requesting functor evaluation at quadrature point locations on an element side.
A structure defining a "face" evaluation calling argument for Moose functors.