/
meshtype.hpp
1669 lines (1366 loc) · 43.4 KB
/
meshtype.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef MESHTYPE
#define MESHTYPE
/**************************************************************************/
/* File: meshtype.hpp */
/* Author: Joachim Schoeberl */
/* Date: 01. Okt. 95 */
/**************************************************************************/
#include <mydefs.hpp>
#include <general/template.hpp>
#include <gprim/geom3d.hpp>
#include <linalg.hpp>
#include "core/exception.hpp"
#include "msghandler.hpp"
namespace netgen
{
/*
Classes for NETGEN
*/
enum ELEMENT_TYPE : unsigned char {
SEGMENT = 1, SEGMENT3 = 2,
TRIG = 10, QUAD=11, TRIG6 = 12, QUAD6 = 13, QUAD8 = 14,
TET = 20, TET10 = 21,
PYRAMID = 22, PRISM = 23, PRISM12 = 24, PRISM15 = 27, PYRAMID13 = 28,
HEX = 25, HEX20 = 26, HEX7 = 29
};
/*
typedef int ELEMENT_EDGE[2]; // initial point, end point
typedef int ELEMENT_FACE[4]; // points, last one is -1 for trig
*/
struct ELEMENT_EDGE
{
int vals[2];
int & operator[] (size_t i) { return vals[i]; }
int operator[] (size_t i) const { return vals[i]; }
};
struct ELEMENT_FACE
{
int vals[4];
int & operator[] (size_t i) { return vals[i]; }
int operator[] (size_t i) const { return vals[i]; }
};
#define ELEMENT_MAXPOINTS 20
#define ELEMENT2D_MAXPOINTS 8
enum POINTTYPE : unsigned char { FIXEDPOINT = 1, EDGEPOINT = 2, SURFACEPOINT = 3, INNERPOINT = 4 };
enum ELEMENTTYPE { FREEELEMENT, FIXEDELEMENT };
enum OPTIMIZEGOAL { OPT_QUALITY, OPT_CONFORM, OPT_REST, OPT_WORSTCASE, OPT_LEGAL };
extern DLL_HEADER size_t timestamp;
inline size_t GetTimeStamp()
{
return timestamp;
}
inline size_t NextTimeStamp()
{
timestamp++;
return timestamp;
}
/*
extern DLL_HEADER int GetTimeStamp();
extern DLL_HEADER int NextTimeStamp();
*/
class PointGeomInfo
{
public:
int trignum; // for STL Meshing
double u, v; // for OCC Meshing
PointGeomInfo () = default;
// : trignum(-1), u(0), v(0) { ; }
PointGeomInfo (const PointGeomInfo&) = default;
PointGeomInfo (PointGeomInfo &&) = default;
PointGeomInfo & operator= (const PointGeomInfo&) = default;
PointGeomInfo & operator= (PointGeomInfo&&) = default;
};
inline ostream & operator<< (ostream & ost, const PointGeomInfo & gi)
{
return (ost << gi.trignum << " " << gi.u << " " << gi.v);
}
inline istream & operator>> (istream & ist, PointGeomInfo & gi)
{
return (ist >> gi.trignum >> gi.u >> gi.v);
}
class MultiPointGeomInfo
{
ArrayMem<PointGeomInfo, 100> mgi;
public:
int AddPointGeomInfo (const PointGeomInfo & gi);
void Init () { mgi.SetSize(0); }
void DeleteAll () { mgi.SetSize(0); }
int GetNPGI () const { return mgi.Size(); }
const PointGeomInfo & GetPGI (int i) const { return mgi[i-1]; }
MultiPointGeomInfo () = default;
MultiPointGeomInfo (const MultiPointGeomInfo&) = default;
MultiPointGeomInfo (MultiPointGeomInfo &&) = default;
MultiPointGeomInfo & operator= (const MultiPointGeomInfo&) = delete;
MultiPointGeomInfo & operator= (MultiPointGeomInfo&&) = default;
};
class EdgePointGeomInfo
{
public:
int edgenr;
int body; // for ACIS
double dist; // for 2d meshing
double u, v; // for OCC Meshing
public:
EdgePointGeomInfo ()
: edgenr(-1), body(0), dist(0.0), u(0.0), v(0.0) { ; }
EdgePointGeomInfo & operator= (const EdgePointGeomInfo & gi2) = default;
};
inline ostream & operator<< (ostream & ost, const EdgePointGeomInfo & gi)
{
ost << "epgi: edgnr=" << gi.edgenr << ", dist=" << gi.dist;
return ost;
}
class PointIndex
{
int i;
public:
class t_invalid { public: constexpr t_invalid() = default; };
static constexpr t_invalid INVALID{};
PointIndex () = default;
PointIndex (const PointIndex&) = default;
PointIndex (PointIndex &&) = default;
PointIndex & operator= (const PointIndex&) = default;
PointIndex & operator= (PointIndex&&) = default;
constexpr PointIndex (int ai) : i(ai)
{
#ifdef DEBUG
if (ai < PointIndex::BASE)
cout << "illegal PointIndex, use PointIndex::INVALID instead" << endl;
// throw Exception("illegal PointIndex, use PointIndex::INVALID instead");
#endif
}
constexpr PointIndex (t_invalid inv) : i(PointIndex::BASE-1) { ; }
// PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; }
constexpr operator int () const { return i; }
PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; }
PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; }
PointIndex & operator++ () { i++; return *this; }
PointIndex operator-- () { i--; return *this; }
PointIndex operator+= (int add) { i += add; return *this; }
void Invalidate() { i = PointIndex::BASE-1; }
bool IsValid() const { return i != PointIndex::BASE-1; }
#ifdef BASE0
static constexpr size_t BASE = 0;
#else
static constexpr size_t BASE = 1;
#endif
void DoArchive (Archive & ar) { ar & i; }
};
}
namespace ngcore
{
template<>
constexpr netgen::PointIndex IndexBASE<netgen::PointIndex> () { return netgen::PointIndex(netgen::PointIndex::BASE); }
}
namespace netgen
{
inline istream & operator>> (istream & ist, PointIndex & pi)
{
int i; ist >> i; pi = PointIndex(i); return ist;
}
inline ostream & operator<< (ostream & ost, const PointIndex & pi)
{
return (ost << int(pi));
}
template <int N> class PointIndices;
template <> class PointIndices<2> : public INDEX_2
{
public:
PointIndices () = default;
PointIndices (INDEX_2 i2) : INDEX_2(i2) { ; }
PointIndices (PointIndex i1, PointIndex i2) : INDEX_2(i1,i2) { ; }
PointIndex operator[] (int i) const { return PointIndex(INDEX_2::operator[](i)); }
PointIndex & operator[] (int i) { return reinterpret_cast<PointIndex&>(INDEX_2::operator[](i)); }
static PointIndices Sort(PointIndex i1, PointIndex i2) { return INDEX_2::Sort(i1, i2); }
template <size_t J>
PointIndex get() const { return PointIndex(INDEX_2::operator[](J)); }
};
}
namespace std
{
// structured binding support
template <auto N>
struct tuple_size<netgen::PointIndices<N>> : std::integral_constant<std::size_t, N> {};
template<size_t N, auto M> struct tuple_element<N,netgen::PointIndices<M>> { using type = netgen::PointIndex; };
}
namespace netgen
{
class ElementIndex
{
int i;
public:
ElementIndex () = default;
constexpr ElementIndex (int ai) : i(ai) { ; }
ElementIndex & operator= (const ElementIndex & ai) { i = ai.i; return *this; }
ElementIndex & operator= (int ai) { i = ai; return *this; }
constexpr operator int () const { return i; }
ElementIndex operator++ (int) { return ElementIndex(i++); }
ElementIndex operator-- (int) { return ElementIndex(i--); }
ElementIndex & operator++ () { ++i; return *this; }
ElementIndex & operator-- () { --i; return *this; }
};
inline istream & operator>> (istream & ist, ElementIndex & pi)
{
int i; ist >> i; pi = i; return ist;
}
inline ostream & operator<< (ostream & ost, const ElementIndex & pi)
{
return (ost << int(pi));
}
class SurfaceElementIndex
{
int i;
public:
SurfaceElementIndex () = default;
constexpr SurfaceElementIndex (int ai) : i(ai) { ; }
/*
SurfaceElementIndex & operator= (const SurfaceElementIndex & ai)
{ i = ai.i; return *this; }
*/
SurfaceElementIndex & operator= (const SurfaceElementIndex & ai) = default;
SurfaceElementIndex & operator= (int ai) { i = ai; return *this; }
constexpr operator int () const { return i; }
SurfaceElementIndex operator++ (int) { SurfaceElementIndex hi(*this); i++; return hi; }
SurfaceElementIndex operator-- (int) { SurfaceElementIndex hi(*this); i--; return hi; }
SurfaceElementIndex & operator++ () { ++i; return *this; }
SurfaceElementIndex & operator-- () { --i; return *this; }
SurfaceElementIndex & operator+= (int inc) { i+=inc; return *this; }
void DoArchive (Archive & ar) { ar & i; }
};
inline void SetInvalid (SurfaceElementIndex & id) { id = -1; }
inline bool IsInvalid (SurfaceElementIndex & id) { return id == -1; }
inline istream & operator>> (istream & ist, SurfaceElementIndex & pi)
{
int i; ist >> i; pi = i; return ist;
}
inline ostream & operator<< (ostream & ost, const SurfaceElementIndex & pi)
{
return (ost << int(pi));
}
class SegmentIndex
{
int i;
public:
SegmentIndex () = default;
constexpr SegmentIndex (int ai) : i(ai) { ; }
SegmentIndex & operator= (const SegmentIndex & ai)
{ i = ai.i; return *this; }
SegmentIndex & operator= (int ai) { i = ai; return *this; }
constexpr operator int () const { return i; }
SegmentIndex& operator++ () { ++i; return *this; }
SegmentIndex& operator-- () { --i; return *this; }
SegmentIndex operator++ (int) { return i++; }
SegmentIndex operator-- (int) { return i--; }
};
inline void SetInvalid (SegmentIndex & id) { id = -1; }
inline bool IsInvalid (SegmentIndex & id) { return id == -1; }
inline istream & operator>> (istream & ist, SegmentIndex & pi)
{
int i; ist >> i; pi = i; return ist;
}
inline ostream & operator<< (ostream & ost, const SegmentIndex & pi)
{
return (ost << int(pi));
}
/**
Point in the mesh.
Contains layer (a new feature in 4.3 for overlapping meshes.
*/
class MeshPoint : public Point<3>
{
double singular; // singular factor for hp-refinement
int layer;
POINTTYPE type;
public:
MeshPoint ()
{
;
}
MeshPoint (const Point<3> & ap, int alayer = 1, POINTTYPE apt = INNERPOINT)
: Point<3> (ap), singular(0.), layer(alayer), type(apt)
{
;
}
void SetPoint (const Point<3> & ap)
{
Point<3>::operator= (ap);
layer = 0;
singular = 0;
}
void Scale(double factor) { *testout << "before: " << x[0] << endl; x[0] *= factor; x[1] *= factor; x[2] *= factor; *testout << "after: " << x[0] << endl;}
int GetLayer() const { return layer; }
POINTTYPE Type() const { return type; }
void SetType(POINTTYPE at) { type = at; }
double Singularity() const { return singular; }
void Singularity(double s) { singular = s; }
bool IsSingular() const { return (singular != 0.0); }
#ifdef PARALLEL
static MPI_Datatype MyGetMPIType ( );
#endif
void DoArchive (Archive & ar)
{
// ar & x[0] & x[1] & x[2] & layer & singular;
// ar.Do(&x[0], 3);
// ar & layer & singular;
// ar & (unsigned char&)(type);
ar.DoPacked (x[0], x[1], x[2], layer, singular, (unsigned char&)(type));
}
};
inline ostream & operator<<(ostream & s, const MeshPoint & pt)
{
return (s << Point<3> (pt));
}
// typedef NgArray<MeshPoint, PointIndex::BASE, PointIndex> T_POINTS;
typedef Array<MeshPoint, PointIndex> T_POINTS;
/**
Triangle element for surface mesh generation.
*/
class Element2d
{
/// point numbers
PointIndex pnum[ELEMENT2D_MAXPOINTS];
/// geom info of points
PointGeomInfo geominfo[ELEMENT2D_MAXPOINTS];
/// surface nr
int index;
///
ELEMENT_TYPE typ;
/// number of points
int8_t np;
bool refflag; // marked for refinement
bool badel:1;
bool strongrefflag:1;
bool deleted:1; // element is deleted
// Philippose - 08 August 2010
// Set a new property for each element, to
// control whether it is visible or not
bool visible:1; // element visible
bool is_curved:1; // element is (high order) curved
/// order for hp-FEM
unsigned int orderx:6;
unsigned int ordery:6;
/// a linked list for all segments in the same face
SurfaceElementIndex next;
///
int hp_elnr;
public:
static auto GetDataLayout()
{
return std::map<string, int>({
{ "pnum", offsetof(Element2d, pnum)},
{ "index", offsetof(Element2d, index) },
{ "np", offsetof(Element2d, np) },
{ "refine", offsetof(Element2d, refflag) }
});
}
///
DLL_HEADER Element2d ();
Element2d (const Element2d &) = default;
Element2d (Element2d &&) = default;
Element2d & operator= (const Element2d &) = default;
Element2d & operator= (Element2d &&) = default;
Element2d & operator= (initializer_list<PointIndex> list)
{
size_t cnt = 0;
for (auto val : list)
pnum[cnt++] = val;
return *this;
}
Element2d & operator= (initializer_list<std::tuple<PointIndex,PointGeomInfo>> list)
{
size_t cnt = 0;
for (auto val : list)
{
pnum[cnt] = get<0>(val);
geominfo[cnt++] = get<1>(val);
}
return *this;
}
///
DLL_HEADER Element2d (int anp);
///
DLL_HEADER Element2d (ELEMENT_TYPE type);
///
DLL_HEADER Element2d (int pi1, int pi2, int pi3);
///
DLL_HEADER Element2d (int pi1, int pi2, int pi3, int pi4);
///
ELEMENT_TYPE GetType () const { return typ; }
///
void SetType (ELEMENT_TYPE atyp)
{
typ = atyp;
switch (typ)
{
case TRIG: np = 3; break;
case QUAD: np = 4; break;
case TRIG6: np = 6; break;
case QUAD6: np = 6; break;
case QUAD8: np = 8; break;
default:
PrintSysError ("Element2d::SetType, illegal type ", int(typ));
}
is_curved = (np >= 4);
}
///
int GetNP() const { return np; }
///
int GetNV() const
{
if (typ == TRIG || typ == TRIG6)
return 3;
else
{
#ifdef DEBUG
if (typ != QUAD && typ != QUAD6 && typ != QUAD8)
PrintSysError ("element2d::GetNV not implemented for typ", int(typ));
#endif
return 4;
}
/*
switch (typ)
{
case TRIG:
case TRIG6: return 3;
case QUAD:
case QUAD8:
case QUAD6: return 4;
default:
#ifdef DEBUG
PrintSysError ("element2d::GetNV not implemented for typ", typ)
#endif
;
}
return np;
*/
}
///
PointIndex & operator[] (int i) { return pnum[i]; }
///
const PointIndex & operator[] (int i) const { return pnum[i]; }
auto PNums () const { return FlatArray<const PointIndex> (np, &pnum[0]); }
auto PNums () { return FlatArray<PointIndex> (np, &pnum[0]); }
template <int NP>
auto PNums() const { return FlatArray<const PointIndex> (NP, &pnum[0]); }
auto Vertices() const { return FlatArray<const PointIndex> (GetNV(), &pnum[0]); }
auto GeomInfo() const { return FlatArray<const PointGeomInfo> (np, &geominfo[0]); }
auto GeomInfo() { return FlatArray<PointGeomInfo> (np, &geominfo[0]); }
///
PointIndex & PNum (int i) { return pnum[i-1]; }
///
const PointIndex & PNum (int i) const { return pnum[i-1]; }
///
PointIndex & PNumMod (int i) { return pnum[(i-1) % np]; }
///
const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
///
///
PointGeomInfo & GeomInfoPi (int i) { return geominfo[i-1]; }
///
const PointGeomInfo & GeomInfoPi (int i) const { return geominfo[i-1]; }
///
PointGeomInfo & GeomInfoPiMod (int i) { return geominfo[(i-1) % np]; }
///
const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; }
void DoArchive (Archive & ar)
{
short _np, _typ;
bool _curved, _vis, _deleted;
if (ar.Output())
{ _np = np; _typ = typ; _curved = is_curved;
_vis = visible; _deleted = deleted; }
// ar & _np & _typ & index & _curved & _vis & _deleted;
ar.DoPacked (_np, _typ, index, _curved, _vis, _deleted);
// ar & next; don't need
if (ar.Input())
{ np = _np; typ = ELEMENT_TYPE(_typ); is_curved = _curved;
visible = _vis; deleted = _deleted; }
/*
for (size_t i = 0; i < np; i++)
ar & pnum[i];
*/
static_assert(sizeof(int) == sizeof (PointIndex));
ar.Do( (int*)&pnum[0], np);
}
#ifdef PARALLEL
static MPI_Datatype MyGetMPIType();
#endif
void SetIndex (int si) { index = si; }
///
int GetIndex () const { return index; }
int GetOrder () const { return orderx; }
void SetOrder (int aorder) { orderx = ordery = aorder; }
void GetOrder (int & ox, int & oy) const { ox = orderx, oy =ordery;};
void GetOrder (int & ox, int & oy, int & oz) const { ox = orderx; oy = ordery; oz=0; }
void SetOrder (int ox, int oy, int /* oz */) { orderx = ox; ordery = oy;}
void SetOrder (int ox, int oy) { orderx = ox; ordery = oy;}
int GetHpElnr() const { return hp_elnr; }
void SetHpElnr(int _hp_elnr) { hp_elnr = _hp_elnr; }
///
void GetBox (const T_POINTS & points, Box3d & box) const;
/// invert orientation
inline void Invert ();
///
DLL_HEADER void Invert2 ();
/// first point number is smallest
inline void NormalizeNumbering ();
///
void NormalizeNumbering2 ();
bool BadElement() const { return badel; }
// friend ostream & operator<<(ostream & s, const Element2d & el);
friend class Mesh;
/// get number of 'integration points'
int GetNIP () const;
void GetIntegrationPoint (int ip, Point<2> & p, double & weight) const;
void GetTransformation (int ip, const NgArray<Point<2>> & points,
class DenseMatrix & trans) const;
void GetTransformation (int ip, class DenseMatrix & pmat,
class DenseMatrix & trans) const;
void GetShape (const Point<2> & p, class Vector & shape) const;
DLL_HEADER void GetShapeNew (const Point<2> & p, class FlatVector & shape) const;
template <typename T>
DLL_HEADER void GetShapeNew (const Point<2,T> & p, TFlatVector<T> shape) const;
/// matrix 2 * np
DLL_HEADER void GetDShape (const Point<2> & p, class DenseMatrix & dshape) const;
template <typename T>
DLL_HEADER void GetDShapeNew (const Point<2,T> & p, class MatrixFixWidth<2,T> & dshape) const;
/// matrix 2 * np
void GetPointMatrix (const NgArray<Point<2>> & points,
class DenseMatrix & pmat) const;
void ComputeIntegrationPointData () const;
double CalcJacobianBadness (const NgArray<Point<2>> & points) const;
double CalcJacobianBadness (const T_POINTS & points,
const Vec<3> & n) const;
double CalcJacobianBadnessDirDeriv (const NgArray<Point<2>> & points,
int pi, Vec<2> & dir, double & dd) const;
void Delete ()
{
deleted = 1;
// for (PointIndex & p : pnum) p.Invalidate();
}
bool IsDeleted () const
{
#ifdef DEBUG
if (pnum[0] < PointIndex::BASE && !deleted)
cerr << "Surfelement has illegal pnum, but not marked as deleted" << endl;
#endif
return deleted;
}
// Philippose - 08 August 2010
// Access functions for the new property: visible
void Visible(bool vis = true)
{ visible = vis; }
bool IsVisible () const
{ return visible; }
void SetRefinementFlag (bool rflag = true)
{ refflag = rflag; }
bool TestRefinementFlag () const
{ return refflag; }
void SetStrongRefinementFlag (bool rflag = true)
{ strongrefflag = rflag; }
bool TestStrongRefinementFlag () const
{ return strongrefflag; }
bool IsCurved () const { return is_curved; }
void SetCurved (bool acurved) { is_curved = acurved; }
SurfaceElementIndex NextElement() { return next; }
bool operator==(const Element2d & el2) const;
int HasFace(const Element2d& el) const;
};
ostream & operator<<(ostream & s, const Element2d & el);
class IntegrationPointData
{
public:
Point<3> p;
double weight;
Vector shape;
DenseMatrix dshape;
};
/**
Volume element
*/
class Element
{
private:
/// point numbers
PointIndex pnum[ELEMENT_MAXPOINTS];
///
ELEMENT_TYPE typ;
/// number of points (4..tet, 5..pyramid, 6..prism, 8..hex, 10..quad tet, 12..quad prism)
int8_t np;
/// sub-domain index
int index;
/// order for hp-FEM
unsigned int orderx:6;
unsigned int ordery:6;
unsigned int orderz:6;
/* unsigned int levelx:6;
unsigned int levely:6;
unsigned int levelz:6; */
/// stored shape-badness of element
float badness;
bool is_curved:1; // element is (high order) curved
class flagstruct {
public:
bool refflag; // mark element for refinement
bool marked:1; // marked for refinement
bool badel:1; // angles worse then limit
bool reverse:1; // for refinement a la Bey
bool illegal:1; // illegal, will be split or swapped
bool illegal_valid:1; // is illegal-flag valid ?
bool badness_valid:1; // is badness valid ?
bool strongrefflag:1;
bool deleted:1; // element is deleted, will be removed from array
bool fixed:1; // don't change element in optimization
};
flagstruct flags;
int hp_elnr;
public:
static auto GetDataLayout()
{
return std::map<string, int>({
{ "pnum", offsetof(Element, pnum)},
{ "index", offsetof(Element, index) },
{ "np", offsetof(Element, np) },
{ "refine", offsetof(Element, flags.refflag) }
});
}
///
DLL_HEADER Element () = default;
Element (const Element &) = default;
Element (Element &&) = default;
Element & operator= (const Element &) = default;
Element & operator= (Element &&) = default;
///
DLL_HEADER Element (int anp);
///
DLL_HEADER Element (ELEMENT_TYPE type);
///
// Element & operator= (const Element & el2);
const flagstruct& Flags() const { return flags; }
flagstruct& Flags() { return flags; }
///
DLL_HEADER void SetNP (int anp);
///
DLL_HEADER void SetType (ELEMENT_TYPE atyp);
///
int GetNP () const { return np; }
///
uint8_t GetNV() const
{
// __assume(typ >= TET && typ <= PYRAMID13);
switch (typ)
{
case TET:
case TET10:
return 4;
case PRISM12:
case PRISM15:
case PRISM:
return 6;
case PYRAMID:
case PYRAMID13:
return 5;
case HEX7:
return 7;
case HEX:
case HEX20:
return 8;
default: // not a 3D element
#ifdef DEBUG
PrintSysError ("Element3d::GetNV not implemented for typ ", int(typ));
#endif
__assume(false);
return -1;
}
}
DLL_HEADER bool operator==(const Element & el2) const;
// old style:
int NP () const { return np; }
///
ELEMENT_TYPE GetType () const { return typ; }
///
PointIndex & operator[] (int i) { return pnum[i]; }
///
const PointIndex & operator[] (int i) const { return pnum[i]; }
auto PNums () const { return FlatArray<const PointIndex> (np, &pnum[0]); }
auto PNums () { return FlatArray<PointIndex> (np, &pnum[0]); }
template <int NP>
auto PNums() const { return FlatArray<const PointIndex> (NP, &pnum[0]); }
FlatArray<const PointIndex> Vertices() const { return { GetNV(), &pnum[0] }; }
///
PointIndex & PNum (int i) { return pnum[i-1]; }
///
const PointIndex & PNum (int i) const { return pnum[i-1]; }
///
PointIndex & PNumMod (int i) { return pnum[(i-1) % np]; }
///
const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
void DoArchive (Archive & ar)
{
short _np, _typ;
bool _curved;
if (ar.Output())
{ _np = np; _typ = typ; _curved = is_curved; }
// ar & _np & _typ & index & _curved;
ar.DoPacked (_np, _typ, index, _curved);
if (ar.Input())
{
np = _np;
typ = ELEMENT_TYPE(_typ);
is_curved = _curved;
flags.marked = 1;
flags.badel = 0;
flags.reverse = 0;
flags.illegal = 0;
flags.illegal_valid = 0;
flags.badness_valid = 0;
flags.refflag = 1;
flags.strongrefflag = false;
flags.deleted = 0;
flags.fixed = 0;
}
static_assert(sizeof(int) == sizeof (PointIndex));
ar.Do( (int*)&pnum[0], np);
}
#ifdef PARALLEL
static MPI_Datatype MyGetMPIType();
#endif
///
void SetIndex (int si) { index = si; }
///
int GetIndex () const { return index; }
int GetOrder () const { return orderx; }
void SetOrder (const int aorder) ;
void GetOrder (int & ox, int & oy, int & oz) const { ox = orderx; oy = ordery; oz = orderz; }
void SetOrder (const int ox, const int oy, const int oz);
// void GetLevel (int & ox, int & oy, int & oz) const { ox = levelx; oy = levely; oz = levelz; }
// void SetLevel (int ox, int oy, int oz) { levelx = ox; levely = oy; levelz = oz; }
///
void GetBox (const T_POINTS & points, Box3d & box) const;
/// Calculates Volume of element
double Volume (const T_POINTS & points) const;
///
DLL_HEADER void Print (ostream & ost) const;
///
int GetNFaces () const
{
switch (typ)
{
case TET:
case TET10: return 4;
case PYRAMID: case PYRAMID13: return 5;
case PRISM:
case PRISM15:
case PRISM12: return 5;
case HEX7: return 6;
case HEX: case HEX20:
return 6;
default:
#ifdef DEBUG
PrintSysError ("element3d::GetNFaces not implemented for typ", int(typ))
#endif
;
}
return 0;
}
///
inline void GetFace (int i, Element2d & face) const;
///
DLL_HEADER void GetFace2 (int i, Element2d & face) const;
///
DLL_HEADER void Invert ();
int GetHpElnr() const { return hp_elnr; }
void SetHpElnr(int _hp_elnr) { hp_elnr = _hp_elnr; }
/// split into 4 node tets
void GetTets (NgArray<Element> & locels) const;
/// split into 4 node tets, local point nrs
void GetTetsLocal (NgArray<Element> & locels) const;
/// returns coordinates of nodes
// void GetNodesLocal (NgArray<Point<3> > & points) const;
void GetNodesLocalNew (NgArray<Point<3> > & points) const;
/// split surface into 3 node trigs
DLL_HEADER void GetSurfaceTriangles (NgArray<Element2d> & surftrigs) const;
/// get number of 'integration points'
int GetNIP () const;
void GetIntegrationPoint (int ip, Point<3> & p, double & weight) const;
void GetTransformation (int ip, const T_POINTS & points,
class DenseMatrix & trans) const;
void GetTransformation (int ip, class DenseMatrix & pmat,
class DenseMatrix & trans) const;
void GetShape (const Point<3> & p, class Vector & shape) const;
// void GetShapeNew (const Point<3> & p, class FlatVector & shape) const;
template <typename T>
DLL_HEADER void GetShapeNew (const Point<3,T> & p, TFlatVector<T> shape) const;
/// matrix 2 * np
void GetDShape (const Point<3> & p, class DenseMatrix & dshape) const;
template <typename T>
void GetDShapeNew (const Point<3,T> & p, class MatrixFixWidth<3,T> & dshape) const;
/// matrix 3 * np
void GetPointMatrix (const T_POINTS & points,
class DenseMatrix & pmat) const;
void ComputeIntegrationPointData () const;
double CalcJacobianBadness (const T_POINTS & points) const;
double CalcJacobianBadnessDirDeriv (const T_POINTS & points,
int pi, Vec<3> & dir, double & dd) const;
double CalcJacobianBadnessGradient (const T_POINTS & points,
int pi, Vec<3> & grad) const;
///
// friend ostream & operator<<(ostream & s, const Element & el);
void SetRefinementFlag (bool rflag = 1)
{ flags.refflag = rflag; }
int TestRefinementFlag () const
{ return flags.refflag; }
void SetStrongRefinementFlag (bool rflag = 1)
{ flags.strongrefflag = rflag; }
int TestStrongRefinementFlag () const
{ return flags.strongrefflag; }
int Illegal () const
{
NETGEN_CHECK_SAME(flags.illegal_valid, true);
return flags.illegal;