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 : #pragma once 11 : 12 : #include "RhieChowInterpolatorBase.h" 13 : #include "CellCenteredMapFunctor.h" 14 : #include "VectorComponentFunctor.h" 15 : #include "VectorCompositeFunctor.h" 16 : 17 : #include <unordered_map> 18 : #include <set> 19 : #include <unordered_set> 20 : 21 : class MooseMesh; 22 : class INSFVVelocityVariable; 23 : class INSFVPressureVariable; 24 : namespace libMesh 25 : { 26 : class Elem; 27 : class MeshBase; 28 : } 29 : 30 : /** 31 : * This user-object gathers 'a' (on-diagonal velocity coefficients) data. Having the gathered 'a' 32 : * data, this object is responsible for the computation of the Rhie-Chow velocity, which can be used 33 : * in advection kernels and postprocessors. This class also supports computation of an average face 34 : * velocity although this is generally not encouraged as it will lead to a checkerboard in the 35 : * pressure field 36 : */ 37 : 38 : class INSFVRhieChowInterpolator : public RhieChowInterpolatorBase 39 : { 40 : public: 41 : /** 42 : * Parameters of this object that should be added to the NSFV action that are unique to this 43 : * object 44 : */ 45 : static InputParameters uniqueParams(); 46 : 47 : /** 48 : * @returns A list of the parameters that are common between this object and the NSFV action 49 : */ 50 : static std::vector<std::string> listOfCommonParams(); 51 : 52 : static InputParameters validParams(); 53 : INSFVRhieChowInterpolator(const InputParameters & params); 54 : 55 : /** 56 : * API that momentum residual objects that have on-diagonals for velocity call 57 : * @param The element we are adding 'a' coefficient data for 58 : * @param component The velocity component we are adding 'a' coefficient data for 59 : * @param value The value of 'a' that we are adding 60 : */ 61 : virtual void 62 : addToA(const libMesh::Elem * elem, unsigned int component, const ADReal & value) override; 63 : 64 : /** 65 : * Retrieve a face velocity 66 : * @param m The velocity interpolation method. This is either Rhie-Chow or Average. Rhie-Chow is 67 : * recommended as it avoids checkerboards in the pressure field 68 : * @param fi The face that we wish to retrieve the velocity for 69 : * @param time The time at which to evaluate the velocity 70 : * @param tid The thread ID 71 : * @param subtract_mesh_velocity Whether to subtract the mesh velocity if running on a displaced 72 : * mesh 73 : * @return The face velocity 74 : */ 75 : virtual VectorValue<ADReal> getVelocity(const Moose::FV::InterpMethod m, 76 : const FaceInfo & fi, 77 : const Moose::StateArg & time, 78 : const THREAD_ID tid, 79 : bool subtract_mesh_velocity) const override; 80 : 81 : virtual void initialSetup() override; 82 : virtual void meshChanged() override; 83 : 84 : virtual void initialize() override; 85 : virtual void execute() override; 86 : virtual void finalize() override; 87 : 88 119694653 : virtual bool segregated() const override { return false; }; 89 : 90 : /** 91 : * makes sure coefficient data gets communicated on both sides of a given boundary 92 : */ 93 : virtual void ghostADataOnBoundary(const BoundaryID boundary_id) override; 94 : 95 : /** 96 : * Whether to pull all 'a' coefficient data from the owning process for all nonlocal elements we 97 : * have access to (e.g. all of our nonlocal elements we have pointers to) 98 : */ 99 19 : void pullAllNonlocal() { _pull_all_nonlocal = true; } 100 : 101 : /** 102 : * Whether central differencing face interpolations of velocity should include a skewness 103 : * correction 104 : * Also used for the face interpolation of the D coefficient 105 : * and the face interpolation of volumetric forces for for the volume correction method 106 : * and the face interpolation of porosity 107 : */ 108 : bool velocitySkewCorrection(THREAD_ID tid) const; 109 : 110 : /** 111 : * Whether central differencing face interpolations of pressure should include a skewness 112 : * correction 113 : */ 114 : bool pressureSkewCorrection(THREAD_ID tid) const; 115 : 116 : protected: 117 : /** 118 : * perform the setup of this object 119 : */ 120 : void insfvSetup(); 121 : 122 : /// A functor for computing the (non-RC corrected) velocity 123 : std::vector<std::unique_ptr<PiecewiseByBlockLambdaFunctor<ADRealVectorValue>>> _vel; 124 : 125 : /// All the thread copies of the x-displacement variable 126 : std::vector<MooseVariableField<Real> *> _disp_xs; 127 : 128 : /// All the thread copies of the y-displacement variable 129 : std::vector<MooseVariableField<Real> *> _disp_ys; 130 : 131 : /// All the thread copies of the z-displacement variable 132 : std::vector<MooseVariableField<Real> *> _disp_zs; 133 : 134 : /// A functor for computing the displacement 135 : std::vector<std::unique_ptr<Moose::VectorCompositeFunctor<ADReal>>> _disps; 136 : 137 : /// All the active and elements local to this process that exist on this object's subdomains 138 : std::unique_ptr<ConstElemRange> _elem_range; 139 : 140 : /// A map from element IDs to 'a' coefficient data 141 : CellCenteredMapFunctor<ADRealVectorValue, std::unordered_map<dof_id_type, ADRealVectorValue>> _a; 142 : 143 : /** 144 : * @name 'a' component functors 145 : * These vector component functors are not used anywhere within this class but they can be used 146 : * for outputting, to auxiliary variables, the on-diagonal 'a' coefficients for use in 147 : * visualization or transfer to other applications 148 : */ 149 : ///@{ 150 : /// The x-component of 'a' 151 : Moose::VectorComponentFunctor<ADReal> _ax; 152 : 153 : /// The y-component of 'a' 154 : Moose::VectorComponentFunctor<ADReal> _ay; 155 : 156 : /// The z-component of 'a' 157 : Moose::VectorComponentFunctor<ADReal> _az; 158 : ///@} 159 : 160 : /// The number of the nonlinear system in which the monolithic momentum and continuity equations are located 161 : const unsigned int _momentum_sys_number; 162 : 163 : private: 164 : /** 165 : * Fills the _a_read data member at construction time with the appropriate functors. _a_read will 166 : * be used later when computing the Rhie-Chow velocity 167 : */ 168 : void fillARead(); 169 : 170 : /** 171 : * Whether we need 'a' coefficient computation 172 : */ 173 : bool needAComputation() const; 174 : 175 : /// Non-local elements that we should push and pull data for across processes 176 : std::unordered_set<const Elem *> _elements_to_push_pull; 177 : 178 : /// An example datum used to help communicate AD vector information in parallel 179 : const VectorValue<ADReal> _example; 180 : 181 : /// Mutex that prevents multiple threads from saving into the 'a' coefficients at the same time 182 : Threads::spin_mutex _a_mutex; 183 : 184 : /// A vector sized according to the number of threads that holds the 'a' data we will read from 185 : /// when computing the Rhie-Chow velocity 186 : std::vector<const Moose::FunctorBase<VectorValue<ADReal>> *> _a_read; 187 : 188 : /// A vector sized according to the number of threads that holds vector composites of 'a' 189 : /// component functors. This member is leveraged when advecting velocities are auxiliary variables 190 : /// and the 'a' data has been transferred from another application 191 : std::vector<std::unique_ptr<Moose::FunctorBase<VectorValue<ADReal>>>> _a_aux; 192 : 193 : /// Whether 'a' data has been provided by the user. This can happen if we are running in an 194 : /// application solving precursor advection, and another application has computed the fluid flow 195 : /// field 196 : bool _a_data_provided; 197 : 198 : /// Whether we want to pull all nonlocal 'a' coefficient data 199 : bool _pull_all_nonlocal; 200 : 201 : /// Correct Rhie-Chow coefficients for volumetric force flag 202 : const bool & _bool_correct_vf; 203 : 204 : /// -- Method used for computing the properties average 205 : const MooseEnum _volume_force_correction_method; 206 : 207 : /// Names of the functors storing the volumetric forces 208 : const std::vector<MooseFunctorName> * _volumetric_force_functors; 209 : 210 : /// Values of the functors storing the volumetric forces 211 : std::vector<const Moose::Functor<Real> *> _volumetric_force; 212 : 213 : /// Minimum absolute RC force over the domain 214 : Real _baseline_volume_force; 215 : 216 : /// A zero functor potentially used in _a_read 217 : const Moose::ConstantFunctor<ADReal> _zero_functor{0}; 218 : }; 219 : 220 : inline void 221 413183774 : INSFVRhieChowInterpolator::addToA(const Elem * const elem, 222 : const unsigned int component, 223 : const ADReal & value) 224 : { 225 : Threads::spin_mutex::scoped_lock lock(_a_mutex); 226 : 227 413183774 : if (elem->processor_id() != this->processor_id()) 228 : _elements_to_push_pull.insert(elem); 229 : 230 413183774 : _a[elem->id()](component) += value; 231 413183774 : } 232 : 233 : inline bool 234 : INSFVRhieChowInterpolator::needAComputation() const 235 : { 236 : // We dont check for "a"s being in another nonlinear system here, only being auxiliary 237 189133 : return !_a_data_provided && _velocity_interp_method == Moose::FV::InterpMethod::RhieChow; 238 : } 239 : 240 : inline bool 241 : INSFVRhieChowInterpolator::velocitySkewCorrection(const THREAD_ID tid) const 242 : { 243 : const auto * const u = _us[tid]; 244 245302473 : return (u->faceInterpolationMethod() == Moose::FV::InterpMethod::SkewCorrectedAverage); 245 : } 246 : 247 : inline bool 248 : INSFVRhieChowInterpolator::pressureSkewCorrection(const THREAD_ID tid) const 249 : { 250 148878507 : const auto * const p = _ps[tid]; 251 148878507 : return (p->faceInterpolationMethod() == Moose::FV::InterpMethod::SkewCorrectedAverage); 252 : }