-
Notifications
You must be signed in to change notification settings - Fork 2
/
derivs.f
502 lines (333 loc) · 11 KB
/
derivs.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
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
subroutine derivs(p,q,F,alpha,beta,lambda,cnu,df)
implicit none
integer p,q,alpha,beta,mini
integer N
integer nmax
parameter(nmax=500)
double precision F(0:nmax,0:nmax,3,3)
double precision cnu,df,retshift,ds,nu,lambda
double precision sum,sumret,sumcon,sumccr,sumrep
double precision pi,taue, extdot,dssqinv,ds2inv
double precision pp,pm,qp,qm,epsilon,eps2inv
double precision fpq,fpp1q,fpm1q,fpqp1,fpqm1
double precision fpp1qp1,fpm1qm1
double precision feqpq,feqpp1q,feqpm1q,feqpqp1,feqpqm1
double precision trpp,trqq
double precision trppp1,trppm1,trqqp1,trqqm1
double precision trppsr,trqqsr
double precision trppp1sr,trppm1sr,trqqp1sr,trqqm1sr
double precision flampp,flamqq
double precision flamppp1,flamppm1,flamqqp1,flamqqm1
double precision flambylpp,flambylqq
double precision flambylppp1,flambylppm1
double precision flambylqqp1,flambylqqm1
double precision trmsr,trmp1sr,trmm1sr,dclfpq
double precision TrF,Feq,Dclf,flambda,flambdabyl
integer findMini
external TrF,Feq,Dclf,flambda,flambdabyl, findMini
common/retractionshift/RetShift
common/segment/ds,dssqinv,ds2inv
common/epsilon/epsilon,eps2inv
common/taue/taue
common/Pi/pi
common/extension/extdot
common/points/N
nu=Cnu*lambda
sum=0.0
sumret = 0.0
sumcon = 0.0
sumccr = 0.0
sumrep = 0.0
fpq = f(p,q,alpha,beta)
fpp1q = f(p+1,q,alpha,beta)
fpm1q = f(p-1,q,alpha,beta)
fpqp1 = f(p,q+1,alpha,beta)
fpqm1 = f(p,q-1,alpha,beta)
feqpq = feq(p,q,alpha,beta)
feqpp1q = feq(p+1,q,alpha,beta)
feqpm1q = feq(p-1,q,alpha,beta)
feqpqp1 = feq(p,q+1,alpha,beta)
feqpqm1 = feq(p,q-1,alpha,beta)
trpp = TrF(p,p,F)
trqq = TrF(q,q,F)
trppp1 = TrF(p+1,p+1,F)
trppm1 = TrF(p-1,p-1,F)
trqqp1 = TrF(q+1,q+1,F)
trqqm1 = Trf(q-1,q-1,F)
trppsr = dsqrt(TrF(p,p,F))
trqqsr = dsqrt(TrF(q,q,F))
trppp1sr = dsqrt(TrF(p+1,p+1,F))
trppm1sr = dsqrt(TrF(p-1,p-1,F))
trqqp1sr = dsqrt(TrF(q+1,q+1,F))
trqqm1sr = dsqrt(Trf(q-1,q-1,F))
flampp = flambda(p,p,F)
flamqq = flambda(q,q,F)
flamppp1 = flambda(p+1,p+1,F)
flamppm1 = flambda(p-1,p-1,F)
flamqqp1 = flambda(q+1,q+1,F)
flamqqm1 = flambda(q-1,q-1,F)
flambylpp = flambdabyl(p,p,F)
flambylqq = flambdabyl(q,q,F)
flambylppp1 = flambdabyl(p+1,p+1,F)
flambylppm1 = flambdabyl(p-1,p-1,F)
flambylqqp1 = flambdabyl(q+1,q+1,F)
flambylqqm1 = flambdabyl(q-1,q-1,F)
C =======Retraction term======================
C ### (df/dp)*(1/lambda_p)*(dflambda/dp) term ###
sumret=sumret+
& ds2inv*(fpp1q-fpm1q)
& *1.0/trppsr
& *ds2inv*(flamppp1-flamppm1)
sumret=sumret+
& ds2inv*(fpqp1-fpqm1)
& *1.0/trqqsr
& *ds2inv*(flamqqp1-flamqqm1)
C ### f*d(1/lambda_p)/dp*(dflambda/dp) term ###
sumret=sumret+fpq
& *ds2inv*(1.0/trppp1sr-1.0/trppm1sr)
& *ds2inv*(flamppp1-flamppm1)
sumret=sumret+fpq
& *ds2inv*(1.0/trqqp1sr-1.0/trqqm1sr)
& *ds2inv*(flamqqp1-flamqqm1)
C ### f*(1/lambda_p)*(d2/dp^2)flambda term ###
sumret=sumret+fpq
& *1.0/trppsr
& *dssqinv*(flamppp1+flamppm1-2.0*flampp)
sumret=sumret+fpq
& *1.0/trqqsr
& *dssqinv*(flamqqp1+flamqqm1-2.0*flamqq)
sumret=sumret/(Pi**2*taue)*RetShift
C =======Convection term for extension======================
C ### Fxx ###
!if (alpha.EQ.1) then
! if (beta.EQ.1) then
! sumcon=sumcon+2.0*extdot*F(p,q,1,1)
!endif
!endif
C ### Fyy ###
!if (alpha.EQ.2) then
! if (beta.EQ.2) then
! sumcon=sumcon-extdot*F(p,q,2,2)
! endif
!endif
!==shear==
!Fxx
if (alpha.EQ.1) then
if (beta.EQ.1) then
sumcon=sumcon+2.0*extdot*F(p,q,1,2)
endif
endif
!Fxy,yx term
if (alpha.EQ.1) then
if (beta.EQ.2) then
sumcon=sumcon+extdot*F(p,q,2,2)
endif
endif
C =======CCr term======================
C ### f(s,s') terms ###
C ### (Flambda/(lambdap2))*(d^2/ds^2)F term ###
sumccr=sumccr+
& dssqinv*(fpp1q+fpm1q-2.0*fpq)
& *flampp/Trpp
sumccr=sumccr+
& dssqinv*(fpqp1+fpqm1-2.0*fpq)
& *flamqq/Trqq
C ### flambda*(d(1/lambdap2)/ds)*d/ds(F) ###
sumccr=sumccr+flampp
& *ds2inv*(1.0/Trppp1-1.0/Trppm1)
& *ds2inv*(fpp1q-fpm1q)
sumccr=sumccr+flamqq
& *ds2inv*(1.0/Trqqp1-1.0/Trqqm1)
& *ds2inv*(fpqp1-fpqm1)
C ### d(flambda)/ds*(1/lambdap2)*d/ds(F) ###
sumccr=sumccr+
& ds2inv*(flamppp1-flamppm1)
& *1.0/Trpp
& *ds2inv*(fpp1q-fpm1q)
sumccr=sumccr+
& ds2inv*(flamqqp1-flamqqm1)
& *1.0/Trqq
& *ds2inv*(fpqp1-fpqm1)
C ### Extra terms ###
C ### f/lambdap*d2(flambdabyl)/dp2
sumccr=sumccr+fpq/trppsr
& *dssqinv*(flambylppp1+flambylppm1-2.0*flambylpp)
sumccr=sumccr+fpq/trqqsr
& *dssqinv*(flambylqqp1+flambylqqm1-2.0*flambylqq)
C ### (df/ds)*(1/lambdap)*(dflambdabyl/dp)
sumccr=sumccr+1.0/trppsr
& *ds2inv*(fpp1q-fpm1q)
& *ds2inv*(flambylppp1-flambylppm1)
sumccr=sumccr+1.0/trqqsr
& *ds2inv*(fpqp1-fpqm1)
& *ds2inv*(flambylqqp1-flambylqqm1)
C ### f*(d(1/lambdap)/dp)*(dflambdabyl/dp)
sumccr=sumccr+fpq
& *ds2inv*(1.0/trppp1sr-1.0/trppm1sr)
& *ds2inv*(flambylppp1-flambylppm1)
sumccr=sumccr+fpq
& *ds2inv*(1.0/trqqp1sr-1.0/trqqm1sr)
& *ds2inv*(flambylqqp1-flambylqqm1)
C ### feq terms ###
C ### 1/sqrt(TrFpp)(d^2/ds^2)Feq term ###
sumccr=sumccr-
& dssqinv*(Feqpp1q+Feqpm1q-2.0*Feqpq)
& *1.0/trppsr
sumccr=sumccr-
& dssqinv*(Feqpqp1+Feqpqm1-2.0*Feqpq)
& *1.0/trqqsr
C ### d/ds(1/sqrt(TrFpp)*d/ds(Feq) ###
sumccr=sumccr-
& ds2inv*(1.0/trppp1sr-1.0/trppm1sr)
& *ds2inv*(Feqpp1q-Feqpm1q)
sumccr=sumccr-
& ds2inv*(1.0/trqqp1sr-1.0/trqqm1sr)
& *ds2inv*(Feqpqp1-Feqpqm1)
sumccr=sumccr*1.5*nu
C =======Reptation + CLF term======================
C find point closest to chain end
mini=findMini(p,q)
pp=ds*p+epsilon
pm=ds*p-epsilon
qp=ds*q+epsilon
qm=ds*q-epsilon
fpp1qp1 = f(p+1,q+1,alpha,beta)
fpm1qm1 = f(p-1,q-1,alpha,beta)
trmsr = dsqrt(trF(mini,mini,F))
trmp1sr = dsqrt(TrF(mini+1,mini+1,F))
trmm1sr = dsqrt(TrF(mini-1,mini-1,F))
dclfpq = Dclf(ds*p,ds*q)
C ### (d/dp+d/dq)Dclf*(1/sqrt(Trfmin))*(d/dp+d/dq)F ###
sumrep=sumrep+
& eps2inv*(Dclf(pp,qp)-Dclf(pm,qm))
& *1.0/trmsr
& *ds2inv*(fpp1qp1-fpm1qm1)
C ### Dclf*(d/dp+d/dq)(1/sqrt(Trfmin))*(d/dp+d/dq)F
sumrep=sumrep+
& Dclfpq
& *ds2inv*(1.0/trmp1sr-1.0/trmm1sr)
& *ds2inv*(fpp1qp1-fpm1qm1)
C ### Dclf*(1/sqrt(Trfmin))*(d/dq+d/dq)**2F ###
sumrep=sumrep+
& Dclfpq/trmsr
& *dssqinv*(fpp1qp1+fpm1qm1-2.0*fpq)
sumrep=sumrep*1.0/(3.0*Pi**2*taue)*(1.0/trmsr)
df = sumret + sumcon + sumccr + sumrep
return
end
Double Precision function TrF(p,q,F)
implicit none
integer p,q
integer nmax
parameter(nmax=500)
double precision F(0:nmax,0:nmax,3,3)
TrF=F(p,q,1,1)+2.0*F(p,q,2,2)
end function
Double precision function flambda(p,q,F)
implicit none
integer p,q
integer nmax
double precision term,lambdam2,const,trace
double precision TrF
external TrF
common/lambdamaxsq/lambdam2
common/constant/const
parameter(nmax=500)
double precision F(0:nmax,0:nmax,3,3)
trace = TrF(p,q,F)
if (trace .gt. lambdam2) then
write(*,*) "Lambda exceeding lambda_max !!!!!!"
write(*,*) lambdam2,trace
stop
endif
term=(lambdam2-trace/3.0)/(lambdam2-trace)
term=dsqrt(trace)*term
flambda=term*const
end function
Double precision function flambdabyl(p,q,F)
implicit none
integer p,q
integer nmax
double precision term,lambdam2,const,trace
double precision TrF
external TrF
common/lambdamaxsq/lambdam2
common/constant/const
parameter(nmax=500)
double precision F(0:nmax,0:nmax,3,3)
trace = TrF(p,q,F)
term=(lambdam2-trace/3.0)/(lambdam2-trace)
flambdabyl=term*const
end function
Double Precision function Feq(p,q,alpha,beta)
implicit none
integer p,q,alpha,beta
double precision dum,ds,preal,qreal,dssqinv,ds2inv
common/segment/ds,dssqinv,ds2inv
dum=0.0
preal = 1.0*p
qreal = 1.0*q
if(dabs(preal-qreal).lt.ds2inv) then
if(alpha.EQ.beta) then
dum=1.0/3.0
endif
endif
Feq=dum
end function
Double Precision Function Dclf(p,q)
implicit none
Double Precision alphad,s,p,q,zreal
integer z
common/entanglements/Z
zreal = 1.0*z
alphad=1.15
s=Min(1.0*p,1.0*q,1.0*(Z-p),1.0*(Z-q))
if (s.lt.alphaD*dsqrt(zreal)) then
Dclf=(alphaD/s)**2
else
if(s.gt.Zreal-alphaD*dsqrt(zreal)) then
Dclf=(alphaD/(s-Zreal))**2
else
Dclf=1.0/Zreal
endif
endif
end function
Integer function findMini(p,q)
implicit none
integer :: p,q, answ,N
common/points/N
if(p==q) then
answ=p
endif
if( (1.0*p< 1.0*N/2.0) .AND. (1.0*q<1.0*N/2.0)) then
answ = min( p,q)
endif
if( (1.0*p > 1.0*N/2.0) .AND. (1.0*q > 1.0*N/2.0)) then
answ = max(p,q)
endif
if( (1.0*p < 1.0*N/2.0) .AND. (1.0*q > 1.0*N/2.0)) then
if( p< N-q) then
answ = p
else
answ = q
endif
endif
if( (1.0*p > 1.0*N/2.0) .AND. (1.0*q < 1.0*N/2.0)) then
if( q< N-p) then
answ = q
else
answ = p
endif
endif
if(p==q) then
answ=p
endif
if(p==N/2) then
answ = q
endif
if(q==N/2) then
answ = p
endif
!print*,"mini",p,q,N, N/2, answ
findMini = answ
end function findMini