From 659d2fa3fe149205ba3b4d8dca5997579583c490 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 30 Dec 2022 15:15:29 -0700 Subject: [PATCH] Move an if-condition into the body of a loop, rather than repeating the loop. --- source/base/data_out_base.cc | 306 ++++++++++++++++------------------- 1 file changed, 136 insertions(+), 170 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 650959b266..9a460e5198 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -5861,184 +5861,46 @@ namespace DataOutBase << ascii_or_binary << "\">\n"; std::vector cells; - if (flags.write_higher_order_cells) - { - Assert(dim <= 3 && dim > 1, ExcNotImplemented()); - unsigned int first_vertex_of_patch = 0; - - for (const auto &patch : patches) - { - if (patch.reference_cell != ReferenceCells::get_hypercube()) - { - // Array to hold all the node numbers of a cell - std::vector connectivity(patch.data.n_cols()); + Assert(dim <= 3, ExcNotImplemented()); - for (unsigned int i = 0; i < patch.data.n_cols(); ++i) - connectivity[i] = i; + unsigned int first_vertex_of_patch = 0; - if (deal_ii_with_zlib && - (flags.compression_level != - DataOutBase::CompressionLevel::plain_text)) - { - for (const auto &c : connectivity) - cells.push_back(first_vertex_of_patch + c); - } - else - { - for (const auto &c : connectivity) - o << '\t' << first_vertex_of_patch + c; - o << '\n'; - } + for (const auto &patch : patches) + { + // special treatment of simplices since they are not subdivided + if (patch.reference_cell != ReferenceCells::get_hypercube()) + { + const unsigned int n_points = patch.data.n_cols(); + static const std::array + pyramid_index_translation_table = {{0, 1, 3, 2, 4}}; - first_vertex_of_patch += patch.data.n_cols(); + if (deal_ii_with_zlib && + (flags.compression_level != + DataOutBase::CompressionLevel::plain_text)) + { + for (unsigned int i = 0; i < n_points; ++i) + cells.push_back( + first_vertex_of_patch + + (patch.reference_cell == ReferenceCells::Pyramid ? + pyramid_index_translation_table[i] : + i)); } else { - const unsigned int n_subdivisions = patch.n_subdivisions; - const unsigned int n = n_subdivisions + 1; - - // Array to hold all the node numbers of a cell - std::vector connectivity( - Utilities::fixed_power(n)); - - 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 = - patch.reference_cell - .template vtk_lexicographic_to_node_index<1>( - {{i1}}, - {{n_subdivisions}}, - /* use VTU, not VTK: */ false); - connectivity[connectivity_index] = local_index; - } - - break; - } - case 2: - { - 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 = - patch.reference_cell - .template vtk_lexicographic_to_node_index< - 2>({{i1, i2}}, - {{n_subdivisions, n_subdivisions}}, - /* use VTU, not VTK: */ false); - 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 = - patch.reference_cell - .template vtk_lexicographic_to_node_index< - 3>({{i1, i2, i3}}, - {{n_subdivisions, - n_subdivisions, - n_subdivisions}}, - /* use VTU, not VTK: */ false); - connectivity[connectivity_index] = - local_index; - } - - break; - } - default: - Assert(false, ExcNotImplemented()); - } - - // Having so set up the 'connectivity' data structure, - // output it: - if (deal_ii_with_zlib && - (flags.compression_level != - DataOutBase::CompressionLevel::plain_text)) - { - for (const auto &c : connectivity) - cells.push_back(first_vertex_of_patch + c); - } - else - { - for (const auto &c : connectivity) - o << '\t' << first_vertex_of_patch + c; - o << '\n'; - } - - // Finally update the number of the first vertex of this - // patch - first_vertex_of_patch += Utilities::fixed_power(n); + for (unsigned int i = 0; i < n_points; ++i) + o << '\t' + << first_vertex_of_patch + + (patch.reference_cell == ReferenceCells::Pyramid ? + pyramid_index_translation_table[i] : + i); + o << '\n'; } - } - } - else // do not as higher-order cells - { - Assert(dim <= 3, ExcNotImplemented()); - unsigned int first_vertex_of_patch = 0; - - for (const auto &patch : patches) + first_vertex_of_patch += n_points; + } + else // a hypercube cell { - // special treatment of simplices since they are not subdivided - if (patch.reference_cell != ReferenceCells::get_hypercube()) - { - const unsigned int n_points = patch.data.n_cols(); - static const std::array - pyramid_index_translation_table = {{0, 1, 3, 2, 4}}; - - if (deal_ii_with_zlib && - (flags.compression_level != - DataOutBase::CompressionLevel::plain_text)) - { - for (unsigned int i = 0; i < n_points; ++i) - cells.push_back( - first_vertex_of_patch + - (patch.reference_cell == ReferenceCells::Pyramid ? - pyramid_index_translation_table[i] : - i)); - } - else - { - for (unsigned int i = 0; i < n_points; ++i) - o << '\t' - << first_vertex_of_patch + - (patch.reference_cell == - ReferenceCells::Pyramid ? - pyramid_index_translation_table[i] : - i); - o << '\n'; - } - - first_vertex_of_patch += n_points; - } - else + if (flags.write_higher_order_cells == false) { const unsigned int n_subdivisions = patch.n_subdivisions; const unsigned int n_points_per_direction = @@ -6209,10 +6071,114 @@ namespace DataOutBase Assert(false, ExcNotImplemented()); } - // 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_subdivisions + 1); } + else // use higher-order output + { + const unsigned int n_subdivisions = patch.n_subdivisions; + const unsigned int n = n_subdivisions + 1; + + std::vector connectivity( + Utilities::fixed_power(n)); + + 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 = + patch.reference_cell + .template vtk_lexicographic_to_node_index<1>( + {{i1}}, + {{n_subdivisions}}, + /* use VTU, not VTK: */ false); + connectivity[connectivity_index] = local_index; + } + + break; + } + case 2: + { + 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 = + patch.reference_cell + .template vtk_lexicographic_to_node_index< + 2>({{i1, i2}}, + {{n_subdivisions, n_subdivisions}}, + /* use VTU, not VTK: */ false); + 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 = + patch.reference_cell + .template vtk_lexicographic_to_node_index< + 3>({{i1, i2, i3}}, + {{n_subdivisions, + n_subdivisions, + n_subdivisions}}, + /* use VTU, not VTK: */ false); + connectivity[connectivity_index] = + local_index; + } + + break; + } + default: + Assert(false, ExcNotImplemented()); + } + + // Having so set up the 'connectivity' data structure, + // output it: + if (deal_ii_with_zlib && + (flags.compression_level != + DataOutBase::CompressionLevel::plain_text)) + { + for (const auto &c : connectivity) + cells.push_back(first_vertex_of_patch + c); + } + else + { + for (const auto &c : connectivity) + o << '\t' << first_vertex_of_patch + c; + o << '\n'; + } + + // Finally update the number of the first vertex of this + // patch + first_vertex_of_patch += Utilities::fixed_power(n); + } } } -- 2.39.5