https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SIMPLESolveNonlinearAssembly.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
11#include "FEProblem.h"
13#include "NonlinearSystemBase.h"
14
15#include "libmesh/nonlinear_implicit_system.h"
16
19{
21
22 params.addParam<TagName>("pressure_gradient_tag",
23 "pressure_momentum_kernels",
24 "The name of the tags associated with the kernels in the momentum "
25 "equations which are not related to the pressure gradient.");
26
27 return params;
28}
29
31 : SIMPLESolveBase(ex),
32 _pressure_sys_number(_problem.nlSysNum(getParam<SolverSystemName>("pressure_system"))),
33 _pressure_system(_problem.getNonlinearSystemBase(_pressure_sys_number)),
34 _has_turbulence_systems(!getParam<std::vector<SolverSystemName>>("turbulence_systems").empty()),
35 _energy_sys_number(_has_energy_system
36 ? _problem.nlSysNum(getParam<SolverSystemName>("energy_system"))
37 : libMesh::invalid_uint),
38 _energy_system(_has_energy_system ? &_problem.getNonlinearSystemBase(_energy_sys_number)
39 : nullptr),
40 _solid_energy_sys_number(
41 _has_solid_energy_system
42 ? _problem.nlSysNum(getParam<SolverSystemName>("solid_energy_system"))
43 : libMesh::invalid_uint),
44 _solid_energy_system(_has_solid_energy_system
45 ? &_problem.getNonlinearSystemBase(_solid_energy_sys_number)
46 : nullptr),
47 _turbulence_system_names(getParam<std::vector<SolverSystemName>>("turbulence_systems")),
48 _turbulence_equation_relaxation(getParam<std::vector<Real>>("turbulence_equation_relaxation")),
49 _turbulence_field_min_limit(getParam<std::vector<Real>>("turbulence_field_min_limit")),
50 _turbulence_l_abs_tol(getParam<Real>("turbulence_l_abs_tol")),
51 _turbulence_absolute_tolerance(getParam<std::vector<Real>>("turbulence_absolute_tolerance")),
52 _pressure_tag_name(getParam<TagName>("pressure_gradient_tag")),
53 _pressure_tag_id(_problem.addVectorTag(_pressure_tag_name))
54{
55 // We disable this considering that this object passes petsc options a little differently
57
58 // We fetch the system numbers for the momentum components plus add vectors
59 // for removing the contribution from the pressure gradient terms.
60 for (auto system_i : index_range(_momentum_system_names))
61 {
63 _momentum_systems.push_back(
65 _momentum_systems[system_i]->addVector(_pressure_tag_id, false, PARALLEL);
66
67 // We disable this considering that this object passes petsc options a little differently
68 _momentum_systems[system_i]->system().prefix_with_name(false);
69 }
70
72 for (auto system_i : index_range(_passive_scalar_system_names))
73 {
78
79 // We disable this considering that this object passes petsc options a little differently
80 _passive_scalar_systems[system_i]->system().prefix_with_name(false);
81 }
82
84 {
85 for (auto system_i : index_range(_turbulence_system_names))
86 {
88 _turbulence_systems.push_back(
90
91 // We disable this considering that this object passes petsc options a little differently
92 _turbulence_systems[system_i]->system().prefix_with_name(false);
93 }
94
95 // We check for input errors with regards to the turbulence equations. At the same time, we
96 // set up the corresponding system numbers
98 paramError("turbulence_equation_relaxation",
99 "The number of equation relaxation parameters does not match the number of "
100 "turbulence scalar equations!");
102 paramError("turbulence_absolute_tolerance",
103 "The number of absolute tolerances does not match the number of "
104 "turbulence equations!");
105 if (_turbulence_field_min_limit.empty())
106 // If no minimum bounds are given, initialize to default value 1e-8
109 paramError("turbulence_field_min_limit",
110 "The number of lower bounds for turbulent quantities does not match the "
111 "number of turbulence equations!");
112 }
113
114 if (isParamValid("solid_energy_system") && !_has_energy_system)
116 "solid_energy_system",
117 "We cannot solve a solid energy system without solving for the fluid energy as well!");
118
120 {
121 const auto & turbulence_petsc_options = getParam<MultiMooseEnum>("turbulence_petsc_options");
122 const auto & turbulence_petsc_pair_options = getParam<MooseEnumItem, std::string>(
123 "turbulence_petsc_options_iname", "turbulence_petsc_options_value");
125 turbulence_petsc_options, "", *this, _turbulence_petsc_options);
126 Moose::PetscSupport::addPetscPairsToPetscOptions(turbulence_petsc_pair_options,
128 "",
129 *this,
131
132 _turbulence_linear_control.real_valued_data["rel_tol"] = getParam<Real>("turbulence_l_tol");
133 _turbulence_linear_control.real_valued_data["abs_tol"] = getParam<Real>("turbulence_l_abs_tol");
135 getParam<unsigned int>("turbulence_l_max_its");
136 }
137 else
138 checkDependentParameterError("turbulence_system",
139 {"turbulence_petsc_options",
140 "turbulence_petsc_options_iname",
141 "turbulence_petsc_options_value",
142 "turbulence_l_tol",
143 "turbulence_l_abs_tol",
144 "turbulence_l_max_its",
145 "turbulence_equation_relaxation",
146 "turbulence_absolute_tolerance"},
147 false);
148}
149
150void
152{
153 // Fetch the segregated rhie-chow object and transfer some information about the momentum
154 // system(s)
156 &getUserObject<INSFVRhieChowInterpolatorSegregated>("rhie_chow_user_object"));
158
159 // Initialize the face velocities in the RC object
161}
162
163std::vector<std::pair<unsigned int, Real>>
165{
166 // Temporary storage for the (flux-normalized) residuals form
167 // different momentum components
168 std::vector<std::pair<unsigned int, Real>> its_normalized_residuals;
169
170 // We can create this here with the assumption that every momentum component has the same number
171 // of dofs
172 auto zero_solution = _momentum_systems[0]->system().current_local_solution->zero_clone();
173
174 // Solve the momentum equations.
175 // TO DO: These equations are VERY similar. If we can store the differences (things coming from
176 // BCs for example) separately, it is enough to construct one matrix.
177 for (const auto system_i : index_range(_momentum_systems))
178 {
180
181 // We will need the right hand side and the solution of the next component
182 NonlinearImplicitSystem & momentum_system =
183 cast_ref<NonlinearImplicitSystem &>(_momentum_systems[system_i]->system());
184
185 libMesh::PetscLinearSolver<Real> & momentum_solver =
186 cast_ref<libMesh::PetscLinearSolver<Real> &>(*momentum_system.get_linear_solver());
187
188 NumericVector<Number> & solution = *(momentum_system.solution);
189 NumericVector<Number> & rhs = *(momentum_system.rhs);
190 SparseMatrix<Number> & mmat = *(momentum_system.matrix);
191
192 auto diff_diagonal = solution.zero_clone();
193
194 // We plug zero in this to get the system matrix and the right hand side of the linear problem
195 _problem.computeResidualAndJacobian(*zero_solution, rhs, mmat);
196 // Sadly, this returns -b so we multiply with -1
197 rhs.scale(-1.0);
198
199 // Still need to relax the right hand side with the same vector
201 NS::FV::relaxRightHandSide(rhs, solution, *diff_diagonal);
202
203 // The normalization factor depends on the right hand side so we need to recompute it for this
204 // component
205 Real norm_factor = NS::FV::computeNormalizationFactor(solution, mmat, rhs);
206
207 // Very important, for deciding the convergence, we need the unpreconditioned
208 // norms in the linear solve
209 LibmeshPetscCall(KSPSetNormType(momentum_solver.ksp(), KSP_NORM_UNPRECONDITIONED));
210 // Solve this component. We don't update the ghosted solution yet, that will come at the end
211 // of the corrector step. Also setting the linear tolerances and maximum iteration counts.
214
215 // We solve the equation
216 auto its_resid_pair = momentum_solver.solve(mmat, mmat, solution, rhs);
217 momentum_system.update();
218
219 // Save the normalized residual
220 its_normalized_residuals.push_back(
221 std::make_pair(its_resid_pair.first, momentum_solver.get_initial_residual() / norm_factor));
222
223 if (_print_fields)
224 {
225 _console << " matrix when we solve " << std::endl;
226 mmat.print();
227 _console << " rhs when we solve " << std::endl;
228 rhs.print();
229 _console << " velocity solution component " << system_i << std::endl;
230 solution.print();
231 _console << "Norm factor " << norm_factor << std::endl;
232 _console << Moose::stringify(momentum_solver.get_initial_residual()) << std::endl;
233 }
234
235 _momentum_systems[system_i]->setSolution(*(momentum_system.current_local_solution));
236 _momentum_systems[system_i]->copyPreviousSolutions(Moose::SolutionIterationType::Nonlinear);
237 }
238
239 return its_normalized_residuals;
240}
241
242std::pair<unsigned int, Real>
244{
246
247 // We will need some members from the implicit nonlinear system
248 NonlinearImplicitSystem & pressure_system =
249 cast_ref<NonlinearImplicitSystem &>(_pressure_system.system());
250
251 // We will need the solution, the right hand side and the matrix
252 NumericVector<Number> & current_local_solution = *(pressure_system.current_local_solution);
253 NumericVector<Number> & solution = *(pressure_system.solution);
254 SparseMatrix<Number> & mmat = *(pressure_system.matrix);
255 NumericVector<Number> & rhs = *(pressure_system.rhs);
256
257 // Fetch the linear solver from the system
258 libMesh::PetscLinearSolver<Real> & pressure_solver =
259 cast_ref<libMesh::PetscLinearSolver<Real> &>(*pressure_system.get_linear_solver());
260
261 // We need a zero vector to be able to emulate the Ax=b system by evaluating the
262 // residual and jacobian. Unfortunately, this will leave us with the -b on the right hand side
263 // so we correct it by multiplying it with (-1)
264 auto zero_solution = current_local_solution.zero_clone();
265 _problem.computeResidualAndJacobian(*zero_solution, rhs, mmat);
266 rhs.scale(-1.0);
267
268 if (_print_fields)
269 {
270 _console << "Pressure matrix" << std::endl;
271 mmat.print();
272 }
273
274 // We compute the normalization factors based on the fluxes
275 Real norm_factor = NS::FV::computeNormalizationFactor(solution, mmat, rhs);
276
277 // We need the non-preconditioned norm to be consistent with the norm factor
278 LibmeshPetscCall(KSPSetNormType(pressure_solver.ksp(), KSP_NORM_UNPRECONDITIONED));
279
280 // Setting the linear tolerances and maximum iteration counts
283
284 if (_pin_pressure)
286
287 auto its_res_pair = pressure_solver.solve(mmat, mmat, solution, rhs);
288 pressure_system.update();
289
290 if (_print_fields)
291 {
292 _console << " rhs when we solve pressure " << std::endl;
293 rhs.print();
294 _console << " Pressure " << std::endl;
295 solution.print();
296 _console << "Norm factor " << norm_factor << std::endl;
297 }
298
299 _pressure_system.setSolution(current_local_solution);
300
301 return std::make_pair(its_res_pair.first, pressure_solver.get_initial_residual() / norm_factor);
302}
303
304std::pair<unsigned int, Real>
306 NonlinearSystemBase & system,
307 const Real relaxation_factor,
308 libMesh::SolverConfiguration & solver_config,
309 const Real absolute_tol)
310{
312
313 // We will need some members from the implicit nonlinear system
314 NonlinearImplicitSystem & ni_system = cast_ref<NonlinearImplicitSystem &>(system.system());
315
316 // We will need the solution, the right hand side and the matrix
317 NumericVector<Number> & current_local_solution = *(ni_system.current_local_solution);
318 NumericVector<Number> & solution = *(ni_system.solution);
319 SparseMatrix<Number> & mmat = *(ni_system.matrix);
320 NumericVector<Number> & rhs = *(ni_system.rhs);
321
322 // We need a vector that stores the (diagonal_relaxed-original_diagonal) vector
323 auto diff_diagonal = solution.zero_clone();
324
325 // Fetch the linear solver from the system
326 libMesh::PetscLinearSolver<Real> & linear_solver =
327 cast_ref<libMesh::PetscLinearSolver<Real> &>(*ni_system.get_linear_solver());
328
329 // We need a zero vector to be able to emulate the Ax=b system by evaluating the
330 // residual and jacobian. Unfortunately, this will leave us with the -b on the right hand side
331 // so we correct it by multiplying it with (-1)
332 auto zero_solution = current_local_solution.zero_clone();
333 _problem.computeResidualAndJacobian(*zero_solution, rhs, mmat);
334 rhs.scale(-1.0);
335
336 // Go and relax the system matrix and the right hand side
337 NS::FV::relaxMatrix(mmat, relaxation_factor, *diff_diagonal);
338 NS::FV::relaxRightHandSide(rhs, solution, *diff_diagonal);
339
340 if (_print_fields)
341 {
342 _console << system.name() << " system matrix" << std::endl;
343 mmat.print();
344 _console << system.name() << " RHS vector" << std::endl;
345 rhs.print();
346 }
347
348 // We compute the normalization factors based on the fluxes
349 Real norm_factor = NS::FV::computeNormalizationFactor(solution, mmat, rhs);
350
351 // We need the non-preconditioned norm to be consistent with the norm factor
352 LibmeshPetscCall(KSPSetNormType(linear_solver.ksp(), KSP_NORM_UNPRECONDITIONED));
353
354 // Setting the linear tolerances and maximum iteration counts
355 solver_config.real_valued_data["abs_tol"] = absolute_tol * norm_factor;
356 linear_solver.set_solver_configuration(solver_config);
357
358 // Solve the system and update current local solution
359 auto its_res_pair = linear_solver.solve(mmat, mmat, solution, rhs);
360 ni_system.update();
361
362 if (_print_fields)
363 {
364 _console << " rhs when we solve " << system.name() << std::endl;
365 rhs.print();
366 _console << system.name() << " solution " << std::endl;
367 solution.print();
368 _console << " Norm factor " << norm_factor << std::endl;
369 }
370
371 system.setSolution(current_local_solution);
372
373 return std::make_pair(its_res_pair.first, linear_solver.get_initial_residual() / norm_factor);
374}
375
376std::pair<unsigned int, Real>
378{
380
381 // We will need some members from the implicit nonlinear system
382 NonlinearImplicitSystem & se_system =
383 cast_ref<NonlinearImplicitSystem &>(_solid_energy_system->system());
384
385 // We will need the solution, the right hand side and the matrix
386 NumericVector<Number> & current_local_solution = *(se_system.current_local_solution);
387 NumericVector<Number> & solution = *(se_system.solution);
388 SparseMatrix<Number> & mat = *(se_system.matrix);
389 NumericVector<Number> & rhs = *(se_system.rhs);
390
391 // Fetch the linear solver from the system
393 cast_ref<libMesh::PetscLinearSolver<Real> &>(*se_system.get_linear_solver());
394
395 // We need a zero vector to be able to emulate the Ax=b system by evaluating the
396 // residual and jacobian. Unfortunately, this will leave us with the -b on the righ hand side
397 // so we correct it by multiplying it with (-1)
398 auto zero_solution = current_local_solution.zero_clone();
399 _problem.computeResidualAndJacobian(*zero_solution, rhs, mat);
400 rhs.scale(-1.0);
401
402 if (_print_fields)
403 {
404 _console << "Solid energy matrix" << std::endl;
405 mat.print();
406 }
407
408 // We compute the normalization factors based on the fluxes
409 Real norm_factor = NS::FV::computeNormalizationFactor(solution, mat, rhs);
410
411 // We need the non-preconditioned norm to be consistent with the norm factor
412 LibmeshPetscCall(KSPSetNormType(se_solver.ksp(), KSP_NORM_UNPRECONDITIONED));
413
414 // Setting the linear tolerances and maximum iteration counts
417
418 auto its_res_pair = se_solver.solve(mat, mat, solution, rhs);
419 se_system.update();
420
421 if (_print_fields)
422 {
423 _console << " Solid energy rhs " << std::endl;
424 rhs.print();
425 _console << " Solid temperature " << std::endl;
426 solution.print();
427 _console << "Norm factor " << norm_factor << std::endl;
428 }
429
430 _solid_energy_system->setSolution(current_local_solution);
431
432 return std::make_pair(its_res_pair.first, se_solver.get_initial_residual() / norm_factor);
433}
434
435bool
437{
439
440 // Dummy solver parameter file which is needed for switching petsc options
441 SolverParams solver_params;
442 solver_params._type = Moose::SolveType::ST_LINEAR;
443 solver_params._line_search = Moose::LineSearchType::LS_NONE;
444
445 // Initialize the quantities which matter in terms of the iteration
446 unsigned int iteration_counter = 0;
447
448 // Assign residuals to general residual vector
449 unsigned int no_systems =
452 no_systems += _turbulence_systems.size();
453 std::vector<std::pair<unsigned int, Real>> ns_its_residuals(no_systems, std::make_pair(0, 1.0));
454
455 std::vector<Real> ns_abs_tols;
456 ns_abs_tols.reserve(no_systems);
457
458 for (const auto system_i : index_range(_momentum_systems))
459 {
460 const auto abs_tol = _momentum_absolute_tolerance.size() == 1
463 ns_abs_tols.push_back(abs_tol);
464 }
465
466 ns_abs_tols.push_back(_pressure_absolute_tolerance);
468 {
469 ns_abs_tols.push_back(_energy_absolute_tolerance);
471 ns_abs_tols.push_back(_solid_energy_absolute_tolerance);
472 }
474 for (auto system_i : index_range(_turbulence_absolute_tolerance))
475 ns_abs_tols.push_back(_turbulence_absolute_tolerance[system_i]);
476
477 bool converged = false;
478 // Loop until converged or hit the maximum allowed iteration number
479 while (iteration_counter < _num_iterations && !converged)
480 {
481 iteration_counter++;
482 // Resdiual index
483 size_t residual_index = 0;
484
485 // Execute all objects tagged as nonlinear
486 // This will execute everything in the problem at nonlinear, including the aux kernels.
487 // This way we compute the aux kernels before the momentum equations are solved.
489
490 // We clear the caches in the momentum and pressure variables
491 for (auto system_i : index_range(_momentum_systems))
492 _momentum_systems[system_i]->residualSetup();
494
495 // If we solve for energy, we clear the caches there too
497 {
501 }
502
503 // If we solve for turbulence, we clear the caches there too
505 for (auto system_i : index_range(_turbulence_systems))
506 _turbulence_systems[system_i]->residualSetup();
507
508 // We set the preconditioner/controllable parameters through petsc options. Linear
509 // tolerances will be overridden within the solver. In case of a segregated momentum
510 // solver, we assume that every velocity component uses the same preconditioner
512
513 // Solve the momentum predictor step
514 auto momentum_residual = solveMomentumPredictor();
515 for (const auto system_i : index_range(momentum_residual))
516 ns_its_residuals[system_i] = momentum_residual[system_i];
517
518 // Compute the coupling fields between the momentum and pressure equations
520
521 // We set the preconditioner/controllable parameters for the pressure equations through
522 // petsc options. Linear tolerances will be overridden within the solver.
524
525 // Solve the pressure corrector
526 ns_its_residuals[momentum_residual.size()] = solvePressureCorrector();
527 // We need this to make sure we evaluate cell gradients for the nonorthogonal correction in
528 // the face velocity update
530
531 // Compute the face velocity which is used in the advection terms
533
534 auto & pressure_current_solution = *(_pressure_system.system().current_local_solution.get());
535 auto & pressure_old_solution = *(_pressure_system.solutionPreviousNewton());
536 // Relax the pressure update for the next momentum predictor
538 pressure_current_solution, pressure_old_solution, _pressure_variable_relaxation);
539
540 // Overwrite old solution
541 pressure_old_solution = pressure_current_solution;
542 _pressure_system.setSolution(pressure_current_solution);
543
544 // We clear out the caches so that the gradients can be computed with the relaxed solution
546
547 // Reconstruct the cell velocity as well to accelerate convergence
549
550 // Update residual index
551 residual_index = momentum_residual.size();
552
553 // If we have an energy equation, solve it here. We assume the material properties in the
554 // Navier-Stokes equations depend on temperature, therefore we can not solve for temperature
555 // outside of the velocity-pressure loop
557 {
558 // We set the preconditioner/controllable parameters through petsc options. Linear
559 // tolerances will be overridden within the solver.
561 residual_index += 1;
562 ns_its_residuals[residual_index] = solveAdvectedSystem(_energy_sys_number,
567
569 {
570 // We set the preconditioner/controllable parameters through petsc options. Linear
571 // tolerances will be overridden within the solver.
573 residual_index += 1;
574 ns_its_residuals[residual_index] = solveSolidEnergySystem();
575 }
576 }
577
578 // If we have an turbulence equations, we solve it here. We solve it inside the
579 // momentum-pressure loop because it affects the turbulent viscosity
581 {
583
584 for (auto system_i : index_range(_turbulence_systems))
585 {
586 residual_index += 1;
587 ns_its_residuals[residual_index] =
589 *_turbulence_systems[system_i],
593
594 auto & current_solution =
595 *(_turbulence_systems[system_i]->system().current_local_solution.get());
596 NS::FV::limitSolutionUpdate(current_solution, _turbulence_field_min_limit[system_i]);
597
598 // Relax the turbulence update for the next momentum predictor
599 auto & old_solution = *(_turbulence_systems[system_i]->solutionPreviousNewton());
600
601 // Relax the pressure update for the next momentum predictor
603 current_solution, old_solution, _turbulence_equation_relaxation[system_i]);
604
605 // Overwrite old solution
606 old_solution = current_solution;
607 _turbulence_systems[system_i]->setSolution(current_solution);
608
609 // We clear out the caches so that the gradients can be computed with the relaxed solution
610 _turbulence_systems[system_i]->residualSetup();
611 }
612 }
613
614 // Printing residuals
615 residual_index = 0;
616 _console << "Iteration " << iteration_counter << " Initial residual norms:" << std::endl;
617 for (auto system_i : index_range(_momentum_systems))
618 _console << " Momentum equation:"
619 << (_momentum_systems.size() > 1
620 ? std::string(" Component ") + std::to_string(system_i + 1) +
621 std::string(" ")
622 : std::string(" "))
623 << COLOR_GREEN << ns_its_residuals[system_i].second << COLOR_DEFAULT << std::endl;
624 _console << " Pressure equation: " << COLOR_GREEN
625 << ns_its_residuals[momentum_residual.size()].second << COLOR_DEFAULT << std::endl;
626 residual_index = momentum_residual.size();
627
629 {
630 residual_index += 1;
631 _console << " Energy equation: " << COLOR_GREEN << ns_its_residuals[residual_index].second
632 << COLOR_DEFAULT << std::endl;
634 {
635 residual_index += 1;
636 _console << " Solid energy equation: " << COLOR_GREEN
637 << ns_its_residuals[residual_index].second << COLOR_DEFAULT << std::endl;
638 }
639 }
640
642 {
643 _console << "Turbulence Iteration " << std::endl;
644 for (auto system_i : index_range(_turbulence_systems))
645 {
646 residual_index += 1;
647 _console << _turbulence_systems[system_i]->name() << " " << COLOR_GREEN
648 << ns_its_residuals[residual_index].second << COLOR_DEFAULT << std::endl;
649 }
650 }
651
652 converged = NS::FV::converged(ns_its_residuals, ns_abs_tols);
653 }
654
655 converged = _continue_on_max_its ? true : converged;
656
657 // Now we solve for the passive scalar equations, they should not influence the solution of the
658 // system above. The reason why we need more than one iteration is due to the matrix relaxation
659 // which can be used to stabilize the equations
661 {
662 _console << " Passive Scalar Iteration " << iteration_counter << std::endl;
663
664 // We set the options used by Petsc (preconditioners etc). We assume that every passive
665 // scalar equation uses the same options for now.
667
668 iteration_counter = 0;
669 std::vector<std::pair<unsigned int, Real>> passive_scalar_residuals(
670 _passive_scalar_systems.size(), std::make_pair(0, 1.0));
671
672 bool passive_scalar_converged =
673 NS::FV::converged(passive_scalar_residuals, _passive_scalar_absolute_tolerance);
674 while (iteration_counter < _num_iterations && !passive_scalar_converged)
675 {
676 // We clear the caches in the passive scalar variables
677 for (auto system_i : index_range(_passive_scalar_systems))
678 _passive_scalar_systems[system_i]->residualSetup();
679
680 iteration_counter++;
681
682 // Solve the passive scalar equations
683 for (auto system_i : index_range(_passive_scalar_systems))
684 passive_scalar_residuals[system_i] =
686 *_passive_scalar_systems[system_i],
690
691 _console << "Iteration " << iteration_counter << " Initial residual norms:" << std::endl;
692 for (auto system_i : index_range(_passive_scalar_systems))
693 _console << _passive_scalar_systems[system_i]->name() << " " << COLOR_GREEN
694 << passive_scalar_residuals[system_i].second << COLOR_DEFAULT << std::endl;
695
696 passive_scalar_converged =
697 NS::FV::converged(passive_scalar_residuals, _passive_scalar_absolute_tolerance);
698 }
699
700 converged = _continue_on_max_its ? true : passive_scalar_converged;
701 }
702
703 return converged;
704}
705
706void
708{
709 // check to make sure that we don't have any time kernels in this simulation (Steady State)
710 for (const auto system : _momentum_systems)
711 checkTimeKernels(*system);
712
714
716 {
720 }
721
723 for (const auto system : _passive_scalar_systems)
724 checkTimeKernels(*system);
725
727 for (const auto system : _turbulence_systems)
728 checkTimeKernels(*system);
729}
730
731void
733{
734 // check to make sure that we don't have any time kernels in this simulation (Steady State)
735 if (system.containsTimeKernel())
736 mooseError("You have specified time kernels in your steady state simulation in system",
737 system.name());
738}
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.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const std::string & name() const
void paramError(const std::string &param, 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()
const std::vector< Real > _momentum_absolute_tolerance
The user-defined absolute tolerance(s) for determining the convergence in momentum.
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 _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.
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.
FEProblemBase & _problem
Moose::LineSearchType _line_search
Moose::SolveType _type
void setSolution(const NumericVector< Number > &soln)
virtual const NumericVector< Number > * solutionPreviousNewton() const
virtual const std::string & name() const
void set_solver_configuration(SolverConfiguration &solver_configuration)
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
std::unique_ptr< NumericVector< Number > > current_local_solution
void prefix_with_name(bool value)
void petscSetOptions(const PetscOptions &po, const SolverParams &solver_params, FEProblemBase *const problem=nullptr)
void addPetscFlagsToPetscOptions(const MultiMooseEnum &petsc_flags, std::string prefix, const ParallelParamObject &param_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 &param_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...