Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder | ||
3 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
4 | // | ||
5 | /*! | ||
6 | * \file | ||
7 | * \ingroup Common | ||
8 | * \brief A function to write a triangulation to vtk | ||
9 | */ | ||
10 | #ifndef DUMUX_TEST_WRITE_TRIANGULATION_HH | ||
11 | #define DUMUX_TEST_WRITE_TRIANGULATION_HH | ||
12 | |||
13 | #include <fstream> | ||
14 | #include <string> | ||
15 | #include <iterator> | ||
16 | |||
17 | namespace Dumux { | ||
18 | |||
19 | //! TriangleVector has to be a nested vector of triangles in 3d | ||
20 | template<class TriangleVector> | ||
21 | 22 | void writeVTKPolyDataTriangle(const TriangleVector& triangles, | |
22 | const std::string& filename) | ||
23 | { | ||
24 |
1/2✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
|
44 | std::ofstream fout(filename + ".vtp"); |
25 | fout << "<?xml version=\"1.0\"?>\n" | ||
26 | << "<VTKFile type=\"PolyData\" version=\"0.1\">\n" | ||
27 | << " <PolyData>\n" | ||
28 |
4/8✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 22 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 22 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 22 times.
✗ Branch 16 not taken.
|
176 | << " <Piece NumberOfPoints=\"" << triangles.size()*3 << "\" NumberOfLines=\"" << triangles.size()*3 << "\">\n" |
29 | << " <Points>\n" | ||
30 |
1/2✓ Branch 3 taken 22 times.
✗ Branch 4 not taken.
|
66 | << " <DataArray type=\"Float32\" Name=\"Coordinates\" NumberOfComponents=\"3\" format=\"ascii\">\n"; |
31 | |||
32 |
4/4✓ Branch 0 taken 6776 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 6776 times.
✓ Branch 3 taken 22 times.
|
6842 | for (const auto& t : triangles) |
33 | { | ||
34 |
4/4✓ Branch 0 taken 20328 times.
✓ Branch 1 taken 6776 times.
✓ Branch 2 taken 20106 times.
✓ Branch 3 taken 6702 times.
|
40656 | for (const auto& p : t) |
35 | { | ||
36 |
2/4✓ Branch 1 taken 20328 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20328 times.
✗ Branch 5 not taken.
|
20328 | fout << p << " "; |
37 | if (p.size() == 1) | ||
38 | fout << "0.0 0.0 "; | ||
39 | else if (p.size() == 2) | ||
40 | fout << "0.0 "; | ||
41 | } | ||
42 | |||
43 | } | ||
44 |
1/2✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
|
22 | fout << '\n'; |
45 | |||
46 | fout << " </DataArray>\n" | ||
47 | << " </Points>\n" | ||
48 | << " <Lines>\n" | ||
49 |
1/2✓ Branch 4 taken 22 times.
✗ Branch 5 not taken.
|
88 | << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
50 | |||
51 | 22 | int offset = 0; | |
52 |
4/4✓ Branch 0 taken 6776 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 6776 times.
✓ Branch 3 taken 22 times.
|
13618 | for (const auto& t : triangles) |
53 | { | ||
54 |
4/4✓ Branch 0 taken 13552 times.
✓ Branch 1 taken 6776 times.
✓ Branch 2 taken 13404 times.
✓ Branch 3 taken 6702 times.
|
27030 | for (std::size_t i = 0; i < t.size()-1; ++i) |
55 |
3/6✓ Branch 1 taken 13552 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 13552 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 13552 times.
✗ Branch 9 not taken.
|
27104 | fout << i + offset*3 << " " << i+1 + offset*3 << " "; |
56 |
3/6✓ Branch 1 taken 6776 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 6776 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 6776 times.
✗ Branch 9 not taken.
|
13552 | fout << t.size()-1 + offset*3 << " " << offset*3 << " "; |
57 | 6776 | ++offset; | |
58 | } | ||
59 | |||
60 |
1/2✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
|
22 | fout << " </DataArray>\n"; |
61 |
1/2✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
|
22 | fout << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
62 | |||
63 | 22 | offset = 0; | |
64 |
4/4✓ Branch 0 taken 6776 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 6776 times.
✓ Branch 3 taken 22 times.
|
13618 | for (const auto& t : triangles) |
65 | { | ||
66 |
4/4✓ Branch 0 taken 20328 times.
✓ Branch 1 taken 6776 times.
✓ Branch 2 taken 20106 times.
✓ Branch 3 taken 6702 times.
|
33806 | for (std::size_t i = 1; i <= t.size(); ++i) |
67 |
2/4✓ Branch 1 taken 20328 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20328 times.
✗ Branch 5 not taken.
|
20328 | fout << i*2 + offset*6 << " "; |
68 | 6776 | ++offset; | |
69 | } | ||
70 |
1/2✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
|
22 | fout << '\n'; |
71 | |||
72 | fout << " </DataArray>\n" | ||
73 | << " </Lines>\n" | ||
74 | << " </Piece>\n" | ||
75 | << "</PolyData>\n" | ||
76 |
1/2✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
|
110 | << "</VTKFile>\n"; |
77 | 22 | } | |
78 | |||
79 | //! TetrahedronVector has to be a nested vector of tets in 3d | ||
80 | template<class TetrahedronVector> | ||
81 | 116 | void writeVTUTetrahedron(const TetrahedronVector& tets, | |
82 | const std::string& filename) | ||
83 | { | ||
84 |
1/2✓ Branch 2 taken 116 times.
✗ Branch 3 not taken.
|
232 | std::ofstream fout(filename + ".vtu"); |
85 | fout << "<?xml version=\"1.0\"?>\n" | ||
86 | << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\">\n" | ||
87 | << " <UnstructuredGrid>\n" | ||
88 |
4/8✓ Branch 5 taken 116 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 116 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 116 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 116 times.
✗ Branch 16 not taken.
|
928 | << " <Piece NumberOfPoints=\"" << tets.size()*4 << "\" NumberOfCells=\"" << tets.size() << "\">\n" |
89 | << " <Points>\n" | ||
90 |
1/2✓ Branch 3 taken 116 times.
✗ Branch 4 not taken.
|
348 | << " <DataArray type=\"Float32\" Name=\"Points\" NumberOfComponents=\"3\" format=\"ascii\">\n"; |
91 | |||
92 |
4/4✓ Branch 0 taken 29142 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 29142 times.
✓ Branch 3 taken 116 times.
|
58632 | for (const auto& t : tets) |
93 | { | ||
94 |
4/4✓ Branch 0 taken 116568 times.
✓ Branch 1 taken 29142 times.
✓ Branch 2 taken 105812 times.
✓ Branch 3 taken 26453 times.
|
203994 | for (const auto& p : t) |
95 |
2/4✓ Branch 1 taken 116568 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 116568 times.
✗ Branch 5 not taken.
|
116568 | fout << p << " "; |
96 | |||
97 |
1/2✓ Branch 1 taken 29142 times.
✗ Branch 2 not taken.
|
29142 | fout << '\n'; |
98 | } | ||
99 | |||
100 | fout << " </DataArray>\n" | ||
101 | << " </Points>\n" | ||
102 | << " <Cells>\n" | ||
103 |
1/2✓ Branch 4 taken 116 times.
✗ Branch 5 not taken.
|
464 | << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
104 | |||
105 | 116 | int offset = 0; | |
106 |
4/4✓ Branch 0 taken 29142 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 29142 times.
✓ Branch 3 taken 116 times.
|
58632 | for (const auto& t : tets) |
107 | { | ||
108 |
5/10✓ Branch 1 taken 29142 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 29142 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 29142 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 29142 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 29142 times.
✗ Branch 17 not taken.
|
116568 | fout << offset << " " << offset+1 << " " << offset+2 << " " << offset+3 << "\n"; |
109 | 55595 | offset += t.size(); | |
110 | } | ||
111 | |||
112 |
1/2✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
|
116 | fout << " </DataArray>\n"; |
113 |
1/2✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
|
116 | fout << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
114 | |||
115 | 116 | offset = 4; | |
116 |
4/4✓ Branch 0 taken 29142 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 29142 times.
✓ Branch 3 taken 116 times.
|
58632 | for (const auto& t : tets) |
117 | { | ||
118 |
2/4✓ Branch 1 taken 29142 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 29142 times.
✗ Branch 5 not taken.
|
29142 | fout << offset << '\n'; |
119 | 55595 | offset += t.size(); | |
120 | } | ||
121 | |||
122 |
1/2✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
|
116 | fout << " </DataArray>\n"; |
123 |
1/2✓ Branch 1 taken 116 times.
✗ Branch 2 not taken.
|
116 | fout << " <DataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\" format=\"ascii\">\n"; |
124 | |||
125 |
4/4✓ Branch 0 taken 29142 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 29142 times.
✓ Branch 3 taken 116 times.
|
29374 | for (int i = 0; i < tets.size(); ++i) |
126 |
1/2✓ Branch 1 taken 29142 times.
✗ Branch 2 not taken.
|
29142 | fout << "10\n"; |
127 | |||
128 | fout << " </DataArray>\n" | ||
129 | << " </Cells>\n" | ||
130 | << " </Piece>\n" | ||
131 | << "</UnstructuredGrid>\n" | ||
132 |
1/2✓ Branch 5 taken 116 times.
✗ Branch 6 not taken.
|
580 | << "</VTKFile>\n"; |
133 | 116 | } | |
134 | |||
135 | template<class LineVector> | ||
136 | void writeVTKPolyDataLines(const LineVector& lines, | ||
137 | const std::string& filename) | ||
138 | { | ||
139 | std::ofstream fout(filename + ".vtp"); | ||
140 | fout << "<?xml version=\"1.0\"?>\n" | ||
141 | << "<VTKFile type=\"PolyData\" version=\"0.1\">\n" | ||
142 | << " <PolyData>\n" | ||
143 | << " <Piece NumberOfPoints=\"" << lines.size()*2 << "\" NumberOfLines=\"" << lines.size() << "\">\n" | ||
144 | << " <Points>\n" | ||
145 | << " <DataArray type=\"Float32\" Name=\"Coordinates\" NumberOfComponents=\"3\" format=\"ascii\">\n"; | ||
146 | |||
147 | for (const auto& l : lines) | ||
148 | { | ||
149 | for (const auto& p : l) | ||
150 | { | ||
151 | fout << p << " "; | ||
152 | if (p.size() == 1) | ||
153 | fout << "0.0 0.0 "; | ||
154 | else if (p.size() == 2) | ||
155 | fout << "0.0 "; | ||
156 | } | ||
157 | } | ||
158 | fout << '\n'; | ||
159 | |||
160 | fout << " </DataArray>\n" | ||
161 | << " </Points>\n" | ||
162 | << " <Lines>\n" | ||
163 | << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n"; | ||
164 | |||
165 | int offset = 0; | ||
166 | for (int i = 0; i < lines.size(); ++i) | ||
167 | { | ||
168 | fout << offset*2 << " " << offset*2 + 1 << "\n"; | ||
169 | ++offset; | ||
170 | } | ||
171 | |||
172 | fout << " </DataArray>\n"; | ||
173 | fout << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n"; | ||
174 | |||
175 | for (int i = 0; i < lines.size(); ++i) | ||
176 | fout << (i+1)*2 << "\n"; | ||
177 | |||
178 | fout << " </DataArray>\n" | ||
179 | << " </Lines>\n" | ||
180 | << " </Piece>\n" | ||
181 | << "</PolyData>\n" | ||
182 | << "</VTKFile>\n"; | ||
183 | } | ||
184 | |||
185 | } // end namespace Dumux | ||
186 | |||
187 | #endif | ||
188 |