Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/interface/readuser.cpp
3206 views
1
//
2
// Read user dependent output file
3
//
4
5
6
#include <mystdlib.h>
7
8
9
#include <myadt.hpp>
10
#include <linalg.hpp>
11
#include <csg.hpp>
12
#include <meshing.hpp>
13
14
namespace netgen
15
{
16
#include "writeuser.hpp"
17
18
void ReadFile (Mesh & mesh,
19
const string & hfilename)
20
{
21
cout << "Read User File" << endl;
22
23
const char * filename = hfilename.c_str();
24
25
int i, j;
26
27
char reco[100];
28
int np, nbe;
29
30
31
32
// ".surf" - mesh
33
34
if ( (strlen (filename) > 5) &&
35
strcmp (&filename[strlen (filename)-5], ".surf") == 0 )
36
37
{
38
cout << "Surface file" << endl;
39
40
ifstream in (filename);
41
42
in >> reco;
43
in >> np;
44
for (i = 1; i <= np; i++)
45
{
46
Point3d p;
47
in >> p.X() >> p.Y() >> p.Z();
48
mesh.AddPoint (p);
49
}
50
51
mesh.ClearFaceDescriptors();
52
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
53
54
in >> nbe;
55
// int invert = globflags.GetDefineFlag ("invertsurfacemesh");
56
for (i = 1; i <= nbe; i++)
57
{
58
Element2d el;
59
int hi;
60
61
el.SetIndex(1);
62
63
// in >> hi;
64
for (j = 1; j <= 3; j++)
65
{
66
in >> el.PNum(j);
67
// el.PNum(j)++;
68
if (el.PNum(j) < PointIndex(1) ||
69
el.PNum(j) > PointIndex(np))
70
{
71
cerr << "Point Number " << el.PNum(j) << " out of range 1..."
72
<< np << endl;
73
return;
74
}
75
}
76
77
/*
78
if (invert)
79
swap (el.PNum(2), el.PNum(3));
80
*/
81
82
mesh.AddSurfaceElement (el);
83
}
84
85
86
cout << "points: " << np << " faces: " << nbe << endl;
87
}
88
89
90
91
92
93
// Universal mesh (AVL)
94
if ( (strlen (filename) > 4) &&
95
strcmp (&filename[strlen (filename)-4], ".unv") == 0 )
96
{
97
int i, j, k;
98
99
double h;
100
char reco[100];
101
int np, nbe;
102
int invert;
103
104
105
ifstream in(filename);
106
107
invert = 0; // globflags.GetDefineFlag ("invertsurfacemesh");
108
double scale = 1; // globflags.GetNumFlag ("scale", 1);
109
110
mesh.ClearFaceDescriptors();
111
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
112
113
114
while (in.good())
115
{
116
in >> reco;
117
if (strcmp (reco, "NODES") == 0)
118
{
119
cout << "nodes found" << endl;
120
for (j = 1; j <= 4; j++)
121
in >> reco; // read dummy
122
123
while (1)
124
{
125
int pi, hi;
126
double x, y, z;
127
Point3d p;
128
129
in >> pi;
130
if (pi == -1)
131
break;
132
133
in >> hi >> hi >> hi;
134
in >> p.X() >> p.Y() >> p.Z();
135
136
p.X() *= scale;
137
p.Y() *= scale;
138
p.Z() *= scale;
139
140
141
mesh.AddPoint (p);
142
}
143
}
144
145
if (strcmp (reco, "ELEMENTS") == 0)
146
{
147
cout << "elements found" << endl;
148
for (j = 1; j <= 4; j++)
149
in >> reco; // read dummy
150
151
while (1)
152
{
153
int hi;
154
in >> hi;
155
if (hi == -1) break;
156
for (j = 1; j <= 7; j++)
157
in >> hi;
158
159
Element2d el;
160
el.SetIndex(1);
161
in >> el.PNum(1) >> el.PNum(2) >> el.PNum(3);
162
163
if (invert)
164
swap (el.PNum(2), el.PNum(3));
165
mesh.AddSurfaceElement (el);
166
167
for (j = 1; j <= 5; j++)
168
in >> hi;
169
}
170
}
171
}
172
173
174
Point3d pmin, pmax;
175
mesh.GetBox (pmin, pmax);
176
cout << "bounding-box = " << pmin << "-" << pmax << endl;
177
}
178
179
180
181
// fepp format2d:
182
183
if ( (strlen (filename) > 7) &&
184
strcmp (&filename[strlen (filename)-7], ".mesh2d") == 0 )
185
{
186
cout << "Reading FEPP2D Mesh" << endl;
187
188
char buf[100];
189
int np, ne, nseg, i, j;
190
191
ifstream in (filename);
192
193
in >> buf;
194
195
in >> nseg;
196
for (i = 1; i <= nseg; i++)
197
{
198
int bound, p1, p2;
199
in >> bound >> p1 >> p2;
200
// forget them
201
}
202
203
in >> ne;
204
for (i = 1; i <= ne; i++)
205
{
206
int mat, nelp;
207
in >> mat >> nelp;
208
Element2d el (nelp == 3 ? TRIG : QUAD);
209
el.SetIndex (mat);
210
for (j = 1; j <= nelp; j++)
211
in >> el.PNum(j);
212
mesh.AddSurfaceElement (el);
213
}
214
215
in >> np;
216
for (i = 1; i <= np; i++)
217
{
218
Point3d p(0,0,0);
219
in >> p.X() >> p.Y();
220
mesh.AddPoint (p);
221
}
222
}
223
224
225
else if ( (strlen (filename) > 5) &&
226
strcmp (&filename[strlen (filename)-5], ".mesh") == 0 )
227
{
228
cout << "Reading Neutral Format" << endl;
229
230
int np, ne, nse, i, j;
231
232
ifstream in (filename);
233
234
in >> np;
235
236
if (in.good())
237
{
238
// file starts with an integer
239
240
for (i = 1; i <= np; i++)
241
{
242
Point3d p(0,0,0);
243
in >> p.X() >> p.Y() >> p.Z();
244
mesh.AddPoint (p);
245
}
246
247
in >> ne;
248
for (i = 1; i <= ne; i++)
249
{
250
int mat;
251
in >> mat;
252
Element el (4);
253
el.SetIndex (mat);
254
for (j = 1; j <= 4; j++)
255
in >> el.PNum(j);
256
mesh.AddVolumeElement (el);
257
}
258
259
mesh.AddFaceDescriptor (FaceDescriptor (1, 1, 0, 0));
260
261
in >> nse;
262
for (i = 1; i <= nse; i++)
263
{
264
int mat, nelp;
265
in >> mat;
266
Element2d el (TRIG);
267
el.SetIndex (mat);
268
for (j = 1; j <= 3; j++)
269
in >> el.PNum(j);
270
mesh.AddSurfaceElement (el);
271
}
272
}
273
else
274
{
275
char buf[100];
276
in.clear();
277
do
278
{
279
in >> buf;
280
cout << "buf = " << buf << endl;
281
if (strcmp (buf, "points") == 0)
282
{
283
in >> np;
284
cout << "np = " << np << endl;
285
}
286
}
287
while (in.good());
288
}
289
}
290
291
292
if ( (strlen (filename) > 4) &&
293
strcmp (&filename[strlen (filename)-4], ".emt") == 0 )
294
{
295
ifstream inemt (filename);
296
297
string pktfile = filename;
298
int len = strlen (filename);
299
pktfile[len-3] = 'p';
300
pktfile[len-2] = 'k';
301
pktfile[len-1] = 't';
302
cout << "pktfile = " << pktfile << endl;
303
304
int np, nse, i;
305
int num, bcprop;
306
ifstream inpkt (pktfile.c_str());
307
inpkt >> np;
308
ARRAY<double> values(np);
309
for (i = 1; i <= np; i++)
310
{
311
Point3d p(0,0,0);
312
inpkt >> p.X() >> p.Y() >> p.Z()
313
>> bcprop >> values.Elem(i);
314
mesh.AddPoint (p);
315
}
316
317
mesh.ClearFaceDescriptors();
318
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
319
mesh.GetFaceDescriptor(1).SetBCProperty (1);
320
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
321
mesh.GetFaceDescriptor(2).SetBCProperty (2);
322
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
323
mesh.GetFaceDescriptor(3).SetBCProperty (3);
324
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
325
mesh.GetFaceDescriptor(4).SetBCProperty (4);
326
mesh.AddFaceDescriptor (FaceDescriptor(0,1,0,0));
327
mesh.GetFaceDescriptor(5).SetBCProperty (5);
328
329
int p1, p2, p3;
330
double value;
331
inemt >> nse;
332
for (i = 1; i <= nse; i++)
333
{
334
inemt >> p1 >> p2 >> p3 >> bcprop >> value;
335
336
if (bcprop < 1 || bcprop > 4)
337
cerr << "bcprop out of range, bcprop = " << bcprop << endl;
338
p1++;
339
p2++;
340
p3++;
341
if (p1 < 1 || p1 > np || p2 < 1 || p2 > np || p3 < 1 || p3 > np)
342
{
343
cout << "p1 = " << p1 << " p2 = " << p2 << " p3 = " << p3 << endl;
344
}
345
346
if (i > 110354) Swap (p2, p3);
347
if (mesh.Point(p1)(0) < 0.25)
348
Swap (p2,p3);
349
350
Element2d el(TRIG);
351
352
if (bcprop == 1)
353
{
354
if (values.Get(p1) < -69999)
355
el.SetIndex(1);
356
else
357
el.SetIndex(2);
358
}
359
else
360
el.SetIndex(3);
361
362
363
el.PNum(1) = p1;
364
el.PNum(2) = p2;
365
el.PNum(3) = p3;
366
mesh.AddSurfaceElement (el);
367
}
368
369
370
ifstream incyl ("ngusers/guenter/cylinder.surf");
371
int npcyl, nsecyl;
372
incyl >> npcyl;
373
cout << "npcyl = " << npcyl << endl;
374
for (i = 1; i <= npcyl; i++)
375
{
376
Point3d p(0,0,0);
377
incyl >> p.X() >> p.Y() >> p.Z();
378
mesh.AddPoint (p);
379
}
380
incyl >> nsecyl;
381
cout << "nsecyl = " << nsecyl << endl;
382
for (i = 1; i <= nsecyl; i++)
383
{
384
incyl >> p1 >> p2 >> p3;
385
p1 += np;
386
p2 += np;
387
p3 += np;
388
Element2d el(TRIG);
389
el.SetIndex(5);
390
el.PNum(1) = p1;
391
el.PNum(2) = p2;
392
el.PNum(3) = p3;
393
mesh.AddSurfaceElement (el);
394
}
395
}
396
397
398
// .tet mesh
399
if ( (strlen (filename) > 4) &&
400
strcmp (&filename[strlen (filename)-4], ".tet") == 0 )
401
{
402
ReadTETFormat (mesh, filename);
403
}
404
}
405
406
}
407
408
409