]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix warnings in step-10
authorTimo Heister <timo.heister@gmail.com>
Wed, 6 Sep 2017 21:15:03 +0000 (17:15 -0400)
committerTimo Heister <timo.heister@gmail.com>
Wed, 6 Sep 2017 21:15:03 +0000 (17:15 -0400)
The clang code model in qtcreator was showing me these warnings. While
here, remove weird '0'+integer hack.

examples/step-10/step-10.cc

index 9e4edf920ef5fa5a083cb9f8822dc42c2ec498f9..a73bd2feaff8c8acd07b38887e58b73eb3d65b22 100644 (file)
@@ -54,7 +54,7 @@ namespace Step10
   // computed approximation to $\pi$ being in the range of the number of
   // digits which a double variable can hold, we rather declare the reference
   // value as a <code>long double</code> and give it a number of extra digits:
-  const long double pi = 3.141592653589793238462643;
+  const long double pi = 3.141592653589793238462643L;
 
 
 
@@ -95,17 +95,9 @@ namespace Step10
         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. Note that in the parentheses
-        // in the initializer we do arithmetic on characters, which assumes
-        // that first the characters denoting numbers are placed consecutively
-        // (which is probably true for all reasonable character sets
-        // nowadays), but also assumes that the increment
-        // <code>refinement</code> is less than ten. This is therefore more a
-        // quick hack if we know exactly the values which the increment can
-        // assume. A better implementation would use the
-        // <code>std::istringstream</code> class to generate a name.
-        std::string filename_base = "ball";
-        filename_base += '0'+refinement;
+        // 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)
@@ -145,11 +137,11 @@ namespace Step10
             GridOutFlags::Gnuplot gnuplot_flags(false, 30);
             grid_out.set_flags(gnuplot_flags);
 
-            // Finally, generate a filename and a file for output using the
-            // same evil hack as above:
-            std::string filename = filename_base+"_mapping_q";
-            filename += ('0'+degree);
-            filename += ".dat";
+            // Finally, generate a filename and a file for output:
+            std::string filename = filename_base
+                                   + "_mapping_q"
+                                   + Utilities::to_string(degree)
+                                   + ".dat";
             std::ofstream gnuplot_file (filename.c_str());
 
             // Then write out the triangulation to this file. The last
@@ -291,7 +283,7 @@ namespace Step10
               {
                 fe_values.reinit (cell);
                 for (unsigned int i=0; i<fe_values.n_quadrature_points; ++i)
-                  area += fe_values.JxW (i);
+                  area += static_cast<long double>(fe_values.JxW (i));
               }
 
             // ...and store the resulting area values and the errors in the
@@ -390,11 +382,11 @@ namespace Step10
                     // iterator and the number of the face.
                     fe_face_values.reinit (cell, face_no);
                     for (unsigned int i=0; i<fe_face_values.n_quadrature_points; ++i)
-                      perimeter += fe_face_values.JxW (i);
+                      perimeter += static_cast<long double>(fe_face_values.JxW (i));
                   }
             // Then store the evaluated values in the table...
-            table.add_value("eval.pi", static_cast<double> (perimeter/2.));
-            table.add_value("error",   static_cast<double> (std::fabs(perimeter/2.-pi)));
+            table.add_value("eval.pi", static_cast<double> (perimeter/2.0L));
+            table.add_value("error",   static_cast<double> (std::fabs(perimeter/2.0L-pi)));
           }
 
         // ...and end this function as we did in the previous one:

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.