From 772232c0715ad33977f88482d300f04771c8a9b1 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 6 Feb 2024 13:30:28 -0700 Subject: [PATCH] Convert tutorials to use DEAL_II_ASSERT_UNREACHABLE(). --- examples/step-17/step-17.cc | 2 +- examples/step-34/step-34.cc | 6 ++---- examples/step-35/step-35.cc | 2 +- examples/step-50/step-50.cc | 4 ++-- examples/step-6/doc/results.dox | 15 ++++----------- examples/step-62/step-62.cc | 5 ++--- examples/step-68/step-68.cc | 3 +-- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/examples/step-17/step-17.cc b/examples/step-17/step-17.cc index 8c549b6afe..dbdb7db9d7 100644 --- a/examples/step-17/step-17.cc +++ b/examples/step-17/step-17.cc @@ -913,7 +913,7 @@ namespace Step17 solution_names.emplace_back("z_displacement"); break; default: - Assert(false, ExcInternalError()); + DEAL_II_NOT_IMPLEMENTED(); } data_out.add_data_vector(localized_solution, solution_names); diff --git a/examples/step-34/step-34.cc b/examples/step-34/step-34.cc index de5290dc41..1398bbb350 100644 --- a/examples/step-34/step-34.cc +++ b/examples/step-34/step-34.cc @@ -87,8 +87,7 @@ namespace Step34 return (1. / (R.norm() * 4 * numbers::PI)); default: - Assert(false, ExcInternalError()); - return 0.; + DEAL_II_NOT_IMPLEMENTED(); } } @@ -105,8 +104,7 @@ namespace Step34 return R / (-4 * numbers::PI * R.norm_square() * R.norm()); default: - Assert(false, ExcInternalError()); - return Tensor<1, dim>(); + DEAL_II_NOT_IMPLEMENTED(); } } } // namespace LaplaceKernel diff --git a/examples/step-35/step-35.cc b/examples/step-35/step-35.cc index 7890177a8d..fbafbb4327 100644 --- a/examples/step-35/step-35.cc +++ b/examples/step-35/step-35.cc @@ -1337,7 +1337,7 @@ namespace Step35 loc_vel_dof_indices[joint_fe.system_to_base_index(i).second]); break; default: - Assert(false, ExcInternalError()); + DEAL_II_ASSERT_UNREACHABLE(); } } std::vector joint_solution_names(dim, "v"); diff --git a/examples/step-50/step-50.cc b/examples/step-50/step-50.cc index 2239385f6c..f82e09dd32 100644 --- a/examples/step-50/step-50.cc +++ b/examples/step-50/step-50.cc @@ -1191,7 +1191,7 @@ void LaplaceProblem::solve() } default: - Assert(false, ExcInternalError()); + DEAL_II_ASSERT_UNREACHABLE(); } pcout << " Number of CG iterations: " << solver_control.last_step() @@ -1569,7 +1569,7 @@ int main(int argc, char *argv[]) } default: - Assert(false, ExcMessage("This program only works in 2d and 3d.")); + DEAL_II_NOT_IMPLEMENTED(); } } catch (std::exception &exc) diff --git a/examples/step-6/doc/results.dox b/examples/step-6/doc/results.dox index ed135a8b43..650280da53 100644 --- a/examples/step-6/doc/results.dox +++ b/examples/step-6/doc/results.dox @@ -593,25 +593,18 @@ double coefficient (const Point &p) else if ((p[0] >= 0) && (p[1] >= 0)) // upper right quadrant return 1000; else - { - Assert(false, ExcInternalError()); - return 0; - } + DEAL_II_ASSERT_UNREACHABLE(); } @endcode -(Adding the Assert at the end ensures that either an exception +(Adding the `DEAL_II_ASSERT_UNREACHABLE();` call at the end ensures that either an exception is thrown or that the program aborts if we ever get to that point -- which of course we shouldn't, -but this is a good way to insure yourself: we all make mistakes by +but this is a good way to insure yourself: We all make mistakes by sometimes not thinking of all cases, for example by checking for p[0] to be less than and greater than zero, rather than greater-or-equal to zero, and thereby forgetting some cases that would otherwise lead to bugs that are awkward -to find. The return 0; at the end is only there to -avoid compiler warnings that the function does not end in a -return statement -- the compiler cannot see that the -function would never actually get to that point because of the -preceding Assert statement.) +to find. By playing with such cases where four or more sectors come together and on which the coefficient has different values, one can diff --git a/examples/step-62/step-62.cc b/examples/step-62/step-62.cc index 3a486edbd9..80856be1dd 100644 --- a/examples/step-62/step-62.cc +++ b/examples/step-62/step-62.cc @@ -546,9 +546,8 @@ namespace step62 elastic_constant = mu * (3 * lambda + 2 * mu) / (lambda + mu); } else - { - Assert(false, ExcInternalError()); - } + DEAL_II_NOT_IMPLEMENTED(); + const double material_a_speed_of_sound = std::sqrt(elastic_constant / material_a_rho); const double material_a_wavelength = diff --git a/examples/step-68/step-68.cc b/examples/step-68/step-68.cc index cdb3d99f6f..149892bc5f 100644 --- a/examples/step-68/step-68.cc +++ b/examples/step-68/step-68.cc @@ -323,8 +323,7 @@ namespace Step68 break; default: - Assert(false, ExcInternalError()); - break; + DEAL_II_ASSERT_UNREACHABLE(); } return base_weight + particle_weight * n_particles_in_cell; -- 2.39.5