From d9f41bd6695b9d7da1a4856522f6254b375a9543 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Fri, 11 May 2018 17:49:16 +0200
Subject: [PATCH] Plugged VTKWriter to 1d meshes

---
 src/output/VTKWriter.hpp | 132 +++++++++++++++++++++------------------
 1 file changed, 72 insertions(+), 60 deletions(-)

diff --git a/src/output/VTKWriter.hpp b/src/output/VTKWriter.hpp
index b5d6ad685..070f24f22 100644
--- a/src/output/VTKWriter.hpp
+++ b/src/output/VTKWriter.hpp
@@ -30,16 +30,23 @@ public:
     std::ostringstream sout;
     sout << m_base_filename << '.' << std::setfill('0') << std::setw(4) << m_file_number << ".vtu" << std::ends;
     std::ofstream fout(sout.str());
-    if constexpr(MeshType::dimension ==2) {
-	fout << "<?xml version=\"1.0\"?>\n";
-	fout << "<VTKFile type=\"UnstructuredGrid\">\n";
-	fout << "<UnstructuredGrid>\n";
-	fout << "<Piece NumberOfPoints=\""<< mesh.numberOfNodes()
-	     << "\" NumberOfCells=\"" << mesh.numberOfCells() << "\">\n";
-
-	fout << "<Points>\n";
-	fout << "<DataArray Name=\"Positions\" NumberOfComponents=\"3\" type=\"Float64\" format=\"ascii\">\n";
+    fout << "<?xml version=\"1.0\"?>\n";
+    fout << "<VTKFile type=\"UnstructuredGrid\">\n";
+    fout << "<UnstructuredGrid>\n";
+    fout << "<Piece NumberOfPoints=\""<< mesh.numberOfNodes()
+	 << "\" 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 (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) {
@@ -47,62 +54,67 @@ public:
 	  }
 	  fout << "0 "; // VTK requires 3 components
 	}
-	fout << '\n';
-	fout << "</DataArray>\n";
-	fout << "</Points>\n";
-	fout << "<Cells>\n";
-
-	const Kokkos::View<const unsigned int**> cell_nodes = mesh.connectivity().cellNodes();
-	const Kokkos::View<const unsigned short*> cell_nb_nodes = mesh.connectivity().cellNbNodes();
+    } else {
+      std::cerr << "VTKWriter not implemented in dimension " << MeshType::dimension << '\n';
+      std::exit(1);
+    }
+    fout << '\n';
+    fout << "</DataArray>\n";
+    fout << "</Points>\n";
 
-	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 << '\n';
-	fout << "</DataArray>\n";
+    fout << "<Cells>\n";
+    const Kokkos::View<const unsigned int**> cell_nodes = mesh.connectivity().cellNodes();
+    const Kokkos::View<const unsigned short*> cell_nb_nodes = mesh.connectivity().cellNbNodes();
 
-	fout << "<DataArray type=\"UInt32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
-	{
-	  unsigned int offset=0;
-	  for (unsigned int j=0; j<mesh.numberOfCells(); ++j) {
-	    offset += cell_nb_nodes[j];
-	    fout << offset << ' ';
-	  }
-	}
-	fout << '\n';
-	fout << "</DataArray>\n";
+    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 << '\n';
+    fout << "</DataArray>\n";
 
-	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 3: {
-	    fout << "5 ";
-	    break;
-	  }
-	  case 4: {
-	    fout << "9 ";
-	    break;
-	  }
-	  default: {
-	    fout << "7 ";
-	    break;
-	  }
-	  }
-	}
-	fout << '\n';
-	fout << "</DataArray>\n";
+    fout << "<DataArray type=\"UInt32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
+    {
+      unsigned int offset=0;
+      for (unsigned int j=0; j<mesh.numberOfCells(); ++j) {
+	offset += cell_nb_nodes[j];
+	fout << offset << ' ';
+      }
+    }
+    fout << '\n';
+    fout << "</DataArray>\n";
 
-	fout << "</Cells>\n";
-	fout << "</Piece>\n";
-	fout << "</UnstructuredGrid>\n";
-	fout << "</VTKFile>\n";
-      } else {
-      std::cerr << "VTKWriter not implemented in dimension " << MeshType::dimension << '\n';
-      std::exit(1);
+    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;
+      }
+      }
     }
+    fout << '\n';
+    fout << "</DataArray>\n";
+
+    fout << "</Cells>\n";
+    fout << "</Piece>\n";
+    fout << "</UnstructuredGrid>\n";
+    fout << "</VTKFile>\n";
+
     m_file_number++;
   }
   VTKWriter(const std::string& base_filename,
-- 
GitLab