23 params.
addParam<std::vector<SolverSystemName>>(
24 "active_scalar_systems", {},
"The solver system for each active scalar advection equation.");
29 params.
addParam<std::vector<Real>>(
"active_scalar_equation_relaxation",
31 "The relaxation which should be used for the active scalar " 32 "equations. (=1 for no relaxation, " 33 "diagonal dominance will still be enforced)");
37 "Singleton PETSc options for the active scalar equation(s)");
39 "active_scalar_petsc_options_iname",
41 "Names of PETSc name/value pairs for the active scalar equation(s)");
42 params.
addParam<std::vector<std::string>>(
43 "active_scalar_petsc_options_value",
44 "Values of PETSc name/value pairs (must correspond with \"petsc_options_iname\" for the " 45 "active scalar equation(s)");
47 "active_scalar_absolute_tolerance",
49 "The absolute tolerance(s) on the normalized residual(s) of the active scalar equation(s).");
52 "0.0<=active_scalar_l_tol & active_scalar_l_tol<1.0",
53 "The relative tolerance on the normalized residual in the " 54 "linear solver of the active scalar equation(s).");
57 "0.0<active_scalar_l_abs_tol",
58 "The absolute tolerance on the normalized residual in the " 59 "linear solver of the active scalar equation(s).");
61 "active_scalar_l_max_its",
63 "The maximum allowed iterations in the linear solver of the turbulence equation.");
66 "active_scalar_systems active_scalar_equation_relaxation active_scalar_petsc_options " 67 "active_scalar_petsc_options_iname " 68 "active_scalar_petsc_options_value active_scalar_petsc_options_value " 69 "active_scalar_absolute_tolerance " 70 "active_scalar_l_tol active_scalar_l_abs_tol active_scalar_l_max_its",
71 "Active Scalars Equations");
83 _pressure_sys_number(_problem.linearSysNum(getParam<SolverSystemName>(
"pressure_system"))),
84 _pressure_system(_problem.getLinearSystem(_pressure_sys_number)),
85 _energy_sys_number(_has_energy_system
86 ? _problem.linearSysNum(getParam<SolverSystemName>(
"energy_system"))
88 _energy_system(_has_energy_system ? &_problem.getLinearSystem(_energy_sys_number) : nullptr),
89 _solid_energy_sys_number(
90 _has_solid_energy_system
91 ? _problem.linearSysNum(getParam<SolverSystemName>(
"solid_energy_system"))
94 _has_solid_energy_system ? &_problem.getLinearSystem(_solid_energy_sys_number) : nullptr),
95 _active_scalar_system_names(getParam<
std::vector<SolverSystemName>>(
"active_scalar_systems")),
96 _has_active_scalar_systems(!_active_scalar_system_names.empty()),
97 _active_scalar_equation_relaxation(
98 getParam<
std::vector<
Real>>(
"active_scalar_equation_relaxation")),
99 _active_scalar_l_abs_tol(getParam<
Real>(
"active_scalar_l_abs_tol")),
100 _active_scalar_absolute_tolerance(
101 getParam<
std::vector<
Real>>(
"active_scalar_absolute_tolerance")),
102 _cht(ex.parameters())
150 const auto & active_scalar_petsc_options =
151 getParam<MultiMooseEnum>(
"active_scalar_petsc_options");
152 const auto & active_scalar_petsc_pair_options = getParam<MooseEnumItem, std::string>(
153 "active_scalar_petsc_options_iname",
"active_scalar_petsc_options_value");
163 getParam<Real>(
"active_scalar_l_tol");
165 getParam<Real>(
"active_scalar_l_abs_tol");
167 getParam<unsigned int>(
"active_scalar_l_max_its");
171 paramError(
"active_scalar_equation_relaxation",
172 "Should be the same size as the number of systems");
177 system->system().prefix_with_name(
false);
188 const_cast<RhieChowMassFlux *
>(&getUserObject<RhieChowMassFlux>(
"rhie_chow_user_object"));
198 std::vector<std::pair<unsigned int, Real>>
203 std::vector<std::pair<unsigned int, Real>> its_normalized_residuals;
209 libMesh::cast_ref<PetscLinearSolver<Real> &>(*momentum_system_0.
get_linear_solver());
220 libMesh::cast_ref<LinearImplicitSystem &>(
_momentum_systems[system_i]->system());
241 LibmeshPetscCall(KSPSetNormType(momentum_solver.ksp(), KSP_NORM_UNPRECONDITIONED));
248 auto its_resid_pair = momentum_solver.solve(mmat, mmat, solution, rhs);
253 momentum_solver.reuse_preconditioner(
true);
256 its_normalized_residuals.push_back(
257 std::make_pair(its_resid_pair.first, momentum_solver.get_initial_residual() / norm_factor));
261 _console <<
" solution after solve " << std::endl;
263 _console <<
" matrix when we solve " << std::endl;
265 _console <<
" rhs when we solve " << std::endl;
267 _console <<
" velocity solution component " << system_i << std::endl;
269 _console <<
"Norm factor " << norm_factor << std::endl;
276 ? std::string(
" Component ") + std::to_string(system_i + 1) + std::string(
" ")
278 << COLOR_GREEN << its_normalized_residuals[system_i].second << COLOR_DEFAULT
279 <<
" Linear its: " << its_normalized_residuals[system_i].first << std::endl;
285 libMesh::cast_ref<LinearImplicitSystem &>(
_momentum_systems[system_i]->system());
292 momentum_solver.reuse_preconditioner(
false);
294 return its_normalized_residuals;
307 std::pair<unsigned int, Real>
324 libMesh::cast_ref<PetscLinearSolver<Real> &>(*pressure_system.
get_linear_solver());
330 _console <<
"Pressure matrix" << std::endl;
338 LibmeshPetscCall(KSPSetNormType(pressure_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
348 auto its_res_pair = pressure_solver.
solve(mmat, mmat, solution, rhs);
353 _console <<
" rhs when we solve pressure " << std::endl;
355 _console <<
" Pressure " << std::endl;
357 _console <<
"Norm factor " << norm_factor << std::endl;
362 const auto residuals =
365 _console <<
" Pressure equation: " << COLOR_GREEN << residuals.second << COLOR_DEFAULT
366 <<
" Linear its: " << residuals.first << std::endl;
371 std::pair<unsigned int, Real>
394 _console <<
"Solid energy matrix" << std::endl;
402 LibmeshPetscCall(KSPSetNormType(solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
408 auto its_res_pair = solver.
solve(mmat, mmat, solution, rhs);
413 _console <<
" rhs when we solve solid energy " << std::endl;
415 _console <<
" Solid energy " << std::endl;
417 _console <<
"Norm factor " << norm_factor << std::endl;
422 const auto residuals =
425 _console <<
" Solid energy equation: " << COLOR_GREEN << residuals.second << COLOR_DEFAULT
426 <<
" Linear its: " << residuals.first << std::endl;
431 std::pair<unsigned int, Real>
433 const bool recompute_face_mass_flux,
450 if (recompute_face_mass_flux)
461 pressure_old_solution = pressure_current_solution;
473 std::pair<unsigned int, Real>
476 const Real relaxation_factor,
478 const Real absolute_tol,
479 const Real field_relaxation,
480 const Real min_value_limiter)
508 _console << system.
name() <<
" system matrix" << std::endl;
516 LibmeshPetscCall(KSPSetNormType(linear_solver.
ksp(), KSP_NORM_UNPRECONDITIONED));
523 auto its_res_pair = linear_solver.
solve(mmat, mmat, solution, rhs);
528 _console <<
" rhs when we solve " << system.
name() << std::endl;
532 _console <<
" Norm factor " << norm_factor << std::endl;
536 if (min_value_limiter != std::numeric_limits<Real>::min())
540 if (field_relaxation != 1.0)
546 old_local_solution = current_local_solution;
551 const auto residuals =
554 _console <<
" Advected system: " << system.
name() <<
" " << COLOR_GREEN << residuals.second
555 << COLOR_DEFAULT <<
" Linear its: " << residuals.first << std::endl;
569 solver_params.
_type = Moose::SolveType::ST_LINEAR;
570 solver_params.
_line_search = Moose::LineSearchType::LS_NONE;
573 unsigned int simple_iteration_counter = 0;
580 std::vector<std::pair<unsigned int, Real>> ns_residuals(no_systems, std::make_pair(0, 1.0));
591 ns_abs_tols.push_back(scalar_tol);
596 ns_abs_tols.push_back(turbulence_tol);
605 simple_iteration_counter++;
614 if (simple_iteration_counter == 1)
617 _console <<
"Iteration " << simple_iteration_counter <<
" Initial residual norms:" << std::endl;
621 for (
const auto system_i :
index_range(momentum_residual))
622 ns_residuals[system_i] = momentum_residual[system_i];
626 ns_residuals[momentum_residual.size()] =
correctVelocity(
true,
true, solver_params);
734 bool passive_scalar_converged =
false;
735 unsigned int ps_iteration_counter = 0;
737 _console <<
"Passive scalar iteration " << ps_iteration_counter
738 <<
" Initial residual norms:" << std::endl;
740 while (ps_iteration_counter <
_num_iterations && !passive_scalar_converged)
742 ps_iteration_counter++;
743 std::vector<std::pair<unsigned int, Real>> scalar_residuals(
745 std::vector<Real> scalar_abs_tols;
747 scalar_abs_tols.push_back(scalar_tol);
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...
const std::vector< Real > _active_scalar_equation_relaxation
The user-defined relaxation parameter(s) for the active scalar equation(s)
static InputParameters validParams()
SIMPLESolverConfiguration _momentum_linear_control
Options for the linear solver of the momentum equation.
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject ¶m_object, PetscOptions &petsc_options)
SIMPLESolverConfiguration _turbulence_linear_control
Options for the linear solver of the turbulence equation(s)
const Real _energy_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in energy.
void updateCHTBoundaryCouplingFields(const NS::CHTSide side)
Update the coupling fields for.
const unsigned int _num_iterations
The maximum number of momentum-pressure iterations.
User object responsible for determining the face fluxes using the Rhie-Chow interpolation in a segreg...
SIMPLESolverConfiguration _energy_linear_control
Options for the linear solver of the energy equation.
const unsigned int invalid_uint
void paramError(const std::string ¶m, Args... args) const
const bool _print_fields
Debug parameter which allows printing the coupling and solution vectors/matrices. ...
Moose::PetscSupport::PetscOptions _turbulence_petsc_options
Options which hold the petsc settings for the turbulence equation(s)
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...
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)
SIMPLESolverConfiguration _active_scalar_linear_control
Options for the linear solver of the active scalar equation(s)
std::vector< Real > _turbulence_field_relaxation
The user-defined relaxation parameter(s) for the turbulence field(s)
const Real _passive_scalar_l_abs_tol
Absolute linear tolerance for the passive scalar equation(s).
std::pair< unsigned int, Real > solveSolidEnergy()
Solve an equation which contains the solid energy conservation.
std::vector< LinearSystem * > _passive_scalar_systems
Pointer(s) to the system(s) corresponding to the passive scalar equation(s)
void resetIntegratedFluxes()
Reset the heat fluxes to 0.
Moose::PetscSupport::PetscOptions _solid_energy_petsc_options
Options which hold the petsc settings for the fluid energy equation.
const Real _momentum_equation_relaxation
The user-defined relaxation parameter for the momentum equation.
virtual std::unique_ptr< NumericVector< T > > zero_clone() const=0
const bool _has_turbulence_systems
Boolean for easy check if a turbulence scalar systems shall be solved or not.
void computeFaceMassFlux()
Update the values of the face velocities in the containers.
std::vector< unsigned int > _turbulence_system_numbers
static InputParameters validParams()
void printIntegratedFluxes() const
Print the integrated heat fluxes.
LinearSystem * _solid_energy_system
Pointer to the linear system corresponding to the solid energy equation.
std::pair< unsigned int, Real > solveAdvectedSystem(const unsigned int system_num, LinearSystem &system, const Real relaxation_factor, libMesh::SolverConfiguration &solver_config, const Real abs_tol, const Real field_relaxation=1.0, const Real min_value_limiter=std::numeric_limits< Real >::min())
Solve an equation which contains an advection term that depends on the solution of the segregated Nav...
NumericVector< Number > * rhs
const Real _momentum_l_abs_tol
Absolute linear tolerance for the momentum equation(s).
void setSolution(const NumericVector< Number > &soln)
const bool _has_active_scalar_systems
Boolean for easy check if a active scalar systems shall be solved or not.
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
const Real _active_scalar_l_abs_tol
Absolute linear tolerance for the active scalar equation(s).
virtual LinearSolver< Number > * get_linear_solver() const override
void initializeCHTCouplingFields()
Initialize the coupling fields for the conjugate heat transfer routines.
RhieChowMassFlux * _rc_uo
Pointer to the segregated RhieChow interpolation object.
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
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
void setupConjugateHeatTransferContainers()
Set up the boundary condition pairs, functor maps, and every other necessary structure for the conjug...
virtual std::pair< unsigned int, Real > correctVelocity(const bool subtract_updated_pressure, const bool recompute_face_mass_flux, const SolverParams &solver_params)
Computes new velocity field based on computed pressure gradients.
void resetCHTConvergence()
Reset the convergence 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.
const Real _pressure_variable_relaxation
The user-defined relaxation parameter for the pressure variable.
virtual void computeLinearSystemSys(libMesh::LinearImplicitSystem &sys, libMesh::SparseMatrix< libMesh::Number > &system_matrix, NumericVector< libMesh::Number > &rhs, const bool compute_gradients=true)
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.
const unsigned int _solid_energy_sys_number
The number of the system corresponding to the solid energy equation.
std::vector< LinearSystem * > _active_scalar_systems
Pointer(s) to the system(s) corresponding to the active scalar equation(s)
SIMPLESolverConfiguration _passive_scalar_linear_control
Options for the linear solver of the passive scalar equation(s)
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...
virtual void execute(const ExecFlagType &exec_type)
Moose::PetscSupport::PetscOptions _energy_petsc_options
Options which hold the petsc settings for the fluid energy equation.
LinearSystem & _pressure_system
Reference to the linear system corresponding to the pressure equation.
std::vector< unsigned int > _momentum_system_numbers
The number(s) of the system(s) corresponding to the momentum equation(s)
SIMPLESolverConfiguration _pressure_linear_control
Options for the linear solver of the pressure equation.
MultiMooseEnum getCommonPetscFlags()
LinearSystem * _energy_system
Pointer to the linear system corresponding to the fluid energy equation.
const unsigned int _energy_sys_number
The number of the system corresponding to the energy equation.
void incrementCHTIterators()
Increment CHT iterators in the loop.
void linkEnergySystems(SystemBase *solid_energy_system, SystemBase *fluid_energy_system)
Link energy systems.
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
bool converged() const
Check if CHT iteration converged.
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const=0
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.
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.
void computeCellVelocity()
Update the cell values of the velocity variables.
const std::vector< SolverSystemName > & _turbulence_system_names
The names of the turbulence systems.
virtual bool solve() override
Performs the momentum pressure coupling.
virtual void print(std::ostream &os=libMesh::out) const
const bool _pin_pressure
If the pressure needs to be pinned.
const Real _energy_l_abs_tol
Absolute linear tolerance for the energy equations.
std::string stringify(const T &t)
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
void sumIntegratedFluxes()
Sum the integrated fluxes over all processors.
virtual void initialSetup() override
virtual void linkRhieChowUserObject() override
Fetch the Rhie Chow user object that is reponsible for determining face velocities and mass flux...
LinearSystem & getLinearSystem(unsigned int sys_num)
void set_solver_configuration(SolverConfiguration &solver_configuration)
const std::vector< Real > _turbulence_equation_relaxation
The user-defined relaxation parameter(s) for the turbulence equation(s)
const std::vector< SolverSystemName > & _momentum_system_names
The names of the momentum systems.
std::vector< LinearSystem * > _turbulence_systems
Pointer(s) to the system(s) corresponding to the turbulence equation(s)
LinearAssemblySegregatedSolve(Executioner &ex)
const ExecFlagType EXEC_NONLINEAR
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
const std::vector< SolverSystemName > & _active_scalar_system_names
The names of the active scalar systems.
Real get_initial_residual()
const Real _energy_equation_relaxation
The user-defined relaxation parameter for the energy equation.
SparseMatrix< Number > * matrix
void setCurrentLinearSystem(unsigned int sys_num)
std::vector< LinearSystem * > _systems_to_solve
Shortcut to every linear system that we solve for here.
const Real _pressure_pin_value
The value we want to enforce for pressure.
virtual std::vector< std::pair< unsigned int, Real > > solveMomentumPredictor() override
Solve a momentum predictor step with a fixed pressure field.
const Real _turbulence_l_abs_tol
Absolute linear tolerance for the turbulence equation(s).
virtual MooseMesh & mesh() override
unsigned int linearSysNum(const LinearSystemName &linear_sys_name) const override
void deduceCHTBoundaryCoupling()
Run error checks and make sure everything works.
virtual std::pair< unsigned int, Real > solvePressureCorrector() override
Solve a pressure corrector step.
Moose::PetscSupport::PetscOptions _active_scalar_petsc_options
Options which hold the petsc settings for the active scalar equation(s)
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.
const std::vector< Real > _active_scalar_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in active scalars.
virtual bool enabled() const override final
Check if CHT treatment is needed.
const ConsoleStream _console
static InputParameters validParams()
const Real _solid_energy_absolute_tolerance
The user-defined absolute tolerance for determining the convergence in solid energy.
std::vector< unsigned int > _active_scalar_system_numbers
SIMPLESolverConfiguration _solid_energy_linear_control
Options for the linear solver of the energy equation.
std::vector< LinearSystem * > _momentum_systems
Pointer(s) to the system(s) corresponding to the momentum equation(s)
const bool _continue_on_max_its
If solve should continue if maximum number of iterations is hit.
std::vector< Real > _turbulence_field_min_limit
The user-defined lower limit for turbulent quantities e.g. k, eps/omega, etc..
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 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)$.
bool isRecovering() const
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})$...
const std::vector< Real > _turbulence_absolute_tolerance
The user-defined absolute tolerance for determining the convergence turbulence variables.
auto index_range(const T &sizable)
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
std::vector< unsigned int > _passive_scalar_system_numbers
NS::FV::CHTHandler _cht
********************** Conjugate heat transfer variables ************** //
void initCouplingField()
Initialize the coupling fields (HbyA and Ainv)
Moose::PetscSupport::PetscOptions _pressure_petsc_options
Options which hold the petsc settings for the pressure equation.
virtual System & system() override
const bool _has_solid_energy_system
Boolean for easy check if a solid energy system shall be solved or not.
void initFaceMassFlux()
Initialize the container for face velocities.
const unsigned int _pressure_sys_number
The number of the system corresponding to the pressure equation.