forked from parmes/solfec-1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fem.c
3935 lines (3257 loc) · 118 KB
/
fem.c
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
/*
* fem.c
* Copyright (C) 2008, Tomasz Koziara (t.koziara AT gmail.com)
* --------------------------------------------------------------
* finite element method
*/
/* This file is part of Solfec.
* Solfec is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Solfec is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Solfec. If not, see <http://www.gnu.org/licenses/>. */
#include <string.h>
#include <float.h>
#include "lap.h"
#include "mem.h"
#include "sol.h"
#include "fem.h"
#include "alg.h"
#include "bla.h"
#include "hyb.h"
#include "cvi.h"
#include "gjk.h"
#include "kdt.h"
#include "svk.h"
#include "but.h"
#include "err.h"
typedef double (*node_t) [3]; /* mesh node */
#define IMP_EPS 1E-9
#define MAX_ITERS 64
#define MAX_NODES 20
#define DOM_TOL 0.1
#define CUT_TOL 0.001
#define MESH_DOFS(msh) ((msh)->nodes_count * 3)
#define FEM_MESH_CONF(bod) ((bod)->form != REDUCED_ORDER ? (bod)->conf : (bod)->conf + (bod)->dofs + 9) /* mesh space configuration */
#define FEM_MESH_VELO(bod) ((bod)->form != REDUCED_ORDER ? (bod)->velo : (bod)->velo + (bod)->dofs * 4) /* mesh space velocity */
#define FEM_MESH_VEL0(bod) (FEM_MESH_VELO(bod) + MESH_DOFS(FEM_MESH(bod))) /* mesh space previous velocity */
#define FEM_MESH_MASS(bod) ((bod)->form != REDUCED_ORDER ? (bod)->M->x : ((bod)->conf + (bod)->dofs + 9 + MESH_DOFS(FEM_MESH(bod)))) /* mesh space velocity */
#define FEM_VEL0(bod) ((bod)->velo + (bod)->dofs) /* previous velocity */
#define FEM_FEXT(bod) ((bod)->velo + (bod)->dofs * 2) /* external force */
#define FEM_FINT(bod) ((bod)->velo + (bod)->dofs * 3) /* internal force */
#define FEM_FBOD(bod) ((bod)->form != REDUCED_ORDER ? (bod)->velo + (bod)->dofs * 4 : FEM_MESH_VEL0(bod) + MESH_DOFS(FEM_MESH(bod))) /* unit body force */
#define FEM_ROT(bod) ((bod)->conf + (bod)->dofs) /* rotation */
/* ==================== INTEGRATION ======================= */
/* order 1 */
static const double I_TET1_X[] = {0.25};
static const double I_TET1_Y[] = {0.25};
static const double I_TET1_Z[] = {0.25};
static const double I_TET1_W[] = {0.16666666666666666};
#define I_TET1_N 1
static const double I_PYR1_X[] = {0.00};
static const double I_PYR1_Y[] = {0.00};
static const double I_PYR1_Z[] = {0.25};
static const double I_PYR1_W[] = {1.333333333333333333};
#define I_PYR1_N 1
static const double I_WED1_X[] = {0.25};
static const double I_WED1_Y[] = {0.25};
static const double I_WED1_Z[] = {0.00};
static const double I_WED1_W[] = {0.333333333333333333};
#define I_WED1_N 1
static const double I_HEX1_X[] = {0.0};
static const double I_HEX1_Y[] = {0.0};
static const double I_HEX1_Z[] = {0.0};
static const double I_HEX1_W[] = {8.0};
#define I_HEX1_N 1
static const double I_TRI1_X[] = {0.333333333333333333};
static const double I_TRI1_Y[] = {0.333333333333333333};
static const double I_TRI1_W[] = {0.5};
#define I_TRI1_N 1
static const double I_QUA1_X [] = {0.0};
static const double I_QUA1_Y [] = {0.0};
static const double I_QUA1_W [] = {4.0};
#define I_QUA1_N 1
/* order 2 */
static const double I_TET2_X [] = {0.13819660112501052, 0.13819660112501052, 0.13819660112501052, 0.58541019662496840};
static const double I_TET2_Y [] = {0.13819660112501052, 0.13819660112501052, 0.58541019662496840, 0.13819660112501052};
static const double I_TET2_Z [] = {0.13819660112501052, 0.58541019662496840, 0.13819660112501052, 0.13819660112501052};
static const double I_TET2_W [] = {0.04166666666666666, 0.04166666666666666, 0.04166666666666666, 0.04166666666666666};
#define I_TET2_N 4
#define ISQR3_PYR1 0.263184055569714
#define ISQR3_PYR2 0.506616303349788
#define _1SUB_PYR1 0.544151844011225
#define _1SUB_PYR2 0.122514822655441
#define _1_WPYR1 0.100785882079825
#define _1_WPYR2 0.232547451253508
static const double I_PYR2_X[] = {-ISQR3_PYR1, ISQR3_PYR1, ISQR3_PYR1, -ISQR3_PYR1, -ISQR3_PYR2, ISQR3_PYR2, ISQR3_PYR2, -ISQR3_PYR2};
static const double I_PYR2_Y[] = {-ISQR3_PYR1, -ISQR3_PYR1, ISQR3_PYR1, ISQR3_PYR1, -ISQR3_PYR2, -ISQR3_PYR2, ISQR3_PYR2, ISQR3_PYR2};
static const double I_PYR2_Z[] = {_1SUB_PYR1, _1SUB_PYR1, _1SUB_PYR1, _1SUB_PYR1, _1SUB_PYR2, _1SUB_PYR2, _1SUB_PYR2, _1SUB_PYR2};
static const double I_PYR2_W[] = {_1_WPYR1, _1_WPYR1, _1_WPYR1, _1_WPYR1, _1_WPYR2, _1_WPYR2, _1_WPYR2, _1_WPYR2};
#define I_PYR2_N 8
#define ISQR3 0.57735026918962584
static const double I_WED2_X[] = {0.66666666666666667, 0.16666666666666667, 0.16666666666666667, 0.66666666666666667, 0.16666666666666667, 0.16666666666666667};
static const double I_WED2_Y[] = {0.16666666666666667, 0.66666666666666667, 0.16666666666666667, 0.16666666666666667, 0.66666666666666667, 0.16666666666666667};
static const double I_WED2_Z[] = {-ISQR3, -ISQR3, -ISQR3, ISQR3, ISQR3, ISQR3};
static const double I_WED2_W[] = {0.16666666666666667, 0.16666666666666667, 0.16666666666666667, 0.16666666666666667, 0.16666666666666667, 0.16666666666666667};
#define I_WED2_N 6
static const double I_HEX2_X [] = {-ISQR3, ISQR3, ISQR3, -ISQR3, -ISQR3, ISQR3, ISQR3, -ISQR3};
static const double I_HEX2_Y [] = {-ISQR3, -ISQR3, ISQR3, ISQR3, -ISQR3, -ISQR3, ISQR3, ISQR3};
static const double I_HEX2_Z [] = {-ISQR3, -ISQR3, -ISQR3, -ISQR3, ISQR3, ISQR3, ISQR3, ISQR3};
static const double I_HEX2_W [] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
#define I_HEX2_N 8
static const double I_TRI2_X[] = {0.66666666666666667, 0.16666666666666667, 0.16666666666666667};
static const double I_TRI2_Y[] = {0.16666666666666667, 0.66666666666666667, 0.16666666666666667};
static const double I_TRI2_W[] = {0.16666666666666667, 0.16666666666666667, 0.16666666666666667};
#define I_TRI2_N 3
static const double I_QUA2_X [] = {-ISQR3, ISQR3, ISQR3, -ISQR3};
static const double I_QUA2_Y [] = {-ISQR3, -ISQR3, ISQR3, ISQR3};
static const double I_QUA2_W [] = {1.0, 1.0, 1.0, 1.0};
#define I_QUA2_N 4
/* order 3 */
static const double I_HEX3_X [] = {0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834};
static const double I_HEX3_Y [] = {-0.7745966692414834, -0.7745966692414834, -0.7745966692414834, 0.0, 0.0, 0.0, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, 0.0, 0.0, 0.0, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834, -0.7745966692414834, -0.7745966692414834, -0.7745966692414834, 0.0, 0.0, 0.0, 0.7745966692414834, 0.7745966692414834, 0.7745966692414834};
static const double I_HEX3_Z [] = {-0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834, -0.7745966692414834, 0.0, 0.7745966692414834};
static const double I_HEX3_W [] = {0.1714677640603567, 0.27434842249657065, 0.1714677640603567, 0.27434842249657065, 0.43895747599451296, 0.27434842249657065, 0.1714677640603567, 0.27434842249657065, 0.1714677640603567, 0.27434842249657065, 0.43895747599451296, 0.27434842249657065, 0.438957475994513, 0.7023319615912208, 0.438957475994513, 0.27434842249657065, 0.43895747599451296, 0.27434842249657065, 0.1714677640603567, 0.27434842249657065, 0.1714677640603567, 0.27434842249657065, 0.43895747599451296, 0.27434842249657065, 0.1714677640603567, 0.27434842249657065, 0.1714677640603567};
#define I_HEX3_N 27
/* order 4 */
static const double I_HEX4_X [] = {-0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526};
static const double I_HEX4_Y [] = {-0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.8611363115940526, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, -0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.3399810435848563, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526, 0.8611363115940526};
static const double I_HEX4_Z [] = {-0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526, -0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526};
static const double I_HEX4_W [] = {0.04209147749053145, 0.07891151579507055, 0.07891151579507055, 0.04209147749053145, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.04209147749053145, 0.07891151579507055, 0.07891151579507055, 0.04209147749053145, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.1479403360567813, 0.27735296695391304, 0.27735296695391304, 0.1479403360567813, 0.1479403360567813, 0.27735296695391304, 0.27735296695391304, 0.1479403360567813, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.1479403360567813, 0.27735296695391304, 0.27735296695391304, 0.1479403360567813, 0.1479403360567813, 0.27735296695391304, 0.27735296695391304, 0.1479403360567813, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.04209147749053145, 0.07891151579507055, 0.07891151579507055, 0.04209147749053145, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.07891151579507055, 0.1479403360567813, 0.1479403360567813, 0.07891151579507055, 0.04209147749053145, 0.07891151579507055, 0.07891151579507055, 0.04209147749053145};
#define I_HEX4_N 64
/* collective rules */
static const double *I_TET_X [] = {NULL, I_TET1_X, I_TET2_X};
static const double *I_TET_Y [] = {NULL, I_TET1_Y, I_TET2_Y};
static const double *I_TET_Z [] = {NULL, I_TET1_Z, I_TET2_Z};
static const double *I_TET_W [] = {NULL, I_TET1_W, I_TET2_W};
static const int I_TET_N [] = { 0, I_TET1_N, I_TET2_N};
static const double *I_PYR_X [] = {NULL, I_PYR1_X, I_PYR2_X};
static const double *I_PYR_Y [] = {NULL, I_PYR1_Y, I_PYR2_Y};
static const double *I_PYR_Z [] = {NULL, I_PYR1_Z, I_PYR2_Z};
static const double *I_PYR_W [] = {NULL, I_PYR1_W, I_PYR2_W};
static const int I_PYR_N [] = { 0, I_PYR1_N, I_PYR2_N};
static const double *I_WED_X [] = {NULL, I_WED1_X, I_WED2_X};
static const double *I_WED_Y [] = {NULL, I_WED1_Y, I_WED2_Y};
static const double *I_WED_Z [] = {NULL, I_WED1_Z, I_WED2_Z};
static const double *I_WED_W [] = {NULL, I_WED1_W, I_WED2_W};
static const int I_WED_N [] = { 0, I_WED1_N, I_WED2_N};
static const double *I_HEX_X [] = {NULL, I_HEX1_X, I_HEX2_X, I_HEX3_X, I_HEX4_X};
static const double *I_HEX_Y [] = {NULL, I_HEX1_Y, I_HEX2_Y, I_HEX3_Y, I_HEX4_Y};
static const double *I_HEX_Z [] = {NULL, I_HEX1_Z, I_HEX2_Z, I_HEX3_Z, I_HEX4_Z};
static const double *I_HEX_W [] = {NULL, I_HEX1_W, I_HEX2_W, I_HEX3_W, I_HEX4_W};
static const int I_HEX_N [] = { 0, I_HEX1_N, I_HEX2_N, I_HEX3_N, I_HEX4_N};
static const double *I_TRI_X [] = {NULL, I_TRI1_X, I_TRI2_X};
static const double *I_TRI_Y [] = {NULL, I_TRI1_Y, I_TRI2_Y};
static const double *I_TRI_W [] = {NULL, I_TRI1_W, I_TRI2_W};
static const int I_TRI_N [] = { 0, I_TRI1_N, I_TRI2_N};
static const double *I_QUA_X [] = {NULL, I_QUA1_X, I_QUA2_X};
static const double *I_QUA_Y [] = {NULL, I_QUA1_Y, I_QUA2_Y};
static const double *I_QUA_W [] = {NULL, I_QUA1_W, I_QUA2_W};
static const int I_QUA_N [] = { 0, I_QUA1_N, I_QUA2_N};
#define MAX_ORDER 4 /* integration order bound */
/* minimal local coords */
static double mincoord [9][3] =
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
{0, 0, 0}, /* tet */
{-1, -1, 0}, /* pyr */
{0, 0, -1}, /* wed */
{0, 0, 0},
{-1, -1, -1}}; /* hex */
/* maximal local coords */
static double maxcoord [9][3] =
{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
{1, 1, 1}, /* tet */
{1, 1, 1}, /* pyr */
{1, 1, 1}, /* wed */
{0, 0, 0},
{1, 1, 1}}; /* hex */
/* load 3D integrator data */
inline static int integrator3d_load (int type, int order, const double **X, const double **Y, const double **Z, const double **W)
{
int N;
ASSERT_DEBUG (order >= 1 && order <= MAX_ORDER, "Integration order out of bounds");
switch (type)
{
case 4:
{
*X = I_TET_X [order];
*Y = I_TET_Y [order];
*Z = I_TET_Z [order];
*W = I_TET_W [order];
N = I_TET_N [order];
}
break;
case 5:
{
*X = I_PYR_X [order];
*Y = I_PYR_Y [order];
*Z = I_PYR_Z [order];
*W = I_PYR_W [order];
N = I_PYR_N [order];
}
break;
case 6:
{
*X = I_WED_X [order];
*Y = I_WED_Y [order];
*Z = I_WED_Z [order];
*W = I_WED_W [order];
N = I_WED_N [order];
}
break;
case 8:
{
*X = I_HEX_X [order];
*Y = I_HEX_Y [order];
*Z = I_HEX_Z [order];
*W = I_HEX_W [order];
N = I_HEX_N [order];
}
break;
}
return N;
}
/* predict 3D integration order */
typedef enum {MASS, BODF, INTF} ENTITY3D;
static int integrator3d_order (int type, ENTITY3D entity)
{
if (type == 8 && entity == MASS) return 4;
return 2; /* XXX */
}
/* load 2D integrator data */
inline static int integrator2d_load (int type, int order, const double **X, const double **Y, const double **W)
{
int N;
ASSERT_DEBUG (order >= 1 && order <= MAX_ORDER, "Integration order out of bounds");
switch (type)
{
case 3:
{
*X = I_TRI_X [order];
*Y = I_TRI_Y [order];
*W = I_TRI_W [order];
N = I_TRI_N [order];
}
break;
case 4:
{
*X = I_QUA_X [order];
*Y = I_QUA_Y [order];
*W = I_QUA_W [order];
N = I_QUA_N [order];
}
break;
}
return N;
}
/* predict 2D integration order */
static int integrator2d_order (int type)
{
if (type == 3) return 1;
else return 2; /* quads */
}
/* element integration; note that below __t__->ver, __t__->center are in local element coordinates already */
#define INTEGRATE3D(TYPE, ENTITY, DOM, DOMNUM, ...)\
{\
const double *__X__, *__Y__, *__Z__, *__W__;\
double point [3], weight;\
int __N__, __k__, __l__;\
TRISURF *__d__ = DOM;\
\
if (__d__)\
{\
double __subnodes__ [4][3], __subJ__;\
double __subpoint__ [3];\
int __domnum__ = DOMNUM;\
TRI *__t__, *__e__;\
double __volume__;\
\
__N__ = integrator3d_load (4, 1, &__X__, &__Y__, &__Z__, &__W__);\
\
for (__volume__ = __k__ = 0; __k__ < __domnum__; __k__ ++) __volume__ += __d__ [__k__].volume;\
\
for (__l__ = 0; __l__ < __domnum__; __d__ ++, __l__ ++)\
{\
if (__d__->volume > DOM_TOL * __volume__)\
{\
COPY (__d__->center, __subnodes__ [3]);\
\
for (__t__ = __d__->tri, __e__ = __t__ + __d__->m; __t__ < __e__; __t__ ++)\
{\
COPY (__t__->ver [0], __subnodes__ [2]);\
COPY (__t__->ver [1], __subnodes__ [1]);\
COPY (__t__->ver [2], __subnodes__ [0]);\
\
for (__k__ = 0; __k__ < __N__; __k__ ++)\
{\
__subpoint__ [0] = __X__ [__k__];\
__subpoint__ [1] = __Y__ [__k__];\
__subpoint__ [2] = __Z__ [__k__];\
__subJ__ = element_det (4, __subnodes__, __subpoint__, NULL);\
tet_o1_local_to_global (__subnodes__, __subpoint__, point);\
weight = __subJ__ * __W__ [__k__];\
\
__VA_ARGS__\
}\
}\
}\
else\
{\
COPY (__d__->center, point);\
weight = __d__->volume;\
\
__VA_ARGS__\
}\
}\
}\
else\
{\
__N__ = integrator3d_load (TYPE, integrator3d_order (TYPE, ENTITY), &__X__, &__Y__, &__Z__, &__W__);\
for (__k__ = 0; __k__ < __N__; __k__ ++)\
{\
point [0] = __X__ [__k__];\
point [1] = __Y__ [__k__];\
point [2] = __Z__ [__k__];\
weight = __W__ [__k__];\
\
__VA_ARGS__\
}\
}\
}
/* face integral begins */
#define INTEGRAL2D_BEGIN(TYPE)\
{\
const double *__X__, *__Y__, *__W__;\
double point [2], weight;\
int __N__, __k__;\
\
__N__ = integrator2d_load (TYPE, integrator2d_order (TYPE), &__X__, &__Y__, &__W__);\
for (__k__ = 0; __k__ < __N__; __k__ ++)\
{\
point [0] = __X__ [__k__];\
point [1] = __Y__ [__k__];\
weight = __W__ [__k__];\
/* integration code in between
* uses point and weight values */
/* face integral ends */
#define INTEGRAL2D_END()\
}\
}
/* ==================== FACE ======================= */
/* face shape functions at a local 2-point */
inline static int face_shapes (FACE *fac, double *point, double *shapes)
{
switch (fac->type)
{
case 3: /* 1st order triangle */
shapes [0] = point [0];
shapes [1] = point [1];
shapes [2] = 1.0 - point [0] - point [1];
return 3;
case 4: /* 1st order quadrilateral */
shapes [0] = 0.25 * (1.0 - point [0]) * (1.0 - point [1]);
shapes [1] = 0.25 * (1.0 + point [0]) * (1.0 - point [1]);
shapes [2] = 0.25 * (1.0 + point [0]) * (1.0 + point [1]);
shapes [3] = 0.25 * (1.0 - point [0]) * (1.0 + point [1]);
return 4;
}
return 0;
}
/* face shape derivatices at a local 2-point */
inline static int face_derivs (FACE *fac, double *point, double *derivs)
{
switch (fac->type)
{
case 3:
derivs [0] = 1.0;
derivs [1] = 0.0;
derivs [2] = 0.0;
derivs [3] = 1.0;
derivs [4] = -1.0;
derivs [5] = -1.0;
return 3;
case 4:
derivs [0] = 0.25 * (point [1] - 1.0);
derivs [1] = 0.25 * (point [0] - 1.0);
derivs [2] = 0.25 * (1.0 - point [1]);
derivs [3] = -0.25 * (1.0 + point [0]);
derivs [4] = 0.25 * (1.0 + point [1]);
derivs [5] = 0.25 * (1.0 + point [0]);
derivs [6] = -0.25 * (1.0 + point [1]);
derivs [7] = 0.25 * (1.0 - point [0]);
return 4;
}
return 0;
}
/* compute face coordinates transformation determinant at a local 2-point */
inline static double face_det (FACE *fac, node_t nodes, double *point, double *normal)
{
double derivs [16], d0 [3], d1[3], tmp [3], *d;
int i, n;
n = face_derivs (fac, point, derivs);
if (!normal) normal = tmp;
SET (d0, 0);
SET (d1, 0);
for (i = 0, d = derivs; i < n; i ++, d += 2)
{
ADDMUL (d0, d[0], nodes[i], d0);
ADDMUL (d1, d[1], nodes[i], d1);
}
PRODUCT (d0, d1, normal);
return LEN (normal);
}
/* load face node coordinates into a local table */
inline static int element_nodes (node_t heap, int type, int *nodes, node_t stack);
#define face_nodes(heap, type, nodes, stack) element_nodes (heap, type, nodes, stack)
/* load face displacemnts into a local table */
inline static void face_displacements (double *heap, FACE *fac, double (*q) [3])
{
double *p;
int i;
for (i = 0; i < fac->type; i ++)
{
p = &heap [3 * fac->nodes [i]];
COPY (p, q[i]);
}
}
/* create face integration data;
* FACE->idata = {shapes0, normal0, J0*wgt0, shapes1, normal1, J1*wgt1, shapes2, normal2, J2*wgt2, shapes3, normal3, J3*wgt3} */
#define FACE_SHAPES(fac, i) ((fac)->idata+(i)*((fac)->type+4))
#define FACE_NORMAL(fac, i) (FACE_SHAPES(fac,i)+(fac)->type)
static void create_face_integration_data (MESH *msh)
{
double refn [4][3], J, *N, *shapes;
FACE *fac;
int n;
for (fac = msh->faces; fac; fac = fac->n)
{
n = 0; INTEGRAL2D_BEGIN (fac->type) { n ++; } INTEGRAL2D_END ()
ERRMEM (fac->idata = malloc (sizeof (double [n * (fac->type + 4)])));
face_nodes (msh->ref_nodes, fac->type, fac->nodes, refn);
INTEGRAL2D_BEGIN (fac->type) /* defines point and weight */
{
shapes = FACE_SHAPES (fac, __k__);
N = FACE_NORMAL (fac, __k__);
face_shapes (fac, point, shapes);
J = face_det (fac, refn, point, N);
N [3] = J * weight;
NORMALIZE (N);
}
INTEGRAL2D_END ()
}
}
/* =============================== ELEMENT ================================ */
/* linear tetrahedron shape functions */
inline static void tet_o1_shapes (double *point, double *shapes)
{
shapes [0] = 1.0 - (point [0] + point [1] + point [2]);
shapes [1] = point [0];
shapes [2] = point [1];
shapes [3] = point [2];
}
/* linear hexahedron shape functions */
inline static void hex_o1_shapes (double *point, double *shapes)
{
shapes [0] = 0.125 * (1.0 - point [0]) * (1.0 - point [1]) * (1.0 - point [2]);
shapes [1] = 0.125 * (1.0 + point [0]) * (1.0 - point [1]) * (1.0 - point [2]);
shapes [2] = 0.125 * (1.0 + point [0]) * (1.0 + point [1]) * (1.0 - point [2]);
shapes [3] = 0.125 * (1.0 - point [0]) * (1.0 + point [1]) * (1.0 - point [2]);
shapes [4] = 0.125 * (1.0 - point [0]) * (1.0 - point [1]) * (1.0 + point [2]);
shapes [5] = 0.125 * (1.0 + point [0]) * (1.0 - point [1]) * (1.0 + point [2]);
shapes [6] = 0.125 * (1.0 + point [0]) * (1.0 + point [1]) * (1.0 + point [2]);
shapes [7] = 0.125 * (1.0 - point [0]) * (1.0 + point [1]) * (1.0 + point [2]);
}
/* linear pyramid shape functions */
inline static void pyr_o1_shapes (double *point, double *shapes)
{
double ratio;
if (point [2] != 1.0) ratio = (point[0]*point[1]*point[2]) / (1 - point[2]);
else ratio = 0.0; /* XXX */
shapes [0] = 0.25 * ((1.0 + point[0])*(1.0 + point[1]) - point[2] + ratio); /* rabbit functions */
shapes [1] = 0.25 * ((1.0 - point[0])*(1.0 + point[1]) - point[2] - ratio);
shapes [2] = 0.25 * ((1.0 - point[0])*(1.0 - point[1]) - point[2] + ratio);
shapes [3] = 0.25 * ((1.0 + point[0])*(1.0 - point[1]) - point[2] - ratio);
shapes [4] = point [2];
}
/* linear wedge shape functions */
inline static void wed_o1_shapes (double *point, double *shapes)
{
shapes [0] = 0.5 * (1.0 - point[0] - point[1])*(1.0 - point[2]);
shapes [1] = 0.5 * point[0]*(1.0 - point[2]);
shapes [2] = 0.5 * point[1]*(1.0 - point[2]);
shapes [3] = 0.5 * (1.0 - point[0] - point[1])*(1.0 + point[2]);
shapes [4] = 0.5 * point[0]*(1.0 + point[2]);
shapes [5] = 0.5 * point[1]*(1.0 + point[2]);
}
/* linear tetrahedron shape derivatives */
inline static void tet_o1_derivs (double *point, double *derivs)
{
derivs [0] = -1.0;
derivs [1] = -1.0;
derivs [2] = -1.0;
derivs [3] = 1.0;
derivs [4] = 0.0;
derivs [5] = 0.0;
derivs [6] = 0.0;
derivs [7] = 1.0;
derivs [8] = 0.0;
derivs [9] = 0.0;
derivs [10] = 0.0;
derivs [11] = 1.0;
}
/* linear hexahedron shape derivatives */
inline static void hex_o1_derivs (double *point, double *derivs)
{
derivs[0] = -0.125 * (1 - point[1]) * (1 - point[2]);
derivs[1] = -0.125 * (1 - point[0]) * (1 - point[2]);
derivs[2] = -0.125 * (1 - point[0]) * (1 - point[1]);
derivs[3] = 0.125 * (1 - point[1]) * (1 - point[2]);
derivs[4] = -0.125 * (1 + point[0]) * (1 - point[2]);
derivs[5] = -0.125 * (1 + point[0]) * (1 - point[1]);
derivs[6] = 0.125 * (1 + point[1]) * (1 - point[2]);
derivs[7] = 0.125 * (1 + point[0]) * (1 - point[2]);
derivs[8] = -0.125 * (1 + point[0]) * (1 + point[1]);
derivs[9] = -0.125 * (1 + point[1]) * (1 - point[2]);
derivs[10] = 0.125 * (1 - point[0]) * (1 - point[2]);
derivs[11] = -0.125 * (1 - point[0]) * (1 + point[1]);
derivs[12] = -0.125 * (1 - point[1]) * (1 + point[2]);
derivs[13] = -0.125 * (1 - point[0]) * (1 + point[2]);
derivs[14] = 0.125 * (1 - point[0]) * (1 - point[1]);
derivs[15] = 0.125 * (1 - point[1]) * (1 + point[2]);
derivs[16] = -0.125 * (1 + point[0]) * (1 + point[2]);
derivs[17] = 0.125 * (1 + point[0]) * (1 - point[1]);
derivs[18] = 0.125 * (1 + point[1]) * (1 + point[2]);
derivs[19] = 0.125 * (1 + point[0]) * (1 + point[2]);
derivs[20] = 0.125 * (1 + point[0]) * (1 + point[1]);
derivs[21] = -0.125 * (1 + point[1]) * (1 + point[2]);
derivs[22] = 0.125 * (1 - point[0]) * (1 + point[2]);
derivs[23] = 0.125 * (1 - point[0]) * (1 + point[1]);
}
/* linear pyramid shape derivatives */
inline static void pyr_o1_derivs (double *point, double *derivs)
{
double drat0, drat1, drat2;
if (point [2] != 1.0)
{
drat0 = (point[1]*point[2]) / (1.0 - point[2]),
drat1 = (point[0]*point[2]) / (1.0 - point[2]),
drat2 = (point[0]*point[1]) / (1.0 - point[2])*(1.0 - point[2]);
}
else drat0 = drat1 = drat2 = 0.0; /* XXX */
derivs [0] = 0.25 * ((1.0 + point[1]) + drat0);
derivs [1] = 0.25 * ((1.0 + point[0]) + drat1);
derivs [2] = 0.25 * (-1.0 + drat2);
derivs [3] = 0.25 * (-(1.0 + point[1]) - drat0);
derivs [4] = 0.25 * ((1.0 - point[0]) - drat1);
derivs [5] = 0.25 * (-1.0 - drat2);
derivs [6] = 0.25 * (-(1.0 - point[1]) + drat0);
derivs [7] = 0.25 * (-(1.0 - point[0]) + drat1);
derivs [8] = 0.25 * (-1.0 + drat2);
derivs [ 9] = 0.25 * ((1.0 - point[1]) - drat0);
derivs [10] = 0.25 * (-(1.0 + point[0]) - drat1);
derivs [11] = 0.25 * (-1.0 - drat2);
derivs [12] = 0.0;
derivs [13] = 0.0;
derivs [14] = 1.0;
}
/* linear wedge shape derivatives */
inline static void wed_o1_derivs (double *point, double *derivs)
{
derivs [0] = -0.5 * (1.0 - point[2]);
derivs [1] = -0.5 * (1.0 - point[2]);
derivs [2] = -0.5 * (1.0 - point[0] - point[1]);
derivs [3] = 0.5 * (1.0 - point[2]);
derivs [4] = 0.0;
derivs [5] = -0.5 * point[0];
derivs [6] = 0.0;
derivs [7] = 0.5 * (1.0 - point[2]);
derivs [8] = -0.5 * point[1];
derivs [ 9] = -0.5 * (1.0 + point[2]);
derivs [10] = -0.5 * (1.0 + point[2]);
derivs [11] = 0.5 * (1.0 - point[0] - point[1]);
derivs [12] = 0.5 * (1.0 + point[2]);
derivs [13] = 0.0;
derivs [14] = 0.5 * point[0];
derivs [15] = 0.0;
derivs [16] = 0.5 * (1.0 + point[2]);
derivs [17] = 0.5 * point[1];
}
/* linear tetrahedron local to global point transformation */
static void tet_o1_local_to_global (node_t nodes, double *local, double *global)
{
double shapes [4];
int i, j;
tet_o1_shapes (local, shapes);
SET (global, 0.0);
for (i = 0; i < 3; i ++)
for (j = 0; j < 4; j ++)
global [i] += nodes [j][i] * shapes [j];
}
/* finite element shape functions; returns the number of nodes */
inline static int element_shapes (int type, double *point, double *shapes)
{
switch (type)
{
case 4: tet_o1_shapes (point, shapes); return 4;
case 5: pyr_o1_shapes (point, shapes); return 5;
case 6: wed_o1_shapes (point, shapes); return 6;
case 8: hex_o1_shapes (point, shapes); return 8;
}
return 0;
}
/* finite element shape derivatives; returns the number of nodes */
inline static int element_derivs (int type, double *point, double *derivs)
{
switch (type)
{
case 4: tet_o1_derivs (point, derivs); return 4;
case 5: pyr_o1_derivs (point, derivs); return 5;
case 6: wed_o1_derivs (point, derivs); return 6;
case 8: hex_o1_derivs (point, derivs); return 8;
}
return 0;
}
/* copy element node coordinates into a local table */
inline static int element_nodes (node_t heap, int type, int *nodes, node_t stack)
{
int i;
for (i = 0; i < type; i ++)
{
COPY (heap [nodes [i]], stack [i]);
}
return i;
}
/* copy element nodal values into a local table */
static int element_nodal_values (double *heap, ELEMENT *ele, double (*q) [3])
{
double *p;
int i;
for (i = 0; i < ele->type; i ++)
{
p = &heap [3 * ele->nodes [i]];
COPY (p, q[i]);
}
return i;
}
/* copy element node numbers into a local table */
static int element_node_numbers (ELEMENT *ele, int *numbers)
{
int i;
for (i = 0; i < ele->type; i ++) numbers [i] = ele->nodes [i];
return i;
}
/* local to global point transformation */
static void local_to_global (node_t heap, ELEMENT *ele, double *local, double *global)
{
double nodes [MAX_NODES][3], shapes [MAX_NODES];
int i, j, n;
n = element_nodes (heap, ele->type, ele->nodes, nodes);
element_shapes (ele->type, local, shapes);
SET (global, 0.0);
for (i = 0; i < 3; i ++)
for (j = 0; j < n; j ++)
global [i] += nodes [j][i] * shapes [j];
}
/* global to local point transformation */
static void global_to_local (node_t heap, ELEMENT *ele, double *global, double *local)
{
double nodes [MAX_NODES][3], derivs [3*MAX_NODES], shapes [MAX_NODES];
double A [9], B [3], error;
int i, j, k, l, n, ipiv [3];
element_nodes (heap, ele->type, ele->nodes, nodes);
SET (local, 0.0);
l = 0;
do
{
n = element_shapes (ele->type, local, shapes);
COPY (global, B);
for (i = 0; i < 3; i ++)
for (j = 0; j < n; j ++)
B [i] -= nodes [j][i] * shapes [j];
element_derivs (ele->type, local, derivs);
SET9 (A, 0.0);
for (i = 0; i < 3; i ++)
for (j = 0; j < 3; j ++)
for (k = 0; k < n; k ++) A [3*j+i] += nodes[k][i] * derivs [3*k+j];
ASSERT (lapack_dgesv (3, 1, A, 3, ipiv, B, 3) == 0, ERR_FEM_COORDS_INVERT);
ADD (local, B, local);
error = LEN (B);
} while (++l < 64 && error > 1E-9);
ASSERT (l < 64, ERR_FEM_COORDS_INVERT);
for (i = 0; i < 3; i ++) /* project back onto the element if the point is off due to roundoff */
{
if (local [i] < mincoord [ele->type][i]) local [i] = mincoord [ele->type][i];
else if (local [i] > maxcoord [ele->type][i]) local [i] = maxcoord [ele->type][i];
}
}
/* compute local coordinates of a spatial point */
#define spatial_to_local(msh, ele, x, point) global_to_local ((msh)->cur_nodes, ele, x, point)
/* compute local coordinates of a referential point */
#define referential_to_local(msh, ele, X, point) global_to_local ((msh)->ref_nodes, ele, X, point)
/* compute spatial coordinates of a local point */
#define local_to_spatial(msh, ele, x, point) local_to_global ((msh)->cur_nodes, ele, x, point)
/* compute referential coordinates of a local point */
#define local_to_referential(msh, ele, X, point) local_to_global ((msh)->ref_nodes, ele, X, point)
/* coordinates transformation determinant at local point */
inline static double element_det (int type, node_t nodes, double *point, double *F)
{
double derivs [3*MAX_NODES], G [9];
int i, j, k, n;
n = element_derivs (type, point, derivs);
if (!F) F = G;
SET9 (F, 0.0);
for (i = 0; i < 3; i ++)
for (j = 0; j < 3; j ++)
for (k = 0; k < n; k ++) F [3*j+i] += nodes[k][i] * derivs [3*k+j];
return DET (F);
}
/* element deformation determinant at local point */
inline static void element_gradient (int type, node_t q, double *point, double *F0, double *derivs, double *F)
{
double local_derivs [3*MAX_NODES], IF0 [9], det, *l, *d;
int i, j, k, n;
n = element_derivs (type, point, local_derivs);
INVERT (F0, IF0, det);
ASSERT (det > 0.0, ERR_FEM_COORDS_INVERT);
for (k = 0, l = local_derivs, d = derivs; k < n; k ++, l += 3, d += 3) { TVMUL (IF0, l, d); }
IDENTITY (F);
for (i = 0; i < 3; i ++)
for (j = 0; j < 3; j ++)
for (k = 0; k < n; k ++) F [3*j+i] += q[k][i] * derivs [3*k+j];
}
/* compute element shape functions at a local point and return global matrix */
static MX* element_shapes_matrix (BODY *bod, MESH *msh, ELEMENT *ele, double *point)
{
static int *p, *i, *q, *u, k, n, m, o;
double shapes [MAX_NODES], *x, *y;
int dofs = MESH_DOFS (msh);
MX *N;
o = element_shapes (ele->type, point, shapes);
n = dofs;
ERRMEM (p = MEM_CALLOC ((2*n+1) * sizeof (int)));
i = p + n + 1;
for (k = 0, u = i; k < o; k ++, u += 3)
{
m = ele->nodes [k] * 3;
q = &p [m + 1];
q [0] = 1; q [1] = 1; q [2] = 1;
u [0] = 0; u [1] = 1; u [2] = 2;
}
for (q = p + 1; q < i; q ++) *q += *(q-1);
N = MX_Create (MXCSC, 3, n, p, i);
x = N->x;
free (p);
p = N->p;
for (k = 0; k < o; k ++)
{
m = ele->nodes [k] * 3;
y = &x [p [m]];
SET (y, shapes [k]);
}
return N;
}
/* return number of integration points for internal force computation */
static int number_of_integration_points (ELEMENT *ele)
{
int i = 0;
INTEGRATE3D (ele->type, INTF, ele->dom, ele->domnum, i ++;)
return i;
}
/* allocate bulk material states at integration points */
static void allocate_element_states (MESH *msh, BULK_MATERIAL *mat)
{
ELEMENT *ele;
int nip;
for (ele = msh->surfeles; ele; ele = ele->next)
{
if (mat->nstate && ele->state == NULL)
{
nip = number_of_integration_points (ele);
ERRMEM (ele->state = MEM_CALLOC (nip * sizeof (double [mat->nstate])));
}
}
}
/* simplex integrated volume ==
* shape functions integrated volume test */
static void test_volume_integral (MESH *msh, double ref_volume, int body_id)
{
double J, volume, nodes [MAX_NODES][3];
ELEMENT *ele;
int bulk;
for (ele = msh->surfeles, bulk = 0, volume = 0.0; ele; )
{
element_nodes (msh->ref_nodes, ele->type, ele->nodes, nodes);
INTEGRATE3D (ele->type, MASS, ele->dom, ele->domnum,
J = element_det (ele->type, nodes, point, NULL);
volume += J * weight;
)
if (bulk) ele = ele->next;
else if (ele->next) ele = ele->next;
else ele = msh->bulkeles, bulk = 1;
}
WARNING (fabs (volume - ref_volume) < CUT_TOL * ref_volume,
"FEM BODY %d:\nShape volume is %g.\nIntegrated volume is %g.\n"
"Error %g is beyond the tolerance of %g.\n"
"This issue occurs when your background hexahedrons are not rectilinear.\n"
"Refine the background mesh or make it rectilinear. Alternately, use a tetrahedral background mesh.\n",
body_id, ref_volume, volume, fabs (ref_volume - volume) / ref_volume, CUT_TOL);
}
/* lump contribution of the element mass into the global diagonal matrix */
static void element_lump_mass (BODY *bod, MESH *msh, ELEMENT *ele, double *x)
{
double J, coef, integral, density,
nodes [MAX_NODES][3],
shapes [MAX_NODES],
*out [MAX_NODES];
int i, j, n;
density = ele->mat ? ele->mat->density : bod->mat->density;
n = element_nodes (msh->ref_nodes, ele->type, ele->nodes, nodes);
for (i = 0; i < n; i ++) out [i] = &x [3 * ele->nodes [i]];
INTEGRATE3D (ele->type, MASS, ele->dom, ele->domnum,
element_shapes (ele->type, point, shapes);
J = element_det (ele->type, nodes, point, NULL);
coef = density * J * weight;
for (i = 0; i < n; i ++)
{
for (j = 0; j < n; j ++)
{
integral = coef * shapes [i] * shapes [j];
out [i][0] += integral;
out [i][1] += integral;