preCICE v3.1.1
Loading...
Searching...
No Matches
ExportVTU.cpp
Go to the documentation of this file.
1#include "io/ExportVTU.hpp"
2#include <Eigen/Core>
3#include <algorithm>
4#include <filesystem>
5#include <fstream>
6#include <memory>
7#include <string>
8#include "io/Export.hpp"
10#include "mesh/Data.hpp"
11#include "mesh/Edge.hpp"
12#include "mesh/Mesh.hpp"
14#include "mesh/Triangle.hpp"
15#include "mesh/Vertex.hpp"
16#include "utils/Helpers.hpp"
17#include "utils/IntraComm.hpp"
18#include "utils/assertion.hpp"
19
20namespace precice::io {
21
23{
24 return "UnstructuredGrid";
25}
26
28{
29 return ".pvtu";
30}
31
33{
34 return ".vtu";
35}
36
38{
40 oss << "NumberOfPoints=\"" << mesh.nVertices() << "\" ";
41 oss << "NumberOfCells=\"" << mesh.edges().size() + mesh.triangles().size() + mesh.tetrahedra().size() << "\" ";
42 return oss.str();
43}
44
46{
47 out << " <PCells>\n";
48 out << " <PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
49 out << " <PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
50 out << " <PDataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\"/>\n";
51 out << " </PCells>\n";
52}
53
55 std::ostream & outFile,
56 const mesh::Mesh &mesh) const
57{
58 outFile << " <Cells>\n";
59 outFile << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
60 outFile << " ";
61 for (const mesh::Triangle &triangle : mesh.triangles()) {
62 writeTriangle(triangle, outFile);
63 }
64 for (const mesh::Edge &edge : mesh.edges()) {
65 writeLine(edge, outFile);
66 }
67 for (const mesh::Tetrahedron &tetra : mesh.tetrahedra()) {
68 writeTetrahedron(tetra, outFile);
69 }
70 outFile << '\n';
71 outFile << " </DataArray> \n";
72 outFile << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
73 outFile << " ";
74 for (size_t i = 1; i <= mesh.triangles().size(); i++) {
75 outFile << 3 * i << " ";
76 }
77 const auto triangleOffset = 3 * mesh.triangles().size();
78 for (size_t i = 1; i <= mesh.edges().size(); i++) {
79 outFile << 2 * i + triangleOffset << " ";
80 }
81 const auto tetraOffset = 2 * mesh.edges().size() + triangleOffset;
82 for (size_t i = 1; i <= mesh.tetrahedra().size(); i++) {
83 outFile << 4 * i + tetraOffset << " ";
84 }
85 outFile << '\n';
86 outFile << " </DataArray>\n";
87 outFile << " <DataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">\n";
88 outFile << " ";
89 for (size_t i = 1; i <= mesh.triangles().size(); i++) {
90 outFile << 5 << " ";
91 }
92 for (size_t i = 1; i <= mesh.edges().size(); i++) {
93 outFile << 3 << " ";
94 }
95 for (size_t i = 1; i <= mesh.tetrahedra().size(); i++) {
96 outFile << 10 << " ";
97 }
98 outFile << '\n';
99 outFile << " </DataArray>\n";
100 outFile << " </Cells>\n";
101}
102} // namespace precice::io
std::ostream & out
std::string getVTKFormat() const override
Definition ExportVTU.cpp:22
void writeParallelCells(std::ostream &out) const override
Definition ExportVTU.cpp:45
std::string getParallelExtension() const override
Definition ExportVTU.cpp:27
std::string getPieceExtension() const override
Definition ExportVTU.cpp:32
std::string getPieceAttributes(const mesh::Mesh &mesh) const override
Definition ExportVTU.cpp:37
void exportConnectivity(std::ostream &outFile, const mesh::Mesh &mesh) const override
Definition ExportVTU.cpp:54
static void writeLine(const mesh::Edge &edge, std::ostream &outFile)
static void writeTriangle(const mesh::Triangle &triangle, std::ostream &outFile)
static void writeTetrahedron(const mesh::Tetrahedron &tetra, std::ostream &outFile)
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
Container and creator for meshes.
Definition Mesh.hpp:39
std::size_t nVertices() const
Returns the number of vertices.
Definition Mesh.cpp:63
TetraContainer & tetrahedra()
Returns modifiable container holding all tetrahedra.
Definition Mesh.cpp:93
TriangleContainer & triangles()
Returns modifiable container holding all triangles.
Definition Mesh.cpp:78
EdgeContainer & edges()
Returns modifiable container holding all edges.
Definition Mesh.cpp:68
Tetrahedron of a mesh, defined by 4 vertices.
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:27
provides Import and Export of the coupling mesh and data.
T size(T... args)
T str(T... args)