Bembel
 
Loading...
Searching...
No Matches
writeVTK.hpp
1// This file is part of Bembel, the higher order C++ boundary element library.
2//
3// Copyright (C) 2022 see <http://www.bembel.eu>
4//
5// It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz,
6// M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt,
7// Universitaet Basel, and Universita della Svizzera italiana, Lugano. This
8// source code is subject to the GNU General Public License version 3 and
9// provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further
10// information.
11
12#ifndef EXAMPLES_WRITEVTK_HPP_
13#define EXAMPLES_WRITEVTK_HPP_
14
15#include <Eigen/Dense>
16#include <fstream>
17#include <iomanip>
18#include <iostream>
19#include <string>
20
24namespace Eigen {
25template <typename Derived1, typename Derived2, typename Derived3>
26void writeMesh2vtk(const std::string &fileName,
27 const Eigen::MatrixBase<Derived1> &P,
28 const Eigen::MatrixBase<Derived2> &E,
29 const Eigen::MatrixBase<Derived3> &Cdata,
30 bool isCellData = false) {
31 std::ofstream myfile;
32 myfile.open(fileName);
33 myfile << "# vtk DataFile Version 3.1\n";
34 myfile << "this file hopefully represents my surface now\n";
35 myfile << "ASCII\n";
36 myfile << "DATASET UNSTRUCTURED_GRID\n";
37 // print point list
38 myfile << "POINTS " << P.cols() << " FLOAT\n";
39 for (auto i = 0; i < P.cols(); ++i)
40 myfile << float(P(0, i)) << " " << float(P(1, i)) << " " << float(P(2, i))
41 << "\n";
42 myfile << "\n";
43
44 // print element list
45 myfile << "CELLS " << E.cols() << " " << 5 * E.cols() << "\n";
46 for (auto i = 0; i < E.cols(); ++i)
47 myfile << int(4) << " " << int(E(0, i)) << " " << int(E(1, i)) << " "
48 << int(E(2, i)) << " " << int(E(3, i)) << "\n";
49 myfile << "\n";
50
51 myfile << "CELL_TYPES " << E.cols() << "\n";
52 for (auto i = 0; i < E.cols(); ++i) myfile << int(9) << "\n";
53 myfile << "\n";
54 // print cell labels
55 if (isCellData) {
56 myfile << "CELL_DATA " << E.cols() << "\n";
57 myfile << "SCALARS value FLOAT\n";
58 myfile << "LOOKUP_TABLE default\n";
59 for (auto i = 0; i < E.cols(); ++i) myfile << float(Cdata(i)) << "\n";
60
61 } else {
62 myfile << "POINT_DATA " << P.cols() << "\n";
63 myfile << "SCALARS value FLOAT\n";
64 myfile << "LOOKUP_TABLE default\n";
65 for (auto i = 0; i < P.cols(); ++i) myfile << float(Cdata(i)) << "\n";
66 }
67 myfile.close();
68#if 0
69// print z-values of the geometry and solved density for visualization
70/*
71fprintf (f, "POINT_DATA %d\n", np);
72fprintf (f, "SCALARS Solution FLOAT\n");
73fprintf (f, "LOOKUP_TABLE default\n");
74for (i = 0 ; i < np ; ++i)
75 fprintf (f, "%20.16f\n", u[i]);
76fprintf (f, "\n");
77*/
78#endif
79 return;
80}
81} // namespace Eigen
82#endif // EXAMPLES_WRITEVTK_HPP_