]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Set physical units in VTU files in several steps.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 9 Jul 2021 18:37:44 +0000 (12:37 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 15 Jul 2021 16:35:54 +0000 (10:35 -0600)
examples/step-19/step-19.cc
examples/step-44/step-44.cc
examples/step-69/step-69.cc

index 37ab1240fff89851ddb788d678a347435fb7988d..aac35e91b85ea08ef32b873e5dd03f69ed174a0f 100644 (file)
@@ -903,12 +903,14 @@ namespace Step19
 
 
   // With this, the `output_results()` function becomes relatively
-  // straightforward: We use the DataOut class as we have in almost every one of
-  // the previous tutorial programs to output the solution (the "electric
-  // potential") and we use the postprocessor defined above to also output its
-  // gradient (the "electric field"). This all is then written into a file in
-  // VTU format after also associating the current time and time step number
-  // with this file.
+  // straightforward: We use the DataOut class as we have in almost
+  // every one of the previous tutorial programs to output the
+  // solution (the "electric potential") and we use the postprocessor
+  // defined above to also output its gradient (the "electric
+  // field"). This all is then written into a file in VTU format after
+  // also associating the current time and time step number with this
+  // file, and providing physical units for the two fields to be
+  // output.
   template <int dim>
   void CathodeRaySimulator<dim>::output_results() const
   {
@@ -920,8 +922,13 @@ namespace Step19
       data_out.add_data_vector(solution, electric_field);
       data_out.build_patches();
 
-      data_out.set_flags(
-        DataOutBase::VtkFlags(time.get_current_time(), time.get_step_number()));
+      DataOutBase::VtkFlags output_flags;
+      output_flags.time  = time.get_current_time();
+      output_flags.cycle = time.get_step_number();
+      output_flags.physical_units["electric_potential"] = "V";
+      output_flags.physical_units["electric_field"]     = "V/m";
+
+      data_out.set_flags(output_flags);
 
       std::ofstream output("solution-" +
                            Utilities::int_to_string(time.get_step_number(), 4) +
@@ -943,8 +950,12 @@ namespace Step19
         std::vector<DataComponentInterpretation::DataComponentInterpretation>(
           dim, DataComponentInterpretation::component_is_part_of_vector));
 
-      particle_out.set_flags(
-        DataOutBase::VtkFlags(time.get_current_time(), time.get_step_number()));
+      DataOutBase::VtkFlags output_flags;
+      output_flags.time                       = time.get_current_time();
+      output_flags.cycle                      = time.get_step_number();
+      output_flags.physical_units["velocity"] = "m/s";
+
+      particle_out.set_flags(output_flags);
 
       std::ofstream output("particles-" +
                            Utilities::int_to_string(time.get_step_number(), 4) +
index ca8515584e8069fe076f6dea0a500a0b9bd18423..0a5e7c9e4aadd556b5054e1456c45b6174acd4fb 100644 (file)
@@ -3216,7 +3216,8 @@ namespace Step44
     solution_name.emplace_back("dilatation");
 
     DataOutBase::VtkFlags output_flags;
-    output_flags.write_higher_order_cells = true;
+    output_flags.write_higher_order_cells       = true;
+    output_flags.physical_units["displacement"] = "m";
     data_out.set_flags(output_flags);
 
     data_out.attach_dof_handler(dof_handler);
index aaeb1d1e23ac1467bc8a078148e717b294311e57..49edcf57a39f42b6ea3b85e82309fcc76e659365 100644 (file)
@@ -258,6 +258,7 @@ namespace Step69
   //   $[\rho,\textbf{m},E]$.
   //
   // The purpose of the class members <code>component_names</code>,
+  // <code>component_physical_units</code>,
   // <code>pressure</code>, and <code>speed_of_sound</code> is evident from
   // their names. We also provide a function
   // <code>compute_lambda_max()</code>, that computes the wave speed
@@ -292,6 +293,8 @@ namespace Step69
     using flux_type  = Tensor<1, problem_dimension, Tensor<1, dim>>;
 
     const static std::array<std::string, problem_dimension> component_names;
+    const static std::array<std::string, problem_dimension>
+      component_physical_units;
 
     static constexpr double gamma = 7. / 5.;
 
@@ -1597,23 +1600,43 @@ namespace Step69
   }
 
   // We conclude this section by defining static arrays
-  // <code>component_names</code> that contain strings describing the
-  // component names of our state vector. We have template specializations
-  // for dimensions one, two and three, that are used later in DataOut for
-  // naming the corresponding components:
+  // <code>component_names</code> and <code>component_physical_units</code>
+  // that contain strings describing the
+  // components of our state vector, as well as the physical units of
+  // these quantities that can be used to annotate the VTU output
+  // files we generate for visualization and postprocessing. We have
+  // template specializations for dimensions one, two and three, that
+  // are used later in DataOut for naming the corresponding
+  // components:
 
   template <>
   const std::array<std::string, 3> ProblemDescription<1>::component_names{
     {"rho", "m", "E"}};
 
+  template <>
+  const std::array<std::string, 3>
+    ProblemDescription<1>::component_physical_units{
+      {"kg/m", "kg*m/s/m", "J/m"}};
+
+
   template <>
   const std::array<std::string, 4> ProblemDescription<2>::component_names{
     {"rho", "m_1", "m_2", "E"}};
 
+  template <>
+  const std::array<std::string, 4>
+    ProblemDescription<2>::component_physical_units{
+      {"kg/m/m", "kg*m/s/m/m", "kg*m/s/m/m", "J/m/m"}};
+
   template <>
   const std::array<std::string, 5> ProblemDescription<3>::component_names{
     {"rho", "m_1", "m_2", "m_3", "E"}};
 
+  template <>
+  const std::array<std::string, 5>
+    ProblemDescription<3>::component_physical_units{
+      {"kg/m/m/m", "kg*m/s/m/m/m", "kg*m/s/m/m/m", "kg*m/s/m/m/m", "J/m/m/m"}};
+
   // @sect4{Initial values}
 
   // The last preparatory step, before we discuss the implementation of the
@@ -2733,11 +2756,18 @@ namespace Step69
               oa << it2;
         }
 
-      DataOutBase::VtkFlags flags(t,
-                                  cycle,
-                                  true,
-                                  DataOutBase::VtkFlags::best_speed);
-      data_out->set_flags(flags);
+      DataOutBase::VtkFlags output_flags;
+      output_flags.time              = t;
+      output_flags.cycle             = cycle;
+      output_flags.compression_level = DataOutBase::VtkFlags::best_speed;
+      for (unsigned int i = 0;
+           i < ProblemDescription<dim>::component_names.size();
+           ++i)
+        output_flags
+          .physical_units[ProblemDescription<dim>::component_names[i]] =
+          ProblemDescription<dim>::component_physical_units[i];
+
+      data_out->set_flags(output_flags);
 
       data_out->write_vtu_with_pvtu_record(
         "", name + "-solution", cycle, mpi_communicator, 6);

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.