From 4bdd5aec2d3ba23fc49d39dd559d9197ab81fc20 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 23 Aug 2018 15:06:09 -0600 Subject: [PATCH] Avoid loop increment operations with side effects. Just because it can be done does not mean that it *should* be done. --- examples/step-10/step-10.cc | 19 ++++++++----------- examples/step-11/step-11.cc | 7 ++++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/step-10/step-10.cc b/examples/step-10/step-10.cc index 8ddacbf912..8b6215f52b 100644 --- a/examples/step-10/step-10.cc +++ b/examples/step-10/step-10.cc @@ -83,21 +83,15 @@ namespace Step10 Triangulation triangulation; GridGenerator::hyper_ball(triangulation); - // Next generate output for this grid and for a once refined grid. Note - // that we have hidden the mesh refinement in the loop header, which might - // be uncommon but nevertheless works. Also it is strangely consistent - // with incrementing the loop index denoting the refinement level. - for (unsigned int refinement = 0; refinement < 2; - ++refinement, triangulation.refine_global(1)) + // Then alternate between generating output on the current mesh + // for $Q_1$, $Q_2$, and $Q_3$ mappings, and (at the end of the + // loop body) refining the mesh once globally. + for (unsigned int refinement = 0; refinement < 2; ++refinement) { std::cout << "Refinement level: " << refinement << std::endl; - // Then have a string which denotes the base part of the names of the - // files into which we write the output (ending with the refinement - // level). std::string filename_base = "ball_" + Utilities::to_string(refinement); - // Then output the present grid for $Q_1$, $Q_2$, and $Q_3$ mappings: for (unsigned int degree = 1; degree < 4; ++degree) { std::cout << "Degree = " << degree << std::endl; @@ -118,7 +112,7 @@ namespace Step10 // explicitly. - // In degree to actually write out the present grid with this + // In order to actually write out the present grid with this // mapping, we set up an object which we will use for output. We // will generate Gnuplot output, which consists of a set of lines // describing the mapped triangulation. By default, only one line @@ -149,6 +143,9 @@ namespace Step10 grid_out.write_gnuplot(triangulation, gnuplot_file, &mapping); } std::cout << std::endl; + + // At the end of the loop, refine the mesh globally. + triangulation.refine_global(); } } diff --git a/examples/step-11/step-11.cc b/examples/step-11/step-11.cc index 61550df2d4..775f54fd5f 100644 --- a/examples/step-11/step-11.cc +++ b/examples/step-11/step-11.cc @@ -415,12 +415,13 @@ namespace Step11 { GridGenerator::hyper_ball(triangulation); - for (unsigned int cycle = 0; cycle < 6; - ++cycle, triangulation.refine_global(1)) + for (unsigned int cycle = 0; cycle < 6; ++cycle) { setup_system(); assemble_and_solve(); - }; + + triangulation.refine_global(); + } // After all the data is generated, write a table of results to the // screen: -- 2.39.5