]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make Patch<0,spacedim>::n_subdivisions a 'const' variable. 12874/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 25 Oct 2021 01:47:54 +0000 (19:47 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 28 Oct 2021 03:21:59 +0000 (21:21 -0600)
include/deal.II/base/data_out_base.h
source/base/data_out_base.cc
source/particles/data_out.cc

index 6d8e17febd86212db63fb09905afa3af1f465c57..c5179555816fa4fa2f6d54725706749d46ed37b1 100644 (file)
@@ -433,7 +433,7 @@ namespace DataOutBase
      * this variable is not used but exists only to allow access
      * from general code in a generic fashion.
      */
-    static unsigned int n_subdivisions;
+    static const unsigned int n_subdivisions;
 
     /**
      * Data vectors. The format is as follows: <tt>data(i,.)</tt> denotes the
index 295babfe601eea53fcd5a73fb522651d9a9485d5..f2a28610de9005f7091d2b5d66166a8363aa7df8 100644 (file)
@@ -2070,7 +2070,7 @@ namespace DataOutBase
     Patch<0, spacedim>::no_neighbor};
 
   template <int spacedim>
-  unsigned int Patch<0, spacedim>::n_subdivisions = 1;
+  const unsigned int Patch<0, spacedim>::n_subdivisions = 1;
 
   template <int spacedim>
   const ReferenceCell Patch<0, spacedim>::reference_cell =
@@ -9088,7 +9088,22 @@ namespace DataOutBase
     for (unsigned int i : patch.reference_cell.face_indices())
       in >> patch.neighbors[i];
 
-    in >> patch.patch_index >> patch.n_subdivisions;
+    in >> patch.patch_index;
+
+    // If dim>1, we also need to set the number of subdivisions, whereas
+    // in dim==1, this is a const variable equal to one that can't be changed.
+    unsigned int n_subdivisions;
+    in >> n_subdivisions;
+#ifdef DEAL_II_HAVE_CXX17
+    if constexpr (dim > 1)
+      patch.n_subdivisions = n_subdivisions;
+#else
+    // If we can't use 'if constexpr', work around the fact that we can't
+    // write to a 'const' variable by using a const_cast that is a no-op
+    // whenever the code is actually executed
+    if (dim > 1)
+      const_cast<unsigned int &>(patch.n_subdivisions) = n_subdivisions;
+#endif
 
     in >> patch.points_are_available;
 
index 901a7ea050472ced15b68aa8371d7a85fb591973..f0c7273b2107b88e56e99c9f8136dea526189d54 100644 (file)
@@ -80,9 +80,8 @@ namespace Particles
     auto particle = particles.begin();
     for (unsigned int i = 0; particle != particles.end(); ++particle, ++i)
       {
-        patches[i].vertices[0]    = particle->get_location();
-        patches[i].patch_index    = i;
-        patches[i].n_subdivisions = 1;
+        patches[i].vertices[0] = particle->get_location();
+        patches[i].patch_index = i;
 
         // We have one more data components than dataset_names (the particle id)
         patches[i].data.reinit(n_data_components, 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.