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.");
32 params.
addParam<std::vector<SolverSystemName>>(
33 "turbulence_systems", {},
"The solver system(s) for the turbulence equation(s).");
39 "turbulence_equation_relaxation",
41 "The relaxation which should be used for the turbulence equations " 42 "equations. (=1 for no relaxation, " 43 "diagonal dominance will still be enforced)");
46 "turbulence_field_min_limit",
48 "The lower limit imposed on turbulent quantities. The recommended value for robustness " 58 "Singleton PETSc options for the turbulence equation(s)");
61 "Names of PETSc name/value pairs for the turbulence equation(s)");
62 params.
addParam<std::vector<std::string>>(
63 "turbulence_petsc_options_value",
64 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\" for the " 65 "turbulence equation");
68 "turbulence_petsc_options turbulence_petsc_options_iname turbulence_petsc_options_value",
76 "turbulence_absolute_tolerance",
78 "The absolute tolerance(s) on the normalized residual(s) of the turbulence equation(s).");
87 "0.0<=turbulence_l_tol & turbulence_l_tol<1.0",
88 "The relative tolerance on the normalized residual in the " 89 "linear solver of the turbulence equation(s).");
92 "0.0<turbulence_l_abs_tol",
93 "The absolute tolerance on the normalized residual in the " 94 "linear solver of the turbulence equation(s).");
96 "turbulence_l_max_its",
98 "The maximum allowed iterations in the linear solver of the turbulence equation(s).");
101 "turbulence_l_abs_tol turbulence_l_max_its",
102 "Linear Iteration Control");
109 _pressure_sys_number(_problem.nlSysNum(getParam<SolverSystemName>(
"pressure_system"))),
110 _pressure_system(_problem.getNonlinearSystemBase(_pressure_sys_number)),
111 _has_turbulence_systems(!getParam<
std::vector<SolverSystemName>>(
"turbulence_systems").empty()),
112 _energy_sys_number(_has_energy_system
113 ? _problem.nlSysNum(getParam<SolverSystemName>(
"energy_system"))
115 _energy_system(_has_energy_system ? &_problem.getNonlinearSystemBase(_energy_sys_number)
117 _solid_energy_sys_number(
118 _has_solid_energy_system
119 ? _problem.nlSysNum(getParam<SolverSystemName>(
"solid_energy_system"))
121 _solid_energy_system(_has_solid_energy_system
122 ? &_problem.getNonlinearSystemBase(_solid_energy_sys_number)
124 _turbulence_system_names(getParam<
std::vector<SolverSystemName>>(
"turbulence_systems")),
125 _turbulence_equation_relaxation(getParam<
std::vector<
Real>>(
"turbulence_equation_relaxation")),
126 _turbulence_field_min_limit(getParam<
std::vector<
Real>>(
"turbulence_field_min_limit")),
127 _turbulence_l_abs_tol(getParam<
Real>(
"turbulence_l_abs_tol")),
128 _turbulence_absolute_tolerance(getParam<
std::vector<
Real>>(
"turbulence_absolute_tolerance")),
129 _pressure_tag_name(getParam<TagName>(
"pressure_gradient_tag")),
130 _pressure_tag_id(_problem.addVectorTag(_pressure_tag_name))
176 "The number of equation relaxation parameters does not match the number of " 177 "turbulence scalar equations!");
180 "The number of absolute tolerances does not match the number of " 181 "turbulence equations!");
187 "The number of lower bounds for turbulent quantities does not match the " 188 "number of turbulence equations!");
193 "solid_energy_system",
194 "We cannot solve a solid energy system without solving for the fluid energy as well!");
198 const auto & turbulence_petsc_options = getParam<MultiMooseEnum>(
"turbulence_petsc_options");
199 const auto & turbulence_petsc_pair_options = getParam<MooseEnumItem, std::string>(
200 "turbulence_petsc_options_iname",
"turbulence_petsc_options_value");
212 getParam<unsigned int>(
"turbulence_l_max_its");
216 {
"turbulence_petsc_options",
217 "turbulence_petsc_options_iname",
218 "turbulence_petsc_options_value",
220 "turbulence_l_abs_tol",
221 "turbulence_l_max_its",
222 "turbulence_equation_relaxation",
223 "turbulence_absolute_tolerance"},
233 &getUserObject<INSFVRhieChowInterpolatorSegregated>(
"rhie_chow_user_object"));
240 std::vector<std::pair<unsigned int, Real>>
245 std::vector<std::pair<unsigned int, Real>> its_normalized_residuals;
249 auto zero_solution =
_momentum_systems[0]->system().current_local_solution->zero_clone();
260 libMesh::cast_ref<NonlinearImplicitSystem &>(
_momentum_systems[system_i]->system());
263 libMesh::cast_ref<PetscLinearSolver<Real> &>(*momentum_system.
get_linear_solver());
286 LibmeshPetscCall(KSPSetNormType(momentum_solver.ksp(), KSP_NORM_UNPRECONDITIONED));
293 auto its_resid_pair = momentum_solver.solve(mmat, mmat, solution, rhs);
297 its_normalized_residuals.push_back(
298 std::make_pair(its_resid_pair.first, momentum_solver.get_initial_residual() / norm_factor));
302 _console <<
" matrix when we solve " << std::endl;
304 _console <<
" rhs when we solve " << std::endl;
306 _console <<
" velocity solution component " << system_i << std::endl;
308 _console <<
"Norm factor " << norm_factor << std::endl;
316 libMesh::cast_ref<NonlinearImplicitSystem &>(
_momentum_systems[system_i]->system());
321 return its_normalized_residuals;
324 std::pair<unsigned int, Real>
341 libMesh::cast_ref<PetscLinearSolver<Real> &>(*pressure_system.
get_linear_solver());
346 auto zero_solution = current_local_solution.zero_clone();
352 _console <<
"Pressure matrix" << std::endl;
360 LibmeshPetscCall(KSPSetNormType(pressure_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
369 auto its_res_pair = pressure_solver.
solve(mmat, mmat, solution, rhs);
374 _console <<
" rhs when we solve pressure " << std::endl;
376 _console <<
" Pressure " << std::endl;
378 _console <<
"Norm factor " << norm_factor << std::endl;
383 return std::make_pair(its_res_pair.first, pressure_solver.
get_initial_residual() / norm_factor);
386 std::pair<unsigned int, Real>
389 const Real relaxation_factor,
391 const Real absolute_tol)
397 libMesh::cast_ref<NonlinearImplicitSystem &>(system.
system());
415 auto zero_solution = current_local_solution.zero_clone();
425 _console << system.
name() <<
" system matrix" << std::endl;
433 LibmeshPetscCall(KSPSetNormType(linear_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
440 auto its_res_pair = linear_solver.
solve(mmat, mmat, solution, rhs);
445 _console <<
" rhs when we solve " << system.
name() << std::endl;
449 _console <<
" Norm factor " << norm_factor << std::endl;
457 std::pair<unsigned int, Real>
479 auto zero_solution = current_local_solution.zero_clone();
485 _console <<
"Solid energy matrix" << std::endl;
493 LibmeshPetscCall(KSPSetNormType(se_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
499 auto its_res_pair = se_solver.
solve(mat, mat, solution, rhs);
504 _console <<
" Solid energy rhs " << std::endl;
506 _console <<
" Solid temperature " << std::endl;
508 _console <<
"Norm factor " << norm_factor << std::endl;
521 solver_params.
_type = Moose::SolveType::ST_LINEAR;
522 solver_params.
_line_search = Moose::LineSearchType::LS_NONE;
525 unsigned int iteration_counter = 0;
528 unsigned int no_systems =
532 std::vector<std::pair<unsigned int, Real>> ns_its_residuals(no_systems, std::make_pair(0, 1.0));
551 size_t residual_index = 0;
583 for (
const auto system_i :
index_range(momentum_residual))
584 ns_its_residuals[system_i] = momentum_residual[system_i];
609 pressure_old_solution = pressure_current_solution;
619 residual_index = momentum_residual.size();
655 ns_its_residuals[residual_index] =
662 auto & current_solution =
674 old_solution = current_solution;
684 _console <<
"Iteration " << iteration_counter <<
" Initial residual norms:" << std::endl;
688 ? std::string(
" Component ") + std::to_string(system_i + 1) +
691 << COLOR_GREEN << ns_its_residuals[system_i].second << COLOR_DEFAULT << std::endl;
692 _console <<
" Pressure equation: " << COLOR_GREEN
693 << ns_its_residuals[momentum_residual.size()].second << COLOR_DEFAULT << std::endl;
694 residual_index = momentum_residual.size();
699 _console <<
" Energy equation: " << COLOR_GREEN << ns_its_residuals[residual_index].second
700 << COLOR_DEFAULT << std::endl;
704 _console <<
" Solid energy equation: " << COLOR_GREEN
705 << ns_its_residuals[residual_index].second << COLOR_DEFAULT << std::endl;
711 _console <<
"Turbulence Iteration " << std::endl;
716 << ns_its_residuals[residual_index].second << COLOR_DEFAULT << std::endl;
730 _console <<
" Passive Scalar Iteration " << iteration_counter << std::endl;
736 iteration_counter = 0;
737 std::vector<std::pair<unsigned int, Real>> passive_scalar_residuals(
740 bool passive_scalar_converged =
742 while (iteration_counter <
_num_iterations && !passive_scalar_converged)
752 passive_scalar_residuals[system_i] =
759 _console <<
"Iteration " << iteration_counter <<
" Initial residual norms:" << std::endl;
762 << passive_scalar_residuals[system_i].second << COLOR_DEFAULT << std::endl;
764 passive_scalar_converged =
804 mooseError(
"You have specified time kernels in your steady state simulation in system",
const unsigned int _energy_sys_number
The number of the system corresponding to the energy equation.
MultiMooseEnum getCommonPetscKeys()
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...
SIMPLESolveNonlinearAssembly(Executioner &ex)
SIMPLESolverConfiguration _momentum_linear_control
Options for the linear solver of the momentum equation.
const Real _energy_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in energy.
const TagID _pressure_tag_id
The ID of the tag which corresponds to the pressure gradient terms in the momentum equation...
const unsigned int _num_iterations
The maximum number of momentum-pressure iterations.
SIMPLESolverConfiguration _energy_linear_control
Options for the linear solver of the energy equation.
const unsigned int invalid_uint
const bool _print_fields
Debug parameter which allows printing the coupling and solution vectors/matrices. ...
INSFVRhieChowInterpolatorSegregated * _rc_uo
Pointer to the segregated RhieChow interpolation object.
const Real _solid_energy_l_abs_tol
Absolute linear tolerance for the energy equations.
const bool _has_energy_system
Boolean for easy check if a fluid energy system shall be solved or not.
Moose::LineSearchType _line_search
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...
const Real _passive_scalar_l_abs_tol
Absolute linear tolerance for the passive scalar equation(s).
std::vector< Real > _turbulence_field_min_limit
The user-defined lower limit for turbulent quantities e.g. k, eps/omega, etc..
const Real _momentum_equation_relaxation
The user-defined relaxation parameter for the momentum equation.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const=0
std::vector< unsigned int > _turbulence_system_numbers
virtual void checkTimeKernels(NonlinearSystemBase &system)
Check if the system contains time kernels.
void checkDependentParameterError(const std::string &main_parameter, const std::vector< std::string > &dependent_parameters, const bool should_be_defined)
static InputParameters validParams()
NumericVector< Number > * rhs
const unsigned int _solid_energy_sys_number
The number of the system corresponding to the solid energy equation.
const Real _momentum_l_abs_tol
Absolute linear tolerance for the momentum equation(s).
void setSolution(const NumericVector< Number > &soln)
virtual LinearSolver< Number > * get_linear_solver() const
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
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
virtual void linkRhieChowUserObject() override
Fetch the Rhie Chow user object that is reponsible for determining face velocities and mass flux...
const Real _turbulence_l_abs_tol
Absolute linear tolerance for the turbulence equation(s).
NonlinearSystemBase & _pressure_system
Reference to the nonlinear system corresponding to the pressure equation.
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...
std::map< std::string, Real > real_valued_data
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.
const Real _pressure_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in pressure.
bool isParamValid(const std::string &name) const
const Real _pressure_variable_relaxation
The user-defined relaxation parameter for the pressure variable.
const Real _momentum_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in momentum.
virtual const std::string & name() const
const std::vector< SolverSystemName > & _passive_scalar_system_names
The names of the passive scalar systems.
virtual bool containsTimeKernel() override
SIMPLESolverConfiguration _turbulence_linear_control
Options for the linear solver of the turbulence equation(s)
virtual void scale(const T factor)=0
void computeFaceVelocity()
Update the values of the face velocities in the containers.
SIMPLESolverConfiguration _passive_scalar_linear_control
Options for the linear solver of the passive scalar equation(s)
virtual void execute(const ExecFlagType &exec_type)
Moose::PetscSupport::PetscOptions _energy_petsc_options
Options which hold the petsc settings for the fluid energy equation.
SIMPLESolverConfiguration _pressure_linear_control
Options for the linear solver of the pressure equation.
MultiMooseEnum getCommonPetscFlags()
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
Moose::PetscSupport::PetscOptions _passive_scalar_petsc_options
Options which hold the petsc settings for the passive scalar equation(s)
virtual unsigned int dimension() const
std::map< std::string, int > int_valued_data
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const=0
const bool _has_turbulence_systems
Boolean for easy check if turbulence systems shall be solved or not.
Moose::PetscSupport::PetscOptions _momentum_petsc_options
Options which hold the petsc settings for the momentum equation.
const Real _pressure_l_abs_tol
Absolute linear tolerance for the pressure equation.
const std::vector< Real > _passive_scalar_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in passive scalars.
std::unique_ptr< NumericVector< Number > > solution
dof_id_type _pressure_pin_dof
The dof ID where the pressure needs to be pinned.
const std::vector< SolverSystemName > & _turbulence_system_names
The names of the turbulence scalar systems.
virtual void print(std::ostream &os=libMesh::out) const
const bool _pin_pressure
If the pressure needs to be pinned.
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
void paramError(const std::string ¶m, Args... args) const
const Real _energy_l_abs_tol
Absolute linear tolerance for the energy equations.
std::string stringify(const T &t)
std::pair< unsigned int, Real > solveSolidEnergySystem()
Solve the solid energy conservation equation.
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
void set_solver_configuration(SolverConfiguration &solver_configuration)
const std::vector< SolverSystemName > & _momentum_system_names
The names of the momentum systems.
const ExecFlagType EXEC_NONLINEAR
NonlinearSystemBase * _solid_energy_system
Pointer to the nonlinear system corresponding to the solid energy equation.
const std::vector< Real > _passive_scalar_equation_relaxation
The user-defined relaxation parameter(s) for the passive scalar equation(s)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual bool solve() override
Performs the momentum pressure coupling.
NonlinearSystemBase * _energy_system
Pointer to the nonlinear system corresponding to the fluid energy equation.
void addPetscPairsToPetscOptions(const std::vector< std::pair< MooseEnumItem, std::string >> &petsc_pair_options, const unsigned int mesh_dimension, const std::string &prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
Real get_initial_residual()
const Real _energy_equation_relaxation
The user-defined relaxation parameter for the energy equation.
SparseMatrix< Number > * matrix
std::vector< NonlinearSystemBase * > _momentum_systems
Pointer(s) to the system(s) corresponding to the momentum equation(s)
const Real _pressure_pin_value
The value we want to enforce for pressure.
void computeResidualAndJacobian(const NumericVector< libMesh::Number > &soln, NumericVector< libMesh::Number > &residual, libMesh::SparseMatrix< libMesh::Number > &jacobian)
static InputParameters validParams()
virtual MooseMesh & mesh() override
void computeCellVelocity()
Update the cell values of the velocity variables.
void mooseError(Args &&... args) const
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::unique_ptr< NumericVector< Number > > current_local_solution
virtual const NumericVector< Number > * solutionPreviousNewton() const
Solve class serving as a base class for the two SIMPLE solvers that operate with different assembly a...
const bool _has_passive_scalar_systems
Boolean for easy check if a passive scalar systems shall be solved or not.
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, const std::string &prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
const ConsoleStream _console
const Real _solid_energy_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in solid energy.
SIMPLESolverConfiguration _solid_energy_linear_control
Options for the linear solver of the energy equation.
const bool _continue_on_max_its
If solve should continue if maximum number of iterations is hit.
Moose::PetscSupport::PetscOptions _turbulence_petsc_options
Options which hold the petsc settings for the turbulence equation(s)
const unsigned int _pressure_sys_number
The number of the system corresponding to the pressure equation.
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 prefix_with_name(bool value)
const std::vector< Real > _turbulence_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in turbulence equations...
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 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}+ (u - u_{old})$...
void computeHbyA(bool verbose)
Computes the inverse of the digaonal (1/A) of the system matrix plus the H/A components for the press...
const std::vector< Real > _turbulence_equation_relaxation
The user-defined relaxation parameter(s) for the turbulence equation(s)
std::vector< NonlinearSystemBase * > _passive_scalar_systems
Pointer(s) to the system(s) corresponding to the passive scalar equation(s)
auto index_range(const T &sizable)
std::vector< NonlinearSystemBase * > _turbulence_systems
Pointer(s) to the system(s) corresponding to the turbulence equation(s)
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
std::vector< unsigned int > _momentum_system_numbers
The number(s) of the system(s) corresponding to the momentum equation(s)
virtual void checkIntegrity() override
Check if the user defined time kernels.
std::vector< unsigned int > _passive_scalar_system_numbers
virtual unsigned int nlSysNum(const NonlinearSystemName &nl_sys_name) const override
Moose::PetscSupport::PetscOptions _pressure_petsc_options
Options which hold the petsc settings for the pressure equation.
A user object which implements the Rhie Chow interpolation for segregated momentum-pressure systems...
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.
const bool _has_solid_energy_system
Boolean for easy check if a solid energy system 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.
virtual std::pair< unsigned int, Real > solvePressureCorrector() override
Solve a pressure corrector step.
void initFaceVelocities()
Initialize the container for face velocities.
virtual void residualSetup() override
virtual libMesh::System & system() override