3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
writetriangulation.hh
Go to the documentation of this file.
1/*****************************************************************************
2 * See the file COPYING for full copying permissions. *
3 * *
4 * This program is free software: you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation, either version 3 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 *****************************************************************************/
22#ifndef DUMUX_TEST_WRITE_TRIANGULATION_HH
23#define DUMUX_TEST_WRITE_TRIANGULATION_HH
24
25#include <fstream>
26#include <string>
27#include <iterator>
28
29namespace Dumux {
30
32template<class TriangleVector>
33void writeVTKPolyDataTriangle(const TriangleVector& triangles,
34 const std::string& filename)
35{
36 std::ofstream fout(filename + ".vtp");
37 fout << "<?xml version=\"1.0\"?>\n"
38 << "<VTKFile type=\"PolyData\" version=\"0.1\" byte_order=\"LittleEndian\">\n"
39 << " <PolyData>\n"
40 << " <Piece NumberOfPoints=\"" << triangles.size()*3 << "\" NumberOfLines=\"" << triangles.size()*3 << "\">\n"
41 << " <Points>\n"
42 << " <DataArray type=\"Float32\" Name=\"Coordinates\" NumberOfComponents=\"3\" format=\"ascii\">\n";
43
44 for (const auto& t : triangles)
45 {
46 for (const auto& p : t)
47 {
48 fout << p << " ";
49 if (p.size() == 1)
50 fout << "0.0 0.0 ";
51 else if (p.size() == 2)
52 fout << "0.0 ";
53 }
54
55 }
56 fout << '\n';
57
58 fout << " </DataArray>\n"
59 << " </Points>\n"
60 << " <Lines>\n"
61 << " <DataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\" format=\"ascii\">\n";
62
63 int offset = 0;
64 for (const auto& t : triangles)
65 {
66 for (std::size_t i = 0; i < t.size()-1; ++i)
67 fout << i + offset*3 << " " << i+1 + offset*3 << " ";
68 fout << t.size()-1 + offset*3 << " " << offset*3 << " ";
69 ++offset;
70 }
71
72 fout << " </DataArray>\n";
73 fout << " <DataArray type=\"Int32\" Name=\"offsets\" NumberOfComponents=\"1\" format=\"ascii\">\n";
74
75 offset = 0;
76 for (const auto& t : triangles)
77 {
78 for (std::size_t i = 1; i <= t.size(); ++i)
79 fout << i*2 + offset*6 << " ";
80 ++offset;
81 }
82 fout << '\n';
83
84 fout << " </DataArray>\n"
85 << " </Lines>\n"
86 << " </Piece>\n"
87 << "</PolyData>\n"
88 << "</VTKFile>\n";
89}
90
91} // end namespace Dumux
92
93# endif
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
void writeVTKPolyDataTriangle(const TriangleVector &triangles, const std::string &filename)
TriangleVector has to be a nested vector of triangles in 3d.
Definition: writetriangulation.hh:33