Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writediffpack.cpp
3206 views
1
//
2
// Write diffpack file
3
//
4
// by
5
// Bartosz Sawicki <[email protected]>
6
// extended by
7
// Jacques Lechelle <[email protected]>
8
//
9
#include <mystdlib.h>
10
11
#include <myadt.hpp>
12
#include <linalg.hpp>
13
#include <csg.hpp>
14
#include <meshing.hpp>
15
16
17
namespace netgen
18
{
19
#include "writeuser.hpp"
20
21
22
void WriteDiffPackFormat (const Mesh & mesh,
23
const CSGeometry & geom,
24
const string & filename)
25
{
26
// double scale = globflags.GetNumFlag ("scale", 1);
27
double scale = 1;
28
29
ofstream outfile(filename.c_str());
30
31
if (mesh.GetDimension() == 3)
32
33
{
34
// Output compatible to Diffpack grid format
35
// Bartosz Sawicki <[email protected]>
36
37
int np = mesh.GetNP();
38
int ne = mesh.GetNE();
39
int nse = mesh.GetNSE();
40
ARRAY <int> BIname;
41
ARRAY <int> BCsinpoint;
42
int i, j, k, l;
43
44
45
outfile.precision(6);
46
outfile.setf (ios::fixed, ios::floatfield);
47
outfile.setf (ios::showpoint);
48
49
const Element & eldummy = mesh.VolumeElement((int)1);
50
outfile << "\n\n"
51
"Finite element mesh (GridFE):\n\n"
52
" Number of space dim. = 3\n"
53
" Number of elements = " << ne << "\n"
54
" Number of nodes = " << np << "\n\n"
55
" All elements are of the same type : dpTRUE\n"
56
" Max number of nodes in an element: "<< eldummy.GetNP() << "\n"
57
" Only one subdomain : dpFALSE\n"
58
" Lattice data ? 0\n\n\n\n";
59
60
for (i = 1; i <= nse; i++)
61
{
62
int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty();
63
int nbi=BIname.Size();
64
int found=0;
65
for (j = 1; j <= nbi; j++)
66
if(BI == BIname.Get(j)) found = 1;
67
if( ! found ) BIname.Append(BI);
68
}
69
70
outfile << " " << BIname.Size() << " Boundary indicators: ";
71
for (i =1 ; i <= BIname.Size(); i++)
72
outfile << BIname.Get(i) << " ";
73
outfile << "\n\n\n";
74
75
outfile << " Nodal coordinates and nodal boundary indicators,\n"
76
" the columns contain:\n"
77
" - node number\n"
78
" - coordinates\n"
79
" - no of boundary indicators that are set (ON)\n"
80
" - the boundary indicators that are set (ON) if any.\n"
81
"#\n";
82
83
for (i = 1; i <= np; i++)
84
{
85
const Point3d & p = mesh.Point(i);
86
87
outfile.width(4);
88
outfile << i << " (";
89
outfile.width(10);
90
outfile << p.X()/scale << ", ";
91
outfile.width(9);
92
outfile << p.Y()/scale << ", ";
93
outfile.width(9);
94
outfile << p.Z()/scale << ") ";
95
96
if(mesh[PointIndex(i)].Type() != INNERPOINT)
97
{
98
BCsinpoint.DeleteAll();
99
for (j = 1; j <= nse; j++)
100
{
101
for (k = 1; k <= mesh.SurfaceElement(j).GetNP(); k++)
102
{
103
if(mesh.SurfaceElement(j).PNum(k)==i)
104
{
105
int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty();
106
int nbcsp=BCsinpoint.Size();
107
int found = 0;
108
for (l = 1; l <= nbcsp; l++)
109
if(BC == BCsinpoint.Get(l)) found = 1;
110
if( ! found ) BCsinpoint.Append(BC);
111
}
112
}
113
}
114
int nbcsp = BCsinpoint.Size();
115
outfile << "[" << nbcsp << "] ";
116
for (j = 1; j <= nbcsp; j++)
117
outfile << BCsinpoint.Get(j) << " ";
118
outfile << "\n";
119
}
120
else outfile << "[0]\n";
121
122
}
123
124
outfile << "\n"
125
" Element types and connectivity\n"
126
" the columns contain:\n"
127
" - element number\n"
128
" - element type\n"
129
" - subdomain number\n"
130
" - the global node numbers of the nodes in the element.\n"
131
"#\n";
132
133
for (i = 1; i <= ne; i++)
134
{
135
const Element & el = mesh.VolumeElement(i);
136
outfile.width(5);
137
if(el.GetNP()==4)
138
outfile << i << " ElmT4n3D ";
139
else
140
outfile << i << " ElmT10n3D ";
141
outfile.width(4);
142
outfile << el.GetIndex() << " ";
143
if(el.GetNP()==10)
144
{
145
outfile.width(8);
146
outfile << el.PNum(1);
147
outfile.width(8);
148
outfile << el.PNum(3);
149
outfile.width(8);
150
outfile << el.PNum(2);
151
outfile.width(8);
152
outfile << el.PNum(4);
153
outfile.width(8);
154
outfile << el.PNum(6);
155
outfile.width(8);
156
outfile << el.PNum(8);
157
outfile.width(8);
158
outfile << el.PNum(5);
159
outfile.width(8);
160
outfile << el.PNum(7);
161
outfile.width(8);
162
outfile << el.PNum(10);
163
outfile.width(8);
164
outfile << el.PNum(9);
165
}
166
else
167
{
168
outfile.width(8);
169
outfile << el.PNum(1);
170
outfile.width(8);
171
outfile << el.PNum(3);
172
outfile.width(8);
173
outfile << el.PNum(2);
174
outfile.width(8);
175
outfile << el.PNum(4);
176
}
177
outfile << "\n";
178
}
179
} /* Diffpack */
180
181
else
182
183
{
184
// Output compatible to Diffpack grid format 2D
185
186
int np = mesh.GetNP();
187
//int ne = mesh.GetNE();
188
int nse = mesh.GetNSE();
189
ARRAY <int> BIname;
190
ARRAY <int> BCsinpoint;
191
int i, j, k, l;
192
193
194
outfile.precision(6);
195
outfile.setf (ios::fixed, ios::floatfield);
196
outfile.setf (ios::showpoint);
197
198
outfile << "\n\n"
199
"Finite element mesh (GridFE):\n\n"
200
" Number of space dim. = 2\n"
201
" Number of elements = " << nse << "\n"
202
" Number of nodes = " << np << "\n\n"
203
" All elements are of the same type : dpTRUE\n"
204
" Max number of nodes in an element: 3\n"
205
" Only one subdomain : dpFALSE\n"
206
" Lattice data ? 0\n\n\n\n";
207
208
for (i = 1; i <= nse; i++)
209
{
210
int BI=mesh.GetFaceDescriptor(mesh.SurfaceElement(i).GetIndex()).BCProperty();
211
int nbi=BIname.Size();
212
int found=0;
213
for (j = 1; j <= nbi; j++)
214
if(BI == BIname.Get(j)) found = 1;
215
if( ! found ) BIname.Append(BI);
216
}
217
218
outfile << " " << BIname.Size() << " Boundary indicators: ";
219
for (i =1 ; i <= BIname.Size(); i++)
220
outfile << BIname.Get(i) << " ";
221
outfile << "\n\n\n";
222
223
outfile << " Nodal coordinates and nodal boundary indicators,\n"
224
" the columns contain:\n"
225
" - node number\n"
226
" - coordinates\n"
227
" - no of boundary indicators that are set (ON)\n"
228
" - the boundary indicators that are set (ON) if any.\n"
229
"#\n";
230
231
for (i = 1; i <= np; i++)
232
{
233
const Point3d & p = mesh.Point(i);
234
235
outfile.width(4);
236
outfile << i << " (";
237
outfile.width(10);
238
outfile << p.X()/scale << ", ";
239
outfile.width(9);
240
outfile << p.Y()/scale << ", ";
241
242
if(mesh[PointIndex(i)].Type() != INNERPOINT)
243
{
244
BCsinpoint.DeleteAll();
245
for (j = 1; j <= nse; j++)
246
{
247
for (k = 1; k <= 2; k++)
248
{
249
if(mesh.SurfaceElement(j).PNum(k)==i)
250
{
251
int BC=mesh.GetFaceDescriptor(mesh.SurfaceElement(j).GetIndex()).BCProperty();
252
int nbcsp=BCsinpoint.Size();
253
int found = 0;
254
for (l = 1; l <= nbcsp; l++)
255
if(BC == BCsinpoint.Get(l)) found = 1;
256
if( ! found ) BCsinpoint.Append(BC);
257
}
258
}
259
}
260
int nbcsp = BCsinpoint.Size();
261
outfile << "[" << nbcsp << "] ";
262
for (j = 1; j <= nbcsp; j++)
263
outfile << BCsinpoint.Get(j) << " ";
264
outfile << "\n";
265
}
266
else outfile << "[0]\n";
267
268
}
269
270
outfile << "\n"
271
" Element types and connectivity\n"
272
" the columns contain:\n"
273
" - element number\n"
274
" - element type\n"
275
" - subdomain number\n"
276
" - the global node numbers of the nodes in the element.\n"
277
"#\n";
278
279
for (i = 1; i <= nse; i++)
280
{
281
const Element2d & el = mesh.SurfaceElement(i);
282
outfile.width(5);
283
outfile << i << " ElmT3n2D ";
284
outfile.width(4);
285
outfile << el.GetIndex() << " ";
286
outfile.width(8);
287
outfile << el.PNum(1);
288
outfile.width(8);
289
outfile << el.PNum(3);
290
outfile.width(8);
291
outfile << el.PNum(2);
292
outfile << "\n";
293
}
294
}
295
}
296
}
297
298