Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/interface/nginterface.cpp
3206 views
1
#include <mystdlib.h>
2
3
4
#include <meshing.hpp>
5
#include <csg.hpp>
6
#include <geometry2d.hpp>
7
#include <stlgeom.hpp>
8
9
10
#ifdef OCCGEOMETRY
11
#include <occgeom.hpp>
12
#endif
13
14
#ifdef ACIS
15
#include <acisgeom.hpp>
16
#endif
17
18
#ifdef SOCKETS
19
#include "../sockets/sockets.hpp"
20
#endif
21
22
#ifndef NOTCL
23
#include <visual.hpp>
24
#endif
25
26
27
#include "nginterface.h"
28
29
// #include <FlexLexer.h>
30
31
32
// #include <mystdlib.h>
33
34
35
namespace netgen
36
{
37
#include "writeuser.hpp"
38
39
extern AutoPtr<Mesh> mesh;
40
#ifndef NOTCL
41
extern VisualSceneMesh vsmesh;
42
extern Tcl_Interp * tcl_interp;
43
#endif
44
45
extern AutoPtr<SplineGeometry2d> geometry2d;
46
extern AutoPtr<CSGeometry> geometry;
47
extern STLGeometry * stlgeometry;
48
49
#ifdef OCCGEOMETRY
50
extern OCCGeometry * occgeometry;
51
#endif
52
#ifdef ACIS
53
extern ACISGeometry * acisgeometry;
54
#endif
55
56
#ifdef OPENGL
57
extern VisualSceneSolution vssolution;
58
#endif
59
extern CSGeometry * ParseCSG (istream & istr);
60
61
#ifdef SOCKETS
62
extern AutoPtr<ClientSocket> clientsocket;
63
//extern ARRAY< AutoPtr < ServerInfo > > servers;
64
extern ARRAY< ServerInfo* > servers;
65
#endif
66
}
67
68
69
using namespace netgen;
70
71
/*
72
extern void * operator new (size_t s);
73
extern void * operator new [] (size_t s);
74
extern void operator delete (void * p);
75
extern void operator delete [] (void * p);
76
*/
77
78
// extern FlexLexer * lexer;
79
80
81
82
void Ng_LoadGeometry (const char * filename)
83
{
84
85
86
if (printmessage_importance>0)
87
cout << "CALLED NG LOAD GEOMETRY" << endl;
88
89
geometry.Reset (new CSGeometry ());
90
geometry2d.Reset ();
91
92
#ifdef OCCGEOMETRY
93
delete occgeometry;
94
occgeometry = 0;
95
#endif
96
#ifdef ACIS
97
delete acisgeometry;
98
acisgeometry = 0;
99
#endif
100
101
// he: if filename is empty, return
102
// can be used to reset geometry
103
if (strcmp(filename,"")==0)
104
return;
105
106
ifstream infile (filename);
107
108
if ((strcmp (&filename[strlen(filename)-3], "geo") == 0) ||
109
(strcmp (&filename[strlen(filename)-3], "GEO") == 0) ||
110
(strcmp (&filename[strlen(filename)-3], "Geo") == 0))
111
{
112
113
114
geometry.Reset( netgen::ParseCSG(infile) );
115
116
if (!geometry)
117
{
118
geometry.Reset (new CSGeometry ());
119
//throw NgException ("input file not found");
120
cerr << "Error: input file \"" << filename << "\" not found" << endl;
121
}
122
123
geometry -> FindIdenticSurfaces(1e-6);
124
125
#ifdef PARALLEL
126
int id, rc, ntasks;
127
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
128
MPI_Comm_rank(MPI_COMM_WORLD, &id);
129
if ( id > 0 )
130
{
131
geometry->CalcTriangleApproximation ( geometry->BoundingBox(), 0.001, 20 );
132
return;
133
}
134
#endif
135
136
Box<3> box (geometry->BoundingBox());
137
#ifdef NOTCL
138
double detail = 0.001;
139
double facets = 20;
140
geometry->CalcTriangleApproximation(box, detail, facets);
141
142
#else
143
double detail = atof (Tcl_GetVar (tcl_interp, "::geooptions.detail", 0));
144
double facets = atof (Tcl_GetVar (tcl_interp, "::geooptions.facets", 0));
145
146
if (atoi (Tcl_GetVar (tcl_interp, "::geooptions.drawcsg", 0)))
147
geometry->CalcTriangleApproximation(box, detail, facets);
148
#endif
149
}
150
151
else if (strcmp (&filename[strlen(filename)-4], "in2d") == 0)
152
{
153
geometry2d.Reset (new SplineGeometry2d());
154
geometry2d -> Load (filename);
155
}
156
157
else if ((strcmp (&filename[strlen(filename)-3], "stl") == 0) ||
158
(strcmp (&filename[strlen(filename)-3], "STL") == 0) ||
159
(strcmp (&filename[strlen(filename)-3], "Stl") == 0))
160
{
161
stlgeometry = STLGeometry :: Load (infile);
162
stlgeometry->edgesfound = 0;
163
Mesh meshdummy;
164
stlgeometry->Clear();
165
stlgeometry->BuildEdges();
166
stlgeometry->MakeAtlas(meshdummy);
167
stlgeometry->CalcFaceNums();
168
stlgeometry->AddFaceEdges();
169
stlgeometry->LinkEdges();
170
}
171
172
#ifdef OCCGEOMETRY
173
else if ((strcmp (&filename[strlen(filename)-4], "iges") == 0) ||
174
(strcmp (&filename[strlen(filename)-3], "igs") == 0) ||
175
(strcmp (&filename[strlen(filename)-3], "IGS") == 0) ||
176
(strcmp (&filename[strlen(filename)-4], "IGES") == 0))
177
{
178
PrintMessage (1, "Load IGES geometry file ", filename);
179
occgeometry = LoadOCC_IGES (filename);
180
}
181
else if ((strcmp (&filename[strlen(filename)-4], "step") == 0) ||
182
(strcmp (&filename[strlen(filename)-3], "stp") == 0) ||
183
(strcmp (&filename[strlen(filename)-3], "STP") == 0) ||
184
(strcmp (&filename[strlen(filename)-4], "STEP") == 0))
185
{
186
PrintMessage (1, "Load STEP geometry file ", filename);
187
occgeometry = LoadOCC_STEP (filename);
188
}
189
#endif
190
191
#ifdef ACIS
192
else if (
193
strcmp (&filename[strlen(filename)-3], "sat") == 0 ||
194
( strlen(filename) >= 7 && strcmp ( &filename[ strlen( filename)-7 ], "sat.tet" ) == 0 )
195
)
196
{
197
PrintMessage (1, "Load ACIS geometry file ", filename);
198
acisgeometry = LoadACIS_SAT (filename);
199
}
200
#endif
201
else
202
{
203
//throw NgException("Unknown geometry extension");
204
cerr << "Error: Unknown geometry extension \"" << filename[strlen(filename)-3] << "\"" << endl;
205
}
206
207
208
}
209
210
211
void Ng_LoadMeshFromStream ( istream & input )
212
{
213
mesh.Reset (new Mesh());
214
mesh -> Load(input);
215
if(input.good())
216
{
217
string auxstring;
218
input >> auxstring;
219
if(auxstring == "csgsurfaces")
220
{
221
if (geometry)
222
{
223
geometry.Reset (new CSGeometry (""));
224
}
225
if (stlgeometry)
226
{
227
delete stlgeometry;
228
stlgeometry = NULL;
229
}
230
#ifdef OCCGEOMETRY
231
if (occgeometry)
232
{
233
delete occgeometry;
234
occgeometry = NULL;
235
}
236
#endif
237
#ifdef ACIS
238
if (acisgeometry)
239
{
240
delete acisgeometry;
241
acisgeometry = NULL;
242
}
243
#endif
244
geometry2d.Reset (0);
245
246
geometry -> LoadSurfaces(input);
247
}
248
}
249
250
}
251
252
253
void Ng_LoadMesh (const char * filename)
254
{
255
if ( (strlen (filename) > 4) &&
256
strcmp (filename + (strlen (filename)-4), ".vol") != 0 )
257
{
258
mesh.Reset (new Mesh());
259
ReadFile(*mesh,filename);
260
261
//mesh->SetGlobalH (mparam.maxh);
262
//mesh->CalcLocalH();
263
return;
264
}
265
266
ifstream infile(filename);
267
Ng_LoadMeshFromStream(infile);
268
}
269
270
void Ng_LoadMeshFromString (char * mesh_as_string)
271
{
272
istringstream instream(mesh_as_string);
273
Ng_LoadMeshFromStream(instream);
274
}
275
276
277
278
279
int Ng_GetDimension ()
280
{
281
return (mesh) ? mesh->GetDimension() : -1;
282
}
283
284
int Ng_GetNP ()
285
{
286
return (mesh) ? mesh->GetNP() : 0;
287
}
288
289
int Ng_GetNV ()
290
{
291
return (mesh) ? mesh->GetNV() : 0;
292
}
293
294
int Ng_GetNE ()
295
{
296
if(!mesh) return 0;
297
if (mesh->GetDimension() == 3)
298
return mesh->GetNE();
299
else
300
return mesh->GetNSE();
301
}
302
303
int Ng_GetNSE ()
304
{
305
if(!mesh) return 0;
306
if (mesh->GetDimension() == 3)
307
return mesh->GetNSE();
308
else
309
return mesh->GetNSeg();
310
}
311
312
void Ng_GetPoint (int pi, double * p)
313
{
314
if (pi < 1 || pi > mesh->GetNP())
315
{
316
if (printmessage_importance>0)
317
cout << "Ng_GetPoint: illegal point " << pi << endl;
318
return;
319
}
320
321
const Point3d & hp = mesh->Point (pi);
322
p[0] = hp.X();
323
p[1] = hp.Y();
324
if (mesh->GetDimension() == 3)
325
p[2] = hp.Z();
326
}
327
328
329
NG_ELEMENT_TYPE Ng_GetElement (int ei, int * epi, int * np)
330
{
331
if (mesh->GetDimension() == 3)
332
{
333
int i;
334
const Element & el = mesh->VolumeElement (ei);
335
for (i = 0; i < el.GetNP(); i++)
336
epi[i] = el.PNum(i+1);
337
338
if (np)
339
*np = el.GetNP();
340
341
if (el.GetType() == PRISM)
342
{
343
// degenerated prism, (should be obsolete)
344
const int map1[] = { 3, 2, 5, 6, 1 };
345
const int map2[] = { 1, 3, 6, 4, 2 };
346
const int map3[] = { 2, 1, 4, 5, 3 };
347
348
const int * map = NULL;
349
int deg1 = 0, deg2 = 0, deg3 = 0;
350
//int deg = 0;
351
if (el.PNum(1) == el.PNum(4)) { map = map1; deg1 = 1; }
352
if (el.PNum(2) == el.PNum(5)) { map = map2; deg2 = 1; }
353
if (el.PNum(3) == el.PNum(6)) { map = map3; deg3 = 1; }
354
355
switch (deg1+deg2+deg3)
356
{
357
{
358
case 1:
359
if (printmessage_importance>0)
360
cout << "degenerated prism found, deg = 1" << endl;
361
for (i = 0; i < 5; i++)
362
epi[i] = el.PNum (map[i]);
363
364
if (np) *np = 5;
365
return NG_PYRAMID;
366
break;
367
}
368
case 2:
369
{
370
if (printmessage_importance>0)
371
cout << "degenerated prism found, deg = 2" << endl;
372
if (!deg1) epi[3] = el.PNum(4);
373
if (!deg2) epi[3] = el.PNum(5);
374
if (!deg3) epi[3] = el.PNum(6);
375
376
if (np) *np = 4;
377
return NG_TET;
378
break;
379
}
380
default:
381
;
382
}
383
384
}
385
386
return NG_ELEMENT_TYPE (el.GetType());
387
}
388
else
389
{
390
int i;
391
const Element2d & el = mesh->SurfaceElement (ei);
392
for (i = 0; i < el.GetNP(); i++)
393
epi[i] = el.PNum(i+1);
394
395
if (np) *np = el.GetNP();
396
return NG_ELEMENT_TYPE (el.GetType());
397
/*
398
switch (el.GetNP())
399
{
400
case 3: return NG_TRIG;
401
case 4: return NG_QUAD;
402
case 6: return NG_TRIG6;
403
}
404
*/
405
}
406
407
// should not occur
408
return NG_TET;
409
}
410
411
412
NG_ELEMENT_TYPE Ng_GetElementType (int ei)
413
{
414
if (mesh->GetDimension() == 3)
415
{
416
return NG_ELEMENT_TYPE (mesh->VolumeElement (ei).GetType());
417
}
418
else
419
{
420
const Element2d & el = mesh->SurfaceElement (ei);
421
switch (el.GetNP())
422
{
423
case 3: return NG_TRIG;
424
case 4: return NG_QUAD;
425
case 6: return NG_TRIG6;
426
}
427
}
428
429
// should not occur
430
return NG_TET;
431
}
432
433
434
435
int Ng_GetElementIndex (int ei)
436
{
437
if (mesh->GetDimension() == 3)
438
return mesh->VolumeElement(ei).GetIndex();
439
else
440
{
441
int ind = mesh->SurfaceElement(ei).GetIndex();
442
ind = mesh->GetFaceDescriptor(ind).BCProperty();
443
return ind;
444
}
445
}
446
447
void Ng_SetElementIndex(const int ei, const int index)
448
{
449
mesh->VolumeElement(ei).SetIndex(index);
450
}
451
452
char * Ng_GetElementMaterial (int ei)
453
{
454
static char empty[] = "";
455
if (mesh->GetDimension() == 3)
456
{
457
int ind = mesh->VolumeElement(ei).GetIndex();
458
// cout << "ind = " << ind << endl;
459
const char * mat = mesh->GetMaterial (ind);
460
if (mat)
461
return const_cast<char*> (mat);
462
else
463
return empty;
464
}
465
// add astrid
466
else
467
{
468
int ind = mesh->SurfaceElement(ei).GetIndex();
469
ind = mesh->GetFaceDescriptor(ind).BCProperty();
470
const char * mat = mesh->GetMaterial ( ind );
471
if (mat)
472
return const_cast<char*> (mat);
473
else
474
return empty;
475
}
476
return 0;
477
}
478
479
char * Ng_GetDomainMaterial (int dom)
480
{
481
static char empty[] = "";
482
// astrid
483
if ( 1 ) // mesh->GetDimension() == 3)
484
{
485
const char * mat = mesh->GetMaterial(dom);
486
if (mat)
487
return const_cast<char*> (mat);
488
else
489
return empty;
490
}
491
492
return 0;
493
}
494
495
496
NG_ELEMENT_TYPE Ng_GetSurfaceElement (int ei, int * epi, int * np)
497
{
498
if (mesh->GetDimension() == 3)
499
{
500
const Element2d & el = mesh->SurfaceElement (ei);
501
for (int i = 0; i < el.GetNP(); i++)
502
epi[i] = el[i];
503
504
if (np) *np = el.GetNP();
505
506
return NG_ELEMENT_TYPE (el.GetType());
507
}
508
else
509
{
510
const Segment & seg = mesh->LineSegment (ei);
511
512
if (seg.pmid < 0)
513
{
514
epi[0] = seg.p1;
515
epi[1] = seg.p2;
516
517
if (np) *np = 2;
518
return NG_SEGM;
519
}
520
else
521
{
522
epi[0] = seg.p1;
523
epi[1] = seg.p2;
524
epi[2] = seg.pmid;
525
526
if (np) *np = 3;
527
return NG_SEGM3;
528
}
529
}
530
531
return NG_TRIG;
532
}
533
534
int Ng_GetSurfaceElementIndex (int ei)
535
{
536
if (mesh->GetDimension() == 3)
537
return mesh->GetFaceDescriptor(mesh->SurfaceElement(ei).GetIndex()).BCProperty();
538
else
539
return mesh->LineSegment(ei).si;
540
}
541
542
int Ng_GetSurfaceElementSurfaceNumber (int ei)
543
{
544
if (mesh->GetDimension() == 3)
545
return mesh->GetFaceDescriptor(mesh->SurfaceElement(ei).GetIndex()).SurfNr();
546
else
547
return mesh->LineSegment(ei).si;
548
}
549
int Ng_GetSurfaceElementFDNumber (int ei)
550
{
551
if (mesh->GetDimension() == 3)
552
return mesh->SurfaceElement(ei).GetIndex();
553
else
554
return -1;
555
}
556
557
558
char * Ng_GetSurfaceElementBCName (int ei)
559
{
560
if ( mesh->GetDimension() == 3 )
561
return const_cast<char *>(mesh->GetFaceDescriptor(mesh->SurfaceElement(ei).GetIndex()).GetBCName().c_str());
562
else
563
return const_cast<char *>(mesh->LineSegment(ei).GetBCName().c_str());
564
}
565
566
567
// Inefficient (but maybe safer) version:
568
//void Ng_GetSurfaceElementBCName (int ei, char * name)
569
//{
570
// if ( mesh->GetDimension() == 3 )
571
// strcpy(name,mesh->GetFaceDescriptor(mesh->SurfaceElement(ei).GetIndex()).GetBCName().c_str());
572
// else
573
// strcpy(name,mesh->LineSegment(ei).GetBCName().c_str());
574
//}
575
576
char * Ng_GetBCNumBCName (int bcnr)
577
{
578
return const_cast<char *>(mesh->GetBCName(bcnr).c_str());
579
}
580
581
582
// Inefficient (but maybe safer) version:
583
//void Ng_GetBCNumBCName (int bcnr, char * name)
584
//{
585
// strcpy(name,mesh->GetBCName(bcnr).c_str());
586
//}
587
588
void Ng_GetNormalVector (int sei, int locpi, double * nv)
589
{
590
nv[0] = 0;
591
nv[1] = 0;
592
nv[2] = 1;
593
594
(*testout) << "Ng_GetNormalVector (sei = " << sei << ", locpi = " << locpi << ")" << endl;
595
596
if (mesh->GetDimension() == 3)
597
{
598
Vec<3> n;
599
Point<3> p;
600
p = mesh->Point (mesh->SurfaceElement(sei).PNum(locpi));
601
602
int surfi = mesh->GetFaceDescriptor(mesh->SurfaceElement(sei).GetIndex()).SurfNr();
603
604
(*testout) << "surfi = " << surfi << endl;
605
#ifdef OCCGEOMETRY
606
if (occgeometry)
607
{
608
PointGeomInfo gi = mesh->SurfaceElement(sei).GeomInfoPi(locpi);
609
occgeometry->GetSurface (surfi).GetNormalVector(p, gi, n);
610
nv[0] = n(0);
611
nv[1] = n(1);
612
nv[2] = n(2);
613
}
614
else
615
#endif
616
if (geometry)
617
{
618
(*testout) << "geometry defined" << endl;
619
n = geometry->GetSurface (surfi) -> GetNormalVector(p);
620
(*testout) << "aus is" << endl;
621
nv[0] = n(0);
622
nv[1] = n(1);
623
nv[2] = n(2);
624
}
625
}
626
}
627
628
629
630
void Ng_SetPointSearchStartElement(const int el)
631
{
632
mesh->SetPointSearchStartElement(el);
633
}
634
635
636
int Ng_FindElementOfPoint (double * p, double * lami, int build_searchtree,
637
const int * const indices, const int numind)
638
639
{
640
ARRAY<int> * dummy(NULL);
641
int ind = -1;
642
643
if(indices != NULL)
644
{
645
dummy = new ARRAY<int>(numind);
646
for(int i=0; i<numind; i++) (*dummy)[i] = indices[i];
647
}
648
649
if (mesh->GetDimension() == 3)
650
{
651
Point3d p3d(p[0], p[1], p[2]);
652
ind =
653
mesh->GetElementOfPoint(p3d, lami, dummy, build_searchtree != 0);
654
}
655
else
656
{
657
double lam3[3];
658
Point3d p2d(p[0], p[1], 0);
659
ind =
660
mesh->GetElementOfPoint(p2d, lam3, dummy, build_searchtree != 0);
661
662
663
if(mesh->SurfaceElement(ind).GetType()==QUAD)
664
{
665
lami[0] = lam3[0];
666
lami[1] = lam3[1];
667
}
668
else
669
{
670
lami[0] = 1-lam3[0]-lam3[1];
671
lami[1] = lam3[0];
672
}
673
}
674
675
delete dummy;
676
677
return ind;
678
}
679
680
int Ng_FindSurfaceElementOfPoint (double * p, double * lami, int build_searchtree,
681
const int * const indices, const int numind)
682
683
{
684
ARRAY<int> * dummy(NULL);
685
int ind = -1;
686
687
if(indices != NULL)
688
{
689
dummy = new ARRAY<int>(numind);
690
for(int i=0; i<numind; i++) (*dummy)[i] = indices[i];
691
}
692
693
if (mesh->GetDimension() == 3)
694
{
695
Point3d p3d(p[0], p[1], p[2]);
696
ind =
697
mesh->GetSurfaceElementOfPoint(p3d, lami, dummy, build_searchtree != 0);
698
}
699
else
700
{
701
//throw NgException("FindSurfaceElementOfPoint for 2D meshes not yet implemented");
702
cerr << "FindSurfaceElementOfPoint for 2D meshes not yet implemented" << endl;
703
}
704
705
delete dummy;
706
707
return ind;
708
}
709
710
711
int Ng_IsElementCurved (int ei)
712
{
713
if (mesh->GetDimension() == 2)
714
return mesh->GetCurvedElements().IsSurfaceElementCurved (ei-1);
715
else
716
return mesh->GetCurvedElements().IsElementCurved (ei-1);
717
}
718
719
720
int Ng_IsSurfaceElementCurved (int sei)
721
{
722
if (mesh->GetDimension() == 2)
723
return mesh->GetCurvedElements().IsSegmentCurved (sei-1);
724
else
725
return mesh->GetCurvedElements().IsSurfaceElementCurved (sei-1);
726
}
727
728
729
730
731
void Ng_GetElementTransformation (int ei, const double * xi,
732
double * x, double * dxdxi)
733
{
734
if (mesh->GetDimension() == 2)
735
{
736
Point<2> xl(xi[0], xi[1]);
737
Point<3> xg;
738
Mat<3,2> dx;
739
740
mesh->GetCurvedElements().CalcSurfaceTransformation (xl, ei-1, xg, dx);
741
742
if (x)
743
{
744
for (int i = 0; i < 2; i++)
745
x[i] = xg(i);
746
}
747
748
if (dxdxi)
749
{
750
for (int i=0; i<2; i++)
751
{
752
dxdxi[2*i] = dx(i,0);
753
dxdxi[2*i+1] = dx(i,1);
754
}
755
}
756
}
757
else
758
{
759
Point<3> xl(xi[0], xi[1], xi[2]);
760
Point<3> xg;
761
Mat<3,3> dx;
762
763
mesh->GetCurvedElements().CalcElementTransformation (xl, ei-1, xg, dx);
764
765
// still 1-based arrays
766
if (x)
767
{
768
for (int i = 0; i < 3; i++)
769
x[i] = xg(i);
770
}
771
772
if (dxdxi)
773
{
774
for (int i=0; i<3; i++)
775
{
776
dxdxi[3*i] = dx(i,0);
777
dxdxi[3*i+1] = dx(i,1);
778
dxdxi[3*i+2] = dx(i,2);
779
}
780
}
781
}
782
}
783
784
785
786
void Ng_GetBufferedElementTransformation (int ei, const double * xi,
787
double * x, double * dxdxi,
788
void * buffer, int buffervalid)
789
{
790
// buffer = 0;
791
// buffervalid = 0;
792
if (mesh->GetDimension() == 2)
793
{
794
return Ng_GetElementTransformation (ei, xi, x, dxdxi);
795
}
796
else
797
{
798
mesh->GetCurvedElements().CalcElementTransformation (reinterpret_cast<const Point<3> &> (*xi),
799
ei-1,
800
reinterpret_cast<Point<3> &> (*x),
801
reinterpret_cast<Mat<3,3> &> (*dxdxi),
802
buffer, (buffervalid != 0));
803
804
/*
805
Point<3> xl(xi[0], xi[1], xi[2]);
806
Point<3> xg;
807
Mat<3,3> dx;
808
// buffervalid = 0;
809
mesh->GetCurvedElements().CalcElementTransformation (xl, ei-1, xg, dx, buffer, buffervalid);
810
811
// still 1-based arrays
812
if (x)
813
{
814
for (int i = 0; i < 3; i++)
815
x[i] = xg(i);
816
}
817
818
if (dxdxi)
819
{
820
for (int i=0; i<3; i++)
821
{
822
dxdxi[3*i] = dx(i,0);
823
dxdxi[3*i+1] = dx(i,1);
824
dxdxi[3*i+2] = dx(i,2);
825
}
826
}
827
*/
828
}
829
}
830
831
832
833
834
835
836
837
838
void Ng_GetMultiElementTransformation (int ei, int n,
839
const double * xi, int sxi,
840
double * x, int sx,
841
double * dxdxi, int sdxdxi)
842
{
843
if (mesh->GetDimension() == 2)
844
{
845
for (int i = 0; i < n; i++)
846
{
847
Point<2> xl(xi[i*sxi], xi[i*sxi+1]);
848
Point<3> xg;
849
Mat<3,2> dx;
850
851
mesh->GetCurvedElements().CalcSurfaceTransformation (xl, ei-1, xg, dx);
852
853
if (x)
854
{
855
x[i*sx ] = xg(0);
856
x[i*sx+1] = xg(1);
857
}
858
859
if (dxdxi)
860
{
861
dxdxi[i*sdxdxi ] = dx(0,0);
862
dxdxi[i*sdxdxi+1] = dx(0,1);
863
dxdxi[i*sdxdxi+2] = dx(1,0);
864
dxdxi[i*sdxdxi+3] = dx(1,1);
865
}
866
}
867
}
868
else
869
{
870
mesh->GetCurvedElements().CalcMultiPointElementTransformation (ei-1, n, xi, sxi, x, sx, dxdxi, sdxdxi);
871
}
872
}
873
874
875
876
877
878
879
880
881
void Ng_GetSurfaceElementTransformation (int sei, const double * xi,
882
double * x, double * dxdxi)
883
{
884
if (mesh->GetDimension() == 2)
885
{
886
Point<3> xg;
887
Vec<3> dx;
888
889
mesh->GetCurvedElements().CalcSegmentTransformation (xi[0], sei-1, xg, dx);
890
891
if (x)
892
for (int i = 0; i < 2; i++)
893
x[i] = xg(i);
894
895
if (dxdxi)
896
for (int i=0; i<2; i++)
897
dxdxi[i] = dx(i);
898
899
}
900
else
901
{
902
Point<2> xl(xi[0], xi[1]);
903
Point<3> xg;
904
Mat<3,2> dx;
905
906
mesh->GetCurvedElements().CalcSurfaceTransformation (xl, sei-1, xg, dx);
907
908
for (int i=0; i<3; i++)
909
{
910
if (x)
911
x[i] = xg(i);
912
if (dxdxi)
913
{
914
dxdxi[2*i] = dx(i,0);
915
dxdxi[2*i+1] = dx(i,1);
916
}
917
}
918
}
919
}
920
921
922
923
void Ng_GetSurfaceElementNeighbouringDomains(const int selnr, int & in, int & out)
924
{
925
if ( mesh->GetDimension() == 3 )
926
{
927
in = mesh->GetFaceDescriptor(mesh->SurfaceElement(selnr).GetIndex()).DomainIn();
928
out = mesh->GetFaceDescriptor(mesh->SurfaceElement(selnr).GetIndex()).DomainOut();
929
}
930
else
931
{
932
in = mesh -> LineSegment(selnr) . domin;
933
out = mesh -> LineSegment(selnr) . domout;
934
}
935
}
936
937
938
#ifdef PARALLEL
939
// Is Element ei an element of this processor ??
940
bool Ng_IsGhostEl (int ei)
941
{
942
if ( mesh->GetDimension() == 3 )
943
return mesh->VolumeElement(ei).IsGhost();
944
else
945
return false;
946
}
947
948
void Ng_SetGhostEl(const int ei, const bool aisghost )
949
{
950
if ( mesh -> GetDimension () == 3 )
951
mesh -> VolumeElement(ei).SetGhost (aisghost);
952
}
953
954
bool Ng_IsGhostSEl (int ei)
955
{
956
if ( mesh -> GetDimension () == 3 )
957
return mesh->SurfaceElement(ei).IsGhost();
958
else
959
return false;
960
}
961
962
void Ng_SetGhostSEl(const int ei, const bool aisghost )
963
{
964
if ( mesh -> GetDimension () == 3 )
965
mesh -> SurfaceElement(ei).SetGhost (aisghost);
966
}
967
968
969
bool Ng_IsGhostVert ( int pnum )
970
{
971
return mesh -> Point ( pnum ).IsGhost() ;
972
}
973
bool Ng_IsGhostEdge ( int ednum )
974
{
975
return mesh -> GetParallelTopology() . IsGhostEdge ( ednum );
976
}
977
978
bool Ng_IsGhostFace ( int fanum )
979
{
980
return mesh -> GetParallelTopology() . IsGhostFace ( fanum );
981
}
982
983
// void Ng_SetGhostVert ( const int pnum, const bool aisghost );
984
// void Ng_SetGhostEdge ( const int ednum, const bool aisghost );
985
// void Ng_SetGhostFace ( const int fanum, const bool aisghost );
986
987
988
bool Ng_IsExchangeEl ( int elnum )
989
{ return mesh -> GetParallelTopology() . IsExchangeElement ( elnum ); }
990
991
bool Ng_IsExchangeSEl ( int selnum )
992
{ return mesh -> GetParallelTopology() . IsExchangeSEl ( selnum ); }
993
994
void Ng_UpdateOverlap()
995
{ mesh->UpdateOverlap(); }
996
997
int Ng_Overlap ()
998
{ return mesh->GetParallelTopology() . Overlap(); }
999
1000
#endif
1001
1002
void Ng_SetRefinementFlag (int ei, int flag)
1003
{
1004
if (mesh->GetDimension() == 3)
1005
{
1006
mesh->VolumeElement(ei).SetRefinementFlag (flag != 0);
1007
mesh->VolumeElement(ei).SetStrongRefinementFlag (flag >= 10);
1008
}
1009
else
1010
{
1011
mesh->SurfaceElement(ei).SetRefinementFlag (flag != 0);
1012
mesh->SurfaceElement(ei).SetStrongRefinementFlag (flag >= 10);
1013
}
1014
}
1015
1016
void Ng_SetSurfaceRefinementFlag (int ei, int flag)
1017
{
1018
if (mesh->GetDimension() == 3)
1019
{
1020
mesh->SurfaceElement(ei).SetRefinementFlag (flag != 0);
1021
mesh->SurfaceElement(ei).SetStrongRefinementFlag (flag >= 10);
1022
}
1023
}
1024
1025
1026
void Ng_Refine (NG_REFINEMENT_TYPE reftype)
1027
{
1028
NgLock meshlock (mesh->MajorMutex(), 1);
1029
1030
BisectionOptions biopt;
1031
biopt.usemarkedelements = 1;
1032
biopt.refine_p = 0;
1033
biopt.refine_hp = 0;
1034
if (reftype == NG_REFINE_P)
1035
biopt.refine_p = 1;
1036
if (reftype == NG_REFINE_HP)
1037
biopt.refine_hp = 1;
1038
Refinement * ref;
1039
MeshOptimize2d * opt = NULL;
1040
1041
if (geometry2d)
1042
ref = new Refinement2d(*geometry2d);
1043
else if (stlgeometry)
1044
ref = new RefinementSTLGeometry(*stlgeometry);
1045
#ifdef OCCGEOMETRY
1046
else if (occgeometry)
1047
ref = new OCCRefinementSurfaces (*occgeometry);
1048
#endif
1049
#ifdef ACIS
1050
else if (acisgeometry)
1051
{
1052
ref = new ACISRefinementSurfaces (*acisgeometry);
1053
opt = new ACISMeshOptimize2dSurfaces(*acisgeometry);
1054
ref->Set2dOptimizer(opt);
1055
}
1056
#endif
1057
else if (geometry && mesh->GetDimension() == 3)
1058
{
1059
ref = new RefinementSurfaces(*geometry);
1060
opt = new MeshOptimize2dSurfaces(*geometry);
1061
ref->Set2dOptimizer(opt);
1062
}
1063
else
1064
{
1065
ref = new Refinement();
1066
}
1067
1068
1069
ref -> Bisect (*mesh, biopt);
1070
1071
mesh -> UpdateTopology();
1072
1073
// mesh -> GetCurvedElements().BuildCurvedElements (ref, mparam.elementorder);
1074
delete ref;
1075
delete opt;
1076
}
1077
1078
void Ng_SecondOrder ()
1079
{
1080
if (stlgeometry)
1081
{
1082
RefinementSTLGeometry ref (*stlgeometry);
1083
ref.MakeSecondOrder (*mesh);
1084
}
1085
1086
else if (geometry2d)
1087
{
1088
Refinement2d ref (*geometry2d);
1089
ref.MakeSecondOrder (*mesh);
1090
}
1091
1092
else if (geometry && mesh->GetDimension() == 3)
1093
1094
{
1095
RefinementSurfaces ref (*geometry);
1096
ref.MakeSecondOrder (*mesh);
1097
}
1098
else
1099
{
1100
if (printmessage_importance>0)
1101
cout << "no geom" << endl;
1102
Refinement ref;
1103
ref.MakeSecondOrder (*mesh);
1104
}
1105
1106
mesh -> UpdateTopology();
1107
}
1108
1109
/*
1110
void Ng_HPRefinement (int levels)
1111
{
1112
Refinement * ref;
1113
1114
if (stlgeometry)
1115
ref = new RefinementSTLGeometry (*stlgeometry);
1116
else if (geometry2d)
1117
ref = new Refinement2d (*geometry2d);
1118
else
1119
ref = new RefinementSurfaces (*geometry);
1120
1121
1122
HPRefinement (*mesh, ref, levels);
1123
}
1124
1125
void Ng_HPRefinement (int levels, double parameter)
1126
{
1127
Refinement * ref;
1128
1129
if (stlgeometry)
1130
ref = new RefinementSTLGeometry (*stlgeometry);
1131
else if (geometry2d)
1132
ref = new Refinement2d (*geometry2d);
1133
else
1134
ref = new RefinementSurfaces (*geometry);
1135
1136
1137
HPRefinement (*mesh, ref, levels, parameter);
1138
}
1139
*/
1140
1141
void Ng_HPRefinement (int levels, double parameter, bool setorders,
1142
bool ref_level)
1143
{
1144
Refinement * ref;
1145
1146
if (stlgeometry)
1147
ref = new RefinementSTLGeometry (*stlgeometry);
1148
else if (geometry2d)
1149
ref = new Refinement2d (*geometry2d);
1150
else
1151
ref = new RefinementSurfaces (*geometry);
1152
1153
1154
HPRefinement (*mesh, ref, levels, parameter, setorders, ref_level);
1155
}
1156
1157
1158
void Ng_HighOrder (int order, bool rational)
1159
{
1160
NgLock meshlock (mesh->MajorMutex(), true);
1161
1162
Refinement * ref;
1163
1164
if (stlgeometry)
1165
ref = new RefinementSTLGeometry (*stlgeometry);
1166
#ifdef OCCGEOMETRY
1167
else if (occgeometry)
1168
ref = new OCCRefinementSurfaces (*occgeometry);
1169
#endif
1170
#ifdef ACIS
1171
else if (acisgeometry)
1172
{
1173
ref = new ACISRefinementSurfaces (*acisgeometry);
1174
}
1175
#endif
1176
else if (geometry2d)
1177
ref = new Refinement2d (*geometry2d);
1178
else
1179
{
1180
ref = new RefinementSurfaces (*geometry);
1181
}
1182
1183
// cout << "parameter 1: " << argv[1] << " (conversion to int = " << atoi(argv[1]) << ")" << endl;
1184
1185
1186
mesh -> GetCurvedElements().BuildCurvedElements (ref, order, rational);
1187
1188
1189
/*
1190
if(mesh)
1191
mesh -> GetCurvedElements().BuildCurvedElements (ref, order, rational);
1192
*/
1193
1194
delete ref;
1195
}
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
int Ng_ME_GetNVertices (NG_ELEMENT_TYPE et)
1209
{
1210
switch (et)
1211
{
1212
case NG_SEGM:
1213
case NG_SEGM3:
1214
return 2;
1215
1216
case NG_TRIG:
1217
case NG_TRIG6:
1218
return 3;
1219
1220
case NG_QUAD:
1221
return 4;
1222
1223
case NG_TET:
1224
case NG_TET10:
1225
return 4;
1226
1227
case NG_PYRAMID:
1228
return 5;
1229
1230
case NG_PRISM:
1231
case NG_PRISM12:
1232
return 6;
1233
1234
case NG_HEX:
1235
return 8;
1236
1237
default:
1238
cerr << "Ng_ME_GetNVertices, illegal element type " << et << endl;
1239
}
1240
return 0;
1241
}
1242
1243
int Ng_ME_GetNEdges (NG_ELEMENT_TYPE et)
1244
{
1245
switch (et)
1246
{
1247
case NG_SEGM:
1248
case NG_SEGM3:
1249
return 1;
1250
1251
case NG_TRIG:
1252
case NG_TRIG6:
1253
return 3;
1254
1255
case NG_QUAD:
1256
return 4;
1257
1258
case NG_TET:
1259
case NG_TET10:
1260
return 6;
1261
1262
case NG_PYRAMID:
1263
return 8;
1264
1265
case NG_PRISM:
1266
case NG_PRISM12:
1267
return 9;
1268
1269
case NG_HEX:
1270
return 12;
1271
1272
default:
1273
cerr << "Ng_ME_GetNEdges, illegal element type " << et << endl;
1274
}
1275
return 0;
1276
}
1277
1278
1279
int Ng_ME_GetNFaces (NG_ELEMENT_TYPE et)
1280
{
1281
switch (et)
1282
{
1283
case NG_SEGM:
1284
case NG_SEGM3:
1285
return 0;
1286
1287
case NG_TRIG:
1288
case NG_TRIG6:
1289
return 1;
1290
1291
case NG_QUAD:
1292
case NG_QUAD6:
1293
return 1;
1294
1295
case NG_TET:
1296
case NG_TET10:
1297
return 4;
1298
1299
case NG_PYRAMID:
1300
return 5;
1301
1302
case NG_PRISM:
1303
case NG_PRISM12:
1304
return 5;
1305
1306
case NG_HEX:
1307
return 6;
1308
1309
default:
1310
cerr << "Ng_ME_GetNVertices, illegal element type " << et << endl;
1311
}
1312
return 0;
1313
}
1314
1315
1316
const NG_POINT * Ng_ME_GetVertices (NG_ELEMENT_TYPE et)
1317
{
1318
static double segm_points [][3] =
1319
{ { 1, 0, 0 },
1320
{ 0, 0, 0 } };
1321
1322
static double trig_points [][3] =
1323
{ { 1, 0, 0 },
1324
{ 0, 1, 0 },
1325
{ 0, 0, 0 } };
1326
1327
static double quad_points [][3] =
1328
{ { 0, 0, 0 },
1329
{ 1, 0, 0 },
1330
{ 1, 1, 0 },
1331
{ 0, 1, 0 } };
1332
1333
static double tet_points [][3] =
1334
{ { 1, 0, 0 },
1335
{ 0, 1, 0 },
1336
{ 0, 0, 1 },
1337
{ 0, 0, 0 } };
1338
1339
static double pyramid_points [][3] =
1340
{
1341
{ 0, 0, 0 },
1342
{ 1, 0, 0 },
1343
{ 1, 1, 0 },
1344
{ 0, 1, 0 },
1345
{ 0, 0, 1-1e-7 },
1346
};
1347
1348
static double prism_points[][3] =
1349
{
1350
{ 1, 0, 0 },
1351
{ 0, 1, 0 },
1352
{ 0, 0, 0 },
1353
{ 1, 0, 1 },
1354
{ 0, 1, 1 },
1355
{ 0, 0, 1 }
1356
};
1357
1358
switch (et)
1359
{
1360
case NG_SEGM:
1361
case NG_SEGM3:
1362
return segm_points;
1363
1364
case NG_TRIG:
1365
case NG_TRIG6:
1366
return trig_points;
1367
1368
case NG_QUAD:
1369
case NG_QUAD6:
1370
return quad_points;
1371
1372
case NG_TET:
1373
case NG_TET10:
1374
return tet_points;
1375
1376
case NG_PYRAMID:
1377
return pyramid_points;
1378
1379
case NG_PRISM:
1380
case NG_PRISM12:
1381
return prism_points;
1382
1383
case NG_HEX:
1384
default:
1385
cerr << "Ng_ME_GetVertices, illegal element type " << et << endl;
1386
}
1387
return 0;
1388
}
1389
1390
1391
1392
const NG_EDGE * Ng_ME_GetEdges (NG_ELEMENT_TYPE et)
1393
{
1394
static int segm_edges[1][2] =
1395
{ { 1, 2 }};
1396
1397
static int trig_edges[3][2] =
1398
{ { 3, 1 },
1399
{ 3, 2 },
1400
{ 1, 2 }};
1401
1402
static int quad_edges[4][2] =
1403
{ { 1, 2 },
1404
{ 4, 3 },
1405
{ 1, 4 },
1406
{ 2, 3 }};
1407
1408
1409
static int tet_edges[6][2] =
1410
{ { 4, 1 },
1411
{ 4, 2 },
1412
{ 4, 3 },
1413
{ 1, 2 },
1414
{ 1, 3 },
1415
{ 2, 3 }};
1416
1417
static int prism_edges[9][2] =
1418
{ { 3, 1 },
1419
{ 1, 2 },
1420
{ 3, 2 },
1421
{ 6, 4 },
1422
{ 4, 5 },
1423
{ 6, 5 },
1424
{ 3, 6 },
1425
{ 1, 4 },
1426
{ 2, 5 }};
1427
1428
static int pyramid_edges[8][2] =
1429
{ { 1, 2 },
1430
{ 2, 3 },
1431
{ 1, 4 },
1432
{ 4, 3 },
1433
{ 1, 5 },
1434
{ 2, 5 },
1435
{ 3, 5 },
1436
{ 4, 5 }};
1437
1438
1439
1440
switch (et)
1441
{
1442
case NG_SEGM:
1443
case NG_SEGM3:
1444
return segm_edges;
1445
1446
case NG_TRIG:
1447
case NG_TRIG6:
1448
return trig_edges;
1449
1450
case NG_QUAD:
1451
case NG_QUAD6:
1452
return quad_edges;
1453
1454
case NG_TET:
1455
case NG_TET10:
1456
return tet_edges;
1457
1458
case NG_PYRAMID:
1459
return pyramid_edges;
1460
1461
case NG_PRISM:
1462
case NG_PRISM12:
1463
return prism_edges;
1464
1465
case NG_HEX:
1466
default:
1467
cerr << "Ng_ME_GetEdges, illegal element type " << et << endl;
1468
}
1469
return 0;
1470
}
1471
1472
1473
const NG_FACE * Ng_ME_GetFaces (NG_ELEMENT_TYPE et)
1474
{
1475
static int tet_faces[4][4] =
1476
{ { 4, 2, 3, 0 },
1477
{ 4, 1, 3, 0 },
1478
{ 4, 1, 2, 0 },
1479
{ 1, 2, 3, 0 } };
1480
1481
static int prism_faces[5][4] =
1482
{
1483
{ 1, 2, 3, 0 },
1484
{ 4, 5, 6, 0 },
1485
{ 3, 1, 4, 6 },
1486
{ 1, 2, 5, 4 },
1487
{ 2, 3, 6, 5 }
1488
};
1489
1490
static int pyramid_faces[5][4] =
1491
{
1492
{ 1, 2, 5, 0 },
1493
{ 2, 3, 5, 0 },
1494
{ 3, 4, 5, 0 },
1495
{ 4, 1, 5, 0 },
1496
{ 1, 2, 3, 4 }
1497
};
1498
1499
static int trig_faces[1][4] =
1500
{
1501
{ 1, 2, 3, 0 },
1502
};
1503
1504
switch (et)
1505
{
1506
case NG_TET:
1507
case NG_TET10:
1508
return tet_faces;
1509
1510
case NG_PRISM:
1511
case NG_PRISM12:
1512
return prism_faces;
1513
1514
case NG_PYRAMID:
1515
return pyramid_faces;
1516
1517
1518
case NG_SEGM:
1519
case NG_SEGM3:
1520
1521
case NG_TRIG:
1522
case NG_TRIG6:
1523
return trig_faces;
1524
case NG_QUAD:
1525
1526
1527
case NG_HEX:
1528
1529
default:
1530
cerr << "Ng_ME_GetFaces, illegal element type " << et << endl;
1531
}
1532
return 0;
1533
}
1534
1535
1536
int Ng_GetNEdges()
1537
{
1538
return mesh->GetTopology().GetNEdges();
1539
}
1540
int Ng_GetNFaces()
1541
{
1542
return mesh->GetTopology().GetNFaces();
1543
}
1544
1545
1546
1547
int Ng_GetElement_Edges (int elnr, int * edges, int * orient)
1548
{
1549
const MeshTopology & topology = mesh->GetTopology();
1550
if (mesh->GetDimension() == 3)
1551
return topology.GetElementEdges (elnr, edges, orient);
1552
else
1553
return topology.GetSurfaceElementEdges (elnr, edges, orient);
1554
}
1555
1556
int Ng_GetElement_Faces (int elnr, int * faces, int * orient)
1557
{
1558
const MeshTopology & topology = mesh->GetTopology();
1559
if (mesh->GetDimension() == 3)
1560
return topology.GetElementFaces (elnr, faces, orient);
1561
else
1562
{
1563
faces[0] = elnr;
1564
if (orient) orient[0] = 0;
1565
return 1;
1566
}
1567
}
1568
1569
int Ng_GetSurfaceElement_Edges (int elnr, int * edges, int * orient)
1570
{
1571
const MeshTopology & topology = mesh->GetTopology();
1572
if (mesh->GetDimension() == 3)
1573
return topology.GetSurfaceElementEdges (elnr, edges, orient);
1574
else
1575
{
1576
if (orient)
1577
topology.GetSegmentEdge(elnr, edges[0], orient[0]);
1578
else
1579
edges[0] = topology.GetSegmentEdge(elnr);
1580
}
1581
return 1;
1582
/*
1583
int i, ned;
1584
const MeshTopology & topology = mesh->GetTopology();
1585
ARRAY<int> ia;
1586
topology.GetSurfaceElementEdges (elnr, ia);
1587
ned = ia.Size();
1588
for (i = 1; i <= ned; i++)
1589
edges[i-1] = ia.Get(i);
1590
1591
if (orient)
1592
{
1593
topology.GetSurfaceElementEdgeOrientations (elnr, ia);
1594
for (i = 1; i <= ned; i++)
1595
orient[i-1] = ia.Get(i);
1596
}
1597
return ned;
1598
*/
1599
}
1600
1601
int Ng_GetSurfaceElement_Face (int selnr, int * orient)
1602
{
1603
if (mesh->GetDimension() == 3)
1604
{
1605
const MeshTopology & topology = mesh->GetTopology();
1606
if (orient)
1607
*orient = topology.GetSurfaceElementFaceOrientation (selnr);
1608
return topology.GetSurfaceElementFace (selnr);
1609
}
1610
return -1;
1611
}
1612
1613
int Ng_GetFace_Vertices (int fnr, int * vert)
1614
{
1615
const MeshTopology & topology = mesh->GetTopology();
1616
ArrayMem<int,4> ia;
1617
topology.GetFaceVertices (fnr, ia);
1618
for (int i = 0; i < ia.Size(); i++)
1619
vert[i] = ia[i];
1620
// cout << "face verts = " << ia << endl;
1621
return ia.Size();
1622
}
1623
1624
1625
int Ng_GetFace_Edges (int fnr, int * edge)
1626
{
1627
const MeshTopology & topology = mesh->GetTopology();
1628
ArrayMem<int,4> ia;
1629
topology.GetFaceEdges (fnr, ia);
1630
for (int i = 0; i < ia.Size(); i++)
1631
edge[i] = ia[i];
1632
return ia.Size();
1633
}
1634
1635
void Ng_GetEdge_Vertices (int ednr, int * vert)
1636
{
1637
const MeshTopology & topology = mesh->GetTopology();
1638
topology.GetEdgeVertices (ednr, vert[0], vert[1]);
1639
}
1640
1641
1642
int Ng_GetNVertexElements (int vnr)
1643
{
1644
if (mesh->GetDimension() == 3)
1645
return mesh->GetTopology().GetVertexElements(vnr).Size();
1646
else
1647
return mesh->GetTopology().GetVertexSurfaceElements(vnr).Size();
1648
}
1649
1650
void Ng_GetVertexElements (int vnr, int * els)
1651
{
1652
FlatArray<int> ia(0,0);
1653
if (mesh->GetDimension() == 3)
1654
ia = mesh->GetTopology().GetVertexElements(vnr);
1655
else
1656
ia = mesh->GetTopology().GetVertexSurfaceElements(vnr);
1657
for (int i = 0; i < ia.Size(); i++)
1658
els[i] = ia[i];
1659
}
1660
1661
1662
int Ng_GetElementOrder (int enr)
1663
{
1664
if (mesh->GetDimension() == 3)
1665
return mesh->VolumeElement(enr).GetOrder();
1666
else
1667
return mesh->SurfaceElement(enr).GetOrder();
1668
}
1669
1670
void Ng_GetElementOrders (int enr, int * ox, int * oy, int * oz)
1671
{
1672
if (mesh->GetDimension() == 3)
1673
mesh->VolumeElement(enr).GetOrder(*ox, *oy, *oz);
1674
else
1675
mesh->SurfaceElement(enr).GetOrder(*ox, *oy, *oz);
1676
}
1677
1678
void Ng_SetElementOrder (int enr, int order)
1679
{
1680
if (mesh->GetDimension() == 3)
1681
return mesh->VolumeElement(enr).SetOrder(order);
1682
else
1683
return mesh->SurfaceElement(enr).SetOrder(order);
1684
}
1685
1686
void Ng_SetElementOrders (int enr, int ox, int oy, int oz)
1687
{
1688
if (mesh->GetDimension() == 3)
1689
mesh->VolumeElement(enr).SetOrder(ox, oy, oz);
1690
else
1691
mesh->SurfaceElement(enr).SetOrder(ox, oy);
1692
}
1693
1694
1695
int Ng_GetSurfaceElementOrder (int enr)
1696
{
1697
return mesh->SurfaceElement(enr).GetOrder();
1698
}
1699
1700
//HERBERT: falsche Anzahl von Argumenten
1701
//void Ng_GetSurfaceElementOrders (int enr, int * ox, int * oy, int * oz)
1702
void Ng_GetSurfaceElementOrders (int enr, int * ox, int * oy)
1703
{
1704
int d;
1705
mesh->SurfaceElement(enr).GetOrder(*ox, *oy, d);
1706
}
1707
1708
void Ng_SetSurfaceElementOrder (int enr, int order)
1709
{
1710
return mesh->SurfaceElement(enr).SetOrder(order);
1711
}
1712
1713
void Ng_SetSurfaceElementOrders (int enr, int ox, int oy)
1714
{
1715
mesh->SurfaceElement(enr).SetOrder(ox, oy);
1716
}
1717
1718
1719
int Ng_GetNLevels ()
1720
{
1721
return (mesh) ? mesh->mglevels : 0;
1722
}
1723
1724
1725
void Ng_GetParentNodes (int ni, int * parents)
1726
{
1727
if (ni <= mesh->mlbetweennodes.Size())
1728
{
1729
parents[0] = mesh->mlbetweennodes.Get(ni).I1();
1730
parents[1] = mesh->mlbetweennodes.Get(ni).I2();
1731
}
1732
else
1733
parents[0] = parents[1] = 0;
1734
}
1735
1736
1737
int Ng_GetParentElement (int ei)
1738
{
1739
if (mesh->GetDimension() == 3)
1740
{
1741
if (ei <= mesh->mlparentelement.Size())
1742
return mesh->mlparentelement.Get(ei);
1743
}
1744
else
1745
{
1746
if (ei <= mesh->mlparentsurfaceelement.Size())
1747
return mesh->mlparentsurfaceelement.Get(ei);
1748
}
1749
return 0;
1750
}
1751
1752
1753
int Ng_GetParentSElement (int ei)
1754
{
1755
if (mesh->GetDimension() == 3)
1756
{
1757
if (ei <= mesh->mlparentsurfaceelement.Size())
1758
return mesh->mlparentsurfaceelement.Get(ei);
1759
}
1760
else
1761
{
1762
return 0;
1763
}
1764
return 0;
1765
}
1766
1767
1768
1769
1770
1771
int Ng_GetClusterRepVertex (int pi)
1772
{
1773
return mesh->GetClusters().GetVertexRepresentant(pi);
1774
}
1775
1776
int Ng_GetClusterRepEdge (int pi)
1777
{
1778
return mesh->GetClusters().GetEdgeRepresentant(pi);
1779
}
1780
1781
int Ng_GetClusterRepFace (int pi)
1782
{
1783
return mesh->GetClusters().GetFaceRepresentant(pi);
1784
}
1785
1786
int Ng_GetClusterRepElement (int pi)
1787
{
1788
return mesh->GetClusters().GetElementRepresentant(pi);
1789
}
1790
1791
1792
1793
1794
1795
1796
void Ng_InitSolutionData (Ng_SolutionData * soldata)
1797
{
1798
soldata -> name = NULL;
1799
soldata -> data = NULL;
1800
soldata -> components = 1;
1801
soldata -> dist = 1;
1802
soldata -> order = 1;
1803
soldata -> iscomplex = 0;
1804
soldata -> draw_surface = 1;
1805
soldata -> draw_volume = 1;
1806
soldata -> soltype = NG_SOLUTION_NODAL;
1807
soldata -> solclass = 0;
1808
}
1809
1810
void Ng_SetSolutionData (Ng_SolutionData * soldata)
1811
{
1812
#ifdef OPENGL
1813
// vssolution.ClearSolutionData ();
1814
VisualSceneSolution::SolData * vss = new VisualSceneSolution::SolData;
1815
1816
// cout << "Add solution " << soldata->name << ", type = " << soldata->soltype << endl;
1817
1818
vss->name = new char[strlen (soldata->name)+1];
1819
strcpy (vss->name, soldata->name);
1820
1821
vss->data = soldata->data;
1822
vss->components = soldata->components;
1823
vss->dist = soldata->dist;
1824
vss->order = soldata->order;
1825
vss->iscomplex = bool(soldata->iscomplex);
1826
vss->draw_surface = soldata->draw_surface;
1827
vss->draw_volume = soldata->draw_volume;
1828
vss->soltype = VisualSceneSolution::SolType (soldata->soltype);
1829
vss->solclass = soldata->solclass;
1830
vssolution.AddSolutionData (vss);
1831
#endif
1832
}
1833
1834
void Ng_ClearSolutionData ()
1835
{
1836
#ifdef OPENGL
1837
vssolution.ClearSolutionData();
1838
#endif
1839
}
1840
1841
1842
1843
void Ng_Redraw ()
1844
{
1845
#ifdef OPENGL
1846
extern bool nodisplay; // he: global in ngappinit.cpp
1847
if (!nodisplay)
1848
{
1849
vssolution.UpdateSolutionTimeStamp();
1850
Render();
1851
}
1852
#endif
1853
}
1854
1855
1856
void Ng_SetVisualizationParameter (const char * name, const char * value)
1857
{
1858
#ifdef OPENGL
1859
#ifndef NOTCL
1860
char buf[100];
1861
sprintf (buf, "visoptions.%s", name);
1862
if (printmessage_importance>0)
1863
{
1864
cout << "name = " << name << ", value = " << value << endl;
1865
cout << "set tcl-variable " << buf << " to " << value << endl;
1866
}
1867
Tcl_SetVar (tcl_interp, buf, const_cast<char*> (value), 0);
1868
Tcl_Eval (tcl_interp, "Ng_Vis_Set parameters;");
1869
#endif
1870
#endif
1871
}
1872
1873
1874
1875
1876
int firsttime = 1;
1877
int animcnt = 0;
1878
void PlayAnimFile(const char* name, int speed, int maxcnt)
1879
{
1880
//extern Mesh * mesh;
1881
1882
/*
1883
if (mesh.Ptr()) mesh->DeleteMesh();
1884
if (!mesh.Ptr()) mesh = new Mesh();
1885
*/
1886
mesh.Reset (new Mesh());
1887
1888
int ne, np, i;
1889
1890
char str[80];
1891
char str2[80];
1892
1893
//int tend = 5000;
1894
// for (ti = 1; ti <= tend; ti++)
1895
//{
1896
int rti = (animcnt%(maxcnt-1)) + 1;
1897
animcnt+=speed;
1898
1899
sprintf(str2,"%05i.sol",rti);
1900
strcpy(str,"mbssol/");
1901
strcat(str,name);
1902
strcat(str,str2);
1903
1904
if (printmessage_importance>0)
1905
cout << "read file '" << str << "'" << endl;
1906
1907
ifstream infile(str);
1908
infile >> ne;
1909
for (i = 1; i <= ne; i++)
1910
{
1911
int j;
1912
Element2d tri(TRIG);
1913
tri.SetIndex(1); //faceind
1914
1915
for (j = 1; j <= 3; j++)
1916
infile >> tri.PNum(j);
1917
1918
infile >> np;
1919
for (i = 1; i <= np; i++)
1920
{
1921
Point3d p;
1922
infile >> p.X() >> p.Y() >> p.Z();
1923
if (firsttime)
1924
mesh->AddPoint (p);
1925
else
1926
mesh->Point(i) = Point<3> (p);
1927
}
1928
1929
//firsttime = 0;
1930
Ng_Redraw();
1931
}
1932
}
1933
1934
1935
int Ng_GetNPeriodicVertices (int idnr)
1936
{
1937
ARRAY<INDEX_2> apairs;
1938
mesh->GetIdentifications().GetPairs (idnr, apairs);
1939
return apairs.Size();
1940
}
1941
1942
1943
// pairs should be an integer array of 2*npairs
1944
void Ng_GetPeriodicVertices (int idnr, int * pairs)
1945
{
1946
ARRAY<INDEX_2> apairs;
1947
mesh->GetIdentifications().GetPairs (idnr, apairs);
1948
for (int i = 0; i < apairs.Size(); i++)
1949
{
1950
pairs[2*i] = apairs[i].I1();
1951
pairs[2*i+1] = apairs[i].I2();
1952
}
1953
1954
}
1955
1956
1957
1958
int Ng_GetNPeriodicEdges (int idnr)
1959
{
1960
ARRAY<INDEX,PointIndex::BASE> map;
1961
//const MeshTopology & top = mesh->GetTopology();
1962
int nse = mesh->GetNSeg();
1963
1964
int cnt = 0;
1965
// for (int id = 1; id <= mesh->GetIdentifications().GetMaxNr(); id++)
1966
{
1967
mesh->GetIdentifications().GetMap(idnr, map);
1968
//(*testout) << "ident-map " << id << ":" << endl << map << endl;
1969
1970
for (SegmentIndex si = 0; si < nse; si++)
1971
{
1972
PointIndex other1 = map[(*mesh)[si].p1];
1973
PointIndex other2 = map[(*mesh)[si].p2];
1974
// (*testout) << "seg = " << (*mesh)[si] << "; other = "
1975
// << other1 << "-" << other2 << endl;
1976
if (other1 && other2 && mesh->IsSegment (other1, other2))
1977
{
1978
cnt++;
1979
}
1980
}
1981
}
1982
return cnt;
1983
}
1984
1985
void Ng_GetPeriodicEdges (int idnr, int * pairs)
1986
{
1987
ARRAY<INDEX,PointIndex::BASE> map;
1988
const MeshTopology & top = mesh->GetTopology();
1989
int nse = mesh->GetNSeg();
1990
1991
int cnt = 0;
1992
// for (int id = 1; id <= mesh->GetIdentifications().GetMaxNr(); id++)
1993
{
1994
mesh->GetIdentifications().GetMap(idnr, map);
1995
1996
//(*testout) << "map = " << map << endl;
1997
1998
for (SegmentIndex si = 0; si < nse; si++)
1999
{
2000
PointIndex other1 = map[(*mesh)[si].p1];
2001
PointIndex other2 = map[(*mesh)[si].p2];
2002
if (other1 && other2 && mesh->IsSegment (other1, other2))
2003
{
2004
SegmentIndex otherseg = mesh->SegmentNr (other1, other2);
2005
pairs[cnt++] = top.GetSegmentEdge (si+1);
2006
pairs[cnt++] = top.GetSegmentEdge (otherseg+1);
2007
}
2008
}
2009
}
2010
}
2011
2012
2013
2014
void Ng_PushStatus (const char * str)
2015
{
2016
PushStatus (MyStr (str));
2017
}
2018
2019
void Ng_PopStatus ()
2020
{
2021
PopStatus ();
2022
}
2023
2024
void Ng_SetThreadPercentage (double percent)
2025
{
2026
SetThreadPercent (percent);
2027
}
2028
2029
void Ng_GetStatus (char ** str, double & percent)
2030
{
2031
MyStr s;
2032
GetStatus(s,percent);
2033
*str = new char[s.Length()+1];
2034
strcpy(*str,s.c_str());
2035
}
2036
2037
2038
void Ng_SetTerminate(void)
2039
{
2040
multithread.terminate = 1;
2041
}
2042
void Ng_UnSetTerminate(void)
2043
{
2044
multithread.terminate = 0;
2045
}
2046
2047
int Ng_ShouldTerminate(void)
2048
{
2049
return multithread.terminate;
2050
}
2051
2052
///// Added by Roman Stainko ....
2053
int Ng_GetVertex_Elements( int vnr, int* elems )
2054
{
2055
const MeshTopology& topology = mesh->GetTopology();
2056
ArrayMem<int,4> indexArray;
2057
topology.GetVertexElements( vnr, indexArray );
2058
2059
for( int i=0; i<indexArray.Size(); i++ )
2060
elems[i] = indexArray[i];
2061
2062
return indexArray.Size();
2063
}
2064
2065
///// Added by Roman Stainko ....
2066
int Ng_GetVertex_SurfaceElements( int vnr, int* elems )
2067
{
2068
const MeshTopology& topology = mesh->GetTopology();
2069
ArrayMem<int,4> indexArray;
2070
topology.GetVertexSurfaceElements( vnr, indexArray );
2071
2072
for( int i=0; i<indexArray.Size(); i++ )
2073
elems[i] = indexArray[i];
2074
2075
return indexArray.Size();
2076
}
2077
2078
///// Added by Roman Stainko ....
2079
int Ng_GetVertex_NElements( int vnr )
2080
{
2081
const MeshTopology& topology = mesh->GetTopology();
2082
ArrayMem<int,4> indexArray;
2083
topology.GetVertexElements( vnr, indexArray );
2084
2085
return indexArray.Size();
2086
}
2087
2088
///// Added by Roman Stainko ....
2089
int Ng_GetVertex_NSurfaceElements( int vnr )
2090
{
2091
const MeshTopology& topology = mesh->GetTopology();
2092
ArrayMem<int,4> indexArray;
2093
topology.GetVertexSurfaceElements( vnr, indexArray );
2094
2095
return indexArray.Size();
2096
}
2097
2098
2099
2100
#ifdef SOCKETS
2101
int Ng_SocketClientOpen( const int port, const char * host )
2102
{
2103
try
2104
{
2105
if(host)
2106
clientsocket.Reset(new ClientSocket(port,host));
2107
else
2108
clientsocket.Reset(new ClientSocket(port));
2109
}
2110
catch( SocketException e)
2111
{
2112
cerr << e.Description() << endl;
2113
return 0;
2114
}
2115
return 1;
2116
}
2117
2118
void Ng_SocketClientWrite( const char * write, char** reply)
2119
{
2120
string output = write;
2121
(*clientsocket) << output;
2122
string sreply;
2123
(*clientsocket) >> sreply;
2124
*reply = new char[sreply.size()+1];
2125
strcpy(*reply,sreply.c_str());
2126
}
2127
2128
2129
void Ng_SocketClientClose ( void )
2130
{
2131
clientsocket.Reset(NULL);
2132
}
2133
2134
2135
void Ng_SocketClientGetServerHost ( const int number, char ** host )
2136
{
2137
*host = new char[servers[number]->host.size()+1];
2138
strcpy(*host,servers[number]->host.c_str());
2139
}
2140
2141
void Ng_SocketClientGetServerPort ( const int number, int * port )
2142
{
2143
*port = servers[number]->port;
2144
}
2145
2146
void Ng_SocketClientGetServerClientID ( const int number, int * id )
2147
{
2148
*id = servers[number]->clientid;
2149
}
2150
2151
#endif // SOCKETS
2152
2153
2154
2155
2156
#ifdef PARALLEL
2157
void Ng_SetElementPartition ( const int elnr, const int part )
2158
{
2159
mesh->VolumeElement(elnr+1).SetPartition(part);
2160
2161
}
2162
int Ng_GetElementPartition ( const int elnr )
2163
{
2164
return mesh->VolumeElement(elnr+1).GetPartition();
2165
}
2166
#endif
2167
2168
2169
void Ng_InitPointCurve(double red, double green, double blue)
2170
{
2171
mesh->InitPointCurve(red, green, blue);
2172
}
2173
2174
void Ng_AddPointCurvePoint(const double * point)
2175
{
2176
Point3d pt;
2177
pt.X() = point[0];
2178
pt.Y() = point[1];
2179
pt.Z() = point[2];
2180
mesh->AddPointCurvePoint(pt);
2181
}
2182
2183
2184
void Ng_SaveMesh ( const char * meshfile )
2185
{
2186
mesh -> Save(string(meshfile));
2187
}
2188
2189
2190
int Ng_Bisect_WithInfo ( const char * refinementfile, double ** qualityloss, int * qualityloss_size )
2191
{
2192
BisectionOptions biopt;
2193
biopt.outfilename = NULL; // "ngfepp.vol";
2194
biopt.femcode = "fepp";
2195
biopt.refinementfilename = refinementfile;
2196
2197
Refinement * ref;
2198
MeshOptimize2d * opt = NULL;
2199
if (stlgeometry)
2200
ref = new RefinementSTLGeometry(*stlgeometry);
2201
#ifdef OCCGEOMETRY
2202
else if (occgeometry)
2203
ref = new OCCRefinementSurfaces (*occgeometry);
2204
#endif
2205
#ifdef ACIS
2206
else if (acisgeometry)
2207
{
2208
ref = new ACISRefinementSurfaces(*acisgeometry);
2209
opt = new ACISMeshOptimize2dSurfaces(*acisgeometry);
2210
ref->Set2dOptimizer(opt);
2211
}
2212
#endif
2213
else
2214
{
2215
ref = new RefinementSurfaces(*geometry);
2216
opt = new MeshOptimize2dSurfaces(*geometry);
2217
ref->Set2dOptimizer(opt);
2218
}
2219
2220
if(!mesh->LocalHFunctionGenerated())
2221
mesh->CalcLocalH();
2222
2223
mesh->LocalHFunction().SetGrading (mparam.grading);
2224
2225
ARRAY<double> * qualityloss_arr = NULL;
2226
if(qualityloss != NULL)
2227
qualityloss_arr = new ARRAY<double>;
2228
2229
ref -> Bisect (*mesh, biopt, qualityloss_arr);
2230
2231
int retval = 0;
2232
2233
if(qualityloss != NULL)
2234
{
2235
*qualityloss = new double[qualityloss_arr->Size()+1];
2236
2237
for(int i = 0; i<qualityloss_arr->Size(); i++)
2238
(*qualityloss)[i+1] = (*qualityloss_arr)[i];
2239
2240
retval = qualityloss_arr->Size();
2241
2242
delete qualityloss_arr;
2243
}
2244
2245
mesh -> UpdateTopology();
2246
mesh -> GetCurvedElements().BuildCurvedElements (ref, mparam.elementorder);
2247
2248
multithread.running = 0;
2249
delete ref;
2250
delete opt;
2251
2252
return retval;
2253
}
2254
2255
void Ng_Bisect ( const char * refinementfile )
2256
{
2257
Ng_Bisect_WithInfo( refinementfile, NULL, NULL );
2258
}
2259
2260
2261
2262
2263
2264
/*
2265
number of nodes of type nt
2266
nt = 0 is Vertex
2267
nt = 1 is Edge
2268
nt = 2 is Face
2269
nt = 3 is Cell
2270
*/
2271
int Ng_GetNNodes (int nt)
2272
{
2273
switch (nt)
2274
{
2275
case 0: return mesh -> GetNV();
2276
case 1: return mesh->GetTopology().GetNEdges();
2277
case 2: return mesh->GetTopology().GetNFaces();
2278
case 3: return mesh -> GetNE();
2279
}
2280
return -1;
2281
}
2282
2283
2284
int Ng_GetClosureNodes (int nt, int nodenr, int nodeset, int * nodes)
2285
{
2286
switch (nt)
2287
{
2288
case 3: // The closure of a cell
2289
{
2290
int cnt = 0;
2291
if (nodeset & 1) // Vertices
2292
{
2293
const Element & el = (*mesh)[ElementIndex(nodenr)];
2294
for (int i = 0; i < el.GetNP(); i++)
2295
{
2296
nodes[cnt++] = 0;
2297
nodes[cnt++] = el[i] - PointIndex::BASE;
2298
}
2299
}
2300
2301
if (nodeset & 2) // Edges
2302
{
2303
int edges[12];
2304
int ned;
2305
ned = mesh->GetTopology().GetElementEdges (nodenr+1, edges, 0);
2306
for (int i = 0; i < ned; i++)
2307
{
2308
nodes[cnt++] = 1;
2309
nodes[cnt++] = edges[i]-1;
2310
}
2311
}
2312
2313
if (nodeset & 4) // Faces
2314
{
2315
int faces[12];
2316
int nfa;
2317
nfa = mesh->GetTopology().GetElementFaces (nodenr+1, faces, 0);
2318
for (int i = 0; i < nfa; i++)
2319
{
2320
nodes[cnt++] = 2;
2321
nodes[cnt++] = faces[i]-1;
2322
}
2323
}
2324
2325
if (nodeset & 8) // Cell
2326
{
2327
nodes[cnt++] = 3;
2328
nodes[cnt++] = nodenr;
2329
}
2330
2331
return cnt/2;
2332
}
2333
default:
2334
{
2335
cerr << "GetClosureNodes not implemented for Nodetype " << nt << endl;
2336
}
2337
}
2338
return 0;
2339
}
2340
2341
2342
2343
int Ng_GetNElements (int dim)
2344
{
2345
switch (dim)
2346
{
2347
case 0: return mesh -> GetNV();
2348
case 1: return mesh -> GetNSeg();
2349
case 2: return mesh -> GetNSE();
2350
case 3: return mesh -> GetNE();
2351
}
2352
return -1;
2353
}
2354
2355
2356
2357
/*
2358
closure nodes of element
2359
nodeset is bit-coded, bit 0 includes Vertices, bit 1 edges, etc
2360
E.g., nodeset = 6 includes edge and face nodes
2361
nodes is pair of integers (nodetype, nodenr)
2362
return value is number of nodes
2363
*/
2364
int Ng_GetElementClosureNodes (int dim, int elementnr, int nodeset, int * nodes)
2365
{
2366
switch (dim)
2367
{
2368
case 3: // The closure of a volume element = CELL
2369
{
2370
return Ng_GetClosureNodes (3, elementnr, nodeset, nodes);
2371
}
2372
case 2:
2373
{
2374
int cnt = 0;
2375
if (nodeset & 1) // Vertices
2376
{
2377
const Element2d & el = (*mesh)[SurfaceElementIndex(elementnr)];
2378
for (int i = 0; i < el.GetNP(); i++)
2379
{
2380
nodes[cnt++] = 0;
2381
nodes[cnt++] = el[i] - PointIndex::BASE;
2382
}
2383
}
2384
2385
if (nodeset & 2) // Edges
2386
{
2387
int edges[12];
2388
int ned;
2389
ned = mesh->GetTopology().GetSurfaceElementEdges (elementnr+1, edges, 0);
2390
for (int i = 0; i < ned; i++)
2391
{
2392
nodes[cnt++] = 1;
2393
nodes[cnt++] = edges[i]-1;
2394
}
2395
}
2396
2397
if (nodeset & 4) // Faces
2398
{
2399
int face = mesh->GetTopology().GetSurfaceElementFace (elementnr+1);
2400
nodes[cnt++] = 2;
2401
nodes[cnt++] = face-1;
2402
}
2403
2404
return cnt/2;
2405
}
2406
default:
2407
{
2408
cerr << "GetClosureNodes not implemented for Element of dimension " << dim << endl;
2409
}
2410
}
2411
return 0;
2412
}
2413
2414