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#include <unordered_set>
19
20#include "libmesh/petsc_vector.h"
21
22class 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
53 const FaceInfo & fi,
54 const Moose::StateArg & time,
55 const THREAD_ID tid,
56 bool subtract_mesh_velocity) const override;
57
59 void initFaceMassFlux();
61 void initCouplingField();
66
67 virtual void meshChanged() override;
68 virtual void initialize() override;
69 virtual void execute() override {}
70 virtual void finalize() override {}
71 virtual void initialSetup() override;
72
80 void linkMomentumPressureSystems(const std::vector<LinearSystem *> & momentum_systems,
81 LinearSystem & pressure_system,
82 const std::vector<unsigned int> & momentum_system_numbers);
83
88 void computeHbyA(const bool with_updated_pressure, const bool verbose);
89
90protected:
92 std::vector<std::unique_ptr<NumericVector<Number>>> &
93 selectPressureGradient(const bool updated_pressure);
94
96 const std::vector<std::unique_ptr<NumericVector<Number>>> & pressureGradientComponents() const;
97
100
102 void
103 populateCouplingFunctors(const std::vector<std::unique_ptr<NumericVector<Number>>> & raw_hbya,
104 const std::vector<std::unique_ptr<NumericVector<Number>>> & raw_Ainv);
105
109 template <typename VarType>
110 void checkBlocks(const VarType & var) const;
111
112 virtual bool supportMeshVelocity() const override { return false; }
113
116
119
121 const unsigned int _dim;
122
125
127 std::vector<const MooseLinearVariableFVReal *> _vel;
128
131
139
144 std::vector<std::unique_ptr<NumericVector<Number>>> _HbyA_raw;
145
151
156 std::vector<std::unique_ptr<NumericVector<Number>>> _Ainv_raw;
157
158 std::unique_ptr<NumericVector<Number>> _A_avg;
159
164
169 std::vector<std::unique_ptr<NumericVector<Number>>> _grad_p_current;
170
175
177 std::vector<LinearSystem *> _momentum_systems;
178
180 std::vector<unsigned int> _momentum_system_numbers;
181
183 std::vector<unsigned int> _global_momentum_system_numbers;
184
186 std::vector<libMesh::LinearImplicitSystem *> _momentum_implicit_systems;
187
190
193
196
198 std::unique_ptr<NumericVector<Number>> _cell_volumes;
199
202
205
206private:
209 std::vector<const FaceInfo *> _flow_face_info;
210};
211
212template <typename VarType>
213void
214RhieChowMassFlux::checkBlocks(const VarType & var) const
215{
216 const auto & var_blocks = var.blockIDs();
217 const auto & uo_blocks = blockIDs();
218
219 // Error if this UO has any blocks that the variable does not
220 std::set<SubdomainID> uo_blocks_minus_var_blocks;
221 std::set_difference(uo_blocks.begin(),
222 uo_blocks.end(),
223 var_blocks.begin(),
224 var_blocks.end(),
225 std::inserter(uo_blocks_minus_var_blocks, uo_blocks_minus_var_blocks.end()));
226 if (uo_blocks_minus_var_blocks.size() > 0)
227 mooseError("Block restriction of interpolator user object '",
228 this->name(),
229 "' (",
231 ") includes blocks not in the block restriction of variable '",
232 var.name(),
233 "' (",
234 Moose::stringify(var.blocks()),
235 ")");
236
237 // Get the blocks in the variable but not this UO
238 std::set<SubdomainID> var_blocks_minus_uo_blocks;
239 std::set_difference(var_blocks.begin(),
240 var_blocks.end(),
241 uo_blocks.begin(),
242 uo_blocks.end(),
243 std::inserter(var_blocks_minus_uo_blocks, var_blocks_minus_uo_blocks.end()));
244
245 // For each block in the variable but not this UO, error if there is connection
246 // to any blocks on the UO.
247 for (auto & block_id : var_blocks_minus_uo_blocks)
248 {
249 const auto connected_blocks = _moose_mesh.getBlockConnectedBlocks(block_id);
250 std::set<SubdomainID> connected_blocks_on_uo;
251 std::set_intersection(connected_blocks.begin(),
252 connected_blocks.end(),
253 uo_blocks.begin(),
254 uo_blocks.end(),
255 std::inserter(connected_blocks_on_uo, connected_blocks_on_uo.end()));
256 if (connected_blocks_on_uo.size() > 0)
257 mooseError("Block restriction of interpolator user object '",
258 this->name(),
259 "' (",
260 Moose::stringify(uo_blocks),
261 ") doesn't match the block restriction of variable '",
262 var.name(),
263 "' (",
264 Moose::stringify(var_blocks),
265 ")");
266 }
267}
unsigned int THREAD_ID
virtual const std::set< SubdomainID > & blockIDs() const
const std::vector< SubdomainName > & blocks() const
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.
const Moose::FV::InterpMethod _pressure_diffusion_interp_method
Interpolation method used for the pressure diffusion coefficient on faces.
std::vector< std::unique_ptr< NumericVector< Number > > > _grad_p_current
for a PISO iteration we need to hold on to the original pressure gradient field.
std::vector< std::unique_ptr< NumericVector< Number > > > & selectPressureGradient(const bool updated_pressure)
Select the right pressure gradient field and return a reference to the container.
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.
std::vector< const MooseLinearVariableFVReal * > _vel
The thread 0 copy of the x-velocity variable.
const std::vector< std::unique_ptr< NumericVector< Number > > > & pressureGradientComponents() const
Get the registered pressure gradient component vectors.
void initFaceMassFlux()
Initialize the container for face velocities.
LinearFVPressureCorrectionDiffusion * _p_diffusion_kernel
Pointer to the pressure diffusion term in the pressure Poisson equation.
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
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
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.
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)
LinearSystem * _pressure_system
Pointer to the pressure system.
void computeHbyA(const bool with_updated_pressure, const bool verbose)
Computes the inverse of the diagonal (1/A) of the system matrix plus the H/A components for the press...
void computeCellVelocity()
Update the cell values of the velocity variables.
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...
std::vector< const FaceInfo * > _flow_face_info
The subset of the FaceInfo objects that actually cover the subdomains which the flow field is defined...
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.
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
void initCouplingField()
Initialize the coupling fields (HbyA and Ainv)
FaceCenteredMapFunctor< RealVectorValue, std::unordered_map< dof_id_type, RealVectorValue > > _Ainv
A map functor from faces to $(1/A)_f$.
virtual void finalize() override
const unsigned int _dim
The dimension of the mesh, e.g. 3 for hexes and tets, 2 for quads and tris.
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}...
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...