-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtensor_ope_module.for
1211 lines (1068 loc) · 45.6 KB
/
tensor_ope_module.for
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
c======================================================================
c Module Tensor operations
c=======================================================================
c This module contains all the operations required to do tensor operations,
c map into equivalent notations of tensor. print in a sorted way in the
c termianl, and auxiliary functions used in testing of the material routine.
c-----------------------------------------------------------------------
c Version 0.9.4 Include Inverse without external package
c Oct 2021
c-----------------------------------------------------------------------
module tensor_operations
c INCLUDE 'ABA_PARAM.INC'
implicit none
contains
c=======================================================================
c subroutine linespace
c=======================================================================
c=======================================================================
c subroutine linespace(ini, end, vector, type): returns a 1st order
C tensor with even spaced double precision numbers according to the size
c of vector
c-----------------------------------------------------------------------
c Inputs
c ini: initial value
c end: end value
c vector: 1st order tensor with the right size to store the result
c type: select if incluedes lower end
c type= 0: not include lower end
c type= 1: includes lower end
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c=======================================================================
subroutine linespace (ini, end, vector, type)
implicit none
double precision ::ini, end
double precision, dimension (:) :: vector
integer :: i, type
if (type==1) then
do i=1, (size(vector,1))
vector(i)=ini+(end-ini)*(i-1)/(size(vector,1)-1)
end do
else
do i=1, (size(vector,1))
vector(i)=ini+(end-ini)*(i)/(size(vector,1))
end do
end if
end subroutine linespace
c=======================================================================
c funcion Trace
c=======================================================================
c=======================================================================
c Returns the trace of a 2nd order tensor
c-----------------------------------------------------------------------
c Inputs
c array: array of size n1xn1
c-----------------------------------------------------------------------
c Output
c tr_A: trace
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c=======================================================================
function Trace(A) result(Tr_A)
implicit none
double precision, dimension(:,:):: A
double precision :: Tr_A
integer n1
Tr_A=0.0
do n1=1,size (A,1)
Tr_A=Tr_A+A(n1,n1)
end do
end function Trace
c=======================================================================
c subroutine Ident1
c=======================================================================
c==================================================================
c subroutine Ident1(array,n1): returns a 2nd order identity tensor
c------------------------------------------------------------------]
c Inputs
c array: array of size n1xn1
c n1 : dimension of the array
c-----------------------------------------------------------------
c Output
c array: identy tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c==================================================================
subroutine Ident1(array,n1)
implicit none
integer:: i, j !iterators
integer:: n1 !dimension square tensor
double precision :: array(n1,n1)
do i=1,n1
do j=1,n1
array(j,i)=0.0
end do
end do
do i=1,n1
array(i,i)=1.0
end do
end subroutine Ident1
c=======================================================================
c function inv_T_2D
c=======================================================================
c=======================================================================
c Returns the inverse of a 2nd order tensor using the LU decomposition.
c Depends on the LAPACK Fortran package
c http://www.netlib.org/lapack/explore-html/dd/d9a/group__double_g_ecomputational_ga0019443faea08275ca60a734d0593e60.html
c-----------------------------------------------------------------------
cInputs
c A: Tensor 2D se nxn
c-----------------------------------------------------------------------
cOutput
c A: inverted tensor
c-----------------------------------------------------------------------
c coded by: W. Mora Oct 2021
c=======================================================================
function inv_T_2D(A) result(Ainv)
external:: DGETRF
external:: DGETRI
double precision, dimension(:,:), intent(in) :: A
double precision, dimension(size(A,1),size(A,2)) :: Ainv
double precision, dimension(size(A,1),size(A,2)) :: Ainv_temp
double precision, dimension(size(A,1)) :: work ! work array for LAPACK
integer, dimension(size(A,1)) :: ipiv ! pivot indices
integer :: n, info
! Store A in Ainv to prevent it from being overwritten by LAPACK
Ainv_temp =dble(A)
n = size(A,1)
! DGETRF computes an LU factorization of a general M-by-N matrix A
! using partial pivoting with row interchanges.
call DGETRF(n, n, Ainv_temp, n, ipiv, info)
!Error mesage genetrated in the LU decomposition, see the possible
!option of values for info in LAPACK documentation
if (info /= 0) then
stop 'function inv_T_2D- Matrix is numerically singular!'
end if
! DGETRI computes the inverse of a matrix using the LU factorization
call DGETRI(n, Ainv_temp, n, ipiv, work, n, info)
!Error mesage genetrated in the LU decomposition, see the possible
!option of values for info in LAPACK documentation
if (info /= 0) then
stop 'Matrix inversion failed!'
end if
Ainv=Ainv_temp
end function inv_T_2D
c=======================================================================
c inv_T_2Dg
c=======================================================================
c=======================================================================
c Returns the inverse of a 2nd order tensor according to the Gaus Jordan
c elimination, the code was modified from
c http://computer-programming-forum.com/49-fortran/6083a0ae451dd206.htm
c-----------------------------------------------------------------------
cInputs
c A: Tensor 2D se nxn
c-----------------------------------------------------------------------
cOutput
c A: inverted tensor
c-----------------------------------------------------------------------
c coded by: -----
c=======================================================================
SUBROUTINE inv_T_2Dg(A,n,Ainv)
INTEGER :: m,n,NMAX
double precision :: a(n,n),Ainv(n,n)
PARAMETER (NMAX=50)
INTEGER :: i,icol,irow,j,k,l,ll,indxc(NMAX),indxr(NMAX),ipiv(NMAX)
double precision :: big,dum,pivinv
Ainv=A
do 11 j=1,n
ipiv(j)=0
11 continue
do 22 i=1,n
big=0.
do 13 j=1,n
if(ipiv(j).ne.1)then
do 12 k=1,n
if (ipiv(k).eq.0) then
if (abs(Ainv(j,k)).ge.big)then
big=abs(Ainv(j,k))
irow=j
icol=k
endif
else if (ipiv(k).gt.1) then
pause 'singular matrix in gaussj'
endif
12 continue
endif
13 continue
ipiv(icol)=ipiv(icol)+1
if (irow.ne.icol) then
do 14 l=1,n
dum=Ainv(irow,l)
Ainv(irow,l)=Ainv(icol,l)
Ainv(icol,l)=dum
14 continue
c do 15 l=1,m
c dum=b(irow,l)
c b(irow,l)=b(icol,l)
c b(icol,l)=dum
c 15 continue
endif
indxr(i)=irow
indxc(i)=icol
if (Ainv(icol,icol).eq.0.) pause 'singular matrix in gaussj'
pivinv=1./Ainv(icol,icol)
Ainv(icol,icol)=1.
do 16 l=1,n
Ainv(icol,l)=Ainv(icol,l)*pivinv
16 continue
c do 17 l=1,m
c b(icol,l)=b(icol,l)*pivinv
c 17 continue
do 21 ll=1,n
if(ll.ne.icol)then
dum=Ainv(ll,icol)
Ainv(ll,icol)=0.
do 18 l=1,n
Ainv(ll,l)=Ainv(ll,l)-Ainv(icol,l)*dum
18 continue
c do 19 l=1,m
c b(ll,l)=b(ll,l)-b(icol,l)*dum
c 19 continue
endif
21 continue
22 continue
do 24 l=n,1,-1
if(indxr(l).ne.indxc(l))then
do 23 k=1,n
dum=Ainv(k,indxr(l))
Ainv(k,indxr(l))=Ainv(k,indxc(l))
Ainv(k,indxc(l))=dum
23 continue
endif
24 continue
return
END subroutine inv_T_2Dg
c=======================================================================
c inv_T_2Dd
c=======================================================================
c=======================================================================
c Returns the inverse of a 2nd order tensor of maximum size equal to 3x3
c-----------------------------------------------------------------------
cInputs
c A: Tensor 2D se 2x2 or 3x3
c-----------------------------------------------------------------------
cOutput
c A: inverted tensor
c n: size of square matrix
c-----------------------------------------------------------------------
c coded by: W. Mora Oct 2021
c=======================================================================
subroutine inv_T_2Dd(A,n,Ainv)
c INCLUDE 'ABA_PARAM.INC'
Implicit none
integer :: n
double precision :: A(n,n), Ainv(n,n)
double precision :: Det
double precision::Ainv2(2,2), Ainv3(3,3), Cof(3,3), Adj(3,3)
if (n==2) then
Det=A(1,1)*A(2,1)-A(1,2)*A(2,1)
if (Det==0) then
WRITE(6,1)
1 FORMAT(//,30X,'***Error - Singular matrix',
1 'without inverse')
end if
Ainv=reshape((/A(2,2), -A(1,2),
& -A(2,1), A(1,1)/), shape(Ainv2), order=(/2,1/))
& /Det
!In this case Dets is the cofactor matrix
elseif (n==3) then
Cof(1,1)=A(2,2)*A(3,3)-A(2,3)*A(3,2)
Cof(2,1)=-(A(1,2)*A(3,3)-A(1,3)*A(3,2))
Cof(3,1)=A(1,2)*A(2,3)-A(1,3)*A(2,2)
Cof(1,2)=-(A(2,1)*A(3,3)-A(2,3)*A(3,1))
Cof(2,2)=A(1,1)*A(3,3)-A(1,3)*A(3,1)
Cof(3,2)=-(A(1,1)*A(2,3)-A(1,3)*A(2,1))
Cof(1,3)=A(1,2)*A(2,3)-A(1,3)*A(2,2)
Cof(2,3)=(A(1,1)*A(2,3)-A(1,3)*A(2,2))
Cof(3,3)=A(1,1)*A(2,2)-A(1,2)*A(2,1)
!Adjugate Matrix
Adj(1,1)=Cof(1,1)
Adj(2,1)=Cof(1,2)
Adj(3,1)=Cof(1,3)
Adj(1,2)=Cof(2,1)
Adj(2,2)=Cof(2,2)
Adj(3,2)=Cof(2,3)
Adj(1,3)=Cof(3,1)
Adj(2,3)=Cof(3,2)
Adj(3,3)=Cof(3,3)
Det=(A(1,1)*Cof(1,1)+A(2,1)*Cof(2,1)+A(3,1)*Cof(3,1))
if (Det==0) then
WRITE(6,1)
end if
Ainv=Adj/Det
else
WRITE(6,2)
2 FORMAT(//,30X,'***Error -This function can be used only with',
2 '2x2 and 3x3 matrices')
end if
end subroutine inv_T_2Dd
c=======================================================================
c subroutine I4dikdjl
cc=======================================================================
cc==================================================================
c Returns the 4th order unit tensor I4ikjl
c-----------------------------------------------------------------------c-----------------------------------------------------------------------
cInputs
c I4dikdjl_o: 4th order tensor
c-----------------------------------------------------------------------
c coded by: W. Mora Oct 2021
c=====================================================================
subroutine I4dikdjl(I4dikdjl_o)
implicit none
integer:: i, j, k , l !iterators
integer:: n1 !matrix dimension
double precision, dimension(3,3,3,3)::I4dikdjl_o
double precision, dimension(3,3):: I_3D !Auxiliary 2D order tensors
n1=3
call Ident1(I_3D,n1)
do i=1,n1
do j=1,n1
do k=1,n1
do l=1,n1
I4dikdjl_o(i,j,k,l)=I_3D(i,k)*I_3D(j,l)
end do
end do
end do
end do
end subroutine I4dikdjl
c=======================================================================
c subroutine I4dildjk
c=======================================================================
c=======================================================================
c Returns the 4th order unit tensor Iiljk
c-----------------------------------------------------------------------
cInputs
c I4dildjk_o: 4th order tensor
c-----------------------------------------------------------------------
c coded by: W. Mora Oct 2021
c=====================================================================
subroutine I4dildjk(I4dildjk_o)
implicit none
integer:: i, j, k , l !iterators
integer:: n1 !matrix dimension
double precision, dimension(3,3,3,3)::I4dildjk_o
double precision, dimension(3,3):: I_3D !Auxiliary 2D order tensors
n1=3
call Ident1(I_3D,n1)
do i=1,n1
do j=1,n1
do k=1,n1
do l=1,n1
I4dildjk_o(i,j,k,l)=I_3D(i,l)*I_3D(j,k)
end do
end do
end do
end do
end subroutine I4dildjk
c=======================================================================
c subroutine I4dildjk
c=======================================================================
c=======================================================================
c Returns the 4th order unit tensor Iiljk
c-----------------------------------------------------------------------
cInputs
c I4dildjk_o: 4th order tensor
c-----------------------------------------------------------------------
c coded by: W. Mora Oct 2021
c=====================================================================
subroutine I4dijdkl(I4dijdkl_o)
implicit none
integer:: i, j, k , l !iterators
integer:: n1 !matrix dimension
double precision, dimension(3,3,3,3)::I4dijdkl_o
double precision, dimension(3,3):: I_3D !Auxiliary 2D order tensors
n1=3
call Ident1(I_3D,n1)
do i=1,n1
do j=1,n1
do k=1,n1
do l=1,n1
I4dijdkl_o(i,j,k,l)=I_3D(i,j)*I_3D(k,l)
end do
end do
end do
end do
end subroutine I4dijdkl
c======================================================================
c Subroutine I4sym
c=======================================================================
c==================================================================
c Returns the 4th order symmetric identity tensor
c-------------------------------------------------------------------
cInputs
c I4sym_o: 4th order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c=====================================================================
subroutine I4sym(I4sym_o)
implicit none
integer:: i, j, k , l !iterators
integer:: n1 !matrix dimension
double precision, dimension(3,3,3,3)::I4sym_o
double precision, dimension(3,3):: I_3D !Auxiliary 2D order tensors
n1=3
call Ident1(I_3D,n1)
do i=1,n1
do j=1,n1
do k=1,n1
do l=1,n1
I4sym_o(i,j,k,l)=(1.0/2.0)*(I_3D(i,k)*
& I_3D(j,l)+I_3D(i,l)*I_3D(j,k))
end do
end do
end do
end do
end subroutine I4sym
c======================================================================
c subroutine P4sym
c=======================================================================
c==================================================================
c Returns 4th order deviatoric projection tensor
c------------------------------------------------------------------]
cInputs
c P4sym: 4th order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
subroutine P4sym(P4sym_o)
implicit none
integer:: i, j, k , l !iterators
integer:: n1 !matrix dimension
double precision, dimension(3,3,3,3)::I4sym_o, P4sym_o !4th order tensors
double precision, dimension(3,3):: I_3D !Auxiliary 2D order tensors
n1=3
call Ident1(I_3D,n1)
call I4sym(I4sym_o)
do i = 1,3
do j = 1,3
do k = 1,3
do l = 1,3
P4sym_o(i,j,k,l) =0.0
P4sym_o(i,j,k,l) =I4sym_o(i,j,k,l)-
& I_3D(i,j)*I_3D(k,l)/3.000000
end do
end do
end do
end do
end subroutine P4sym
c======================================================================
c Subroutine invT4
c=======================================================================
c==================================================================
c inverts a 4th order tensor
c------------------------------------------------------------------]
cInputs
c tensor: 4th order tensor to invert
c tensor_In: inverted tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
subroutine invT4(tensor,tensor_Inv)
implicit none
integer:: i, j, k , l !iterators
integer:: n1 !matrix dimension
double precision, dimension(3,3,3,3)::tensor, tensor_Inv !4th order tensors
double precision, dimension(6,6)::A6x6, A6x6_inv !Auxiliary 2D order
call T4th_2_Voig(tensor, A6x6)
call inv_T_2Dg(A6x6, 6,A6x6_inv)
call Voig_2_T4th(A6x6_inv,tensor_Inv)
end subroutine invT4
c=======================================================================
c Function contrac_2nd_2nd
c=======================================================================
c=======================================================================
c Returns the contraction between two second order tensors
c-----------------------------------------------------------------------
cInputs
c T_2D_1: 2nd order tensor
c T_2D_2: 2nd order tensor
c------------------------------------------------------------------------
cOutput
c Contr: result of the contraction, 0 order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
function contrac_2nd_2nd(T_2D_1, T_2D_2) result(Contr)
implicit none
double precision, dimension(:,:) :: T_2D_1, T_2D_2 !2nd order tensor
double precision :: Contr !Result of the contraction
integer:: i, j !Iterators
integer:: n !dimension tensor.
Contr =0.00000000
n=size(T_2D_1,1)
do i=1,n
do j=1,n
Contr =Contr+ T_2D_1(j,i)*T_2D_2(j,i)
end do
end do
end function contrac_2nd_2nd
c======================================================================
c Fucntion diadic_prod_T2_T2
c=======================================================================
c==================================================================
c Returns the diadic product between two second order tensors
c------------------------------------------------------------------]
cInputs
c T_2D_1: 2nd order tensor
c T_2D_2: 2nd order tensor
c Diad: result of the diadic product, 4th order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
function diadic_prod_T2_T2(T_2D_1,T_2D_2) result(Diad)
implicit none
double precision, dimension(:,:) :: T_2D_1, T_2D_2 !2nd order tensor
double precision, dimension(size(T_2D_1,1),size(T_2D_1,1),
& size(T_2D_1,1),size(T_2D_1,1)):: Diad !4th order tensor
integer:: i, j, k, l !Iterators
integer:: n,n2 !size dimension tensor
n=size(T_2D_1,1)
n2=size(Diad,4)
do i=1,n
do j=1,n
do k=1,n
do l=1,n
Diad(j,i,l,k) = T_2D_1(j,i)*T_2D_2(l,k)
end do
end do
end do
end do
end function diadic_prod_T2_T2
c=======================================================================
c function contrac_4th_2nd
c=======================================================================
c=======================================================================
c Returns the contraction between a 4th order tensor a a 2nd order tensor
c-----------------------------------------------------------------------
cInputs
c T_4th: 4th order tensor
c T_2D: 2nd order tensor
c-----------------------------------------------------------------------
cOutput
c Contr: result of the contraction, a 2nd order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c=======================================================================
function contrac_4th_2nd(T_4th,T_2D) result(Contr)
implicit none
double precision, dimension(3,3,3,3):: T_4th !2nd order tensor
double precision, dimension(size(T_4th,3),size(T_4th,4)) ::T_2D
$ , Contr !4th order tensor
integer:: i, j, k, l
integer:: n !size dimension tensor
n=size(T_4th,1)
do i=1,3
do j=1,3
do k=1,3
do l=1,3
!Contr(j,i) =Contr(j,i)+T_4th(j,i,l,k)*T_2D(l,k)
Contr(i,j)= Contr(i,j)+T_4th(i,j,k,l)*T_2D(k,l)
end do
end do
end do
end do
end function contrac_4th_2nd
c======================================================================
c subroutine Voig_2_T4th
c=======================================================================
c==================================================================
c maps a 2D (6x6) tensor in voigth notation into a 4th order tensor
c------------------------------------------------------------------]
cInputs
c tensor: 4th order tensor to map
c T_2D: Voigth notation (6x6) 2nd order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
subroutine voig_2_T4th(T_2D, tensor_4th)
implicit none
integer:: i, j, k , l !iterators
integer:: n1,n2,elements !dimension matrix
integer, dimension(3,3)::nn !Auxiliar iterators
double precision, dimension(6,6)::T_2D !2nd order tensor
double precision, dimension(6,6):: Aux,temp !2nd order auxiliary tensor
double precision, dimension(3,3,3,3)::tensor_4th !4th order
double precision:: sq2, tem_n1, tem_n2 !Auxiliary scalars
sq2 =2.00000**0.5
tem_n1=1.0
tem_n2=2.0
Aux=reshape((
& / tem_n1, tem_n1, tem_n1, sq2, sq2, sq2,
& tem_n1, tem_n1, tem_n1, sq2, sq2, sq2,
& tem_n1, tem_n1, tem_n1, sq2, sq2, sq2,
& sq2, sq2, sq2, tem_n2, tem_n2, tem_n2,
& sq2, sq2, sq2, tem_n2, tem_n2, tem_n2,
& sq2, sq2, sq2, tem_n2, tem_n2, tem_n2 /),
& shape(Aux), order=(/2,1/) )
nn=reshape(( /1, 4, 6,
& 4, 2, 5,
& 6, 5, 3/),shape(nn), order =(/2,1/))
do i=1,6
do j=1,6
temp(j,i)=0
temp(j,i)=T_2D(j,i)/Aux(j,i)
end do
end do
do i=1,3
do j=1,3
do k=1,3
do l=1,3
tensor_4th(i,j,l,k)=temp(nn(i,j),nn(l,k))
end do
end do
end do
end do
end subroutine voig_2_T4th
c======================================================================
c subroutine T4th_2_Voig
c=======================================================================
c==================================================================
c maps a 4th order tensor into a 2th order tensor according
cthe voight notation
c------------------------------------------------------------------]
cInputs
c tensor: 4th order tensor to map
c Vn_2D: kelvin notation 6x6 2nd order tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
subroutine T4th_2_Voig(tensor_4th, Vn_2D)
implicit none
integer:: i, j, k , l !iterators
integer:: n1,n2,elements !dimension matrix
double precision, dimension(3,3,3,3)::tensor_4th !4nd order tensor
double precision, dimension(6,6)::Vn_2D !2nd order tensor
double precision:: sq2,const1 !Auxiliary scalar
sq2 =2.000000**0.5
const1=2.000000
elements=size(tensor_4th)
n1=size(tensor_4th,1)
n2=size(tensor_4th,2)
if (elements .eq. 81) then
Vn_2D=reshape( (
& /tensor_4th(1,1,1,1), tensor_4th(1,1,2,2),
& tensor_4th(1,1,3,3), sq2*tensor_4th(1,1,1,2),
& sq2*tensor_4th(1,1,2,3), sq2*tensor_4th(1,1,1,3),
& tensor_4th(2,2,1,1), tensor_4th(2,2,2,2),
& tensor_4th(2,2,3,3), sq2*tensor_4th(2,2,1,2),
& sq2*tensor_4th(2,2,2,3), sq2*tensor_4th(2,2,1,3),
& tensor_4th(3,3,1,1), tensor_4th(3,3,2,2),
& tensor_4th(3,3,3,3), sq2*tensor_4th(3,3,1,2),
& sq2*tensor_4th(3,3,2,3), sq2*tensor_4th(3,3,1,3),
& sq2*tensor_4th(1,2,1,1), sq2*tensor_4th(1,2,2,2),
& sq2*tensor_4th(1,2,3,3), const1*tensor_4th(1,2,1,2),
& 2*tensor_4th(1,2,2,3), const1*tensor_4th(1,2,1,3),
& sq2*tensor_4th(2,3,1,1), sq2*tensor_4th(2,3,2,2),
& sq2*tensor_4th(2,3,3,3), const1*tensor_4th(2,3,1,2),
& const1*tensor_4th(2,3,2,3), const1*tensor_4th(2,3,1,3),
& sq2*tensor_4th(1,3,1,1), sq2*tensor_4th(1,3,2,2),
& sq2*tensor_4th(1,3,3,3), const1*tensor_4th(1,3,1,2),
& const1*tensor_4th(1,3,2,3), const1*tensor_4th(1,3,1,3)/),
& shape(Vn_2D), order=(/2,1/) )
end if
end subroutine T4th_2_Voig
c=======================================================================
c T2nd_2_Voig
c=======================================================================
c=======================================================================
c maps 2nd order tensor to 1st order tensor according the voight
cnotation
c-----------------------------------------------------------------------
cInputs
c T_2D: 6x6 2nd order tensor in voigth notation
c T_1D: vector 6 size in voigth notation
c-----------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c=======================================================================
subroutine T2nd_2_Voig(T_2D,T_1D)
implicit none
integer:: i, j !iterators
integer:: n1,n2,elements !dimension matrix
double precision, dimension(6,6)::T_2D !2nd order tensor
double precision, dimension(6)::T_1D !1st order tensor
double precision:: sq2 !Auxiliar scalar
sq2 =2.0**0.5
elements=size(T_2D)
if (elements==9) then
T_1D=(/T_2D(1,1), T_2D(2,2), T_2D(3,3), sq2*T_2D(1,2),
& sq2*T_2D(2,3), sq2*T_2D(1,3)/)
end if
end subroutine T2nd_2_Voig
c=======================================================================
c 4th_2_66_sym
c=======================================================================
c=======================================================================
c maps 4th order symmetric tensor to 2nd order tensor 6 x 6
c-----------------------------------------------------------------------
cInputs
c tensor_4th : 4th order symmetric tensor
c M66: 6x6 2nd order tensor in voigth notation
c-----------------------------------------------------------------------
c coded by: W. Mora Oct 2021
c=======================================================================
subroutine m4th_2_66_sym (tensor_4th, M66)
implicit none
integer, dimension(6):: ii, jj
integer:: rc, sc
double precision:: M66(6,6), tensor_4th(3,3,3,3)
ii = (/1,2,3,1,2,1/)
jj = (/1,2,3,2,3,3/)
do rc=1,6
do sc=1,6
M66(rc,sc) = tensor_4th(ii(rc),jj(rc),ii(sc),jj(sc))
end do
end do
end subroutine m4th_2_66_sym
c======================================================================
c subroutine print_matrix
c=======================================================================
c==================================================================
c subroutine print in the terminal a 2D tensor of dimension n1 x n2
c------------------------------------------------------------------]
c Inputs
c array: array of size n1xn2
c n1, n2 : array dimensions
cc------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c==================================================================
subroutine print_matrix(array,n1,n2)
implicit none
integer:: i, j !iterators
integer:: n1, n2 !dimension matrix
double precision :: array(n1,n2) !2D test tensors
do i=1,n1
write(*,*) (array(i,j), j = lbound(array,2), ubound(array,2))
end do
end subroutine print_matrix
c======================================================================
c subroutine print_4D_tensor
c=======================================================================
c==================================================================
c Prints in the terminal a 4th grade tensor of dimension n1 x n1 x n1 x n1
c------------------------------------------------------------------]
cInputs
c tensor :
c n1 : size of the inner 2nd grade tensor
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c===================================================================
subroutine print_4D_tensor(tensor,n1)
implicit none
integer:: i, j,k,l !iterators
integer:: n1, n2 !dimension matrix
double precision , dimension(3,3,3,3)::tensor !4th order tensor
print*,"tensor 4th grade"
do i = 1,3
do j = 1,3
print*,"submatrix", j,",",i
call print_matrix(tensor(j,i,:,:),n1,n1)
end do
end do
end subroutine print_4D_tensor
c======================================================================
c Subroutine loading2
c=======================================================================
c==================================================================
c Return the ramp of the strain load for a strain driven tension test
c------------------------------------------------------------------
c Inputs
c ltype: load tyoe
c 1. Simple load
c 2. Load and unload (only compression)
c 3.
c 4. Load and compression (full cycle)
c posi_last_time: indeces that indicates the position in the vector
c "t" of last data for each kind of load
c dt: time step size
c t: vector with the range of time for the load, its contents depends
c on each load type
c lam: vector with the range of strain for the load, its contents depends
c on each load type
c load : vector with the strain load ramp
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c==================================================================
subroutine loading2(ltype,posi_last_time,dt,t,lam,load)
!use tensor_operations
implicit none
integer:: ltype, type !
integer, dimension(5) :: posi_last_time
integer::n_step_a, n_step_b, n_step_c
double precision :: dt
double precision, dimension(7) :: t
double precision, dimension(3) ::lam
double precision, dimension(:):: load
double precision, dimension(:), allocatable :: xa, ya, xb, yb,
$ xc, yc
double precision ::xa1, ya1, xb1, yb1, xc1, yc1
double precision ::xa2, ya2, xb2, yb2, xc2, yc2
print*, "Enter load general"
!ltype==1 correspond to a load with one linear load
if (ltype==1) then
type=1
n_step_a=nint((t(2)-t(1))/dt)
allocate (xa(n_step_a+1))
allocate (ya(n_step_a+1))
xa1=t(1); ya1=lam(1)
xa2=t(2); ya2=lam(2)
call linespace(ya1,ya2,ya,type)
load=ya
deallocate(xa)
deallocate(ya)
!ltype==2 correspond to a semicycle with one linear load and a linear unload
elseif (ltype==2) then
type=1
n_step_a=nint((t(2)-t(1))/dt)
allocate (xa(n_step_a+1))
allocate (ya(n_step_a+1))
call linespace(t(1),t(2),xa,type)
xa1=t(1); ya1=lam(1)
xa2=t(2); ya2=lam(2)
call linespace(ya1,ya2,ya,type)
type=0
n_step_b=nint((t(3)-t(2))/dt)
allocate (xb(n_step_b))
allocate (yb(n_step_b))
call linespace(t(2),t(3),xb, type)
xb1=t(2); yb1=lam(2)
xb2=t(3); yb2=lam(1)
yb=(yb2-yb1)/(xb2-xb1)*(xb-xb1)+yb1
deallocate (xa)
deallocate (xb)
load=(/ya,yb/)
deallocate (ya)
deallocate (yb)
print*, "End load 2"
!ltype==4 correspond to a load with 1 load, 1 unload including
! a negative part and a load to the zero point
elseif (ltype==4) then
type=1
n_step_a=nint((t(2)-t(1))/dt)
allocate (xa(n_step_a+1))
allocate (ya(n_step_a+1))
call linespace(t(1),t(2),xa,type)
xa1=t(1); ya1=lam(1)
xa2=t(2); ya2=lam(2)
call linespace(ya1,ya2,ya,type)
type=0
n_step_b=nint((t(3)-t(2))/dt)
allocate (xb(n_step_b))
allocate (yb(n_step_b))
call linespace(t(2),t(3),xb, type)
xb1=t(2); yb1=lam(2)
xb2=t(3); yb2=lam(3)
yb=(yb2-yb1)/(xb2-xb1)*(xb-xb1)+yb1
n_step_c=nint((t(4)-t(3))/dt)
allocate (xc(n_step_c))
allocate (yc(n_step_c))
call linespace(t(3),t(4),xc, type)
xc1=t(3); yc1=lam(3)
xc2=t(4); yc2=lam(1)
yc=(yc2-yc1)/(xc2-xc1)*(xc-xc1)+yc1
deallocate (xa)
deallocate (xb)
deallocate (xc)
load=(/ya, yb, yc/)
deallocate (ya)
deallocate (yb)
deallocate (yc)
print*, "End load 4"
end if
end subroutine loading2
c======================================================================
c function partition_1D
c=======================================================================
c==================================================================
c function partition_1D (T_1D)
c------------------------------------------------------------------]
c Inputs
c T_1D: 1st order tensor dimension 1x6
c-----------------------------------------------------------------
c Outputs
c T_1D_Par: 1st order tensor dimension 1x5
c------------------------------------------------------------------------
c coded by: W. Mora Sep 2021
c==================================================================
function partition_1D(T_1D) result(T_1D_Par)
implicit none
double precision, dimension (6) ::T_1D