Commit 396a57a0 authored by Stenger, Florian's avatar Stenger, Florian
Browse files

new branch for physicalTags and msh2-format

parent cafde68d
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/grid/utility/structuredgridfactory.hh>
#include <dune/vtk/vtkreader.hh>
#include <dune/vtk/gridcreators/lagrangegridcreator.hh>
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
#include <dune/vtk/datacollectors/lagrangedatacollector.hh>
#include <dune/vtk/datacollectors/continuousdatacollector.hh>
#include <dune/gmsh4/gmsh4reader.hh>
#include <dune/gmsh4/gridcreators/continuousgridcreator.hh>
#include <dune/gmsh4/gridcreators/lagrangegridcreator.hh>
#include <dune/foamgrid/foamgrid.hh>
#include <dune/curvedgrid/curvedgrid.hh>
using namespace Dune;
template <int p>
constexpr std::integral_constant<int,p> order_c = {};
int main(int argc, char** argv)
{
Dune::MPIHelper::instance(argc, argv);
using GridType = FoamGrid<2, 3>;
{ //test 01: triangle: msh4.1 -> vtk (flat, order 1)
std::cout << "\ntriangle: msh4.1 -> vtk (flat, order 1)" << std::endl;
GridFactory<GridType> factory;
Gmsh4::ContinuousGridCreator creator(factory);
Gmsh4Reader reader(creator);
reader.read(GRID_PATH "/triangle_msh4.1.msh");
std::cout << "\nelement-tags:" << std::endl;
int i = 0;
std::vector<std::vector<int>> &elementTags = creator.elementTags();
for(auto &tagvec : elementTags){
std::cout << ++i << ":";
for(auto tag : tagvec) std::cout << " " << tag;
std::cout << std::endl;
}
std::cout << "\nboundary-tags:" << std::endl;
i = 0;
std::vector<std::vector<int>> &boundaryTags = creator.boundaryTags();
for(auto &tagvec : boundaryTags){
std::cout << ++i << ":";
for(auto tag : tagvec) std::cout << " " << tag;
std::cout << std::endl;
}
std::unique_ptr gridPtr = factory.createGrid();
auto& grid = *gridPtr;
Vtk::ContinuousDataCollector dataCollector(grid.leafGridView());
VtkUnstructuredGridWriter vtkWriter(dataCollector, Vtk::FormatTypes::ASCII);
vtkWriter.write("BG_test01_triangle.vtu");
}
{ //test 02: triangle: msh2.2 -> vtk (flat, order 1)
std::cout << "\ntriangle: msh2.2 -> vtk (flat, order 1)" << std::endl;
GridFactory<GridType> factory;
Gmsh4::ContinuousGridCreator creator(factory);
Gmsh4Reader reader(creator);
reader.read(GRID_PATH "triangle_msh2.2.msh");
std::cout << "\nelement-tags:" << std::endl;
int i = 0;
std::vector<std::vector<int>> &elementTags = creator.elementTags();
for(auto &tagvec : elementTags){
std::cout << ++i << ":";
for(auto tag : tagvec) std::cout << " " << tag;
std::cout << std::endl;
}
std::cout << "\nboundary-tags:" << std::endl;
i = 0;
std::vector<std::vector<int>> &boundaryTags = creator.boundaryTags();
for(auto &tagvec : boundaryTags){
std::cout << ++i << ":";
for(auto tag : tagvec) std::cout << " " << tag;
std::cout << std::endl;
}
std::unique_ptr gridPtr = factory.createGrid();
auto& grid = *gridPtr;
Vtk::ContinuousDataCollector dataCollector(grid.leafGridView());
VtkUnstructuredGridWriter vtkWriter(dataCollector, Vtk::FormatTypes::ASCII);
vtkWriter.write("BG_test02_triangle.vtu");
}
{ //test 03: triangle: msh2.2 -> vtk (flat, order 1, deprecated syntax)
std::cout << "\ntriangle: msh2.2 -> vtk (flat, order 1, deprecated syntax)" << std::endl;
std::vector<int> elementTags;
std::vector<int> boundaryTags;
GridFactory<GridType> factory;
Gmsh4Reader<GridType>::read(factory, GRID_PATH "triangle_msh2.2.msh", boundaryTags, elementTags);
std::cout << "\nelement-tags:" << std::endl;
int i = 0;
for(auto &tag : elementTags) std::cout << ++i << ": " << tag << std::endl;
std::cout << "\nboundary-tags:" << std::endl;
i = 0;
for(auto &tag : boundaryTags) std::cout << ++i << ": " << tag << std::endl;
std::unique_ptr gridPtr = factory.createGrid();
auto& grid = *gridPtr;
Vtk::ContinuousDataCollector dataCollector(grid.leafGridView());
VtkUnstructuredGridWriter vtkWriter(dataCollector, Vtk::FormatTypes::ASCII);
vtkWriter.write("BG_test03_triangle.vtu");
}
return 0;
}
$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
81
1 0 0 0
2 1 0 0
3 0.5 0.866 0
4 2 0 0
5 3 0 0
6 2.5 0.866 0
7 0.2499999999994117 0 0
8 0.4999999999986935 0 0
9 0.7499999999993413 0 0
10 0.8750000000002091 0.2164999999996379 0
11 0.7500000000004508 0.4329999999992192 0
12 0.6250000000003404 0.6494999999994103 0
13 0.3750000000003806 0.6495000000006592 0
14 0.2500000000007488 0.4330000000012971 0
15 0.1250000000003718 0.216500000000644 0
16 2.1 0 0
17 2.2 0 0
18 2.3 0 0
19 2.4 0 0
20 2.5 0 0
21 2.6 0 0
22 2.7 0 0
23 2.8 0 0
24 2.9 0 0
25 2.950000000000063 0.08659999999989157 0
26 2.900000000000157 0.173199999999729 0
27 2.850000000000262 0.2597999999995461 0
28 2.800000000000337 0.346399999999416 0
29 2.750000000000451 0.4329999999992192 0
30 2.700000000000329 0.5195999999994309 0
31 2.650000000000367 0.6061999999993641 0
32 2.60000000000024 0.6927999999995837 0
33 2.55000000000004 0.7793999999999303 0
34 2.450000000000045 0.7794000000000775 0
35 2.400000000000279 0.6928000000004836 0
36 2.35000000000036 0.6062000000006228 0
37 2.300000000000404 0.5196000000007004 0
38 2.250000000000491 0.4330000000008511 0
39 2.200000000000397 0.3464000000006878 0
40 2.150000000000284 0.2598000000004922 0
41 2.100000000000191 0.1732000000003298 0
42 2.050000000000099 0.08660000000017112 0
43 0.5000022262186237 0.4329990927218975 0
44 0.3749999999990526 0.2165000000002625 0
45 0.6250003710360618 0.2164998487868362 0
46 2.650002200032771 0.4329987298101691 0
47 2.449999853328922 0.08660234719938903 0
48 2.349998554570598 0.4329992870166215 0
49 2.649998743681354 0.08660234685038831 0
50 2.249998418061561 0.2597997712906855 0
51 2.549999266675548 0.6061987298072604 0
52 2.750001578306097 0.259799542187477 0
53 2.250000197062874 0.0866009129626132 0
54 2.450000244431277 0.6061987298073576 0
55 2.499999918517905 0.6927995766024488 0
56 2.499999999999075 0.5195980947093465 0
57 2.350000544629728 0.08660181885434153 0
58 2.400000550152423 0.1732040961700083 0
59 2.499999375822922 0.173204455733195 0
60 2.450000339504461 0.2598057802042459 0
61 2.549998074337962 0.2598060099964589 0
62 2.499999304735777 0.3464057058013348 0
63 2.350000294739454 0.2598030805122277 0
64 2.599998142723091 0.1732049416906352 0
65 2.649998580573702 0.2598034746914967 0
66 2.7499993065682 0.08660109404405941 0
67 2.549999352592715 0.08660234857893458 0
68 2.599999786140418 0.5195996949867708 0
69 2.400000258141928 0.5195998902637224 0
70 2.85 0.08659999999990961 0
71 2.15 0.08660000000010992 0
72 2.200000305418537 0.1732006194862968 0
73 2.799999296764349 0.1732008089408293 0
74 2.300000956165682 0.1732020925796064 0
75 2.699998023610013 0.1732026583570355 0
76 2.69999944464567 0.3464013058991125 0
77 2.300000209753777 0.3464012901243509 0
78 2.59999677500627 0.3464044993831082 0
79 2.400002624911882 0.346404676400024 0
80 2.550000135960694 0.4330016591230693 0
81 2.450000890233286 0.4330020315986387 0
$EndNodes
$Elements
158
1 1 2 5 1 1 7
2 1 2 5 1 7 8
3 1 2 5 1 8 9
4 1 2 5 1 9 2
5 1 2 6 2 2 10
6 1 2 6 2 10 11
7 1 2 6 2 11 12
8 1 2 6 2 12 3
9 1 2 7 3 3 13
10 1 2 7 3 13 14
11 1 2 7 3 14 15
12 1 2 7 3 15 1
13 1 2 15 11 4 16
14 1 2 15 11 16 17
15 1 2 15 11 17 18
16 1 2 15 11 18 19
17 1 2 15 11 19 20
18 1 2 15 11 20 21
19 1 2 15 11 21 22
20 1 2 15 11 22 23
21 1 2 15 11 23 24
22 1 2 15 11 24 5
23 1 2 16 12 5 25
24 1 2 16 12 25 26
25 1 2 16 12 26 27
26 1 2 16 12 27 28
27 1 2 16 12 28 29
28 1 2 16 12 29 30
29 1 2 16 12 30 31
30 1 2 16 12 31 32
31 1 2 16 12 32 33
32 1 2 16 12 33 6
33 1 2 17 13 6 34
34 1 2 17 13 34 35
35 1 2 17 13 35 36
36 1 2 17 13 36 37
37 1 2 17 13 37 38
38 1 2 17 13 38 39
39 1 2 17 13 39 40
40 1 2 17 13 40 41
41 1 2 17 13 41 42
42 1 2 17 13 42 4
43 2 2 9 1 13 14 43
44 2 2 9 1 12 13 43
45 2 2 9 1 43 14 44
46 2 2 9 1 43 44 45
47 2 2 9 1 44 8 45
48 2 2 9 1 13 12 3
49 2 2 9 1 9 2 10
50 2 2 9 1 7 15 1
51 2 2 9 1 14 15 44
52 2 2 9 1 15 7 44
53 2 2 9 1 8 9 45
54 2 2 9 1 11 12 43
55 2 2 9 1 7 8 44
56 2 2 9 1 9 10 45
57 2 2 9 1 10 11 45
58 2 2 9 1 11 43 45
59 2 2 19 11 51 54 56
60 2 2 19 11 54 51 55
61 2 2 19 11 65 76 78
62 2 2 19 11 76 46 78
63 2 2 19 11 66 73 75
64 2 2 19 11 30 31 68
65 2 2 19 11 36 37 69
66 2 2 19 11 77 63 79
67 2 2 19 11 48 77 79
68 2 2 19 11 72 53 74
69 2 2 19 11 73 52 75
70 2 2 19 11 52 65 75
71 2 2 19 11 31 51 68
72 2 2 19 11 54 36 69
73 2 2 19 11 46 30 68
74 2 2 19 11 37 48 69
75 2 2 19 11 51 32 55
76 2 2 19 11 35 54 55
77 2 2 19 11 63 50 74
78 2 2 19 11 33 34 55
79 2 2 19 11 65 52 76
80 2 2 19 11 50 72 74
81 2 2 19 11 49 64 67
82 2 2 19 11 32 33 55
83 2 2 19 11 34 35 55
84 2 2 19 11 33 6 34
85 2 2 19 11 5 25 24
86 2 2 19 11 4 16 42
87 2 2 19 11 51 56 68
88 2 2 19 11 56 54 69
89 2 2 19 11 46 68 80
90 2 2 19 11 21 49 67
91 2 2 19 11 53 18 57
92 2 2 19 11 50 63 77
93 2 2 19 11 25 26 70
94 2 2 19 11 24 25 70
95 2 2 19 11 42 16 71
96 2 2 19 11 41 42 71
97 2 2 19 11 69 48 81
98 2 2 19 11 58 59 60
99 2 2 19 11 48 79 81
100 2 2 19 11 57 47 58
101 2 2 19 11 59 47 67
102 2 2 19 11 64 59 67
103 2 2 19 11 58 60 63
104 2 2 19 11 58 47 59
105 2 2 19 11 49 22 66
106 2 2 19 11 60 61 62
107 2 2 19 11 60 59 61
108 2 2 19 11 19 47 57
109 2 2 19 11 17 18 53
110 2 2 19 11 21 22 49
111 2 2 19 11 49 66 75
112 2 2 19 11 19 20 47
113 2 2 19 11 18 19 57
114 2 2 19 11 61 64 65
115 2 2 19 11 22 23 66
116 2 2 19 11 47 20 67
117 2 2 19 11 20 21 67
118 2 2 19 11 31 32 51
119 2 2 19 11 35 36 54
120 2 2 19 11 29 30 46
121 2 2 19 11 37 38 48
122 2 2 19 11 61 59 64
123 2 2 19 11 66 23 70
124 2 2 19 11 78 46 80
125 2 2 19 11 39 40 50
126 2 2 19 11 17 53 71
127 2 2 19 11 27 28 52
128 2 2 19 11 53 57 74
129 2 2 19 11 23 24 70
130 2 2 19 11 16 17 71
131 2 2 19 11 58 63 74
132 2 2 19 11 40 41 72
133 2 2 19 11 26 27 73
134 2 2 19 11 65 64 75
135 2 2 19 11 61 65 78
136 2 2 19 11 63 60 79
137 2 2 19 11 29 46 76
138 2 2 19 11 48 38 77
139 2 2 19 11 41 71 72
140 2 2 19 11 64 49 75
141 2 2 19 11 70 26 73
142 2 2 19 11 66 70 73
143 2 2 19 11 52 28 76
144 2 2 19 11 39 50 77
145 2 2 19 11 50 40 72
146 2 2 19 11 71 53 72
147 2 2 19 11 27 52 73
148 2 2 19 11 57 58 74
149 2 2 19 11 28 29 76
150 2 2 19 11 38 39 77
151 2 2 19 11 62 61 78
152 2 2 19 11 60 62 79
153 2 2 19 11 68 56 80
154 2 2 19 11 56 69 81
155 2 2 19 11 79 62 81
156 2 2 19 11 62 78 80
157 2 2 19 11 80 56 81
158 2 2 19 11 62 80 81
$EndElements
$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
6 6 2 0
1 0 0 0 0
2 1 0 0 0
3 0.5 0.866 0 0
11 2 0 0 0
12 3 0 0 0
13 2.5 0.866 0 0
1 0 0 0 1 0 0 1 5 2 1 -2
2 0.5 0 0 1 0.866 0 1 6 2 2 -3
3 0 0 0 0.5 0.866 0 1 7 2 3 -1
11 2 0 0 3 0 0 1 15 2 11 -12
12 2.5 0 0 3 0.866 0 1 16 2 12 -13
13 2 0 0 2.5 0.866 0 1 17 2 13 -11
1 0 0 0 1 0.866 0 1 9 3 1 2 3
11 2 0 0 3 0.866 0 1 19 3 11 12 13
$EndEntities
$Nodes
14 81 1 81
0 1 0 1
1
0 0 0
0 2 0 1
2
1 0 0
0 3 0 1
3
0.5 0.866 0
0 11 0 1
4
2 0 0
0 12 0 1
5
3 0 0
0 13 0 1
6
2.5 0.866 0
1 1 0 3
7
8
9
0.2499999999994109 0 0
0.4999999999986918 0 0
0.7499999999993401 0 0
1 2 0 3
10
11
12
0.8750000000002088 0.2164999999996383 0
0.7500000000004502 0.4329999999992202 0
0.62500000000034 0.6494999999994112 0
1 3 0 3
13
14
15
0.3750000000003039 0.6495000000005262 0
0.2500000000007268 0.4330000000012587 0
0.1250000000004798 0.216500000000831 0
1 11 0 9
16
17
18
19
20
21
22
23
24
2.1 0 0
2.2 0 0
2.299999999999999 0 0
2.399999999999999 0 0
2.5 0 0
2.6 0 0
2.7 0 0
2.8 0 0
2.9 0 0
1 12 0 9
25
26
27
28
29
30
31
32
33
2.950000000000063 0.08659999999989144 0
2.900000000000157 0.1731999999997288 0
2.850000000000262 0.2597999999995458 0
2.800000000000337 0.3463999999994155 0
2.750000000000451 0.4329999999992186 0
2.700000000000329 0.5195999999994301 0
2.650000000000367 0.6061999999993637 0
2.60000000000024 0.6927999999995836 0
2.55000000000004 0.7793999999999304 0
1 13 0 9
34
35
36
37
38
39
40
41
42
2.450000000000037 0.7794000000000635 0
2.400000000000182 0.6928000000003156 0
2.350000000000298 0.606200000000516 0
2.300000000000365 0.5196000000006317 0
2.25000000000047 0.4330000000008138 0
2.200000000000344 0.346400000000596 0
2.150000000000379 0.259800000000656 0
2.100000000000248 0.1732000000004295 0
2.050000000000044 0.08660000000007617 0
2 1 0 3
43
44
45
0.5000022262186115 0.432999092721876 0
0.3749999999990514 0.2165000000002495 0
0.6250003710360589 0.2164998487868307 0
2 11 0 36
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
2.650002200032772 0.432998729810168 0
2.449999853328917 0.08660234719938223 0
2.349998554570568 0.4329992870165743 0
2.649998743681336 0.0866023468503911 0
2.249998418061443 0.2597997712907851 0
2.549999266675583 0.6061987298072222 0
2.750001578306093 0.2597995421874758 0
2.250000197062848 0.08660091296264096 0
2.450000244431305 0.6061987298072462 0
2.499999918517898 0.6927995766023936 0
2.499999999999192 0.5195980947092964 0
2.350000544629705 0.08660181885435189 0
2.400000550152397 0.1732040961700007 0
2.499999375822898 0.1732044557331776 0
2.450000339504432 0.259805780204209 0
2.549998074337925 0.2598060099964337 0
2.499999304735809 0.3464057058012877 0
2.350000294739392 0.2598030805122276 0
2.599998142723049 0.1732049416906326 0
2.649998580573675 0.2598034746914901 0
2.749999306568191 0.08660109404406292 0
2.5499993525927 0.08660234857893057 0
2.599999786140479 0.519599694986739 0
2.400000258141978 0.5195998902636567 0
2.150000000000001 0.08660000000014331 0
2.850000000000003 0.08659999999990528 0
2.200000305418521 0.1732006194863775 0
2.799999296764339 0.173200808940833 0
2.300000956165619 0.1732020925796486 0
2.699998023609986 0.1732026583570425 0
2.699999444645663 0.3464013058991069 0
2.30000020975372 0.3464012901243292 0
2.599996775006279 0.3464044993830812 0
2.400002624911855 0.3464046763999806 0
2.550000135960778 0.4330016591230413 0
2.450000890233395 0.4330020315986023 0
$EndNodes
$Elements
8 158 1 158
1 1 1 4
1 1 7
2 7 8
3 8 9
4 9 2
1 2 1 4
5 2 10
6 10 11
7 11 12
8 12 3
1 3 1 4
9 3 13
10 13 14
11 14 15
12 15 1
1 11 1 10
13 4 16
14 16 17
15 17 18
16 18 19
17 19 20
18 20 21
19 21 22
20 22 23
21 23 24
22 24 5
1 12 1 10
23 5 25
24 25 26
25 26 27
26 27 28
27 28 29
28 29 30
29 30 31
30 31 32
31 32 33
32 33 6
1 13 1 10
33 6 34
34 34 35
35 35 36
36 36 37
37 37 38
38 38 39
39 39 40
40 40 41
41 41 42
42 42 4
2 1 2 16
43 13 14 43
44 12 13 43
45 43 14 44
46 43 44 45
47 44 8 45
48 12 3 13
49 9 2 10
50 1 7 15
51 14 15 44
52 15 7 44
53 8 9 45
54 11 12 43
55 7 8 44
56 9 10 45
57 10 11 45
58 11 43 45
2 11 2 100
59 51 54 56
60 54 51 55
61 65 76 78
62 76 46 78
63 66 73 75
64 30 31 68
65 36 37 69
66 77 63 79
67 48 77 79
68 72 53 74
69 73 52 75
70 52 65 75
71 31 51 68