15#include "libmesh/nonlinear_implicit_system.h"
24 params.
addParam<TagName>(
"pressure_gradient_tag",
25 "pressure_momentum_kernels",
26 "The name of the tags associated with the kernels in the momentum "
27 "equations which are not related to the pressure gradient.");
34 _pressure_sys_number(_problem.nlSysNum(getParam<SolverSystemName>(
"pressure_system"))),
35 _pressure_system(_problem.getNonlinearSystemBase(_pressure_sys_number)),
36 _has_turbulence_systems(!getParam<
std::vector<SolverSystemName>>(
"turbulence_systems").empty()),
37 _energy_sys_number(_has_energy_system
38 ? _problem.nlSysNum(getParam<SolverSystemName>(
"energy_system"))
40 _energy_system(_has_energy_system ? &_problem.getNonlinearSystemBase(_energy_sys_number)
42 _solid_energy_sys_number(
43 _has_solid_energy_system
44 ? _problem.nlSysNum(getParam<SolverSystemName>(
"solid_energy_system"))
46 _solid_energy_system(_has_solid_energy_system
47 ? &_problem.getNonlinearSystemBase(_solid_energy_sys_number)
49 _turbulence_system_names(getParam<
std::vector<SolverSystemName>>(
"turbulence_systems")),
50 _turbulence_equation_relaxation(getParam<
std::vector<
Real>>(
"turbulence_equation_relaxation")),
51 _turbulence_field_min_limit(getParam<
std::vector<
Real>>(
"turbulence_field_min_limit")),
52 _turbulence_l_abs_tol(getParam<
Real>(
"turbulence_l_abs_tol")),
53 _turbulence_absolute_tolerance(getParam<
std::vector<
Real>>(
"turbulence_absolute_tolerance")),
54 _pressure_tag_name(getParam<TagName>(
"pressure_gradient_tag")),
55 _pressure_tag_id(_problem.addVectorTag(_pressure_tag_name))
101 "The number of equation relaxation parameters does not match the number of "
102 "turbulence scalar equations!");
105 "The number of absolute tolerances does not match the number of "
106 "turbulence equations!");
112 "The number of lower bounds for turbulent quantities does not match the "
113 "number of turbulence equations!");
118 "solid_energy_system",
119 "We cannot solve a solid energy system without solving for the fluid energy as well!");
123 const auto & turbulence_petsc_options = getParam<MultiMooseEnum>(
"turbulence_petsc_options");
124 const auto & turbulence_petsc_pair_options = getParam<MooseEnumItem, std::string>(
125 "turbulence_petsc_options_iname",
"turbulence_petsc_options_value");
137 getParam<unsigned int>(
"turbulence_l_max_its");
141 {
"turbulence_petsc_options",
142 "turbulence_petsc_options_iname",
143 "turbulence_petsc_options_value",
145 "turbulence_l_abs_tol",
146 "turbulence_l_max_its",
147 "turbulence_equation_relaxation",
148 "turbulence_absolute_tolerance"},
158 &getUserObject<INSFVRhieChowInterpolatorSegregated>(
"rhie_chow_user_object"));
165std::vector<std::pair<unsigned int, Real>>
170 std::vector<std::pair<unsigned int, Real>> its_normalized_residuals;
174 auto zero_solution =
_momentum_systems[0]->system().current_local_solution->zero_clone();
185 libMesh::cast_ref<NonlinearImplicitSystem &>(
_momentum_systems[system_i]->system());
188 libMesh::cast_ref<PetscLinearSolver<Real> &>(*momentum_system.
get_linear_solver());
211 LibmeshPetscCall(KSPSetNormType(momentum_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
218 auto its_resid_pair = momentum_solver.
solve(mmat, mmat, solution, rhs);
222 its_normalized_residuals.push_back(
227 _console <<
" matrix when we solve " << std::endl;
229 _console <<
" rhs when we solve " << std::endl;
231 _console <<
" velocity solution component " << system_i << std::endl;
233 _console <<
"Norm factor " << norm_factor << std::endl;
238 _momentum_systems[system_i]->copyPreviousSolutions(Moose::SolutionIterationType::Nonlinear);
241 return its_normalized_residuals;
244std::pair<unsigned int, Real>
261 libMesh::cast_ref<PetscLinearSolver<Real> &>(*pressure_system.
get_linear_solver());
266 auto zero_solution = current_local_solution.
zero_clone();
272 _console <<
"Pressure matrix" << std::endl;
280 LibmeshPetscCall(KSPSetNormType(pressure_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
289 auto its_res_pair = pressure_solver.
solve(mmat, mmat, solution, rhs);
294 _console <<
" rhs when we solve pressure " << std::endl;
296 _console <<
" Pressure " << std::endl;
298 _console <<
"Norm factor " << norm_factor << std::endl;
303 return std::make_pair(its_res_pair.first, pressure_solver.
get_initial_residual() / norm_factor);
306std::pair<unsigned int, Real>
309 const Real relaxation_factor,
311 const Real absolute_tol)
317 libMesh::cast_ref<NonlinearImplicitSystem &>(system.
system());
335 auto zero_solution = current_local_solution.
zero_clone();
345 _console << system.
name() <<
" system matrix" << std::endl;
347 _console << system.
name() <<
" RHS vector" << std::endl;
355 LibmeshPetscCall(KSPSetNormType(linear_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
362 auto its_res_pair = linear_solver.
solve(mmat, mmat, solution, rhs);
367 _console <<
" rhs when we solve " << system.
name() << std::endl;
371 _console <<
" Norm factor " << norm_factor << std::endl;
379std::pair<unsigned int, Real>
401 auto zero_solution = current_local_solution.
zero_clone();
407 _console <<
"Solid energy matrix" << std::endl;
415 LibmeshPetscCall(KSPSetNormType(se_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
421 auto its_res_pair = se_solver.
solve(mat, mat, solution, rhs);
426 _console <<
" Solid energy rhs " << std::endl;
428 _console <<
" Solid temperature " << std::endl;
430 _console <<
"Norm factor " << norm_factor << std::endl;
445 solver_params.
_type = Moose::SolveType::ST_LINEAR;
446 solver_params.
_line_search = Moose::LineSearchType::LS_NONE;
449 unsigned int iteration_counter = 0;
452 unsigned int no_systems =
456 std::vector<std::pair<unsigned int, Real>> ns_its_residuals(no_systems, std::make_pair(0, 1.0));
469 bool converged =
false;
475 size_t residual_index = 0;
507 for (
const auto system_i :
index_range(momentum_residual))
508 ns_its_residuals[system_i] = momentum_residual[system_i];
533 pressure_old_solution = pressure_current_solution;
543 residual_index = momentum_residual.size();
579 ns_its_residuals[residual_index] =
586 auto & current_solution =
598 old_solution = current_solution;
608 _console <<
"Iteration " << iteration_counter <<
" Initial residual norms:" << std::endl;
612 ? std::string(
" Component ") + std::to_string(system_i + 1) +
615 << COLOR_GREEN << ns_its_residuals[system_i].second << COLOR_DEFAULT << std::endl;
616 _console <<
" Pressure equation: " << COLOR_GREEN
617 << ns_its_residuals[momentum_residual.size()].second << COLOR_DEFAULT << std::endl;
618 residual_index = momentum_residual.size();
623 _console <<
" Energy equation: " << COLOR_GREEN << ns_its_residuals[residual_index].second
624 << COLOR_DEFAULT << std::endl;
628 _console <<
" Solid energy equation: " << COLOR_GREEN
629 << ns_its_residuals[residual_index].second << COLOR_DEFAULT << std::endl;
635 _console <<
"Turbulence Iteration " << std::endl;
640 << ns_its_residuals[residual_index].second << COLOR_DEFAULT << std::endl;
654 _console <<
" Passive Scalar Iteration " << iteration_counter << std::endl;
660 iteration_counter = 0;
661 std::vector<std::pair<unsigned int, Real>> passive_scalar_residuals(
664 bool passive_scalar_converged =
666 while (iteration_counter <
_num_iterations && !passive_scalar_converged)
676 passive_scalar_residuals[system_i] =
683 _console <<
"Iteration " << iteration_counter <<
" Initial residual norms:" << std::endl;
686 << passive_scalar_residuals[system_i].second << COLOR_DEFAULT << std::endl;
688 passive_scalar_converged =
728 mooseError(
"You have specified time kernels in your steady state simulation in system",
const ExecFlagType EXEC_NONLINEAR
const ConsoleStream _console
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
virtual unsigned int nlSysNum(const NonlinearSystemName &nl_sys_name) const override
void computeResidualAndJacobian(const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual, libMesh::SparseMatrix< libMesh::Number > &jacobian)
virtual MooseMesh & mesh() override
virtual void execute(const ExecFlagType &exec_type)
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
A user object which implements the Rhie Chow interpolation for segregated momentum-pressure systems.
void computeHbyA(bool verbose)
Computes the inverse of the digaonal (1/A) of the system matrix plus the H/A components for the press...
void computeFaceVelocity()
Update the values of the face velocities in the containers.
void initFaceVelocities()
Initialize the container for face velocities.
void linkMomentumSystem(std::vector< NonlinearSystemBase * > momentum_systems, const std::vector< unsigned int > &momentum_system_numbers, const TagID pressure_gradient_tag)
Update the momentum system-related information.
void computeCellVelocity()
Update the cell values of the velocity variables.
const std::string & name() const
void paramError(const std::string ¶m, Args... args) const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
virtual unsigned int dimension() const
virtual bool containsTimeKernel() override
virtual void residualSetup() override
virtual libMesh::System & system() override
Solve class serving as a base class for the two SIMPLE solvers that operate with different assembly a...
const Real _momentum_equation_relaxation
The user-defined relaxation parameter for the momentum equation.
const bool _has_energy_system
Boolean for easy check if a fluid energy system shall be solved or not.
dof_id_type _pressure_pin_dof
The dof ID where the pressure needs to be pinned.
const std::vector< SolverSystemName > & _passive_scalar_system_names
The names of the passive scalar systems.
std::vector< unsigned int > _passive_scalar_system_numbers
const Real _pressure_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in pressure.
const std::vector< Real > _passive_scalar_equation_relaxation
The user-defined relaxation parameter(s) for the passive scalar equation(s)
const Real _pressure_l_abs_tol
Absolute linear tolerance for the pressure equation.
const Real _passive_scalar_l_abs_tol
Absolute linear tolerance for the passive scalar equation(s).
const bool _has_solid_energy_system
Boolean for easy check if a solid energy system shall be solved or not.
Moose::PetscSupport::PetscOptions _passive_scalar_petsc_options
Options which hold the petsc settings for the passive scalar equation(s)
SIMPLESolverConfiguration _pressure_linear_control
Options for the linear solver of the pressure equation.
static InputParameters validParams()
SIMPLESolverConfiguration _solid_energy_linear_control
Options for the linear solver of the energy equation.
const bool _has_passive_scalar_systems
Boolean for easy check if a passive scalar systems shall be solved or not.
const Real _momentum_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in momentum.
const Real _pressure_variable_relaxation
The user-defined relaxation parameter for the pressure variable.
const Real _momentum_l_abs_tol
Absolute linear tolerance for the momentum equation(s).
Moose::PetscSupport::PetscOptions _momentum_petsc_options
Options which hold the petsc settings for the momentum equation.
SIMPLESolverConfiguration _energy_linear_control
Options for the linear solver of the energy equation.
const Real _energy_l_abs_tol
Absolute linear tolerance for the energy equations.
const Real _pressure_pin_value
The value we want to enforce for pressure.
Moose::PetscSupport::PetscOptions _pressure_petsc_options
Options which hold the petsc settings for the pressure equation.
const bool _continue_on_max_its
If solve should continue if maximum number of iterations is hit.
void checkDependentParameterError(const std::string &main_parameter, const std::vector< std::string > &dependent_parameters, const bool should_be_defined)
const Real _energy_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in energy.
const unsigned int _num_iterations
The maximum number of momentum-pressure iterations.
const std::vector< Real > _passive_scalar_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in passive scalars.
const std::vector< SolverSystemName > & _momentum_system_names
The names of the momentum systems.
const Real _energy_equation_relaxation
The user-defined relaxation parameter for the energy equation.
SIMPLESolverConfiguration _momentum_linear_control
Options for the linear solver of the momentum equation.
SIMPLESolverConfiguration _passive_scalar_linear_control
Options for the linear solver of the passive scalar equation(s)
const Real _solid_energy_l_abs_tol
Absolute linear tolerance for the energy equations.
const bool _pin_pressure
If the pressure needs to be pinned.
Moose::PetscSupport::PetscOptions _energy_petsc_options
Options which hold the petsc settings for the fluid energy equation.
const bool _print_fields
Debug parameter which allows printing the coupling and solution vectors/matrices.
const Real _solid_energy_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in solid energy.
const std::vector< Real > _turbulence_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in turbulence equations.
virtual void checkTimeKernels(NonlinearSystemBase &system)
Check if the system contains time kernels.
const bool _has_turbulence_systems
Boolean for easy check if turbulence systems shall be solved or not.
virtual std::vector< std::pair< unsigned int, Real > > solveMomentumPredictor() override
Solve a momentum predictor step with a fixed pressure field.
SIMPLESolverConfiguration _turbulence_linear_control
Options for the linear solver of the turbulence equation(s)
NonlinearSystemBase * _solid_energy_system
Pointer to the nonlinear system corresponding to the solid energy equation.
std::vector< unsigned int > _momentum_system_numbers
The number(s) of the system(s) corresponding to the momentum equation(s)
virtual std::pair< unsigned int, Real > solvePressureCorrector() override
Solve a pressure corrector step.
std::vector< Real > _turbulence_field_min_limit
The user-defined lower limit for turbulent quantities e.g. k, eps/omega, etc..
const TagID _pressure_tag_id
The ID of the tag which corresponds to the pressure gradient terms in the momentum equation.
virtual void linkRhieChowUserObject() override
Fetch the Rhie Chow user object that is reponsible for determining face velocities and mass flux.
virtual void checkIntegrity() override
Check if the user defined time kernels.
std::pair< unsigned int, Real > solveAdvectedSystem(const unsigned int system_num, NonlinearSystemBase &system, const Real relaxation_factor, libMesh::SolverConfiguration &solver_config, const Real abs_tol)
Solve an equation which contains an advection term that depends on the solution of the segregated Nav...
std::vector< unsigned int > _turbulence_system_numbers
const unsigned int _energy_sys_number
The number of the system corresponding to the energy equation.
const unsigned int _pressure_sys_number
The number of the system corresponding to the pressure equation.
std::vector< NonlinearSystemBase * > _momentum_systems
Pointer(s) to the system(s) corresponding to the momentum equation(s)
const std::vector< Real > _turbulence_equation_relaxation
The user-defined relaxation parameter(s) for the turbulence equation(s)
std::vector< NonlinearSystemBase * > _turbulence_systems
Pointer(s) to the system(s) corresponding to the turbulence equation(s)
Moose::PetscSupport::PetscOptions _turbulence_petsc_options
Options which hold the petsc settings for the turbulence equation(s)
std::pair< unsigned int, Real > solveSolidEnergySystem()
Solve the solid energy conservation equation.
INSFVRhieChowInterpolatorSegregated * _rc_uo
Pointer to the segregated RhieChow interpolation object.
SIMPLESolveNonlinearAssembly(Executioner &ex)
static InputParameters validParams()
const unsigned int _solid_energy_sys_number
The number of the system corresponding to the solid energy equation.
NonlinearSystemBase * _energy_system
Pointer to the nonlinear system corresponding to the fluid energy equation.
const std::vector< SolverSystemName > & _turbulence_system_names
The names of the turbulence scalar systems.
virtual bool solve() override
Performs the momentum pressure coupling.
const Real _turbulence_l_abs_tol
Absolute linear tolerance for the turbulence equation(s).
std::vector< NonlinearSystemBase * > _passive_scalar_systems
Pointer(s) to the system(s) corresponding to the passive scalar equation(s)
NonlinearSystemBase & _pressure_system
Reference to the nonlinear system corresponding to the pressure equation.
Moose::LineSearchType _line_search
void setSolution(const NumericVector< Number > &soln)
virtual const NumericVector< Number > * solutionPreviousNewton() const
virtual const std::string & name() const
NumericVector< Number > * rhs
virtual LinearSolver< Number > * get_linear_solver() const
SparseMatrix< Number > * matrix
void set_solver_configuration(SolverConfiguration &solver_configuration)
virtual void print(std::ostream &os=libMesh::out) const
virtual void scale(const T factor)=0
virtual std::unique_ptr< NumericVector< T > > zero_clone() const=0
Real get_initial_residual()
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &matrix_in, NumericVector< T > &solution_in, NumericVector< T > &rhs_in, const std::optional< double > tol=std::nullopt, const std::optional< unsigned int > m_its=std::nullopt) override
std::map< std::string, int > int_valued_data
std::map< std::string, Real > real_valued_data
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const=0
std::unique_ptr< NumericVector< Number > > current_local_solution
void prefix_with_name(bool value)
std::unique_ptr< NumericVector< Number > > solution
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
void addPetscPairsToPetscOptions(const std::vector< std::pair< MooseEnumItem, std::string > > &petsc_pair_options, const unsigned int mesh_dimension, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
std::string stringify(const T &t)
Real computeNormalizationFactor(const NumericVector< Number > &solution, const SparseMatrix< Number > &mat, const NumericVector< Number > &rhs)
Compute a normalization factor which is applied to the linear residual to determine convergence.
bool converged(const std::vector< std::pair< unsigned int, Real > > &residuals, const std::vector< Real > &abs_tolerances)
Based on the residuals, determine if the iterative process converged or not.
void relaxMatrix(SparseMatrix< Number > &matrix_in, const Real relaxation_parameter, NumericVector< Number > &diff_diagonal)
Relax the matrix to ensure diagonal dominance, we hold onto the difference in diagonals for later use...
void constrainSystem(SparseMatrix< Number > &mx, NumericVector< Number > &rhs, const Real desired_value, const dof_id_type dof_id)
Implicitly constrain the system by adding a factor*(u-u_desired) to it at a desired dof value.
void relaxSolutionUpdate(NumericVector< Number > &vec_new, const NumericVector< Number > &vec_old, const Real relaxation_factor)
Relax the update on a solution field using the following approach: $u = u_{old}+\lambda (u - u_{old})...
void limitSolutionUpdate(NumericVector< Number > &solution, const Real min_limit=std::numeric_limits< Real >::epsilon(), const Real max_limit=1e10)
Limit a solution to its minimum and maximum bounds: $u = min(max(u, min_limit), max_limit)$.
void relaxRightHandSide(NumericVector< Number > &rhs_in, const NumericVector< Number > &solution_in, const NumericVector< Number > &diff_diagonal)
Relax the right hand side of an equation, this needs to be called once and the system matrix has been...
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
auto index_range(const T &sizable)
const unsigned int invalid_uint
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real