-
Notifications
You must be signed in to change notification settings - Fork 6
/
Element_calculations.c
2430 lines (2042 loc) · 77.2 KB
/
Element_calculations.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
/*
Copyright (C) 2003 The GeoFramework Consortium
This file is part of Ellipsis3D.
Ellipsis3D is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2,
as published by the Free Software Foundation.
Ellipsis3D 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 General Public License for more details.
Authors:
Louis Moresi <[email protected]>
Richard Albert <[email protected]>
*/
#include "config.h"
#include <math.h>
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "element_definitions.h"
#include "global_defs.h"
struct SORT {
standard_precision value;
int node;
};
void build_diagonal_of_K(
struct All_variables *E,
int level
)
{
int i,a,e,k,loc0,found1;
int compare_function();
struct SORT *nodesort;
const int neq=E->mesh.NEQ[level];
const int nno=E->mesh.NNO[level];
const int nel=E->mesh.NEL[level];
const int dims=E->mesh.nsd;
const int dofs=E->mesh.dof;
const int ends=enodes[dims];
const int max_eqn = dofs * max_node_interaction[dims];
const int max_node = max_node_interaction[dims];
higher_precision b1,b2,b3,b4,b5,b6;
standard_precision time,CPU_time();
nodesort = (struct SORT *) Malloc0((E->mesh.nno+100) * sizeof(struct SORT));
/* E->monitor.max_BI[level] = 0.0;
E->monitor.min_BI[level] = 1.0e32;*/
if (E->control.B_is_good[level] == 1) return;
for(i=1;i<=nno;i++) {
if(E->NODE[level][i] & ( OFFSIDE )) {
E->BI1[level][i] = 0.0;
E->BI2[level][i] = 0.0;
if(dofs==3)
E->BI3[level][i] = 0.0;
else if(dofs==6) {
E->BI3[level][i] = 0.0;
E->BI4[level][i] = 0.0;
E->BI5[level][i] = 0.0;
E->BI6[level][i] = 0.0;
}
continue;
}
found1=0;
loc0=i*max_node;
for(k=0;k<max_node;k++) {
if(E->Node_map_3[level][loc0+k] == i) {
b1= E->Node_k11[level][loc0+k];
b2= E->Node_k22[level][loc0+k];
if(dofs==3)
b3= E->Node_k33[level][loc0+k];
else if(dofs==6) {
b3= E->Node_k33[level][loc0+k];
b4= E->Node_k44[level][loc0+k];
b5= E->Node_k55[level][loc0+k];
b6= E->Node_k66[level][loc0+k];
}
}
}
if(b1 != 0.0) /* Boundary conditions */
E->BI1[level][i] = 1.0/b1;
else
E->BI1[level][i] = 0.0;
if(b2 != 0.0)
E->BI2[level][i] = 1.0/b2;
else
E->BI2[level][i] = 0.0;
if(dofs==3) {
if(b3 != 0.0)
E->BI3[level][i] = 1.0/b3;
else
E->BI3[level][i] = 0.0;
}
else if(dofs==6) {
if(b3 != 0.0) /* Boundary conditions */
E->BI3[level][i] = 1.0/b3;
else
E->BI3[level][i] = 0.0;
if(b4 != 0.0)
E->BI4[level][i] = 1.0/b4;
else
E->BI4[level][i] = 0.0;
if(b5 != 0.0) /* Boundary conditions */
E->BI5[level][i] = 1.0/b5;
else
E->BI5[level][i] = 0.0;
if(b6 != 0.0)
E->BI6[level][i] = 1.0/b6;
else
E->BI6[level][i] = 0.0;
}
E->BI[level][E->ID[level][i].doff[1]] = E->BI1[level][i];
E->BI[level][E->ID[level][i].doff[2]] = E->BI2[level][i];
if(dofs==3)
E->BI[level][E->ID[level][i].doff[3]] = E->BI3[level][i];
else if(dofs==6) {
E->BI[level][E->ID[level][i].doff[3]] = E->BI3[level][i];
E->BI[level][E->ID[level][i].doff[4]] = E->BI4[level][i];
E->BI[level][E->ID[level][i].doff[5]] = E->BI5[level][i];
E->BI[level][E->ID[level][i].doff[6]] = E->BI6[level][i];
}
}
E->control.B_is_good[level] = 1;
/* Create a sort for node ordering based on the values of BI */
for(i=1;i<=E->mesh.NNO[level];i++) {
nodesort[i].value = E->BI1[level][i];
nodesort[i].node = i;
}
qsort(nodesort+1,E->mesh.NNO[level],sizeof(struct SORT),compare_function);
for(i=1;i<=E->mesh.NNO[level];i++) {
E->index[level][i] = nodesort[i].node;
}
free((void *) nodesort);
return;
}
int compare_function
( struct SORT *s1,
struct SORT *s2
)
{
if(s1->value < s2->value)
return(-1);
else if (s1->value > s2->value)
return(1);
else
return(0);
}
void build_diagonal_of_Ahat_level(
struct All_variables *E,
int level
)
{
higher_precision assemble_dAhatq_entry();
int i,j,k,el,m;
standard_precision time,time0,CPU_time(),visc,comp,v1;
const int npno = E->mesh.npno;
const int neq = E->mesh.neq;
const int dims = E->mesh.nsd;
time=CPU_time();
if(E->control.verbose)
fprintf(stderr,"Building pressure preconditioner %d\n",level);
for(i=1;i<=E->mesh.NPNO[level];i++)
E->BPI[level][i]=1.0;
for(el=1;el<=E->mesh.NEL[level];el++) {
visc = 0.0;
comp = 0.0;
for(i=0;i<E->tracer.tr_in_element_number[level][el];i++) {
m = E->tracer.tr_in_element[level][i+E->tracer.tr_in_element_offset[level][el]];
visc += 1.0/(E->tracer.Visc[m]);
if(3==dims) {
if(E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio > 0.0 &&
E->tracer.BulkVisc[m] > 0.6666666 * E->tracer.Visc[m])
comp += 1.0/(E->tracer.BulkVisc[m] - 0.6666666 * E->tracer.Visc[m]);
}
else {
if(E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio > 0.0 &&
E->tracer.BulkVisc[m] > E->tracer.Visc[m] )
comp += 1.0/(E->tracer.BulkVisc[m] - E->tracer.Visc[m]);
}
}
if(E->tracer.tr_in_element_number[level][el] != 0) {
visc = E->tracer.tr_in_element_number[level][el]/(visc);
v1 = (higher_precision) assemble_dAhatq_entry(E,el,level);
if(comp != 0.0) {
comp = E->tracer.tr_in_element_number[level][el]/comp;
/* E->BPI[level][el] = visc * comp / (comp+visc) ; /* */
E->BPI[level][el] = 1.0 / ( v1 + 1.0/comp); /**/
}
else {
/* E->BPI[level][el] = visc; /**/
E->BPI[level][el] = 1.0/v1; /**/
}
}
else
E->BPI[level][el] = 1.0;
}
return;
}
void build_diagonal_of_Ahat_level1(
struct All_variables *E,
int level
)
{
higher_precision assemble_dAhatq_entry();
int i,j,k,el,m;
standard_precision time,time0,CPU_time(),comp,v1;
const int npno = E->mesh.npno;
const int neq = E->mesh.neq;
const int dims = E->mesh.nsd;
time=CPU_time();
if(E->control.verbose)
fprintf(stderr,"Building pressure preconditioner %d\n",level);
for(i=1;i<=E->mesh.NPNO[level];i++)
E->BPI[level][i]=1.0;
for(el=1;el<=E->mesh.NEL[level];el++) {
comp = 0.0;
for(i=0;i<E->tracer.tr_in_element_number[level][el];i++) {
m = E->tracer.tr_in_element[level][i+E->tracer.tr_in_element_offset[level][el]];
if(E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio > (2.0/dims))
comp += 1.0/(E->tracer.BulkVisc[m] - (2.0/dims) * E->tracer.Visc[m]);
}
if(E->tracer.tr_in_element_number[level][el] != 0) {
v1 = (higher_precision) assemble_dAhatq_entry(E,el,level);
if(comp != 0.0) {
comp = E->tracer.tr_in_element_number[level][el]/comp;
E->BPI[level][el] = 1.0 / ( v1 + 1.0/comp);
}
else {
E->BPI[level][el] = 1.0/v1;
}
}
else
E->BPI[level][el] = 1.0;
}
return;
}
#if 0
void build_diagonal_of_Ahat_level(
struct All_variables *E,
int level
)
{
higher_precision assemble_dAhatq_entry();
int i,j,k,el,m;
standard_precision time,time0,CPU_time(),visc,comp,v1;
const int npno = E->mesh.npno;
const int neq = E->mesh.neq;
const int dims = E->mesh.nsd;
time=CPU_time();
if(E->control.verbose)
fprintf(stderr,"Building pressure preconditioner %d\n",level);
for(i=1;i<=E->mesh.NPNO[level];i++)
E->BPI[level][i]=1.0;
for(el=1;el<=E->mesh.NEL[level];el++) {
visc = 0.0;
comp = 0.0;
for(i=0;i<E->tracer.tr_in_element_number[level][el];i++) {
m = E->tracer.tr_in_element[level][i+E->tracer.tr_in_element_offset[level][el]];
visc += 1.0/(E->tracer.Visc[m]);
if(3==dims) {
if(E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio > 0.666666666)
comp += 1.0/(E->tracer.BulkVisc[m] - 0.6666666 * E->tracer.Visc[m]);
}
else {
if(E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio > 1.0)
comp += 1.0/(E->tracer.BulkVisc[m] - E->tracer.Visc[m]);
}
}
if(E->tracer.tr_in_element_number[level][el] != 0) {
visc = E->tracer.tr_in_element_number[level][el]/(visc);
if(comp != 0.0) {
comp = E->tracer.tr_in_element_number[level][el]/comp;
E->BPI[level][el] = visc * comp / (comp+visc) ;
}
else {
E->BPI[level][el] = visc;
}
}
else
E->BPI[level][el] = 1.0;
}
return;
}
#endif
higher_precision assemble_dAhatq_entry(
struct All_variables *E,
int e,
int level
)
{
int i,j,p,a,b,node,ee,element,lnode;
higher_precision elt_g[24][1];
void get_elt_g();
higher_precision gradQ[81],divU;
const int nel=E->mesh.nel;
const int ends=enodes[E->mesh.nsd];
const int dims=E->mesh.nsd;
const int dofs=E->mesh.dof;
const int npno=E->mesh.npno;
for(i=0;i<81;i++)
gradQ[i] = 0.0;
divU=0.0;
for(a=1;a<=ends;a++) {
node=E->IEN[level][e].node[a];
p = (a-1)*dims;
if(!(E->NODE[level][node] & BC1 )) {
j=E->ID[level][node].doff[1];
gradQ[p] += E->BI[level][j]*E->elt_del[level][e].g[p][0];
}
if(!(E->NODE[level][node] & BC2)) {
j=E->ID[level][node].doff[2];
gradQ[p+1] += E->BI[level][j]*E->elt_del[level][e].g[p+1][0];
}
if(3==dims) {
if(!(E->NODE[level][node] & BC3)) {
j=E->ID[level][node].doff[3];
gradQ[p+2] += E->BI[level][j]*E->elt_del[level][e].g[p+2][0];
}
}
}
/* calculate div U from the same thing .... */
/* only need to run over nodes with non-zero grad P, i.e. the ones in
the element accessed above, BUT it is only necessary to update the
value in the original element, because the diagonal is all we use at
the end ... */
for(b=1;b<=ends;b++) {
p = (b-1)*dims;
divU +=E->elt_del[level][e].g[p][0] * gradQ[p];
divU +=E->elt_del[level][e].g[p+1][0] * gradQ[p+1];
if(3==dims) {
divU +=E->elt_del[level][e].g[p+2][0] * gradQ[p+2];
}
}
return(divU);
}
/*==============================================================
Function to supply the element g matrix for a given element e.
============================================================== */
void get_elt_g(
struct All_variables *E,
int el,
higher_precision elt_del[24][1],
int lev
)
{
void get_global_shape_fn();
void get_global_shape_fn_curvilin();
int p,a,nint,es,d,i,j,k;
higher_precision ra,ct,si,x[4],rtf[4][9];
higher_precision dGNdash[3];
higher_precision recip_radius,temp;
int lmsize;
higher_precision elt_R[24*24];
higher_precision elt_del1[24];
higher_precision *node_R;
higher_precision sum;
int px,pz,py,node;
struct Shape_function GN;
struct Shape_function_dA dOmega;
struct Shape_function_dx GNx;
const int dims=E->mesh.nsd;
const int dofs=E->mesh.dof;
const int ends=enodes[dims];
const int nn=loc_mat_size[dims][E->control.model];
/* Special case, 4/8 node bilinear v/constant p element -> 1 pressure point */
get_global_shape_fn(E,el,&GN,&GNx,&dOmega,2,lev);
temp=p_point[1].weight[dims-1] * dOmega.ppt[1];
/* for(a=1;a<=ends;a++)
for(i=1;i<=dims;i++)
{ p = dims*(a-1) + i -1;
elt_del[p][0] = -GNx.ppt[GNPXINDEX(i-1,a,1)] * temp;
}
*/
/* unroll loops for speed */
for(a=1;a<=ends;a++) {
p=dims*(a-1);
elt_del[p][0] = -GNx.ppt[GNPXINDEX(0,a,1)] * temp;
elt_del[p+1][0] = -GNx.ppt[GNPXINDEX(1,a,1)] * temp;
if(3==dims)
elt_del[p+2][0] = -GNx.ppt[GNPXINDEX(2,a,1)] * temp;
if(E->control.AXI)
elt_del[p][0] += -GN.ppt[GNPINDEX(a,1)] * temp / E->ECO[lev][el].centre[1];
}
if (E->control.HAVE_SKEWBCS) {
/* Build elt_Rot matrix */
/* Identity */
for(p=0;p<nn*nn;p++) {
elt_R[p] = 0.0;
}
for(p=0;p<nn;p++)
elt_R[p*nn+p] = 1.0;
/* Add in all nodal rotation matrix terms */
for(a=1;a<=ends;a++) {
node=E->IEN[lev][el].node[a];
if(E->NODE[lev][node] & SKEWBC) {
node_R = E->curvilinear.NODE_R[lev][node];
px = (a-1) * dims;
pz = (a-1) * dims + 1;
py = (a-1) * dims + 2;
elt_R[px*nn+px] = node_R[0*dims+0]; /* note all nodes independent effect on elt_K */
elt_R[px*nn+pz] = node_R[0*dims+1];
elt_R[pz*nn+px] = node_R[1*dims+0];
elt_R[pz*nn+pz] = node_R[1*dims+1];
if(dims==3) {
elt_R[px*nn+py] = node_R[0*dims+2];
elt_R[pz*nn+py] = node_R[1*dims+2];
elt_R[py*nn+px] = node_R[2*dims+0];
elt_R[py*nn+pz] = node_R[2*dims+1];
elt_R[py*nn+py] = node_R[2*dims+2];
}
}
}
/* pre multiply by RotT */
for(i=0;i<nn;i++) {
sum=0.0;
for(k=0;k<nn;k++)
sum += elt_R[k*nn+i] * elt_del[k][0];
elt_del1[i] = sum;
}
for(i=0;i<nn;i++)
elt_del[i][0] = elt_del1[i] ;
}
return;
}
/* This is a wrapper for the various specialized element stiffness
routines - it just interprets the prevailing settings and calls
the appropriate function from there */
void get_elt_k(
struct All_variables *E,
int el,
higher_precision *elt_k,
int level
)
{
void get_elt_k_viscous_2D();
void get_elt_k_viscous_3D();
void get_elt_k_cosserat_2D();
void get_elt_k_cosserat_3D();
void get_elt_k_general();
const int dims = E->mesh.nsd;
/* Normally we expect to use a hand-coded
stiffness matrix formulation. However, for
debugging, testing and for new problems, the
perfectly general version is available.
By putting the tests here we can ensure that
the code itself is significantly simpler to follow
and more efficiently executed.
*/
if(E->control.B_matrix!=0) {
if(2==dims && 1==E->control.model && !E->control.AXI) { /* 2D viscous, hand-coded */
get_elt_k_viscous_2D(E,el,elt_k,level);
}
else if (3==dims && 1==E->control.model) { /* 3D viscous, hand-coded */
get_elt_k_viscous_3D(E,el,elt_k,level);
}
else if (2==dims && 2==E->control.model) { /* 2D Cosserat, hand-coded */
get_elt_k_cosserat_2D(E,el,elt_k,level);
}
else if (3==dims && 2==E->control.model) { /* 3D Cosserat, hand-coded */
get_elt_k_cosserat_3D(E,el,elt_k,level);
}
else if (2==dims && 1==E->control.model && E->control.AXI) { /* 2D, axisymmetric, hand-coded */
/* get_elt_k_viscous_axi(E,el,elt_k,level); */
}
else { /* use the perfectly general case after all !! */
get_elt_k_general(E,el,elt_k,level);
}
}
else {
get_elt_k_general(E,el,elt_k,level);
}
return;
}
void add_penalty3(
struct All_variables *E,
int el,
higher_precision *elt_k,
int level
)
{
int i,m,pn,qn,a,b;
standard_precision dOmega,penalty ;
standard_precision pen_dO; /* DAS: 21/01/03 */
standard_precision lNxO[4][ELNMAX+1];
const int dims=E->mesh.nsd;
const int dofs=E->mesh.dof;
const int nn=loc_mat_size[dims][E->control.model];
const int ends=enodes[dims];
get_global_v_x_shape_fn(E,el,lNxO,&dOmega,0.0,0.0,0.0,level);
for(i=0;i<E->tracer.tr_in_element_number[level][el];i++) {
m = E->tracer.tr_in_element[level][i+E->tracer.tr_in_element_offset[level][el]];
dOmega =
E->tracer.tracer_weight_fn[level][m]
* E->tracer.tracer_jacobian[level][m]
* E->tracer.Visc[m];
/* DAS: 21/01/03, factorised penalty and dOmega out of this loop */
penalty=E->tracer.visc[E->tracer.property_group[m]].Pen_bulk;
pen_dO = dOmega * penalty;
for(a=1;a<=ends;a++)
for(b=a;b<=ends;b++) {
pn=(dofs*(a-1))*nn+dofs*(b-1);
qn=(dofs*(b-1))*nn+dofs*(a-1);
/* Augmented Lagrangian (penalty) to enhance incompressibility */
if(penalty!=0.0) {
standard_precision t1a = lNxO[1][a] * pen_dO,
t2a = lNxO[2][a] * pen_dO;
elt_k[pn] += t1a * lNxO[1][b];
elt_k[pn+1] += t1a * lNxO[2][b];
elt_k[pn+nn] += t2a * lNxO[1][b];
elt_k[pn+nn+1] += t2a * lNxO[2][b];
if(3==dims) { /*RAA: 10/01/03, put in 3D stuff here*/
standard_precision t3a = lNxO[3][a] * pen_dO;
elt_k[pn+2] += t1a * lNxO[3][b];
elt_k[pn+nn+2] += t2a * lNxO[3][b];
elt_k[pn+2*nn] += t3a * lNxO[1][b];
elt_k[pn+2*nn+1] += t3a * lNxO[2][b];
elt_k[pn+2*nn+2] += t3a * lNxO[3][b];
}
}
/* And the matrix is symmetric so, for the time being, this is stored */
elt_k[qn] = elt_k[pn];
elt_k[qn+nn] = elt_k[pn+1];
elt_k[qn+1] = elt_k[pn+nn];
elt_k[qn+nn+1] = elt_k[pn+nn+1];
if(3==dims) { /*RAA: 10/01/03, added 3D stuff here*/
elt_k[qn+2*nn] = elt_k[pn+2];
elt_k[qn+2*nn+1]= elt_k[pn+nn+2];
elt_k[qn+2] = elt_k[pn+2*nn];
elt_k[qn+nn+2] = elt_k[pn+2*nn+1];
elt_k[qn+2*nn+2]= elt_k[pn+2*nn+2];
}
}
}
return;
}
#if 1
void get_all_elt_k
( struct All_variables *E,
higher_precision *elt_k,
int level ) {
void get_all_elt_k_viscous_2D();
/* void get_all_elt_k_viscous_3D(); */
const int dims = E->mesh.nsd;
/* Normally we expect to use a hand-coded
stiffness matrix formulation. However, for
debugging, testing and for new problems, the
perfectly general version is available.
By putting the tests here we can ensure that
the code itself is significantly simpler to follow
and more efficiently executed.
*/
if(E->control.B_matrix!=0) {
if(2==dims && 1==E->control.model && !E->control.AXI) { /* 2D viscous, hand-coded */
get_all_elt_k_viscous_2D(E,elt_k,level);
}
else if (3==dims && 1==E->control.model) { /* 3D viscous, hand-coded */
/* get_all_elt_k_viscous_3D(E,elt_k,level); */
}
else if (2==dims && 2==E->control.model) { /* 2D Cosserat, hand-coded */
/* get_elt_k_cosserat_2D(E,el,elt_k,level); */
}
else if (3==dims && 2==E->control.model) { /* 3D Cosserat, hand-coded */
/* get_elt_k_cosserat_3D(E,el,elt_k,level); */
}
else if (2==dims && 1==E->control.model && !E->control.AXI) { /* 2D, axisymmetric, hand-coded */
/* get_elt_k_viscous_axi(E,el,elt_k,level); */
}
else { /* use the perfectly general case after all !! */
/* get_elt_k_general(E,el,elt_k,level); */
}
}
else {
/* get_elt_k_general(E,el,elt_k,level); */
}
return;
}
#endif
void get_elt_k_viscous_2D(
struct All_variables *E,
int el,
higher_precision *elt_k,
int level
)
{
int a,b,p,q,m,i,j,k,tracers,tr;
int pn,qn,ad,bd;
standard_precision lN[ELNMAX+1];
standard_precision lNx[4][ELNMAX+1];
standard_precision lNxO[4][ELNMAX+1];
standard_precision eta1,eta2;
standard_precision dOmega,weight,dOmegaq;
standard_precision a1,a0,delta;
standard_precision H,phi;
higher_precision del_elt_k[24*24];
higher_precision elt_R[24*24];
higher_precision cos_theta,sin_theta;
higher_precision elt_k1[24*24];
higher_precision *node_R;
higher_precision sum;
int px,pz,py,node;
standard_precision penalty;
const int dims=E->mesh.nsd;
const int dofs=E->mesh.dof;
const int nn=loc_mat_size[dims][E->control.model];
const int ends=enodes[dims];
for(p=0;p<nn*nn;p++)
elt_k[p] = elt_k1[p] = 0.0; /* !!!!!! */
/* fprintf(stderr,"GEK - 1\n"); */
get_global_v_x_shape_fn(E,el,lNxO,&dOmega,0.0,0.0,0.0,level);
if(E->tracer.tr_in_element_number[level][el] == 0)
fprintf(E->fp,"Warning: no tracers in %d/%d\n",level,el);
for(i=0;i<E->tracer.tr_in_element_number[level][el];i++) {
m = E->tracer.tr_in_element[level][i+E->tracer.tr_in_element_offset[level][el]];
eta1 = E->tracer.eta1[level][m];
eta2 = E->tracer.eta2[level][m];
get_global_v_x_shape_fn(E,el,lNx,&dOmega,eta1,eta2,NULL,level);
dOmegaq = dOmega =
E->tracer.tracer_weight_fn[level][m]
* E->tracer.tracer_jacobian[level][m]
* E->tracer.Visc[m];
if(E->control.CHEM_TRANS &&
E->tracer.visc[E->tracer.property_group[m]].mobile_phase_ratio != 1.0 ) {
H = E->tracer.visc[E->tracer.property_group[m]].mobile_phase_ratio;
phi = E->tracer.volfraction[m];
delta = 1.0 - H / ((phi * H + 1.0 - phi) * (phi + H - phi * H)) ;
/*fprintf(stderr,"%d: phi %g , H %g , delta %g\n",m,phi,H,delta); */
a0 = 4.0 * delta *
E->tracer.n1[m] * E->tracer.n1[m] * E->tracer.n2[m] * E->tracer.n2[m];
a1 = 2.0 * delta * E->tracer.n1[m] * E->tracer.n2[m] *
( E->tracer.n2[m] * E->tracer.n2[m] - E->tracer.n1[m] * E->tracer.n1[m] );
}
else if((E->control.ORTHOTROPY &&
E->tracer.visc[E->tracer.property_group[m]].Ortho_viscosity_ratio < 1.0)) {
delta = (1.0 - E->tracer.visc[E->tracer.property_group[m]].Ortho_viscosity_ratio);
a0 = 4.0 * delta *
E->tracer.n1[m] * E->tracer.n1[m] * E->tracer.n2[m] * E->tracer.n2[m];
a1 = 2.0 * delta * E->tracer.n1[m] * E->tracer.n2[m] *
( E->tracer.n2[m] * E->tracer.n2[m] - E->tracer.n1[m] * E->tracer.n1[m] );
}
for(a=1;a<=ends;a++)
for(b=a;b<=ends;b++) {
pn=(dofs*(a-1))*nn+dofs*(b-1);
qn=(dofs*(b-1))*nn+dofs*(a-1);
elt_k[pn] += (2.0 * lNx[1][a] * lNx[1][b] + lNx[2][a] * lNx[2][b]) * dOmega;
elt_k[pn+1] += lNx[2][a] * lNx[1][b] * dOmega;
elt_k[pn+nn] += lNx[1][a] * lNx[2][b] * dOmega;
elt_k[pn+nn+1] += (2.0 * lNx[2][a] * lNx[2][b] + lNx[1][a] * lNx[1][b]) * dOmega;
/* Orthotropic - additional terms */
if((E->control.ORTHOTROPY &&
E->tracer.visc[E->tracer.property_group[m]].Ortho_viscosity_ratio < 1.0) ||
(E->control.CHEM_TRANS &&
E->tracer.visc[E->tracer.property_group[m]].mobile_phase_ratio != 1.0)
) {
elt_k[pn] += ( -a0 * lNx[1][a] * lNx[1][b]
-a1 * lNx[1][a] * lNx[2][b]
-a1 * lNx[2][a] * lNx[1][b]
+a0 * lNx[2][a] * lNx[2][b]
- delta * lNx[2][a] * lNx[2][b] ) * dOmega;
elt_k[pn+1] += ( a0 * lNx[2][a] * lNx[1][b]
+a1 * lNx[2][a] * lNx[2][b]
-a1 * lNx[1][a] * lNx[1][b]
+a0 * lNx[1][a] * lNx[2][b]
- delta * lNx[2][a] * lNx[1][b] ) * dOmega; /* corrected May 11, 2001 */
elt_k[pn+nn] += ( a0 * lNx[1][a] * lNx[2][b]
-a1 * lNx[1][a] * lNx[1][b]
+a1 * lNx[2][a] * lNx[2][b]
+a0 * lNx[2][a] * lNx[1][b]
- delta * lNx[1][a] * lNx[2][b] ) * dOmega;
elt_k[pn+nn+1] += (-a0 * lNx[2][a] * lNx[2][b]
+a1 * lNx[2][a] * lNx[1][b]
+a1 * lNx[1][a] * lNx[2][b]
+a0 * lNx[1][a] * lNx[1][b]
- delta * lNx[1][a] * lNx[1][b] ) * dOmega;
}
/* And the matrix is symmetric so, for the time being, this is stored */
elt_k[qn] = elt_k[pn];
elt_k[qn+nn] = elt_k[pn+1];
elt_k[qn+1] = elt_k[pn+nn];
elt_k[qn+nn+1] = elt_k[pn+nn+1];
elt_k1[qn] = elt_k1[pn];
elt_k1[qn+nn] = elt_k1[pn+1];
elt_k1[qn+1] = elt_k1[pn+nn];
elt_k1[qn+nn+1] = elt_k1[pn+nn+1];
}
}
if(E->control.HAVE_SKEWBCS) {
/* Build elt_Rot matrix */
/* Identity */
for(p=0;p<nn*nn;p++)
elt_R[p] = 0.0;
for(p=0;p<nn;p++)
elt_R[p*nn+p] = 1.0;
/* Add in all nodal rotation matrix terms */
for(a=1;a<=ends;a++) {/*5*/
node=E->IEN[level][el].node[a];
if(E->NODE[level][node] & SKEWBC) {
node_R = E->curvilinear.NODE_R[level][node];
px = (a-1) * dims;
pz = (a-1) * dims + 1;
py = (a-1) * dims + 2;
elt_R[px*nn+px] = node_R[0*dims+0];
/* note all nodes independent effect on elt_K */
elt_R[px*nn+pz] = node_R[0*dims+1];
elt_R[pz*nn+px] = node_R[1*dims+0];
elt_R[pz*nn+pz] = node_R[1*dims+1];
}
}
/* post multiply by Rot */
for(i=0;i<nn;i++)
for(j=0;j<nn;j++) {
sum=0.0;
for(k=0;k<nn;k++)
sum += elt_k[i*nn+k] * elt_R[k*nn+j];
elt_k1[i*nn+j] = sum;
}
/* pre multiply by RotT */
for(i=0;i<nn;i++)
for(j=0;j<nn;j++) {
sum=0.0;
for(k=0;k<nn;k++)
sum += elt_R[k*nn+i] * elt_k1[k*nn+j];
elt_k[i*nn+j] = sum;
}
}
return;
}
void get_all_elt_k_viscous_2D(
struct All_variables *E,
higher_precision *Elt_K,
int level
)
{
int a,b,p,q,m,i,j,k,tracers,tr;
int pn,qn,ad,bd;
int el;
standard_precision lN[ELNMAX+1];
standard_precision lNx[4][ELNMAX+1];
standard_precision lNxO[4][ELNMAX+1];
standard_precision eta1,eta2,eta3;
standard_precision dOmega,weight,dOmegaq;
standard_precision t1;
higher_precision del_elt_k[24*24];
higher_precision elt_R[24*24];
higher_precision cos_theta,sin_theta;
higher_precision *elt_k;
higher_precision *node_R;
higher_precision sum;
int px,pz,py,node;
standard_precision penalty;
const int dims=E->mesh.nsd;
const int dofs=E->mesh.dof;
const int nn=loc_mat_size[dims][E->control.model];
const int ends=enodes[dims];
const int elts=E->mesh.NEL[level];
const int eksize = dofs*ends*dofs*ends;
const int numtrc = E->tracer.NUM_TRACERS;
for(p=0;p<elts*eksize;p++)
Elt_K[p] = 0.0;
for(el=1;el<=elts;el++) {
elt_k = Elt_K + (el-1) * eksize;
get_global_v_x_shape_fn(E,el,lNxO,&dOmega,0.0,0.0,0.0,level);
for(i=0;i<E->tracer.tr_in_element_number[level][el];i++) {
m = E->tracer.tr_in_element[level][i+E->tracer.tr_in_element_offset[level][el]];
eta1 = E->tracer.eta1[level][m];
eta2 = E->tracer.eta2[level][m];
if (3==dims)
eta3 = E->tracer.eta3[level][m];
get_global_v_x_shape_fn(E,el,lNx,&dOmega,eta1,eta2,eta3,level);
dOmegaq = dOmega =
E->tracer.tracer_weight_fn[level][m]
* E->tracer.tracer_jacobian[level][m]
* E->tracer.Visc[m];
/* Algebraic expression for this ?? */
if(E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio >= 0.0)
penalty = max(0.0,min(E->control.AUG_lagrangian,E->tracer.visc[E->tracer.property_group[m]].Bulk_visc_ratio));
else
penalty = E->control.AUG_lagrangian;
t1 = dOmega;
#pragma loop novrec elt_k,lNx,lNxO
#pragma loop temp a,b,pn
/* for(a=1;a<=ends;a++)
for(b=1;b<=ends;b++) { */
for(k=0;k<ends*ends;k++) {
a = k/ends+1;
b = k%ends+1;
pn=(dofs*(a-1))*nn+dofs*(b-1);
/*
elt_k[pn] += t1 * (2.0 * lNx[1][a] * lNx[1][b] + lNx[2][a] * lNx[2][b] +
penalty * (lNxO[1][a] * lNxO[1][b]));
elt_k[pn+1] += t1 * (lNx[2][a] * lNx[1][b] +
penalty * (lNxO[1][a] * lNxO[2][b]));
elt_k[pn+nn] += t1 * (lNx[1][a] * lNx[2][b] +
penalty * (lNxO[2][a] * lNxO[1][b]));
elt_k[pn+nn+1] += t1 * (2.0 * lNx[2][a] * lNx[2][b] + lNx[1][a] * lNx[1][b] +
penalty * (lNxO[2][a] * lNxO[2][b]));
*/
/* deviatoric */
elt_k[pn] += t1 * (1.0 * lNx[1][a] * lNx[1][b] + lNx[2][a] * lNx[2][b]);
elt_k[pn+1] += t1 * (lNx[2][a] * lNx[1][b] - 1.0 * lNx[1][a] * lNx[2][b]);
elt_k[pn+nn] += t1 * (lNx[1][a] * lNx[2][b] - 1.0 * lNx[2][a] * lNx[1][b]);
elt_k[pn+nn+1] += t1 * (1.0 * lNx[2][a] * lNx[2][b] + lNx[1][a] * lNx[1][b]);
}
}
#if 0
if(E->control.HAVE_SKEWBCS) {
/* Build elt_Rot matrix */