From: Wolfgang Bangerth Date: Fri, 9 Jul 2021 18:37:44 +0000 (-0600) Subject: Set physical units in VTU files in several steps. X-Git-Tag: v9.4.0-rc1~1116^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d840420c84a7e766778f9a21c9250ecd4121fede;p=dealii.git Set physical units in VTU files in several steps. --- diff --git a/examples/step-19/step-19.cc b/examples/step-19/step-19.cc index 37ab1240ff..aac35e91b8 100644 --- a/examples/step-19/step-19.cc +++ b/examples/step-19/step-19.cc @@ -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 void CathodeRaySimulator::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( 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) + diff --git a/examples/step-44/step-44.cc b/examples/step-44/step-44.cc index ca8515584e..0a5e7c9e4a 100644 --- a/examples/step-44/step-44.cc +++ b/examples/step-44/step-44.cc @@ -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); diff --git a/examples/step-69/step-69.cc b/examples/step-69/step-69.cc index aaeb1d1e23..49edcf57a3 100644 --- a/examples/step-69/step-69.cc +++ b/examples/step-69/step-69.cc @@ -258,6 +258,7 @@ namespace Step69 // $[\rho,\textbf{m},E]$. // // The purpose of the class members component_names, + // component_physical_units, // pressure, and speed_of_sound is evident from // their names. We also provide a function // compute_lambda_max(), 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 component_names; + const static std::array + component_physical_units; static constexpr double gamma = 7. / 5.; @@ -1597,23 +1600,43 @@ namespace Step69 } // We conclude this section by defining static arrays - // component_names 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: + // component_names and component_physical_units + // 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 ProblemDescription<1>::component_names{ {"rho", "m", "E"}}; + template <> + const std::array + ProblemDescription<1>::component_physical_units{ + {"kg/m", "kg*m/s/m", "J/m"}}; + + template <> const std::array ProblemDescription<2>::component_names{ {"rho", "m_1", "m_2", "E"}}; + template <> + const std::array + 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 ProblemDescription<3>::component_names{ {"rho", "m_1", "m_2", "m_3", "E"}}; + template <> + const std::array + 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::component_names.size(); + ++i) + output_flags + .physical_units[ProblemDescription::component_names[i]] = + ProblemDescription::component_physical_units[i]; + + data_out->set_flags(output_flags); data_out->write_vtu_with_pvtu_record( "", name + "-solution", cycle, mpi_communicator, 6);