Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/geom2d/splinegeometry.cpp
3206 views
1
/*
2
3
2d Spline curve for Mesh generator
4
5
*/
6
7
8
#include <mystdlib.h>
9
#include <csg.hpp>
10
#include <geometry2d.hpp>
11
#include "meshing.hpp"
12
13
namespace netgen
14
{
15
16
//using namespace netgen;
17
18
template<int D>
19
void SplineGeometry<D> :: LoadDataV2 ( ifstream & infile )
20
{
21
PrintMessage (1, "Load 2D Geometry V2");
22
int nump, leftdom, rightdom;
23
Point<D> x;
24
int hi1, hi2, hi3;
25
double hd;
26
char buf[50], ch;
27
int pointnr;
28
29
string keyword;
30
31
ARRAY < GeomPoint<D> > infilepoints (0);
32
ARRAY <int> pointnrs (0);
33
nump = 0;
34
int numdomains = 0;
35
36
37
TestComment ( infile );
38
// refinement factor
39
infile >> elto0;
40
TestComment ( infile );
41
42
43
// test if next ch is a letter, i.e. new keyword starts
44
bool ischar = false;
45
46
while ( infile.good() )
47
{
48
infile >> keyword;
49
50
ischar = false;
51
52
if ( keyword == "points" )
53
{
54
PrintMessage (3, "load points");
55
infile.get(ch);
56
infile.putback(ch);
57
58
// test if ch is a letter
59
if ( int(ch) >= 65 && int(ch) <=90 )
60
ischar = true;
61
if ( int(ch) >= 97 && int(ch) <= 122 )
62
ischar = true;
63
64
while ( ! ischar )
65
{
66
TestComment ( infile );
67
infile >> pointnr;
68
// pointnrs 1-based
69
if ( pointnr > nump ) nump = pointnr;
70
pointnrs.Append(pointnr);
71
72
for(int j=0; j<D; j++)
73
infile >> x(j);
74
// hd is now optional, default 1
75
// infile >> hd;
76
hd = 1;
77
78
Flags flags;
79
80
81
// get flags,
82
ch = 'a';
83
// infile >> ch;
84
do
85
{
86
infile.get (ch);
87
// if another int-value, set refinement flag to this value
88
// (corresponding to old files)
89
if ( int (ch) >= 48 && int(ch) <= 57 )
90
{
91
infile.putback(ch);
92
infile >> hd;
93
infile.get(ch);
94
}
95
}
96
while (isspace(ch) && ch != '\n');
97
while (ch == '-')
98
{
99
char flag[100];
100
flag[0]='-';
101
infile >> (flag+1);
102
flags.SetCommandLineFlag (flag);
103
ch = 'a';
104
do {
105
infile.get (ch);
106
} while (isspace(ch) && ch != '\n');
107
}
108
if (infile.good())
109
infile.putback (ch);
110
111
if ( hd == 1 )
112
hd = flags.GetNumFlag ( "ref", 1.0);
113
// geompoints.Append (GeomPoint<D>(x, hd));
114
115
infilepoints.Append ( GeomPoint<D>(x, hd) );
116
infilepoints.Last().hpref = flags.GetDefineFlag ("hpref");
117
118
TestComment(infile);
119
infile.get(ch);
120
infile.putback(ch);
121
122
// test if letter
123
if ( int(ch) >= 65 && int(ch) <=90 )
124
ischar = true;
125
if ( int(ch) >= 97 && int(ch) <= 122 )
126
ischar = true;
127
}
128
129
// infile.putback (ch);
130
131
geompoints.SetSize(nump);
132
for ( int i = 0; i < nump; i++ )
133
{
134
geompoints[pointnrs[i] - 1] = infilepoints[i];
135
geompoints[pointnrs[i] - 1].hpref = infilepoints[i].hpref;
136
}
137
TestComment(infile);
138
}
139
140
else if ( keyword == "segments" )
141
{
142
PrintMessage (3, "load segments");
143
144
bcnames.SetSize(0);
145
infile.get(ch);
146
infile.putback(ch);
147
int i = 0;
148
149
// test if ch is a letter
150
if ( int(ch) >= 65 && int(ch) <=90 )
151
ischar = true;
152
if ( int(ch) >= 97 && int(ch) <= 122 )
153
ischar = true;
154
155
while ( !ischar ) //ch != 'p' && ch != 'm' )
156
{
157
i++;
158
TestComment ( infile );
159
160
SplineSeg<D> * spline = 0;
161
TestComment ( infile );
162
163
infile >> leftdom >> rightdom;
164
165
if ( leftdom > numdomains ) numdomains = leftdom;
166
if ( rightdom > numdomains ) numdomains = rightdom;
167
168
169
infile >> buf;
170
// type of spline segement
171
if (strcmp (buf, "2") == 0)
172
{ // a line
173
infile >> hi1 >> hi2;
174
spline = new LineSeg<D>(geompoints[hi1-1],
175
geompoints[hi2-1]);
176
}
177
else if (strcmp (buf, "3") == 0)
178
{ // a rational spline
179
infile >> hi1 >> hi2 >> hi3;
180
spline = new SplineSeg3<D> (geompoints[hi1-1],
181
geompoints[hi2-1],
182
geompoints[hi3-1]);
183
}
184
else if (strcmp (buf, "4") == 0)
185
{ // an arc
186
infile >> hi1 >> hi2 >> hi3;
187
spline = new CircleSeg<D> (geompoints[hi1-1],
188
geompoints[hi2-1],
189
geompoints[hi3-1]);
190
break;
191
}
192
else if (strcmp (buf, "discretepoints") == 0)
193
{
194
int npts;
195
infile >> npts;
196
ARRAY< Point<D> > pts(npts);
197
for (int j = 0; j < npts; j++)
198
for(int k=0; k<D; k++)
199
infile >> pts[j](k);
200
201
spline = new DiscretePointsSeg<D> (pts);
202
}
203
204
// infile >> spline->reffak;
205
spline -> leftdom = leftdom;
206
spline -> rightdom = rightdom;
207
splines.Append (spline);
208
209
210
// hd is now optional, default 1
211
// infile >> hd;
212
hd = 1;
213
infile >> ch;
214
215
// get refinement parameter, if it is there
216
//infile.get (ch);
217
// if another int-value, set refinement flag to this value
218
// (corresponding to old files)
219
220
if ( int (ch) >= 48 && int(ch) <= 57 )
221
{
222
infile.putback(ch);
223
infile >> hd;
224
infile >> ch ;
225
}
226
227
// get flags,
228
Flags flags;
229
while (ch == '-')
230
{
231
char flag[100];
232
flag[0]='-';
233
infile >> (flag+1);
234
flags.SetCommandLineFlag (flag);
235
ch = 'a';
236
infile >> ch;
237
}
238
239
if (infile.good())
240
infile.putback (ch);
241
242
splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));
243
splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||
244
int (flags.GetDefineFlag ("hprefleft"));
245
splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||
246
int (flags.GetDefineFlag ("hprefright"));
247
splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));
248
splines.Last()->reffak = flags.GetNumFlag ("ref", 1 );
249
if ( hd != 1 )
250
splines.Last()->reffak = hd;
251
252
if ( flags.StringFlagDefined("bcname") )
253
{
254
int mybc = splines.Last()->bc-1;
255
for ( int ii = bcnames.Size(); ii <= mybc; ii++ )
256
bcnames.Append ( new string ("default"));
257
if ( bcnames[mybc] ) delete bcnames[mybc];
258
bcnames[mybc] = new string (flags.GetStringFlag("bcname","") );
259
}
260
261
TestComment(infile);
262
infile.get(ch);
263
infile.putback(ch);
264
265
// test if ch is a letter
266
if ( int(ch) >= 65 && int(ch) <=90 )
267
ischar = true;
268
if ( int(ch) >= 97 && int(ch) <= 122 )
269
ischar = true;
270
271
}
272
273
infile.get(ch);
274
infile.putback(ch);
275
276
277
}
278
else if ( keyword == "materials" )
279
{
280
TestComment ( infile );
281
int domainnr;
282
char material[100];
283
284
if ( !infile.good() )
285
return;
286
287
materials.SetSize(numdomains) ;
288
maxh.SetSize ( numdomains ) ;
289
for ( int i = 0; i < numdomains; i++)
290
maxh[i] = 1000;
291
quadmeshing.SetSize ( numdomains );
292
quadmeshing = false;
293
tensormeshing.SetSize ( numdomains );
294
tensormeshing = false;
295
296
297
TestComment ( infile );
298
299
for ( int i=0; i<numdomains; i++)
300
materials [ i ] = new char[100];
301
302
for ( int i=0; i<numdomains && infile.good(); i++)
303
{
304
TestComment ( infile );
305
infile >> domainnr;
306
infile >> material;
307
308
strcpy (materials[domainnr-1], material);
309
310
Flags flags;
311
ch = 'a';
312
infile >> ch;
313
while (ch == '-')
314
{
315
char flag[100];
316
flag[0]='-';
317
infile >> (flag+1);
318
flags.SetCommandLineFlag (flag);
319
ch = 'a';
320
infile >> ch;
321
}
322
323
if (infile.good())
324
infile.putback (ch);
325
326
maxh[domainnr-1] = flags.GetNumFlag ( "maxh", 1000);
327
if (flags.GetDefineFlag("quad")) quadmeshing[domainnr-1] = true;
328
if (flags.GetDefineFlag("tensor")) tensormeshing[domainnr-1] = true;
329
}
330
}
331
}
332
return;
333
}
334
335
336
337
338
339
340
341
// check if comments in a .in2d file...
342
// template <int D>
343
// void SplineGeometry<D> :: TestComment ( ifstream & infile )
344
// {
345
// bool comment = true;
346
// char ch;
347
// infile.get(ch);
348
// infile.putback(ch);
349
// int ii = 0;
350
// while ( comment == true && ii < 100)
351
// {
352
// infile.get(ch);
353
// if ( ch == '#' )
354
// while ( ch != '\n')
355
// {
356
// infile.get(ch);
357
// comment = false;
358
// }
359
// else if ( ch == '\n' )
360
// {
361
// comment = true;
362
// ii ++;
363
// }
364
// else
365
// {
366
// infile.putback(ch);
367
// comment = false;
368
// }
369
//
370
// infile.get(ch) ;
371
// if ( ch == '\n' || ch == '#' )
372
// {
373
// comment = true;
374
// }
375
// infile.putback(ch);
376
// if ( !comment ) break;
377
// }
378
// cerr << "** comment done" << endl;
379
// cerr << " * last char was " << ch << endl;
380
// return;
381
//
382
// }
383
384
// herbert: fixed TestComment
385
template <int D>
386
void SplineGeometry<D> :: TestComment ( ifstream & infile )
387
{
388
bool comment = true;
389
char ch;
390
while ( comment == true && !infile.eof() ) {
391
infile.get(ch);
392
if ( ch == '#' ) { // skip comments
393
while ( ch != '\n' && !infile.eof() ) {
394
infile.get(ch);
395
}
396
}
397
else if ( ch == '\n' ) { // skip empty lines
398
;
399
}
400
else if ( isspace(ch) ) { // skip whitespaces
401
;
402
}
403
else { // end of comment
404
infile.putback(ch);
405
comment = false;
406
}
407
}
408
return;
409
}
410
411
412
413
template<int D>
414
SplineGeometry<D> :: ~SplineGeometry()
415
{
416
for(int i=0; i<splines.Size(); i++)
417
{
418
delete splines[i];
419
}
420
splines.DeleteAll();
421
geompoints.DeleteAll();
422
for (int i=0; i<materials.Size(); i++)
423
delete materials[i];
424
for ( int i = 0; i < bcnames.Size(); i++ )
425
if ( bcnames[i] ) delete bcnames[i];
426
}
427
428
429
430
template<int D>
431
int SplineGeometry<D> :: Load (const ARRAY<double> & raw_data, const int startpos)
432
{
433
int pos = startpos;
434
if(raw_data[pos] != D)
435
throw NgException("wrong dimension of spline raw_data");
436
437
pos++;
438
439
elto0 = raw_data[pos]; pos++;
440
441
splines.SetSize(int(raw_data[pos]));
442
pos++;
443
444
ARRAY< Point<D> > pts(3);
445
446
for(int i=0; i<splines.Size(); i++)
447
{
448
int type = int(raw_data[pos]);
449
pos++;
450
451
for(int j=0; j<type; j++)
452
for(int k=0; k<D; k++)
453
{
454
pts[j](k) = raw_data[pos];
455
pos++;
456
}
457
458
if (type == 2)
459
{
460
splines[i] = new LineSeg<D>(GeomPoint<D>(pts[0],1),
461
GeomPoint<D>(pts[1],1));
462
//(*testout) << "appending line segment "
463
// << pts[0] << " -- " << pts[1] << endl;
464
}
465
else if (type == 3)
466
{
467
splines[i] = new SplineSeg3<D>(GeomPoint<D>(pts[0],1),
468
GeomPoint<D>(pts[1],1),
469
GeomPoint<D>(pts[2],1));
470
//(*testout) << "appending spline segment "
471
// << pts[0] << " -- " << pts[1] << " -- " << pts[2] << endl;
472
473
}
474
else
475
throw NgException("something wrong with spline raw data");
476
477
}
478
return pos;
479
}
480
481
template<int D>
482
void SplineGeometry<D> :: GetRawData (ARRAY<double> & raw_data) const
483
{
484
raw_data.Append(D);
485
raw_data.Append(elto0);
486
487
488
raw_data.Append(splines.Size());
489
for(int i=0; i<splines.Size(); i++)
490
splines[i]->GetRawData(raw_data);
491
492
493
}
494
495
template<int D>
496
void SplineGeometry<D> :: CSGLoad (CSGScanner & scan)
497
{
498
double hd;
499
Point<D> x;
500
int nump, numseg;
501
502
//scan.ReadNext();
503
scan >> nump >> ';';
504
505
hd = 1;
506
geompoints.SetSize(nump);
507
for(int i = 0; i<nump; i++)
508
{
509
if(D==2)
510
scan >> x(0) >> ',' >> x(1) >> ';';
511
else if(D==3)
512
scan >> x(0) >> ',' >> x(1) >> ',' >> x(2) >> ';';
513
514
geompoints[i] = GeomPoint<D>(x,hd);
515
}
516
517
scan >> numseg;// >> ';';
518
519
splines.SetSize(numseg);
520
521
int pnums,pnum1,pnum2,pnum3;
522
523
524
for(int i = 0; i<numseg; i++)
525
{
526
scan >> ';' >> pnums >> ',';
527
if (pnums == 2)
528
{
529
scan >> pnum1 >> ',' >> pnum2;// >> ';';
530
splines[i] = new LineSeg<D>(geompoints[pnum1-1],
531
geompoints[pnum2-1]);
532
}
533
else if (pnums == 3)
534
{
535
scan >> pnum1 >> ',' >> pnum2 >> ','
536
>> pnum3;// >> ';';
537
splines[i] = new SplineSeg3<D>(geompoints[pnum1-1],
538
geompoints[pnum2-1],
539
geompoints[pnum3-1]);
540
}
541
else if (pnums == 4)
542
{
543
scan >> pnum1 >> ',' >> pnum2 >> ','
544
>> pnum3;// >> ';';
545
splines[i] = new CircleSeg<D>(geompoints[pnum1-1],
546
geompoints[pnum2-1],
547
geompoints[pnum3-1]);
548
549
}
550
551
}
552
}
553
554
555
556
557
template<int D>
558
void SplineGeometry<D> :: Load (const char * filename)
559
{
560
561
ifstream infile;
562
Point<D> x;
563
char buf[50];
564
565
566
infile.open (filename);
567
568
if ( ! infile.good() )
569
throw NgException(string ("Input file '") +
570
string (filename) +
571
string ("' not available!"));
572
573
TestComment ( infile );
574
575
infile >> buf; // file recognition
576
577
tensormeshing.SetSize(0);
578
quadmeshing.SetSize(0);
579
580
TestComment ( infile );
581
if ( strcmp (buf, "splinecurves2dnew") == 0 )
582
{
583
LoadDataNew ( infile );
584
}
585
else if ( strcmp (buf, "splinecurves2dv2") == 0 )
586
{
587
LoadDataV2 ( infile );
588
}
589
else
590
{
591
LoadData(infile );
592
}
593
infile.close();
594
}
595
596
597
template<int D>
598
void SplineGeometry<D> :: LoadDataNew ( ifstream & infile )
599
{
600
601
int nump, numseg, leftdom, rightdom;
602
Point<D> x;
603
int hi1, hi2, hi3;
604
double hd;
605
char buf[50], ch;
606
int pointnr;
607
608
609
TestComment ( infile );
610
infile >> elto0;
611
TestComment ( infile );
612
613
infile >> nump;
614
geompoints.SetSize(nump);
615
616
for (int i = 0; i < nump; i++)
617
{
618
TestComment ( infile );
619
infile >> pointnr;
620
if ( pointnr > nump )
621
{
622
throw NgException(string ("Point number greater than total number of points") );
623
}
624
for(int j=0; j<D; j++)
625
infile >> x(j);
626
627
628
// hd is now optional, default 1
629
// infile >> hd;
630
hd = 1;
631
632
Flags flags;
633
634
635
// get flags,
636
ch = 'a';
637
// infile >> ch;
638
do
639
{
640
641
infile.get (ch);
642
// if another int-value, set refinement flag to this value
643
// (corresponding to old files)
644
if ( int (ch) >= 48 && int(ch) <= 57 )
645
{
646
infile.putback(ch);
647
infile >> hd;
648
infile.get(ch);
649
}
650
}
651
while (isspace(ch) && ch != '\n');
652
while (ch == '-')
653
{
654
char flag[100];
655
flag[0]='-';
656
infile >> (flag+1);
657
flags.SetCommandLineFlag (flag);
658
ch = 'a';
659
do {
660
infile.get (ch);
661
} while (isspace(ch) && ch != '\n');
662
}
663
664
if (infile.good())
665
infile.putback (ch);
666
667
if ( hd == 1 )
668
hd = flags.GetNumFlag ( "ref", 1.0);
669
// geompoints.Append (GeomPoint<D>(x, hd));
670
geompoints[pointnr-1] = GeomPoint<D>(x, hd);
671
geompoints[pointnr-1].hpref = flags.GetDefineFlag ("hpref");
672
}
673
674
TestComment ( infile );
675
676
infile >> numseg;
677
bcnames.SetSize(numseg);
678
for ( int i = 0; i < numseg; i++ )
679
bcnames[i] = 0;//new"default";
680
681
SplineSeg<D> * spline = 0;
682
for (int i = 0; i < numseg; i++)
683
{
684
TestComment ( infile );
685
686
infile >> leftdom >> rightdom;
687
688
// cout << "add spline " << i << ", left = " << leftdom << endl;
689
690
infile >> buf;
691
// type of spline segement
692
if (strcmp (buf, "2") == 0)
693
{ // a line
694
infile >> hi1 >> hi2;
695
spline = new LineSeg<D> (geompoints[hi1-1],
696
geompoints[hi2-1]);
697
}
698
else if (strcmp (buf, "3") == 0)
699
{ // a rational spline
700
infile >> hi1 >> hi2 >> hi3;
701
spline = new SplineSeg3<D> (geompoints[hi1-1],
702
geompoints[hi2-1],
703
geompoints[hi3-1]);
704
}
705
else if (strcmp (buf, "4") == 0)
706
{ // an arc
707
infile >> hi1 >> hi2 >> hi3;
708
spline = new CircleSeg<D> (geompoints[hi1-1],
709
geompoints[hi2-1],
710
geompoints[hi3-1]);
711
// break;
712
}
713
else if (strcmp (buf, "discretepoints") == 0)
714
{
715
int npts;
716
infile >> npts;
717
ARRAY< Point<D> > pts(npts);
718
for (int j = 0; j < npts; j++)
719
for(int k=0; k<D; k++)
720
infile >> pts[j](k);
721
722
spline = new DiscretePointsSeg<D> (pts);
723
}
724
725
// infile >> spline->reffak;
726
spline -> leftdom = leftdom;
727
spline -> rightdom = rightdom;
728
splines.Append (spline);
729
730
// hd is now optional, default 1
731
// infile >> hd;
732
hd = 1;
733
infile >> ch;
734
735
// get refinement parameter, if it is there
736
// infile.get (ch);
737
// if another int-value, set refinement flag to this value
738
// (corresponding to old files)
739
if ( int (ch) >= 48 && int(ch) <= 57 )
740
{
741
infile.putback(ch);
742
infile >> hd;
743
infile >> ch ;
744
}
745
746
Flags flags;
747
while (ch == '-')
748
{
749
char flag[100];
750
flag[0]='-';
751
infile >> (flag+1);
752
flags.SetCommandLineFlag (flag);
753
ch = 'a';
754
infile >> ch;
755
}
756
757
if (infile.good())
758
infile.putback (ch);
759
760
splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));
761
splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||
762
int (flags.GetDefineFlag ("hprefleft"));
763
splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||
764
int (flags.GetDefineFlag ("hprefright"));
765
splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));
766
splines.Last()->reffak = flags.GetNumFlag ("ref", 1 );
767
768
if ( flags.StringFlagDefined("bcname") )
769
{
770
int mybc = splines.Last()->bc-1;
771
if ( bcnames[mybc] ) delete bcnames[mybc];
772
bcnames[mybc] = new string (flags.GetStringFlag("bcname","") );
773
}
774
775
if ( hd != 1 )
776
splines.Last()->reffak = hd;
777
}
778
if ( !infile.good() )
779
return;
780
TestComment ( infile );
781
int numdomains;
782
int domainnr;
783
char material[100];
784
785
if ( !infile.good() )
786
return;
787
788
infile >> numdomains;
789
materials.SetSize(numdomains) ;
790
maxh.SetSize ( numdomains ) ;
791
for ( int i = 0; i < numdomains; i++)
792
maxh[i] = 1000;
793
794
TestComment ( infile );
795
796
for ( int i=0; i<numdomains; i++)
797
materials [ i ] = new char (100);
798
799
for ( int i=0; i<numdomains && infile.good(); i++)
800
{
801
TestComment ( infile );
802
infile >> domainnr;
803
infile >> material;
804
strcpy(materials[domainnr-1], material);
805
806
Flags flags;
807
ch = 'a';
808
infile >> ch;
809
while (ch == '-')
810
{
811
char flag[100];
812
flag[0]='-';
813
infile >> (flag+1);
814
flags.SetCommandLineFlag (flag);
815
ch = 'a';
816
infile >> ch;
817
}
818
819
if (infile.good())
820
infile.putback (ch);
821
822
maxh[domainnr-1] = flags.GetNumFlag ( "maxh", 1000);
823
}
824
return;
825
}
826
827
828
829
template<int D>
830
void SplineGeometry<D> :: LoadData ( ifstream & infile )
831
{
832
833
int nump, numseg, leftdom, rightdom;
834
Point<D> x;
835
int hi1, hi2, hi3;
836
double hd;
837
char buf[50], ch;
838
839
materials.SetSize(0);
840
maxh.SetSize(0);
841
infile >> elto0;
842
843
TestComment ( infile );
844
845
infile >> nump;
846
for (int i = 0; i < nump; i++)
847
{
848
TestComment ( infile );
849
for(int j=0; j<D; j++)
850
infile >> x(j);
851
infile >> hd;
852
853
Flags flags;
854
855
ch = 'a';
856
// infile >> ch;
857
do {
858
infile.get (ch);
859
} while (isspace(ch) && ch != '\n');
860
while (ch == '-')
861
{
862
char flag[100];
863
flag[0]='-';
864
infile >> (flag+1);
865
flags.SetCommandLineFlag (flag);
866
ch = 'a';
867
do {
868
infile.get (ch);
869
} while (isspace(ch) && ch != '\n');
870
}
871
872
if (infile.good())
873
infile.putback (ch);
874
875
geompoints.Append (GeomPoint<D>(x, hd));
876
geompoints.Last().hpref = flags.GetDefineFlag ("hpref");
877
}
878
879
PrintMessage (3, nump, " points loaded");
880
TestComment ( infile );
881
882
infile >> numseg;
883
bcnames.SetSize(numseg);
884
for ( int i = 0; i < numseg; i++ )
885
bcnames[i] = 0; // "default";
886
887
SplineSeg<D> * spline = 0;
888
889
PrintMessage (3, numseg, " segments loaded");
890
for (int i = 0; i < numseg; i++)
891
{
892
TestComment ( infile );
893
894
infile >> leftdom >> rightdom;
895
896
// cout << "add spline " << i << ", left = " << leftdom << ", right = " << rightdom << endl;
897
898
infile >> buf;
899
// type of spline segement
900
if (strcmp (buf, "2") == 0)
901
{ // a line
902
infile >> hi1 >> hi2;
903
spline = new LineSeg<D>(geompoints[hi1-1],
904
geompoints[hi2-1]);
905
}
906
else if (strcmp (buf, "3") == 0)
907
{ // a rational spline
908
infile >> hi1 >> hi2 >> hi3;
909
spline = new SplineSeg3<D> (geompoints[hi1-1],
910
geompoints[hi2-1],
911
geompoints[hi3-1]);
912
}
913
else if (strcmp (buf, "4") == 0)
914
{ // an arc
915
infile >> hi1 >> hi2 >> hi3;
916
spline = new CircleSeg<D> (geompoints[hi1-1],
917
geompoints[hi2-1],
918
geompoints[hi3-1]);
919
// break;
920
}
921
else if (strcmp (buf, "discretepoints") == 0)
922
{
923
int npts;
924
infile >> npts;
925
ARRAY< Point<D> > pts(npts);
926
for (int j = 0; j < npts; j++)
927
for(int k=0; k<D; k++)
928
infile >> pts[j](k);
929
930
spline = new DiscretePointsSeg<D> (pts);
931
}
932
933
infile >> spline->reffak;
934
spline -> leftdom = leftdom;
935
spline -> rightdom = rightdom;
936
splines.Append (spline);
937
938
939
Flags flags;
940
ch = 'a';
941
infile >> ch;
942
while (ch == '-')
943
{
944
char flag[100];
945
flag[0]='-';
946
infile >> (flag+1);
947
flags.SetCommandLineFlag (flag);
948
ch = 'a';
949
infile >> ch;
950
}
951
952
if (infile.good())
953
infile.putback (ch);
954
955
splines.Last()->bc = int (flags.GetNumFlag ("bc", i+1));
956
splines.Last()->hpref_left = int (flags.GetDefineFlag ("hpref")) ||
957
int (flags.GetDefineFlag ("hprefleft"));
958
splines.Last()->hpref_right = int (flags.GetDefineFlag ("hpref")) ||
959
int (flags.GetDefineFlag ("hprefright"));
960
splines.Last()->copyfrom = int (flags.GetNumFlag ("copy", -1));
961
if ( flags.StringFlagDefined("bcname") )
962
{
963
int mybc = splines.Last()->bc-1;
964
if ( bcnames[mybc] ) delete bcnames[mybc];
965
bcnames[mybc] = new string (flags.GetStringFlag("bcname","") );
966
}
967
}
968
}
969
970
971
972
template<int D>
973
void SplineGeometry<D> :: PartitionBoundary (double h, Mesh & mesh2d)
974
{
975
Box<D> bbox;
976
GetBoundingBox (bbox);
977
double dist = Dist (bbox.PMin(), bbox.PMax());
978
Point<3> pmin;
979
Point<3> pmax;
980
981
pmin(2) = -dist; pmax(2) = dist;
982
for(int j=0;j<D;j++)
983
{
984
pmin(j) = bbox.PMin()(j);
985
pmax(j) = bbox.PMax()(j);
986
}
987
988
989
if (printmessage_importance>0)
990
cout << "searchtree from " << pmin << " to " << pmax << endl;
991
Point3dTree searchtree (pmin, pmax);
992
993
for (int i = 0; i < splines.Size(); i++)
994
if (splines[i]->copyfrom == -1)
995
{
996
// astrid - set boundary meshsize to domain meshsize h
997
// if no domain mesh size is given, the max h value from the bounding box is used
998
double minimum = min2 ( GetDomainMaxh ( splines[i]->leftdom ), GetDomainMaxh ( splines[i]->rightdom ) );
999
double maximum = max2 ( GetDomainMaxh ( splines[i]->leftdom ), GetDomainMaxh ( splines[i]->rightdom ) );
1000
minimum = min2 ( minimum, h );
1001
maximum = min2 ( maximum, h);
1002
if ( minimum > 0 )
1003
splines[i]->Partition(minimum, elto0, mesh2d, searchtree, i+1);
1004
else if ( maximum > 0 )
1005
splines[i]->Partition(maximum, elto0, mesh2d, searchtree, i+1);
1006
else
1007
splines[i]->Partition(h, elto0, mesh2d, searchtree, i+1);
1008
}
1009
else
1010
{
1011
CopyEdgeMesh (splines[i]->copyfrom, i+1, mesh2d, searchtree);
1012
}
1013
}
1014
1015
1016
template<int D>
1017
void SplineGeometry<D> :: CopyEdgeMesh (int from, int to, Mesh & mesh, Point3dTree & searchtree)
1018
{
1019
int i;
1020
1021
ARRAY<int, PointIndex::BASE> mappoints (mesh.GetNP());
1022
ARRAY<double, PointIndex::BASE> param (mesh.GetNP());
1023
mappoints = -1;
1024
param = 0;
1025
1026
Point3d pmin, pmax;
1027
mesh.GetBox (pmin, pmax);
1028
double diam2 = Dist2(pmin, pmax);
1029
1030
if (printmessage_importance>0)
1031
cout << "copy edge, from = " << from << " to " << to << endl;
1032
1033
for (i = 1; i <= mesh.GetNSeg(); i++)
1034
{
1035
const Segment & seg = mesh.LineSegment(i);
1036
if (seg.edgenr == from)
1037
{
1038
mappoints.Elem(seg.p1) = 1;
1039
param.Elem(seg.p1) = seg.epgeominfo[0].dist;
1040
1041
mappoints.Elem(seg.p2) = 1;
1042
param.Elem(seg.p2) = seg.epgeominfo[1].dist;
1043
}
1044
}
1045
1046
bool mapped = false;
1047
for (i = 1; i <= mappoints.Size(); i++)
1048
{
1049
if (mappoints.Get(i) != -1)
1050
{
1051
Point<D> newp = splines.Get(to)->GetPoint (param.Get(i));
1052
Point<3> newp3;
1053
for(int j=0; j<min2(D,3); j++)
1054
newp3(j) = newp(j);
1055
for(int j=min2(D,3); j<3; j++)
1056
newp3(j) = 0;
1057
1058
int npi = -1;
1059
1060
for (PointIndex pi = PointIndex::BASE;
1061
pi < mesh.GetNP()+PointIndex::BASE; pi++)
1062
if (Dist2 (mesh.Point(pi), newp3) < 1e-12 * diam2)
1063
npi = pi;
1064
1065
if (npi == -1)
1066
{
1067
npi = mesh.AddPoint (newp3);
1068
searchtree.Insert (newp3, npi);
1069
}
1070
1071
mappoints.Elem(i) = npi;
1072
1073
mesh.GetIdentifications().Add (i, npi, to);
1074
mapped = true;
1075
}
1076
}
1077
if(mapped)
1078
mesh.GetIdentifications().SetType(to,Identifications::PERIODIC);
1079
1080
// copy segments
1081
int oldnseg = mesh.GetNSeg();
1082
for (i = 1; i <= oldnseg; i++)
1083
{
1084
const Segment & seg = mesh.LineSegment(i);
1085
if (seg.edgenr == from)
1086
{
1087
Segment nseg;
1088
nseg.edgenr = to;
1089
nseg.si = splines.Get(to)->bc;
1090
nseg.p1 = mappoints.Get(seg.p1);
1091
nseg.p2 = mappoints.Get(seg.p2);
1092
nseg.domin = splines.Get(to)->leftdom;
1093
nseg.domout = splines.Get(to)->rightdom;
1094
1095
nseg.epgeominfo[0].edgenr = to;
1096
nseg.epgeominfo[0].dist = param.Get(seg.p1);
1097
nseg.epgeominfo[1].edgenr = to;
1098
nseg.epgeominfo[1].dist = param.Get(seg.p2);
1099
mesh.AddSegment (nseg);
1100
}
1101
}
1102
}
1103
1104
1105
template<int D>
1106
void SplineGeometry<D> :: GetBoundingBox (Box<D> & box) const
1107
{
1108
if (!splines.Size())
1109
{
1110
Point<D> auxp = 0.;
1111
box.Set (auxp);
1112
return;
1113
}
1114
1115
ARRAY<Point<D> > points;
1116
for (int i = 0; i < splines.Size(); i++)
1117
{
1118
splines[i]->GetPoints (20, points);
1119
1120
if (i == 0) box.Set(points[0]);
1121
for (int j = 0; j < points.Size(); j++)
1122
box.Add (points[j]);
1123
}
1124
}
1125
1126
template<int D>
1127
void SplineGeometry<D> :: SetGrading (const double grading)
1128
{ elto0 = grading;}
1129
1130
template<int D>
1131
void SplineGeometry<D> :: AppendPoint (const double x, const double y, const double reffac, const bool hpref)
1132
{
1133
geompoints.Append (GeomPoint<D>(x, y, reffac));
1134
geompoints.Last().hpref = hpref;
1135
}
1136
1137
template<int D>
1138
void SplineGeometry<D> :: AppendPoint (const Point<D> & p, const double reffac, const bool hpref)
1139
{
1140
geompoints.Append (GeomPoint<D>(p, reffac));
1141
geompoints.Last().hpref = hpref;
1142
}
1143
1144
1145
1146
1147
template<int D>
1148
void SplineGeometry<D> :: AppendSegment(SplineSeg<D> * spline, const int leftdomain, const int rightdomain,
1149
const int bc,
1150
const double reffac, const bool hprefleft, const bool hprefright,
1151
const int copyfrom)
1152
{
1153
spline -> leftdom = leftdomain;
1154
spline -> rightdom = rightdomain;
1155
spline -> bc = (bc >= 0) ? bc : (splines.Size()+1);
1156
spline -> reffak = reffac;
1157
spline -> hpref_left = hprefleft;
1158
spline -> hpref_right = hprefright;
1159
spline -> copyfrom = copyfrom;
1160
1161
splines.Append(spline);
1162
}
1163
1164
template<int D>
1165
void SplineGeometry<D> :: AppendLineSegment (const int n1, const int n2, const int leftdomain, const int rightdomain,
1166
const int bc,
1167
const double reffac, const bool hprefleft, const bool hprefright,
1168
const int copyfrom)
1169
{
1170
SplineSeg<D> * spline = new LineSeg<D>(geompoints[n1],geompoints[n2]);
1171
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
1172
}
1173
1174
template<int D>
1175
void SplineGeometry<D> :: AppendSplineSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,
1176
const int bc,
1177
const double reffac, const bool hprefleft, const bool hprefright,
1178
const int copyfrom)
1179
{
1180
SplineSeg<D> * spline = new SplineSeg3<D>(geompoints[n1],geompoints[n2],geompoints[n3]);
1181
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
1182
}
1183
1184
template<int D>
1185
void SplineGeometry<D> :: AppendCircleSegment (const int n1, const int n2, const int n3, const int leftdomain, const int rightdomain,
1186
const int bc,
1187
const double reffac, const bool hprefleft, const bool hprefright,
1188
const int copyfrom)
1189
{
1190
SplineSeg<D> * spline = new CircleSeg<D>(geompoints[n1],geompoints[n2],geompoints[n3]);
1191
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
1192
}
1193
1194
template<int D>
1195
void SplineGeometry<D> :: AppendDiscretePointsSegment (const ARRAY< Point<D> > & points, const int leftdomain, const int rightdomain,
1196
const int bc,
1197
const double reffac, const bool hprefleft, const bool hprefright,
1198
const int copyfrom)
1199
{
1200
SplineSeg<D> * spline = new DiscretePointsSeg<D>(points);
1201
AppendSegment(spline,leftdomain,rightdomain,bc,reffac,hprefleft,hprefright,copyfrom);
1202
}
1203
1204
1205
template<int D>
1206
void SplineGeometry<D> :: GetMaterial( const int domnr, char* & material )
1207
{
1208
if ( materials.Size() >= domnr)
1209
material = materials[domnr-1];
1210
else material = 0;
1211
return;
1212
}
1213
1214
1215
1216
template<int D>
1217
double SplineGeometry<D> :: GetDomainMaxh( const int domnr )
1218
{
1219
if ( maxh.Size() >= domnr && domnr > 0)
1220
return maxh[domnr-1];
1221
else
1222
return -1;
1223
}
1224
1225
1226
template<int D>
1227
string SplineGeometry<D> :: GetBCName( const int bcnr ) const
1228
{
1229
string bcname;
1230
if ( bcnames.Size() >= bcnr)
1231
if ( bcnames[bcnr-1] )
1232
bcname = *bcnames[bcnr-1];
1233
else bcname = "default";
1234
return bcname;
1235
}
1236
1237
template<int D>
1238
string * SplineGeometry<D> :: BCNamePtr( const int bcnr )
1239
{
1240
if ( bcnr > bcnames.Size() )
1241
return 0;
1242
else
1243
return bcnames[bcnr-1];
1244
}
1245
1246
1247
1248
template class SplineGeometry<2>;
1249
template class SplineGeometry<3>;
1250
}
1251
1252
1253
1254