From 3f136fd9d724c83bbde4760443dd8750b33314a8 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 9 Dec 2022 19:36:45 -0700 Subject: [PATCH] Replace one more occurrence of dim-predicated loops. --- source/base/data_out_base.cc | 74 +++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 000cde7d28..38b9579631 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -3088,31 +3088,69 @@ namespace DataOutBase cell_order.fill(n_subdivisions); connectivity.resize(Utilities::fixed_power(n)); - // Length of loops in all dimensons - const unsigned int n1 = (dim > 0) ? n_subdivisions : 0; - const unsigned int n2 = (dim > 1) ? n_subdivisions : 0; - const unsigned int n3 = (dim > 2) ? n_subdivisions : 0; - // Offsets of outer loops - constexpr 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: + { + 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 = + vtk_point_index_from_ijk( + i1, 0, 0, cell_order, legacy_format); + connectivity[connectivity_index] = local_index; + } + + break; + } + case 2: { - const unsigned int local_index = - i3 * d3 + i2 * d2 + i1 * d1; - const unsigned int connectivity_index = - vtk_point_index_from_ijk( - i1, i2, i3, cell_order, legacy_format); - connectivity[connectivity_index] = local_index; + 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 connectivity_index = + vtk_point_index_from_ijk( + i1, i2, 0, cell_order, legacy_format); + 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 = + vtk_point_index_from_ijk( + i1, i2, i3, cell_order, legacy_format); + connectivity[connectivity_index] = local_index; + } + + break; } + default: + Assert(false, ExcNotImplemented()); + } + // Having so set up the 'connectivity' data structure, + // output it: out.template write_high_order_cell(count++, first_vertex_of_patch, connectivity); - // finally update the number of the first vertex of this patch + // Finally update the number of the first vertex of this patch first_vertex_of_patch += Utilities::fixed_power(n); } } -- 2.39.5