Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/csg/genmesh.cpp
3206 views
1
#include <mystdlib.h>
2
3
4
#include <myadt.hpp>
5
6
#include <linalg.hpp>
7
#include <csg.hpp>
8
#include <meshing.hpp>
9
10
11
namespace netgen
12
{
13
ARRAY<SpecialPoint> specpoints;
14
static ARRAY<MeshPoint> spoints;
15
16
#define TCL_OK 0
17
#define TCL_ERROR 1
18
19
20
21
static void FindPoints (CSGeometry & geom, Mesh & mesh)
22
{
23
PrintMessage (1, "Start Findpoints");
24
25
const char * savetask = multithread.task;
26
multithread.task = "Find points";
27
28
for (int i = 0; i < geom.GetNUserPoints(); i++)
29
{
30
mesh.AddPoint(geom.GetUserPoint (i));
31
mesh.Points().Last().Singularity (geom.GetUserPointRefFactor(i));
32
mesh.AddLockedPoint (PointIndex (i+1));
33
}
34
35
SpecialPointCalculation spc;
36
37
spc.SetIdEps(geom.GetIdEps());
38
39
if (spoints.Size() == 0)
40
spc.CalcSpecialPoints (geom, spoints);
41
42
PrintMessage (2, "Analyze spec points");
43
spc.AnalyzeSpecialPoints (geom, spoints, specpoints);
44
45
PrintMessage (5, "done");
46
47
(*testout) << specpoints.Size() << " special points:" << endl;
48
for (int i = 0; i < specpoints.Size(); i++)
49
specpoints[i].Print (*testout);
50
51
/*
52
for (int i = 1; i <= geom.identifications.Size(); i++)
53
geom.identifications.Elem(i)->IdentifySpecialPoints (specpoints);
54
*/
55
multithread.task = savetask;
56
}
57
58
59
60
61
62
63
static void FindEdges (CSGeometry & geom, Mesh & mesh, const bool setmeshsize = false)
64
{
65
EdgeCalculation ec (geom, specpoints);
66
ec.SetIdEps(geom.GetIdEps());
67
ec.Calc (mparam.maxh, mesh);
68
69
for (int i = 0; i < geom.singedges.Size(); i++)
70
{
71
geom.singedges[i]->FindPointsOnEdge (mesh);
72
if(setmeshsize)
73
geom.singedges[i]->SetMeshSize(mesh,10.*geom.BoundingBox().Diam());
74
}
75
for (int i = 0; i < geom.singpoints.Size(); i++)
76
geom.singpoints[i]->FindPoints (mesh);
77
78
for (int i = 1; i <= mesh.GetNSeg(); i++)
79
{
80
//(*testout) << "segment " << mesh.LineSegment(i) << endl;
81
int ok = 0;
82
for (int k = 1; k <= mesh.GetNFD(); k++)
83
if (mesh.GetFaceDescriptor(k).SegmentFits (mesh.LineSegment(i)))
84
{
85
ok = k;
86
//(*testout) << "fits to " << k << endl;
87
}
88
89
if (!ok)
90
{
91
ok = mesh.AddFaceDescriptor (FaceDescriptor (mesh.LineSegment(i)));
92
//(*testout) << "did not find, now " << ok << endl;
93
}
94
95
//(*testout) << "change from " << mesh.LineSegment(i).si;
96
mesh.LineSegment(i).si = ok;
97
//(*testout) << " to " << mesh.LineSegment(i).si << endl;
98
}
99
100
if (geom.identifications.Size())
101
{
102
PrintMessage (3, "Find Identifications");
103
for (int i = 0; i < geom.identifications.Size(); i++)
104
{
105
geom.identifications[i]->IdentifyPoints (mesh);
106
//(*testout) << "identification " << i << " is "
107
// << *geom.identifications[i] << endl;
108
109
}
110
for (int i = 0; i < geom.identifications.Size(); i++)
111
geom.identifications[i]->IdentifyFaces (mesh);
112
}
113
114
115
// find intersecting segments
116
PrintMessage (3, "Check intersecting edges");
117
118
Point3d pmin, pmax;
119
mesh.GetBox (pmin, pmax);
120
Box3dTree segtree (pmin, pmax);
121
122
for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++)
123
{
124
if (mesh[si].seginfo)
125
{
126
Box<3> hbox;
127
hbox.Set (mesh[mesh[si].p1]);
128
hbox.Add (mesh[mesh[si].p2]);
129
segtree.Insert (hbox.PMin(), hbox.PMax(), si);
130
}
131
}
132
133
ARRAY<int> loc;
134
if (!ec.point_on_edge_problem)
135
for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++)
136
{
137
if (!mesh[si].seginfo) continue;
138
139
Box<3> hbox;
140
hbox.Set (mesh[mesh[si].p1]);
141
hbox.Add (mesh[mesh[si].p2]);
142
hbox.Increase (1e-6);
143
segtree.GetIntersecting (hbox.PMin(), hbox.PMax(), loc);
144
145
// for (SegmentIndex sj = 0; sj < si; sj++)
146
for (int j = 0; j < loc.Size(); j++)
147
{
148
SegmentIndex sj = loc[j];
149
if (sj >= si) continue;
150
if (!mesh[si].seginfo || !mesh[sj].seginfo) continue;
151
if (mesh[mesh[si].p1].GetLayer() != mesh[mesh[sj].p2].GetLayer()) continue;
152
153
Point<3> pi1 = mesh[mesh[si].p1];
154
Point<3> pi2 = mesh[mesh[si].p2];
155
Point<3> pj1 = mesh[mesh[sj].p1];
156
Point<3> pj2 = mesh[mesh[sj].p2];
157
Vec<3> vi = pi2 - pi1;
158
Vec<3> vj = pj2 - pj1;
159
160
if (sqr (vi * vj) > (1.-1e-6) * Abs2 (vi) * Abs2 (vj)) continue;
161
162
// pi1 + vi t = pj1 + vj s
163
Mat<3,2> mat;
164
Vec<3> rhs;
165
Vec<2> sol;
166
167
for (int jj = 0; jj < 3; jj++)
168
{
169
mat(jj,0) = vi(jj);
170
mat(jj,1) = -vj(jj);
171
rhs(jj) = pj1(jj)-pi1(jj);
172
}
173
174
mat.Solve (rhs, sol);
175
176
//(*testout) << "mat " << mat << endl << "rhs " << rhs << endl << "sol " << sol << endl;
177
178
if (sol(0) > 1e-6 && sol(0) < 1-1e-6 &&
179
sol(1) > 1e-6 && sol(1) < 1-1e-6 &&
180
Abs (rhs - mat*sol) < 1e-6)
181
{
182
Point<3> ip = pi1 + sol(0) * vi;
183
184
//(*testout) << "ip " << ip << endl;
185
186
Point<3> pip = ip;
187
ProjectToEdge (geom.GetSurface (mesh[si].surfnr1),
188
geom.GetSurface (mesh[si].surfnr2), pip);
189
190
//(*testout) << "Dist (ip, pip_si) " << Dist (ip, pip) << endl;
191
if (Dist (ip, pip) > 1e-6*geom.MaxSize()) continue;
192
pip = ip;
193
ProjectToEdge (geom.GetSurface (mesh[sj].surfnr1),
194
geom.GetSurface (mesh[sj].surfnr2), pip);
195
196
//(*testout) << "Dist (ip, pip_sj) " << Dist (ip, pip) << endl;
197
if (Dist (ip, pip) > 1e-6*geom.MaxSize()) continue;
198
199
200
201
cout << "Intersection at " << ip << endl;
202
203
geom.AddUserPoint (ip);
204
spoints.Append (MeshPoint (ip, mesh[mesh[si].p1].GetLayer()));
205
mesh.AddPoint (ip);
206
207
(*testout) << "found intersection at " << ip << endl;
208
(*testout) << "sol = " << sol << endl;
209
(*testout) << "res = " << (rhs - mat*sol) << endl;
210
(*testout) << "segs = " << pi1 << " - " << pi2 << endl;
211
(*testout) << "and = " << pj1 << " - " << pj2 << endl << endl;
212
}
213
}
214
}
215
}
216
217
218
219
220
221
222
static void MeshSurface (CSGeometry & geom, Mesh & mesh)
223
{
224
const char * savetask = multithread.task;
225
multithread.task = "Surface meshing";
226
227
ARRAY<Segment> segments;
228
int noldp = mesh.GetNP();
229
230
double starttime = GetTime();
231
232
// find master faces from identified
233
ARRAY<int> masterface(mesh.GetNFD());
234
for (int i = 1; i <= mesh.GetNFD(); i++)
235
masterface.Elem(i) = i;
236
237
ARRAY<INDEX_2> fpairs;
238
bool changed;
239
do
240
{
241
changed = 0;
242
for (int i = 0; i < geom.identifications.Size(); i++)
243
{
244
geom.identifications[i]->GetIdentifiedFaces (fpairs);
245
246
for (int j = 0; j < fpairs.Size(); j++)
247
{
248
if (masterface.Get(fpairs[j].I1()) <
249
masterface.Get(fpairs[j].I2()))
250
{
251
changed = 1;
252
masterface.Elem(fpairs[j].I2()) =
253
masterface.Elem(fpairs[j].I1());
254
}
255
if (masterface.Get(fpairs[j].I2()) <
256
masterface.Get(fpairs[j].I1()))
257
{
258
changed = 1;
259
masterface.Elem(fpairs[j].I1()) =
260
masterface.Elem(fpairs[j].I2());
261
}
262
}
263
}
264
}
265
while (changed);
266
267
268
int bccnt=0;
269
for (int k = 0; k < geom.GetNSurf(); k++)
270
bccnt = max2 (bccnt, geom.GetSurface(k)->GetBCProperty());
271
272
for (int k = 1; k <= mesh.GetNFD(); k++)
273
{
274
bool increased = false;
275
276
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
277
const Surface * surf = geom.GetSurface(fd.SurfNr());
278
279
if (fd.TLOSurface() &&
280
geom.GetTopLevelObject(fd.TLOSurface()-1) -> GetBCProp() > 0)
281
fd.SetBCProperty (geom.GetTopLevelObject(fd.TLOSurface()-1) -> GetBCProp());
282
else if (surf -> GetBCProperty() != -1)
283
fd.SetBCProperty (surf->GetBCProperty());
284
else
285
{
286
bccnt++;
287
fd.SetBCProperty (bccnt);
288
increased = true;
289
}
290
291
for (int l = 0; l < geom.bcmodifications.Size(); l++)
292
{
293
if (geom.GetSurfaceClassRepresentant (fd.SurfNr()) ==
294
geom.GetSurfaceClassRepresentant (geom.bcmodifications[l].si) &&
295
(fd.DomainIn() == geom.bcmodifications[l].tlonr+1 ||
296
fd.DomainOut() == geom.bcmodifications[l].tlonr+1))
297
{
298
if(geom.bcmodifications[l].bcname == NULL)
299
fd.SetBCProperty (geom.bcmodifications[l].bcnr);
300
else
301
{
302
if(!increased)
303
{
304
bccnt++;
305
fd.SetBCProperty (bccnt);
306
increased = true;
307
}
308
}
309
}
310
}
311
}
312
313
mesh.SetNBCNames( bccnt );
314
315
for (int k = 1; k <= mesh.GetNFD(); k++)
316
{
317
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
318
const Surface * surf = geom.GetSurface(fd.SurfNr());
319
if (fd.TLOSurface() )
320
{
321
int bcp = fd.BCProperty();
322
string nextbcname = geom.GetTopLevelObject(fd.TLOSurface()-1) -> GetBCName();
323
if ( nextbcname != "default" )
324
mesh.SetBCName ( bcp - 1 , nextbcname );
325
}
326
else // if (surf -> GetBCProperty() != -1)
327
{
328
int bcp = fd.BCProperty();
329
string nextbcname = surf->GetBCName();
330
if ( nextbcname != "default" )
331
mesh.SetBCName ( bcp - 1, nextbcname );
332
}
333
}
334
335
for (int k = 1; k <= mesh.GetNFD(); k++)
336
{
337
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
338
fd.SetBCName ( mesh.GetBCNamePtr ( fd.BCProperty() - 1 ) );
339
}
340
341
342
//!!
343
344
for (int k = 1; k <= mesh.GetNFD(); k++)
345
{
346
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
347
//const Surface * surf = geom.GetSurface(fd.SurfNr());
348
349
for (int l = 0; l < geom.bcmodifications.Size(); l++)
350
{
351
if (geom.GetSurfaceClassRepresentant (fd.SurfNr()) ==
352
geom.GetSurfaceClassRepresentant (geom.bcmodifications[l].si) &&
353
(fd.DomainIn() == geom.bcmodifications[l].tlonr+1 ||
354
fd.DomainOut() == geom.bcmodifications[l].tlonr+1) &&
355
geom.bcmodifications[l].bcname != NULL
356
)
357
{
358
int bcp = fd.BCProperty();
359
mesh.SetBCName ( bcp - 1, *(geom.bcmodifications[l].bcname) );
360
fd.SetBCName ( mesh.GetBCNamePtr ( bcp - 1) );
361
}
362
}
363
}
364
365
for(int k = 0; k<geom.bcmodifications.Size(); k++)
366
{
367
delete geom.bcmodifications[k].bcname;
368
geom.bcmodifications[k].bcname = NULL;
369
}
370
371
//!!
372
373
374
for (int j = 0; j < geom.singfaces.Size(); j++)
375
{
376
ARRAY<int> surfs;
377
geom.GetIndependentSurfaceIndices (geom.singfaces[j]->GetSolid(),
378
geom.BoundingBox(), surfs);
379
for (int k = 1; k <= mesh.GetNFD(); k++)
380
{
381
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
382
for (int l = 0; l < surfs.Size(); l++)
383
if (surfs[l] == fd.SurfNr())
384
{
385
if (geom.singfaces[j]->GetDomainNr() == fd.DomainIn())
386
fd.domin_singular = 1;
387
if (geom.singfaces[j]->GetDomainNr() == fd.DomainOut())
388
fd.domout_singular = 1;
389
}
390
}
391
}
392
393
394
// assemble edge hash-table
395
mesh.CalcSurfacesOfNode();
396
397
for (int k = 1; k <= mesh.GetNFD(); k++)
398
{
399
multithread.percent = 100.0 * k / (mesh.GetNFD()+1e-10);
400
401
if (masterface.Get(k) != k)
402
continue;
403
404
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
405
406
(*testout) << "Surface " << k << endl;
407
(*testout) << "Face Descriptor: " << fd << endl;
408
PrintMessage (1, "Surface ", k, " / ", mesh.GetNFD());
409
410
int oldnf = mesh.GetNSE();
411
412
const Surface * surf =
413
geom.GetSurface((mesh.GetFaceDescriptor(k).SurfNr()));
414
415
416
Meshing2Surfaces meshing(*surf, geom.BoundingBox());
417
meshing.SetStartTime (starttime);
418
419
420
for (PointIndex pi = PointIndex::BASE; pi < noldp+PointIndex::BASE; pi++)
421
{
422
//if(surf->PointOnSurface(mesh[pi]))
423
meshing.AddPoint (mesh[pi], pi, NULL,
424
(surf->PointOnSurface(mesh[pi])!=0));
425
}
426
427
segments.SetSize (0);
428
429
for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++)
430
if (mesh[si].si == k)
431
{
432
segments.Append (mesh[si]);
433
(*testout) << "appending segment " << mesh[si] << endl;
434
//<< " from " << mesh[mesh[si][0]]
435
// << " to " <<mesh[mesh[si][1]]<< endl;
436
}
437
438
(*testout) << "num-segments " << segments.Size() << endl;
439
440
for (int i = 1; i <= geom.identifications.Size(); i++)
441
{
442
geom.identifications.Get(i)->
443
BuildSurfaceElements(segments, mesh, surf);
444
}
445
446
for (int si = 0; si < segments.Size(); si++)
447
{
448
PointGeomInfo gi;
449
gi.trignum = k;
450
meshing.AddBoundaryElement (segments[si].p1 + 1 - PointIndex::BASE,
451
segments[si].p2 + 1 - PointIndex::BASE,
452
gi, gi);
453
}
454
455
double maxh = mparam.maxh;
456
if (fd.DomainIn() != 0)
457
{
458
const Solid * s1 =
459
geom.GetTopLevelObject(fd.DomainIn()-1) -> GetSolid();
460
if (s1->GetMaxH() < maxh)
461
maxh = s1->GetMaxH();
462
maxh = min2(maxh, geom.GetTopLevelObject(fd.DomainIn()-1)->GetMaxH());
463
}
464
if (fd.DomainOut() != 0)
465
{
466
const Solid * s1 =
467
geom.GetTopLevelObject(fd.DomainOut()-1) -> GetSolid();
468
if (s1->GetMaxH() < maxh)
469
maxh = s1->GetMaxH();
470
maxh = min2(maxh, geom.GetTopLevelObject(fd.DomainOut()-1)->GetMaxH());
471
}
472
if (fd.TLOSurface() != 0)
473
{
474
double hi = geom.GetTopLevelObject(fd.TLOSurface()-1) -> GetMaxH();
475
if (hi < maxh) maxh = hi;
476
}
477
478
(*testout) << "domin = " << fd.DomainIn() << ", domout = " << fd.DomainOut()
479
<< ", tlo-surf = " << fd.TLOSurface()
480
<< " mpram.maxh = " << mparam.maxh << ", maxh = " << maxh << endl;
481
482
mparam.checkoverlap = 0;
483
484
MESHING2_RESULT res =
485
meshing.GenerateMesh (mesh, maxh, k);
486
487
if (res != MESHING2_OK)
488
{
489
PrintError ("Problem in Surface mesh generation");
490
throw NgException ("Problem in Surface mesh generation");
491
}
492
493
if (multithread.terminate) return;
494
495
for (int i = oldnf+1; i <= mesh.GetNSE(); i++)
496
mesh.SurfaceElement(i).SetIndex (k);
497
498
499
// mesh.CalcSurfacesOfNode();
500
501
if (segments.Size())
502
{
503
// surface was meshed, not copied
504
PrintMessage (2, "Optimize Surface");
505
for (int i = 1; i <= mparam.optsteps2d; i++)
506
{
507
if (multithread.terminate) return;
508
509
{
510
MeshOptimize2dSurfaces meshopt(geom);
511
meshopt.SetFaceIndex (k);
512
meshopt.SetImproveEdges (0);
513
meshopt.SetMetricWeight (mparam.elsizeweight);
514
meshopt.SetWriteStatus (0);
515
516
meshopt.EdgeSwapping (mesh, (i > mparam.optsteps2d/2));
517
}
518
519
if (multithread.terminate) return;
520
{
521
// mesh.CalcSurfacesOfNode();
522
523
MeshOptimize2dSurfaces meshopt(geom);
524
meshopt.SetFaceIndex (k);
525
meshopt.SetImproveEdges (0);
526
meshopt.SetMetricWeight (mparam.elsizeweight);
527
meshopt.SetWriteStatus (0);
528
529
meshopt.ImproveMesh (mesh);
530
}
531
532
{
533
MeshOptimize2dSurfaces meshopt(geom);
534
meshopt.SetFaceIndex (k);
535
meshopt.SetImproveEdges (0);
536
meshopt.SetMetricWeight (mparam.elsizeweight);
537
meshopt.SetWriteStatus (0);
538
539
meshopt.CombineImprove (mesh);
540
// mesh.CalcSurfacesOfNode();
541
}
542
543
if (multithread.terminate) return;
544
{
545
MeshOptimize2dSurfaces meshopt(geom);
546
meshopt.SetFaceIndex (k);
547
meshopt.SetImproveEdges (0);
548
meshopt.SetMetricWeight (mparam.elsizeweight);
549
meshopt.SetWriteStatus (0);
550
551
meshopt.ImproveMesh (mesh);
552
}
553
}
554
}
555
556
557
PrintMessage (3, (mesh.GetNSE() - oldnf), " elements, ", mesh.GetNP(), " points");
558
559
#ifdef OPENGL
560
extern void Render();
561
Render();
562
#endif
563
}
564
565
mesh.Compress();
566
567
do
568
{
569
changed = 0;
570
for (int k = 1; k <= mesh.GetNFD(); k++)
571
{
572
multithread.percent = 100.0 * k / (mesh.GetNFD()+1e-10);
573
574
if (masterface.Get(k) == k)
575
continue;
576
577
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
578
579
(*testout) << "Surface " << k << endl;
580
(*testout) << "Face Descriptor: " << fd << endl;
581
PrintMessage (2, "Surface ", k);
582
583
int oldnf = mesh.GetNSE();
584
585
const Surface * surf =
586
geom.GetSurface((mesh.GetFaceDescriptor(k).SurfNr()));
587
588
/*
589
if (surf -> GetBCProperty() != -1)
590
fd.SetBCProperty (surf->GetBCProperty());
591
else
592
{
593
bccnt++;
594
fd.SetBCProperty (bccnt);
595
}
596
*/
597
598
segments.SetSize (0);
599
for (int i = 1; i <= mesh.GetNSeg(); i++)
600
{
601
Segment * seg = &mesh.LineSegment(i);
602
if (seg->si == k)
603
segments.Append (*seg);
604
}
605
606
for (int i = 1; i <= geom.identifications.Size(); i++)
607
{
608
geom.identifications.Elem(i)->GetIdentifiedFaces (fpairs);
609
int found = 0;
610
for (int j = 1; j <= fpairs.Size(); j++)
611
if (fpairs.Get(j).I1() == k || fpairs.Get(j).I2() == k)
612
found = 1;
613
614
if (!found)
615
continue;
616
617
geom.identifications.Get(i)->
618
BuildSurfaceElements(segments, mesh, surf);
619
if (!segments.Size())
620
break;
621
}
622
623
624
if (multithread.terminate) return;
625
626
for (int i = oldnf+1; i <= mesh.GetNSE(); i++)
627
mesh.SurfaceElement(i).SetIndex (k);
628
629
630
if (!segments.Size())
631
{
632
masterface.Elem(k) = k;
633
changed = 1;
634
}
635
636
PrintMessage (3, (mesh.GetNSE() - oldnf), " elements, ", mesh.GetNP(), " points");
637
}
638
639
#ifdef OPENGL
640
extern void Render();
641
Render();
642
#endif
643
}
644
while (changed);
645
646
647
mesh.SplitSeparatedFaces();
648
mesh.CalcSurfacesOfNode();
649
650
multithread.task = savetask;
651
}
652
653
654
655
656
657
658
659
int GenerateMesh (CSGeometry & geom,
660
Mesh *& mesh,
661
int perfstepsstart, int perfstepsend,
662
const char * optstr)
663
{
664
665
if (mesh && mesh->GetNSE() &&
666
!geom.GetNSolids())
667
{
668
if (perfstepsstart < MESHCONST_MESHVOLUME)
669
perfstepsstart = MESHCONST_MESHVOLUME;
670
}
671
672
673
674
if (perfstepsstart <= MESHCONST_ANALYSE)
675
{
676
delete mesh;
677
mesh = new Mesh();
678
679
mesh->SetGlobalH (mparam.maxh);
680
mesh->SetMinimalH (mparam.minh);
681
682
ARRAY<double> maxhdom(geom.GetNTopLevelObjects());
683
for (int i = 0; i < maxhdom.Size(); i++)
684
maxhdom[i] = geom.GetTopLevelObject(i)->GetMaxH();
685
686
mesh->SetMaxHDomain (maxhdom);
687
688
if (mparam.uselocalh)
689
{
690
double maxsize = geom.MaxSize();
691
mesh->SetLocalH (Point<3>(-maxsize, -maxsize, -maxsize),
692
Point<3>(maxsize, maxsize, maxsize),
693
mparam.grading);
694
695
mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
696
}
697
698
spoints.SetSize(0);
699
FindPoints (geom, *mesh);
700
701
PrintMessage (5, "find points done");
702
703
#ifdef LOG_STREAM
704
(*logout) << "Special points found" << endl
705
<< "time = " << GetTime() << " sec" << endl
706
<< "points: " << mesh->GetNP() << endl << endl;
707
#endif
708
}
709
710
711
if (multithread.terminate || perfstepsend <= MESHCONST_ANALYSE)
712
return TCL_OK;
713
714
715
if (perfstepsstart <= MESHCONST_MESHEDGES)
716
{
717
FindEdges (geom, *mesh, true);
718
if (multithread.terminate) return TCL_OK;
719
#ifdef LOG_STREAM
720
(*logout) << "Edges meshed" << endl
721
<< "time = " << GetTime() << " sec" << endl
722
<< "points: " << mesh->GetNP() << endl;
723
#endif
724
725
726
if (multithread.terminate)
727
return TCL_OK;
728
729
if (mparam.uselocalh)
730
{
731
mesh->CalcLocalH();
732
mesh->DeleteMesh();
733
734
FindPoints (geom, *mesh);
735
if (multithread.terminate) return TCL_OK;
736
FindEdges (geom, *mesh, true);
737
if (multithread.terminate) return TCL_OK;
738
739
mesh->DeleteMesh();
740
741
FindPoints (geom, *mesh);
742
if (multithread.terminate) return TCL_OK;
743
FindEdges (geom, *mesh);
744
if (multithread.terminate) return TCL_OK;
745
}
746
}
747
748
if (multithread.terminate || perfstepsend <= MESHCONST_MESHEDGES)
749
return TCL_OK;
750
751
752
if (perfstepsstart <= MESHCONST_MESHSURFACE)
753
{
754
MeshSurface (geom, *mesh);
755
if (multithread.terminate) return TCL_OK;
756
757
#ifdef LOG_STREAM
758
(*logout) << "Surfaces meshed" << endl
759
<< "time = " << GetTime() << " sec" << endl
760
<< "points: " << mesh->GetNP() << endl;
761
#endif
762
763
if (mparam.uselocalh && 0)
764
{
765
mesh->CalcLocalH();
766
mesh->DeleteMesh();
767
768
FindPoints (geom, *mesh);
769
if (multithread.terminate) return TCL_OK;
770
FindEdges (geom, *mesh);
771
if (multithread.terminate) return TCL_OK;
772
773
MeshSurface (geom, *mesh);
774
if (multithread.terminate) return TCL_OK;
775
}
776
777
#ifdef LOG_STREAM
778
(*logout) << "Surfaces remeshed" << endl
779
<< "time = " << GetTime() << " sec" << endl
780
<< "points: " << mesh->GetNP() << endl;
781
#endif
782
783
#ifdef STAT_STREAM
784
(*statout) << mesh->GetNSeg() << " & "
785
<< mesh->GetNSE() << " & - &"
786
<< GetTime() << " & " << endl;
787
#endif
788
789
MeshQuality2d (*mesh);
790
mesh->CalcSurfacesOfNode();
791
}
792
793
if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE)
794
return TCL_OK;
795
796
797
if (perfstepsstart <= MESHCONST_MESHVOLUME)
798
{
799
multithread.task = "Volume meshing";
800
801
MESHING3_RESULT res =
802
MeshVolume (mparam, *mesh);
803
804
if (res != MESHING3_OK) return TCL_ERROR;
805
806
if (multithread.terminate) return TCL_OK;
807
808
RemoveIllegalElements (*mesh);
809
if (multithread.terminate) return TCL_OK;
810
811
MeshQuality3d (*mesh);
812
813
for (int i = 0; i < geom.GetNTopLevelObjects(); i++)
814
mesh->SetMaterial (i+1, geom.GetTopLevelObject(i)->GetMaterial().c_str());
815
816
817
#ifdef STAT_STREAM
818
(*statout) << GetTime() << " & ";
819
#endif
820
821
#ifdef LOG_STREAM
822
(*logout) << "Volume meshed" << endl
823
<< "time = " << GetTime() << " sec" << endl
824
<< "points: " << mesh->GetNP() << endl;
825
#endif
826
}
827
828
if (multithread.terminate || perfstepsend <= MESHCONST_MESHVOLUME)
829
return TCL_OK;
830
831
832
if (perfstepsstart <= MESHCONST_OPTVOLUME)
833
{
834
multithread.task = "Volume optimization";
835
836
OptimizeVolume (mparam, *mesh);
837
if (multithread.terminate) return TCL_OK;
838
839
#ifdef STAT_STREAM
840
(*statout) << GetTime() << " & "
841
<< mesh->GetNE() << " & "
842
<< mesh->GetNP() << " " << '\\' << '\\' << " \\" << "hline" << endl;
843
#endif
844
845
#ifdef LOG_STREAM
846
(*logout) << "Volume optimized" << endl
847
<< "time = " << GetTime() << " sec" << endl
848
<< "points: " << mesh->GetNP() << endl;
849
#endif
850
}
851
852
return TCL_OK;
853
}
854
}
855
856