]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use a better way to create graphical output in step-61.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 3 Dec 2019 00:29:55 +0000 (17:29 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 3 Dec 2019 18:00:21 +0000 (11:00 -0700)
Specifically, rather than creating two output files for the cell pressures
and the Darcy velocities, put them all into a single file using a method
that @kronbichler introduced a while ago.

examples/step-61/step-61.cc
include/deal.II/numerics/data_out_dof_data.h

index 5c77011b1585c321c015d8f200b60f05d0b29c7a..9495bb041c18bff7599444c6e9d781e09097ffae 100644 (file)
@@ -958,15 +958,40 @@ namespace Step61
   // because these are only available on interfaces and not cell
   // interiors. Consequently, you will see them shown as an invalid
   // value (such as an infinity).
+  //
+  // For the cell interior output, we also want to output the velocity
+  // variables. This is a bit tricky since it lives on the same mesh
+  // but uses a different DoFHandler object (the pressure variables live
+  // on the `dof_handler` object, the Darcy velocity on the `dof_handler_dgrt`
+  // object). Fortunately, there are variations of the
+  // DataOut::add_data_vector() function that allow specifying which
+  // DoFHandler a vector corresponds to, and consequently we can visualize
+  // the data from both DoFHandler objects within the same file.
   template <int dim>
   void WGDarcyEquation<dim>::output_results() const
   {
     {
       DataOut<dim> data_out;
-      data_out.attach_dof_handler(dof_handler);
-      data_out.add_data_vector(solution, "Pressure_Interior");
+
+      // First attach the pressure solution to the DataOut object:
+      const std::vector<std::string> solution_names = {"interior_pressure",
+                                                       "interface_pressure"};
+      data_out.add_data_vector(dof_handler, solution, solution_names);
+
+      // Then do the same with the Darcy velocity field, and continue
+      // with writing everything out into a file.
+      const std::vector<std::string> velocity_names(dim, "velocity");
+      const std::vector<
+        DataComponentInterpretation::DataComponentInterpretation>
+        velocity_component_interpretation(
+          dim, DataComponentInterpretation::component_is_part_of_vector);
+      data_out.add_data_vector(dof_handler_dgrt,
+                               darcy_velocity,
+                               velocity_names,
+                               velocity_component_interpretation);
+
       data_out.build_patches(fe.degree);
-      std::ofstream output("Pressure_Interior.vtu");
+      std::ofstream output("solution_interior.vtu");
       data_out.write_vtu(output);
     }
 
@@ -975,26 +1000,9 @@ namespace Step61
       data_out_faces.attach_dof_handler(dof_handler);
       data_out_faces.add_data_vector(solution, "Pressure_Face");
       data_out_faces.build_patches(fe.degree);
-      std::ofstream face_output("Pressure_Face.vtu");
+      std::ofstream face_output("solution_interface.vtu");
       data_out_faces.write_vtu(face_output);
     }
-    // Output Darcy velocity vectors.
-    {
-      std::vector<std::string> solution_names(dim, "velocity");
-      std::vector<DataComponentInterpretation::DataComponentInterpretation>
-        data_component_interpretation(
-          dim, DataComponentInterpretation::component_is_part_of_vector);
-
-      DataOut<dim> data_out_dgrt;
-      data_out_dgrt.attach_dof_handler(dof_handler_dgrt);
-      data_out_dgrt.add_data_vector(darcy_velocity,
-                                    solution_names,
-                                    DataOut<dim>::type_dof_data,
-                                    data_component_interpretation);
-      data_out_dgrt.build_patches(fe_dgrt.degree);
-      std::ofstream dgrt_output("Darcy_velocity.vtk");
-      data_out_dgrt.write_vtk(dgrt_output);
-    }
   }
 
 
index 7d6622dac45c87c6e7f1fe7f775867ba7004dde3..4f8f14bf550fa4a36260c9d3a4be4aba070b9828 100644 (file)
@@ -773,14 +773,15 @@ public:
    * discussion of the arguments except the first one) and allows to set a
    * vector with its own DoFHandler object. This DoFHandler needs to be
    * compatible with the other DoFHandler objects assigned with calls to @p
-   * add_data_vector or @p attach_dof_handler, in the sense that the
+   * add_data_vector or @p attach_dof_handler, in the sense that all of the
    * DoFHandler objects need to be based on the same triangulation. This
-   * function allows you to export data from multiple DoFHandlers that
-   * describe different solution components.
+   * function allows you to export data from multiple DoFHandler objects that
+   * describe different solution components. An example of using this function
+   * is given in step-61.
    *
    * Since this function takes a DoFHandler object and hence naturally
    * represents dof data, the data vector type argument present in the other
-   * methods above is skipped.
+   * methods above is not necessary.
    */
   template <class VectorType>
   void

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.