Skip to content

Commit 14e30a4

Browse files
authored
Merge pull request #6685 from bangerth/wrap-solvers
When solvers fail, make sure we get an exception message only on process zero.
2 parents 53922b5 + e6de8f3 commit 14e30a4

File tree

4 files changed

+85
-14
lines changed

4 files changed

+85
-14
lines changed

source/mesh_deformation/diffusion.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,21 @@ namespace aspect
373373
this->get_pcout() << " Solving mesh surface diffusion" << std::endl;
374374
SolverControl solver_control(5*system_rhs.size(), this->get_parameters().linear_stokes_solver_tolerance*system_rhs.l2_norm());
375375
SolverCG<LinearAlgebra::Vector> cg(solver_control);
376-
cg.solve (matrix, solution, system_rhs, preconditioner_mass);
376+
try
377+
{
378+
cg.solve (matrix, solution, system_rhs, preconditioner_mass);
379+
}
380+
catch (const std::exception &exc)
381+
{
382+
// if the solver fails, report the error from processor 0 with some additional
383+
// information about its location, and throw a quiet exception on all other
384+
// processors
385+
Utilities::throw_linear_solver_failure_exception("iterative diffusion surface deformation solver",
386+
"MeshDeformation::Diffusion::diffuse_boundary()",
387+
std::vector<SolverControl> {solver_control},
388+
exc,
389+
this->get_mpi_communicator());
390+
}
377391

378392
// Distribute constraints on mass matrix
379393
matrix_constraints.distribute (solution);

source/mesh_deformation/free_surface.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,22 @@ namespace aspect
201201

202202
SolverControl solver_control(5*rhs.size(), this->get_parameters().linear_stokes_solver_tolerance*rhs.l2_norm());
203203
SolverCG<LinearAlgebra::Vector> cg(solver_control);
204-
cg.solve (mass_matrix, dist_solution, rhs, preconditioner_mass);
204+
205+
try
206+
{
207+
cg.solve (mass_matrix, dist_solution, rhs, preconditioner_mass);
208+
}
209+
catch (const std::exception &exc)
210+
{
211+
// if the solver fails, report the error from processor 0 with some additional
212+
// information about its location, and throw a quiet exception on all other
213+
// processors
214+
Utilities::throw_linear_solver_failure_exception("iterative free surface solver",
215+
"MeshDeformation::FreeSurface::project_velocity_onto_boundary()",
216+
std::vector<SolverControl> {solver_control},
217+
exc,
218+
this->get_mpi_communicator());
219+
}
205220

206221
mass_matrix_constraints.distribute (dist_solution);
207222
output = dist_solution;

source/mesh_deformation/interface.cc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,22 @@ namespace aspect
946946
SolverControl solver_control(5*rhs.size(), tolerance * rhs.l2_norm());
947947
SolverCG<LinearAlgebra::Vector> cg(solver_control);
948948

949-
cg.solve (mesh_matrix, solution, rhs, preconditioner_stiffness);
950-
this->get_pcout() << " Solving mesh displacement system... " << solver_control.last_step() <<" iterations."<< std::endl;
949+
try
950+
{
951+
cg.solve (mesh_matrix, solution, rhs, preconditioner_stiffness);
952+
this->get_pcout() << " Solving mesh displacement system... " << solver_control.last_step() <<" iterations."<< std::endl;
953+
}
954+
catch (const std::exception &exc)
955+
{
956+
// if the solver fails, report the error from processor 0 with some additional
957+
// information about its location, and throw a quiet exception on all other
958+
// processors
959+
Utilities::throw_linear_solver_failure_exception("iterative mesh displacement solver",
960+
"MeshDeformationHandler::compute_mesh_displacements()",
961+
std::vector<SolverControl> {solver_control},
962+
exc,
963+
this->get_mpi_communicator());
964+
}
951965

952966
mesh_velocity_constraints.distribute (solution);
953967

@@ -1222,8 +1236,23 @@ namespace aspect
12221236
SolverCG<dealii::LinearAlgebra::distributed::Vector<double>> cg(solver_control_mf);
12231237

12241238
mesh_velocity_constraints.set_zero(solution);
1225-
cg.solve(laplace_operator, solution, rhs, preconditioner);
1226-
this->get_pcout() << " Solving mesh displacement system... " << solver_control_mf.last_step() <<" iterations."<< std::endl;
1239+
1240+
try
1241+
{
1242+
cg.solve(laplace_operator, solution, rhs, preconditioner);
1243+
this->get_pcout() << " Solving mesh displacement system... " << solver_control_mf.last_step() <<" iterations."<< std::endl;
1244+
}
1245+
catch (const std::exception &exc)
1246+
{
1247+
// if the solver fails, report the error from processor 0 with some additional
1248+
// information about its location, and throw a quiet exception on all other
1249+
// processors
1250+
Utilities::throw_linear_solver_failure_exception("iterative mesh displacement solver",
1251+
"MeshDeformationHandler::compute_mesh_displacements_gmg()",
1252+
std::vector<SolverControl> {solver_control_mf},
1253+
exc,
1254+
this->get_mpi_communicator());
1255+
}
12271256

12281257
mesh_velocity_constraints.distribute(solution);
12291258
solution.update_ghost_values();

source/simulator/melt.cc

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,18 +1262,31 @@ namespace aspect
12621262
Amg_data.aggregation_threshold = 0.02;
12631263
preconditioner.initialize(system_matrix.block(block_idx, block_idx));
12641264

1265+
this->get_pcout() << " Solving fluid velocity system... " << std::flush;
1266+
12651267
SolverControl solver_control(system_rhs.block(block_idx).size(),
12661268
1e-8*system_rhs.block(block_idx).l2_norm());
12671269
SolverCG<LinearAlgebra::Vector> cg(solver_control);
12681270

1269-
this->get_pcout() << " Solving fluid velocity system... " << std::flush;
1270-
1271-
cg.solve (system_matrix.block(block_idx, block_idx),
1272-
distributed_solution.block(block_idx),
1273-
system_rhs.block(block_idx),
1274-
preconditioner);
1275-
1276-
this->get_pcout() << solver_control.last_step() <<" iterations."<< std::endl;
1271+
try
1272+
{
1273+
cg.solve (system_matrix.block(block_idx, block_idx),
1274+
distributed_solution.block(block_idx),
1275+
system_rhs.block(block_idx),
1276+
preconditioner);
1277+
this->get_pcout() << solver_control.last_step() <<" iterations."<< std::endl;
1278+
}
1279+
catch (const std::exception &exc)
1280+
{
1281+
// if the solver fails, report the error from processor 0 with some additional
1282+
// information about its location, and throw a quiet exception on all other
1283+
// processors
1284+
Utilities::throw_linear_solver_failure_exception("iterative melt solver",
1285+
"MeltHandler::compute_melt_variables",
1286+
std::vector<SolverControl> {solver_control},
1287+
exc,
1288+
this->get_mpi_communicator());
1289+
}
12771290

12781291
this->get_current_constraints().distribute (distributed_solution);
12791292
solution.block(block_idx) = distributed_solution.block(block_idx);

0 commit comments

Comments
 (0)