-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule_Thickness_GRAV_Arrhenius.f90
615 lines (528 loc) · 27.6 KB
/
Module_Thickness_GRAV_Arrhenius.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
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
MODULE MODULE_THICKNESS_NEWTON_GRAV_ARRHENIUS
CONTAINS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! SUBROUTINE THICKNESS_NEWTON_SOLVER
SUBROUTINE THICKNESS_NEWTON_GRAV_ARRHENIUS(H,P,T,BL,Ts,Dt,Dr,M,dist,ray,el,grav,sigma,nu,&
&delta0,z,F_err,theta)
!*****************************************************************
!Solve for the thickness in the thickenss evolution equation using the Newton
! method
!*****************************************************************
IMPLICIT NONE
! Tableaux
DOUBLE PRECISION , DIMENSION(:,:), INTENT(INOUT) :: H,P
DOUBLE PRECISION, DIMENSIOn(:,:), INTENT(IN) :: T,BL,Ts
DOUBLE PRECISION , DIMENSION(:), INTENT(IN) :: dist,ray
!Parametre du model
DOUBLE PRECISION , INTENT(IN) :: Dt,Dr,theta
!Nombre sans dimensions
DOUBLE PRECISION , INTENT(IN) :: el,grav,sigma,nu,delta0
INTEGER, INTENT(IN) :: M, z
DOUBLE PRECISION , INTENT(INOUT) :: F_err
!Variable du sous programmes
DOUBLE PRECISION, DIMENSION(:,:), ALLOCATABLE :: Coeff
DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: fguess,ftmps
DOUBLE PRECISION, DIMENSION(:),ALLOCATABLE :: a,b,c,d,e,f,g,k,l,S
DOUBLE PRECISION, DIMENSION(:),ALLOCATABLE :: a1,b1,c1,d1,e1,f1,g1,k1,l1
DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: Hm,qa
DOUBLE PRECISION :: U,Test_Eta,Test_Eta2
INTEGER :: ndyke,i,N,Size,code
INTEGER :: err1,col,algo1
LOGICAL :: cho
! Taille de la grille sur laquelle on fait l'inversion
ndyke=sigma/Dr
CHO=COUNT(H(:,2)>0.D0)<ndyke
SELECT CASE (CHO)
CASE(.TRUE.)
N = ndyke+1
CASE(.FALSE.)
N = COUNT(H(:,2)>1D-10)
Test_Eta = ABS((H(N,2)-H(N-1,2))/Dr)
Test_Eta2 =H(N,2)/Dr
! print*,Test_Eta,Test_Eta2
IF (Test_Eta2 >Test_Eta) THEN
N = N+1
ENDIF
END SELECT
! Caracterisation du flux
ALLOCATE(qa(1:N),stat=err1)
IF (err1>1) THEN
PRINT*, 'Erreur alloc flux';STOP
END IF
DO i = 1,N,1
U = 2.d0/(sigma)**4.
IF (i<ndyke+1) THEN
qa(i) = U*(sigma**2.-dist(i)**2.)
ELSE
qa(i) = 0.d0
END IF
END DO
! Calcule coefficient pression elastique
ALLOCATE(Coeff(1:N,7),stat=err1)
IF (err1>1) THEN
PRINT*, 'Erreur alloc dans coeff du systeme'; STOP
END IF
! Calcule de f tmps n et n+1
ALLOCATE(ftmps(1:N),fguess(1:N),stat=err1)
IF (err1>1) THEN
PRINT*, 'Erreur de f';STOP
END IF
col=1
CALL THICKNESS(ftmps,col,N,M,H,P,T,BL,Ts,Coeff,Dt,Dr,dist,ray,qa,el,grav,nu,delta0)
col=2
CALL THICKNESS(fguess,col,N,M,H,P,T,BL,Ts,Coeff,Dt,Dr,dist,ray,qa,el,grav,nu,delta0)
! Jacbienne
ALLOCATE(a1(1:N),b1(1:N),c1(1:N),d1(1:N),e1(1:N), stat = err1)
ALLOCATE(f1(1:N),g1(1:N),k1(1:N),l1(1:N), stat = err1)
IF (err1>1) THEN
PRINT*, 'Erreur d''allocation dans coeff du systeme'; STOP
END IF
CALL JACOBI_THICKNESS(a1,b1,c1,d1,e1,f1,g1,k1,l1,N,M,H,P,T,BL,Ts,Coeff,Dt,Dr,dist,ray,el,grav,nu,delta0)
!Systeme a inverser
ALLOCATE(a(1:N),b(1:N),c(1:N),d(1:N),e(1:N),stat = err1)
ALLOCATE(f(1:N),g(1:N),k(1:N),l(1:N),S(1:N),stat = err1)
IF (err1>1) THEN
PRINT*, 'Erreur d''allocation dans coeff du systeme'; STOP
END IF
DO i=1,N,1
a(i)=-theta*Dt*a1(i)
b(i)=-theta*Dt*b1(i)
c(i)=-theta*Dt*c1(i)
d(i)=-theta*Dt*d1(i)
e(i)=1.d0-theta*Dt*e1(i)
f(i)=-theta*Dt*f1(i)
g(i)=-theta*Dt*g1(i)
k(i)=-theta*Dt*k1(i)
l(i)=-theta*Dt*l1(i)
S(i)=H(i,1)-H(i,2)+theta*Dt*fguess(i)+(1-theta)*Dt*ftmps(i)
END DO
d(1)=0.d0
f(N) =0.d0
!Inversion de la matrice
ALLOCATE(Hm(1:N),stat=err1)
IF (err1>1) THEN
PRINT*, 'Erreur d''allocation dans vecteur Hm'; STOP
END IF
CALL TRIDIAG(d,e,f,S,N,Hm)
DO i=1,N,1
H(i,3)=Hm(i)+H(i,2)
END DO
! Calcul du soeuil F_err
IF (DOT_PRODUCT(H(:,2),H(:,2)) == 0D0) THEN
F_err = ABS(MAXVAL((Hm(:))))
ELSE
Size = COUNT(H(:,2)>0D0)
F_err = ABS(MAXVAL((H(:Size,3)-H(:Size,2))/H(:Size,2)))
ENDIF
DEALLOCATE(Hm,a,b,c,d,e,f,g,k,l,S,Coeff,qa)
DEALLOCATE(fguess,ftmps,a1,b1,c1,d1,e1,f1,g1,k1,l1)
END SUBROUTINE THICKNESS_NEWTON_GRAV_ARRHENIUS
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
! SUBROUTINE THICKNESS
!-------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------
SUBROUTINE THICKNESS(f,col,N,M,H,P,T,BL,Ts,Coeff,Dt,Dr,dist,ray,qa,el,grav,nu,delta0)
!*****************************************************************
! Give the vector f
!*****************************************************************
IMPLICIT NONE
! Tableaux
DOUBLE PRECISION ,DIMENSION(:) , INTENT(INOUT) :: f
DOUBLE PRECISION ,DIMENSION(:,:), INTENT(IN) :: H,T,BL,Ts
DOUBLE PRECISION ,DIMENSION(:,:), INTENT(INOUT) :: P,Coeff
DOUBLE PRECISION ,DIMENSION(:), INTENT(IN) :: qa
DOUBLE PRECISION ,DIMENSION(:), INTENT(IN) :: dist,ray
! Prametre du model
DOUBLE PRECISION ,INTENT(IN) :: Dt,Dr
INTEGER ,INTENT(IN) :: col,N,M
DOUBLE PRECISION, PARAMETER :: pi=3.14159265358979d0
! Nombre sans dimension
DOUBLE PRECISION ,INTENT(IN) :: el,grav,nu,delta0
! Parametre pour le sous programme
DOUBLE PRECISION :: h_a,h_b,h_a2,h_b2,h_a3,h_b3,T_a,T_b
DOUBLE PRECISION :: delta_a,delta_b,delta_a2,delta_b2,delta_a3,delta_b3
DOUBLE PRECISION :: Ael,Bel,Agrav,Bgrav,phi_a,phi_b
DOUBLE PRECISION :: Ts_a,Ts_b,Ds_b,Ds_a
INTEGER :: i,err1,algo1
! Remplissage de f
!### REMPLISSAGE DE f ###!
DO i=1,N,1
IF (i .NE. N) THEN
Ael=el*(ray(i)/(dist(i)*Dr**2))
Agrav=grav*(ray(i)/(dist(i)*Dr**2))
h_a=0.5d0*(H(i+1,col)+H(i,col))
h_a2=0.5d0*(H(i+1,col)**2+H(i,col)**2)
h_a3=0.5d0*(H(i+1,col)**3+H(i,col)**3)
delta_a=0.5d0*(BL(i+1,3)+BL(i,3))
delta_a2=0.5d0*(BL(i+1,3)**2+BL(i,3)**2)
delta_a3=0.5d0*(BL(i+1,3)**3+BL(i,3)**3)
T_a=0.5d0*(T(i,3)+T(i+1,3))
Ts_a = 0.5d0*(Ts(i,3)+Ts(i+1,3))
Ds_a = T_a -Ts_a
IF (nu <1D0) THEN
phi_a = 6*sqrt(pi)*Ds_a**(-1.5d0)*delta_a3*nu*nu**(-T_a)*(-log(&
& nu))**(-1.5d0)*erf(sqrt(Ds_a)*sqrt(-log(nu))) + 12*1.0/Ds_a*&
& delta_a3*nu*nu**Ds_a*nu**(-T_a)*1.0/(-log(nu)) - 24*1.0/Ds_a*&
& delta_a3*nu*nu**(-T_a)*1.0/(-log(nu)) - 12*1.0/Ds_a*delta_a2*&
& h_a*nu*nu**Ds_a*nu**(-T_a)*1.0/(-log(nu)) + 12*1.0/Ds_a*delta_a2&
& *h_a*nu*nu**(-T_a)*1.0/(-log(nu)) - 12*sqrt(pi)*Ds_a**(-0.5d0)*&
& delta_a3*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_a)*sqrt(-log(nu))) + 12*sqrt(pi)*Ds_a**(-0.5d0)*delta_a2*h_a&
& *nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_a)*sqrt(&
& -log(nu))) - 3*sqrt(pi)*Ds_a**(-0.5d0)*delta_a*h_a**2*nu*nu**(&
& -T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_a)*sqrt(-log(nu&
& ))) + 8*delta_a3*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) - 12*&
& delta_a2*h_a*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) + 6*delta_a*&
& h_a**2*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) - h_a**3*nu*nu**(-T_a&
& )*1.0/(-log(nu))*log(nu)
phi_a = -12.0d0*sqrt(pi)*T_a*delta_a**3*nu*nu**(-T_a)*(-log(nu))**&
& (-1.5d0)*(T_a - Ts_a)**(-1.5d0)*log(nu)*erf(sqrt(-log(nu))*sqrt(&
& T_a - Ts_a)) + 8.0d0*T_a*delta_a**3*nu*nu**(-T_a)*1.0/(-log(nu))*&
& 1.0/(T_a - Ts_a)*log(nu) + 12.0d0*sqrt(pi)*T_a*delta_a**2*h_a*nu*&
& nu**(-T_a)*(-log(nu))**(-1.5d0)*(T_a - Ts_a)**(-1.5d0)*log(nu)*&
& erf(sqrt(-log(nu))*sqrt(T_a - Ts_a)) - 12.0d0*T_a*delta_a**2*h_a*&
& nu*nu**(-T_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a)*log(nu) - 3.0d0*&
& sqrt(pi)*T_a*delta_a*h_a**2*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*(&
& T_a - Ts_a)**(-1.5d0)*log(nu)*erf(sqrt(-log(nu))*sqrt(T_a - Ts_a&
& )) + 6.0d0*T_a*delta_a*h_a**2*nu*nu**(-T_a)*1.0/(-log(nu))*1.0/(&
& T_a - Ts_a)*log(nu) - 1.0d0*T_a*h_a**3*nu*nu**(-T_a)*1.0/(-log(nu&
& ))*1.0/(T_a - Ts_a)*log(nu) + 12.0d0*sqrt(pi)*Ts_a*delta_a**3*nu*&
& nu**(-T_a)*(-log(nu))**(-1.5d0)*(T_a - Ts_a)**(-1.5d0)*log(nu)*&
& erf(sqrt(-log(nu))*sqrt(T_a - Ts_a)) - 8.0d0*Ts_a*delta_a**3*nu*&
& nu**(-T_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a)*log(nu) - 12.0d0*sqrt(&
& pi)*Ts_a*delta_a**2*h_a*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*(T_a -&
& Ts_a)**(-1.5d0)*log(nu)*erf(sqrt(-log(nu))*sqrt(T_a - Ts_a)) +&
& 12.0d0*Ts_a*delta_a**2*h_a*nu*nu**(-T_a)*1.0/(-log(nu))*1.0/(T_a&
& - Ts_a)*log(nu) + 3.0d0*sqrt(pi)*Ts_a*delta_a*h_a**2*nu*nu**(-T_a&
& )*(-log(nu))**(-1.5d0)*(T_a - Ts_a)**(-1.5d0)*log(nu)*erf(sqrt(&
& -log(nu))*sqrt(T_a - Ts_a)) - 6.0d0*Ts_a*delta_a*h_a**2*nu*nu**(&
& -T_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a)*log(nu) + 1.0d0*Ts_a*h_a**3&
& *nu*nu**(-T_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a)*log(nu) + 12.0d0*&
& delta_a**3*nu*nu**(-Ts_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a) + 6.0d0&
& *sqrt(pi)*delta_a**3*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*(T_a -&
& Ts_a)**(-1.5d0)*erf(sqrt(-log(nu))*sqrt(T_a - Ts_a)) - 24.0d0*&
& delta_a**3*nu*nu**(-T_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a) - 12.0d0&
& *delta_a**2*h_a*nu*nu**(-Ts_a)*1.0/(-log(nu))*1.0/(T_a - Ts_a) +&
& 12.0d0*delta_a**2*h_a*nu*nu**(-T_a)*1.0/(-log(nu))*1.0/(T_a -&
& Ts_a)
ELSEIF (nu .EQ. 1D0) THEN
phi_a = h_a**3
ENDIF
ENDIF
IF (i .NE. 1) THEN
Bel=el*(ray(i-1)/(dist(i)*Dr**2))
Bgrav=grav*(ray(i-1)/(dist(i)*Dr**2))
h_b=0.5d0*(H(i,col)+H(i-1,col))
h_b2=0.5d0*(H(i,col)**2+H(i-1,col)**2)
h_b3=0.5d0*(H(i,col)**3+H(i-1,col)**3)
delta_b=0.5d0*(BL(i,3)+BL(i-1,3))
delta_b2=0.5d0*(BL(i,3)**2+BL(i-1,3)**2)
delta_b3=0.5d0*(BL(i,3)**3+BL(i-1,3)**3)
T_b=0.5d0*(T(i,3)+T(i-1,3))
Ts_b = 0.5d0*(Ts(i,3)+Ts(i-1,3))
Ds_b = T_b - Ts_b
IF (nu <1D0) THEN
phi_b = 6*sqrt(pi)*Ds_b**(-1.5d0)*delta_b3*nu*nu**(-T_b)*(-log(&
& nu))**(-1.5d0)*erf(sqrt(Ds_b)*sqrt(-log(nu))) + 12*1.0/Ds_b*&
& delta_b3*nu*nu**Ds_b*nu**(-T_b)*1.0/(-log(nu)) - 24*1.0/Ds_b*&
& delta_b3*nu*nu**(-T_b)*1.0/(-log(nu)) - 12*1.0/Ds_b*delta_b2*&
& h_b*nu*nu**Ds_b*nu**(-T_b)*1.0/(-log(nu)) + 12*1.0/Ds_b*delta_b2&
& *h_b*nu*nu**(-T_b)*1.0/(-log(nu)) - 12*sqrt(pi)*Ds_b**(-0.5d0)*&
& delta_b3*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_b)*sqrt(-log(nu))) + 12*sqrt(pi)*Ds_b**(-0.5d0)*delta_b2*h_b&
& *nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_b)*sqrt(&
& -log(nu))) - 3*sqrt(pi)*Ds_b**(-0.5d0)*delta_b*h_b**2*nu*nu**(&
& -T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_b)*sqrt(-log(nu&
& ))) + 8*delta_b3*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) - 12*&
& delta_b2*h_b*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) + 6*delta_b*&
& h_b**2*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) - h_b**3*nu*nu**(-T_b&
& )*1.0/(-log(nu))*log(nu)
phi_b = -12.0d0*sqrt(pi)*T_b*delta_b**3*nu*nu**(-T_b)*(-log(nu))**&
& (-1.5d0)*(T_b - Ts_b)**(-1.5d0)*log(nu)*erf(sqrt(-log(nu))*sqrt(&
& T_b - Ts_b)) + 8.0d0*T_b*delta_b**3*nu*nu**(-T_b)*1.0/(-log(nu))*&
& 1.0/(T_b - Ts_b)*log(nu) + 12.0d0*sqrt(pi)*T_b*delta_b**2*h_b*nu*&
& nu**(-T_b)*(-log(nu))**(-1.5d0)*(T_b - Ts_b)**(-1.5d0)*log(nu)*&
& erf(sqrt(-log(nu))*sqrt(T_b - Ts_b)) - 12.0d0*T_b*delta_b**2*h_b*&
& nu*nu**(-T_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b)*log(nu) - 3.0d0*&
& sqrt(pi)*T_b*delta_b*h_b**2*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*(&
& T_b - Ts_b)**(-1.5d0)*log(nu)*erf(sqrt(-log(nu))*sqrt(T_b - Ts_b&
& )) + 6.0d0*T_b*delta_b*h_b**2*nu*nu**(-T_b)*1.0/(-log(nu))*1.0/(&
& T_b - Ts_b)*log(nu) - 1.0d0*T_b*h_b**3*nu*nu**(-T_b)*1.0/(-log(nu&
& ))*1.0/(T_b - Ts_b)*log(nu) + 12.0d0*sqrt(pi)*Ts_b*delta_b**3*nu*&
& nu**(-T_b)*(-log(nu))**(-1.5d0)*(T_b - Ts_b)**(-1.5d0)*log(nu)*&
& erf(sqrt(-log(nu))*sqrt(T_b - Ts_b)) - 8.0d0*Ts_b*delta_b**3*nu*&
& nu**(-T_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b)*log(nu) - 12.0d0*sqrt(&
& pi)*Ts_b*delta_b**2*h_b*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*(T_b -&
& Ts_b)**(-1.5d0)*log(nu)*erf(sqrt(-log(nu))*sqrt(T_b - Ts_b)) +&
& 12.0d0*Ts_b*delta_b**2*h_b*nu*nu**(-T_b)*1.0/(-log(nu))*1.0/(T_b&
& - Ts_b)*log(nu) + 3.0d0*sqrt(pi)*Ts_b*delta_b*h_b**2*nu*nu**(-T_b&
& )*(-log(nu))**(-1.5d0)*(T_b - Ts_b)**(-1.5d0)*log(nu)*erf(sqrt(&
& -log(nu))*sqrt(T_b - Ts_b)) - 6.0d0*Ts_b*delta_b*h_b**2*nu*nu**(&
& -T_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b)*log(nu) + 1.0d0*Ts_b*h_b**3&
& *nu*nu**(-T_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b)*log(nu) + 12.0d0*&
& delta_b**3*nu*nu**(-Ts_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b) + 6.0d0&
& *sqrt(pi)*delta_b**3*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*(T_b -&
& Ts_b)**(-1.5d0)*erf(sqrt(-log(nu))*sqrt(T_b - Ts_b)) - 24.0d0*&
& delta_b**3*nu*nu**(-T_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b) - 12.0d0&
& *delta_b**2*h_b*nu*nu**(-Ts_b)*1.0/(-log(nu))*1.0/(T_b - Ts_b) +&
& 12.0d0*delta_b**2*h_b*nu*nu**(-T_b)*1.0/(-log(nu))*1.0/(T_b -&
& Ts_b)
ELSEIF (nu .EQ. 1D0) THEN
phi_b = h_b**3
ENDIF
ENDIF
IF (i==1) THEN
f(i)=Ael*phi_a*(P(2,col)-P(1,col))+Agrav*phi_a*(H(2,col)-H(1,col))&
&+qa(i)
ELSEIF (i==N) THEN
f(i)=-Bel*phi_b*(P(i,col)-P(i-1,col))-Bgrav*phi_b*(H(i,col)-H(i-1,col))&
&+qa(i)
ELSE
f(i)=Ael*phi_a*(P(i+1,col)-P(i,col))-Bel*phi_b*(P(i,col)-P(i-1,col))&
&+Agrav*phi_a*(H(i+1,col)-H(i,col))-Bgrav*phi_b*(H(i,col)-H(i-1,col))&
&+qa(i)
END IF
END DO
END SUBROUTINE THICKNESS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!-------------------------------------------------------------------------------------
! SUBROUTINE THICKNESS
!-------------------------------------------------------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SUBROUTINE JACOBI_THICKNESS(a,b,c,d,e,f,g,k,l,N,M,H,P,T,BL,Ts,Coeff,Dt,Dr,dist,ray,el,grav,nu,delta0)
!*****************************************************************
! Give the jacobian coeficient a1,b1,c1
!*****************************************************************
IMPLICIT NONE
! Tableaux
DOUBLE PRECISION ,DIMENSION(:) , INTENT(INOUT) :: a,b,c,d,e,f,g,k,l
DOUBLE PRECISION ,DIMENSION(:,:), INTENT(IN) :: H,T,BL,Ts
DOUBLE PRECISION ,DIMENSION(:,:), INTENT(INOUT) :: P,Coeff
DOUBLE PRECISION ,DIMENSION(:), INTENT(IN) :: dist,ray
! Prametre du model
DOUBLE PRECISION ,INTENT(IN) :: Dt,Dr
INTEGER ,INTENT(IN) :: N,M
! Nombre sans dimension
DOUBLE PRECISION ,INTENT(IN) :: el,grav,nu,delta0
DOUBLE PRECISION, PARAMETER :: pi=3.14159265358979d0
! Parametre pour le sous programme
DOUBLE PRECISION ,DIMENSION(:), ALLOCATABLE :: alpha,beta,gamma,lambda,kappa,delta,epsilonn
DOUBLE PRECISION ::Ael,Bel,Agrav,Bgrav,h_a,h_b,h_a2,h_b2,h_a3,h_b3,T_a,T_b
DOUBLE PRECISION ::delta_a,delta_b,delta_a2,delta_b2,delta_a3,delta_b3
DOUBLE PRECISION :: Ts_a,Ts_b,Ds_b,Ds_a
DOUBLE PRECISION :: phi_a,phi_b,dphib_dhi,dphib_dhi1,dphia_dhi,dphia_dhi1
DOUBLE PRECISION :: H1,H2,P1,P2,hi,hi2,hia,hib,hia2,hib2
INTEGER :: i,col,algo1,err1
! Allocation + remplissage pression
ALLOCATE(alpha(1:N),beta(1:N),gamma(1:N),lambda(1:N),stat=err1)
ALLOCATE(kappa(1:N),delta(1:N),epsilonn(1:N),stat=err1)
IF (err1>1) THEN !On teste si nos tableau sont bien alloués
PRINT*,"Erreur ds alloc alpha,beta.." ;STOP
END IF
algo1=2;col=2
alpha=Coeff(:,1)
beta=Coeff(:,2)
gamma=Coeff(:,3)
lambda=Coeff(:,4)
kappa=Coeff(:,5)
delta=Coeff(:,6)
epsilonn=Coeff(:,7)
! Remplissage de la matrice Jacobienne
DO i=1,N,1
IF1: IF (i .NE. N) THEN
Ael=el*(ray(i)/(dist(i)*Dr**2))
Agrav=grav*(ray(i)/(dist(i)*Dr**2))
h_a=0.5d0*(H(i+1,col)+H(i,col))
h_a2=0.5d0*(H(i+1,col)**2+H(i,col)**2)
h_a3=0.5d0*(H(i+1,col)**3+H(i,col)**3)
delta_a=0.5d0*(BL(i+1,3)+BL(i,3))
delta_a2=0.5d0*(BL(i+1,3)**2+BL(i,3)**2)
delta_a3=0.5d0*(BL(i+1,3)**3+BL(i,3)**3)
T_a=0.5d0*(T(i,3)+T(i+1,3))
Ts_a = 0.5d0*(Ts(i,3)+Ts(i+1,3))
Ds_a = T_a -Ts_a
hia = H(i+1,col); hia2 = H(i+1,col)**2
hi = H(i,col);hi2 = H(i,col)**2
IF (nu <1D0) THEN
phi_a = 6*sqrt(pi)*Ds_a**(-1.5d0)*delta_a3*nu*nu**(-T_a)*(-log(&
& nu))**(-1.5d0)*erf(sqrt(Ds_a)*sqrt(-log(nu))) + 12*1.0/Ds_a*&
& delta_a3*nu*nu**Ds_a*nu**(-T_a)*1.0/(-log(nu)) - 24*1.0/Ds_a*&
& delta_a3*nu*nu**(-T_a)*1.0/(-log(nu)) - 12*1.0/Ds_a*delta_a2*&
& h_a*nu*nu**Ds_a*nu**(-T_a)*1.0/(-log(nu)) + 12*1.0/Ds_a*delta_a2&
& *h_a*nu*nu**(-T_a)*1.0/(-log(nu)) - 12*sqrt(pi)*Ds_a**(-0.5d0)*&
& delta_a3*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_a)*sqrt(-log(nu))) + 12*sqrt(pi)*Ds_a**(-0.5d0)*delta_a2*h_a&
& *nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_a)*sqrt(&
& -log(nu))) - 3*sqrt(pi)*Ds_a**(-0.5d0)*delta_a*h_a**2*nu*nu**(&
& -T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_a)*sqrt(-log(nu&
& ))) + 8*delta_a3*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) - 12*&
& delta_a2*h_a*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) + 6*delta_a*&
& h_a**2*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) - h_a**3*nu*nu**(-T_a&
& )*1.0/(-log(nu))*log(nu)
dphia_dhi1 = -12*1.0/Ds_a*delta_a2*nu*nu**Ds_a*nu**(-T_a)*1.0/(&
& -log(nu)) + 12*1.0/Ds_a*delta_a2*nu*nu**(-T_a)*1.0/(-log(nu)) +&
& 12*sqrt(pi)*Ds_a**(-0.5d0)*delta_a2*nu*nu**(-T_a)*(-log(nu))**(&
& -1.5d0)*log(nu)*erf(sqrt(Ds_a)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_a&
& **(-0.5d0)*delta_a*hi*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*&
& erf(sqrt(Ds_a)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_a**(-0.5d0)*&
& delta_a*hia*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_a)*sqrt(-log(nu))) - 12*delta_a2*nu*nu**(-T_a)*1.0/(-log(nu&
& ))*log(nu) + 12*delta_a*hi*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) +&
& 12*delta_a*hia*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) - 3*hi**2*nu*&
& nu**(-T_a)*1.0/(-log(nu))*log(nu) - 6*hi*hia*nu*nu**(-T_a)*1.0/(&
& -log(nu))*log(nu) - 3*hia**2*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu)
dphia_dhi = -12*1.0/Ds_a*delta_a2*nu*nu**Ds_a*nu**(-T_a)*1.0/(&
& -log(nu)) + 12*1.0/Ds_a*delta_a2*nu*nu**(-T_a)*1.0/(-log(nu)) +&
& 12*sqrt(pi)*Ds_a**(-0.5d0)*delta_a2*nu*nu**(-T_a)*(-log(nu))**(&
& -1.5d0)*log(nu)*erf(sqrt(Ds_a)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_a&
& **(-0.5d0)*delta_a*hi*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*&
& erf(sqrt(Ds_a)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_a**(-0.5d0)*&
& delta_a*hia*nu*nu**(-T_a)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_a)*sqrt(-log(nu))) - 12*delta_a2*nu*nu**(-T_a)*1.0/(-log(nu&
& ))*log(nu) + 12*delta_a*hi*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) +&
& 12*delta_a*hia*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu) - 3*hi**2*nu*&
& nu**(-T_a)*1.0/(-log(nu))*log(nu) - 6*hi*hia*nu*nu**(-T_a)*1.0/(&
& -log(nu))*log(nu) - 3*hia**2*nu*nu**(-T_a)*1.0/(-log(nu))*log(nu)
ELSEIF (nu .EQ. 1D0) THEN
phi_a = h_a**3
dphia_dhi1 = 3*hi**2 + 6*hi*hia + 3*hia**2
dphia_dhi = 3*hi**2 + 6*hi*hia + 3*hia**2
ENDIF
P1=P(i+1,2)-P(i,2); P2=P(i,2)-P(i-1,2)
H1=H(i+1,2)-H(i,2); H2=H(i,2)-H(i-1,2)
ENDIF IF1
IF2: IF (i .NE. 1) THEN
Bel=el*(ray(i-1)/(dist(i)*Dr**2))
Bgrav=grav*(ray(i-1)/(dist(i)*Dr**2))
h_b=0.5d0*(H(i,col)+H(i-1,col))
h_b2=0.5d0*(H(i,col)**2+H(i-1,col)**2)
h_b3=0.5d0*(H(i,col)**3+H(i-1,col)**3)
delta_b=0.5d0*(BL(i,3)+BL(i-1,3))
delta_b2=0.5d0*(BL(i,3)**2+BL(i-1,3)**2)
delta_b3=0.5d0*(BL(i,3)**3+BL(i-1,3)**3)
T_b=0.5d0*(T(i,3)+T(i-1,3))
Ts_b = 0.5d0*(Ts(i,3)+Ts(i-1,3))
Ds_b = T_b - Ts_b
hib = H(i-1,col); hib2 = H(i-1,col)**2
hi = H(i,col);hi2 = H(i,col)**2
IF (nu <1D0) THEN
phi_b = 6*sqrt(pi)*Ds_b**(-1.5d0)*delta_b3*nu*nu**(-T_b)*(-log(&
& nu))**(-1.5d0)*erf(sqrt(Ds_b)*sqrt(-log(nu))) + 12*1.0/Ds_b*&
& delta_b3*nu*nu**Ds_b*nu**(-T_b)*1.0/(-log(nu)) - 24*1.0/Ds_b*&
& delta_b3*nu*nu**(-T_b)*1.0/(-log(nu)) - 12*1.0/Ds_b*delta_b2*&
& h_b*nu*nu**Ds_b*nu**(-T_b)*1.0/(-log(nu)) + 12*1.0/Ds_b*delta_b2&
& *h_b*nu*nu**(-T_b)*1.0/(-log(nu)) - 12*sqrt(pi)*Ds_b**(-0.5d0)*&
& delta_b3*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_b)*sqrt(-log(nu))) + 12*sqrt(pi)*Ds_b**(-0.5d0)*delta_b2*h_b&
& *nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_b)*sqrt(&
& -log(nu))) - 3*sqrt(pi)*Ds_b**(-0.5d0)*delta_b*h_b**2*nu*nu**(&
& -T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(Ds_b)*sqrt(-log(nu&
& ))) + 8*delta_b3*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) - 12*&
& delta_b2*h_b*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) + 6*delta_b*&
& h_b**2*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) - h_b**3*nu*nu**(-T_b&
& )*1.0/(-log(nu))*log(nu)
dphib_dhi = -12*1.0/Ds_b*delta_b2*nu*nu**Ds_b*nu**(-T_b)*1.0/(&
& -log(nu)) + 12*1.0/Ds_b*delta_b2*nu*nu**(-T_b)*1.0/(-log(nu)) +&
& 12*sqrt(pi)*Ds_b**(-0.5d0)*delta_b2*nu*nu**(-T_b)*(-log(nu))**(&
& -1.5d0)*log(nu)*erf(sqrt(Ds_b)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_b&
& **(-0.5d0)*delta_b*hi*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*&
& erf(sqrt(Ds_b)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_b**(-0.5d0)*&
& delta_b*hib*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_b)*sqrt(-log(nu))) - 12*delta_b2*nu*nu**(-T_b)*1.0/(-log(nu&
& ))*log(nu) + 12*delta_b*hi*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) +&
& 12*delta_b*hib*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) - 3*hi**2*nu*&
& nu**(-T_b)*1.0/(-log(nu))*log(nu) - 6*hi*hib*nu*nu**(-T_b)*1.0/(&
& -log(nu))*log(nu) - 3*hib**2*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu)
dphib_dhi1 = -12*1.0/Ds_b*delta_b2*nu*nu**Ds_b*nu**(-T_b)*1.0/(&
& -log(nu)) + 12*1.0/Ds_b*delta_b2*nu*nu**(-T_b)*1.0/(-log(nu)) +&
& 12*sqrt(pi)*Ds_b**(-0.5d0)*delta_b2*nu*nu**(-T_b)*(-log(nu))**(&
& -1.5d0)*log(nu)*erf(sqrt(Ds_b)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_b&
& **(-0.5d0)*delta_b*hi*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*&
& erf(sqrt(Ds_b)*sqrt(-log(nu))) - 6*sqrt(pi)*Ds_b**(-0.5d0)*&
& delta_b*hib*nu*nu**(-T_b)*(-log(nu))**(-1.5d0)*log(nu)*erf(sqrt(&
& Ds_b)*sqrt(-log(nu))) - 12*delta_b2*nu*nu**(-T_b)*1.0/(-log(nu&
& ))*log(nu) + 12*delta_b*hi*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) +&
& 12*delta_b*hib*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu) - 3*hi**2*nu*&
& nu**(-T_b)*1.0/(-log(nu))*log(nu) - 6*hi*hib*nu*nu**(-T_b)*1.0/(&
& -log(nu))*log(nu) - 3*hib**2*nu*nu**(-T_b)*1.0/(-log(nu))*log(nu)
ELSEIF (nu .EQ. 1D0) THEN
phi_b = h_b**3
dphib_dhi1 = 3*hi**2 + 6*hi*hib + 3*hib**2
dphib_dhi = 3*hi**2 + 6*hi*hib + 3*hib**2
ENDIF
P2=P(i,2)-P(i-1,2)
H2=H(i,2)-H(i-1,2)
ENDIF IF2
IF3: IF (i==1) THEN
a(i)=0;b(i)=0;c(i)=0;d(i)=0
e(i)=Agrav*(dphia_dhi*H1-phi_a)
f(i)=Agrav*(dphia_dhi1*H1+phi_a)
g(i)=0.d0
k(i)=0.d0
l(i)=0.d0
ELSEIF (i ==N) THEN
a(i)=0.d0
b(i)=0.d0
c(i)=0.d0
d(i)=Bgrav*(-dphib_dhi1*H2+phi_b)
e(i)=-Bgrav*(dphib_dhi*H2+phi_b)
f(i)=0.d0
g(i)=0.D0
k(i)=0.d0
l(i)=0.d0
ELSE
a(i)=0.d0
b(i)=0.d0
c(i)=0.d0
d(i)=Bgrav*(-dphib_dhi1*H2+phi_b)
e(i)=Agrav*(dphia_dhi*H1-phi_a)-Bgrav*(dphib_dhi*H2+phi_b)
f(i)=Agrav*(dphia_dhi1*H1+phi_a)
g(i)=0.D0
k(i)=0.d0
l(i)=0.d0
END IF IF3
END DO
DEALLOCATE(alpha,beta,gamma,lambda,kappa,delta,epsilonn)
END SUBROUTINE JACOBI_THICKNESS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!-------------------------------------------------------------------------------------
! SUBROUTINE TRIDIAG
!-------------------------------------------------------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SUBROUTINE TRIDIAG(A,B,C,S,N,U)
!*****************************************************************
! Solves for a vector U of length N the tridiagonal linear set
! M U = R, where A, B and C are the three main diagonals of matrix
! M(N,N), the other terms are 0. R is the right side vector.
!*****************************************************************
IMPLICIT NONE
DOUBLE PRECISION, DIMENSION(N), INTENT(IN) :: A,B,C,S
DOUBLE PRECISION, DIMENSION(N), INTENT(INOUT) :: U
INTEGER, INTENT(IN) :: N
INTEGER :: CODE
DOUBLE PRECISION, DIMENSION(N) :: GAM
DOUBLE PRECISION :: BET
INTEGER :: j
BET = B(1)
IF (BET == 0.D0) THEN
PRINT*,'ERROR TRIDIAG'
STOP
ENDIF
U(1) = S(1)/BET
DO J=2,N !Decomposition and forward substitution
GAM(j)=C(j-1)/BET
BET=B(j)-A(j)*GAM(j)
IF(BET.EQ.0.D0) THEN !Algorithm fails
PRINT*,'ERRORTRIDIAG2',j,N
STOP
END IF
U(j)=(S(j)-A(j)*U(j-1))/BET
END DO
DO j=N-1,1,-1 !Back substitution
U(j)=U(j)-GAM(j+1)*U(j+1)
END DO
CODE=0
RETURN
END SUBROUTINE TRIDIAG
END MODULE MODULE_THICKNESS_NEWTON_GRAV_ARRHENIUS