preCICE v3.2.0
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 std::string_view participantName,
12 std::string_view location,
13 const mesh::Mesh &mesh,
14 ExportKind kind,
15 int frequency,
16 int rank,
17 int size)
18
19 : ExportXML(participantName, location, mesh, kind, frequency, rank, size) {};
20
22{
23 return "PolyData";
24}
25
27{
28 return "pvtp";
29}
30
32{
33 return "vtp";
34}
35
37{
39 oss << "NumberOfPoints=\"" << mesh.nVertices() << "\" ";
40 oss << "NumberOfLines=\"" << mesh.edges().size() << "\" ";
41 oss << "NumberOfPolys=\"" << mesh.triangles().size() << "\"";
42 return oss.str();
43}
44
46{
47 out << " <PLines>\n";
48 out << " <PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
49 out << " <PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
50 out << " </PLines>\n";
51 out << " <PPolys>\n";
52 out << " <PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
53 out << " <PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
54 out << " </PPolys>\n";
55}
56
58 std::ostream &outFile,
59 const mesh::Mesh &mesh) const
60{
61 outFile << " <Lines>\n";
62 outFile << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
63 outFile << " ";
64 for (const mesh::Edge &edge : mesh.edges()) {
65 writeLine(edge, outFile);
66 }
67 outFile << '\n';
68 outFile << " </DataArray> \n";
69 outFile << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
70 outFile << " ";
71 for (size_t i = 1; i <= mesh.edges().size(); i++) {
72 outFile << 2 * i << " ";
73 }
74 outFile << '\n';
75 outFile << " </DataArray>\n";
76 outFile << " </Lines>\n";
77 outFile << " <Polys>\n";
78 outFile << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
79 outFile << " ";
80 for (const mesh::Triangle &triangle : mesh.triangles()) {
81 writeTriangle(triangle, outFile);
82 }
83 outFile << '\n';
84 outFile << " </DataArray> \n";
85 outFile << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
86 outFile << " ";
87 for (size_t i = 1; i <= mesh.triangles().size(); i++) {
88 outFile << 3 * i << " ";
89 }
90 outFile << '\n';
91 outFile << " </DataArray>\n";
92 outFile << " </Polys>\n";
93}
94} // namespace precice::io
ExportVTP(std::string_view participantName, std::string_view location, const mesh::Mesh &mesh, ExportKind kind, int frequency, int rank, int size)
Definition ExportVTP.cpp:10
std::string getVTKFormat() const override
Definition ExportVTP.cpp:21
std::string getPieceAttributes(const mesh::Mesh &mesh) const override
Definition ExportVTP.cpp:36
void exportConnectivity(std::ostream &outFile, const mesh::Mesh &mesh) const override
Definition ExportVTP.cpp:57
void writeParallelCells(std::ostream &out) const override
Definition ExportVTP.cpp:45
std::string getPieceExtension() const override
Definition ExportVTP.cpp:31
std::string getParallelExtension() const override
Definition ExportVTP.cpp:26
static void writeLine(const mesh::Edge &edge, std::ostream &outFile)
static void writeTriangle(const mesh::Triangle &triangle, std::ostream &outFile)
ExportXML(std::string_view participantName, std::string_view location, const mesh::Mesh &mesh, ExportKind kind, int frequency, int rank, int size)
Definition ExportXML.cpp:23
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:15
Container and creator for meshes.
Definition Mesh.hpp:38
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:24
provides Import and Export of the coupling mesh and data.
provides Mesh, Data and primitives.
T str(T... args)