]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make code easier to read by replacing a preprocessor variable by a constexpr variable.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 26 Nov 2022 04:13:01 +0000 (21:13 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 27 Nov 2022 22:47:13 +0000 (15:47 -0700)
source/base/data_out_base.cc

index 09ee6e76fc3e6d61a0e72da52e4191bf41a5caeb..2a9891dff74507fa0a90b5da8eae88f10b3c6448 100644 (file)
@@ -89,6 +89,13 @@ namespace
 
 namespace
 {
+#ifdef DEAL_II_WITH_ZLIB
+  constexpr bool deal_ii_with_zlib = true;
+#else
+  constexpr bool deal_ii_with_zlib = false;
+#endif
+
+
 #ifdef DEAL_II_WITH_ZLIB
   /**
    * Convert between the CompressionLevel enum (used inside VtkFlags
@@ -137,6 +144,7 @@ namespace
       }
   }
 #  endif
+#endif
 
   /**
    * Do a zlib compression followed by a base64 encoding of the given data. The
@@ -147,6 +155,7 @@ namespace
   compress_array(const std::vector<T> &              data,
                  const DataOutBase::CompressionLevel compression_level)
   {
+#ifdef DEAL_II_WITH_ZLIB
     if (data.size() != 0)
       {
         const std::size_t uncompressed_size = (data.size() * sizeof(T));
@@ -197,9 +206,15 @@ namespace
       }
     else
       return {};
-  }
-
+#else
+    (void)data;
+    (void)compression_level;
+    Assert(false,
+           ExcMessage("This function can only be called if cmake found "
+                      "a working libz installation."));
+    return {};
 #endif
+  }
 
 
 
@@ -217,17 +232,13 @@ namespace
                       const DataOutBase::CompressionLevel compression_level,
                       const int                           precision)
   {
-    (void)compression_level;
-    (void)precision;
-
-#ifdef DEAL_II_WITH_ZLIB
-    if (compression_level != DataOutBase::CompressionLevel::plain_text)
+    if (deal_ii_with_zlib &&
+        (compression_level != DataOutBase::CompressionLevel::plain_text))
       {
         // compress the data we have in memory
         return compress_array(data, compression_level);
       }
     else
-#endif
       {
         std::ostringstream stream;
         stream.precision(precision);
@@ -2045,14 +2056,13 @@ namespace
                                    const unsigned int           start,
                                    const std::vector<unsigned> &connectivity)
   {
-#ifdef DEAL_II_WITH_ZLIB
-    if (flags.compression_level != DataOutBase::CompressionLevel::plain_text)
+    if (deal_ii_with_zlib &&
+        (flags.compression_level != DataOutBase::CompressionLevel::plain_text))
       {
         for (const auto &c : connectivity)
           cells.push_back(start + c);
       }
     else
-#endif
       {
         for (const auto &c : connectivity)
           stream << '\t' << start + c;
@@ -2063,8 +2073,8 @@ namespace
   void
   VtuStream::flush_cells()
   {
-#ifdef DEAL_II_WITH_ZLIB
-    if (flags.compression_level != DataOutBase::CompressionLevel::plain_text)
+    if (deal_ii_with_zlib &&
+        (flags.compression_level != DataOutBase::CompressionLevel::plain_text))
       {
         // compress the data we have in memory and write them to the stream.
         // then release the data
@@ -2073,7 +2083,6 @@ namespace
                                      stream.precision());
         cells.clear();
       }
-#endif
   }
 } // namespace
 
@@ -5874,10 +5883,9 @@ namespace DataOutBase
       out << "<VTKFile type=\"UnstructuredGrid\" version=\"2.2\"";
     else
       out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\"";
-#ifdef DEAL_II_WITH_ZLIB
-    if (flags.compression_level != CompressionLevel::plain_text)
+    if (deal_ii_with_zlib &&
+        (flags.compression_level != CompressionLevel::plain_text))
       out << " compressor=\"vtkZLibDataCompressor\"";
-#endif
 #ifdef DEAL_II_WORDS_BIGENDIAN
     out << " byte_order=\"BigEndian\"";
 #else
@@ -6059,10 +6067,10 @@ namespace DataOutBase
       }
 
     const char *ascii_or_binary =
-#ifdef DEAL_II_WITH_ZLIB
-      (flags.compression_level != CompressionLevel::plain_text) ? "binary" :
-#endif
-                                                                  "ascii";
+      (deal_ii_with_zlib &&
+       (flags.compression_level != CompressionLevel::plain_text)) ?
+        "binary" :
+        "ascii";
 
 
     // first count the number of cells and cells for later use
@@ -6154,9 +6162,9 @@ namespace DataOutBase
                 static const std::array<unsigned int, 5>
                   pyramid_index_translation_table = {{0, 1, 3, 2, 4}};
 
-#ifdef DEAL_II_WITH_ZLIB
-                if (flags.compression_level !=
-                    DataOutBase::CompressionLevel::plain_text)
+                if (deal_ii_with_zlib &&
+                    (flags.compression_level !=
+                     DataOutBase::CompressionLevel::plain_text))
                   {
                     for (unsigned int i = 0; i < n_points; ++i)
                       cells.push_back(
@@ -6166,7 +6174,6 @@ namespace DataOutBase
                            i));
                   }
                 else
-#endif
                   {
                     for (unsigned int i = 0; i < n_points; ++i)
                       out << '\t'
@@ -6191,14 +6198,13 @@ namespace DataOutBase
                       {
                         auto write_cell =
                           [&flags, &out, &cells](const unsigned int start) {
-#ifdef DEAL_II_WITH_ZLIB
-                            if (flags.compression_level !=
-                                DataOutBase::CompressionLevel::plain_text)
+                            if (deal_ii_with_zlib &&
+                                (flags.compression_level !=
+                                 DataOutBase::CompressionLevel::plain_text))
                               {
                                 cells.push_back(start);
                               }
                             else
-#endif
                               {
                                 out << start;
                                 out << '\n';
@@ -6217,15 +6223,14 @@ namespace DataOutBase
 
                         auto write_cell =
                           [&flags, &out, &cells, d1](const unsigned int start) {
-#ifdef DEAL_II_WITH_ZLIB
-                            if (flags.compression_level !=
-                                DataOutBase::CompressionLevel::plain_text)
+                            if (deal_ii_with_zlib &&
+                                (flags.compression_level !=
+                                 DataOutBase::CompressionLevel::plain_text))
                               {
                                 cells.push_back(start);
                                 cells.push_back(start + d1);
                               }
                             else
-#endif
                               {
                                 out << start << '\t' << start + d1;
                                 out << '\n';
@@ -6248,9 +6253,9 @@ namespace DataOutBase
 
                         auto write_cell = [&flags, &out, &cells, d1, d2](
                                             const unsigned int start) {
-#ifdef DEAL_II_WITH_ZLIB
-                          if (flags.compression_level !=
-                              DataOutBase::CompressionLevel::plain_text)
+                          if (deal_ii_with_zlib &&
+                              (flags.compression_level !=
+                               DataOutBase::CompressionLevel::plain_text))
                             {
                               cells.push_back(start);
                               cells.push_back(start + d1);
@@ -6258,7 +6263,6 @@ namespace DataOutBase
                               cells.push_back(start + d2);
                             }
                           else
-#endif
                             {
                               out << start << '\t' << start + d1 << '\t'
                                   << start + d2 + d1 << '\t' << start + d2;
@@ -6284,9 +6288,9 @@ namespace DataOutBase
 
                         auto write_cell = [&flags, &out, &cells, d1, d2, d3](
                                             const unsigned int start) {
-#ifdef DEAL_II_WITH_ZLIB
-                          if (flags.compression_level !=
-                              DataOutBase::CompressionLevel::plain_text)
+                          if (deal_ii_with_zlib &&
+                              (flags.compression_level !=
+                               DataOutBase::CompressionLevel::plain_text))
                             {
                               cells.push_back(start);
                               cells.push_back(start + d1);
@@ -6298,7 +6302,6 @@ namespace DataOutBase
                               cells.push_back(start + d3 + d2);
                             }
                           else
-#endif
                             {
                               out << start << '\t' << start + d1 << '\t'
                                   << start + d2 + d1 << '\t' << start + d2
@@ -6332,17 +6335,15 @@ namespace DataOutBase
               }
           }
 
-          // Flush the 'cells' object we created herein.
-#ifdef DEAL_II_WITH_ZLIB
-        if (flags.compression_level !=
-            DataOutBase::CompressionLevel::plain_text)
+        // Flush the 'cells' object we created herein.
+        if (deal_ii_with_zlib && (flags.compression_level !=
+                                  DataOutBase::CompressionLevel::plain_text))
           {
             out << vtu_stringize_array(cells,
                                        flags.compression_level,
                                        out.precision())
                 << '\n';
           }
-#endif
       }
     out << "    </DataArray>\n";
 
@@ -6386,8 +6387,8 @@ namespace DataOutBase
         << ascii_or_binary << "\">\n";
 
     // this should compress well :-)
-#ifdef DEAL_II_WITH_ZLIB
-    if (flags.compression_level != CompressionLevel::plain_text)
+    if (deal_ii_with_zlib &&
+        (flags.compression_level != CompressionLevel::plain_text))
       {
         std::vector<uint8_t> cell_types_uint8_t(cell_types.size());
         for (unsigned int i = 0; i < cell_types.size(); ++i)
@@ -6398,7 +6399,6 @@ namespace DataOutBase
                                    out.precision());
       }
     else
-#endif
       {
         out << vtu_stringize_array(cell_types,
                                    flags.compression_level,
@@ -8243,10 +8243,10 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
   write_vtu(f);
 #else
 
-  const unsigned int myrank = Utilities::MPI::this_mpi_process(comm);
+  const unsigned int myrank  = Utilities::MPI::this_mpi_process(comm);
   const unsigned int n_ranks = Utilities::MPI::n_mpi_processes(comm);
-  MPI_Info info;
-  int ierr = MPI_Info_create(&info);
+  MPI_Info           info;
+  int                ierr = MPI_Info_create(&info);
   AssertThrowMPI(ierr);
   MPI_File fh;
   ierr = MPI_File_open(
@@ -8263,7 +8263,7 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
   AssertThrowMPI(ierr);
 
   // Define header size so we can broadcast later.
-  unsigned int header_size;
+  unsigned int  header_size;
   std::uint64_t footer_offset;
 
   // write header
@@ -8282,7 +8282,7 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
   AssertThrowMPI(ierr);
 
   {
-    const auto &patches = get_patches();
+    const auto &                  patches      = get_patches();
     const types::global_dof_index my_n_patches = patches.size();
     const types::global_dof_index global_n_patches =
       Utilities::MPI::sum(my_n_patches, comm);
@@ -8301,7 +8301,7 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
 
     // Use prefix sum to find specific offset to write at.
     const std::uint64_t size_on_proc = ss.str().size();
-    std::uint64_t prefix_sum = 0;
+    std::uint64_t       prefix_sum   = 0;
     ierr =
       MPI_Exscan(&size_on_proc, &prefix_sum, 1, MPI_UINT64_T, MPI_SUM, comm);
     AssertThrowMPI(ierr);
@@ -8544,11 +8544,11 @@ DataOutInterface<dim, spacedim>::create_xdmf_entry(
   // from this rank to rank 0 (if they are different ranks).
 
   const bool have_data = (data_filter.n_nodes() > 0);
-  MPI_Comm split_comm;
+  MPI_Comm   split_comm;
   {
-    const int key = myrank;
+    const int key   = myrank;
     const int color = (have_data ? 1 : 0);
-    const int ierr = MPI_Comm_split(comm, color, key, &split_comm);
+    const int ierr  = MPI_Comm_split(comm, color, key, &split_comm);
     AssertThrowMPI(ierr);
   }
 
@@ -8573,7 +8573,7 @@ DataOutInterface<dim, spacedim>::create_xdmf_entry(
                ExcNotImplemented());
 #  endif
 
-      XDMFEntry entry(h5_mesh_filename,
+      XDMFEntry          entry(h5_mesh_filename,
                       h5_solution_filename,
                       cur_time,
                       global_node_cell_count[0],
@@ -8609,7 +8609,7 @@ DataOutInterface<dim, spacedim>::create_xdmf_entry(
       // receive the XDMF data on rank 0 if we don't have it...
 
       MPI_Status status;
-      int ierr = MPI_Probe(MPI_ANY_SOURCE, tag, comm, &status);
+      int        ierr = MPI_Probe(MPI_ANY_SOURCE, tag, comm, &status);
       AssertThrowMPI(ierr);
 
       int len;
@@ -9232,11 +9232,11 @@ DataOutBase::write_hdf5_parallel(
   // create a new communicator that only contains ranks with cells and
   // use that to perform the write operations:
   const bool have_patches = (patches.size() > 0);
-  MPI_Comm split_comm;
+  MPI_Comm   split_comm;
   {
-    const int key = Utilities::MPI::this_mpi_process(comm);
+    const int key   = Utilities::MPI::this_mpi_process(comm);
     const int color = (have_patches ? 1 : 0);
-    const int ierr = MPI_Comm_split(comm, color, key, &split_comm);
+    const int ierr  = MPI_Comm_split(comm, color, key, &split_comm);
     AssertThrowMPI(ierr);
   }
 

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.