23 #include "libmesh/mesh_base.h" 24 #include "libmesh/elem_range.h" 25 #include "libmesh/petsc_matrix.h" 37 params.addClassDescription(
"Computes H/A and 1/A together with face mass fluxes for segregated " 38 "momentum-pressure equations using linear systems.");
40 params.addRequiredParam<VariableName>(
NS::pressure,
"The pressure variable.");
41 params.addRequiredParam<VariableName>(
"u",
"The x-component of velocity");
42 params.addParam<VariableName>(
"v",
"The y-component of velocity");
43 params.addParam<VariableName>(
"w",
"The z-component of velocity");
44 params.addRequiredParam<std::string>(
"p_diffusion_kernel",
45 "The diffusion kernel acting on the pressure.");
46 params.addParam<std::vector<std::vector<std::string>>>(
47 "body_force_kernel_names",
49 "The body force kernel names." 50 "this double vector would have size index_x_dim: 'f1x f2x; f1y f2y; f1z f2z'");
52 params.addRequiredParam<MooseFunctorName>(
NS::density,
"Density functor");
62 params.addParam<
MooseEnum>(
"pressure_projection_method",
63 MooseEnum(
"standard consistent",
"standard"),
64 "The method to use in the pressure projection for Ainv - " 65 "standard (SIMPLE) or consistent (SIMPLEC)");
74 _dim(blocksMaxDimension()),
78 _HbyA_flux(_moose_mesh, blockIDs(),
"HbyA_flux"),
79 _Ainv(_moose_mesh, blockIDs(),
"Ainv"),
82 "face_flux", _moose_mesh, blockIDs(),
"face_values")),
83 _body_force_kernel_names(
84 getParam<
std::vector<
std::vector<
std::string>>>(
"body_force_kernel_names")),
86 _pressure_projection_method(getParam<
MooseEnum>(
"pressure_projection_method"))
92 std::vector<std::string> vel_names = {
"u",
"v",
"w"};
99 paramError(vel_names[i],
"the velocity must be a MOOSELinearVariableFVReal.");
110 if (!dynamic_cast<SIMPLE *>(
getMooseApp().getExecutioner()) &&
111 !dynamic_cast<PIMPLE *>(
getMooseApp().getExecutioner()))
113 " should only be used with a linear segregated thermal-hydraulics solver!");
118 const std::vector<LinearSystem *> & momentum_systems,
120 const std::vector<unsigned int> & momentum_system_numbers)
151 std::vector<LinearFVFluxKernel *> flux_kernel;
154 .template condition<AttribThread>(
_tid)
155 .
template condition<AttribSysNum>(
_p->
sys().
number())
156 .
template condition<AttribSystem>(
"LinearFVFluxKernel")
157 .template condition<AttribName>(getParam<std::string>(
"p_diffusion_kernel"))
158 .queryInto(flux_kernel);
159 if (flux_kernel.size() != 1)
161 "p_diffusion_kernel",
162 "The kernel with the given name could not be found or multiple instances were identified.");
166 "The provided diffusion kernel should of type LinearFVAnisotropicDiffusion!");
177 "The dimension of the body force vector does not match the problem dimension.");
184 std::vector<LinearFVElementalKernel *> temp_storage;
187 .template condition<AttribThread>(
_tid)
188 .
template condition<AttribSysNum>(
_vel[dim_i]->sys().number())
189 .
template condition<AttribSystem>(
"LinearFVElementalKernel")
190 .template condition<AttribName>(force_name)
191 .queryInto(temp_storage);
192 if (temp_storage.size() != 1)
194 "The kernel with the given name: " + force_name +
195 " could not be found or multiple instances were identified.");
210 if (
hasBlocks(elem_info->subdomain_id()))
213 _cell_volumes->set(elem_dof, elem_info->volume() * elem_info->coordFactor());
220 if (
hasBlocks(fi->elemPtr()->subdomain_id()) ||
221 (fi->neighborPtr() &&
hasBlocks(fi->neighborPtr()->subdomain_id())))
231 for (
const auto & pair :
_Ainv)
232 _Ainv[pair.first] = 0;
249 if (
_vel[0]->isInternalFace(*fi))
251 const auto & elem_info = *fi->elemInfo();
252 const auto & neighbor_info = *fi->neighborInfo();
259 density_times_velocity(dim_i),
260 _vel[dim_i]->getElemValue(elem_info, time_arg) * elem_rho,
261 _vel[dim_i]->getElemValue(neighbor_info, time_arg) * neighbor_rho,
268 const bool elem_is_fluid =
hasBlocks(fi->elemPtr()->subdomain_id());
269 const Elem *
const boundary_elem = elem_is_fluid ? fi->elemPtr() : fi->neighborPtr();
272 const Real boundary_normal_multiplier = elem_is_fluid ? 1.0 : -1.0;
276 const Real face_rho =
_rho(boundary_face, time_arg);
278 density_times_velocity(dim_i) = boundary_normal_multiplier * face_rho *
310 bool libmesh_dbg_var(subtract_mesh_velocity))
const 312 mooseAssert(!subtract_mesh_velocity,
"RhieChowMassFlux does not support moving meshes yet!");
315 mooseError(
"Interpolation methods other than Rhie-Chow are not supported!");
317 mooseError(
"Older interpolation times are not supported!");
343 Real p_grad_flux = 0.0;
346 const auto & elem_info = *fi->
elemInfo();
354 const auto p_elem_value = p_reader(elem_dof);
355 const auto p_neighbor_value = p_reader(neighbor_dof);
359 const auto neighbor_matrix_contribution =
361 const auto elem_rhs_contribution =
365 p_grad_flux = (p_neighbor_value * neighbor_matrix_contribution +
366 p_elem_value * elem_matrix_contribution) -
367 elem_rhs_contribution;
371 mooseAssert(fi->
boundaryIDs().size() == 1,
"We should only have one boundary on every face.");
373 bc_pointer->setupFaceData(
379 const auto matrix_contribution =
381 const auto rhs_contribution =
385 p_grad_flux = (p_elem_value * matrix_contribution - rhs_contribution);
401 auto working_vector =
_Ainv_raw[system_i]->clone();
402 working_vector->pointwise_mult(*working_vector, *pressure_gradient[system_i]);
403 working_vector->add(*
_HbyA_raw[system_i]);
404 working_vector->scale(-1.0);
436 std::vector<PetscVectorReader> hbya_reader;
438 hbya_reader.emplace_back(*raw_hbya[dim_i]);
440 std::vector<PetscVectorReader> ainv_reader;
442 ainv_reader.emplace_back(*raw_Ainv[dim_i]);
454 if (
_vel[0]->isInternalFace(*fi))
457 const auto & elem_info = *fi->
elemInfo();
473 hbya_reader[dim_i](elem_dof),
474 hbya_reader[dim_i](neighbor_dof),
479 elem_rho * ainv_reader[dim_i](elem_dof),
480 neighbor_rho * ainv_reader[dim_i](neighbor_dof),
490 const Real boundary_normal_multiplier = elem_is_fluid ? 1.0 : -1.0;
497 if (
_vel[0]->isDirichletBoundaryFace(*fi))
512 force_kernel->setCurrentElemInfo(&elem_info);
513 face_hbya(dim_i) -= force_kernel->computeRightHandSideContribution() *
514 ainv_reader[dim_i](elem_dof) /
517 face_hbya(dim_i) *= boundary_normal_multiplier;
527 face_hbya(dim_i) = boundary_normal_multiplier * hbya_reader[dim_i](elem_dof);
533 Ainv(dim_i) = elem_rho * ainv_reader[dim_i](elem_dof);
545 _console <<
"************************************" << std::endl;
546 _console <<
"Computing HbyA" << std::endl;
547 _console <<
"************************************" << std::endl;
550 "The momentum system shall be linked before calling this function!");
565 "The matrices used in the segregated INSFVRhieChow objects need to be convertable " 570 _console <<
"Matrix in rc object" << std::endl;
582 _console <<
"Velocity solution in H(u)" << std::endl;
600 mooseAssert(working_vector_petsc,
601 "The vectors used in the RhieChowMassFlux objects need to be convertable " 606 HbyA.
add(-1.0, *working_vector_petsc);
620 HbyA.
add(-1.0, *working_vector_petsc);
624 _console <<
"total RHS" << std::endl;
626 _console <<
"pressure RHS" << std::endl;
627 pressure_gradient[system_i]->print();
628 _console <<
" H(u)-rhs-relaxation_source" << std::endl;
633 *working_vector_petsc = 1.0;
641 _console <<
" (H(u)-rhs)/A" << std::endl;
653 _console <<
"Performing SIMPLEC projection." << std::endl;
662 const auto local_size = mmat->
local_m();
664 for (
const auto row_i :
make_range(local_size))
667 const auto global_index = mmat->
row_start() + row_i;
668 std::vector<numeric_index_type> indices;
669 std::vector<Real> values;
670 mmat->
get_row(global_index, indices, values);
673 const Real row_sum = std::accumulate(values.cbegin(), values.cend(), 0.0);
676 sum_vector.add(global_index, row_sum);
682 auto row_sum = current_local_solution.
zero_clone();
683 get_row_sum(*row_sum);
686 auto Ainv_full = current_local_solution.
zero_clone();
687 *working_vector_petsc = 1.0;
689 const auto Ainv_full_old = Ainv_full->clone();
692 Ainv_full->add(-1.0, Ainv);
693 working_vector_petsc->
pointwise_mult(*Ainv_full, *pressure_gradient[system_i]);
695 HbyA.
add(-1.0, *working_vector_petsc);
698 Ainv = *Ainv_full_old;
709 _console <<
"************************************" << std::endl;
710 _console <<
"DONE Computing HbyA " << std::endl;
711 _console <<
"************************************" << std::endl;
715 std::vector<std::unique_ptr<NumericVector<Number>>> &
718 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
const std::vector< std::unique_ptr< NumericVector< Number > > > & gradientContainer() 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
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)
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
FEProblemBase & _fe_problem
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()
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)
LinearFVAnisotropicDiffusion * _p_diffusion_kernel
Pointer to the pressure diffusion term in the pressure Poisson equation.
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)
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.