From 4a41d5c64035be9f74eb213233814ed839950250 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 13 Jan 2023 13:12:26 -0700 Subject: [PATCH] Minor cleanup in the VTU writer. --- source/base/data_out_base.cc | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index d661106371..2cceadfa09 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -5811,23 +5811,17 @@ namespace DataOutBase const std::vector> node_positions = get_node_positions(patches); - // note that according to the standard, we have to print d=1..3 - // dimensions, even if we are in reality in 2d, for example + // VTK/VTU always wants to see three coordinates, even if we are + // in 1d or 2d. So pad node positions with zeros as appropriate. 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); + for (unsigned int d = 0; d < 3; ++d) + if (d < spacedim) + node_coordinates_3d.emplace_back(node_position[d]); + else + node_coordinates_3d.emplace_back(0.0f); } o << vtu_stringize_array(node_coordinates_3d, flags.compression_level, -- 2.39.5