-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevolution.c
More file actions
1551 lines (1378 loc) · 43.8 KB
/
evolution.c
File metadata and controls
1551 lines (1378 loc) · 43.8 KB
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
#include "evp.h"
static void InteractionStrengthMatrix(char *type, real self, real coplane,
real cross, real glissile, real hirth, real lomer, real **chi)
{
/* The assignment of interaction strength matrix dependes on the label
of the slip system. Currently only FCC is considered according to
"Arsenlis and Parks, JMPS, 50(2002), 1979" */
int i,j;
if(strcmp(type, "FCC")==0||strcmp(type, "fcc")==0){
chi[0][0] = self;
chi[0][1] = coplane;
chi[0][2] = coplane;
chi[0][3] = hirth;
chi[0][4] = glissile;
chi[0][5] = lomer;
chi[0][6] = cross;
chi[0][7] = glissile;
chi[0][8] = glissile;
chi[0][9] = hirth;
chi[0][10] = lomer;
chi[0][11] = glissile;
chi[1][1] = self;
chi[1][2] = coplane;
chi[1][3] = glissile;
chi[1][4] = cross;
chi[1][5] = glissile;
chi[1][6] = glissile;
chi[1][7] = hirth;
chi[1][8] = lomer;
chi[1][9] = lomer;
chi[1][10] = hirth;
chi[1][11] = glissile;
chi[2][2] = self;
chi[2][3] = lomer;
chi[2][4] = glissile;
chi[2][5] = hirth;
chi[2][6] = glissile;
chi[2][7] = lomer;
chi[2][8] = hirth;
chi[2][9] = glissile;
chi[2][10] = glissile;
chi[2][11] = cross;
chi[3][3] = self;
chi[3][4] = coplane;
chi[3][5] = coplane;
chi[3][6] = hirth;
chi[3][7] = lomer;
chi[3][8] = glissile;
chi[3][9] = cross;
chi[3][10] = glissile;
chi[3][11] = glissile;
chi[4][4] = self;
chi[4][5] = coplane;
chi[4][6] = lomer;
chi[4][7] = hirth;
chi[4][8] = glissile;
chi[4][9] = glissile;
chi[4][10] = hirth;
chi[4][11] = lomer;
chi[5][5] = self;
chi[5][6] = glissile;
chi[5][7] = glissile;
chi[5][8] = cross;
chi[5][9] = glissile;
chi[5][10] = lomer;
chi[5][11] = hirth;
chi[6][6] = self;
chi[6][7] = coplane;
chi[6][8] = coplane;
chi[6][9] = hirth;
chi[6][10] = glissile;
chi[6][11] = lomer;
chi[7][7] = self;
chi[7][8] = coplane;
chi[7][9] = glissile;
chi[7][10] = cross;
chi[7][11] = glissile;
chi[8][8] = self;
chi[8][9] = lomer;
chi[8][10] = glissile;
chi[8][11] = hirth;
chi[9][9] = self;
chi[9][10] = coplane;
chi[9][11] = coplane;
chi[10][10] = self;
chi[10][11] = coplane;
chi[11][11] = self;
/* symmetric matrix */
for(i=1;i<12;i++){
for(j=0;j<i;j++){
chi[i][j] = chi[j][i];
}
}
}
else{
PError("Interaction strength matrix is only supported for FCC currently!!", 1110);
}
return;
}/*end InteractionStrengthMatrix()*/
static real NR_quality(voigt sig, voigt xlambda, voigt eps, voigt strain, voigt66 sg, int idx,int jphi)
{
voigt edotp;
voigt66 d_edotp;
voigt tot_eps; // total strain
voigt res;
real f;
int i,j;
#ifdef DD_BASED_FLAG
#ifdef DD_POWER_LAW
StrainRate_Orowan_POWER(sig,edotp,d_edotp,idx,jphi);
#else
StrainRate_Orowan(sig,edotp,d_edotp,idx,jphi);
#endif
#else
StrainRate_eval(sig,edotp, d_edotp,idx, jphi);
#endif
/* tot_eps is the total strain and eps6 is the
current plastic strain, i.e. Eq. 4 */
for(i=0;i<6;i++){
tot_eps[i] = eps[i] + edotp[i]*TimeStep;
for(j=0;j<6;j++){
tot_eps[i] += sg[i][j]*sig[j];
}
}
// calculate the residual R, Eq. 16
for(i=0;i<6;i++){
res[i] = sig[i] - xlambda[i];
for(j=0;j<6;j++){
res[i] += C066[i][j]*(tot_eps[j]-strain[j]);
}
}
for(f=0.0,i=0;i<6;i++){
f += res[i]*res[i];
}
return f/2.0;
}/*end NR_quality()*/
static void UpdateStress(int istep, real *Err_e_local, real *Err_s_local, int update_flag)
{
/* Solve the stress using the updated strain during the iteration for
each single mechanical step (istep), i.e. Eq. 16 */
int jph;
voigt66 sg66;
ten2nd xlambda_aux, sig_aux, eps_aux, strain_aux;
voigt xlambda6, sig6, eps6, strain6;
voigt edotp6;
ten2nd edotp_aux;
voigt66 d_edotp66;
voigt tot_eps; // total strain
voigt sig6_old;
ten4th aux3333;
voigt66 aux66;
real signorm,enorm;
real erroral, erral;
real conv_NR, conv_istep_e, conv_istep_s;
voigt res; // residual R to be nullified
voigt66 jacob_inv; // Jacobian of R
int itmaxal, iterl;
int i,j,k;
local_loop{
jph = phase_f[pIDX];
if(!Type_phases[jph-1]){
C6_loop{
sg66[mi][mj] = C_gr[pIDX][mi][mj];
}
LU_inv_66(sg66);
T2_loop{
/* the iteration starts with the current stress field */
xlambda_aux[mi][mj] = Sig[pIDX][mi][mj];
sig_aux[mi][mj] = Sig[pIDX][mi][mj];
/* plastic strain at time t. This is used in Eq. 4 to update total strain
from calculated strain rate*/
eps_aux[mi][mj] = Eps[pIDX][mi][mj];
/* DisGrad stores the updated displacement gradient obtained from Eq. 15.
So here strain_aux/strain6 stores the updated total strain*/
strain_aux[mi][mj] = (DisGrad[pIDX][mi][mj]+DisGrad[pIDX][mj][mi])/2.0;
}
chg_basis(xlambda6,xlambda_aux,aux66,aux3333,2);
chg_basis(sig6,sig_aux,aux66,aux3333,2);
chg_basis(eps6,eps_aux,aux66,aux3333,2);
chg_basis(strain6,strain_aux,aux66,aux3333,2);
signorm = 0.0;
T2_loop{
signorm += xlambda_aux[mi][mj]*xlambda_aux[mi][mj];
}
signorm = sqrt(signorm);
enorm = 0.0;
T2_loop{
enorm += eps_aux[mi][mj]*eps_aux[mi][mj];
}
enorm = sqrt(enorm);
erroral = 1E-10;
itmaxal = 500;
iterl = 0;
erral = 10*erroral;
/* Newton-Raphson method to solve augmented Lagrangians */
while((iterl<itmaxal)&&(fabs(erral)>fabs(erroral))){
iterl++;
for(i=0;i<6;i++) sig6_old[i] = sig6[i];
/* Update the plastic strain rate based on current stress */
#ifdef DD_BASED_FLAG
#ifdef DD_POWER_LAW
StrainRate_Orowan_POWER(sig6,edotp6,d_edotp66,pIDX,jph);
#else
StrainRate_Orowan(sig6,edotp6,d_edotp66,pIDX,jph);
//exit(0);
#endif
#else
StrainRate_eval(sig6,edotp6, d_edotp66,pIDX, jph);
#endif
/* tot_eps is the total strain and eps6 is the
current plastic strain, i.e. Eq. 4 */
for(i=0;i<6;i++){
tot_eps[i] = eps6[i] + edotp6[i]*TimeStep;
for(j=0;j<6;j++){
tot_eps[i] += sg66[i][j]*sig6[j];
}
}
// calculate the residual R, Eq. 16
for(i=0;i<6;i++){
res[i] = sig6[i] - xlambda6[i];
for(j=0;j<6;j++){
res[i] += C066[i][j]*(tot_eps[j]-strain6[j]);
}
}
// calculate the Jacobian of R
for(i=0;i<6;i++){
for(j=0;j<6;j++){
jacob_inv[i][j] = (real)(i==j);
for(k=0;k<6;k++){
// Eq. 18
jacob_inv[i][j] += C066[i][k]*(sg66[k][j]+d_edotp66[k][j]*TimeStep);
}
}
}
#ifdef NR_MODIFIED
voigt66 jacob; // Jacobian of R, not the inverse!
for(i=0;i<6;i++){
for(j=0;j<6;j++){
jacob[i][j] = jacob_inv[i][j];
}
}
#endif
LU_inv_66(jacob_inv);
//printf("residual = %le and jacob = %le\n",res[1],jacob_inv[5][1]);
// Newton-Raphson update
#ifdef NR_MODIFIED
/* Using line searches and backtracking to ensure global
* convergence */
// current f=F*F/2 value
real f_old = 0.0;
for(i=0;i<6;i++){
f_old += res[i]*res[i];
}
f_old *= 0.5;
// current gradient of f
real gradf[6];
for(i=0;i<6;i++){
gradf[i] = 0.0;
for(j=0;j<6;j++){
gradf[i] += res[j]*jacob[j][i];
}
}
// full NR step
real NR_step[6];
for(i=0;i<6;i++){
NR_step[i] = 0.0;
for(j=0;j<6;j++){
NR_step[i] -= jacob_inv[i][j]*res[j];
}
}
real stpmax = 10.0; // limit of the length
real sum, slope, test, temp, tmplam;
real a_coef, alam, alam2, alamin, b_coef, disc, f2, rhs1, rhs2;
real ALF = 1.E-4;
real TOLX = 1.E-7;
for(sum=0.0,i=0;i<6;i++) sum += NR_step[i]*NR_step[i];
sum = sqrt(sum);
if(sum>stpmax){
for(i=0;i<6;i++) NR_step[i] *= stpmax/sum;
}
for(slope=0.0,i=0;i<6;i++){
slope += gradf[i]*NR_step[i];
}
// printf("slope is = %le\n",slope);
if(slope>=0){
printf("NR_step is = %le %le %le %le %le %le\n", NR_step[0],NR_step[1],NR_step[2],NR_step[3],NR_step[4],NR_step[5]);
printf("gradf is = %le %le %le %le %le %le\n", gradf[0],gradf[1],gradf[2],gradf[3],gradf[4],gradf[5]);
PError("Roundoff problem during line searching in NR.", 1203);
}
test = 0.0;
for(i=0;i<6;i++){
temp = fabs(NR_step[i])/MAX(fabs(sig6_old[i]),1.0);
if(temp>test) test = temp;
}
alamin = TOLX/test;
alam = 1.0;
while(1){
// always try full NR step first
for(i=0;i<6;i++) sig6[i] = sig6_old[i] + alam*NR_step[i];
real f_new = NR_quality(sig6, xlambda6, eps6, strain6, sg66, pIDX, jph);
if(alam<alamin){ // convergence on delta_x
for(i=0;i<6;i++) sig6[i] = sig6_old[i];
break;
}else if(f_new <= f_old+ALF*alam*slope){ // sufficient function decrease
break;
}
else{ // backtrack
if(fabs(alam-1.0)<1.E-4){ // first time
tmplam = -slope/(2.0*(f_new-f_old-slope));
}else{
rhs1 = f_new-f_old-alam*slope;
rhs2 = f2-f_old-alam2*slope;
a_coef = (rhs1/(alam*alam)-rhs2/(alam2*alam2))/(alam-alam2);
b_coef = (-alam2*rhs1/(alam*alam)+alam*rhs2/(alam2*alam2))/(alam-alam2);
if(fabs(a_coef)<1E-4) tmplam = -slope/(2.0*b_coef);
else{
disc = b_coef*b_coef-3.0*a_coef*slope;
if(disc<0.0) tmplam = 0.5*alam;
else if(b_coef<=0.0) tmplam = (-b_coef+sqrt(disc))/(3.0*a_coef);
else tmplam = -slope/(b_coef+sqrt(disc));
}
if(tmplam>0.5*alam)
tmplam = 0.5*alam;
}
}
alam2=alam;
alam = MAX(tmplam,0.1*alam);
}
#else
for(i=0;i<6;i++){
for(j=0;j<6;j++){
sig6[i] -= jacob_inv[i][j]*res[j];
}
}
#endif
// convergence check
conv_NR= 0.0;
conv_istep_e= 0.0;
conv_istep_s = 0.0;
for(i=0;i<6;i++){
conv_NR += (sig6[i]-sig6_old[i])*(sig6[i]-sig6_old[i]);
conv_istep_e += (tot_eps[i]-strain6[i])*(tot_eps[i]-strain6[i]);
conv_istep_s += (sig6[i]-xlambda6[i])*(sig6[i]-xlambda6[i]);
}
erral = sqrt(conv_NR)/signorm;
conv_istep_s = sqrt(conv_istep_s);
conv_istep_e = sqrt(conv_istep_e);
// update crss
if((Hard_Flag==1)){
#ifdef DD_BASED_FLAG
//trial_DislocationEvolution(pIDX,jph);
#else
/* because the shear rate that is about to use
is calcualted (in StrainRate_eval()) based on
trial stress field, we use the get_trialtau()
subroutine which is a trial versio nof harden() */
//get_trialtau(pIDX,jph);
//get_trialtau_anal(pIDX,jph);
#endif
}
} // end of while() loop
chg_basis(sig6,sig_aux,aux66,aux3333,1);
chg_basis(edotp6,edotp_aux,aux66,aux3333,1);
// update stress and strain rate fields
T2_loop{
Sig[pIDX][mi][mj] = sig_aux[mi][mj];
Edot[pIDX][mi][mj] = edotp_aux[mi][mj];
}
*Err_s_local += conv_istep_s;
*Err_e_local += conv_istep_e;
}
else{
T2_loop{
Sig[pIDX][mi][mj] = 0.0;
Edot[pIDX][mi][mj] = 0.0;
}
}
}
return;
}/*end UpdateStress()*/
static void UpdateStress_DRX(int istep, real *Err_e_local, real *Err_s_local, int update_flag)
{
/* Solve the stress using the updated strain during the iteration for
each single mechanical step (istep), i.e. Eq. 16 */
int jph;
voigt66 sg66;
ten2nd xlambda_aux, sig_aux, eps_aux, strain_aux;
voigt xlambda6, sig6, eps6, strain6;
voigt edotp6;
ten2nd edotp_aux;
voigt66 d_edotp66;
voigt tot_eps; // total strain
voigt sig6_old;
ten4th aux3333;
voigt66 aux66;
real signorm;
real erroral, erral;
real conv_NR, conv_istep_e, conv_istep_s;
voigt res; // residual R to be nullified
voigt66 jacob_inv; // Jacobian of R
int itmaxal, iterl;
int i,j,k;
local_loop{
jph = phase_f[pIDX];
if(!Type_phases[jph-1]){
C6_loop{
sg66[mi][mj] = C_gr[pIDX][mi][mj];
}
LU_inv_66(sg66);
T2_loop{
/* the iteration starts with the current stress field */
xlambda_aux[mi][mj] = Sig[pIDX][mi][mj];
sig_aux[mi][mj] = Sig[pIDX][mi][mj];
/* plastic strain at time t. This is used in Eq. 4 to update total strain
from calculated strain rate*/
eps_aux[mi][mj] = Eps[pIDX][mi][mj];
/* DisGrad stores the updated displacement gradient obtained from Eq. 15.
So here strain_aux/strain6 stores the updated total strain*/
strain_aux[mi][mj] = (DisGrad[pIDX][mi][mj]+DisGrad[pIDX][mj][mi])/2.0;
}
chg_basis(xlambda6,xlambda_aux,aux66,aux3333,2);
chg_basis(sig6,sig_aux,aux66,aux3333,2);
chg_basis(eps6,eps_aux,aux66,aux3333,2);
chg_basis(strain6,strain_aux,aux66,aux3333,2);
signorm = 0.0;
T2_loop{
signorm += xlambda_aux[mi][mj]*xlambda_aux[mi][mj];
}
signorm = sqrt(signorm);
erroral = 1E-7;
itmaxal = 100;
iterl = 0;
erral = 10*erroral;
/* Newton-Raphson method to solve augmented Lagrangians */
while((iterl<itmaxal)&&(fabs(erral)>fabs(erroral))){
iterl++;
for(i=0;i<6;i++) sig6_old[i] = sig6[i];
// /* Update the plastic strain rate based on current stress */
//#ifdef DD_BASED_FLAG
//#ifdef DD_POWER_LAW
// StrainRate_Orowan_POWER(sig6,edotp6,d_edotp66,pIDX,jph);
//#else
// StrainRate_Orowan(sig6,edotp6,d_edotp66,pIDX,jph);
//#endif
//#else
// StrainRate_eval(sig6,edotp6, d_edotp66,pIDX, jph);
//#endif
/* tot_eps is the total strain and eps6 is the
current plastic strain, i.e. Eq. 4 */
for(i=0;i<6;i++){
//tot_eps[i] = eps6[i] + edotp6[i]*TimeStep;
tot_eps[i] = eps6[i];
for(j=0;j<6;j++){
tot_eps[i] += sg66[i][j]*sig6[j];
}
}
// calculate the residual R, Eq. 16
for(i=0;i<6;i++){
res[i] = sig6[i] - xlambda6[i];
for(j=0;j<6;j++){
res[i] += C066[i][j]*(tot_eps[j]-strain6[j]);
}
}
// calculate the Jacobian of R
for(i=0;i<6;i++){
for(j=0;j<6;j++){
jacob_inv[i][j] = (real)(i==j);
for(k=0;k<6;k++){
// Eq. 18
//jacob_inv[i][j] += C066[i][k]*(sg66[k][j]+d_edotp66[k][j]*TimeStep);
jacob_inv[i][j] += C066[i][k]*(sg66[k][j]);
}
}
}
LU_inv_66(jacob_inv);
// Newton-Raphson update
for(i=0;i<6;i++){
for(j=0;j<6;j++){
sig6[i] -= jacob_inv[i][j]*res[j];
}
}
// convergence check
conv_NR= 0.0;
conv_istep_e= 0.0;
conv_istep_s = 0.0;
for(i=0;i<6;i++){
conv_NR += (sig6[i]-sig6_old[i])*(sig6[i]-sig6_old[i]);
conv_istep_e += (tot_eps[i]-strain6[i])*(tot_eps[i]-strain6[i]);
conv_istep_s += (sig6[i]-xlambda6[i])*(sig6[i]-xlambda6[i]);
}
erral = conv_NR/signorm;
// update crss
if((Hard_Flag==1)&&(istep>2)&&(update_flag==1)){
#ifdef DD_BASED_FLAG
trial_DislocationEvolution(pIDX,jph);
#else
/* because the shear rate that is about to use
is calcualted (in StrainRate_eval()) based on
trial stress field, we use the get_trialtau()
subroutine which is a trial versio nof harden() */
//get_trialtau(pIDX,jph);
//get_trialtau_anal(pIDX,jph);
#endif
}
} // end of while() loop
chg_basis(sig6,sig_aux,aux66,aux3333,1);
chg_basis(edotp6,edotp_aux,aux66,aux3333,1);
// update stress and strain rate fields
T2_loop{
Sig[pIDX][mi][mj] = sig_aux[mi][mj];
Edot[pIDX][mi][mj] = edotp_aux[mi][mj];
}
*Err_s_local += conv_istep_s;
*Err_e_local += conv_istep_e;
}
else{
T2_loop{
Sig[pIDX][mi][mj] = 0.0;
Edot[pIDX][mi][mj] = 0.0;
}
}
}
return;
}/*end UpdateStress_DRX()*/
static void get_smacro(void)
{
real local_sigavg, local_sigavg1;
voigt sav6;
voigt5 sav5;
voigt66 aux66;
ten4th aux3333;
int i, ii,jj, k, kk,ll;
int IJV[2][6] = {{0,1,2,1,0,0,},{0,1,2,2,2,1}};
// overal stress
T2_loop{
local_sigavg = 0.0;
local_sigavg1 = 0.0;
local_loop{
local_sigavg += Sig[pIDX][mi][mj];
if(phase_f[pIDX]==1)
local_sigavg1 += Sig[pIDX][mi][mj];
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Allreduce(&local_sigavg, &SigAvg[mi][mj], 1, MPI_real,
MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(&local_sigavg1, &SigAvg1[mi][mj], 1, MPI_real,
MPI_SUM, MPI_COMM_WORLD);
SigAvg[mi][mj] *= WGT;
SigAvg1[mi][mj] *= WGT/Wgt_ph1;
}
for(i=0;i<6;i++){
ii=IJV[0][i];
jj=IJV[1][i];
dDisGradAvg[ii][jj] = 0.0;
if(VelGrad_BC_Flag[i]==0){ // the component controlled by stress, implying a disp. variation
for(k=0;k<6;k++){
kk=IJV[0][k];
ll=IJV[1][k];
dDisGradAvg[ii][jj] += S0[ii][jj][kk][ll]*Stress_BC_Flag[k]*
(Scauchy[kk][ll]-SigAvg[kk][ll]);
}
}
}
T2_loop{
dDisGradAvg_acum[mi][mj] += dDisGradAvg[mi][mj];
}
if(mpirank==0){
// printf("dDisGradAvg(1,1),(2,2) = %e,%e\n",dDisGradAvg[0][0],dDisGradAvg[1][1]);
}
chg_basis(sav6,SigAvg,aux66,aux3333,2);
for(i=0;i<5;i++) sav5[i] = sav6[i];
chg_basis5(sav5,SigDevAvg,aux66,aux3333,1);
s_vm = 0.0;
T2_loop{
if(mi!=mj){
s_vm += SigDevAvg[mi][mj]*SigDevAvg[mi][mj];
}
if(mi==mj){
s_vm += (SigDevAvg[mi][mj] - (SigDevAvg[1][1] + SigDevAvg[2][2] + SigDevAvg[3][3])/3.0)*(SigDevAvg[mi][mj] - (SigDevAvg[1][1] + SigDevAvg[2][2] + SigDevAvg[3][3])/3.0);
}
}
s_vm = sqrt(3./2.*s_vm); // for stress, it is 3/2
chg_basis(sav6,SigAvg1,aux66,aux3333,2);
for(i=0;i<5;i++) sav5[i] = sav6[i];
chg_basis5(sav5,SigDevAvg,aux66,aux3333,1);
s_vm1 = 0.0;
T2_loop{
s_vm1 += SigDevAvg[mi][mj]*SigDevAvg[mi][mj];
}
s_vm1 = sqrt(3./2.*s_vm1);
return;
}/*end get_smacro()*/
void Evolution(void)
{
int step_drx,stop_check,count,tmp_flag;
real dd_temp,dd_ave;
int mesh_count,g_count,i,jph;
double rho_avg[60000];
double ph,th,om;
double tmp[3];
real tmp1;
real tmp_re[3];
real tmp_im[3];
int istep; // step # of deformation test
int iter;
int ntimes;// step # of iteration (within a given istep)
ten2nd DisGradAvg_t = {0.0}; // store the actual macro disp. grad. at time t
ten2nd DisGradAvg_actual = {0.0};
voigt66 c066_local;
ten2nd sym_du_r, sym_du_i;
//int nph1, nph1_all;
voigt aux6;
ten2nd aux33;
ten2nd sa2xt;
std::vector<G_Info>::iterator it, end;
//voigt66 c066_local = {0.0};
//int nph1, nph1_all;
//voigt aux6;
//ten2nd aux33;
step_drx = 0;
double Identity[3][3];
count = 0;
ntimes = 1;
for(iter=0;iter<60000;iter++) {
rho_avg[iter] = 0.0;
}
/* 9/16/15 --- PYZ
* Add a list of isteps (involving PF relaxation) to be recorded for further analysis */
//int RC_LIST[14] = {2259,3497,3684,4499,4908,5480,6499,7480,8502,9500,10400,7879,7910,5276};
int RC_LIST[6] = {9604,9605,9606,9607,9608,9610};
int RC_length = 6;
ten2nd EpsAvg_local, EdotAvg_local;
real evmp, dvmp;
real Err_e_local, Err_s_local;
if(mpirank==0){
printf("\n\n======================================\n");
printf("-------------Simulation starts----------------\n");
}
local_loop{
new_position[pIDX][0] = px+lxs;
new_position[pIDX][1] = py;
new_position[pIDX][2] = pz;
}
for(istep=0;istep<N_steps;istep++){
if(mpirank==0){
printf("\n****************************************\n");
printf("STEP = %d\n",istep);
if(N_steps!=1){
fprintf(fp_err,"STEP = %d\n",istep);
}
}
if(CREEP_FLAG==1&&e_vm>0.3){
break;
}
/* "dDisGradAvg" is the local strain deviation part from
the average, i.e. "E-<e>". It is calculated in get_smacro()
according to Eq. 23 (the second term on the l.h.s). It is
calculated for each mechanical step iteration, and "dDisGradAvg_acum"
is the accumulated value after all the iterations (the following
while loop) for the current mechanical step (istep). */
T2_loop{
if(mi==mj){
Identity[mi][mj] = 1.0;
} else{
Identity[mi][mj] = 0.0;
}
}
//
// /***********************************
// iteration to update stress at t+dt
// ***********************************/
// iter = 0;
// Err_e = 2.*Err;
// Err_s = 2.*Err;
//
// while((iter<IterMax)&&((fabs(Err_s)>fabs(Err))||(fabs(Err_e)>fabs(Err)))){
// iter++;
// if(mpirank==0){
// printf("\nITER = %d\n",iter);
// printf("Forward FFT of stress field\n");
// }
// // k-space stress field
// T2_loop{
// local_loop{
// fft_data[pIDX].re = Sig[pIDX][mi][mj];
// fft_data[pIDX].im = 0.0;
// }
// MPI_Barrier(MPI_COMM_WORLD);
// fftwnd_mpi(plan, 1, fft_data, fft_work, FFTW_NORMAL_ORDER);
// local_loop{
// kSig_r[pIDX][mi][mj] = fft_data[pIDX].re;
// kSig_i[pIDX][mi][mj] = fft_data[pIDX].im;
// }
// }
// local_loop{
// T2_loop{
// sym_du_r[mi][mj] = 0.0;;
// sym_du_i[mi][mj] = 0.0;;
// T2p_loop{
// sym_du_r[mi][mj] += GAMMA[pIDX][mi][mj][mip][mjp]*kSig_r[pIDX][mip][mjp];
// sym_du_i[mi][mj] += GAMMA[pIDX][mi][mj][mip][mjp]*kSig_i[pIDX][mip][mjp];
// }
// }
// T2_loop{
// kSig_r[pIDX][mi][mj] = sym_du_r[mi][mj];
// kSig_i[pIDX][mi][mj] = sym_du_i[mi][mj];
// }
//
// }
//
// if(mpirank==0){
// printf("Inverse FFT to get strain field\n");
// }
// // update strain field in real space
// T2_loop{
// local_loop{
// fft_data[pIDX].re = kSig_r[pIDX][mi][mj];
// fft_data[pIDX].im = kSig_i[pIDX][mi][mj];
// }
// MPI_Barrier(MPI_COMM_WORLD);
// fftwnd_mpi(iplan, 1, fft_data, fft_work, FFTW_NORMAL_ORDER);
// local_loop{
// DisGrad[pIDX][mi][mj] += dDisGradAvg[mi][mj] + fft_data[pIDX].re/Nxyz; // Eq. 15
// }
// }
//
// if(mpirank==0){
// printf("Update stress field\n");
// }
// Err_e_local = 0.0;
// Err_s_local = 0.0;
// //#ifdef DD_BASED_FLAG
// //#ifdef DD_GND
// // // graidents of shear rate and shear
// // Gradient_ShearRate();
// // Gradient_Shear();
// //#endif
// //#endif
// // update stress, which requires Newton-Raphson method
// // NOTE: N-R is run locally. So PEs could run for different iteration steps
// UpdateStress(istep, &Err_e_local, &Err_s_local, 1);
// // collect errors
// MPI_Barrier(MPI_COMM_WORLD);
// MPI_Allreduce(&Err_e_local, &Err_e, 1, MPI_real,
// MPI_SUM, MPI_COMM_WORLD);
// MPI_Allreduce(&Err_s_local, &Err_s, 1, MPI_real,
// MPI_SUM, MPI_COMM_WORLD);
// Err_e *= WGT;
// Err_s *= WGT;
//
// if(mpirank==0){
// printf("ERRE = %e\n",Err_e);
// printf("ERRS = %e\n",Err_s);
// }
//
// // update the average quantities.
// get_smacro();
//
// Err_e /= e_vm;
// Err_s /= s_vm;
// if(mpirank==0){
// printf("Strain field error = %f\n", Err_e);
// printf("Stress field error = %e\n", Err_s);
// fprintf(fp_err,"%d\t%e\t%e\t%e\n",iter,Err_e,Err_s,s_vm);
// fflush(fp_err);
// }
//
// }/* while() loop ends and stress converges */
//
// /* update the velocity gradient field. VelGrad on the r.h.s.
// stores the previous displ. gradient fiels */
// local_loop{
// T2_loop{
// VelGrad[pIDX][mi][mj] = (DisGrad[pIDX][mi][mj] - VelGrad[pIDX][mi][mj])/TimeStep;
// }
// }
// T2_loop{
// // dDisGradAvg_acum is updated in get_smacro()
// /* DisGradAvg is always the initially applied strain based on linear ealstic assumption
// for each mechanical step (istep), and dDisGradAvg_acum is the resulted adjustement
// after the iteration, which depends on the boundary conditon. */
// DisGradAvg_actual[mi][mj] = DisGradAvg[mi][mj] + dDisGradAvg_acum[mi][mj];
// VelGradAvg[mi][mj] = (DisGradAvg_actual[mi][mj]-DisGradAvg_t[mi][mj])/TimeStep;
// }
//
// if(mpirank==0){
// printf("DisGradAvg(1,1),DisGradAvg(2,2),DisGradAvg(3,3)\n");
// printf("%e,%e,%e\n",DisGradAvg_actual[0][0], DisGradAvg_actual[1][1], DisGradAvg_actual[2][2]);
// printf("DisGradAvg(1,1)/DisGradAvg(3,3)\n");
// printf("%e\n",DisGradAvg_actual[0][0]/DisGradAvg_actual[2][2]);
// printf("SigAvg(1,1),SigAvg(2,2),SigAvg(3,3)\n");
// printf("%e,%e,%e\n", SigAvg[0][0],SigAvg[1][1],SigAvg[2][2]);
// }
// e_vm = VonMises(DisGradAvg_actual);
// d_vm = VonMises(VelGradAvg);
// TimeTot += TimeStep;
// T2_loop{
// DisGradAvg_t[mi][mj] = DisGradAvg_actual[mi][mj];
// }
//
// // update strain field
// local_loop{
// T2_loop{
// Eps[pIDX][mi][mj] += Edot[pIDX][mi][mj]*TimeStep; // Edot was updated in UpdateStress()
// }
// }
//
//
//
//
// // Plastic VM
// T2_loop{
// EpsAvg_local[mi][mj] = 0.0;
// EdotAvg_local[mi][mj] = 0.0;
// }
// local_loop{
// T2_loop{
// EpsAvg_local[mi][mj] += Eps[pIDX][mi][mj]*WGT;
// EdotAvg_local[mi][mj] += Edot[pIDX][mi][mj]*WGT;
// }
// }
// T2_loop{
// MPI_Barrier(MPI_COMM_WORLD);
// MPI_Allreduce(&EpsAvg_local[mi][mj], &EpsAvg[mi][mj], 1, MPI_real,
// MPI_SUM, MPI_COMM_WORLD);
// MPI_Allreduce(&EdotAvg_local[mi][mj], &EdotAvg[mi][mj], 1, MPI_real,
// MPI_SUM, MPI_COMM_WORLD);
// }
//
// evmp = 0.0;
// dvmp = 0.0;
// T2_loop{
// evmp += EpsAvg[mi][mj]*EpsAvg[mi][mj];
// dvmp += EdotAvg[mi][mj]*EdotAvg[mi][mj];
// }
// evmp = sqrt(2./3.*evmp);
// dvmp = sqrt(2./3.*dvmp);
//
// if((Update_Flag==1)&&(istep>1)){
// // grain reorientation
// update_orient();
// }
/* Integrated modeling with phase-field */
#ifdef DD_BASED_FLAG
#ifdef PF_DRX
/* updte the GB_indicator */
local_loop{
int chk = (GB_checkX[pIDX][0]+GB_checkX[pIDX][1]+
GB_checkY[pIDX][0]+GB_checkY[pIDX][1]+
GB_checkZ[pIDX][0]+GB_checkZ[pIDX][1]);
/* 09/16/15 --- PYZ */
/* >0: at GB; =0: in bulk */
GB_indicator[pIDX] = 6-chk;
if(chk<6){
GB_indicator[pIDX] = 1; // voxel is adjacent to GB
}
else{
GB_indicator[pIDX] = 0;
}
}
/* Implement the DRX nucleation based
on the dislocation density difference. This
will updat the "diff_rho" */
/* if(gID_rex[pIDX] == 1){
if(gsl_rng_uniform(RandInstance) >= 0.5) {
gID_rex[pIDX] = 0;
if(mpirank==0){
printf("gID_rex = 0.0");
}
}
}*/
// printf("kappa is %le\n",kappa_drx[0]);
//cp
/* sort(gID_list.begin(),gID_list.end(),G_Info::before);
dd_size=gID_list.size();
double *dd_id = (double*)malloc(dd_size*sizeof(double));
dd_index=0;
for(it=gID_list.begin();it!=end;it++){
id1=gID_list.ID;
dd=0;
struct dd_info temp_dd={id1,dd};
dd_list.pushback(temp_dd);
}*/
// dd_size=gID_list.size();
// double *dd_average = (double*)malloc(dd_size*sizeof(double));
// dd_index=0;
//std::vector<G_Info>::iterator it2, end2;
//end2=gID_list.end();
//for(it2=gID_list.begin();it2!=end2;it2++){
//dd_temp = 0.0;
//g_count = 0;
//dd_ave=0.0;
//local_loop{
// if(grain_f[pIDX]==(*it2).ID){
// dd_temp += rho_tot[pIDX];
// g_count ++ ;
/* if((*it2).ID==17){
printf("%lf \n",rho_tot[pIDX]);
// d_index[pIDX]=dd_index;
} */ // }
//}
//printf("dd_average=%lf %d\n",dd_temp,g_count);
//MPI_Barrier(MPI_COMM_WORLD);