-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConforming3D.h
1334 lines (1113 loc) · 44 KB
/
Conforming3D.h
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
/**
BSD 2-Clause License
Copyright (c) 2020, Andrey Kudryavtsev ([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <limits>
#include <algorithm>
#include <functional>
#include <numeric>
#include <array>
#include <string>
#include <vector>
#include <assert.h>
#include "Types.h"
#include "Matrix.h"
#include "GaussInt.h"
/**
Conforming linear finite element
--------------------------------
K.-W. Cheng, T.-P. Fries. XFEM with Hanging Nodes for Two-phase
Incompressible Flow.
(7)----------18-----------(6)
/| /|
/ | / |
19 | 25 17 |
/ | / |
/ 15 23 / 14
(4)-----------16----------(5) |
| | | |
| 24 | | 22 |
| | | |
| (3)----------10------|----(2)
12 / 21 13 /
| / | /
| 11 20 | 9
W ^ /V | /
|/ |/
(0)->---------8-----------(1)
U
Any node from 8 to 25 (18 nodes in all) may not exist. That is, 8 standard and
18 hanging. The element provides C0-continuous approximation across faces of
neighbour elements.
Parameters U,V,W change from 0 to 1 from the node 0.
T - class for real numbers
Tvector - class for 3D vector with up to 4 components
Derivatives
-----------
Due to e.g. T c0a = T1 - std::abs(c0); in shapeFunctionsConforming() - abs value
function expressions, derivatives at and near hanging nodes with a parameter 0.5
are not well defined as abs() is discontinuous, therefore the two functions
shapeDerivativesConformingSimple() based on finite differences and shapeDerivativesExact() -
exact expression MAY GIVE VERY DIFFERENT results as the derivative does not exist at x = 0
for function y = |x|.
In addition, first derivatives for a linear approximation must be constant, so the use
of shapeDerivativesConformingFromSubOctant() which calculates derivatives at centres
of sub-octants looks most consistent.
*/
/**
8 sub-elements :
7-------------------6
/| (6) (7) /|
/ | / |
/ | / |
4-------------------5 |
| (4) (5) | |
| | | |
| | | |
| 3---------------|---2
| / (2) (3) /
| / | /
|/ (0) (1) |/
0-------------------1
*/
static const std::array<std::array<int,8>,8> subElements_ =
{{
{0,8,20,11,12,21,26,24},
{8,1,9,20,21,13,22,26},
{11,20,10,3,24,26,23,15},
{20,9,2,10,26,22,14,23},
{12,21,26,24,4,16,25,19},
{21,13,22,26,16,5,17,25},
{24,26,23,15,19,25,18,7},
{26,22,14,23,25,17,6,18}
}};
/**
Element faces :
7-------------------6
/| /|
/ | (5) / |
/ | / |
4-----------(3)-----5 |
| | | |
|(0)| |(1)|
| | | |
| 3----(2)--------|---2
| / | /
| / (4) | /
|/ |/
0-------------------1
Hex faces nodal numbers, mind the order :
-e direction (-x)
+e direction (+x)
-n direction (-y)
+n direction (+y)
-s direction (-z)
+s direction (+z)
First 4 nodes are regular, the other 5 are hanging, last one being face central
*/
static const std::array<std::array<int,9>,6> elementFaces_ =
{{
{3,0,4,7, 11,12,19,15, 24},
{1,2,6,5, 9,14,17,13, 22},
{0,1,5,4, 8,13,16,12, 21},
{2,3,7,6, 10,15,18,14, 23},
{0,3,2,1, 11,10,9,8, 20},
{7,4,5,6, 19,16,17,18, 25}
}};
/**
Every face is divided into 4 subfaces [6][4][4]
*/
static const std::array<std::array<std::array<int,4>,4>,6> subFaceNodes_ =
{{
{{{20,8,0,11}, {20,11,3,10}, {20,10,2,9}, {20,9,1,8}}},
{{{21,12,0,8}, {21,8,1,13}, {21,13,5,16}, {21,16,4,12}}},
{{{22,13,1,9}, {22,9,2,14}, {22,14,6,17}, {22,17,5,13}}},
{{{23,14,2,10}, {23,10,3,15}, {23,15,7,18}, {23,18,6,14}}},
{{{24,15,3,11}, {24,11,0,12}, {24,12,4,19}, {24,19,7,15}}},
{{{25,16,5,17}, {25,17,6,18}, {25,18,7,19}, {25,19,4,16}}}
}};
/**
Element edges, the third number is hanging node [12][3] :
7--------(6)--------6
/| /|
(7)| (5)|
/ | / |
4---------(4)-------5 (10)
| (11) | |
| | | |
| | | |
(8) 3-------(2)----(9)--2
| / | /
|(3) |(1)
|/ |/
0--------(0)--------1
*/
static const std::array<std::array<int,3>,12> elementEdges_ =
{{
{0,1,8},
{1,2,9},
{2,3,10},
{3,0,11},
{4,5,16},
{5,6,17},
{6,7,18},
{7,4,19},
{0,4,12},
{1,5,13},
{2,6,14},
{3,7,15}
}};
/**
Two faces for every edge
*/
static const std::array<std::array<int,2>,12> edgeFaces_ =
{{
{2,4},
{1,4},
{3,4},
{0,4},
{2,5},
{1,5},
{3,5},
{0,5},
{0,2},
{2,1},
{1,3},
{3,0}
}};
template <typename T, typename Tvector> class Conforming3D {
public:
/** Total number of nodes */
static const size_t NUM_NODES = 26;
/** Number of basic nodes which always exist */
static const size_t NUM_BASICNODES = 8;
/** Number of hanging nodes */
static const size_t NUM_HANGINGNODES = NUM_NODES - NUM_BASICNODES;
/** Constructor */
Conforming3D() = delete;
/** Constructors */
//Conforming3D(const std::array<LINT,NUM_BASICNODES> &nodes);
Conforming3D(const std::array<LINT,NUM_NODES> &nodes);
Conforming3D(const std::array<LINT,NUM_BASICNODES> &nodes, const std::array<LINT,NUM_HANGINGNODES> &hanging);
/** Copy constructor */
Conforming3D(const Conforming3D& copy);
/** Assignment operator */
Conforming3D& operator=(const Conforming3D& copy);
/** Nodes */
std::array<LINT,NUM_NODES>& nodes()
{
return nodes_;
}
/** Is this element with hanging nodes? */
bool hasHangingNodes();
/** Get min and max node numbers */
void nodeMinMax(LINT& min, LINT& max);
/** Compute linear shape functions, local coordinates (parms) being [0..1] */
static void shapeFunctions(const Tvector &parms, std::array<T,NUM_NODES> &func);
/** Compute linear conforming shape functions, local coordinates (parms) [0..1] */
void shapeFunctionsConforming(const Tvector &parms, std::array<T,NUM_NODES> &func);
/** Compute derivatives of linear conforming shape functions, local coordinates (parms) [0..1],
non-conforming 8 nodes only used.
*/
void shapeDerivativesNonConforming(const Tvector &parms, std::array<Tvector,NUM_NODES> &func);
/** Compute derivatives of linear conforming shape functions, local coordinates (parms) [0..1],
calculation is made by calling shapeFunctionsConforming() to compute finite differences;
result is approximate.
Very important!
Due to e.g. T c0a = T1 - std::abs(c0); in shapeFunctionsConforming() - abs value
function expressions, derivatives at and near hanging nodes with a parameter 0.5
are not well defined as abs() is discontinuous, therefore the two functions
shapeDerivativesConformingSimple() based on finite differences and shapeDerivativesExact() -
exact expression MAY GIVE VERY DIFFERENT results as the derivative does not exist at x = 0
for function y = |x|.
In addition, first derivatives for a linear approximation must be constant, so the use
of shapeDerivativesConformingFromSubOctant() which calculates derivatives at centres
of sub-octants looks most consistent.
*/
void shapeDerivativesConformingSimple(const Tvector &parms, std::array<Tvector,NUM_NODES> &func);
/** Compute derivatives of linear conforming shape functions, local coordinates (parms) [0..1],
calculation is exact.
Very important!
Due to e.g. T c0a = T1 - std::abs(c0); in shapeFunctionsConforming() - abs value
function expressions, derivatives at and near hanging nodes with a parameter 0.5
are not well defined as abs() is discontinuous, therefore the two functions
shapeDerivativesConformingSimple() based on finite differences and shapeDerivativesExact() -
exact expression MAY GIVE VERY DIFFERENT results as the derivative does not exist at x = 0
for function y = |x|.
In addition, first derivatives for a linear approximation must be constant, so the use
of shapeDerivativesConformingFromSubOctant() which calculates derivatives at centres
of sub-octants looks most consistent.
*/
void shapeDerivativesConformingExact(const Tvector &parms, std::array<Tvector,NUM_NODES> &func);
/** Compute derivatives of linear conforming shape functions, local coordinates
(parms) [0..1], parms position is moved to a centre of closest sub-octant and
calculation is axact at this point */
void shapeDerivativesConformingFromSubOctant(const Tvector &parms, std::array<Tvector,NUM_NODES> &func);
/** Get parameters of all nodes */
static const std::array<Tvector,NUM_NODES + 1>& nodeParms()
{
return nodeParms_;
}
/** Nodes for 8 subelements (icluding central number 26) */
static const std::array<std::array<int,8>,8>& subElements();
/** Element 6 faces, see the picture for elemenFaces_ */
static const std::array<std::array<int,9>,6>& faces();
/** Every face is divided into 4 subfaces [6][4][4] */
static const std::array<std::array<std::array<int,4>,4>,6>& subFaceNodes();
/** Element edges, the third number is hanging node [12][3] */
static const std::array<std::array<int,3>,12>& edges();
/** Two faces for every edge [12][2] */
static const std::array<std::array<int,2>,12>& edgeFaces();
/** Node exists? */
bool nodeExists(const size_t i);
/** Return last error string */
static std::string errorString()
{
return errorString_;
}
// Finite element matrices
/** Get 26 x 3 node coordinate matrix, they are zero for non-existing nodes */
Matrix<T,NUM_NODES,3> coordMatrix(const std::vector<Tvector> &totalCoordinates)
{
Matrix<T,NUM_NODES,3> coords;
for (int i = 0; i < NUM_NODES; i++)
{
if (nodes_[i] >= 0)
{
coords[i][0] = totalCoordinates[nodes_[i]].XYZ[0];
coords[i][1] = totalCoordinates[nodes_[i]].XYZ[1];
coords[i][2] = totalCoordinates[nodes_[i]].XYZ[2];
} else
{
coords[i][0] = coords[i][1] = coords[i][2] = T(0.0);
}
}
return coords;
}
/** Get 26 x 1 shape function matrix, zeroes for non-existing nodes */
static Matrix<T,NUM_NODES,1> shapeFunctionMatrix(const std::array<T,NUM_NODES> &func)
{
Matrix<T,NUM_NODES,1> funcmatrix;
funcmatrix.fill(T0);
for (int i = 0; i < NUM_NODES; i++)
{
funcmatrix[i][0] = func[i];
}
return funcmatrix;
}
/** Get 26 x 3 shape function derivative matrix, they are zero for non-existing nodes */
static Matrix<T,NUM_NODES,3> shapeFunctionDerivativesMatrix(const std::array<Tvector,NUM_NODES> &func)
{
Matrix<T,NUM_NODES,3> dermatrix;
dermatrix.fill(T0);
for (int i = 0; i < NUM_NODES; i++)
{
dermatrix[i][0] = func[i].XYZ[0];
dermatrix[i][1] = func[i].XYZ[1];
dermatrix[i][2] = func[i].XYZ[2];
}
return dermatrix;
}
/**
Calculate matrix B to get deriveatives on X,Y,Z (real coordinates) by
{Ux,Uy,Uz} = B[3,NUM_NODES] * { U nodal values [NUM_NODES] }
See J.J.Connor, C.A.Brebbia Finite Element Techniques for Fluid Flow, page 125, equation (i)
*/
bool Bmatrix(const std::vector<Tvector> &totalCoordinates,
const std::array<Tvector,NUM_NODES> &derivatives, Matrix<T,3,NUM_NODES> &B, T &jacobian);
/** Calculate element stiffness matrix [K] */
bool stiffnessMatrix(const std::vector<Tvector>& totalCoordinates,
Matrix<T,Conforming3D<T,Tvector>::NUM_NODES,Conforming3D<T,Tvector>::NUM_NODES>& matrix, const int power);
/** Calculate element mass matrix [M] */
bool massMatrix(const std::vector<Tvector>& totalCoordinates,
Matrix<T,Conforming3D<T,Tvector>::NUM_NODES,Conforming3D<T,Tvector>::NUM_NODES>& matrix, const int power);
// ===== Solution vector =====
/** Get nodal values for this element */
Matrix<T,1,Conforming3D<T,Tvector>::NUM_NODES> values(const std::vector<T>& totalValues);
/** Calculate coordinate at a point defined by parameter */
Tvector coordinate(const Tvector& parms, const std::vector<Tvector>& totalCoordinates);
/** Calculate a value at a point defined by parameter */
T value(const Tvector& parms, const std::vector<T>& totalValues);
/** Calculate value gradient at a point defined by parameter */
Tvector gradient(const Tvector& parms, const std::vector<Tvector> &totalCoordinates,
const std::vector<T>& totalValues);
private:
/** Node numbers; for hanging nodes 8..25 a node does not exist if -1. */
std::array<LINT,NUM_NODES> nodes_;
/** Parametric values for all nodes plus central node */
static const std::array<Tvector,27> nodeParms_;
/** Last error string */
static std::string errorString_;
/** Compute derivatives of linear shape functions, local coordinates (parms) being [0..1] */
void shapeDerivatives(const Tvector &parms, std::array<Tvector,NUM_NODES> &func);
};
template <typename T, typename Tvector>
std::string Conforming3D<T,Tvector>::errorString_;
template <typename T, typename Tvector> Conforming3D<T,Tvector>::
Conforming3D(const std::array<LINT,NUM_NODES> &nodes)
{
nodes_ = nodes;
}
template <typename T, typename Tvector> Conforming3D<T,Tvector>::
Conforming3D(const std::array<LINT,NUM_BASICNODES> &nodes, const std::array<LINT,NUM_HANGINGNODES> &hanging)
{
std::copy(nodes.begin(),nodes.end(),nodes_.begin());
std::copy(hanging.begin(),hanging.end(),nodes_.begin() + NUM_BASICNODES);
}
template <typename T, typename Tvector> Conforming3D<T,Tvector>::
Conforming3D(const Conforming3D& copy)
{
nodes_ = copy.nodes_;
}
template <typename T, typename Tvector> Conforming3D<T,Tvector>& Conforming3D<T,Tvector>::
operator = (const Conforming3D& copy)
{
nodes_ = copy.nodes_;
return *this;
}
template <typename T, typename Tvector> bool Conforming3D<T,Tvector>::hasHangingNodes()
{
return (std::find_if(nodes_.begin() + NUM_BASICNODES,nodes_.end(),[](auto v) { return (v >= 0); })
!= nodes_.end());
}
template <typename T, typename Tvector> bool Conforming3D<T,Tvector>::nodeExists(const size_t i)
{
return (nodes_[i] >= 0);
}
template <typename T, typename Tvector> static const std::array<std::array<int,8>,8>&
Conforming3D<T,Tvector>::subElements()
{
return subElements_;
}
template <typename T, typename Tvector> const std::array<std::array<int,9>,6>&
Conforming3D<T,Tvector>::faces()
{
return elementFaces_;
}
template <typename T, typename Tvector> const std::array<std::array<std::array<int,4>,4>,6>&
Conforming3D<T,Tvector>::subFaceNodes()
{
return subFaceNodes_;
}
template <typename T, typename Tvector> const std::array<std::array<int,3>,12>&
Conforming3D<T,Tvector>::edges()
{
return elementEdges_;
}
template <typename T, typename Tvector> const std::array<std::array<int,2>,12>&
Conforming3D<T,Tvector>::edgeFaces()
{
return edgeFaces_;
}
template <typename T, typename Tvector> void Conforming3D<T,Tvector>::shapeFunctions(
const Tvector &parms, std::array<T,NUM_NODES> &func)
{
#ifndef NDEBUG
T tol = TOLERANCE(T);
assert(parms.XYZ[0] >= T0 - tol && parms.XYZ[0] <= T1 + tol);
assert(parms.XYZ[1] >= T0 - tol && parms.XYZ[1] <= T1 + tol);
assert(parms.XYZ[2] >= T0 - tol && parms.XYZ[2] <= T1 + tol);
#endif
std::fill(func.begin(),func.end(),T0);
T c0 = parms.XYZ[0] * T2 - T1;
T c1 = parms.XYZ[1] * T2 - T1;
T c2 = parms.XYZ[2] * T2 - T1;
T c0m = T1 - c0;
T c0p = T1 + c0;
T c1m = T1 - c1;
T c1p = T1 + c1;
T c2m = T1 - c2;
T c2p = T1 + c2;
func[0] = T0125 * c0m * c1m * c2m;
func[1] = T0125 * c0p * c1m * c2m;
func[2] = T0125 * c0p * c1p * c2m;
func[3] = T0125 * c0m * c1p * c2m;
func[4] = T0125 * c0m * c1m * c2p;
func[5] = T0125 * c0p * c1m * c2p;
func[6] = T0125 * c0p * c1p * c2p;
func[7] = T0125 * c0m * c1p * c2p;
}
template <class T, class Tvector> void Conforming3D<T,Tvector>::shapeDerivatives(
const Tvector &parms, std::array<Tvector,NUM_NODES> &func)
{
#ifndef NDEBUG
T tol = TOLERANCE(T);
assert(parms.XYZ[0] >= T0 - tol && parms.XYZ[0] <= T1 + tol);
assert(parms.XYZ[1] >= T0 - tol && parms.XYZ[1] <= T1 + tol);
assert(parms.XYZ[2] >= T0 - tol && parms.XYZ[2] <= T1 + tol);
#endif
std::fill(func.begin(),func.end(),Tvector(0,0,0));
T c0 = parms.XYZ[0] * T2 - T1;
T c1 = parms.XYZ[1] * T2 - T1;
T c2 = parms.XYZ[2] * T2 - T1;
T c0m = T1 - c0;
T c0p = T1 + c0;
T c1m = T1 - c1;
T c1p = T1 + c1;
T c2m = T1 - c2;
T c2p = T1 + c2;
func[0] = Tvector(
T0125 * (-T1) * c1m * c2m,
T0125 * c0m * (-T1) * c2m,
T0125 * c0m * c1m * (-T1)
);
func[1] = Tvector(
T0125 * (+T1) * c1m * c2m,
T0125 * c0p * (-T1) * c2m,
T0125 * c0p * c1m * (-T1)
);
func[2] = Tvector(
T0125 * (+T1) * c1p * c2m,
T0125 * c0p * (+T1) * c2m,
T0125 * c0p * c1p * (-T1)
);
func[3] = Tvector(
T0125 * (-T1) * c1p * c2m,
T0125 * c0m * (+T1) * c2m,
T0125 * c0m * c1p * (-T1)
);
func[4] = Tvector(
T0125 * (-T1) * c1m * c2p,
T0125 * c0m * (-T1) * c2p,
T0125 * c0m * c1m * (+T1)
);
func[5] = Tvector(
T0125 * (+T1) * c1m * c2p,
T0125 * c0p * (-T1) * c2p,
T0125 * c0p * c1m * (+T1)
);
func[6] = Tvector(
T0125 * (+T1) * c1p * c2p,
T0125 * c0p * (+T1) * c2p,
T0125 * c0p * c1p * (+T1)
);
func[7] = Tvector(
T0125 * (-T1) * c1p * c2p,
T0125 * c0m * (+T1) * c2p,
T0125 * c0m * c1p * (+T1)
);
}
template <class T, class Tvector> void Conforming3D<T,Tvector>::shapeFunctionsConforming(
const Tvector &parms, std::array<T,NUM_NODES> &func)
{
// main 8-node shape functions
shapeFunctions(parms,func);
if (hasHangingNodes())
{
T c0 = parms.XYZ[0] * T2 - T1;
T c1 = parms.XYZ[1] * T2 - T1;
T c2 = parms.XYZ[2] * T2 - T1;
T c0a = T1 - std::abs(c0);
T c1a = T1 - std::abs(c1);
T c2a = T1 - std::abs(c2);
T c0m = T1 - c0;
T c0p = T1 + c0;
T c1m = T1 - c1;
T c1p = T1 + c1;
T c2m = T1 - c2;
T c2p = T1 + c2;
// these node numbers are offset by 8 : func[0] is actually func[8]
// faces
T func20 = (nodes_[NUM_BASICNODES + 12] < 0) ? T0 : (T05 * c0a * c1a * c2m);
T func25 = (nodes_[NUM_BASICNODES + 17] < 0) ? T0 : (T05 * c0a * c1a * c2p);
T func21 = (nodes_[NUM_BASICNODES + 13] < 0) ? T0 : (T05 * c0a * c1m * c2a);
T func23 = (nodes_[NUM_BASICNODES + 15] < 0) ? T0 : (T05 * c0a * c1p * c2a);
T func24 = (nodes_[NUM_BASICNODES + 16] < 0) ? T0 : (T05 * c0m * c1a * c2a);
T func22 = (nodes_[NUM_BASICNODES + 14] < 0) ? T0 : (T05 * c0p * c1a * c2a);
// edges (preliminary shape functions)
T func8p = (nodes_[NUM_BASICNODES + 0] < 0) ? T0 : (T025 * c0a * c1m * c2m);
T func10p = (nodes_[NUM_BASICNODES + 2] < 0) ? T0 : (T025 * c0a * c1p * c2m);
T func16p = (nodes_[NUM_BASICNODES + 8] < 0) ? T0 : (T025 * c0a * c1m * c2p);
T func18p = (nodes_[NUM_BASICNODES + 10] < 0) ? T0 : (T025 * c0a * c1p * c2p);
T func9p = (nodes_[NUM_BASICNODES + 1] < 0) ? T0 : (T025 * c0p * c1a * c2m);
T func11p = (nodes_[NUM_BASICNODES + 3] < 0) ? T0 : (T025 * c0m * c1a * c2m);
T func17p = (nodes_[NUM_BASICNODES + 9] < 0) ? T0 : (T025 * c0p * c1a * c2p);
T func19p = (nodes_[NUM_BASICNODES + 11] < 0) ? T0 : (T025 * c0m * c1a * c2p);
T func14p = (nodes_[NUM_BASICNODES + 6] < 0) ? T0 : (T025 * c0p * c1p * c2a);
T func15p = (nodes_[NUM_BASICNODES + 7] < 0) ? T0 : (T025 * c0m * c1p * c2a);
T func13p = (nodes_[NUM_BASICNODES + 5] < 0) ? T0 : (T025 * c0p * c1m * c2a);
T func12p = (nodes_[NUM_BASICNODES + 4] < 0) ? T0 : (T025 * c0m * c1m * c2a);
T func8 = func8p - T05 * (func20 + func21);
T func9 = func9p - T05 * (func20 + func22);
T func10 = func10p - T05 * (func20 + func23);
T func11 = func11p - T05 * (func20 + func24);
T func12 = func12p - T05 * (func21 + func24);
T func13 = func13p - T05 * (func21 + func22);
T func14 = func14p - T05 * (func22 + func23);
T func15 = func15p - T05 * (func23 + func24);
T func16 = func16p - T05 * (func25 + func21);
T func17 = func17p - T05 * (func25 + func22);
T func18 = func18p - T05 * (func25 + func23);
T func19 = func19p - T05 * (func25 + func24);
func[0] += (-T05 * (func8p + func11p + func12p) + T025 * (func20 + func21 + func24));
func[1] += (-T05 * (func9p + func8p + func13p) + T025 * (func20 + func22 + func21));
func[2] += (-T05 * (func10p + func9p + func14p) + T025 * (func20 + func23 + func22));
func[3] += (-T05 * (func11p + func10p + func15p) + T025 * (func20 + func24 + func23));
func[4] += (-T05 * (func12p + func16p + func19p) + T025 * (func25 + func24 + func21));
func[5] += (-T05 * (func13p + func17p + func16p) + T025 * (func25 + func21 + func22));
func[6] += (-T05 * (func14p + func18p + func17p) + T025 * (func25 + func22 + func23));
func[7] += (-T05 * (func15p + func19p + func18p) + T025 * (func25 + func23 + func24));
// additional 18 conforming shape functions for hanging nodes
// (indices are offset by 8 -> [0] means [8])
func[NUM_BASICNODES + 0] = func8;
func[NUM_BASICNODES + 1] = func9;
func[NUM_BASICNODES + 2] = func10;
func[NUM_BASICNODES + 3] = func11;
func[NUM_BASICNODES + 4] = func12;
func[NUM_BASICNODES + 5] = func13;
func[NUM_BASICNODES + 6] = func14;
func[NUM_BASICNODES + 7] = func15;
func[NUM_BASICNODES + 8] = func16;
func[NUM_BASICNODES + 9] = func17;
func[NUM_BASICNODES + 10] = func18;
func[NUM_BASICNODES + 11] = func19;
func[NUM_BASICNODES + 12] = func20;
func[NUM_BASICNODES + 13] = func21;
func[NUM_BASICNODES + 14] = func22;
func[NUM_BASICNODES + 15] = func23;
func[NUM_BASICNODES + 16] = func24;
func[NUM_BASICNODES + 17] = func25;
}
}
template <class T, class Tvector> void Conforming3D<T,Tvector>::shapeDerivativesConformingSimple(
const Tvector &parms, std::array<Tvector,NUM_NODES> &func)
{
// Use standard shape functions
if (!hasHangingNodes())
{
shapeDerivatives(parms,func);
// Derivatives are calculated for -1..+1, we need 0..1
std::transform(func.begin(),func.begin() + NUM_BASICNODES,func.begin(),[](auto v) { return v * T2; } );
} else
{
#ifndef NDEBUG
for (int j = 0; j < 3; j++)
{
T d = std::abs(parms.XYZ[j] - T(0.5));
if (d < 0.005) // five times the finite-difference step
{
assert(false && "shapeFunctionsConforming() called near 0.5 cross over discontinuity caused by y = |x|");
}
}
#endif
T step = T(0.001);
Tvector coords0 = parms - Tvector(step,step,step);
Tvector coords1 = parms + Tvector(step,step,step);
Tvector dcoords;
for (int j = 0; j < 3; j++)
{
if (coords0.XYZ[j] < 0)
coords0.XYZ[j] = 0;
if (coords1.XYZ[j] > 1)
coords1.XYZ[j] = 1;
dcoords.XYZ[j] = coords1.XYZ[j] - coords0.XYZ[j];
assert(dcoords[j] > 0);
}
for (int j = 0; j < 3; j++)
{
std::array<T,NUM_NODES> func0;
Tvector c0 = parms;
c0.XYZ[j] = coords0[j];
shapeFunctionsConforming(c0,func0);
std::array<T,NUM_NODES> func1;
Tvector c1 = parms;
c1.XYZ[j] = coords1[j];
shapeFunctionsConforming(c1,func1);
for (int k = 0; k < NUM_NODES; k++)
{
func[k].XYZ[j] = (func1[k] - func0[k]) / dcoords[j];
}
}
}
}
template <class T, class Tvector> void Conforming3D<T,Tvector>::shapeDerivativesConformingExact(
const Tvector &parms, std::array<Tvector,NUM_NODES> &func)
{
// Use standard shape functions
if (!hasHangingNodes())
{
shapeDerivatives(parms,func);
// derivatives are calculated for -1..+1, we need 0..1
std::transform(func.begin(),func.begin() + NUM_BASICNODES,func.begin(),[](auto v) { return v * T2; } );
} else
{
#ifndef NDEBUG
T tol = TOLERANCE(T);
assert(parms.XYZ[0] >= T0 - tol && parms.XYZ[0] <= T1 + tol);
assert(parms.XYZ[1] >= T0 - tol && parms.XYZ[1] <= T1 + tol);
assert(parms.XYZ[2] >= T0 - tol && parms.XYZ[2] <= T1 + tol);
#endif
T c0 = parms.XYZ[0] * T2 - T1;
T c1 = parms.XYZ[1] * T2 - T1;
T c2 = parms.XYZ[2] * T2 - T1;
T c0a = T1 - std::abs(c0);
T c1a = T1 - std::abs(c1);
T c2a = T1 - std::abs(c2);
T c0m = T1 - c0;
T c0p = T1 + c0;
T c1m = T1 - c1;
T c1p = T1 + c1;
T c2m = T1 - c2;
T c2p = T1 + c2;
// these node numbers are offset by 8 : func[0] is actually func[8]
// faces
Tvector func20 = (nodes_[NUM_BASICNODES + 12] < 0) ? Tvector(0,0,0) :
Tvector(
// T05 * c0a * c1a * c2m
(c0 >= 0) ? (T05 * (-T1) * c1a * c2m) : (T05 * (+T1) * c1a * c2m),
(c1 >= 0) ? (T05 * c0a * (-T1) * c2m) : (T05 * c0a * (+T1) * c2m),
T05 * c0a * c1a * (-T1)
);
Tvector func25 = (nodes_[NUM_BASICNODES + 17] < 0) ? Tvector(0,0,0) :
Tvector(
// T05 * c0a * c1a * c2p
(c0 >= 0) ? (T05 * (-T1) * c1a * c2p) : (T05 * (+T1) * c1a * c2p),
(c1 >= 0) ? (T05 * c0a * (-T1) * c2p) : (T05 * c0a * (+T1) * c2p),
T05 * c0a * c1a * (+T1)
);
Tvector func21 = (nodes_[NUM_BASICNODES + 13] < 0) ? Tvector(0,0,0) :
Tvector(
// T05 * c0a * c1m * c2a
(c0 >= 0) ? (T05 * (-T1) * c1m * c2a) : (T05 * (+T1) * c1m * c2a),
T05 * c0a * (-T1) * c2a,
(c2 >= 0) ? (T05 * c0a * c1m * (-T1)) : (T05 * c0a * c1m * (+T1))
);
Tvector func23 = (nodes_[NUM_BASICNODES + 15] < 0) ? Tvector(0,0,0) :
Tvector(
// T05 * c0a * c1p * c2a
(c0 >= 0) ? (T05 * (-T1) * c1p * c2a) : (T05 * (+T1) * c1p * c2a),
T05 * c0a * (+T1) * c2a,
(c2 >= 0) ? (T05 * c0a * c1p * (-T1)) : (T05 * c0a * c1p * (+T1))
);
Tvector func24 = (nodes_[NUM_BASICNODES + 16] < 0) ? Tvector(0,0,0) :
Tvector(
// T05 * c0m * c1a * c2a
T05 * (-T1) * c1a * c2a,
(c1 >= 0) ? (T05 * c0m * (-T1) * c2a) : (T05 * c0m * (+T1) * c2a),
(c2 >= 0) ? (T05 * c0m * c1a * (-T1)) : (T05 * c0m * c1a * (+T1))
);
Tvector func22 = (nodes_[NUM_BASICNODES + 14] < 0) ? Tvector(0,0,0) :
Tvector(
// T05 * c0p * c1a * c2a
T05 * (+T1) * c1a * c2a,
(c1 >= 0) ? (T05 * c0p * (-T1) * c2a) : (T05 * c0p * (+T1) * c2a),
(c2 >= 0) ? (T05 * c0p * c1a * (-T1)) : (T05 * c0p * c1a * (+T1))
);
// edges (preliminary shape functions)
Tvector func8p = (nodes_[NUM_BASICNODES + 0] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0a * c1m * c2m
(c0 >= 0) ? (T025 * (-T1) * c1m * c2m) : (T025 * (+T1) * c1m * c2m),
T025 * c0a * (-T1) * c2m,
T025 * c0a * c1m * (-T1)
);
Tvector func10p = (nodes_[NUM_BASICNODES + 2] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0a * c1p * c2m
(c0 >= 0) ? (T025 * (-T1) * c1p * c2m) : (T025 * (+T1) * c1p * c2m),
T025 * c0a * (+T1) * c2m,
T025 * c0a * c1p * (-T1)
);
Tvector func16p = (nodes_[NUM_BASICNODES + 8] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0a * c1m * c2p
(c0 >= 0) ? (T025 * (-T1) * c1m * c2p) : (T025 * (+T1) * c1m * c2p),
T025 * c0a * (-T1) * c2p,
T025 * c0a * c1m * (+T1)
);
Tvector func18p = (nodes_[NUM_BASICNODES + 10] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0a * c1p * c2p
(c0 >= 0) ? (T025 * (-T1) * c1p * c2p) : (T025 * (+T1) * c1p * c2p),
T025 * c0a * (+T1) * c2p,
T025 * c0a * c1p * (+T1)
);
Tvector func9p = (nodes_[NUM_BASICNODES + 1] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0p * c1a * c2m
T025 * (+T1) * c1a * c2m,
(c1 >= 0) ? (T025 * c0p * (-T1) * c2m) : (T025 * c0p * (+T1) * c2m),
T025 * c0p * c1a * (-T1)
);
Tvector func11p = (nodes_[NUM_BASICNODES + 3] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0m * c1a * c2m
T025 * (-T1) * c1a * c2m,
(c1 >= 0) ? (T025 * c0m * (-T1) * c2m) : (T025 * c0m * (+T1) * c2m),
T025 * c0m * c1a * (-T1)
);
Tvector func17p = (nodes_[NUM_BASICNODES + 9] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0p * c1a * c2p
T025 * (+T1) * c1a * c2p,
(c1 >= 0) ? (T025 * c0p * (-T1) * c2p) : (T025 * c0p * (+T1) * c2p),
T025 * c0p * c1a * (+T1)
);
Tvector func19p = (nodes_[NUM_BASICNODES + 11] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0m * c1a * c2p
T025 * (-T1) * c1a * c2p,
(c1 >= 0) ? (T025 * c0m * (-T1) * c2p) : (T025 * c0m * (+T1) * c2p),
T025 * c0m * c1a * (+T1)
);
Tvector func14p = (nodes_[NUM_BASICNODES + 6] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0p * c1p * c2a
T025 * (+T1) * c1p * c2a,
T025 * c0p * (+T1) * c2a,
(c2 >= 0) ? (T025 * c0p * c1p * (-T1)) : (T025 * c0p * c1p * (+T1))
);
Tvector func15p = (nodes_[NUM_BASICNODES + 7] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0m * c1p * c2a
T025 * (-T1) * c1p * c2a,
T025 * c0m * (+T1) * c2a,
(c2 >= 0) ? (T025 * c0m * c1p * (-T1)) : (T025 * c0m * c1p * (+T1))
);
Tvector func13p = (nodes_[NUM_BASICNODES + 5] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0p * c1m * c2a
T025 * (+T1) * c1m * c2a,
T025 * c0p * (-T1) * c2a,
(c2 >= 0) ? (T025 * c0p * c1m * (-T1)) : (T025 * c0p * c1m * (+T1))
);
Tvector func12p = (nodes_[NUM_BASICNODES + 4] < 0) ? Tvector(0,0,0) :
Tvector(
// T025 * c0m * c1m * c2a
T025 * (-T1) * c1m * c2a,
T025 * c0m * (-T1) * c2a,
(c2 >= 0) ? (T025 * c0m * c1m * (-T1)) : (T025 * c0m * c1m * (+T1))
);
Tvector func8 = func8p - (func20 + func21) * T05;
Tvector func9 = func9p - (func20 + func22) * T05;
Tvector func10 = func10p - (func20 + func23) * T05;
Tvector func11 = func11p - (func20 + func24) * T05;
Tvector func12 = func12p - (func21 + func24) * T05;
Tvector func13 = func13p - (func21 + func22) * T05;
Tvector func14 = func14p - (func22 + func23) * T05;
Tvector func15 = func15p - (func23 + func24) * T05;
Tvector func16 = func16p - (func25 + func21) * T05;
Tvector func17 = func17p - (func25 + func22) * T05;
Tvector func18 = func18p - (func25 + func23) * T05;
Tvector func19 = func19p - (func25 + func24) * T05;
// main 8-node shape functions
shapeDerivatives(parms,func);
Tvector df0 = (func8p + func11p + func12p) * (-T05) + (func20 + func21 + func24) * T025;
Tvector df1 = (func9p + func8p + func13p) * (-T05) + (func20 + func22 + func21) * T025;
Tvector df2 = (func10p + func9p + func14p) * (-T05) + (func20 + func23 + func22) * T025;
Tvector df3 = (func11p + func10p + func15p) * (-T05) + (func20 + func24 + func23) * T025;
Tvector df4 = (func12p + func16p + func19p) * (-T05) + (func25 + func24 + func21) * T025;
Tvector df5 = (func13p + func17p + func16p) * (-T05) + (func25 + func21 + func22) * T025;
Tvector df6 = (func14p + func18p + func17p) * (-T05) + (func25 + func22 + func23) * T025;
Tvector df7 = (func15p + func19p + func18p) * (-T05) + (func25 + func23 + func24) * T025;
func[0] += df0;
func[1] += df1;
func[2] += df2;
func[3] += df3;
func[4] += df4;
func[5] += df5;
func[6] += df6;
func[7] += df7;
// additional 18 conforming shape functions for hanging nodes
// (indices offset by 8 -> [0] means [8])
func[NUM_BASICNODES + 0] = func8;