preCICE v3.1.1
Loading...
Searching...
No Matches
ExportVTP.cpp
Go to the documentation of this file.
1#include "io/ExportVTP.hpp"
2#include <filesystem>
3#include <sstream>
4#include <string>
5#include "mesh/Data.hpp"
6#include "mesh/Mesh.hpp"
7
8namespace precice::io {
9
11{
12 return "PolyData";
13}
14
16{
17 return ".pvtp";
18}
19
21{
22 return ".vtp";
23}
24
26{
28 oss << "NumberOfPoints=\"" << mesh.nVertices() << "\" ";
29 oss << "NumberOfLines=\"" << mesh.edges().size() << "\" ";
30 oss << "NumberOfPolys=\"" << mesh.triangles().size() << "\"";
31 return oss.str();
32}
33
35{
36 out << " <PLines>\n";
37 out << " <PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
38 out << " <PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
39 out << " </PLines>\n";
40 out << " <PPolys>\n";
41 out << " <PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
42 out << " <PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
43 out << " </PPolys>\n";
44}
45
47 std::ostream & outFile,
48 const mesh::Mesh &mesh) const
49{
50 outFile << " <Lines>\n";
51 outFile << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
52 outFile << " ";
53 for (const mesh::Edge &edge : mesh.edges()) {
54 writeLine(edge, outFile);
55 }
56 outFile << '\n';
57 outFile << " </DataArray> \n";
58 outFile << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
59 outFile << " ";
60 for (size_t i = 1; i <= mesh.edges().size(); i++) {
61 outFile << 2 * i << " ";
62 }
63 outFile << '\n';
64 outFile << " </DataArray>\n";
65 outFile << " </Lines>\n";
66 outFile << " <Polys>\n";
67 outFile << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
68 outFile << " ";
69 for (const mesh::Triangle &triangle : mesh.triangles()) {
70 writeTriangle(triangle, outFile);
71 }
72 outFile << '\n';
73 outFile << " </DataArray> \n";
74 outFile << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
75 outFile << " ";
76 for (size_t i = 1; i <= mesh.triangles().size(); i++) {
77 outFile << 3 * i << " ";
78 }
79 outFile << '\n';
80 outFile << " </DataArray>\n";
81 outFile << " </Polys>\n";
82}
83} // namespace precice::io
std::ostream & out
std::string getVTKFormat() const override
Definition ExportVTP.cpp:10
std::string getPieceAttributes(const mesh::Mesh &mesh) const override
Definition ExportVTP.cpp:25
void exportConnectivity(std::ostream &outFile, const mesh::Mesh &mesh) const override
Definition ExportVTP.cpp:46
void writeParallelCells(std::ostream &out) const override
Definition ExportVTP.cpp:34
std::string getPieceExtension() const override
Definition ExportVTP.cpp:20
std::string getParallelExtension() const override
Definition ExportVTP.cpp:15
static void writeLine(const mesh::Edge &edge, std::ostream &outFile)
static void writeTriangle(const mesh::Triangle &triangle, 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
TriangleContainer & triangles()
Returns modifiable container holding all triangles.
Definition Mesh.cpp:78
EdgeContainer & edges()
Returns modifiable container holding all edges.
Definition Mesh.cpp:68
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)