From e2aacc6bf57f2807e59ee6476c8007d0a89ede4a Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 24 Oct 2021 19:47:54 -0600 Subject: [PATCH] Make Patch<0,spacedim>::n_subdivisions a 'const' variable. --- include/deal.II/base/data_out_base.h | 2 +- source/base/data_out_base.cc | 19 +++++++++++++++++-- source/particles/data_out.cc | 5 ++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/deal.II/base/data_out_base.h b/include/deal.II/base/data_out_base.h index 6d8e17febd..c517955581 100644 --- a/include/deal.II/base/data_out_base.h +++ b/include/deal.II/base/data_out_base.h @@ -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: data(i,.) denotes the diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 295babfe60..f2a28610de 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -2070,7 +2070,7 @@ namespace DataOutBase Patch<0, spacedim>::no_neighbor}; template - unsigned int Patch<0, spacedim>::n_subdivisions = 1; + const unsigned int Patch<0, spacedim>::n_subdivisions = 1; template 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(patch.n_subdivisions) = n_subdivisions; +#endif in >> patch.points_are_available; diff --git a/source/particles/data_out.cc b/source/particles/data_out.cc index 901a7ea050..f0c7273b21 100644 --- a/source/particles/data_out.cc +++ b/source/particles/data_out.cc @@ -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); -- 2.39.5