From: Wolfgang Bangerth Date: Tue, 8 Nov 2022 22:09:37 +0000 (-0700) Subject: Do not use VtuStream to output data object; do it directly. X-Git-Tag: v9.5.0-rc1~858^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b0e7edb0424fc4954d7f5276fab80078316db58;p=dealii.git Do not use VtuStream to output data object; do it directly. --- diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index c520da53c4..5b368382ff 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -198,7 +198,44 @@ namespace else return {}; } + +#endif + + + + /** + * Convert an array of data objects into a string that will form part of + * what we then output as data into VTU objects. + * + * If libz was found during configuration, this function compresses and + * encodes the entire data block. Otherwise, it simply writes it element by + * element. + */ + template + std::string + vtu_stringize_array(const std::vector & data, + const DataOutBase::CompressionLevel compression_level, + const int precision) + { + (void)compression_level; + (void)precision; + +#ifdef DEAL_II_WITH_ZLIB + if (compression_level != DataOutBase::CompressionLevel::plain_text) + { + // compress the data we have in memory + return compress_array(data, compression_level); + } + else #endif + { + std::ostringstream stream; + stream.precision(precision); + for (unsigned int i = 0; i < data.size(); ++i) + stream << data[i] << ' '; + return stream.str(); + } + } /** @@ -1519,21 +1556,6 @@ namespace void flush_cells(); - template - std::ostream & - operator<<(const T &); - - /** - * Forwarding of output stream. - * - * If libz was found during configuration, this operator compresses and - * encodes the entire data block. Otherwise, it simply writes it element by - * element. - */ - template - std::ostream & - operator<<(const std::vector &); - private: /** * A list of vertices and cells, to be used in case we want to compress the @@ -1966,7 +1988,10 @@ namespace { // compress the data we have in memory and write them to the stream. // then release the data - *this << vertices << '\n'; + *this << vtu_stringize_array(vertices, + flags.compression_level, + stream.precision()) + << '\n'; vertices.clear(); } #endif @@ -2082,33 +2107,14 @@ namespace { // compress the data we have in memory and write them to the stream. // then release the data - *this << cells << '\n'; + *this << vtu_stringize_array(cells, + flags.compression_level, + stream.precision()) + << '\n'; cells.clear(); } #endif } - - - template - std::ostream & - VtuStream::operator<<(const std::vector &data) - { -#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 - stream << compress_array(data, flags.compression_level); - } - else -#endif - { - for (unsigned int i = 0; i < data.size(); ++i) - stream << data[i] << ' '; - } - - return stream; - } } // namespace @@ -6130,7 +6136,9 @@ namespace DataOutBase } } - vtu_out << offsets; + out << vtu_stringize_array(offsets, + flags.compression_level, + out.precision()); out << '\n'; out << " \n"; @@ -6147,12 +6155,16 @@ namespace DataOutBase for (unsigned int i = 0; i < cell_types.size(); ++i) cell_types_uint8_t[i] = static_cast(cell_types[i]); - vtu_out << cell_types_uint8_t; + vtu_out << vtu_stringize_array(cell_types_uint8_t, + flags.compression_level, + out.precision()); } else #endif { - vtu_out << cell_types; + vtu_out << vtu_stringize_array(cell_types, + flags.compression_level, + out.precision()); } out << '\n'; @@ -6320,7 +6332,9 @@ namespace DataOutBase } } // loop over nodes - vtu_out << data; + out << vtu_stringize_array(data, + flags.compression_level, + out.precision()); out << '\n'; out << " \n"; @@ -6341,9 +6355,11 @@ namespace DataOutBase out << ">\n"; - std::vector data(data_vectors[data_set].begin(), - data_vectors[data_set].end()); - vtu_out << data; + const std::vector data(data_vectors[data_set].begin(), + data_vectors[data_set].end()); + out << vtu_stringize_array(data, + flags.compression_level, + out.precision()); out << '\n'; out << " \n"; }