www.mooseframework.org
VolumetricFlowRate.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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  return params;
42 }
43 
45  : SideIntegralPostprocessor(parameters),
46  _vel_x(coupledValue("vel_x")),
47  _vel_y(coupledValue("vel_y")),
48  _vel_z(coupledValue("vel_z")),
49  _advected_variable_supplied(parameters.isParamSetByUser("advected_variable")),
50  _advected_variable(coupledValue("advected_variable")),
51  _advected_mat_prop_supplied(parameters.isParamSetByUser("advected_mat_prop")),
52  _advected_material_property(getFunctor<ADReal>("advected_mat_prop")),
53  _adv_quant(isParamValid("advected_quantity") ? &getFunctor<ADReal>("advected_quantity")
54  : nullptr),
55  _rc_uo(isParamValid("rhie_chow_user_object")
56  ? &getUserObject<RhieChowInterpolatorBase>("rhie_chow_user_object")
57  : nullptr)
58 {
59  // Check that at most one advected quantity has been provided
61  mooseError("VolumetricFlowRatePostprocessor should be provided either an advected variable "
62  "or an advected material property");
63 
64  // Check that the user isn't trying to get face values for material properties
65  if (parameters.isParamSetByUser("advected_interp_method") && _advected_mat_prop_supplied)
66  mooseWarning("Advected quantity interpolation methods are currently unavailable for "
67  "advected material properties.");
68 
69  _qp_integration = !getFieldVar("vel_x", 0)->isFV();
70 
72  checkFunctorSupportsSideIntegration<ADReal>("advected_mat_prop", _qp_integration);
73  if (_adv_quant)
74  checkFunctorSupportsSideIntegration<ADReal>("advected_quantity", _qp_integration);
75 
76  if (!_qp_integration)
77  {
78  if (!_rc_uo)
79  mooseError("We were instructed to use finite volume, but no Rhie-Chow user object is "
80  "supplied. Please make sure to set the 'rhie_chow_user_object' parameter");
81  if (!_adv_quant)
82  mooseError("We were instructed to use finite volume, but no 'advected_quantity' parameter is "
83  "supplied.");
84 
86  }
87 }
88 
89 void
91 {
93  !_rc_uo->segregated())
94  {
95  // We must make sure the A coefficients in the Rhie Chow interpolator are present on
96  // both sides of the boundaries so that interpolation coefficients may be computed
97  for (const auto bid : boundaryIDs())
98  const_cast<RhieChowInterpolatorBase *>(_rc_uo)->ghostADataOnBoundary(bid);
99 
100  // On INITIAL, we cannot compute Rhie Chow coefficients on internal surfaces because
101  // - the time integrator is not ready to compute time derivatives
102  // - the setup routine is called too early for porosity functions to be initialized
103  // We must check that the boundaries requested are all external
104  if (getExecuteOnEnum().contains(EXEC_INITIAL))
105  for (const auto bid : boundaryIDs())
106  {
108  paramError(
109  "execute_on",
110  "Boundary '",
111  _mesh.getBoundaryName(bid),
112  "' (id=",
113  bid,
114  ") has been detected to be internal to the flow domain.\n"
115  "Volumetric flow rates cannot be computed on internal flow boundaries on INITIAL");
116  }
117  }
118 }
119 
120 void
122 {
123  initialSetup();
124 }
125 
126 Real
128 {
129  mooseAssert(fi, "We should have a face info in " + name());
130  mooseAssert(_adv_quant, "We should have an advected quantity in " + name());
131  const auto state = determineState();
132 
133  // Get face value for velocity
134  const auto vel = MetaPhysicL::raw_value(_rc_uo->getVelocity(
135  _velocity_interp_method, *fi, state, _tid, /*subtract_mesh_velocity=*/true));
136 
137  const bool correct_skewness =
139 
140  const auto adv_quant_face = MetaPhysicL::raw_value(
141  (*_adv_quant)(Moose::FaceArg({fi,
143  MetaPhysicL::raw_value(vel) * fi->normal() > 0,
144  correct_skewness,
145  nullptr}),
146  state));
147  return fi->normal() * adv_quant_face * vel;
148 }
149 
150 Real
152 {
155  _normals[_qp];
160  else
162 }
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 VariableValue & _vel_z
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
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)
Moose::FV::InterpMethod velocityInterpolationMethod() const
Return the interpolation method used for velocity.
const MooseArray< Point > & _q_point
virtual const std::set< SubdomainID > & blockIDs() const
registerMooseObject("NavierStokesApp", VolumetricFlowRate)
Real computeFaceInfoIntegral(const FaceInfo *fi) override
virtual const std::string & name() const
void mooseWarning(Args &&... args) 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.
LimiterType limiterType(InterpMethod interp_method)
virtual bool segregated() const =0
Bool of the Rhie Chow user object is used in monolithic/segregated approaches.
static InputParameters validParams()
const ExecFlagEnum & getExecuteOnEnum() const
const VariableValue & _vel_y
const RhieChowInterpolatorBase *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.
const Point & normal() const
void paramError(const std::string &param, Args... args) const
This postprocessor computes the volumetric flow rate through a boundary, internal or external to the ...
const VariableValue & _advected_variable
Variable storing the advected quantity; used for finite elements.
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
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
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