]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify some code.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 18 Nov 2022 22:51:49 +0000 (15:51 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 18 Nov 2022 22:51:49 +0000 (15:51 -0700)
source/base/data_out_base.cc

index 5fc55469b9d2182fdd1bd2589bbf32b3f3441490..2d60e8f36178821269fafc93f40026cec9caf50d 100644 (file)
@@ -1986,41 +1986,66 @@ namespace
 #ifdef DEAL_II_WITH_ZLIB
     if (flags.compression_level != DataOutBase::CompressionLevel::plain_text)
       {
-        cells.push_back(start);
-        if (dim >= 1)
+        switch (dim)
           {
-            cells.push_back(start + d1);
-            if (dim >= 2)
-              {
-                cells.push_back(start + d2 + d1);
-                cells.push_back(start + d2);
-                if (dim >= 3)
-                  {
-                    cells.push_back(start + d3);
-                    cells.push_back(start + d3 + d1);
-                    cells.push_back(start + d3 + d2 + d1);
-                    cells.push_back(start + d3 + d2);
-                  }
-              }
+            case 0:
+              cells.push_back(start);
+              break;
+
+            case 1:
+              cells.push_back(start);
+              cells.push_back(start + d1);
+              break;
+
+            case 2:
+              cells.push_back(start);
+              cells.push_back(start + d1);
+              cells.push_back(start + d2 + d1);
+              cells.push_back(start + d2);
+              break;
+
+            case 3:
+              cells.push_back(start);
+              cells.push_back(start + d1);
+              cells.push_back(start + d2 + d1);
+              cells.push_back(start + d2);
+              cells.push_back(start + d3);
+              cells.push_back(start + d3 + d1);
+              cells.push_back(start + d3 + d2 + d1);
+              cells.push_back(start + d3 + d2);
+              break;
+
+            default:
+              Assert(false, ExcNotImplemented());
           }
       }
     else
 #endif
       {
-        stream << start;
-        if (dim >= 1)
+        switch (dim)
           {
-            stream << '\t' << start + d1;
-            if (dim >= 2)
-              {
-                stream << '\t' << start + d2 + d1 << '\t' << start + d2;
-                if (dim >= 3)
-                  {
-                    stream << '\t' << start + d3 << '\t' << start + d3 + d1
-                           << '\t' << start + d3 + d2 + d1 << '\t'
-                           << start + d3 + d2;
-                  }
-              }
+            case 0:
+              stream << start;
+              break;
+
+            case 1:
+              stream << start << '\t' << start + d1;
+              break;
+
+            case 2:
+              stream << start << '\t' << start + d1 << '\t' << start + d2 + d1
+                     << '\t' << start + d2;
+              break;
+
+            case 3:
+              stream << start << '\t' << start + d1 << '\t' << start + d2 + d1
+                     << '\t' << start + d2 << '\t' << start + d3 << '\t'
+                     << start + d3 + d1 << '\t' << start + d3 + d2 + d1 << '\t'
+                     << start + d3 + d2;
+              break;
+
+            default:
+              Assert(false, ExcNotImplemented());
           }
         stream << '\n';
       }
@@ -6098,7 +6123,51 @@ namespace DataOutBase
     if (flags.write_higher_order_cells)
       write_high_order_cells(patches, vtu_out, /* legacy_format = */ false);
     else
-      write_cells(patches, vtu_out);
+      {
+        Assert(dim <= 3, ExcNotImplemented());
+        unsigned int count                 = 0;
+        unsigned int first_vertex_of_patch = 0;
+        for (const auto &patch : patches)
+          {
+            // special treatment of simplices since they are not subdivided
+            if (patch.reference_cell != ReferenceCells::get_hypercube<dim>())
+              {
+                vtu_out.write_cell_single(count++,
+                                          first_vertex_of_patch,
+                                          patch.data.n_cols(),
+                                          patch.reference_cell);
+                first_vertex_of_patch += patch.data.n_cols();
+              }
+            else
+              {
+                const unsigned int n_subdivisions = patch.n_subdivisions;
+                const unsigned int n              = n_subdivisions + 1;
+                // Length of loops in all dimensions
+                const unsigned int n1 = (dim > 0) ? n_subdivisions : 1;
+                const unsigned int n2 = (dim > 1) ? n_subdivisions : 1;
+                const unsigned int n3 = (dim > 2) ? n_subdivisions : 1;
+                // Offsets of outer loops
+                const unsigned int d1 = 1;
+                const unsigned int d2 = n;
+                const unsigned int d3 = n * n;
+                for (unsigned int i3 = 0; i3 < n3; ++i3)
+                  for (unsigned int i2 = 0; i2 < n2; ++i2)
+                    for (unsigned int i1 = 0; i1 < n1; ++i1)
+                      {
+                        const unsigned int offset =
+                          first_vertex_of_patch + i3 * d3 + i2 * d2 + i1 * d1;
+                        // First write line in x direction
+                        vtu_out.template write_cell<dim>(
+                          count++, offset, d1, d2, d3);
+                      }
+                // finally update the number of the first vertex of this patch
+                first_vertex_of_patch +=
+                  Utilities::fixed_power<dim>(n_subdivisions + 1);
+              }
+          }
+
+        vtu_out.flush_cells();
+      }
     out << "    </DataArray>\n";
 
     // XML VTU format uses offsets; this is different than the VTK format, which

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.