From ec798f7be76791b460420352bb6bd1f3d6e64530 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 8 Nov 2022 21:30:58 -0700 Subject: [PATCH] Re-factor the use of write_nodes() for VTU output. As part of this, just output the vertex locations as one big array (like all other data), rather than breaking it every three coordinates onto a separate line. --- source/base/data_out_base.cc | 142 ++++----- ...u_compression_levels.with_zlib=true.output | 295 +----------------- 2 files changed, 68 insertions(+), 369 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 5b368382ff..7320294069 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -1508,13 +1508,6 @@ namespace public: VtuStream(std::ostream &stream, const DataOutBase::VtkFlags &flags); - template - void - write_point(const unsigned int index, const Point &); - - void - flush_points(); - /** * The order of vertices for these cells in different dimensions is *
    @@ -1949,54 +1942,13 @@ namespace stream << '\n'; } + + VtuStream::VtuStream(std::ostream &out, const DataOutBase::VtkFlags &f) : StreamBase(out, f) {} - template - void - VtuStream::write_point(const unsigned int, const Point &p) - { -#ifdef DEAL_II_WITH_ZLIB - if (flags.compression_level != DataOutBase::CompressionLevel::plain_text) - { - // if we want to compress, then first collect all the data in an array - for (unsigned int i = 0; i < dim; ++i) - vertices.push_back(p[i]); - for (unsigned int i = dim; i < 3; ++i) - vertices.push_back(0); - } - else -#endif - { - // write out coordinates - stream << p; - // fill with zeroes - for (unsigned int i = dim; i < 3; ++i) - stream << " 0"; - stream << '\n'; - } - } - - - void - VtuStream::flush_points() - { -#ifdef DEAL_II_WITH_ZLIB - if (flags.compression_level != DataOutBase::CompressionLevel::plain_text) - { - // compress the data we have in memory and write them to the stream. - // then release the data - *this << vtu_stringize_array(vertices, - flags.compression_level, - stream.precision()) - << '\n'; - vertices.clear(); - } -#endif - } - template void @@ -2900,15 +2852,19 @@ namespace DataOutBase //----------------------------------------------------------------------// - template - void - write_nodes(const std::vector> &patches, StreamType &out) + + /** + * Obtain the positions of all nodes referenced in the patches given as + * argument. + */ + template + std::vector> + get_node_positions(const std::vector> &patches) { Assert(dim <= 3, ExcNotImplemented()); - unsigned int count = 0; - static const std::array table = {{0, 1, 3, 2, 4}}; + std::vector> node_positions; for (const auto &patch : patches) { // special treatment of non-hypercube cells @@ -2916,12 +2872,11 @@ namespace DataOutBase { for (unsigned int point_no = 0; point_no < patch.data.n_cols(); ++point_no) - out.write_point(count++, - get_node_location(patch, - (patch.reference_cell == - ReferenceCells::Pyramid ? - table[point_no] : - point_no))); + node_positions.emplace_back(get_node_location( + patch, + (patch.reference_cell == ReferenceCells::Pyramid ? + table[point_no] : + point_no))); } else { @@ -2931,33 +2886,26 @@ namespace DataOutBase switch (dim) { case 0: - out.write_point(count++, - get_equispaced_location(patch, - {}, - n_subdivisions)); + node_positions.emplace_back( + get_equispaced_location(patch, {}, n_subdivisions)); break; case 1: for (unsigned int i1 = 0; i1 < n; ++i1) - out.write_point(count++, - get_equispaced_location(patch, - {i1}, - n_subdivisions)); + node_positions.emplace_back( + get_equispaced_location(patch, {i1}, n_subdivisions)); break; case 2: for (unsigned int i2 = 0; i2 < n; ++i2) for (unsigned int i1 = 0; i1 < n; ++i1) - out.write_point(count++, - get_equispaced_location(patch, - {i1, i2}, - n_subdivisions)); + node_positions.emplace_back(get_equispaced_location( + patch, {i1, i2}, n_subdivisions)); break; case 3: for (unsigned int i3 = 0; i3 < n; ++i3) for (unsigned int i2 = 0; i2 < n; ++i2) for (unsigned int i1 = 0; i1 < n; ++i1) - out.write_point(count++, - get_equispaced_location( - patch, {i1, i2, i3}, n_subdivisions)); + node_positions.emplace_back(get_equispaced_location( + patch, {i1, i2, i3}, n_subdivisions)); break; default: @@ -2965,9 +2913,28 @@ namespace DataOutBase } } } + + return node_positions; + } + + + template + void + write_nodes(const std::vector> &patches, StreamType &out) + { + // Obtain the node locations, and then output them via the given stream + // object + const std::vector> node_positions = + get_node_positions(patches); + + int count = 0; + for (const auto &node : node_positions) + out.write_point(count++, node); out.flush_points(); } + + template void write_cells(const std::vector> &patches, StreamType &out) @@ -6094,7 +6061,28 @@ namespace DataOutBase out << " \n"; out << " \n"; - write_nodes(patches, vtu_out); + const std::vector> node_positions = + get_node_positions(patches); + std::vector node_coordinates_3d; + node_coordinates_3d.reserve(node_positions.size() * 3); + for (const auto &node_position : node_positions) + { + node_coordinates_3d.emplace_back(node_position[0]); + + if (spacedim >= 2) + node_coordinates_3d.emplace_back(node_position[1]); + else + node_coordinates_3d.emplace_back(0.0f); + + if (spacedim >= 3) + node_coordinates_3d.emplace_back(node_position[2]); + else + node_coordinates_3d.emplace_back(0.0f); + } + out << vtu_stringize_array(node_coordinates_3d, + flags.compression_level, + out.precision()) + << '\n'; out << " \n"; out << " \n\n"; //------------------------------- diff --git a/tests/data_out/data_out_base_vtu_compression_levels.with_zlib=true.output b/tests/data_out/data_out_base_vtu_compression_levels.with_zlib=true.output index 40b33aa0f0..a55b2c1aff 100644 --- a/tests/data_out/data_out_base_vtu_compression_levels.with_zlib=true.output +++ b/tests/data_out/data_out_base_vtu_compression_levels.with_zlib=true.output @@ -203,20 +203,7 @@ AQAAADgAAAA4AAAAGAAAAA==eJxjYACBBnsGBO2AynbAwm9wAACFNAV9 -0 0 0 -1 0 0 -1 0 0 -1.5 0 0 -2 0 0 -2 0 0 -2.33333 0 0 -2.66667 0 0 -3 0 0 -3 0 0 -3.25 0 0 -3.5 0 0 -3.75 0 0 -4 0 0 +0 0 0 1 0 0 1 0 0 1.5 0 0 2 0 0 2 0 0 2.33333 0 0 2.66667 0 0 3 0 0 3 0 0 3.25 0 0 3.5 0 0 3.75 0 0 4 0 0 @@ -465,60 +452,7 @@ AQAAANgAAADYAAAATQAAAA==eJxjYACBBnsg4QBEDgwY/AYgXgDEB4D4AUjekTg1AkCsAMQGQOwAxAFA -0 0 0 -1 0 0 -0 1 0 -1 1 0 -1 1 0 -1.5 1 0 -2 1 0 -1 1.5 0 -1.5 1.5 0 -2 1.5 0 -1 2 0 -1.5 2 0 -2 2 0 -2 2 0 -2.33333 2 0 -2.66667 2 0 -3 2 0 -2 2.33333 0 -2.33333 2.33333 0 -2.66667 2.33333 0 -3 2.33333 0 -2 2.66667 0 -2.33333 2.66667 0 -2.66667 2.66667 0 -3 2.66667 0 -2 3 0 -2.33333 3 0 -2.66667 3 0 -3 3 0 -3 3 0 -3.25 3 0 -3.5 3 0 -3.75 3 0 -4 3 0 -3 3.25 0 -3.25 3.25 0 -3.5 3.25 0 -3.75 3.25 0 -4 3.25 0 -3 3.5 0 -3.25 3.5 0 -3.5 3.5 0 -3.75 3.5 0 -4 3.5 0 -3 3.75 0 -3.25 3.75 0 -3.5 3.75 0 -3.75 3.75 0 -4 3.75 0 -3 4 0 -3.25 4 0 -3.5 4 0 -3.75 4 0 -4 4 0 +0 0 0 1 0 0 0 1 0 1 1 0 1 1 0 1.5 1 0 2 1 0 1 1.5 0 1.5 1.5 0 2 1.5 0 1 2 0 1.5 2 0 2 2 0 2 2 0 2.33333 2 0 2.66667 2 0 3 2 0 2 2.33333 0 2.33333 2.33333 0 2.66667 2.33333 0 3 2.33333 0 2 2.66667 0 2.33333 2.66667 0 2.66667 2.66667 0 3 2.66667 0 2 3 0 2.33333 3 0 2.66667 3 0 3 3 0 3 3 0 3.25 3 0 3.5 3 0 3.75 3 0 4 3 0 3 3.25 0 3.25 3.25 0 3.5 3.25 0 3.75 3.25 0 4 3.25 0 3 3.5 0 3.25 3.5 0 3.5 3.5 0 3.75 3.5 0 4 3.5 0 3 3.75 0 3.25 3.75 0 3.5 3.75 0 3.75 3.75 0 4 3.75 0 3 4 0 3.25 4 0 3.5 4 0 3.75 4 0 4 4 0 @@ -787,230 +721,7 @@ AQAAAIADAACAAwAA/wAAAA==eJztz7ErhAEYB+BvMBgMBoPBcIPBYLjBYFC+uwwGww0Gg8FgMBhuMBgM -0 0 0 -1 0 0 -0 1 0 -1 1 0 -0 0 1 -1 0 1 -0 1 1 -1 1 1 -1 1 1 -1.5 1 1 -2 1 1 -1 1.5 1 -1.5 1.5 1 -2 1.5 1 -1 2 1 -1.5 2 1 -2 2 1 -1 1 1.5 -1.5 1 1.5 -2 1 1.5 -1 1.5 1.5 -1.5 1.5 1.5 -2 1.5 1.5 -1 2 1.5 -1.5 2 1.5 -2 2 1.5 -1 1 2 -1.5 1 2 -2 1 2 -1 1.5 2 -1.5 1.5 2 -2 1.5 2 -1 2 2 -1.5 2 2 -2 2 2 -2 2 2 -2.33333 2 2 -2.66667 2 2 -3 2 2 -2 2.33333 2 -2.33333 2.33333 2 -2.66667 2.33333 2 -3 2.33333 2 -2 2.66667 2 -2.33333 2.66667 2 -2.66667 2.66667 2 -3 2.66667 2 -2 3 2 -2.33333 3 2 -2.66667 3 2 -3 3 2 -2 2 2.33333 -2.33333 2 2.33333 -2.66667 2 2.33333 -3 2 2.33333 -2 2.33333 2.33333 -2.33333 2.33333 2.33333 -2.66667 2.33333 2.33333 -3 2.33333 2.33333 -2 2.66667 2.33333 -2.33333 2.66667 2.33333 -2.66667 2.66667 2.33333 -3 2.66667 2.33333 -2 3 2.33333 -2.33333 3 2.33333 -2.66667 3 2.33333 -3 3 2.33333 -2 2 2.66667 -2.33333 2 2.66667 -2.66667 2 2.66667 -3 2 2.66667 -2 2.33333 2.66667 -2.33333 2.33333 2.66667 -2.66667 2.33333 2.66667 -3 2.33333 2.66667 -2 2.66667 2.66667 -2.33333 2.66667 2.66667 -2.66667 2.66667 2.66667 -3 2.66667 2.66667 -2 3 2.66667 -2.33333 3 2.66667 -2.66667 3 2.66667 -3 3 2.66667 -2 2 3 -2.33333 2 3 -2.66667 2 3 -3 2 3 -2 2.33333 3 -2.33333 2.33333 3 -2.66667 2.33333 3 -3 2.33333 3 -2 2.66667 3 -2.33333 2.66667 3 -2.66667 2.66667 3 -3 2.66667 3 -2 3 3 -2.33333 3 3 -2.66667 3 3 -3 3 3 -3 3 3 -3.25 3 3 -3.5 3 3 -3.75 3 3 -4 3 3 -3 3.25 3 -3.25 3.25 3 -3.5 3.25 3 -3.75 3.25 3 -4 3.25 3 -3 3.5 3 -3.25 3.5 3 -3.5 3.5 3 -3.75 3.5 3 -4 3.5 3 -3 3.75 3 -3.25 3.75 3 -3.5 3.75 3 -3.75 3.75 3 -4 3.75 3 -3 4 3 -3.25 4 3 -3.5 4 3 -3.75 4 3 -4 4 3 -3 3 3.25 -3.25 3 3.25 -3.5 3 3.25 -3.75 3 3.25 -4 3 3.25 -3 3.25 3.25 -3.25 3.25 3.25 -3.5 3.25 3.25 -3.75 3.25 3.25 -4 3.25 3.25 -3 3.5 3.25 -3.25 3.5 3.25 -3.5 3.5 3.25 -3.75 3.5 3.25 -4 3.5 3.25 -3 3.75 3.25 -3.25 3.75 3.25 -3.5 3.75 3.25 -3.75 3.75 3.25 -4 3.75 3.25 -3 4 3.25 -3.25 4 3.25 -3.5 4 3.25 -3.75 4 3.25 -4 4 3.25 -3 3 3.5 -3.25 3 3.5 -3.5 3 3.5 -3.75 3 3.5 -4 3 3.5 -3 3.25 3.5 -3.25 3.25 3.5 -3.5 3.25 3.5 -3.75 3.25 3.5 -4 3.25 3.5 -3 3.5 3.5 -3.25 3.5 3.5 -3.5 3.5 3.5 -3.75 3.5 3.5 -4 3.5 3.5 -3 3.75 3.5 -3.25 3.75 3.5 -3.5 3.75 3.5 -3.75 3.75 3.5 -4 3.75 3.5 -3 4 3.5 -3.25 4 3.5 -3.5 4 3.5 -3.75 4 3.5 -4 4 3.5 -3 3 3.75 -3.25 3 3.75 -3.5 3 3.75 -3.75 3 3.75 -4 3 3.75 -3 3.25 3.75 -3.25 3.25 3.75 -3.5 3.25 3.75 -3.75 3.25 3.75 -4 3.25 3.75 -3 3.5 3.75 -3.25 3.5 3.75 -3.5 3.5 3.75 -3.75 3.5 3.75 -4 3.5 3.75 -3 3.75 3.75 -3.25 3.75 3.75 -3.5 3.75 3.75 -3.75 3.75 3.75 -4 3.75 3.75 -3 4 3.75 -3.25 4 3.75 -3.5 4 3.75 -3.75 4 3.75 -4 4 3.75 -3 3 4 -3.25 3 4 -3.5 3 4 -3.75 3 4 -4 3 4 -3 3.25 4 -3.25 3.25 4 -3.5 3.25 4 -3.75 3.25 4 -4 3.25 4 -3 3.5 4 -3.25 3.5 4 -3.5 3.5 4 -3.75 3.5 4 -4 3.5 4 -3 3.75 4 -3.25 3.75 4 -3.5 3.75 4 -3.75 3.75 4 -4 3.75 4 -3 4 4 -3.25 4 4 -3.5 4 4 -3.75 4 4 -4 4 4 +0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1.5 1 1 2 1 1 1 1.5 1 1.5 1.5 1 2 1.5 1 1 2 1 1.5 2 1 2 2 1 1 1 1.5 1.5 1 1.5 2 1 1.5 1 1.5 1.5 1.5 1.5 1.5 2 1.5 1.5 1 2 1.5 1.5 2 1.5 2 2 1.5 1 1 2 1.5 1 2 2 1 2 1 1.5 2 1.5 1.5 2 2 1.5 2 1 2 2 1.5 2 2 2 2 2 2 2 2 2.33333 2 2 2.66667 2 2 3 2 2 2 2.33333 2 2.33333 2.33333 2 2.66667 2.33333 2 3 2.33333 2 2 2.66667 2 2.33333 2.66667 2 2.66667 2.66667 2 3 2.66667 2 2 3 2 2.33333 3 2 2.66667 3 2 3 3 2 2 2 2.33333 2.33333 2 2.33333 2.66667 2 2.33333 3 2 2.33333 2 2.33333 2.33333 2.33333 2.33333 2.33333 2.66667 2.33333 2.33333 3 2.33333 2.33333 2 2.66667 2.33333 2.33333 2.66667 2.33333 2.66667 2.66667 2.33333 3 2.66667 2.33333 2 3 2.33333 2.33333 3 2.33333 2.66667 3 2.33333 3 3 2.33333 2 2 2.66667 2.33333 2 2.66667 2.66667 2 2.66667 3 2 2.66667 2 2.33333 2.66667 2.33333 2.33333 2.66667 2.66667 2.33333 2.66667 3 2.33333 2.66667 2 2.66667 2.66667 2.33333 2.66667 2.66667 2.66667 2.66667 2.66667 3 2.66667 2.66667 2 3 2.66667 2.33333 3 2.66667 2.66667 3 2.66667 3 3 2.66667 2 2 3 2.33333 2 3 2.66667 2 3 3 2 3 2 2.33333 3 2.33333 2.33333 3 2.66667 2.33333 3 3 2.33333 3 2 2.66667 3 2.33333 2.66667 3 2.66667 2.66667 3 3 2.66667 3 2 3 3 2.33333 3 3 2.66667 3 3 3 3 3 3 3 3 3.25 3 3 3.5 3 3 3.75 3 3 4 3 3 3 3.25 3 3.25 3.25 3 3.5 3.25 3 3.75 3.25 3 4 3.25 3 3 3.5 3 3.25 3.5 3 3.5 3.5 3 3.75 3.5 3 4 3.5 3 3 3.75 3 3.25 3.75 3 3.5 3.75 3 3.75 3.75 3 4 3.75 3 3 4 3 3.25 4 3 3.5 4 3 3.75 4 3 4 4 3 3 3 3.25 3.25 3 3.25 3.5 3 3.25 3.75 3 3.25 4 3 3.25 3 3.25 3.25 3.25 3.25 3.25 3.5 3.25 3.25 3.75 3.25 3.25 4 3.25 3.25 3 3.5 3.25 3.25 3.5 3.25 3.5 3.5 3.25 3.75 3.5 3.25 4 3.5 3.25 3 3.75 3.25 3.25 3.75 3.25 3.5 3.75 3.25 3.75 3.75 3.25 4 3.75 3.25 3 4 3.25 3.25 4 3.25 3.5 4 3.25 3.75 4 3.25 4 4 3.25 3 3 3.5 3.25 3 3.5 3.5 3 3.5 3.75 3 3.5 4 3 3.5 3 3.25 3.5 3.25 3.25 3.5 3.5 3.25 3.5 3.75 3.25 3.5 4 3.25 3.5 3 3.5 3.5 3.25 3.5 3.5 3.5 3.5 3.5 3.75 3.5 3.5 4 3.5 3.5 3 3.75 3.5 3.25 3.75 3.5 3.5 3.75 3.5 3.75 3.75 3.5 4 3.75 3.5 3 4 3.5 3.25 4 3.5 3.5 4 3.5 3.75 4 3.5 4 4 3.5 3 3 3.75 3.25 3 3.75 3.5 3 3.75 3.75 3 3.75 4 3 3.75 3 3.25 3.75 3.25 3.25 3.75 3.5 3.25 3.75 3.75 3.25 3.75 4 3.25 3.75 3 3.5 3.75 3.25 3.5 3.75 3.5 3.5 3.75 3.75 3.5 3.75 4 3.5 3.75 3 3.75 3.75 3.25 3.75 3.75 3.5 3.75 3.75 3.75 3.75 3.75 4 3.75 3.75 3 4 3.75 3.25 4 3.75 3.5 4 3.75 3.75 4 3.75 4 4 3.75 3 3 4 3.25 3 4 3.5 3 4 3.75 3 4 4 3 4 3 3.25 4 3.25 3.25 4 3.5 3.25 4 3.75 3.25 4 4 3.25 4 3 3.5 4 3.25 3.5 4 3.5 3.5 4 3.75 3.5 4 4 3.5 4 3 3.75 4 3.25 3.75 4 3.5 3.75 4 3.75 3.75 4 4 3.75 4 3 4 4 3.25 4 4 3.5 4 4 3.75 4 4 4 4 4 -- 2.39.5