-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.f90
223 lines (189 loc) · 6.63 KB
/
model.f90
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
subroutine model( F, YDAT, XDAT, RRR, I, JP)
use force
use fit4_tian
implicit none
real(8) :: F
real(8) :: YDAT(5000) !YDAT(N)
real(8) :: XDAT(5000,3,1000) !XDAT(N,M)
real(8) :: RRR(5000)
integer :: I, JP,ij!, rs
real(8) :: B, P, RES
integer :: IP,IB
integer :: N, M, KK
integer :: iteration
real(8) :: energy!, E_dref, dE,pdens
real(8), dimension(14):: denergy
real(8), dimension(14) ::dEref
real(8) :: ncells, Eref!, delta!, rtemp
COMMON /BLK1/ B(20),P(20),RES,N,M,KK
COMMON/ DJA1/ iteration
COMMON/BLK5/IB(20),IP
! COMMON/debug/ debug(5)
ncells = 1.0d0/((2*rep(1)+1)*(2*rep(2)+1))
pars_l = B(8:14)
pars_p = B(1:7)
! Restrict kappa and eta if V0 too small
! rtemp = pars_l(5) * pars_l(6) *(beta*pars_l(1)-pars_l(6))/(pars_l(7)*8.*pi)
! if (rtemp < 0.0944) then ! Shear modulus of 1.52*10^10 Pa
! call restricted_fit(IP, IB)
! end if
! Primitve Fit Restriction
! Calculate V0 from C44
! do ij = 1,IP
! if (IB(ij) == 12) then
! pars_l(5) = 8.0d0*pi*C44*pars_l(7)/&
! (pars_l(6)*(beta*pars_l(1)-pars_l(6)))
! B(12) = pars_l(5)
! end if
! end do
!
! do ij = 1,IP
! if (IB(ij) == 8) then
! pars_l(1) = c44*8.d0*pi*pars_l(7)/(beta*pars_l(5)*pars_l(6)) &
! + pars_l(6)/beta
! B(8) = pars_l(1)
! end if
! end do
!
! do ij = 1,IP
! if (IB(ij) == 13) then
! pars_l(6) = beta*pars_l(1)*0.5d0+Sqrt(beta**2*pars_l(1)**2*0.25d0&
! -c44*pars_l(7)*8.d0*pi/pars_l(5))
! B(13) = pars_l(6)
! end if
! end do
! Select if derivatives shall be called or not.
if (confname == 'fit') then
select case(jp)
case(1)
call emt_e_fit(xdat(1,:,:nl_atoms+np_atoms), Eref)
call emt_e_fit(xdat(I,:,:nl_atoms+np_atoms), energy)
energy=(energy-Eref)*ncells
F = energy
RES = YDAT(I) - F
! Output option
! if ( ((mod(i,10)==0) .or. (i==N))) then
! if (iteration > 0) write(*,1000) iteration, i, YDAT(i), F, B(1:14)
! !write(*,1000) iteration, i, YDAT(i), YDAT(i)-F, B(1:14)
! end if
case(2)
call emt_de_fit(xdat(1,:,:nl_atoms+np_atoms), Eref, dEref)
call emt_de_fit(xdat(I,:,:nl_atoms+np_atoms), energy, denergy)
energy=(energy-Eref)*ncells
denergy=(denergy-dEref)*ncells
F = energy
RES = YDAT(I) - F
P(1:14)=denergy
! Set derivatives of those parameters zero that aren't supposed to contribute to fit.
do ij=1,IP
P(IB(ij)) = 0.0d0
end do
! !--------WRITE ITERATION AND POINT TO SHOW STATUS ------------
!
! if ( ((mod(i,10)==0) .or. (i==N))) then
! !write(*,1000) iteration, i, YDAT(i), F, B(1:14)
! write(*,1000) iteration, i, YDAT(i), YDAT(i)-F, B(1:14)
! end if
case(3)
pars_l = B(8:14)
pars_p = B(1:7)
call emt_e_fit(xdat(1,:,:nl_atoms+np_atoms), Eref)
call emt_e_fit(xdat(I,:,:nl_atoms+np_atoms), energy)
energy=(energy-Eref)*ncells
F = energy
RES = YDAT(I) - F
if ( ((mod(i,10)==0) .or. (i==N))) then
!if (iteration > 0) write(*,1000) iteration, i, YDAT(i), F, B(1:14)
write(*,1000) iteration, i, YDAT(i), YDAT(i)-F, B(1:14)
!print *, pars_l(5)*pars_l(6)*(beta*pars_l(1)-pars_l(6))/(pars_l(7)*8.0d0*pi)
end if
! NUMERICAL DERIVATIVES
! ! Comment in if you want to Check the Derivatives.
! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms), energy, denergy)
! rs=2
! print *, denergy(rs)
! delta = 0.0001d0
! pars_l(rs) = pars_l(rs) - delta
! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms), E_dref, denergy)
! pars_l(rs) = pars_l(rs) + 2*delta
! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms),energy, denergy)
! pars_l(rs) = pars_l(rs) - delta
! print*, (E_dref-energy)/(2*delta)
! stop
! pars_p(rs) = pars_p(rs) - delta
! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms), E_dref, denergy)
! pars_p(rs) = pars_p(rs) + 2*delta
! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms),energy, denergy)
! pars_p(rs) = pars_p(rs) - delta
! print*, (E_dref-energy)/(2*delta)
! stop
case(4)
call emt_e_fit(xdat(1,:,:), Eref)
call emt_e_fit(xdat(I,:,:), energy)
energy=(energy-Eref)*ncells
F = energy
RRR(I) = F
end select
! IF DENSITY IS FITTED. DON'T DO THAT.
!else if (confname == 'dens') then
! select case(jp)
!
! case(1)
! call emt_dens_fit(xdat(I,:,:nl_atoms+np_atoms), energy, pdens)
! F = pdens
! RES = YDAT(I) - F
!
!
! case(2)
! call emt_ddens_fit(xdat(I,:,:nl_atoms+np_atoms), energy, denergy)
! F = energy
! RES = YDAT(I) - F
! P(1:14)=denergy
! ! Set derivatives of those parameters zero that aren't supposed to contribute to fit.
! do ij=1,IP
! P(IB(ij)) = 0.0d0
! end do
!
! case(3)
! pars_l = B(8:14)
! pars_p = B(1:7)
! call emt_dens_fit(xdat(I,:,:nl_atoms+np_atoms), energy,pdens)
! F = pdens
! RES = YDAT(I) - F
!
! if ( ((mod(i,10)==0) .or. (i==N))) then
! write(*,1000) iteration, i, YDAT(i), YDAT(i)-F, B(1:14)
! end if
!
!! ! Comment in if you want to Check the Derivatives.
!! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms), energy, denergy)
!! rs=7
!! delta = 0.0001d0
!!! print *, denergy(rs+7)
!!! pars_l(rs) = pars_l(rs) - delta
!!! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms), E_dref, denergy)
!!! pars_l(rs) = pars_l(rs) + 2*delta
!!! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms),energy, denergy)
!!! pars_l(rs) = pars_l(rs) - delta
!!! print*, (E_dref-energy)/(2*delta)
!!! stop
!!
!! print *, denergy(rs)
!! pars_p(rs) = pars_p(rs) - delta
!! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms), E_dref, denergy)
!! pars_p(rs) = pars_p(rs) + 2*delta
!! call emt_ddens_fit(xdat(2,:,:nl_atoms+np_atoms),energy, denergy)
!! pars_p(rs) = pars_p(rs) - delta
!! print*, (E_dref-energy)/(2*delta)
!! stop
!
!
! end select
!
end if
! F = energy
! RES = YDAT(I) - F
RETURN
1000 format(2i6, 2f12.4, 7f6.2 / 36x,7f6.2)
1010 format(2i6,3f6.2,3E12.3,14f6.2)
end subroutine MODEL