Line data Source code
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 "MassFluxWeightedFlowRate.h" 11 : #include "MathFVUtils.h" 12 : #include "INSFVRhieChowInterpolator.h" 13 : #include "NSFVUtils.h" 14 : #include "NS.h" 15 : #include "SinglePhaseFluidProperties.h" 16 : 17 : #include <math.h> 18 : 19 : registerMooseObject("NavierStokesApp", MassFluxWeightedFlowRate); 20 : 21 : InputParameters 22 38 : MassFluxWeightedFlowRate::validParams() 23 : { 24 38 : InputParameters params = VolumetricFlowRate::validParams(); 25 76 : params.addRequiredParam<MooseFunctorName>("density", 26 : "Provide a functor that returns the density."); 27 38 : params.addClassDescription("Computes the mass flux weighted average of the quantity " 28 : "provided by advected_quantity over a boundary."); 29 38 : return params; 30 0 : } 31 : 32 20 : MassFluxWeightedFlowRate::MassFluxWeightedFlowRate(const InputParameters & parameters) 33 40 : : VolumetricFlowRate(parameters), _density(getFunctor<ADReal>("density")), _mdot(0) 34 : { 35 20 : if (_qp_integration) 36 0 : mooseError("This object only works only with finite volume."); 37 : 38 20 : checkFunctorSupportsSideIntegration<ADReal>("density", _qp_integration); 39 20 : } 40 : 41 : void 42 92 : MassFluxWeightedFlowRate::initialize() 43 : { 44 92 : VolumetricFlowRate::initialize(); 45 92 : _mdot = 0; 46 92 : } 47 : 48 : Real 49 248 : MassFluxWeightedFlowRate::computeFaceInfoIntegral([[maybe_unused]] const FaceInfo * fi) 50 : { 51 : mooseAssert(fi, "We should have a face info in " + name()); 52 : mooseAssert(_adv_quant, "We should have an advected quantity in " + name()); 53 248 : const auto state = determineState(); 54 : 55 : // Get face value for velocity 56 248 : const auto face_flux = MetaPhysicL::raw_value(_rc_uo->getVolumetricFaceFlux( 57 248 : _velocity_interp_method, *fi, state, _tid, /*subtract_mesh_velocity=*/true)); 58 248 : const bool correct_skewness = 59 248 : _advected_interp_method == Moose::FV::InterpMethod::SkewCorrectedAverage; 60 : 61 : mooseAssert(_adv_quant->hasFaceSide(*fi, true) || _adv_quant->hasFaceSide(*fi, true), 62 : "Advected quantity must be defined on one of the sides of the face!"); 63 : mooseAssert((_adv_quant->hasFaceSide(*fi, true) == _density.hasFaceSide(*fi, true)) || 64 : (_adv_quant->hasFaceSide(*fi, false) == _density.hasFaceSide(*fi, false)), 65 : "Density must be defined at least on one of the sides where the advected quantity is " 66 : "defined!"); 67 : 68 248 : const auto face_arg = 69 : Moose::FaceArg({fi, 70 248 : Moose::FV::limiterType(_advected_interp_method), 71 248 : face_flux > 0, 72 : correct_skewness, 73 248 : _adv_quant->hasFaceSide(*fi, true) ? fi->elemPtr() : fi->neighborPtr(), 74 248 : nullptr}); 75 248 : auto dens = _density(face_arg, state); 76 248 : const auto adv_quant_face = MetaPhysicL::raw_value(dens * (*_adv_quant)(face_arg, state)); 77 248 : _mdot += fi->faceArea() * fi->faceCoord() * MetaPhysicL::raw_value(dens) * face_flux; 78 248 : return face_flux * adv_quant_face; 79 : } 80 : 81 : void 82 10 : MassFluxWeightedFlowRate::threadJoin(const UserObject & y) 83 : { 84 10 : VolumetricFlowRate::threadJoin(y); 85 : const auto & pps = static_cast<const MassFluxWeightedFlowRate &>(y); 86 10 : _mdot += pps._mdot; 87 10 : } 88 : 89 : Real 90 82 : MassFluxWeightedFlowRate::getValue() const 91 : { 92 82 : return _integral_value / _mdot; 93 : } 94 : 95 : void 96 82 : MassFluxWeightedFlowRate::finalize() 97 : { 98 82 : VolumetricFlowRate::finalize(); 99 82 : gatherSum(_mdot); 100 82 : }