From: Wolfgang Bangerth Date: Thu, 27 Feb 2025 22:01:05 +0000 (-0700) Subject: Where possible, replace '#ifdef DEBUG' by 'if constexpr(...debug mode...') in tests/. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0260fc0f5ccc2b9b80daf308e5cba0b0a38eb5bf;p=dealii.git Where possible, replace '#ifdef DEBUG' by 'if constexpr(...debug mode...') in tests/. --- diff --git a/tests/adolc/helper_scalar_failure_01.cc b/tests/adolc/helper_scalar_failure_01.cc index b0833e3433..68a4a56f89 100644 --- a/tests/adolc/helper_scalar_failure_01.cc +++ b/tests/adolc/helper_scalar_failure_01.cc @@ -93,13 +93,17 @@ main() initlog(); deal_II_exceptions::disable_abort_on_exception(); -#ifdef DEBUG - // Asserts should be triggered - const bool expected_result = false; -#else - // User beware: Asserts ignored - const bool expected_result = true; -#endif + bool expected_result; + if constexpr (running_in_debug_mode()) + { + // Asserts should be triggered + expected_result = false; + } + else + { + // User beware: Asserts ignored + expected_result = true; + } const unsigned int dim = 2; AssertThrow( diff --git a/tests/adolc/helper_scalar_failure_02.cc b/tests/adolc/helper_scalar_failure_02.cc index e19b136ad1..68b4b57c6c 100644 --- a/tests/adolc/helper_scalar_failure_02.cc +++ b/tests/adolc/helper_scalar_failure_02.cc @@ -95,13 +95,17 @@ main() initlog(); deal_II_exceptions::disable_abort_on_exception(); -#ifdef DEBUG - // Asserts should be triggered - const bool expected_result = false; -#else - // User beware: Asserts ignored - const bool expected_result = true; -#endif + bool expected_result; + if constexpr (running_in_debug_mode()) + { + // Asserts should be triggered + expected_result = false; + } + else + { + // User beware: Asserts ignored + expected_result = true; + } const unsigned int dim = 2; AssertThrow( diff --git a/tests/adolc/helper_scalar_failure_03.cc b/tests/adolc/helper_scalar_failure_03.cc index 19767d78d1..42bbbc2c4f 100644 --- a/tests/adolc/helper_scalar_failure_03.cc +++ b/tests/adolc/helper_scalar_failure_03.cc @@ -96,13 +96,17 @@ main() initlog(); deal_II_exceptions::disable_abort_on_exception(); -#ifdef DEBUG - // Asserts should be triggered - const bool expected_result = false; -#else - // User beware: Asserts ignored - const bool expected_result = true; -#endif + bool expected_result; + if constexpr (running_in_debug_mode()) + { + // Asserts should be triggered + expected_result = false; + } + else + { + // User beware: Asserts ignored + expected_result = true; + } const unsigned int dim = 2; AssertThrow( diff --git a/tests/adolc/helper_scalar_failure_04.cc b/tests/adolc/helper_scalar_failure_04.cc index f874f1df0a..b808efbe0c 100644 --- a/tests/adolc/helper_scalar_failure_04.cc +++ b/tests/adolc/helper_scalar_failure_04.cc @@ -94,15 +94,20 @@ main() initlog(); deal_II_exceptions::disable_abort_on_exception(); -#ifdef DEBUG - // Asserts should be triggered - const bool expected_result_taped = false; - const bool expected_result_tapeless = false; -#else - // User beware: Asserts ignored - const bool expected_result_taped = true; - const bool expected_result_tapeless = false; -#endif + bool expected_result_taped; + bool expected_result_tapeless; + if constexpr (running_in_debug_mode()) + { + // Asserts should be triggered + expected_result_taped = false; + expected_result_tapeless = false; + } + else + { + // User beware: Asserts ignored + expected_result_taped = true; + expected_result_tapeless = false; + } const unsigned int dim = 2; AssertThrow((test_incorrect_no_of_ind_vars void @@ -162,7 +159,6 @@ plot_shape_function(DoFHandler &dof_handler, unsigned int patches = 5) deallog << "...finished plotting shape functions" << std::endl; } -#endif @@ -280,9 +276,7 @@ main(int argc, char **argv) constraints.print(deallog.get_file_stream()); -#ifdef DEBUG - plot_shape_function(dof_handler); -#endif + // plot_shape_function(dof_handler); dof_handler.clear(); return 0; diff --git a/tests/fe/fe_nedelec_sz_hanging_nodes_convergence.cc b/tests/fe/fe_nedelec_sz_hanging_nodes_convergence.cc index 5612038d71..955d9733d2 100644 --- a/tests/fe/fe_nedelec_sz_hanging_nodes_convergence.cc +++ b/tests/fe/fe_nedelec_sz_hanging_nodes_convergence.cc @@ -428,13 +428,9 @@ main() using namespace ConvergenceTest; - const unsigned int refinements = 1; - const unsigned int poly_degree = 2; -#ifdef DEBUG - const unsigned int n_iterations = 2; -#else - const unsigned int n_iterations = 3; -#endif + const unsigned int refinements = 1; + const unsigned int poly_degree = 2; + const unsigned int n_iterations = (running_in_debug_mode ? 2 : 3); MaxwellProblem<2> maxwell_2d(refinements, poly_degree, n_iterations); maxwell_2d.run(); diff --git a/tests/hp/fe_nothing_dominates.h b/tests/hp/fe_nothing_dominates.h index 9b923a5450..b11deb7cbc 100644 --- a/tests/hp/fe_nothing_dominates.h +++ b/tests/hp/fe_nothing_dominates.h @@ -43,13 +43,14 @@ project(const hp::FECollection &fe_collection, const hp::QCollection &q_collection, const Function &function) { -#ifdef DEBUG - Assert(fe_collection.size() == 2, ExcInternalError()); - Assert(q_collection.size() == 2, ExcInternalError()); - for (unsigned int f = 0; f < fe_collection.size(); ++f) - Assert(fe_collection[f].n_components() == function.n_components, - ExcInternalError()); -#endif + if constexpr (running_in_debug_mode()) + { + Assert(fe_collection.size() == 2, ExcInternalError()); + Assert(q_collection.size() == 2, ExcInternalError()); + for (unsigned int f = 0; f < fe_collection.size(); ++f) + Assert(fe_collection[f].n_components() == function.n_components, + ExcInternalError()); + } // setup // +---+---+ diff --git a/tests/hp/limit_p_level_difference_01.cc b/tests/hp/limit_p_level_difference_01.cc index 868bbb8ee8..e9f765ac3f 100644 --- a/tests/hp/limit_p_level_difference_01.cc +++ b/tests/hp/limit_p_level_difference_01.cc @@ -88,19 +88,21 @@ test(const unsigned int fes_size, const unsigned int max_difference) count[cell->active_fe_index()]++; deallog << "fe count:" << count << std::endl; -#ifdef DEBUG - // check each cell's active FE index by its distance from the center - for (const auto &cell : dofh.active_cell_iterators()) + if constexpr (running_in_debug_mode()) { - const double distance = cell->center().distance(center_cell->center()); - const unsigned int expected_level = - (sequence.size() - 1) - - max_difference * static_cast(std::round(distance)); - - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); + // check each cell's active FE index by its distance from the center + for (const auto &cell : dofh.active_cell_iterators()) + { + const double distance = + cell->center().distance(center_cell->center()); + const unsigned int expected_level = + (sequence.size() - 1) - + max_difference * static_cast(std::round(distance)); + + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } } -#endif deallog << "OK" << std::endl; } diff --git a/tests/hp/limit_p_level_difference_02.cc b/tests/hp/limit_p_level_difference_02.cc index 81abc9823b..760fa38637 100644 --- a/tests/hp/limit_p_level_difference_02.cc +++ b/tests/hp/limit_p_level_difference_02.cc @@ -95,19 +95,20 @@ test(const unsigned int fes_size, const unsigned int max_difference) } Assert(center_cell->active_fe_index() == sequence.back(), ExcInternalError()); -#ifdef DEBUG - // check each cell's active FE index by its distance from the center - for (const auto &cell : dofh.active_cell_iterators()) + if constexpr (running_in_debug_mode()) { - const double distance = cell->center().distance(Point()); - const unsigned int expected_level = - (sequence.size() - 1) - - max_difference * static_cast(std::round(distance)); - - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); + // check each cell's active FE index by its distance from the center + for (const auto &cell : dofh.active_cell_iterators()) + { + const double distance = cell->center().distance(Point()); + const unsigned int expected_level = + (sequence.size() - 1) - + max_difference * static_cast(std::round(distance)); + + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } } -#endif deallog << "OK" << std::endl; } diff --git a/tests/hp/limit_p_level_difference_03.cc b/tests/hp/limit_p_level_difference_03.cc index ce75a726bd..1034453e0c 100644 --- a/tests/hp/limit_p_level_difference_03.cc +++ b/tests/hp/limit_p_level_difference_03.cc @@ -98,18 +98,19 @@ test(const unsigned int fes_size, const unsigned int max_difference) (void)fe_indices_changed; Assert(fe_indices_changed, ExcInternalError()); -#ifdef DEBUG - // check each cell's active FE by its h-level - for (unsigned int l = 0; l < tria.n_levels(); ++l) - for (const auto &cell : dofh.cell_iterators_on_level(l)) - if (cell->is_active()) - { - const unsigned int expected_level = std::max( - 0, static_cast(sequence.size() - 1 - l * max_difference)); - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); - } -#endif + if constexpr (running_in_debug_mode()) + { + // check each cell's active FE by its h-level + for (unsigned int l = 0; l < tria.n_levels(); ++l) + for (const auto &cell : dofh.cell_iterators_on_level(l)) + if (cell->is_active()) + { + const unsigned int expected_level = std::max( + 0, static_cast(sequence.size() - 1 - l * max_difference)); + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } + } deallog << "OK" << std::endl; } diff --git a/tests/matrix_free/fe_evaluation_shift.cc b/tests/matrix_free/fe_evaluation_shift.cc index ae41d86066..eda70dac53 100644 --- a/tests/matrix_free/fe_evaluation_shift.cc +++ b/tests/matrix_free/fe_evaluation_shift.cc @@ -137,13 +137,14 @@ namespace dealii else this->data = this->shape_info_base; -#ifdef DEBUG - this->is_reinitialized = true; - this->dof_values_initialized = false; - this->values_quad_initialized = false; - this->gradients_quad_initialized = false; - this->hessians_quad_initialized = false; -#endif + if constexpr (running_in_debug_mode()) + { + this->is_reinitialized = true; + this->dof_values_initialized = false; + this->values_quad_initialized = false; + this->gradients_quad_initialized = false; + this->hessians_quad_initialized = false; + } } template data = this->shape_info_base; -#ifdef DEBUG - this->is_reinitialized = true; - this->dof_values_initialized = false; - this->values_quad_initialized = false; - this->gradients_quad_initialized = false; - this->hessians_quad_initialized = false; -#endif + if constexpr (running_in_debug_mode()) + { + this->is_reinitialized = true; + this->dof_values_initialized = false; + this->values_quad_initialized = false; + this->gradients_quad_initialized = false; + this->hessians_quad_initialized = false; + } } } // namespace dealii diff --git a/tests/mpi/hp_cell_weights_01.cc b/tests/mpi/hp_cell_weights_01.cc index 885c609732..f7dfcb026d 100644 --- a/tests/mpi/hp_cell_weights_01.cc +++ b/tests/mpi/hp_cell_weights_01.cc @@ -90,27 +90,30 @@ test() deallog << " Cumulative dofs per cell: " << dof_counter << std::endl; } -#ifdef DEBUG - parallel::distributed::Triangulation other_tria(MPI_COMM_WORLD); - GridGenerator::hyper_cube(other_tria); - other_tria.refine_global(2); - - dh.reinit(other_tria); - dh.distribute_dofs(fe_collection); - - try + if constexpr (running_in_debug_mode()) { - tria.repartition(); + parallel::distributed::Triangulation other_tria(MPI_COMM_WORLD); + GridGenerator::hyper_cube(other_tria); + other_tria.refine_global(2); + + dh.reinit(other_tria); + dh.distribute_dofs(fe_collection); + + try + { + tria.repartition(); + } + catch (const ExceptionBase &e) + { + deallog << e.get_exc_name() << std::endl; + } } - catch (const ExceptionBase &e) + else { - deallog << e.get_exc_name() << std::endl; + deallog + << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" + << std::endl; } -#else - deallog - << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" - << std::endl; -#endif // make sure no processor is hanging MPI_Barrier(MPI_COMM_WORLD); diff --git a/tests/mpi/hp_cell_weights_02.cc b/tests/mpi/hp_cell_weights_02.cc index f3b5912773..a725ce9a72 100644 --- a/tests/mpi/hp_cell_weights_02.cc +++ b/tests/mpi/hp_cell_weights_02.cc @@ -96,27 +96,30 @@ test() deallog << " Cumulative dofs per cell: " << dof_counter << std::endl; } -#ifdef DEBUG - parallel::distributed::Triangulation other_tria(MPI_COMM_WORLD); - GridGenerator::hyper_cube(other_tria); - other_tria.refine_global(3); - - dh.reinit(other_tria); - dh.distribute_dofs(fe_collection); - - try + if constexpr (running_in_debug_mode()) { - tria.repartition(); + parallel::distributed::Triangulation other_tria(MPI_COMM_WORLD); + GridGenerator::hyper_cube(other_tria); + other_tria.refine_global(3); + + dh.reinit(other_tria); + dh.distribute_dofs(fe_collection); + + try + { + tria.repartition(); + } + catch (const ExceptionBase &e) + { + deallog << e.get_exc_name() << std::endl; + } } - catch (const ExceptionBase &e) + else { - deallog << e.get_exc_name() << std::endl; + deallog + << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" + << std::endl; } -#else - deallog - << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" - << std::endl; -#endif // make sure no processor is hanging MPI_Barrier(MPI_COMM_WORLD); diff --git a/tests/mpi/hp_cell_weights_03.cc b/tests/mpi/hp_cell_weights_03.cc index df5768bc70..02223e2759 100644 --- a/tests/mpi/hp_cell_weights_03.cc +++ b/tests/mpi/hp_cell_weights_03.cc @@ -97,34 +97,37 @@ test() deallog << " Cumulative dofs per cell: " << dof_counter << std::endl; } -#ifdef DEBUG - parallel::shared::Triangulation other_tria( - MPI_COMM_WORLD, - ::Triangulation::none, - false, - parallel::shared::Triangulation::Settings::partition_metis); - GridGenerator::hyper_cube(other_tria); - other_tria.refine_global(3); - - dh.reinit(other_tria); - dh.distribute_dofs(fe_collection); - - try + if constexpr (running_in_debug_mode()) { - tria.execute_coarsening_and_refinement(); - deallog << "Error: we did not throw an exception when we should have" - << std::endl; - std::abort(); + parallel::shared::Triangulation other_tria( + MPI_COMM_WORLD, + ::Triangulation::none, + false, + parallel::shared::Triangulation::Settings::partition_metis); + GridGenerator::hyper_cube(other_tria); + other_tria.refine_global(3); + + dh.reinit(other_tria); + dh.distribute_dofs(fe_collection); + + try + { + tria.execute_coarsening_and_refinement(); + deallog << "Error: we did not throw an exception when we should have" + << std::endl; + std::abort(); + } + catch (const ExceptionBase &e) + { + deallog << e.get_exc_name() << std::endl; + } } - catch (const ExceptionBase &e) + else { - deallog << e.get_exc_name() << std::endl; + deallog + << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" + << std::endl; } -#else - deallog - << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" - << std::endl; -#endif // make sure no processor is hanging MPI_Barrier(MPI_COMM_WORLD); diff --git a/tests/mpi/hp_cell_weights_04.cc b/tests/mpi/hp_cell_weights_04.cc index 7161e8f12b..228c0c0e23 100644 --- a/tests/mpi/hp_cell_weights_04.cc +++ b/tests/mpi/hp_cell_weights_04.cc @@ -99,34 +99,37 @@ test() deallog << " Cumulative dofs per cell: " << dof_counter << std::endl; } -#ifdef DEBUG - parallel::shared::Triangulation other_tria( - MPI_COMM_WORLD, - ::Triangulation::none, - false, - parallel::shared::Triangulation::Settings::partition_metis); - GridGenerator::hyper_cube(other_tria); - other_tria.refine_global(3); - - dh.reinit(other_tria); - dh.distribute_dofs(fe_collection); - - try + if constexpr (running_in_debug_mode()) { - tria.execute_coarsening_and_refinement(); - deallog << "Error: we did not throw an exception when we should have" - << std::endl; - std::abort(); + parallel::shared::Triangulation other_tria( + MPI_COMM_WORLD, + ::Triangulation::none, + false, + parallel::shared::Triangulation::Settings::partition_metis); + GridGenerator::hyper_cube(other_tria); + other_tria.refine_global(3); + + dh.reinit(other_tria); + dh.distribute_dofs(fe_collection); + + try + { + tria.execute_coarsening_and_refinement(); + deallog << "Error: we did not throw an exception when we should have" + << std::endl; + std::abort(); + } + catch (const ExceptionBase &e) + { + deallog << e.get_exc_name() << std::endl; + } } - catch (const ExceptionBase &e) + else { - deallog << e.get_exc_name() << std::endl; + deallog + << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" + << std::endl; } -#else - deallog - << "ExcMessage(\"Triangulation associated with the DoFHandler has changed!\")" - << std::endl; -#endif // make sure no processor is hanging MPI_Barrier(MPI_COMM_WORLD); diff --git a/tests/mpi/hp_constraints_consistent_01.cc b/tests/mpi/hp_constraints_consistent_01.cc index 00e1054dfc..cb1024ba91 100644 --- a/tests/mpi/hp_constraints_consistent_01.cc +++ b/tests/mpi/hp_constraints_consistent_01.cc @@ -86,16 +86,17 @@ test(const unsigned int degree_center, // set different FE on center cell cell->set_active_fe_index(1); -#ifdef DEBUG - // verify that our scenario is initialized correctly - // by checking the number of neighbors of the center cell - unsigned int n_neighbors = 0; - for (const unsigned int i : GeometryInfo::face_indices()) - if (static_cast(cell->neighbor_index(i)) != - numbers::invalid_unsigned_int) - ++n_neighbors; - Assert(n_neighbors == 3, ExcInternalError()); -#endif + if constexpr (running_in_debug_mode()) + { + // verify that our scenario is initialized correctly + // by checking the number of neighbors of the center cell + unsigned int n_neighbors = 0; + for (const unsigned int i : GeometryInfo::face_indices()) + if (static_cast(cell->neighbor_index(i)) != + numbers::invalid_unsigned_int) + ++n_neighbors; + Assert(n_neighbors == 3, ExcInternalError()); + } } dh.distribute_dofs(fe_collection); diff --git a/tests/mpi/hp_constraints_consistent_02.cc b/tests/mpi/hp_constraints_consistent_02.cc index ebaaf0af78..190cbba94e 100644 --- a/tests/mpi/hp_constraints_consistent_02.cc +++ b/tests/mpi/hp_constraints_consistent_02.cc @@ -86,16 +86,17 @@ test(const unsigned int degree_center, // set different FE on center cell cell->set_active_fe_index(1); -#ifdef DEBUG - // verify that our scenario is initialized correctly - // by checking the number of neighbors of the center cell - unsigned int n_neighbors = 0; - for (const unsigned int i : GeometryInfo::face_indices()) - if (static_cast(cell->neighbor_index(i)) != - numbers::invalid_unsigned_int) - ++n_neighbors; - Assert(n_neighbors == 3, ExcInternalError()); -#endif + if constexpr (running_in_debug_mode()) + { + // verify that our scenario is initialized correctly + // by checking the number of neighbors of the center cell + unsigned int n_neighbors = 0; + for (const unsigned int i : GeometryInfo::face_indices()) + if (static_cast(cell->neighbor_index(i)) != + numbers::invalid_unsigned_int) + ++n_neighbors; + Assert(n_neighbors == 3, ExcInternalError()); + } } dh.distribute_dofs(fe_collection); diff --git a/tests/mpi/hp_constraints_consistent_03.cc b/tests/mpi/hp_constraints_consistent_03.cc index bd3bb60865..8cbc8939fa 100644 --- a/tests/mpi/hp_constraints_consistent_03.cc +++ b/tests/mpi/hp_constraints_consistent_03.cc @@ -89,16 +89,17 @@ test(const unsigned int degree_center, // set different FE on center cell cell->set_active_fe_index(1); -#ifdef DEBUG - // verify that our scenario is initialized correctly - // by checking the number of neighbors of the center cell - unsigned int n_neighbors = 0; - for (const unsigned int i : GeometryInfo::face_indices()) - if (static_cast(cell->neighbor_index(i)) != - numbers::invalid_unsigned_int) - ++n_neighbors; - Assert(n_neighbors == 3, ExcInternalError()); -#endif + if constexpr (running_in_debug_mode()) + { + // verify that our scenario is initialized correctly + // by checking the number of neighbors of the center cell + unsigned int n_neighbors = 0; + for (const unsigned int i : GeometryInfo::face_indices()) + if (static_cast(cell->neighbor_index(i)) != + numbers::invalid_unsigned_int) + ++n_neighbors; + Assert(n_neighbors == 3, ExcInternalError()); + } } else if (cell->id().to_string() == "0_0:") { diff --git a/tests/mpi/hp_step-4.cc b/tests/mpi/hp_step-4.cc index 5107070da0..77a0dc4069 100644 --- a/tests/mpi/hp_step-4.cc +++ b/tests/mpi/hp_step-4.cc @@ -197,23 +197,25 @@ namespace Step4 DoFTools::make_zero_boundary_constraints(dof_handler, constraints); -#ifdef DEBUG - // We did not think about hp-constraints on ghost cells yet. - // Thus, we are content with verifying their consistency for now. - const std::vector locally_owned_dofs_per_processor = - Utilities::MPI::all_gather(communicator, - dof_handler.locally_owned_dofs()); - - const IndexSet locally_active_dofs = - DoFTools::extract_locally_active_dofs(dof_handler); - - AssertThrow( - constraints.is_consistent_in_parallel(locally_owned_dofs_per_processor, - locally_active_dofs, - communicator, - /*verbose=*/true), - ExcMessage("AffineConstraints object contains inconsistencies!")); -#endif + if constexpr (running_in_debug_mode()) + { + // We did not think about hp-constraints on ghost cells yet. + // Thus, we are content with verifying their consistency for now. + const std::vector locally_owned_dofs_per_processor = + Utilities::MPI::all_gather(communicator, + dof_handler.locally_owned_dofs()); + + const IndexSet locally_active_dofs = + DoFTools::extract_locally_active_dofs(dof_handler); + + AssertThrow(constraints.is_consistent_in_parallel( + locally_owned_dofs_per_processor, + locally_active_dofs, + communicator, + /*verbose=*/true), + ExcMessage( + "AffineConstraints object contains inconsistencies!")); + } constraints.close(); diff --git a/tests/mpi/limit_p_level_difference_01.cc b/tests/mpi/limit_p_level_difference_01.cc index 51b5395a2c..1271697863 100644 --- a/tests/mpi/limit_p_level_difference_01.cc +++ b/tests/mpi/limit_p_level_difference_01.cc @@ -99,20 +99,21 @@ test(const unsigned int fes_size, const unsigned int max_difference) Utilities::MPI::sum(count, tria.get_mpi_communicator(), count); deallog << "fe count:" << count << std::endl; -#ifdef DEBUG - // check each cell's active FE index by its distance from the center - for (const auto &cell : - dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + if constexpr (running_in_debug_mode()) { - const double distance = cell->center().distance(Point()); - const unsigned int expected_level = - (sequence.size() - 1) - - max_difference * static_cast(std::round(distance)); - - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); + // check each cell's active FE index by its distance from the center + for (const auto &cell : + dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + { + const double distance = cell->center().distance(Point()); + const unsigned int expected_level = + (sequence.size() - 1) - + max_difference * static_cast(std::round(distance)); + + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } } -#endif deallog << "OK" << std::endl; } diff --git a/tests/mpi/limit_p_level_difference_02.cc b/tests/mpi/limit_p_level_difference_02.cc index 6d73219363..3223ad955c 100644 --- a/tests/mpi/limit_p_level_difference_02.cc +++ b/tests/mpi/limit_p_level_difference_02.cc @@ -106,20 +106,21 @@ test(const unsigned int fes_size, const unsigned int max_difference) deallog << "cycle:" << i << ", fe count:" << count << std::endl; } -#ifdef DEBUG - // check each cell's active FE index by its distance from the center - for (const auto &cell : - dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + if constexpr (running_in_debug_mode()) { - const double distance = cell->center().distance(Point()); - const unsigned int expected_level = - (sequence.size() - 1) - - max_difference * static_cast(std::round(distance)); - - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); + // check each cell's active FE index by its distance from the center + for (const auto &cell : + dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + { + const double distance = cell->center().distance(Point()); + const unsigned int expected_level = + (sequence.size() - 1) - + max_difference * static_cast(std::round(distance)); + + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } } -#endif deallog << "OK" << std::endl; } diff --git a/tests/mpi/limit_p_level_difference_03.cc b/tests/mpi/limit_p_level_difference_03.cc index 0a6c774c35..416857a4f8 100644 --- a/tests/mpi/limit_p_level_difference_03.cc +++ b/tests/mpi/limit_p_level_difference_03.cc @@ -105,18 +105,19 @@ test(const unsigned int fes_size, const unsigned int max_difference) Assert(fe_indices_changed, ExcInternalError()); -#ifdef DEBUG - // check each cell's active FE by its h-level - for (unsigned int l = 0; l < tria.n_global_levels(); ++l) - for (const auto &cell : dofh.cell_iterators_on_level(l)) - if (cell->is_active() && cell->is_locally_owned()) - { - const unsigned int expected_level = std::max( - 0, static_cast(sequence.size() - 1 - l * max_difference)); - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); - } -#endif + if constexpr (running_in_debug_mode()) + { + // check each cell's active FE by its h-level + for (unsigned int l = 0; l < tria.n_global_levels(); ++l) + for (const auto &cell : dofh.cell_iterators_on_level(l)) + if (cell->is_active() && cell->is_locally_owned()) + { + const unsigned int expected_level = std::max( + 0, static_cast(sequence.size() - 1 - l * max_difference)); + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } + } deallog << "OK" << std::endl; } diff --git a/tests/mpi/petsc_step-27.cc b/tests/mpi/petsc_step-27.cc index 84287c7242..6ac9b94e08 100644 --- a/tests/mpi/petsc_step-27.cc +++ b/tests/mpi/petsc_step-27.cc @@ -222,23 +222,25 @@ namespace Step27 0, Functions::ZeroFunction(), constraints); -#ifdef DEBUG - // We have not dealt with chains of constraints on ghost cells yet. - // Thus, we are content with verifying their consistency for now. - std::vector locally_owned_dofs_per_processor = - Utilities::MPI::all_gather(dof_handler.get_mpi_communicator(), - dof_handler.locally_owned_dofs()); - - const IndexSet locally_active_dofs = - DoFTools::extract_locally_active_dofs(dof_handler); - - AssertThrow( - constraints.is_consistent_in_parallel(locally_owned_dofs_per_processor, - locally_active_dofs, - mpi_communicator, - /*verbose=*/true), - ExcMessage("AffineConstraints object contains inconsistencies!")); -#endif + if constexpr (running_in_debug_mode()) + { + // We have not dealt with chains of constraints on ghost cells yet. + // Thus, we are content with verifying their consistency for now. + std::vector locally_owned_dofs_per_processor = + Utilities::MPI::all_gather(dof_handler.get_mpi_communicator(), + dof_handler.locally_owned_dofs()); + + const IndexSet locally_active_dofs = + DoFTools::extract_locally_active_dofs(dof_handler); + + AssertThrow(constraints.is_consistent_in_parallel( + locally_owned_dofs_per_processor, + locally_active_dofs, + mpi_communicator, + /*verbose=*/true), + ExcMessage( + "AffineConstraints object contains inconsistencies!")); + } constraints.close(); DynamicSparsityPattern dsp(locally_relevant_dofs); diff --git a/tests/mpi/trilinos_step-27.cc b/tests/mpi/trilinos_step-27.cc index 6e08c65868..fb96ee86b3 100644 --- a/tests/mpi/trilinos_step-27.cc +++ b/tests/mpi/trilinos_step-27.cc @@ -226,23 +226,25 @@ namespace Step27 0, Functions::ZeroFunction(), constraints); -#ifdef DEBUG - // We did not think about hp-constraints on ghost cells yet. - // Thus, we are content with verifying their consistency for now. - std::vector locally_owned_dofs_per_processor = - Utilities::MPI::all_gather(dof_handler.get_mpi_communicator(), - dof_handler.locally_owned_dofs()); - - const IndexSet locally_active_dofs = - DoFTools::extract_locally_active_dofs(dof_handler); - - AssertThrow( - constraints.is_consistent_in_parallel(locally_owned_dofs_per_processor, - locally_active_dofs, - mpi_communicator, - /*verbose=*/true), - ExcMessage("AffineConstraints object contains inconsistencies!")); -#endif + if constexpr (running_in_debug_mode()) + { + // We did not think about hp-constraints on ghost cells yet. + // Thus, we are content with verifying their consistency for now. + std::vector locally_owned_dofs_per_processor = + Utilities::MPI::all_gather(dof_handler.get_mpi_communicator(), + dof_handler.locally_owned_dofs()); + + const IndexSet locally_active_dofs = + DoFTools::extract_locally_active_dofs(dof_handler); + + AssertThrow(constraints.is_consistent_in_parallel( + locally_owned_dofs_per_processor, + locally_active_dofs, + mpi_communicator, + /*verbose=*/true), + ExcMessage( + "AffineConstraints object contains inconsistencies!")); + } constraints.close(); DynamicSparsityPattern dsp(locally_relevant_dofs); diff --git a/tests/sharedtria/limit_p_level_difference_01.cc b/tests/sharedtria/limit_p_level_difference_01.cc index aa45fa3442..85b382b8f8 100644 --- a/tests/sharedtria/limit_p_level_difference_01.cc +++ b/tests/sharedtria/limit_p_level_difference_01.cc @@ -96,20 +96,21 @@ test(const unsigned int fes_size, Utilities::MPI::sum(count, tria.get_mpi_communicator(), count); deallog << "fe count:" << count << std::endl; -#ifdef DEBUG - // check each cell's active FE index by its distance from the center - for (const auto &cell : - dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + if constexpr (running_in_debug_mode()) { - const double distance = cell->center().distance(Point()); - const unsigned int expected_level = - (sequence.size() - 1) - - max_difference * static_cast(std::round(distance)); - - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); + // check each cell's active FE index by its distance from the center + for (const auto &cell : + dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + { + const double distance = cell->center().distance(Point()); + const unsigned int expected_level = + (sequence.size() - 1) - + max_difference * static_cast(std::round(distance)); + + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } } -#endif deallog << "OK" << std::endl; } diff --git a/tests/sharedtria/limit_p_level_difference_02.cc b/tests/sharedtria/limit_p_level_difference_02.cc index fc7093df88..7bb7406808 100644 --- a/tests/sharedtria/limit_p_level_difference_02.cc +++ b/tests/sharedtria/limit_p_level_difference_02.cc @@ -102,20 +102,21 @@ test(const unsigned int fes_size, deallog << "cycle:" << i << ", fe count:" << count << std::endl; } -#ifdef DEBUG - // check each cell's active FE index by its distance from the center - for (const auto &cell : - dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + if constexpr (running_in_debug_mode()) { - const double distance = cell->center().distance(Point()); - const unsigned int expected_level = - (sequence.size() - 1) - - max_difference * static_cast(std::round(distance)); - - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); + // check each cell's active FE index by its distance from the center + for (const auto &cell : + dofh.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) + { + const double distance = cell->center().distance(Point()); + const unsigned int expected_level = + (sequence.size() - 1) - + max_difference * static_cast(std::round(distance)); + + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } } -#endif deallog << "OK" << std::endl; } diff --git a/tests/sharedtria/limit_p_level_difference_03.cc b/tests/sharedtria/limit_p_level_difference_03.cc index 5b44bfcd09..14fc78599a 100644 --- a/tests/sharedtria/limit_p_level_difference_03.cc +++ b/tests/sharedtria/limit_p_level_difference_03.cc @@ -104,18 +104,19 @@ test(const unsigned int fes_size, (void)fe_indices_changed; Assert(fe_indices_changed, ExcInternalError()); -#ifdef DEBUG - // check each cell's active FE by its h-level - for (unsigned int l = 0; l < tria.n_global_levels(); ++l) - for (const auto &cell : dofh.cell_iterators_on_level(l)) - if (cell->is_active() && cell->is_locally_owned()) - { - const unsigned int expected_level = std::max( - 0, static_cast(sequence.size() - 1 - l * max_difference)); - Assert(cell->active_fe_index() == sequence[expected_level], - ExcInternalError()); - } -#endif + if constexpr (running_in_debug_mode()) + { + // check each cell's active FE by its h-level + for (unsigned int l = 0; l < tria.n_global_levels(); ++l) + for (const auto &cell : dofh.cell_iterators_on_level(l)) + if (cell->is_active() && cell->is_locally_owned()) + { + const unsigned int expected_level = std::max( + 0, static_cast(sequence.size() - 1 - l * max_difference)); + Assert(cell->active_fe_index() == sequence[expected_level], + ExcInternalError()); + } + } deallog << "OK" << std::endl; } diff --git a/tests/simplex/hanging_nodes.h b/tests/simplex/hanging_nodes.h index 6c51256605..5dc4fa961d 100644 --- a/tests/simplex/hanging_nodes.h +++ b/tests/simplex/hanging_nodes.h @@ -68,14 +68,15 @@ refine(const std::vector &n_refinements, Triangulation &tria) tria.execute_coarsening_and_refinement(); } -#ifdef DEBUG - for (const auto &cell : tria.active_cell_iterators()) + if constexpr (running_in_debug_mode()) { - const unsigned int coarse_cell_id = cell->id().get_coarse_cell_id(); + for (const auto &cell : tria.active_cell_iterators()) + { + const unsigned int coarse_cell_id = cell->id().get_coarse_cell_id(); - AssertDimension(cell->level(), n_refinements[coarse_cell_id]); + AssertDimension(cell->level(), n_refinements[coarse_cell_id]); + } } -#endif } diff --git a/tests/simplex/simplex_grids.h b/tests/simplex/simplex_grids.h index 5947c9a0a6..fdbd55341d 100644 --- a/tests/simplex/simplex_grids.h +++ b/tests/simplex/simplex_grids.h @@ -412,11 +412,13 @@ namespace dealii // add simplex cell in coordinate direction const unsigned int coordinate = face_no / 2; -#ifdef DEBUG - // all vertices should be in a plane - for (const auto &vertex : vertices) - Assert(midpoint[coordinate] == vertex[coordinate], ExcInternalError()); -#endif + if constexpr (running_in_debug_mode()) + { + // all vertices should be in a plane + for (const auto &vertex : vertices) + Assert(midpoint[coordinate] == vertex[coordinate], + ExcInternalError()); + } // add another vertex as tip of triangle/pyramid Point tip = midpoint; diff --git a/tests/symengine/substitution_maps_scalar_01.cc b/tests/symengine/substitution_maps_scalar_01.cc index 3ffd37b6a8..cae021c05a 100644 --- a/tests/symengine/substitution_maps_scalar_01.cc +++ b/tests/symengine/substitution_maps_scalar_01.cc @@ -67,20 +67,23 @@ main() SD::Utilities::print_substitution_map(deallog, substitution_map); -#ifdef DEBUG - // Check that exceptions are raised when duplicate symbols - // are found in a substitution map - deal_II_exceptions::disable_abort_on_exception(); - try + if constexpr (running_in_debug_mode()) { - SD::add_to_substitution_map(substitution_map, - std::make_pair(SD::Expression("x14"), 14)); + // Check that exceptions are raised when duplicate symbols + // are found in a substitution map + deal_II_exceptions::disable_abort_on_exception(); + try + { + SD::add_to_substitution_map(substitution_map, + std::make_pair(SD::Expression("x14"), + 14)); - deallog << "Duplicate symbol in map did not raise an error." << std::endl; + deallog << "Duplicate symbol in map did not raise an error." + << std::endl; + } + catch (const ExcMessage &) + {} } - catch (const ExcMessage &) - {} -#endif deallog << "OK" << std::endl; } diff --git a/tests/symengine/substitution_maps_scalar_02.cc b/tests/symengine/substitution_maps_scalar_02.cc index 0ce8b780a2..598329c735 100644 --- a/tests/symengine/substitution_maps_scalar_02.cc +++ b/tests/symengine/substitution_maps_scalar_02.cc @@ -125,33 +125,34 @@ main() SD::merge_substitution_maps(substitution_map, substitution_map_1); } -#ifdef DEBUG - // Check that exceptions are raised when duplicate symbols - // associated with unequal values are found in a substitution map - deal_II_exceptions::disable_abort_on_exception(); - try + if constexpr (running_in_debug_mode()) { - { - SD::types::substitution_map substitution_map; - SD::add_to_substitution_map(substitution_map, - SD::Expression("x1"), - SD::Expression(1)); - - SD::types::substitution_map substitution_map_1; - SD::add_to_substitution_map(substitution_map_1, - SD::Expression("x1"), - SD::Expression(2)); - - SD::merge_substitution_maps(substitution_map, substitution_map_1); - } - - deallog - << "Duplicate symbol with non-equal value in map did not raise an error." - << std::endl; + // Check that exceptions are raised when duplicate symbols + // associated with unequal values are found in a substitution map + deal_II_exceptions::disable_abort_on_exception(); + try + { + { + SD::types::substitution_map substitution_map; + SD::add_to_substitution_map(substitution_map, + SD::Expression("x1"), + SD::Expression(1)); + + SD::types::substitution_map substitution_map_1; + SD::add_to_substitution_map(substitution_map_1, + SD::Expression("x1"), + SD::Expression(2)); + + SD::merge_substitution_maps(substitution_map, substitution_map_1); + } + + deallog + << "Duplicate symbol with non-equal value in map did not raise an error." + << std::endl; + } + catch (const ExcMessage &) + {} } - catch (const ExcMessage &) - {} -#endif deallog << "OK" << std::endl; } diff --git a/tests/symengine/symengine_tensor_operations_03.cc b/tests/symengine/symengine_tensor_operations_03.cc index d12d0d560e..f095497ff4 100644 --- a/tests/symengine/symengine_tensor_operations_03.cc +++ b/tests/symengine/symengine_tensor_operations_03.cc @@ -506,39 +506,40 @@ test_symmetric_tensor_tensor_vector_scalar_coupled( symb_d2psi_ds_x_dv = SD::differentiate(symb_dpsi_ds, symb_v); symb_d2psi_ds_x_ds = SD::differentiate(symb_dpsi_ds, symb_s); -#ifdef DEBUG - print(std::cout, "symb_st", symb_st); - print(std::cout, "symb_t", symb_t); - print(std::cout, "symb_v", symb_v); - print(std::cout, "symb_s", symb_s); - - print(std::cout, "symb_psi", symb_psi); - - print(std::cout, "symb_dpsi_dst", symb_dpsi_dst); - print(std::cout, "symb_dpsi_dt", symb_dpsi_dt); - print(std::cout, "symb_dpsi_dv", symb_dpsi_dv); - print(std::cout, "symb_dpsi_ds", symb_dpsi_ds); - - print(std::cout, "symb_d2psi_dst_x_dst", symb_d2psi_dst_x_dst); - print(std::cout, "symb_d2psi_dst_x_dt", symb_d2psi_dst_x_dt); - print(std::cout, "symb_d2psi_dst_x_dv", symb_d2psi_dst_x_dv); - print(std::cout, "symb_d2psi_dst_x_ds", symb_d2psi_dst_x_ds); - - print(std::cout, "symb_d2psi_dt_x_dst", symb_d2psi_dt_x_dst); - print(std::cout, "symb_d2psi_dt_x_dt", symb_d2psi_dt_x_dt); - print(std::cout, "symb_d2psi_dt_x_dv", symb_d2psi_dt_x_dv); - print(std::cout, "symb_d2psi_dt_x_ds", symb_d2psi_dt_x_ds); - - print(std::cout, "symb_d2psi_dv_x_dst", symb_d2psi_dv_x_dst); - print(std::cout, "symb_d2psi_dv_x_dt", symb_d2psi_dv_x_dt); - print(std::cout, "symb_d2psi_dv_x_dv", symb_d2psi_dv_x_dv); - print(std::cout, "symb_d2psi_dv_x_ds", symb_d2psi_dv_x_ds); - - print(std::cout, "symb_d2psi_ds_x_dst", symb_d2psi_ds_x_dst); - print(std::cout, "symb_d2psi_ds_x_dt", symb_d2psi_ds_x_dt); - print(std::cout, "symb_d2psi_ds_x_dv", symb_d2psi_ds_x_dv); - print(std::cout, "symb_d2psi_ds_x_ds", symb_d2psi_ds_x_ds); -#endif + if constexpr (running_in_debug_mode()) + { + print(std::cout, "symb_st", symb_st); + print(std::cout, "symb_t", symb_t); + print(std::cout, "symb_v", symb_v); + print(std::cout, "symb_s", symb_s); + + print(std::cout, "symb_psi", symb_psi); + + print(std::cout, "symb_dpsi_dst", symb_dpsi_dst); + print(std::cout, "symb_dpsi_dt", symb_dpsi_dt); + print(std::cout, "symb_dpsi_dv", symb_dpsi_dv); + print(std::cout, "symb_dpsi_ds", symb_dpsi_ds); + + print(std::cout, "symb_d2psi_dst_x_dst", symb_d2psi_dst_x_dst); + print(std::cout, "symb_d2psi_dst_x_dt", symb_d2psi_dst_x_dt); + print(std::cout, "symb_d2psi_dst_x_dv", symb_d2psi_dst_x_dv); + print(std::cout, "symb_d2psi_dst_x_ds", symb_d2psi_dst_x_ds); + + print(std::cout, "symb_d2psi_dt_x_dst", symb_d2psi_dt_x_dst); + print(std::cout, "symb_d2psi_dt_x_dt", symb_d2psi_dt_x_dt); + print(std::cout, "symb_d2psi_dt_x_dv", symb_d2psi_dt_x_dv); + print(std::cout, "symb_d2psi_dt_x_ds", symb_d2psi_dt_x_ds); + + print(std::cout, "symb_d2psi_dv_x_dst", symb_d2psi_dv_x_dst); + print(std::cout, "symb_d2psi_dv_x_dt", symb_d2psi_dv_x_dt); + print(std::cout, "symb_d2psi_dv_x_dv", symb_d2psi_dv_x_dv); + print(std::cout, "symb_d2psi_dv_x_ds", symb_d2psi_dv_x_ds); + + print(std::cout, "symb_d2psi_ds_x_dst", symb_d2psi_ds_x_dst); + print(std::cout, "symb_d2psi_ds_x_dt", symb_d2psi_ds_x_dt); + print(std::cout, "symb_d2psi_ds_x_dv", symb_d2psi_ds_x_dv); + print(std::cout, "symb_d2psi_ds_x_ds", symb_d2psi_ds_x_ds); + } // It pains me to do this manually... // This is why we have utility functions to create substitution maps diff --git a/tests/trilinos/assemble_matrix_parallel_04.cc b/tests/trilinos/assemble_matrix_parallel_04.cc index ff60c13c47..a35cd06ac0 100644 --- a/tests/trilinos/assemble_matrix_parallel_04.cc +++ b/tests/trilinos/assemble_matrix_parallel_04.cc @@ -468,11 +468,14 @@ LaplaceProblem::run() { GridGenerator::hyper_shell( triangulation, Point(), 0.5, 1., (dim == 3) ? 96 : 12, false); -#ifdef DEBUG - triangulation.refine_global(3); -#else - triangulation.refine_global(5); -#endif + if constexpr (running_in_debug_mode()) + { + triangulation.refine_global(3); + } + else + { + triangulation.refine_global(5); + } } setup_system(); diff --git a/tests/trilinos/assemble_matrix_parallel_06.cc b/tests/trilinos/assemble_matrix_parallel_06.cc index 3ad65cb621..b3efe8cd72 100644 --- a/tests/trilinos/assemble_matrix_parallel_06.cc +++ b/tests/trilinos/assemble_matrix_parallel_06.cc @@ -469,11 +469,14 @@ LaplaceProblem::run() { GridGenerator::hyper_shell( triangulation, Point(), 0.5, 1., (dim == 3) ? 96 : 12, false); -#ifdef DEBUG - triangulation.refine_global(3); -#else - triangulation.refine_global(5); -#endif + if constexpr (running_in_debug_mode()) + { + triangulation.refine_global(3); + } + else + { + triangulation.refine_global(5); + } } setup_system();