]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify string handling in examples/. 17803/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 23 Oct 2024 17:10:26 +0000 (11:10 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 23 Oct 2024 17:17:15 +0000 (11:17 -0600)
examples/step-13/step-13.cc
examples/step-28/step-28.cc
examples/step-35/step-35.cc
examples/step-36/step-36.cc
examples/step-42/step-42.cc
examples/step-62/step-62.cc
examples/step-71/step-71.cc

index a57da8fd55d92e47ab3140db146c7c94c43bed9d..dd2d346762448d9e211c72bcfc9caad5ef35fec5 100644 (file)
@@ -1376,8 +1376,7 @@ namespace Step13
                                                          results_table);
 
     // Also generate an evaluator which writes out the solution:
-    Evaluation::SolutionOutput<dim> postprocessor2(std::string("solution-") +
-                                                     solver_name,
+    Evaluation::SolutionOutput<dim> postprocessor2("solution-" + solver_name,
                                                    DataOutBase::gnuplot);
 
     // Take these two evaluation objects and put them in a list...
index e0e55e9ccd00a7f671dce073b745d1e5c61ff935..dc5f6e493b4b12df722c6a53c7d4aba0c9d68826 100644 (file)
@@ -1104,7 +1104,7 @@ namespace Step28
   template <int dim>
   void EnergyGroup<dim>::output_results(const unsigned int cycle) const
   {
-    const std::string filename = std::string("solution-") +
+    const std::string filename = "solution-" +
                                  Utilities::int_to_string(group, 2) + "." +
                                  Utilities::int_to_string(cycle, 2) + ".vtu";
 
index 689c6f0aa68163568085a54768c1f6eaa880ab9b..819789a5f7e8dac2c7d7d920397e13c0709fd2c2 100644 (file)
@@ -238,7 +238,7 @@ namespace Step35
 
       prm.parse_input(file);
 
-      if (prm.get("Method_Form") == std::string("rotational"))
+      if (prm.get("Method_Form") == "rotational")
         form = Method::rotational;
       else
         form = Method::standard;
index cc0780fbc63ad9f8f32adde50ddd6129de1142eb..71d29e23af790552ea92cb0ad4cc6f6694618b20 100644 (file)
@@ -404,8 +404,7 @@ namespace Step36
 
     for (unsigned int i = 0; i < eigenfunctions.size(); ++i)
       data_out.add_data_vector(eigenfunctions[i],
-                               std::string("eigenfunction_") +
-                                 Utilities::int_to_string(i));
+                               "eigenfunction_" + Utilities::int_to_string(i));
 
     // The only thing worth discussing may be that because the potential is
     // specified as a function expression in the input file, it would be nice
index f601e1baf89e99c1c5b73f1b8d77e9e892475452..ba684576533c05e37d4095a0404f9dbc28223e17 100644 (file)
@@ -447,9 +447,7 @@ namespace Step42
       , ny(0)
     {
       std::ifstream f(name);
-      AssertThrow(f,
-                  ExcMessage(std::string("Can't read from file <") + name +
-                             ">!"));
+      AssertThrow(f, ExcMessage("Can't read from file <" + name + ">!"));
 
       std::string temp;
       f >> temp >> nx >> ny;
index 64e773ad0507449e8fe4f9d45652cf5fb97c5e76..4cd36262f37af085b54c687ccc5806b69dd694a9 100644 (file)
@@ -1461,12 +1461,12 @@ int main(int argc, char *argv[])
               group.get_attribute<double>("frequency_range") / 2);
           group.set_attribute<unsigned int>("nb_frequency_points", 400);
 
-          if (group_name == std::string("displacement"))
-            group.set_attribute<std::string>(
-              "simulation_name", std::string("phononic_cavity_displacement"));
+          if (group_name == "displacement")
+            group.set_attribute<std::string>("simulation_name",
+                                             "phononic_cavity_displacement");
           else
-            group.set_attribute<std::string>(
-              "simulation_name", std::string("phononic_cavity_calibration"));
+            group.set_attribute<std::string>("simulation_name",
+                                             "phononic_cavity_calibration");
 
           group.set_attribute<bool>("save_vtu_files", false);
         }
index ef9699af3856dc7052c1d78f9d6392a0410641f8..08e1514014702c5366873cd0399119ca4b1c4383 100644 (file)
@@ -334,11 +334,11 @@ namespace Step71
       // like the author, you'll be doing the opposite and will rather verify
       // that your implementation of the analytical solution is correct!)
       AssertThrow(std::abs(f(x, y) - computed_f) < tol,
-                  ExcMessage(std::string("Incorrect value computed for f. ") +
-                             std::string("Hand-calculated value: ") +
+                  ExcMessage("Incorrect value computed for f. "
+                             "Hand-calculated value: " +
                              Utilities::to_string(f(x, y)) +
-                             std::string(" ; ") +
-                             std::string("Value computed by AD: ") +
+                             " ; "
+                             "Value computed by AD: " +
                              Utilities::to_string(computed_f)));
 
       // Because we know the ordering of the independent variables, we know
@@ -347,19 +347,19 @@ namespace Step71
       const double computed_df_dy = Df[1];
 
       AssertThrow(std::abs(df_dx(x, y) - computed_df_dx) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for df/dx. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(df_dx(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_df_dx)));
+                  ExcMessage("Incorrect value computed for df/dx. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(df_dx(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_df_dx)));
       AssertThrow(std::abs(df_dy(x, y) - computed_df_dy) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for df/dy. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(df_dy(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_df_dy)));
+                  ExcMessage("Incorrect value computed for df/dy. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(df_dy(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_df_dy)));
 
       // ... and similar for the Hessian.
       const double computed_d2f_dx_dx = D2f[0][0];
@@ -368,33 +368,33 @@ namespace Step71
       const double computed_d2f_dy_dy = D2f[1][1];
 
       AssertThrow(std::abs(d2f_dx_dx(x, y) - computed_d2f_dx_dx) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dx_dx. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dx_dx(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_d2f_dx_dx)));
+                  ExcMessage("Incorrect value computed for d2f/dx_dx. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dx_dx(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_d2f_dx_dx)));
       AssertThrow(std::abs(d2f_dx_dy(x, y) - computed_d2f_dx_dy) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dx_dy. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dx_dy(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_d2f_dx_dy)));
+                  ExcMessage("Incorrect value computed for d2f/dx_dy. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dx_dy(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_d2f_dx_dy)));
       AssertThrow(std::abs(d2f_dy_dx(x, y) - computed_d2f_dy_dx) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dy_dx. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dy_dx(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_d2f_dy_dx)));
+                  ExcMessage("Incorrect value computed for d2f/dy_dx. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dy_dx(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_d2f_dy_dx)));
       AssertThrow(std::abs(d2f_dy_dy(x, y) - computed_d2f_dy_dy) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dy_dy. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dy_dy(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_d2f_dy_dy)));
+                  ExcMessage("Incorrect value computed for d2f/dy_dy. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dy_dy(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_d2f_dy_dy)));
     }
 
     // That's pretty great. There wasn't too much work involved in computing
@@ -650,11 +650,11 @@ namespace Step71
         f_sd.substitute_and_evaluate<double>(substitution_map);
 
       AssertThrow(std::abs(f(x, y) - computed_f) < tol,
-                  ExcMessage(std::string("Incorrect value computed for f. ") +
-                             std::string("Hand-calculated value: ") +
+                  ExcMessage("Incorrect value computed for f. "
+                             "Hand-calculated value: " +
                              Utilities::to_string(f(x, y)) +
-                             std::string(" ; ") +
-                             std::string("Value computed by AD: ") +
+                             " ; "
+                             "Value computed by AD: " +
                              Utilities::to_string(computed_f)));
 
       // We can do the same for the first derivatives...
@@ -664,19 +664,19 @@ namespace Step71
         df_dy_sd.substitute_and_evaluate<double>(substitution_map);
 
       AssertThrow(std::abs(df_dx(x, y) - computed_df_dx) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for df/dx. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(df_dx(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_df_dx)));
+                  ExcMessage("Incorrect value computed for df/dx. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(df_dx(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_df_dx)));
       AssertThrow(std::abs(df_dy(x, y) - computed_df_dy) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for df/dy. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(df_dy(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by AD: ") +
-                    Utilities::to_string(computed_df_dy)));
+                  ExcMessage("Incorrect value computed for df/dy. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(df_dy(x, y)) +
+                             " ; "
+                             "Value computed by AD: " +
+                             Utilities::to_string(computed_df_dy)));
 
       // ... and the second derivatives.
       // Notice that we can reuse the same substitution map for each of these
@@ -696,33 +696,33 @@ namespace Step71
         d2f_dy_dy_sd.substitute_and_evaluate<double>(substitution_map);
 
       AssertThrow(std::abs(d2f_dx_dx(x, y) - computed_d2f_dx_dx) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dx_dx. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dx_dx(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by SD: ") +
-                    Utilities::to_string(computed_d2f_dx_dx)));
+                  ExcMessage("Incorrect value computed for d2f/dx_dx. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dx_dx(x, y)) +
+                             " ; "
+                             "Value computed by SD: " +
+                             Utilities::to_string(computed_d2f_dx_dx)));
       AssertThrow(std::abs(d2f_dx_dy(x, y) - computed_d2f_dx_dy) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dx_dy. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dx_dy(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by SD: ") +
-                    Utilities::to_string(computed_d2f_dx_dy)));
+                  ExcMessage("Incorrect value computed for d2f/dx_dy. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dx_dy(x, y)) +
+                             " ; "
+                             "Value computed by SD: " +
+                             Utilities::to_string(computed_d2f_dx_dy)));
       AssertThrow(std::abs(d2f_dy_dx(x, y) - computed_d2f_dy_dx) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dy_dx. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dy_dx(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by SD: ") +
-                    Utilities::to_string(computed_d2f_dy_dx)));
+                  ExcMessage("Incorrect value computed for d2f/dy_dx. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dy_dx(x, y)) +
+                             " ; "
+                             "Value computed by SD: " +
+                             Utilities::to_string(computed_d2f_dy_dx)));
       AssertThrow(std::abs(d2f_dy_dy(x, y) - computed_d2f_dy_dy) < tol,
-                  ExcMessage(
-                    std::string("Incorrect value computed for d2f/dy_dy. ") +
-                    std::string("Hand-calculated value: ") +
-                    Utilities::to_string(d2f_dy_dy(x, y)) + std::string(" ; ") +
-                    std::string("Value computed by SD: ") +
-                    Utilities::to_string(computed_d2f_dy_dy)));
+                  ExcMessage("Incorrect value computed for d2f/dy_dy. "
+                             "Hand-calculated value: " +
+                             Utilities::to_string(d2f_dy_dy(x, y)) +
+                             " ; "
+                             "Value computed by SD: " +
+                             Utilities::to_string(computed_d2f_dy_dy)));
     }
 
 

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.