]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify the creation of filenames in step-12. 5984/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 1 Mar 2018 17:09:12 +0000 (10:09 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 1 Mar 2018 17:09:12 +0000 (10:09 -0700)
examples/step-12/step-12.cc

index ab59e5a21be467d3f45f9f3117b1c27bda64ae2c..21e9a683596e28be5524f8d5814c7497931a6ba0 100644 (file)
@@ -553,39 +553,34 @@ namespace Step12
 
 
   // The output of this program consists of eps-files of the adaptively
-  // refined grids and the numerical solutions given in gnuplot format. This
-  // was covered in previous examples and will not be further commented on.
+  // refined grids and the numerical solutions given in gnuplot format.
   template <int dim>
   void AdvectionProblem<dim>::output_results (const unsigned int cycle) const
   {
-    // Write the grid in eps format.
-    std::string filename = "grid-";
-    filename += ('0' + cycle);
-    Assert (cycle < 10, ExcInternalError());
-
-    filename += ".eps";
-    deallog << "Writing grid to <" << filename << ">" << std::endl;
-    std::ofstream eps_output (filename.c_str());
-
-    GridOut grid_out;
-    grid_out.write_eps (triangulation, eps_output);
+    // First write the grid in eps format.
+    {
+      const std::string filename = "grid-" + std::to_string(cycle) + ".eps";
+      deallog << "Writing grid to <" << filename << ">" << std::endl;
+      std::ofstream eps_output (filename.c_str());
 
-    // Output of the solution in gnuplot format.
-    filename = "sol-";
-    filename += ('0' + cycle);
-    Assert (cycle < 10, ExcInternalError());
+      GridOut grid_out;
+      grid_out.write_eps (triangulation, eps_output);
+    }
 
-    filename += ".gnuplot";
-    deallog << "Writing solution to <" << filename << ">" << std::endl;
-    std::ofstream gnuplot_output (filename.c_str());
+    // Then output the solution in gnuplot format.
+    {
+      const std::string filename = "sol-" + std::to_string(cycle) + ".gnuplot";
+      deallog << "Writing solution to <" << filename << ">" << std::endl;
+      std::ofstream gnuplot_output (filename.c_str());
 
-    DataOut<dim> data_out;
-    data_out.attach_dof_handler (dof_handler);
-    data_out.add_data_vector (solution, "u");
+      DataOut<dim> data_out;
+      data_out.attach_dof_handler (dof_handler);
+      data_out.add_data_vector (solution, "u");
 
-    data_out.build_patches ();
+      data_out.build_patches ();
 
-    data_out.write_gnuplot(gnuplot_output);
+      data_out.write_gnuplot(gnuplot_output);
+    }
   }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.