From: Wolfgang Bangerth Date: Thu, 23 Aug 2018 21:06:09 +0000 (-0600) Subject: Avoid loop increment operations with side effects. X-Git-Tag: v9.1.0-rc1~783^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7110%2Fhead;p=dealii.git Avoid loop increment operations with side effects. Just because it can be done does not mean that it *should* be done. --- 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: