https://mooseframework.inl.gov
VolumetricFlowRate.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 
10 #include "VolumetricFlowRate.h"
11 #include "MathFVUtils.h"
13 #include "NSFVUtils.h"
14 
15 #include <cmath>
16 
17 registerMooseObject("NavierStokesApp", VolumetricFlowRate);
18 
21 {
23  params.addClassDescription(
24  "Computes the volumetric flow rate of an advected quantity through a sideset.");
25  params.addRequiredCoupledVar("vel_x", "The x-axis velocity");
26  params.addCoupledVar("vel_y", 0, "The y-axis velocity");
27  params.addCoupledVar("vel_z", 0, "The z-axis velocity");
28  params.addCoupledVar("advected_variable",
29  0,
30  "The advected variable quantity of which to study the flow; useful for "
31  "finite element simulations");
32  params.addParam<MooseFunctorName>("advected_mat_prop",
33  0,
34  "The advected material property of which to study the flow; "
35  "useful for finite element simulations");
36  params.addParam<MooseFunctorName>("advected_quantity",
37  "The quantity to advect. This is the canonical parameter to "
38  "set the advected quantity when finite volume is being used.");
40  params.addParam<UserObjectName>("rhie_chow_user_object", "The rhie-chow user-object");
41  params.addParam<bool>("subtract_mesh_velocity",
42  "To subtract the velocity of the potentially moving mesh. Defaults to true "
43  "if a displaced problem exists, else false.");
44  return params;
45 }
46 
48  : SideIntegralPostprocessor(parameters),
49  _vel_x(coupledValue("vel_x")),
50  _vel_y(coupledValue("vel_y")),
51  _vel_z(coupledValue("vel_z")),
52  _advected_variable_supplied(parameters.isParamSetByUser("advected_variable")),
53  _advected_variable(coupledValue("advected_variable")),
54  _advected_mat_prop_supplied(parameters.isParamSetByUser("advected_mat_prop")),
55  _advected_material_property(getFunctor<ADReal>("advected_mat_prop")),
56  _adv_quant(isParamValid("advected_quantity") ? &getFunctor<ADReal>("advected_quantity")
57  : nullptr),
58  _rc_uo(isParamValid("rhie_chow_user_object")
59  ? &getUserObject<RhieChowFaceFluxProvider>("rhie_chow_user_object")
60  : nullptr),
61  _subtract_mesh_velocity(isParamValid("subtract_mesh_velocity")
62  ? getParam<bool>("subtract_mesh_velocity")
63  : _fe_problem.haveDisplaced())
64 {
65  // Check that at most one advected quantity has been provided
67  mooseError("VolumetricFlowRatePostprocessor should be provided either an advected variable "
68  "or an advected material property");
69 
70  // Check that the user isn't trying to get face values for material properties
71  if (parameters.isParamSetByUser("advected_interp_method") && _advected_mat_prop_supplied)
72  mooseWarning("Advected quantity interpolation methods are currently unavailable for "
73  "advected material properties.");
74 
75  _qp_integration = !getFieldVar("vel_x", 0)->isFV();
76 
78  checkFunctorSupportsSideIntegration<ADReal>("advected_mat_prop", _qp_integration);
79  if (_adv_quant)
80  checkFunctorSupportsSideIntegration<ADReal>("advected_quantity", _qp_integration);
81 
82  if (!_qp_integration)
83  {
84  if (!_rc_uo)
85  mooseError("We were instructed to use finite volume, but no Rhie-Chow user object is "
86  "supplied. Please make sure to set the 'rhie_chow_user_object' parameter");
87  if (!_adv_quant)
88  mooseError("We were instructed to use finite volume, but no 'advected_quantity' parameter is "
89  "supplied.");
90 
92  }
93 
95  paramError("subtract_mesh_velocity",
96  "Rhie Chow user object does not support subtracting the mesh velocity");
98  paramError(
99  "subtract_mesh_velocity",
100  "No displaced problem, thus the mesh velocity is 0 and does not need to be subtracted");
101 }
102 
103 void
105 {
106  const auto * rc_base = dynamic_cast<const RhieChowInterpolatorBase *>(_rc_uo);
107  if (_rc_uo && rc_base &&
108  rc_base->velocityInterpolationMethod() == Moose::FV::InterpMethod::RhieChow &&
109  !rc_base->segregated())
110  {
111  // We must make sure the A coefficients in the Rhie Chow interpolator are present on
112  // both sides of the boundaries so that interpolation coefficients may be computed
113  for (const auto bid : boundaryIDs())
114  const_cast<RhieChowInterpolatorBase *>(rc_base)->ghostADataOnBoundary(bid);
115 
116  // On INITIAL, we cannot compute Rhie Chow coefficients on internal surfaces because
117  // - the time integrator is not ready to compute time derivatives
118  // - the setup routine is called too early for porosity functions to be initialized
119  // We must check that the boundaries requested are all external
120  if (getExecuteOnEnum().isValueSet(EXEC_INITIAL))
121  for (const auto bid : boundaryIDs())
122  {
123  if (!_mesh.isBoundaryFullyExternalToSubdomains(bid, rc_base->blockIDs()))
124  paramError(
125  "execute_on",
126  "Boundary '",
127  _mesh.getBoundaryName(bid),
128  "' (id=",
129  bid,
130  ") has been detected to be internal to the flow domain.\n"
131  "Volumetric flow rates cannot be computed on internal flow boundaries on INITIAL");
132  }
133  }
134 }
135 
136 void
138 {
139  initialSetup();
140 }
141 
142 Real
144 {
145  mooseAssert(fi, "We should have a face info in " + name());
146  mooseAssert(_adv_quant, "We should have an advected quantity in " + name());
147  const auto state = determineState();
148 
149  // Get face value for velocity
150  const auto face_flux = MetaPhysicL::raw_value(_rc_uo->getVolumetricFaceFlux(
152 
153  const bool correct_skewness =
155 
156  mooseAssert(_adv_quant->hasFaceSide(*fi, true) || _adv_quant->hasFaceSide(*fi, false),
157  "Advected quantity should be defined on one side of the face!");
158 
159  const auto * elem = _adv_quant->hasFaceSide(*fi, true) ? fi->elemPtr() : fi->neighborPtr();
160 
161  const auto adv_quant_face = MetaPhysicL::raw_value(
162  (*_adv_quant)(Moose::FaceArg({fi,
164  face_flux > 0,
165  correct_skewness,
166  elem,
167  nullptr}),
168  state));
169  return face_flux * adv_quant_face;
170 }
171 
172 Real
174 {
177  _normals[_qp];
182  else
184 }
bool setInterpolationMethods(const MooseObject &obj, Moose::FV::InterpMethod &advected_interp_method, Moose::FV::InterpMethod &velocity_interp_method)
Sets the advection and velocity interpolation methods.
Definition: NSFVUtils.C:21
Moose::FV::InterpMethod _advected_interp_method
The interpolation method to use for the advected quantity.
const bool _subtract_mesh_velocity
If the velocity of the potentially moving mesh should be subtracted or not.
const VariableValue & _vel_z
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
bool haveDisplaced() const override final
static InputParameters validParams()
InputParameters interpolationParameters()
Definition: NSFVUtils.C:41
Moose::StateArg determineState() const
virtual bool isFV() const
const std::string & getBoundaryName(BoundaryID boundary_id)
VolumetricFlowRate(const InputParameters &parameters)
auto raw_value(const Eigen::Map< T > &in)
const MooseArray< Point > & _q_point
virtual void ghostADataOnBoundary(const BoundaryID)
makes sure coefficient data gets communicated on both sides of a given boundary.
registerMooseObject("NavierStokesApp", VolumetricFlowRate)
Real computeFaceInfoIntegral(const FaceInfo *fi) override
virtual const std::string & name() const
void mooseWarning(Args &&... args) const
LimiterType limiterType(InterpMethod interp_method)
const Elem * neighborPtr() const
static InputParameters validParams()
const ExecFlagEnum & getExecuteOnEnum() const
const VariableValue & _vel_y
const RhieChowFaceFluxProvider *const _rc_uo
The Rhie-Chow interpolation user object.
const Moose::Functor< ADReal > *const _adv_quant
The functor representing the advected quantity for finite volume.
const Moose::Functor< ADReal > & _advected_material_property
Material property storing the advected quantity; used for finite elements.
void paramError(const std::string &param, Args... args) const
This postprocessor computes the volumetric flow rate through a boundary, internal or external to the ...
virtual bool supportMeshVelocity() const
Returns whether the UO can support mesh velocity advection.
const VariableValue & _advected_variable
Variable storing the advected quantity; used for finite elements.
const Elem * elemPtr() const
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const bool _advected_mat_prop_supplied
Whether an advected material property was supplied in the input.
bool isParamSetByUser(const std::string &name) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Moose::FV::InterpMethod _velocity_interp_method
The interpolation method to use for the velocity.
void meshChanged() override
FEProblemBase & _fe_problem
const QBase *const & _qrule
const MooseArray< Point > & _normals
void mooseError(Args &&... args) const
const bool _advected_variable_supplied
Whether an advected variable was supplied in the input.
void addClassDescription(const std::string &doc_string)
const InputParameters & parameters() const
const VariableValue & _vel_x
Velocity components.
const Elem *const & _current_elem
virtual Real getVolumetricFaceFlux(const Moose::FV::InterpMethod m, const FaceInfo &fi, const Moose::StateArg &time, const THREAD_ID tid, bool subtract_mesh_velocity) const =0
Retrieve the volumetric face flux, will not include derivatives.
void initialSetup() override
Currently only requests some boundary data from the RhieChow interpolator.
Real computeQpIntegral() override
virtual const std::set< BoundaryID > & boundaryIDs() const
bool isBoundaryFullyExternalToSubdomains(BoundaryID bid, const std::set< SubdomainID > &blk_group) const
const MooseVariableFieldBase * getFieldVar(const std::string &var_name, unsigned int comp) const
const ExecFlagType EXEC_INITIAL