Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/geom2d/splinegeometry2.cpp
3206 views
1
2
OLD IMPLEMENTATION, NOT USED ANYMORE!
3
4
5
6
/*
7
8
2d Spline curve for Mesh generator
9
10
*/
11
12
#include <mystdlib.h>
13
#include <csg.hpp>
14
#include <linalg.hpp>
15
#include <meshing.hpp>
16
17
18
namespace netgen
19
20
{
21
using namespace netgen;
22
23
#include "spline2d.hpp"
24
#include "splinegeometry2.hpp"
25
26
27
28
SplineGeometry2d :: ~SplineGeometry2d()
29
{
30
for(int i=0; i<splines.Size(); i++)
31
{
32
delete splines[i];
33
}
34
splines.DeleteAll();
35
geompoints.DeleteAll();
36
}
37
38
void SplineGeometry2d :: CSGLoad (CSGScanner & scan)
39
{
40
double x,y,hd;
41
int nump, numseg;
42
43
//scan.ReadNext();
44
45
scan >> nump >> ';';
46
47
hd = 1;
48
geompoints.SetSize(nump);
49
for(int i = 0; i<nump; i++)
50
{
51
scan >> x >> ',' >> y >> ';';
52
geompoints[i] = GeomPoint2d(x,y,hd);
53
}
54
55
scan >> numseg;// >> ';';
56
57
splines.SetSize(numseg);
58
59
int pnums,pnum1,pnum2,pnum3;
60
61
62
for(int i = 0; i<numseg; i++)
63
{
64
scan >> ';' >> pnums >> ',';
65
if (pnums == 2)
66
{
67
scan >> pnum1 >> ',' >> pnum2;// >> ';';
68
splines[i] = new LineSegment(geompoints[pnum1-1],
69
geompoints[pnum2-1]);
70
}
71
else if (pnums == 3)
72
{
73
scan >> pnum1 >> ',' >> pnum2 >> ','
74
>> pnum3;// >> ';';
75
splines[i] = new SplineSegment3(geompoints[pnum1-1],
76
geompoints[pnum2-1],
77
geompoints[pnum3-1]);
78
}
79
else if (pnums == 4)
80
{
81
scan >> pnum1 >> ',' >> pnum2 >> ','
82
>> pnum3;// >> ';';
83
splines[i] = new CircleSegment(geompoints[pnum1-1],
84
geompoints[pnum2-1],
85
geompoints[pnum3-1]);
86
87
}
88
89
}
90
91
92
93
}
94
95
96
void SplineGeometry2d :: Load (const char * filename)
97
{
98
cout << "load 2d" << endl;
99
ifstream infile;
100
int nump, numseg, leftdom, rightdom;
101
double x, y;
102
int hi1, hi2, hi3;
103
double hd;
104
char buf[50], ch;
105
106
infile.open (filename);
107
108
if (! infile.good() )
109
throw NgException(string ("2D Input file '") +
110
string (filename) +
111
string ("' not available!"));
112
113
infile >> buf; // file recognition
114
infile >> elto0;
115
116
infile >> nump;
117
for (int i = 0; i < nump; i++)
118
{
119
infile >> x >> y >> hd;
120
121
Flags flags;
122
123
ch = 'a';
124
// infile >> ch;
125
do {
126
infile.get (ch);
127
} while (isspace(ch) && ch != '\n');
128
while (ch == '-')
129
{
130
char flag[100];
131
flag[0]='-';
132
infile >> (flag+1);
133
flags.SetCommandLineFlag (flag);
134
ch = 'a';
135
do {
136
infile.get (ch);
137
} while (isspace(ch) && ch != '\n');
138
}
139
140
if (infile.good())
141
infile.putback (ch);
142
143
geompoints.Append (GeomPoint2d(x, y, hd));
144
geompoints.Last().hpref = flags.GetDefineFlag ("hpref");
145
cout << "point " << x << ", " << y << endl;
146
}
147
148
infile >> numseg;
149
SplineSegment * spline = 0;
150
for (int i = 0; i < numseg; i++)
151
{
152
infile >> leftdom >> rightdom;
153
154
// cout << "add spline " << i << ", left = " << leftdom << endl;
155
156
infile >> buf;
157
// type of spline segement
158
if (strcmp (buf, "2") == 0)
159
{ // a line
160
infile >> hi1 >> hi2;
161
spline = new LineSegment(geompoints[hi1-1],
162
geompoints[hi2-1]);
163
}
164
else if (strcmp (buf, "3") == 0)
165
{ // a rational spline
166
infile >> hi1 >> hi2 >> hi3;
167
spline = new SplineSegment3 (geompoints[hi1-1],
168
geompoints[hi2-1],
169
geompoints[hi3-1]);
170
}
171
else if (strcmp (buf, "4") == 0)
172
{ // an arc
173
infile >> hi1 >> hi2 >> hi3;
174
spline = new CircleSegment (geompoints[hi1-1],
175
geompoints[hi2-1],
176
geompoints[hi3-1]);
177
break;
178
}
179
else if (strcmp (buf, "discretepoints") == 0)
180
{
181
int npts;
182
infile >> npts;
183
ARRAY<Point<2> > pts(npts);
184
for (int j = 0; j < npts; j++)
185
infile >> pts[j](0) >> pts[j](1);
186
187
spline = new DiscretePointsSegment (pts);
188
cout << "pts = " << pts << endl;
189
}
190
191
infile >> spline->reffak;
192
spline -> leftdom = leftdom;
193
spline -> rightdom = rightdom;
194
splines.Append (spline);
195
196
197
Flags flags;
198
ch = 'a';
199
infile >> ch;
200
while (ch == '-')
201
{
202
char flag[100];
203
flag[0]='-';
204
infile >> (flag+1);
205
flags.SetCommandLineFlag (flag);
206
ch = 'a';
207
infile >> ch;
208
}
209
210
if (infile.good())
211
infile.putback (ch);
212
213
splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));
214
splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||
215
int (flags.GetDefineFlag ("hprefleft"));
216
splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||
217
int (flags.GetDefineFlag ("hprefright"));
218
splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));
219
}
220
221
cout << "load complete" << endl;
222
223
infile.close();
224
}
225
226
227
228
void SplineGeometry2d ::
229
PartitionBoundary (double h, Mesh & mesh2d)
230
{
231
Box<2> bbox;
232
GetBoundingBox (bbox);
233
double dist = Dist (bbox.PMin(), bbox.PMax());
234
Point<3> pmin(bbox.PMin()(0), bbox.PMin()(1), -dist);
235
Point<3> pmax(bbox.PMax()(0), bbox.PMax()(1), dist);
236
237
cout << "searchtree from " << pmin << " to " << pmax << endl;
238
Point3dTree searchtree (pmin, pmax);
239
240
for (int i = 0; i < splines.Size(); i++)
241
if (splines[i]->copyfrom == -1)
242
splines[i]->Partition(h, elto0, mesh2d, searchtree, i+1);
243
else
244
CopyEdgeMesh (splines[i]->copyfrom, i+1, mesh2d, searchtree);
245
}
246
247
248
void SplineGeometry2d :: CopyEdgeMesh (int from, int to, Mesh & mesh, Point3dTree & searchtree)
249
{
250
int i, j, k;
251
252
ARRAY<int, PointIndex::BASE> mappoints (mesh.GetNP());
253
ARRAY<double, PointIndex::BASE> param (mesh.GetNP());
254
mappoints = -1;
255
param = 0;
256
257
Point3d pmin, pmax;
258
mesh.GetBox (pmin, pmax);
259
double diam2 = Dist2(pmin, pmax);
260
261
cout << "copy edge, from = " << from << " to " << to << endl;
262
263
for (i = 1; i <= mesh.GetNSeg(); i++)
264
{
265
const Segment & seg = mesh.LineSegment(i);
266
if (seg.edgenr == from)
267
{
268
mappoints.Elem(seg.p1) = 1;
269
param.Elem(seg.p1) = seg.epgeominfo[0].dist;
270
271
mappoints.Elem(seg.p2) = 1;
272
param.Elem(seg.p2) = seg.epgeominfo[1].dist;
273
}
274
}
275
276
bool mapped = false;
277
for (i = 1; i <= mappoints.Size(); i++)
278
{
279
if (mappoints.Get(i) != -1)
280
{
281
Point<2> newp = splines.Get(to)->GetPoint (param.Get(i));
282
Point<3> newp3 (newp(0), newp(1), 0);
283
284
int npi = -1;
285
286
for (PointIndex pi = PointIndex::BASE;
287
pi < mesh.GetNP()+PointIndex::BASE; pi++)
288
if (Dist2 (mesh.Point(pi), newp3) < 1e-12 * diam2)
289
npi = pi;
290
291
if (npi == -1)
292
{
293
npi = mesh.AddPoint (newp3);
294
searchtree.Insert (newp3, npi);
295
}
296
297
mappoints.Elem(i) = npi;
298
299
mesh.GetIdentifications().Add (i, npi, to);
300
mapped = trueM
301
}
302
}
303
if(mapped)
304
mesh.GetIdentifications().SetType(to,Identifications::PERIODIC);
305
306
// copy segments
307
int oldnseg = mesh.GetNSeg();
308
for (i = 1; i <= oldnseg; i++)
309
{
310
const Segment & seg = mesh.LineSegment(i);
311
if (seg.edgenr == from)
312
{
313
Segment nseg;
314
nseg.edgenr = to;
315
nseg.si = splines.Get(to)->bc;
316
nseg.p1 = mappoints.Get(seg.p1);
317
nseg.p2 = mappoints.Get(seg.p2);
318
nseg.domin = splines.Get(to)->leftdom;
319
nseg.domout = splines.Get(to)->rightdom;
320
321
nseg.epgeominfo[0].edgenr = to;
322
nseg.epgeominfo[0].dist = param.Get(seg.p1);
323
nseg.epgeominfo[1].edgenr = to;
324
nseg.epgeominfo[1].dist = param.Get(seg.p2);
325
mesh.AddSegment (nseg);
326
}
327
}
328
}
329
330
331
void SplineGeometry2d ::
332
GetBoundingBox (Box<2> & box) const
333
{
334
if (!splines.Size())
335
{
336
box.Set (Point<2> (0,0));
337
return;
338
}
339
340
ARRAY<Point<2> > points;
341
for (int i = 0; i < splines.Size(); i++)
342
{
343
splines[i]->GetPoints (20, points);
344
345
if (i == 0) box.Set(points[0]);
346
for (int j = 0; j < points.Size(); j++)
347
box.Add (points[j]);
348
}
349
}
350
351
void SplineGeometry2d ::
352
SetGrading (const double grading)
353
{ elto0 = grading;}
354
355
void SplineGeometry2d ::
356
AppendPoint (const double x, const double y, const double reffac, const bool hpref)
357
{
358
geompoints.Append (GeomPoint2d(x, y, reffac));
359
geompoints.Last().hpref = hpref;
360
}
361
362
363
void SplineGeometry2d ::
364
AppendSegment(SplineSegment * spline, const int leftdomain, const int rightdomain,
365
const int bc,
366
const double reffac, const bool hprefleft, const bool hprefright,
367
const int copyfrom)
368
{
369
spline -> leftdom = leftdomain;
370
spline -> rightdom = rightdomain;
371
spline -> bc = (bc >= 0) ? bc : (splines.Size()+1);
372
spline -> reffak = reffac;
373
spline -> hpref_left = hprefleft;
374
spline -> hpref_right = hprefright;
375
spline -> copyfrom = copyfrom;
376
377
splines.Append(spline);
378
}
379
380
void SplineGeometry2d ::
381
AppendLineSegment (const int n1, const int n2, const int leftdomain, const int rightdomain,
382
const int bc,
383
const double reffac, const bool hprefleft, const bool hprefright,
384
const int copyfrom)
385
{
386
SplineSegment * spline = new LineSegment(geompoints[n1],geompoints[n2]);
387
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
388
}
389
void SplineGeometry2d ::
390
AppendSplineSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,
391
const int bc,
392
const double reffac, const bool hprefleft, const bool hprefright,
393
const int copyfrom)
394
{
395
SplineSegment * spline = new SplineSegment3(geompoints[n1],geompoints[n2],geompoints[n3]);
396
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
397
}
398
void SplineGeometry2d ::
399
AppendCircleSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,
400
const int bc,
401
const double reffac, const bool hprefleft, const bool hprefright,
402
const int copyfrom)
403
{
404
SplineSegment * spline = new CircleSegment(geompoints[n1],geompoints[n2],geompoints[n3]);
405
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
406
}
407
void SplineGeometry2d ::
408
AppendDiscretePointsSegment (const ARRAY< Point<2> > & points, const int leftdomain, const int rightdomain,
409
const int bc,
410
const double reffac, const bool hprefleft, const bool hprefright,
411
const int copyfrom)
412
{
413
SplineSegment * spline = new DiscretePointsSegment(points);
414
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
415
}
416
417
}
418
419