]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Minor cleanup in the VTU writer. 14679/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 13 Jan 2023 20:12:26 +0000 (13:12 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 16 Jan 2023 17:25:25 +0000 (10:25 -0700)
source/base/data_out_base.cc

index d661106371bdb0e1735c481b995d7a7116328fea..2cceadfa0916033f6a7415584204c94475d6b760 100644 (file)
@@ -5811,23 +5811,17 @@ namespace DataOutBase
       const std::vector<Point<spacedim>> node_positions =
         get_node_positions(patches);
 
-      // note that according to the standard, we have to print d=1..3
-      // dimensions, even if we are in reality in 2d, for example
+      // VTK/VTU always wants to see three coordinates, even if we are
+      // in 1d or 2d. So pad node positions with zeros as appropriate.
       std::vector<float> node_coordinates_3d;
       node_coordinates_3d.reserve(node_positions.size() * 3);
       for (const auto &node_position : node_positions)
         {
-          node_coordinates_3d.emplace_back(node_position[0]);
-
-          if (spacedim >= 2)
-            node_coordinates_3d.emplace_back(node_position[1]);
-          else
-            node_coordinates_3d.emplace_back(0.0f);
-
-          if (spacedim >= 3)
-            node_coordinates_3d.emplace_back(node_position[2]);
-          else
-            node_coordinates_3d.emplace_back(0.0f);
+          for (unsigned int d = 0; d < 3; ++d)
+            if (d < spacedim)
+              node_coordinates_3d.emplace_back(node_position[d]);
+            else
+              node_coordinates_3d.emplace_back(0.0f);
         }
       o << vtu_stringize_array(node_coordinates_3d,
                                flags.compression_level,

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.