]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Also inline the write_high_order_cell() function into write_vtu_main().
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 30 Dec 2022 21:56:58 +0000 (14:56 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 31 Dec 2022 15:25:43 +0000 (08:25 -0700)
This allows getting rid of the vtu_stream object and associated ostringstream object.

source/base/data_out_base.cc

index 236fbd85c7de9f5902696849a77aad37c32d2cd6..28bfa373c3febeb5346e4dd54b81669604fe8723 100644 (file)
@@ -5935,137 +5935,149 @@ namespace DataOutBase
       o << "  <Cells>\n";
       o << "    <DataArray type=\"Int32\" Name=\"connectivity\" format=\""
         << ascii_or_binary << "\">\n";
+
+      std::vector<int32_t> cells;
       if (flags.write_higher_order_cells)
         {
-          std::ostringstream oo;
-          {
-            VtuStream vtu_out(oo, flags);
+          Assert(dim <= 3 && dim > 1, ExcNotImplemented());
+          unsigned int first_vertex_of_patch = 0;
+          // Array to hold all the node numbers of a cell
+          std::vector<unsigned> connectivity;
 
-            Assert(dim <= 3 && dim > 1, ExcNotImplemented());
-            unsigned int first_vertex_of_patch = 0;
-            // Array to hold all the node numbers of a cell
-            std::vector<unsigned> connectivity;
+          for (const auto &patch : patches)
+            {
+              if (patch.reference_cell != ReferenceCells::get_hypercube<dim>())
+                {
+                  connectivity.resize(patch.data.n_cols());
 
-            for (const auto &patch : patches)
-              {
-                if (patch.reference_cell !=
-                    ReferenceCells::get_hypercube<dim>())
-                  {
-                    connectivity.resize(patch.data.n_cols());
+                  for (unsigned int i = 0; i < patch.data.n_cols(); ++i)
+                    connectivity[i] = i;
 
-                    for (unsigned int i = 0; i < patch.data.n_cols(); ++i)
-                      connectivity[i] = i;
+                  if (deal_ii_with_zlib &&
+                      (flags.compression_level !=
+                       DataOutBase::CompressionLevel::plain_text))
+                    {
+                      for (const auto &c : connectivity)
+                        cells.push_back(first_vertex_of_patch + c);
+                    }
+                  else
+                    {
+                      for (const auto &c : connectivity)
+                        o << '\t' << first_vertex_of_patch + c;
+                      o << '\n';
+                    }
 
-                    vtu_out.template write_high_order_cell<dim>(
-                      first_vertex_of_patch, connectivity);
+                  first_vertex_of_patch += patch.data.n_cols();
+                }
+              else
+                {
+                  const unsigned int n_subdivisions = patch.n_subdivisions;
+                  const unsigned int n              = n_subdivisions + 1;
 
-                    first_vertex_of_patch += patch.data.n_cols();
-                  }
-                else
-                  {
-                    const unsigned int n_subdivisions = patch.n_subdivisions;
-                    const unsigned int n              = n_subdivisions + 1;
+                  connectivity.resize(Utilities::fixed_power<dim>(n));
 
-                    connectivity.resize(Utilities::fixed_power<dim>(n));
+                  switch (dim)
+                    {
+                      case 0:
+                        {
+                          Assert(false,
+                                 ExcMessage(
+                                   "Point-like cells should not be possible "
+                                   "when writing higher-order cells."));
+                          break;
+                        }
+                      case 1:
+                        {
+                          for (unsigned int i1 = 0; i1 < n_subdivisions + 1;
+                               ++i1)
+                            {
+                              const unsigned int local_index = i1;
+                              const unsigned int connectivity_index =
+                                patch.reference_cell
+                                  .template vtk_lexicographic_to_node_index<1>(
+                                    {{i1}},
+                                    {{n_subdivisions}},
+                                    /* use VTU, not VTK: */ false);
+                              connectivity[connectivity_index] = local_index;
+                            }
 
-                    switch (dim)
-                      {
-                        case 0:
-                          {
-                            Assert(false,
-                                   ExcMessage(
-                                     "Point-like cells should not be possible "
-                                     "when writing higher-order cells."));
-                            break;
-                          }
-                        case 1:
-                          {
+                          break;
+                        }
+                      case 2:
+                        {
+                          for (unsigned int i2 = 0; i2 < n_subdivisions + 1;
+                               ++i2)
                             for (unsigned int i1 = 0; i1 < n_subdivisions + 1;
                                  ++i1)
                               {
-                                const unsigned int local_index = i1;
+                                const unsigned int local_index = i2 * n + i1;
                                 const unsigned int connectivity_index =
                                   patch.reference_cell
                                     .template vtk_lexicographic_to_node_index<
-                                      1>({{i1}},
-                                         {{n_subdivisions}},
+                                      2>({{i1, i2}},
+                                         {{n_subdivisions, n_subdivisions}},
                                          /* use VTU, not VTK: */ false);
                                 connectivity[connectivity_index] = local_index;
                               }
 
-                            break;
-                          }
-                        case 2:
-                          {
+                          break;
+                        }
+                      case 3:
+                        {
+                          for (unsigned int i3 = 0; i3 < n_subdivisions + 1;
+                               ++i3)
                             for (unsigned int i2 = 0; i2 < n_subdivisions + 1;
                                  ++i2)
                               for (unsigned int i1 = 0; i1 < n_subdivisions + 1;
                                    ++i1)
                                 {
-                                  const unsigned int local_index = i2 * n + i1;
+                                  const unsigned int local_index =
+                                    i3 * n * n + i2 * n + i1;
                                   const unsigned int connectivity_index =
                                     patch.reference_cell
                                       .template vtk_lexicographic_to_node_index<
-                                        2>({{i1, i2}},
-                                           {{n_subdivisions, n_subdivisions}},
+                                        3>({{i1, i2, i3}},
+                                           {{n_subdivisions,
+                                             n_subdivisions,
+                                             n_subdivisions}},
                                            /* use VTU, not VTK: */ false);
                                   connectivity[connectivity_index] =
                                     local_index;
                                 }
 
-                            break;
-                          }
-                        case 3:
-                          {
-                            for (unsigned int i3 = 0; i3 < n_subdivisions + 1;
-                                 ++i3)
-                              for (unsigned int i2 = 0; i2 < n_subdivisions + 1;
-                                   ++i2)
-                                for (unsigned int i1 = 0;
-                                     i1 < n_subdivisions + 1;
-                                     ++i1)
-                                  {
-                                    const unsigned int local_index =
-                                      i3 * n * n + i2 * n + i1;
-                                    const unsigned int connectivity_index =
-                                      patch.reference_cell
-                                        .template vtk_lexicographic_to_node_index<
-                                          3>({{i1, i2, i3}},
-                                             {{n_subdivisions,
-                                               n_subdivisions,
-                                               n_subdivisions}},
-                                             /* use VTU, not VTK: */ false);
-                                    connectivity[connectivity_index] =
-                                      local_index;
-                                  }
-
-                            break;
-                          }
-                        default:
-                          Assert(false, ExcNotImplemented());
-                      }
-
-                    // Having so set up the 'connectivity' data structure,
-                    // output it:
-                    vtu_out.template write_high_order_cell<dim>(
-                      first_vertex_of_patch, connectivity);
+                          break;
+                        }
+                      default:
+                        Assert(false, ExcNotImplemented());
+                    }
 
-                    // Finally update the number of the first vertex of this
-                    // patch
-                    first_vertex_of_patch += Utilities::fixed_power<dim>(n);
-                  }
-              }
+                  // Having so set up the 'connectivity' data structure,
+                  // output it:
+                  if (deal_ii_with_zlib &&
+                      (flags.compression_level !=
+                       DataOutBase::CompressionLevel::plain_text))
+                    {
+                      for (const auto &c : connectivity)
+                        cells.push_back(first_vertex_of_patch + c);
+                    }
+                  else
+                    {
+                      for (const auto &c : connectivity)
+                        o << '\t' << first_vertex_of_patch + c;
+                      o << '\n';
+                    }
 
-            vtu_out.flush_cells();
-          }
-          o << oo.str() << '\n';
+                  // Finally update the number of the first vertex of this
+                  // patch
+                  first_vertex_of_patch += Utilities::fixed_power<dim>(n);
+                }
+            }
         }
       else
         {
           Assert(dim <= 3, ExcNotImplemented());
 
-          std::vector<int32_t> cells;
-          unsigned int         first_vertex_of_patch = 0;
+          unsigned int first_vertex_of_patch = 0;
 
           for (const auto &patch : patches)
             {
@@ -6277,16 +6289,16 @@ namespace DataOutBase
                     Utilities::fixed_power<dim>(n_subdivisions + 1);
                 }
             }
+        }
 
-          // Flush the 'cells' object we created herein.
-          if (deal_ii_with_zlib && (flags.compression_level !=
-                                    DataOutBase::CompressionLevel::plain_text))
-            {
-              o << vtu_stringize_array(cells,
-                                       flags.compression_level,
-                                       output_precision)
-                << '\n';
-            }
+      // Flush the 'cells' object we created herein.
+      if (deal_ii_with_zlib && (flags.compression_level !=
+                                DataOutBase::CompressionLevel::plain_text))
+        {
+          o << vtu_stringize_array(cells,
+                                   flags.compression_level,
+                                   output_precision)
+            << '\n';
         }
       o << "    </DataArray>\n";
 

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.