From eb480101d7d82a791d48870293a325f452aabbd6 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Fri, 29 Jun 2018 18:21:05 +0200
Subject: [PATCH] Added simple 3d hexahedra output

Should differentiate a bit more dimensional outputs
---
 src/output/VTKWriter.hpp | 100 +++++++++++++++++++++------------------
 1 file changed, 54 insertions(+), 46 deletions(-)

diff --git a/src/output/VTKWriter.hpp b/src/output/VTKWriter.hpp
index da7fc8bf2..50fb147c6 100644
--- a/src/output/VTKWriter.hpp
+++ b/src/output/VTKWriter.hpp
@@ -9,17 +9,17 @@
 
 class VTKWriter
 {
-private:
+ private:
   const std::string m_base_filename;
   unsigned int m_file_number;
   double m_last_time;
   const double m_time_period;
 
-public:
+ public:
   template <typename MeshType>
   void write(const MeshType& mesh,
-	     const double& time,
-	     const bool& forced_output = false)
+             const double& time,
+             const bool& forced_output = false)
   {
     if (time == m_last_time) return; // output already performed
     if ((time - m_last_time >= m_time_period) or forced_output) {
@@ -34,29 +34,33 @@ public:
     fout << "<VTKFile type=\"UnstructuredGrid\">\n";
     fout << "<UnstructuredGrid>\n";
     fout << "<Piece NumberOfPoints=\""<< mesh.numberOfNodes()
-	 << "\" NumberOfCells=\"" << mesh.numberOfCells() << "\">\n";
+         << "\" NumberOfCells=\"" << mesh.numberOfCells() << "\">\n";
 
     fout << "<Points>\n";
     fout << "<DataArray Name=\"Positions\" NumberOfComponents=\"3\" type=\"Float64\" format=\"ascii\">\n";
     if constexpr(MeshType::dimension ==1) {
-	const Kokkos::View<const TinyVector<1>*> xr = mesh.xr();
-	for (unsigned int r=0; r<mesh.numberOfNodes(); ++r) {
-	  for (unsigned short i=0; i<1; ++i) {
-	    fout << xr[r][i] << ' ';
-	  }
-	  fout << "0 0 "; // VTK requires 3 components
-	}
-      } else if constexpr (MeshType::dimension ==2) {
-	const Kokkos::View<const TinyVector<2>*> xr = mesh.xr();
-	for (unsigned int r=0; r<mesh.numberOfNodes(); ++r) {
-	  for (unsigned short i=0; i<2; ++i) {
-	    fout << xr[r][i] << ' ';
-	  }
-	  fout << "0 "; // VTK requires 3 components
-	}
+      const Kokkos::View<const TinyVector<1>*> xr = mesh.xr();
+      for (unsigned int r=0; r<mesh.numberOfNodes(); ++r) {
+        for (unsigned short i=0; i<1; ++i) {
+          fout << xr[r][i] << ' ';
+        }
+        fout << "0 0 "; // VTK requires 3 components
+      }
+    } else if constexpr (MeshType::dimension ==2) {
+      const Kokkos::View<const TinyVector<2>*> xr = mesh.xr();
+      for (unsigned int r=0; r<mesh.numberOfNodes(); ++r) {
+        for (unsigned short i=0; i<2; ++i) {
+          fout << xr[r][i] << ' ';
+        }
+        fout << "0 "; // VTK requires 3 components
+      }
     } else {
-      std::cerr << "VTKWriter not implemented in dimension " << MeshType::dimension << '\n';
-      std::exit(1);
+      const Kokkos::View<const TinyVector<3>*> xr = mesh.xr();
+      for (unsigned int r=0; r<mesh.numberOfNodes(); ++r) {
+        for (unsigned short i=0; i<3; ++i) {
+          fout << xr[r][i] << ' ';
+        }
+      }
     }
     fout << '\n';
     fout << "</DataArray>\n";
@@ -69,7 +73,7 @@ public:
     fout << "<DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
     for (unsigned int j=0; j<mesh.numberOfCells(); ++j) {
       for (unsigned short r=0; r<cell_nb_nodes[j]; ++r) {
-	fout << cell_nodes(j,r) << ' ';
+        fout << cell_nodes(j,r) << ' ';
       }
     }
     fout << '\n';
@@ -79,8 +83,8 @@ public:
     {
       unsigned int offset=0;
       for (unsigned int j=0; j<mesh.numberOfCells(); ++j) {
-	offset += cell_nb_nodes[j];
-	fout << offset << ' ';
+        offset += cell_nb_nodes[j];
+        fout << offset << ' ';
       }
     }
     fout << '\n';
@@ -89,22 +93,26 @@ public:
     fout << "<DataArray type=\"Int8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">\n";
     for (unsigned int j=0; j<mesh.numberOfCells(); ++j) {
       switch (cell_nb_nodes[j]) {
-      case 2: {
-	fout << "3 ";
-	break;
-      }
-      case 3: {
-	fout << "5 ";
-	break;
-      }
-      case 4: {
-	fout << "9 ";
-	break;
-      }
-      default: {
-	fout << "7 ";
-	break;
-      }
+        case 2: {
+          fout << "3 ";
+          break;
+        }
+        case 3: {
+          fout << "5 ";
+          break;
+        }
+        case 4: {
+          fout << "9 ";
+          break;
+        }
+        case 8: {
+          fout << "12 ";
+          break;
+        }
+        default: {
+          fout << "7 ";
+          break;
+        }
       }
     }
     fout << '\n';
@@ -118,11 +126,11 @@ public:
     m_file_number++;
   }
   VTKWriter(const std::string& base_filename,
-	    const double time_period)
-    : m_base_filename(base_filename),
-      m_file_number  (0),
-      m_last_time    (-std::numeric_limits<double>::max()),
-      m_time_period  (time_period)
+            const double time_period)
+      : m_base_filename(base_filename),
+        m_file_number  (0),
+        m_last_time    (-std::numeric_limits<double>::max()),
+        m_time_period  (time_period)
   {}
 
   ~VTKWriter() = default;
-- 
GitLab