From ab5b3659efebcb46370faf07b08e45d19c337854 Mon Sep 17 00:00:00 2001
From: MARMAJOU ISABELLE <id.counilh@wanadoo.fr>
Date: Fri, 7 Mar 2025 17:16:24 +0100
Subject: [PATCH] Fix parabolic triangle VTK output

---
 src/output/VTKWriter.cpp | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/output/VTKWriter.cpp b/src/output/VTKWriter.cpp
index b5f9800a2..19a613610 100644
--- a/src/output/VTKWriter.cpp
+++ b/src/output/VTKWriter.cpp
@@ -606,14 +606,15 @@ VTKWriter::_write(const MeshType& mesh,
 
       Array<unsigned int> offsets(mesh.numberOfCells());
       unsigned int offset = 0;
-      for (CellId j = 0; j < mesh.numberOfCells(); ++j) {
-        const auto& cell_nodes = cell_to_node_matrix[j];
+      for (CellId cell_id = 0; cell_id < mesh.numberOfCells(); ++cell_id) {
+        const auto& cell_nodes = cell_to_node_matrix[cell_id];
         offset += degree * cell_nodes.size();
-        offsets[j] = offset;
+        offsets[cell_id] = offset;
       }
       _write_array(fout, "offsets", offsets, serialize_data_list);
 
       const auto& cell_to_face_matrix = mesh.connectivity().cellToFaceMatrix();
+      const auto& cell_type           = mesh.connectivity().cellType();
 
       Array<NodeId::base_type> nodes{offset};
       size_t index = 0;
@@ -624,8 +625,14 @@ VTKWriter::_write(const MeshType& mesh,
           nodes[index++] = cell_nodes[i_node];
         }
         if (degree == 2) {
-          for (size_t i_face = 0; i_face < cell_faces.size(); ++i_face) {
-            nodes[index++] = number_of_vertices + cell_faces[i_face];
+          if (cell_type[cell_id] == CellType::Triangle) {
+            for (size_t i_face = 0; i_face < cell_faces.size(); ++i_face) {
+              nodes[index++] = number_of_vertices + cell_faces[(i_face + 2) % 3];
+            }
+          } else {
+            for (size_t i_face = 0; i_face < cell_faces.size(); ++i_face) {
+              nodes[index++] = number_of_vertices + cell_faces[i_face];
+            }
           }
         }
       }
-- 
GitLab