-
Notifications
You must be signed in to change notification settings - Fork 5
/
kgndl2ET.f
238 lines (166 loc) · 6.51 KB
/
kgndl2ET.f
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
!Least Squares Density Minimisation
subroutine kgndl2ET(curlFp,xNin,xDin,tau,burgerv,iphase,ne,ns,
+ screwplanes,jelem,kint,time,gndall,gndcut,gndmob)
! implicit real*8(a-h,o-z)
implicit none
integer :: i,m,n,ialloc,info
real*8 :: det, costheta, sumtau
real*8,parameter :: zero = 1.0e-6
integer,intent(in):: ne,iphase,jelem,kint,ns,screwplanes
real*8,intent(in) :: time(2)
real*8,intent(in) :: curlFp(3,3),xNin(ne,3),xDin(ne,3),tau(ne),
+ burgerv(ne)
real*8,dimension(3,3) :: xrot,btdyad,bsdyad
real*8,dimension(3) :: tempn,temps,tempt
real*8,dimension(9) :: btvec,bsvec,gv
real*8,dimension(ne+ns,3) :: xLine
real*8, dimension(ne,ne+ns) :: tdotn
!real*8,dimension(:,:),allocatable :: A,A1,A2,Ainv
!real*8,dimension(:),allocatable :: xvec,absgnds
real*8,dimension(9,ne+ns) :: A
real*8,dimension(ne+ns,9) :: Ainv
real*8,dimension(9,9) :: A1, A2
real*8,dimension(ne+ns):: xvec
!real*8,dimension(:),allocatable :: xvec
real*8, dimension(ne) :: gnde
real*8, dimension(ns) :: gnds
integer,dimension(ns) :: screw
integer, dimension(ne) :: stype
integer, dimension(ne, screwplanes-1) :: sgroup
character (len=*), parameter :: fmt2 = "(24(' ',(I2,1X)))",
+ fmt3="(3(' ',(ES11.3,1X)))",
+ fmt9 = "(9(' ',(ES11.3,1X)))",fmt33 = "(33(' ',(ES11.3,1X)))"
real*8,intent(out) :: gndall(ne+ns), gndcut(ne), gndmob
integer :: j
!EXTERNAL DGELSD
!select case(iphase)
!case (0); ns = 9; ne=12; !HCP
!case (1); ns = 4; ne=24 !BCC
!case (2); ns = 6; ne=12 !FCC
!case (4); ns = 2; ne=7 !olivine
!end select
!allocate(absgnds(ns), STAT=ialloc)
select case(iphase) !build up the screw slip systems
case(0) !HCP
!<a> slip
screw(1) = 1
screw(2) = 2
screw(3) = 3
!<c+a>
screw(4) = 7
screw(5) = 8
screw(6) = 9
screw(7) = 10
screw(8) = 11
screw(9) = 12
case(1) ! BCC
!a/2<111>
screw(1) = 1
screw(2) = 2
screw(3) = 3
screw(4) = 6
case(2) ! FCC
screw(1) = 1
screw(2) = 2
screw(3) = 3
screw(4) = 4
screw(5) = 6
screw(6) = 8
case(4) ! olivine
screw(1) = 1
screw(2) = 3
end select
gnde = 0.; gnds = 0.; gndall = 0.0; gndcut = 0.0; gndmob =0.0
!Compute the geometric dislocation tensor
gv = reshape(curlFp,(/9/))!This happens by column.
!===BEGIN LONG IF
if(maxval(abs(gv)) <= zero) then
!Trying to handle the situation when G = 0.
gnde = 0.; gnds = 0.
else
m = 9; n = ne+ns
!allocate(A(m,n),Ainv(n,m),xvec(n),STAT=ialloc)
A = 0.; Ainv = 0.; xvec=0.
!m < n !right inverse
!allocate(A1(m,m),A2(m,m),STAT=ialloc)
A1=0.; A2=0.
!Construct the matrix of dyadics
!Edge
do i = 1,ne
tempn = xNin(i,:)
temps = xDin(i,:)
CALL KVECPROD(temps,tempn,tempt)
btdyad = spread(tempt,2,3)*spread(temps,1,3)*burgerv(i)
A(:,i) = reshape(btdyad,(/9/))
xLine(i,:) = tempt
end do
do i = 1,ns
j = screw(i)
temps = xDin(j,:)
tempt = temps
btdyad = spread(tempt,2,3)*spread(temps,1,3)*burgerv(i)
A(:,ne+i) = reshape(btdyad,(/9/))
xLine(ne+i,:) = tempt
end do
! if ((jelem == 7910 .or. jelem == 8010) .and. kint == 6) then
! write(6,*) "A, ne",ubound(A,1),ubound(A,2),ne
! write(6,fmt33) (A(k,:),k=1,ubound(A,1)) !Print rows
! write(6,*)
! end if
!! call ksvd(A,m,n,Ainv)
!
! m < n right inverse
A1 = matmul(A,transpose(A)) ![9x9] = [9xn][nx9]
call lapinverse(A1,m,info,A2)
if(info /= 0) write(*,*) "inverse failure: A1 in kgndl2"
Ainv = matmul(transpose(A),A2) ![nx9]=[nx9][9x9]
!three-ifs solution
xvec = matmul(Ainv,gv) ![nx1] = [nx9][9x1]
do i=1,ne+ns !ubound(xvec,1)
if (xvec(i) /= xvec(i)) then
xvec(i) = 0.0
write(*,*) "error in kgndl2 jelem,kint,time",jelem,kint,time
end if
end do
!Density to output
gndall = sqrt(xvec*xvec) !sqrt(gnde*gnde +gnds*gnds)
!deallocate(A,A1,A2,Ainv,xvec)
where(gndall > 1.0E7) gndall = 1.0E7 !catching infinities. 1.0e7 for microns, 1.0e19 for metres.
do i =1,ne
tempn = xNin(i,:)
do j=1,n
tempt = xLine(j,:)
CALL KDOTPROD(tempt,tempn,costheta)
tdotn(i,j) = costheta
end do
end do
gndcut= matmul(tdotn,gndall)
gnde = gndall(1:ne)
gnds = gndall(ne:ne+ns)
!do i =1,ne
! j = stype(i)
!
! sumtau = tau(i)
! do n=1,screwplanes-1 ! other possible slip planes which screw could glide on
! sumtau = sumtau + tau(sgroup(i,n))
! end do
!
! gndmob(i) = gnde(i) + gnds(j)*tau(i)/sumtau
!end do
!Ben's experimental data storage groups
!absgnde = sqrt(gnde*gnde); absgnds = sqrt(gnds*gnds)
!if(iphase == 0) then
!!edge
!abasedge = sum(absgnde(1:3))
!aprismedge = sum(absgnde(4:6))
!apyramedge = sum(absgnde(7:12))
!capyramedge = sum(absgnde(13:18))
!!screw
!ascrew = sum(absgnds(1:3))
!capyramscrew = sum(absgnds(4:9))
!end if
!
!===END LONG IF
end if
return
end