https://mooseframework.inl.gov
Loading...
Searching...
No Matches
RhieChowMassFlux.h
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#pragma once
11
16#include <unordered_map>
17#include <set>
18
19#include "libmesh/petsc_vector.h"
20
21class MooseMesh;
27namespace libMesh
28{
29class Elem;
30class MeshBase;
31}
32
38{
39public:
41 RhieChowMassFlux(const InputParameters & params);
42
44 Real getMassFlux(const FaceInfo & fi) const;
45
47 Real getVolumetricFaceFlux(const FaceInfo & fi) const;
48
51
54
56 const std::vector<NumericVector<Number> *> & basePressureGradientComponents() const;
57
59 const std::vector<std::unique_ptr<NumericVector<Number>>> & HbyAComponents() const;
60
62 const std::vector<std::unique_ptr<NumericVector<Number>>> & AinvComponents() const;
63
65 unsigned int pressureVariableNumber() const;
66
68 unsigned int dimension() const { return _dim; }
69
71 MooseLinearVariableFVReal & velocityVariable(unsigned int component) { return *_vel[component]; }
72
74 const MooseLinearVariableFVReal & velocityVariable(unsigned int component) const
75 {
76 return *_vel[component];
77 }
78
80 LinearSystem & momentumSystem(unsigned int component) { return *_momentum_systems[component]; }
81
83 const LinearSystem & momentumSystem(unsigned int component) const
84 {
85 return *_momentum_systems[component];
86 }
87
89 const LinearSystem & pressureSystem() const { return *_pressure_system; }
90
96 dof_id_type faceMassFluxGeneration() const { return _face_mass_flux_generation; }
97
99 const FaceInfo & fi,
100 const Moose::StateArg & time,
101 const THREAD_ID tid,
102 bool subtract_mesh_velocity) const override;
103
105 void initFaceMassFlux();
107 void initCouplingField();
109 void computeFaceMassFlux();
110
113
116
119
122
129
136
140
141 virtual void meshChanged() override;
142 virtual void initialize() override;
143 virtual void execute() override {}
144 virtual void finalize() override {}
145 virtual void initialSetup() override;
146
152 virtual void timestepSetup() override;
153
161 void linkMomentumPressureSystems(const std::vector<LinearSystem *> & momentum_systems,
162 LinearSystem & pressure_system,
163 const std::vector<unsigned int> & momentum_system_numbers);
164
169 void computeHbyA(const bool verbose);
170
171protected:
173 template <typename GradientComponent>
174 void updateCellVelocity(const std::vector<GradientComponent> & pressure_gradient);
175
177 const std::vector<NumericVector<Number> *> & pressureGradientComponents() const;
178
181
184
187
190
192 void
193 populateCouplingFunctors(const std::vector<std::unique_ptr<NumericVector<Number>>> & raw_hbya,
194 const std::vector<std::unique_ptr<NumericVector<Number>>> & raw_Ainv);
195
199 template <typename VarType>
200 void checkBlocks(const VarType & var) const;
201
202 virtual bool supportMeshVelocity() const override { return false; }
203
206
209
211 const unsigned int _dim;
212
215
218 std::vector<MooseLinearVariableFVReal *> _vel;
219
222
230
235 std::vector<std::unique_ptr<NumericVector<Number>>> _HbyA_raw;
236
242
247 std::vector<std::unique_ptr<NumericVector<Number>>> _Ainv_raw;
248
249 std::unique_ptr<NumericVector<Number>> _A_avg;
250
255
257 std::vector<std::unique_ptr<NumericVector<Number>>> _grad_p_current;
258
266
271
273 std::vector<LinearSystem *> _momentum_systems;
274
276 std::vector<unsigned int> _momentum_system_numbers;
277
279 std::vector<unsigned int> _global_momentum_system_numbers;
280
282 std::vector<libMesh::LinearImplicitSystem *> _momentum_implicit_systems;
283
286
289
292
295
297 std::unique_ptr<NumericVector<Number>> _cell_volumes;
298
301
304
305private:
308 std::vector<const FaceInfo *> _flow_face_info;
309};
310
311template <typename VarType>
312void
313RhieChowMassFlux::checkBlocks(const VarType & var) const
314{
315 const auto & var_blocks = var.blockIDs();
316 const auto & uo_blocks = blockIDs();
317
318 // Error if this UO has any blocks that the variable does not
319 std::set<SubdomainID> uo_blocks_minus_var_blocks;
320 std::set_difference(uo_blocks.begin(),
321 uo_blocks.end(),
322 var_blocks.begin(),
323 var_blocks.end(),
324 std::inserter(uo_blocks_minus_var_blocks, uo_blocks_minus_var_blocks.end()));
325 if (uo_blocks_minus_var_blocks.size() > 0)
326 mooseError("Block restriction of interpolator user object '",
327 this->name(),
328 "' (",
330 ") includes blocks not in the block restriction of variable '",
331 var.name(),
332 "' (",
333 Moose::stringify(var.blocks()),
334 ")");
335
336 // Get the blocks in the variable but not this UO
337 std::set<SubdomainID> var_blocks_minus_uo_blocks;
338 std::set_difference(var_blocks.begin(),
339 var_blocks.end(),
340 uo_blocks.begin(),
341 uo_blocks.end(),
342 std::inserter(var_blocks_minus_uo_blocks, var_blocks_minus_uo_blocks.end()));
343
344 // For each block in the variable but not this UO, error if there is connection
345 // to any blocks on the UO.
346 for (auto & block_id : var_blocks_minus_uo_blocks)
347 {
348 const auto connected_blocks = _moose_mesh.getBlockConnectedBlocks(block_id);
349 std::set<SubdomainID> connected_blocks_on_uo;
350 std::set_intersection(connected_blocks.begin(),
351 connected_blocks.end(),
352 uo_blocks.begin(),
353 uo_blocks.end(),
354 std::inserter(connected_blocks_on_uo, connected_blocks_on_uo.end()));
355 if (connected_blocks_on_uo.size() > 0)
356 mooseError("Block restriction of interpolator user object '",
357 this->name(),
358 "' (",
359 Moose::stringify(uo_blocks),
360 ") doesn't match the block restriction of variable '",
361 var.name(),
362 "' (",
363 Moose::stringify(var_blocks),
364 ")");
365 }
366}
unsigned int THREAD_ID
virtual const std::set< SubdomainID > & blockIDs() const
const std::vector< SubdomainName > & blocks() const
Gradient method that reconstructs and relaxes the pressure gradient used for Rhie-Chow momentum-press...
A functor whose evaluation relies on querying a map where the keys are face info ids and the values c...
Pressure correction diffusion kernel for the linear finite volume SIMPLE algorithm.
const std::string & name() const
void mooseError(Args &&... args) const
const std::set< SubdomainID > & getBlockConnectedBlocks(const SubdomainID subdomain_id) const
User object responsible for determining the face fluxes using the Rhie-Chow interpolation in a segreg...
const MooseMesh & _moose_mesh
The MooseMesh that this user object operates on.
void updateCellVelocity(const std::vector< GradientComponent > &pressure_gradient)
Update cell velocity from the supplied momentum-coupling pressure gradient.
const Moose::FV::InterpMethod _pressure_diffusion_interp_method
Interpolation method used for the pressure diffusion coefficient on faces.
const LinearSystem & momentumSystem(unsigned int component) const
Momentum linear system for one spatial component.
MooseLinearVariableFVReal & velocityVariable(unsigned int component)
Velocity variable for one spatial component.
const LinearFVGradientReader & basePressureGradientField() const
Get the base pressure gradient field used to seed reconstructed gradient updates.
std::vector< std::unique_ptr< NumericVector< Number > > > _grad_p_current
Coupling pressure gradient captured before the current momentum predictor is assembled.
virtual bool supportMeshVelocity() const override
Returns whether the UO can support mesh velocity advection.
const LinearFVGradientReader * _pressure_gradient_field
Registered pressure gradient field used by Rhie-Chow and compatible momentum pressure kernels.
void linkMomentumPressureSystems(const std::vector< LinearSystem * > &momentum_systems, LinearSystem &pressure_system, const std::vector< unsigned int > &momentum_system_numbers)
Update the momentum system-related information.
const LinearSystem & pressureSystem() const
Pressure linear system.
void initFaceMassFlux()
Initialize the container for face velocities.
LinearFVPressureCorrectionDiffusion * _p_diffusion_kernel
Pointer to the pressure diffusion term in the pressure Poisson equation.
const std::vector< NumericVector< Number > * > & pressureGradientComponents() const
Get the registered pressure gradient component vectors.
const libMesh::MeshBase & _mesh
The libMesh mesh that this object acts on.
std::vector< unsigned int > _momentum_system_numbers
Numbers of the momentum system(s)
virtual void initialize() override
virtual void timestepSetup() override
Prepare reconstructed-gradient state once per attempted time step.
unsigned int _global_pressure_system_number
Global number of the pressure system.
const MooseLinearVariableFVReal *const _p
The thread 0 copy of the pressure variable.
Real getMassFlux(const FaceInfo &fi) const
Get the face velocity times density (used in advection terms)
std::vector< LinearSystem * > _momentum_systems
Pointers to the linear system(s) in moose corresponding to the momentum equation(s)
std::unique_ptr< NumericVector< Number > > _A_avg
void finalizePressureCorrector()
After pressure relaxation, refresh every registered pressure gradient and publish relaxed reconstruct...
virtual Real getVolumetricFaceFlux(const Moose::FV::InterpMethod m, const FaceInfo &fi, const Moose::StateArg &time, const THREAD_ID tid, bool subtract_mesh_velocity) const override
Retrieve the volumetric face flux, will not include derivatives.
void preparePISOCorrector()
Capture the lagged velocity gradient for another corrector using the current predictor.
std::unique_ptr< NumericVector< Number > > _cell_volumes
We will hold a vector of cell volumes to make sure we can do volume corrections rapidly.
virtual void meshChanged() override
void populateCouplingFunctors(const std::vector< std::unique_ptr< NumericVector< Number > > > &raw_hbya, const std::vector< std::unique_ptr< NumericVector< Number > > > &raw_Ainv)
Populate the face values of the H/A and 1/A fields.
virtual void initialSetup() override
Real getVolumetricFaceFlux(const FaceInfo &fi) const
Get the volumetric face flux (used in advection terms)
std::vector< MooseLinearVariableFVReal * > _vel
Thread 0 copies of the velocity variables; non-const to allow writing cell velocities in updateCellVe...
void checkReconstructedPressureGradientCompatibility() const
Check the single-variable system layout assumed by reconstructed pressure-gradient vector ops.
void finalizeMomentumPredictor()
Capture the lagged velocity gradients computed while assembling the momentum predictor.
const MooseLinearVariableFVReal & velocityVariable(unsigned int component) const
Velocity variable for one spatial component.
LinearSystem * _pressure_system
Pointer to the pressure system.
dof_id_type _face_mass_flux_generation
Producer counter for the conservative face mass flux: incremented every time computeFaceMassFlux() ru...
void computeFaceMassFlux()
Update the values of the face velocities in the containers.
std::vector< std::unique_ptr< NumericVector< Number > > > _Ainv_raw
We hold on to the cell-based 1/A vectors so that we can easily reconstruct the cell velocities as wel...
void computeHbyA(const bool verbose)
Computes the inverse of the diagonal (1/A) of the system matrix plus the H/A components for the press...
const std::vector< std::unique_ptr< NumericVector< Number > > > & HbyAComponents() const
Get the momentum-layout H/A component vectors.
std::vector< const FaceInfo * > _flow_face_info
The subset of the FaceInfo objects that actually cover the subdomains which the flow field is defined...
dof_id_type faceMassFluxGeneration() const
Producer counter for the conservative face mass flux: incremented every time computeFaceMassFlux() ru...
void initPressureGradient()
Compute every registered pressure gradient once, before the first momentum predictor of a SIMPLE iter...
std::vector< std::unique_ptr< NumericVector< Number > > > _HbyA_raw
We hold on to the cell-based HbyA vectors so that we can easily reconstruct the cell velocities as we...
void checkBlocks(const VarType &var) const
Check the block consistency between the passed in var and us.
LinearSystem & momentumSystem(unsigned int component)
Momentum linear system for one spatial component.
FVReconstructedPressureGradient & reconstructedGradientMethod()
Access the reconstructed gradient method when it is selected.
void setupMeshInformation()
Compute the cell volumes on the mesh.
const Moose::Functor< Real > & _rho
Functor describing the density of the fluid.
std::vector< libMesh::LinearImplicitSystem * > _momentum_implicit_systems
Pointers to the momentum equation implicit system(s) from libmesh.
virtual void execute() override
unsigned int pressureVariableNumber() const
Variable number of the pressure variable reconstructed by this object.
void initCouplingField()
Initialize the coupling fields (HbyA and Ainv)
void preparePressureRelaxation()
Before pressure relaxation, form the conservative reconstructed candidate from the corrected face flu...
const std::vector< NumericVector< Number > * > & basePressureGradientComponents() const
Get the base-pressure gradient component vectors used to seed reconstructed updates.
FaceCenteredMapFunctor< RealVectorValue, std::unordered_map< dof_id_type, RealVectorValue > > _Ainv
A map functor from faces to $(1/A)_f$.
bool usingReconstructedPressureGradientMethod() const
Whether the registered pressure gradient field is produced by the reconstructed method.
virtual void finalize() override
const LinearFVGradientReader * _base_pressure_gradient_field
Base pressure gradient field used to seed reconstructed gradient updates.
void prepareMomentumPredictor()
Snapshot the fields read by the next momentum predictor.
const unsigned int _dim
The dimension of the mesh, e.g. 3 for hexes and tets, 2 for quads and tris.
const std::vector< std::unique_ptr< NumericVector< Number > > > & AinvComponents() const
Get the momentum-layout 1/A component vectors.
FaceCenteredMapFunctor< Real, std::unordered_map< dof_id_type, Real > > & _face_mass_flux
A map functor from faces to mass fluxes which are used in the advection terms.
const LinearFVGradientReader & pressureGradientField() const
Get the registered pressure gradient field used by compatible momentum pressure kernels.
static InputParameters validParams()
FaceCenteredMapFunctor< Real, std::unordered_map< dof_id_type, Real > > _HbyA_flux
A map functor from faces to $HbyA_{ij} = (A_{offdiag}*\mathrm{(predicted~velocity)} - \mathrm{Source}...
unsigned int dimension() const
Number of spatial dimensions of the coupled momentum/pressure systems.
const MooseEnum _pressure_projection_method
Enumerator for the method used for pressure projection.
std::vector< unsigned int > _global_momentum_system_numbers
Global numbers of the momentum system(s)
std::string stringify(const T &t)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...