From a19b121f23df2644aae6f9abe0739a60fff16035 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 18 Nov 2022 15:51:49 -0700 Subject: [PATCH] Simplify some code. --- source/base/data_out_base.cc | 127 +++++++++++++++++++++++++++-------- 1 file changed, 98 insertions(+), 29 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 5fc55469b9..2d60e8f361 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -1986,41 +1986,66 @@ namespace #ifdef DEAL_II_WITH_ZLIB if (flags.compression_level != DataOutBase::CompressionLevel::plain_text) { - cells.push_back(start); - if (dim >= 1) + switch (dim) { - cells.push_back(start + d1); - if (dim >= 2) - { - cells.push_back(start + d2 + d1); - cells.push_back(start + d2); - if (dim >= 3) - { - cells.push_back(start + d3); - cells.push_back(start + d3 + d1); - cells.push_back(start + d3 + d2 + d1); - cells.push_back(start + d3 + d2); - } - } + case 0: + cells.push_back(start); + break; + + case 1: + cells.push_back(start); + cells.push_back(start + d1); + break; + + case 2: + cells.push_back(start); + cells.push_back(start + d1); + cells.push_back(start + d2 + d1); + cells.push_back(start + d2); + break; + + case 3: + cells.push_back(start); + cells.push_back(start + d1); + cells.push_back(start + d2 + d1); + cells.push_back(start + d2); + cells.push_back(start + d3); + cells.push_back(start + d3 + d1); + cells.push_back(start + d3 + d2 + d1); + cells.push_back(start + d3 + d2); + break; + + default: + Assert(false, ExcNotImplemented()); } } else #endif { - stream << start; - if (dim >= 1) + switch (dim) { - stream << '\t' << start + d1; - if (dim >= 2) - { - stream << '\t' << start + d2 + d1 << '\t' << start + d2; - if (dim >= 3) - { - stream << '\t' << start + d3 << '\t' << start + d3 + d1 - << '\t' << start + d3 + d2 + d1 << '\t' - << start + d3 + d2; - } - } + case 0: + stream << start; + break; + + case 1: + stream << start << '\t' << start + d1; + break; + + case 2: + stream << start << '\t' << start + d1 << '\t' << start + d2 + d1 + << '\t' << start + d2; + break; + + case 3: + stream << start << '\t' << start + d1 << '\t' << start + d2 + d1 + << '\t' << start + d2 << '\t' << start + d3 << '\t' + << start + d3 + d1 << '\t' << start + d3 + d2 + d1 << '\t' + << start + d3 + d2; + break; + + default: + Assert(false, ExcNotImplemented()); } stream << '\n'; } @@ -6098,7 +6123,51 @@ namespace DataOutBase if (flags.write_higher_order_cells) write_high_order_cells(patches, vtu_out, /* legacy_format = */ false); else - write_cells(patches, vtu_out); + { + Assert(dim <= 3, ExcNotImplemented()); + unsigned int count = 0; + unsigned int first_vertex_of_patch = 0; + for (const auto &patch : patches) + { + // special treatment of simplices since they are not subdivided + if (patch.reference_cell != ReferenceCells::get_hypercube()) + { + vtu_out.write_cell_single(count++, + first_vertex_of_patch, + patch.data.n_cols(), + patch.reference_cell); + first_vertex_of_patch += patch.data.n_cols(); + } + else + { + const unsigned int n_subdivisions = patch.n_subdivisions; + const unsigned int n = n_subdivisions + 1; + // Length of loops in all dimensions + const unsigned int n1 = (dim > 0) ? n_subdivisions : 1; + const unsigned int n2 = (dim > 1) ? n_subdivisions : 1; + const unsigned int n3 = (dim > 2) ? n_subdivisions : 1; + // Offsets of outer loops + const 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) + { + const unsigned int offset = + first_vertex_of_patch + i3 * d3 + i2 * d2 + i1 * d1; + // First write line in x direction + vtu_out.template write_cell( + count++, offset, d1, d2, d3); + } + // finally update the number of the first vertex of this patch + first_vertex_of_patch += + Utilities::fixed_power(n_subdivisions + 1); + } + } + + vtu_out.flush_cells(); + } out << " \n"; // XML VTU format uses offsets; this is different than the VTK format, which -- 2.39.5