]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify more code.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 18 Nov 2022 22:58:45 +0000 (15:58 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 20 Nov 2022 01:22:16 +0000 (18:22 -0700)
source/base/data_out_base.cc

index 2d60e8f36178821269fafc93f40026cec9caf50d..3eea04099da199ab9975e8aaeb376b560bed191c 100644 (file)
@@ -3007,24 +3007,68 @@ namespace DataOutBase
           {
             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)
+
+            switch (dim)
+              {
+                case 0:
                   {
-                    const unsigned int offset =
-                      first_vertex_of_patch + i3 * d3 + i2 * d2 + i1 * d1;
-                    // First write line in x direction
-                    out.template write_cell<dim>(count++, offset, d1, d2, d3);
+                    const unsigned int offset = first_vertex_of_patch;
+                    out.template write_cell<dim>(count++, offset, 0, 0, 0);
+                    break;
                   }
-            // finally update the number of the first vertex of this patch
+                case 1:
+                  {
+                    const unsigned int d1 = 1;
+
+                    for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
+                      {
+                        const unsigned int offset =
+                          first_vertex_of_patch + i1 * d1;
+                        out.template write_cell<dim>(count++, offset, d1, 0, 0);
+                      }
+
+                    break;
+                  }
+                case 2:
+                  {
+                    const unsigned int d1 = 1;
+                    const unsigned int d2 = n;
+
+                    for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
+                      for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
+                        {
+                          const unsigned int offset =
+                            first_vertex_of_patch + i2 * d2 + i1 * d1;
+                          out.template write_cell<dim>(
+                            count++, offset, d1, d2, 0);
+                        }
+
+                    break;
+                  }
+                case 3:
+                  {
+                    const unsigned int d1 = 1;
+                    const unsigned int d2 = n;
+                    const unsigned int d3 = n * n;
+
+                    for (unsigned int i3 = 0; i3 < n_subdivisions; ++i3)
+                      for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
+                        for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
+                          {
+                            const unsigned int offset = first_vertex_of_patch +
+                                                        i3 * d3 + i2 * d2 +
+                                                        i1 * d1;
+                            out.template write_cell<dim>(
+                              count++, offset, d1, d2, d3);
+                          }
+
+                    break;
+                  }
+                default:
+                  Assert(false, ExcNotImplemented());
+              }
+
+            // Update the number of the first vertex of this patch
             first_vertex_of_patch +=
               Utilities::fixed_power<dim>(n_subdivisions + 1);
           }

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.