Skip to content

Commit 26f828c

Browse files
committed
follow
1 parent a829314 commit 26f828c

File tree

8 files changed

+626
-72
lines changed

8 files changed

+626
-72
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Resolved by CMake Tools:
99
"program": "${workspaceFolder}/build/aspect-debug",
1010
// *** replace --test by the name of the .prm file you want to run: ***
11-
"args": ["TwoDSubduction_skip_expensive_stokes.prm"],
11+
"args": ["TwoDSubduction_skip_expensive_stokes_smaller.prm"],
1212
"stopAtEntry": true,
1313
// *** append to the path here if you want to run inside some directory like /cookbooks/ ***
1414
"cwd": "/home/lochy/Softwares/aspect/dtemp",

source/simulator/newton.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ namespace aspect
185185
"true, the derivatives are slowly introduced by the following equation: $\\max(0.0, "
186186
"(1.0-(residual/switch\\_initial\\_residual)))$, where switch\\_initial\\_residual is the "
187187
"residual at the time when the Newton solver is switched on.");
188-
188+
189189
prm.declare_entry ("Maximum linear Stokes solver tolerance", "1e-2",
190190
Patterns::Double (0., 1.),
191191
"The linear Stokes solver tolerance is dynamically chosen for the Newton solver, based "

source/simulator/parameters.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ namespace aspect
283283
"This parameter is only relevant if the `Nonlinear solver scheme' does nonlinear "
284284
"iterations, in other words, if it is set to something other than "
285285
"`single Advection, single Stokes' or `single Advection, no Stokes'.");
286-
287-
// todo_solver
288-
prm.declare_entry ("Continue nonlinear solver loop after linear solver failure", "false",
289-
Patterns::Bool (),
290-
"This method allows to continue nonlinear solver loop after linear solver fails "
291-
"If set to false, the linear solver failure is thrown as normally. When this is "
292-
"set to true, the failure is tolerated and the nonlinear solver continues with "
293-
"the next linear solve.");
286+
287+
// todo_solver
288+
prm.declare_entry ("Continue nonlinear solver loop after linear solver failure", "false",
289+
Patterns::Bool (),
290+
"This method allows to continue nonlinear solver loop after linear solver fails "
291+
"If set to false, the linear solver failure is thrown as normally. When this is "
292+
"set to true, the failure is tolerated and the nonlinear solver continues with "
293+
"the next linear solve.");
294294

295295
prm.declare_entry ("Pressure normalization", "surface",
296296
Patterns::Selection ("surface|volume|no"),

source/simulator/solver.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -910,13 +910,23 @@ namespace aspect
910910
if (parameters.n_expensive_stokes_solver_steps > 0)
911911
solver_controls.push_back(solver_control_expensive);
912912

913-
// Exit with an exception that describes the underlying cause:
914-
Utilities::throw_linear_solver_failure_exception("iterative Stokes solver",
915-
"Simulator::solve_stokes",
916-
solver_controls,
917-
exc,
918-
mpi_communicator,
919-
parameters.output_directory+"solver_history.txt");
913+
//todo_solver
914+
// when linear failure is allowed, we need to have the following steps other than throwing failure
915+
if (parameters.continue_nonlinear_solver_loop_after_linear_solver_failure)
916+
{
917+
pcout << "linear solver failed, but this is allowed and nonlinear solver loop continues (inside solve_stokes())" << std::endl;
918+
}
919+
else
920+
{
921+
922+
// Exit with an exception that describes the underlying cause:
923+
Utilities::throw_linear_solver_failure_exception("iterative Stokes solver",
924+
"Simulator::solve_stokes",
925+
solver_controls,
926+
exc,
927+
mpi_communicator,
928+
parameters.output_directory+"solver_history.txt");
929+
}
920930
}
921931
}
922932

source/simulator/solver/stokes_matrix_free_local_smoothing.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,12 +1522,21 @@ namespace aspect
15221522
if (this->get_parameters().n_expensive_stokes_solver_steps > 0)
15231523
solver_controls.push_back(solver_control_expensive);
15241524

1525-
Utilities::throw_linear_solver_failure_exception("iterative Stokes solver",
1526-
"StokesMatrixFreeHandlerLocalSmoothingImplementation::solve",
1527-
solver_controls,
1528-
exc,
1529-
this->get_mpi_communicator(),
1530-
this->get_parameters().output_directory+"solver_history.txt");
1525+
//todo_solver
1526+
// when linear failure is allowed, we need to have the following steps other than throwing failure
1527+
if (this->get_parameters().continue_nonlinear_solver_loop_after_linear_solver_failure)
1528+
{
1529+
this->get_pcout() << "linear solver failed, but this is allowed and nonlinear solver loop continues (inside StokesMatrixFreeHandlerLocalSmoothingImplementation:solve())" << std::endl;
1530+
}
1531+
else
1532+
{
1533+
Utilities::throw_linear_solver_failure_exception("iterative Stokes solver",
1534+
"StokesMatrixFreeHandlerLocalSmoothingImplementation::solve",
1535+
solver_controls,
1536+
exc,
1537+
this->get_mpi_communicator(),
1538+
this->get_parameters().output_directory+"solver_history.txt");
1539+
}
15311540
}
15321541
}
15331542

source/simulator/solver_schemes.cc

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -683,61 +683,69 @@ namespace aspect
683683
// why that happened:
684684

685685
// todo_solver
686-
687-
// If the exception we got is not one of the two documented by
688-
// throw_linear_solver_failure_exception(), then we have a genuine
689-
// problem here, and will need to get outta here right away:
690-
if ((dynamic_cast<const ExcMessage *>(&exc)==nullptr) &&
691-
(dynamic_cast<const QuietException *>(&exc)==nullptr))
692-
throw;
693-
694-
// Otherwise, the solver presumably failed because the Newton matrix
695-
// is not symmetric or not definite. If we do not actually want to
696-
// handle this case, then again leave:
697-
if (newton_handler->parameters.use_Newton_failsafe == false)
698-
throw;
699-
700-
// Otherwise, start the solve over again and try with a stabilized version:
701-
pcout << "failed, trying again with stabilization" << std::endl;
702-
newton_handler->parameters.preconditioner_stabilization = Newton::Parameters::Stabilization::SPD;
703-
newton_handler->parameters.velocity_block_stabilization = Newton::Parameters::Stabilization::SPD;
704-
705-
// If the Stokes matrix depends on the solution, or we have active
706-
// velocity boundary conditions, we need to re-assemble the system matrix
707-
// (and preconditioner) every time. If we have active boundary conditions,
708-
// they could a) depend on the solution, or b) be inhomogeneous. In both
709-
// cases, just assembling the RHS will be incorrect. If no active
710-
// boundaries exist, we only have no-slip or free slip conditions, so we
711-
// don't need to force assembly of the matrix.
712-
if (stokes_matrix_depends_on_solution()
713-
||
714-
(nonlinear_iteration == 0 && boundary_velocity_manager.get_prescribed_boundary_velocity_indicators().size() > 0))
715-
rebuild_stokes_matrix = rebuild_stokes_preconditioner = assemble_newton_stokes_matrix = true;
716-
else if (parameters.enable_prescribed_dilation)
717-
// The dilation requires the Stokes matrix (which is on the rhs
718-
// in the Newton solver) to be updated.
719-
rebuild_stokes_matrix = true;
720-
721-
assemble_stokes_system();
722-
723-
/**
724-
* Eisenstat Walker method for determining the tolerance
725-
*/
726-
if (nonlinear_iteration > 1)
686+
// question, how the dcr.stokes_residuals got handled if solve_stokes throws some exception
687+
if (parameters.continue_nonlinear_solver_loop_after_linear_solver_failure)
688+
{
689+
pcout << "linear solver failed, but this is allowed and nonlinear solver loop continues" << std::endl;
690+
}
691+
else
727692
{
728-
update_residuals();
729693

730-
// Eisenstat Walker method for determining the linear solver tolerance
731-
if (!use_picard)
694+
// If the exception we got is not one of the two documented by
695+
// throw_linear_solver_failure_exception(), then we have a genuine
696+
// problem here, and will need to get outta here right away:
697+
if ((dynamic_cast<const ExcMessage *>(&exc)==nullptr) &&
698+
(dynamic_cast<const QuietException *>(&exc)==nullptr))
699+
throw;
700+
701+
// Otherwise, the solver presumably failed because the Newton matrix
702+
// is not symmetric or not definite. If we do not actually want to
703+
// handle this case, then again leave:
704+
if (newton_handler->parameters.use_Newton_failsafe == false)
705+
throw;
706+
707+
// Otherwise, start the solve over again and try with a stabilized version:
708+
pcout << "failed, trying again with stabilization" << std::endl;
709+
newton_handler->parameters.preconditioner_stabilization = Newton::Parameters::Stabilization::SPD;
710+
newton_handler->parameters.velocity_block_stabilization = Newton::Parameters::Stabilization::SPD;
711+
712+
// If the Stokes matrix depends on the solution, or we have active
713+
// velocity boundary conditions, we need to re-assemble the system matrix
714+
// (and preconditioner) every time. If we have active boundary conditions,
715+
// they could a) depend on the solution, or b) be inhomogeneous. In both
716+
// cases, just assembling the RHS will be incorrect. If no active
717+
// boundaries exist, we only have no-slip or free slip conditions, so we
718+
// don't need to force assembly of the matrix.
719+
if (stokes_matrix_depends_on_solution()
720+
||
721+
(nonlinear_iteration == 0 && boundary_velocity_manager.get_prescribed_boundary_velocity_indicators().size() > 0))
722+
rebuild_stokes_matrix = rebuild_stokes_preconditioner = assemble_newton_stokes_matrix = true;
723+
else if (parameters.enable_prescribed_dilation)
724+
// The dilation requires the Stokes matrix (which is on the rhs
725+
// in the Newton solver) to be updated.
726+
rebuild_stokes_matrix = true;
727+
728+
assemble_stokes_system();
729+
730+
/**
731+
* Eisenstat Walker method for determining the tolerance
732+
*/
733+
if (nonlinear_iteration > 1)
732734
{
733-
update_Eisenstat_Walker_tolerance();
735+
update_residuals();
736+
737+
// Eisenstat Walker method for determining the linear solver tolerance
738+
if (!use_picard)
739+
{
740+
update_Eisenstat_Walker_tolerance();
741+
}
734742
}
735-
}
736743

737-
build_preconditioner();
744+
build_preconditioner();
738745

739-
// Give this another try:
740-
dcr.stokes_residuals = solve_stokes(search_direction);
746+
// Give this another try:
747+
dcr.stokes_residuals = solve_stokes(search_direction);
748+
}
741749
}
742750

743751
// Apply the solution or the update of the solution

0 commit comments

Comments
 (0)