24 #include "libmesh/mesh_base.h" 25 #include "libmesh/elem_range.h" 26 #include "libmesh/petsc_matrix.h" 38 params.addClassDescription(
"Computes H/A and 1/A together with face mass fluxes for segregated " 39 "momentum-pressure equations using linear systems.");
41 params.addRequiredParam<VariableName>(
NS::pressure,
"The pressure variable.");
42 params.addRequiredParam<VariableName>(
"u",
"The x-component of velocity");
43 params.addParam<VariableName>(
"v",
"The y-component of velocity");
44 params.addParam<VariableName>(
"w",
"The z-component of velocity");
45 params.addRequiredParam<std::string>(
47 "The LinearFVPressureCorrectionDiffusion kernel acting on the pressure.");
48 params.addParam<std::vector<std::vector<std::string>>>(
49 "body_force_kernel_names",
51 "The body force kernel names." 52 "this double vector would have size index_x_dim: 'f1x f2x; f1y f2y; f1z f2z'");
54 params.addRequiredParam<MooseFunctorName>(
NS::density,
"Density functor");
64 params.addParam<
MooseEnum>(
"pressure_projection_method",
65 MooseEnum(
"standard consistent",
"standard"),
66 "The method to use in the pressure projection for Ainv - " 67 "standard (SIMPLE) or consistent (SIMPLEC)");
69 "pressure_diffusion_interpolation",
71 "The face interpolation method for Ainv in the pressure correction diffusion term.");
80 _dim(blocksMaxDimension()),
84 _HbyA_flux(_moose_mesh, blockIDs(),
"HbyA_flux"),
85 _Ainv(_moose_mesh, blockIDs(),
"Ainv"),
88 "face_flux", _moose_mesh, blockIDs(),
"face_values")),
89 _body_force_kernel_names(
90 getParam<
std::vector<
std::vector<
std::string>>>(
"body_force_kernel_names")),
92 _pressure_projection_method(getParam<
MooseEnum>(
"pressure_projection_method")),
93 _pressure_diffusion_interp_method(getParam<
MooseEnum>(
"pressure_diffusion_interpolation") ==
102 std::vector<std::string> vel_names = {
"u",
"v",
"w"};
109 paramError(vel_names[i],
"the velocity must be a MOOSELinearVariableFVReal.");
120 if (!dynamic_cast<SIMPLE *>(
getMooseApp().getExecutioner()) &&
121 !dynamic_cast<PIMPLE *>(
getMooseApp().getExecutioner()))
123 " should only be used with a linear segregated thermal-hydraulics solver!");
128 const std::vector<LinearSystem *> & momentum_systems,
130 const std::vector<unsigned int> & momentum_system_numbers)
161 std::vector<LinearFVFluxKernel *> flux_kernel;
164 .template condition<AttribThread>(
_tid)
165 .
template condition<AttribSysNum>(
_p->
sys().
number())
166 .
template condition<AttribSystem>(
"LinearFVFluxKernel")
167 .template condition<AttribName>(getParam<std::string>(
"p_diffusion_kernel"))
168 .queryInto(flux_kernel);
169 if (flux_kernel.size() != 1)
171 "p_diffusion_kernel",
172 "The kernel with the given name could not be found or multiple instances were identified.");
176 "The provided diffusion kernel should be of type " 177 "LinearFVPressureCorrectionDiffusion.");
188 "The dimension of the body force vector does not match the problem dimension.");
195 std::vector<LinearFVElementalKernel *> temp_storage;
198 .template condition<AttribThread>(
_tid)
199 .
template condition<AttribSysNum>(
_vel[dim_i]->sys().number())
200 .
template condition<AttribSystem>(
"LinearFVElementalKernel")
201 .template condition<AttribName>(force_name)
202 .queryInto(temp_storage);
203 if (temp_storage.size() != 1)
205 "The kernel with the given name: " + force_name +
206 " could not be found or multiple instances were identified.");
221 if (
hasBlocks(elem_info->subdomain_id()))
224 _cell_volumes->set(elem_dof, elem_info->volume() * elem_info->coordFactor());
231 if (
hasBlocks(fi->elemPtr()->subdomain_id()) ||
232 (fi->neighborPtr() &&
hasBlocks(fi->neighborPtr()->subdomain_id())))
242 for (
const auto & pair :
_Ainv)
243 _Ainv[pair.first] = 0;
260 if (
_vel[0]->isInternalFace(*fi))
262 const auto & elem_info = *fi->elemInfo();
263 const auto & neighbor_info = *fi->neighborInfo();
270 density_times_velocity(dim_i),
271 _vel[dim_i]->getElemValue(elem_info, time_arg) * elem_rho,
272 _vel[dim_i]->getElemValue(neighbor_info, time_arg) * neighbor_rho,
279 const bool elem_is_fluid =
hasBlocks(fi->elemPtr()->subdomain_id());
280 const Elem *
const boundary_elem = elem_is_fluid ? fi->elemPtr() : fi->neighborPtr();
283 const Real boundary_normal_multiplier = elem_is_fluid ? 1.0 : -1.0;
287 const Real face_rho =
_rho(boundary_face, time_arg);
289 density_times_velocity(dim_i) = boundary_normal_multiplier * face_rho *
321 bool libmesh_dbg_var(subtract_mesh_velocity))
const 323 mooseAssert(!subtract_mesh_velocity,
"RhieChowMassFlux does not support moving meshes yet!");
326 mooseError(
"Interpolation methods other than Rhie-Chow are not supported!");
328 mooseError(
"Older interpolation times are not supported!");
354 Real p_grad_flux = 0.0;
357 const auto & elem_info = *fi->
elemInfo();
365 const auto p_elem_value = p_reader(elem_dof);
366 const auto p_neighbor_value = p_reader(neighbor_dof);
370 const auto neighbor_matrix_contribution =
372 const auto elem_rhs_contribution =
376 p_grad_flux = (p_neighbor_value * neighbor_matrix_contribution +
377 p_elem_value * elem_matrix_contribution) -
378 elem_rhs_contribution;
382 mooseAssert(fi->
boundaryIDs().size() == 1,
"We should only have one boundary on every face.");
384 bc_pointer->setupFaceData(
390 const auto matrix_contribution =
392 const auto rhs_contribution =
396 p_grad_flux = (p_elem_value * matrix_contribution - rhs_contribution);
412 auto working_vector =
_Ainv_raw[system_i]->clone();
413 working_vector->pointwise_mult(*working_vector, *pressure_gradient[system_i]);
414 working_vector->add(*
_HbyA_raw[system_i]);
415 working_vector->scale(-1.0);
447 std::vector<PetscVectorReader> hbya_reader;
449 hbya_reader.emplace_back(*raw_hbya[dim_i]);
451 std::vector<PetscVectorReader> ainv_reader;
453 ainv_reader.emplace_back(*raw_Ainv[dim_i]);
465 if (
_vel[0]->isInternalFace(*fi))
468 const auto & elem_info = *fi->
elemInfo();
484 hbya_reader[dim_i](elem_dof),
485 hbya_reader[dim_i](neighbor_dof),
490 elem_rho * ainv_reader[dim_i](elem_dof),
491 neighbor_rho * ainv_reader[dim_i](neighbor_dof),
501 const Real boundary_normal_multiplier = elem_is_fluid ? 1.0 : -1.0;
508 if (
_vel[0]->isDirichletBoundaryFace(*fi))
523 force_kernel->setCurrentElemInfo(&elem_info);
525 force_kernel->computeRightHandSideContribution() * ainv_reader[dim_i](elem_dof) /
528 face_hbya(dim_i) *= boundary_normal_multiplier;
538 face_hbya(dim_i) = boundary_normal_multiplier * hbya_reader[dim_i](elem_dof);
544 Ainv(dim_i) = elem_rho * ainv_reader[dim_i](elem_dof);
556 _console <<
"************************************" << std::endl;
557 _console <<
"Computing HbyA" << std::endl;
558 _console <<
"************************************" << std::endl;
561 "The momentum system shall be linked before calling this function!");
577 "The matrices used in the segregated INSFVRhieChow objects need to be convertable " 582 _console <<
"Matrix in rc object" << std::endl;
594 _console <<
"Velocity solution in H(u)" << std::endl;
612 mooseAssert(working_vector_petsc,
613 "The vectors used in the RhieChowMassFlux objects need to be convertable " 618 HbyA.
add(-1.0, *working_vector_petsc);
632 HbyA.
add(-1.0, *working_vector_petsc);
636 _console <<
"total RHS" << std::endl;
638 _console <<
"pressure RHS" << std::endl;
639 pressure_gradient[system_i]->print();
640 _console <<
" H(u)-rhs-relaxation_source" << std::endl;
645 *working_vector_petsc = 1.0;
653 _console <<
" (H(u)-rhs)/A" << std::endl;
665 _console <<
"Performing SIMPLEC projection." << std::endl;
674 const auto local_size = mmat->
local_m();
676 for (
const auto row_i :
make_range(local_size))
679 const auto global_index = mmat->
row_start() + row_i;
680 std::vector<numeric_index_type> indices;
681 std::vector<Real> values;
682 mmat->
get_row(global_index, indices, values);
685 const Real row_sum = std::accumulate(values.cbegin(), values.cend(), 0.0);
688 sum_vector.add(global_index, row_sum);
694 auto row_sum = current_local_solution.
zero_clone();
695 get_row_sum(*row_sum);
698 auto Ainv_full = current_local_solution.
zero_clone();
699 *working_vector_petsc = 1.0;
701 const auto Ainv_full_old = Ainv_full->clone();
704 Ainv_full->add(-1.0, Ainv);
705 working_vector_petsc->
pointwise_mult(*Ainv_full, *pressure_gradient[system_i]);
707 HbyA.
add(-1.0, *working_vector_petsc);
710 Ainv = *Ainv_full_old;
727 _console <<
"************************************" << std::endl;
728 _console <<
"DONE Computing HbyA " << std::endl;
729 _console <<
"************************************" << std::endl;
733 std::vector<std::unique_ptr<NumericVector<Number>>> &
736 if (updated_pressure)
std::vector< LinearSystem * > _momentum_systems
Pointers to the linear system(s) in moose corresponding to the momentum equation(s) ...
const MooseEnum _pressure_projection_method
Enumerator for the method used for pressure projection.
virtual void initialize() override
void setupMeshInformation()
Compute the cell volumes on the mesh.
User object responsible for determining the face fluxes using the Rhie-Chow interpolation in a segreg...
A functor whose evaluation relies on querying a map where the keys are face info ids and the values c...
const std::set< BoundaryID > & boundaryIDs() const
virtual numeric_index_type local_m() const final
void paramError(const std::string ¶m, Args... args) const
T & getMesh(MooseMesh &mesh)
function to cast mesh
void checkBlocks(const VarType &var) const
Check the block consistency between the passed in var and us.
const std::vector< const ElemInfo *> & elemInfoVector() const
std::vector< libMesh::LinearImplicitSystem * > _momentum_implicit_systems
Pointers to the momentum equation implicit system(s) from libmesh.
unsigned int number() const
Real getMassFlux(const FaceInfo &fi) const
Get the face velocity times density (used in advection terms)
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
virtual Real computeElemMatrixContribution() override
static const std::string component
const Elem & elem() const
virtual std::unique_ptr< NumericVector< T > > zero_clone() const=0
const ElemInfo * neighborInfo() const
const ExecFlagType EXEC_NONE
const Elem * elem() const
registerMooseObject("NavierStokesApp", RhieChowMassFlux)
void computeFaceMassFlux()
Update the values of the face velocities in the containers.
void addFunctor(const std::string &name, const Moose::FunctorBase< T > &functor, const THREAD_ID tid)
static const std::string density
virtual void setupFaceData(const FaceInfo *face_info)
NumericVector< Number > * rhs
void addAvailableFlags(const ExecFlagType &flag, Args... flags)
const ElemInfo * elemInfo() const
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...
const LinearSystem * _pressure_system
Pointer to the pressure system.
LinearFVBoundaryCondition * getBoundaryCondition(const BoundaryID bd_id) const
FaceCenteredMapFunctor< RealVectorValue, std::unordered_map< dof_id_type, RealVectorValue > > _Ainv
A map functor from faces to $(1/A)_f$.
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
std::vector< unsigned int > _momentum_system_numbers
Numbers of the momentum system(s)
virtual void initialSetup() override
virtual void meshChanged() override
virtual void pointwise_divide(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
virtual Real computeBoundaryMatrixContribution(const LinearFVBoundaryCondition &bc) override
MooseApp & getMooseApp() const
std::vector< unsigned int > _global_momentum_system_numbers
Global numbers of the momentum system(s)
static InputParameters validParams()
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
FEProblemBase & _fe_problem
bool isInternalFace(const FaceInfo &) const
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...
const std::vector< const FaceInfo *> & faceInfo() const
ValueType evaluate(const FaceInfo *const fi) const
Evaluate the face functor using a FaceInfo argument.
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
const std::string & name() const
std::vector< std::vector< std::string > > _body_force_kernel_names
Vector of body force term names.
FaceCenteredMapFunctor< Real, std::unordered_map< dof_id_type, Real > > _HbyA_flux
A map functor from faces to $HbyA_{ij} = (A_{offdiag}*{(predicted~velocity)} - {Source})_{ij}/A_{ij}$...
const Elem * neighborPtr() const
virtual const NumericVector< Number > *const & currentSolution() const override final
std::vector< std::vector< LinearFVElementalKernel * > > _body_force_kernels
Pointer to the body force terms.
TheWarehouse & theWarehouse() const
std::vector< const MooseLinearVariableFVReal * > _vel
The thread 0 copy of the x-velocity variable.
const MooseLinearVariableFVReal *const _p
The thread 0 copy of the pressure variable.
unsigned int _global_pressure_system_number
Global number of the pressure system.
RhieChowMassFlux(const InputParameters ¶ms)
void linkMomentumPressureSystems(const std::vector< LinearSystem *> &momentum_systems, const LinearSystem &pressure_system, const std::vector< unsigned int > &momentum_system_numbers)
Update the momentum system-related information.
const Moose::Functor< Real > & _rho
Functor describing the density of the fluid.
static InputParameters validParams()
virtual Real computeElemRightHandSideContribution() override
std::unique_ptr< NumericVector< Number > > solution
void computeCellVelocity()
Update the cell values of the velocity variables.
virtual Real computeNeighborMatrixContribution() override
Real getVolumetricFaceFlux(const FaceInfo &fi) const
Get the volumetric face flux (used in advection terms)
const Moose::FV::InterpMethod _pressure_diffusion_interp_method
Interpolation method used for the pressure diffusion coefficient on faces.
void setCurrentFaceArea(const Real area)
virtual void print(std::ostream &os=libMesh::out) const
virtual Real computeBoundaryRHSContribution(const LinearFVBoundaryCondition &bc) override
const Point & normal() const
unsigned int number() const
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const=0
virtual void get_row(numeric_index_type i, std::vector< numeric_index_type > &indices, std::vector< T > &values) const override
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 void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2)=0
const Elem * elemPtr() const
const std::vector< std::vector< dof_id_type > > & dofIndices() const
virtual void get_diagonal(NumericVector< T > &dest) const override
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.
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
LinearFVPressureCorrectionDiffusion * _p_diffusion_kernel
Pointer to the pressure diffusion term in the pressure Poisson equation.
SparseMatrix< Number > * matrix
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
static const std::string pressure
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
void mooseError(Args &&... args) const
virtual numeric_index_type row_start() const override
std::unique_ptr< NumericVector< Number > > current_local_solution
static InputParameters validParams()
Pressure correction diffusion kernel for the linear finite volume SIMPLE algorithm.
const ConsoleStream _console
std::vector< const FaceInfo * > _flow_face_info
The subset of the FaceInfo objects that actually cover the subdomains which the flow field is defined...
bool hasBlocks(const SubdomainName &name) const
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 add(const numeric_index_type i, const T value)=0
void interpolate(InterpMethod m, T &result, const T2 &value1, const T3 &value2, const FaceInfo &fi, const bool one_is_elem)
auto index_range(const T &sizable)
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
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...
virtual void pointwise_divide(const NumericVector< T > &vec1, const NumericVector< T > &vec2)=0
void initCouplingField()
Initialize the coupling fields (HbyA and Ainv)
const std::vector< std::unique_ptr< libMesh::NumericVector< libMesh::Number > > > & linearFVGradientContainer() const
virtual System & system() override
void initFaceMassFlux()
Initialize the container for face velocities.
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
std::unique_ptr< NumericVector< Number > > _cell_volumes
We will hold a vector of cell volumes to make sure we can do volume corrections rapidly.
const unsigned int _dim
The dimension of the mesh, e.g. 3 for hexes and tets, 2 for quads and tris.