preCICE v3.2.0
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 std::string_view participantName,
24 std::string_view location,
25 const mesh::Mesh &mesh,
26 ExportKind kind,
27 int frequency,
28 int rank,
29 int size)
30
31 : ExportXML(participantName, location, mesh, kind, frequency, rank, size) {};
32
34{
35 return "UnstructuredGrid";
36}
37
39{
40 return "pvtu";
41}
42
44{
45 return "vtu";
46}
47
49{
51 oss << "NumberOfPoints=\"" << mesh.nVertices() << "\" ";
52 oss << "NumberOfCells=\"" << mesh.edges().size() + mesh.triangles().size() + mesh.tetrahedra().size() << "\" ";
53 return oss.str();
54}
55
57{
58 out << " <PCells>\n";
59 out << " <PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n";
60 out << " <PDataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n";
61 out << " <PDataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\"/>\n";
62 out << " </PCells>\n";
63}
64
66 std::ostream &outFile,
67 const mesh::Mesh &mesh) const
68{
69 outFile << " <Cells>\n";
70 outFile << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
71 outFile << " ";
72 for (const mesh::Triangle &triangle : mesh.triangles()) {
73 writeTriangle(triangle, outFile);
74 }
75 for (const mesh::Edge &edge : mesh.edges()) {
76 writeLine(edge, outFile);
77 }
78 for (const mesh::Tetrahedron &tetra : mesh.tetrahedra()) {
79 writeTetrahedron(tetra, outFile);
80 }
81 outFile << '\n';
82 outFile << " </DataArray> \n";
83 outFile << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
84 outFile << " ";
85 for (size_t i = 1; i <= mesh.triangles().size(); i++) {
86 outFile << 3 * i << " ";
87 }
88 const auto triangleOffset = 3 * mesh.triangles().size();
89 for (size_t i = 1; i <= mesh.edges().size(); i++) {
90 outFile << 2 * i + triangleOffset << " ";
91 }
92 const auto tetraOffset = 2 * mesh.edges().size() + triangleOffset;
93 for (size_t i = 1; i <= mesh.tetrahedra().size(); i++) {
94 outFile << 4 * i + tetraOffset << " ";
95 }
96 outFile << '\n';
97 outFile << " </DataArray>\n";
98 outFile << " <DataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">\n";
99 outFile << " ";
100 for (size_t i = 1; i <= mesh.triangles().size(); i++) {
101 outFile << 5 << " ";
102 }
103 for (size_t i = 1; i <= mesh.edges().size(); i++) {
104 outFile << 3 << " ";
105 }
106 for (size_t i = 1; i <= mesh.tetrahedra().size(); i++) {
107 outFile << 10 << " ";
108 }
109 outFile << '\n';
110 outFile << " </DataArray>\n";
111 outFile << " </Cells>\n";
112}
113} // namespace precice::io
std::string getVTKFormat() const override
Definition ExportVTU.cpp:33
void writeParallelCells(std::ostream &out) const override
Definition ExportVTU.cpp:56
std::string getParallelExtension() const override
Definition ExportVTU.cpp:38
std::string getPieceExtension() const override
Definition ExportVTU.cpp:43
std::string getPieceAttributes(const mesh::Mesh &mesh) const override
Definition ExportVTU.cpp:48
void exportConnectivity(std::ostream &outFile, const mesh::Mesh &mesh) const override
Definition ExportVTU.cpp:65
ExportVTU(std::string_view participantName, std::string_view location, const mesh::Mesh &mesh, ExportKind kind, int frequency, int rank, int size)
Definition ExportVTU.cpp:22
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)
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
Tetrahedron of a mesh, defined by 4 vertices.
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)