-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlangevin.f90
413 lines (328 loc) · 12.3 KB
/
langevin.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
! Simple langevin dynamics with brownian motion, no interaction between partciles and custom temperature distribution
! conditions on the cold side will be the reference
module fisica
implicit none
contains
function St_slip(Kn0,T_loc, Tc, N, scorr) result(Cc)
! allen and raabe 1982
use mod1
integer :: N
real(dp) :: Kn0, Tc
real(dp), dimension(:) :: T_loc
real(dp), dimension(N) :: Cc
logical :: scorr
if (scorr) then
Cc = (1 + (Kn0 * T_loc)*(1.155 + 0.471 * exp(-0.596 / (Kn0 * T_loc) )))
else
Cc = 1
end if
end function St_slip
function densitycr(rhof,T_loc,N) result(drho)
! corrige a densidade
! rho é adimensional
use mod1
integer :: N
real(dp) :: T_loc(:), rhof, rho
real(dp), dimension(N) :: drho
drho = (2 - rhof/T_loc)/(2 - rhof)
end function densitycr
function trapz(dx,y,N) result(I)
use mod1
real(dp), intent(in), dimension(:,:) :: y
real(dp), intent(in) :: dx
integer, INTENT(IN) :: N
real(dp), dimension(N) :: I
integer :: j, k
I = 0
do j = 1,N
do k = 2, size(y, dim=2)
I(j) = I(j) + 0.5*dx*(y(j,k-1) + y(j,k))
end do
end do
end function trapz
subroutine comp_F(F,GField,x,v,vp,T_loc,Tc,St0,Pe0,Kn0,rhof,N,dt,scorr,tauc)
use mod1
integer :: N, i, j
real(dp), dimension(:,:,:), intent(inout) :: vp
real(dp), dimension(:,:), intent(inout) :: F, tauc
real(dp), dimension(:,:), intent(in) :: x,v
real(dp), dimension(:), intent(in) :: T_loc, Gfield
real(dp), intent(in) :: St0, Pe0, Kn0, dt, rhof,Tc
logical, INTENT(IN) :: scorr
real(dp) :: xi(N,2),drho(N), Cc(N), kernel1(N,20), kernel2(N,20)
integer, save :: kcont = 1, aux1 = 0
tauc(:,kcont) = Kn0*T_loc/sqrt(T_loc*60)
kernel1 = 0
kernel2 = 0
j = kcont - 1
do i = 1, 20
if (j < 20) then
j = j + 1
else
j = 1
end if
if (i > 20 - aux1) then
kernel1(:,i) = (vp(:,j,1)/tauc(:,j))*(exp(-((20-i)*dt)/tauc(:,j)))
kernel2(:,i) = (vp(:,j,2)/tauc(:,j))*(exp(-((20-i)*dt)/tauc(:,j)))
! print*, "j =", j
end if
end do
! print*, "vp = ", vp(:,:,1)
! print*, "kcont = ", kcont
! print*, "tauc =", tauc
! print*, "kernel1 =", kernel1
! print*, "kernel2 =", kernel2
! read(*,*)
! print*, "--OK--"
if (aux1 <= 20) aux1 = aux1 + 1
if (kcont < 20) then
kcont = kcont + 1
else
kcont = 1
end if
! Gera numero aleatório e normaliza
call random_seed()
call random_number(xi)
xi = xi*2 -1
xi(:,1) = xi(:,1) / sqrt(xi(:,1)**2 + xi(:,2)**2)
xi(:,2) = xi(:,2) / sqrt(xi(:,1)**2 + xi(:,2)**2)
! read(*,*)
drho = densitycr(rhof,T_loc,N)
if (Pe0 > 0) then
Cc = St_slip(Kn0,T_loc,Tc,N, scorr)
! F(:,1) = (1/(St0*drho/St_slip(Kn0,T_loc,Tc,N,scorr))) * (- v(:,1) + GField(1) + sqrt(6*T_loc/(Pe0*dt))*xi(:,1))
! F(:,2) = (1/(St0*drho/St_slip(Kn0,T_loc,Tc,N,scorr))) * (- v(:,2) + GField(2) + sqrt(6*T_loc/(Pe0*dt))*xi(:,2))
F(:,1) = (1/(St0*drho)) * &
(- trapz(dt,kernel1,N)/Cc + GField(1) + sqrt(6*T_loc/(Cc*Pe0*dt))*xi(:,1))
F(:,2) = (1/(St0*drho)) * &
(- trapz(dt,kernel2,N)/Cc + GField(2) + sqrt(6*T_loc/(Cc*Pe0*dt))*xi(:,2))
! u1x = (Cc(T_ax)/(St*Ddensity(T_ax)))*(-u0x + (6/(Pe*tau))^.5*ksi(1)*temper/Cc(T_ax));
! F(:,1) = (1/(St0)) * (- v(:,1) + GField(1) + sqrt(6*T_loc/(Pe0*dt))*xi(:,1))
! F(:,2) = (1/(St0)) * (- v(:,2) + GField(2) + sqrt(6*T_loc/(Pe0*dt))*xi(:,2))
! print*, "F =", F
! print*, "drho =", drho
! print*, "v =", v
! print*, "x =", x
! read(*,*)
else
F(:,1) = (GField(1) + sqrt(6*T_loc/(Pe0*dt))*xi(:,1))/dt
F(:,2) = (GField(2) + sqrt(6*T_loc/(Pe0*dt))*xi(:,2))/dt
end if
end subroutine comp_F
subroutine comp_v(F,v,vp,dt,Pe0)
use mod1
real(dp), dimension(:,:,:), intent(inout) :: vp
real(dp), dimension(:,:), intent(inout) :: v
real(dp), dimension(:,:), intent(in) :: F
real(dp), intent(in) :: dt,Pe0
integer, save :: kcont = 1
if (Pe0 > 0) then
v = v + F*dt
! print*, "F*dt =", F, "x", dt, "=", F*dt
else
v = F*dt
end if
vp(:,kcont,1) = v (:,1)
vp(:,kcont,2) = v (:,2)
if (kcont < 20) then
kcont = kcont + 1
else
kcont = 1
end if
end subroutine comp_v
subroutine comp_x(x,v,dimx,dimy,N,dt,wall)
use mod1
real(dp), dimension(:,:), intent(inout) :: v,x
real(dp), intent(in) :: dt,dimx,dimy
integer, intent(in) :: N
character, intent(in) :: wall(4)
integer :: i
x = x + v*dt
! print*, "v*dt =", v*dt
! read(*,*)
do i = 1,N
if (v(i,1)*dt > dimx/2 .or. v(i,2)*dt > dimy/2) then
print*, "Partículas rápidas demais"
call system("killall langevin")
end if
end do
! print*, "v*dt", v*dt
! read(*,*)
! condições de contorno
! elastico
if (wall(3) == 'e') then
do i = 1,N
if (x(i,1) > dimx) then
x(i,1) = 2*dimx - x(i,1)
v(i,1) = -v(i,1)
else if (x(i,1) < 0) then
x(i,1) = - x(i,1)
v(i,1) = - v(i,1)
end if
end do
end if
if (wall(1) == 'e') then
do i = 1,N
if (x(i,2) > dimy) then
x(i,2) = 2*dimy - x(i,2)
v(i,2) = - v(i,2)
else if (x(i,2) < 0) then
x(i,2) = - x(i,2)
v(i,2) = - v(i,2)
end if
end do
end if
! Periodico
if (wall(3) == 'p') then
do i = 1,N
if (x(i,1) > dimx) then
x(i,1) = -dimx + x(i,1)
else if (x(i,1) < 0) then
x(i,1) = dimx + x(i,1)
end if
end do
end if
if (wall(1) == 'p') then
do i = 1,N
if (x(i,2) > dimy) then
x(i,2) = -dimy + x(i,2)
else if (x(i,2) < 0) then
x(i,2) = dimy + x(i,2)
end if
end do
end if
end subroutine comp_x
end module fisica
program main
use mod1
use m_config
use saida
use fisica
use, intrinsic :: ieee_arithmetic, only: IEEE_Value, IEEE_QUIET_NAN
use, intrinsic :: iso_fortran_env, only: real32
implicit none
! Variables
real(dp) :: Pe0, St0, Th, Tc, Kn0, dt, t_fim, t, rhof, dimx, dimy, Gfield(2),x0(2),v0(2),start,finish
real(dp), allocatable, dimension(:,:) :: v, x, F, tauc
real(dp), allocatable, dimension(:,:,:) :: vp
real(dp), allocatable, dimension(:) :: T_loc
integer :: N, nimpre, i, ic1, cpu_countrate
integer, allocatable :: interv(:)
character(4) :: wall
character(10) :: time
character(8) :: date
type(CFG_t) :: my_cfg
logical :: scorr
! Auxiliary variables
integer :: step, jprint
! Leitura do arquivo de configuração
call CFG_add(my_cfg, "global%N",1,&
"number of particles")
call CFG_add(my_cfg, "global%dt",0.0_dp,&
"time step")
call CFG_add(my_cfg, "global%t_fim",0.0_dp,&
"simulation time")
call CFG_add(my_cfg, "global%nimpre",1,&
"number of result files")
call CFG_add(my_cfg, "global%dimX",1.0_dp,&
"x-dimension of the region of calculus")
call CFG_add(my_cfg, "global%dimY",1.0_dp,&
"y-dimension of the region of calculus")
call CFG_add(my_cfg,"global%Th",-1.0_dp, &
"Thermostat hot wall")
call CFG_add(my_cfg,"global%Tc",-1.0_dp, &
"Thermostat cold wall")
call CFG_add(my_cfg, "global%St0",0.0_dp,&
"Stokes number of reference")
call CFG_add(my_cfg, "global%Pe0",0.0_dp,&
"Peclet number of reference")
call CFG_add(my_cfg, "global%Kn0",0.0_dp,&
"Knuden number of reference")
call CFG_add(my_cfg,"global%slip_correction", .True., &
"Stokes slip correction")
call CFG_add(my_cfg, "global%rhof",0.0_dp,&
"sensitivity of the density to temperature")
call CFG_add(my_cfg,"global%GField",(/0.0_dp, 0.0_dp/), &
"Uniform Gravitational Field")
call CFG_add(my_cfg,"global%wall",'eeee', &
"wall's periodic vs elastic")
call CFG_add(my_cfg,"global%x",(/0.0_dp, 0.0_dp/), &
"position of the particles")
call CFG_add(my_cfg,"global%v",(/0.0_dp, 0.0_dp/), &
"initial velocity of the particles")
call CFG_read_file(my_cfg,'settings.ini')
call CFG_get(my_cfg, "global%N",N)
call CFG_get(my_cfg, "global%dt",dt)
call CFG_get(my_cfg, "global%t_fim", t_fim)
call CFG_get(my_cfg, "global%nimpre",nimpre)
call CFG_get(my_cfg, "global%dimX",dimx)
call CFG_get(my_cfg, "global%dimY",dimy)
call CFG_get(my_cfg,"global%Th",Th)
call CFG_get(my_cfg,"global%Tc",Tc)
call CFG_get(my_cfg, "global%St0",St0)
call CFG_get(my_cfg, "global%Pe0",Pe0)
call CFG_get(my_cfg, "global%Kn0",Kn0)
call CFG_get(my_cfg, "global%slip_correction", scorr)
call CFG_get(my_cfg, "global%Kn0",rhof)
call CFG_get(my_cfg,"global%GField",Gfield)
call CFG_get(my_cfg,"global%x",x0)
call CFG_get(my_cfg,"global%v",v0)
call CFG_get(my_cfg,"global%wall",wall)
call CFG_write(my_cfg, "settings.txt")
allocate(interv(nimpre),T_loc(N),x(N,2),v(N,2),F(N,2),tauc(N,20), vp(N,20,2))
vp = 0
if (x0(1) < 0) then
call random_seed()
call random_number(x)
x(:,1) = x(:,1)*dimx
x(:,2) = x(:,2)*dimy
else
x(:,1) = x0(1) ! ou x = x0 funciona?
x(:,2) = x0(2) ! ou x = x0 funciona?
end if
v(:,1) = v0(1)
v(:,2) = v0(2)
print*, "vini = ", v0
call system_clock(ic1,cpu_countrate)
start = real(ic1,kind(0.d0))/real(cpu_countrate,kind(0.d0))
interv = (/((nint(t_fim/dt)/nimpre)*i,i=0,nimpre) /)
jprint = 1
step = 1
call date_and_time(date,time)
write(*,'("|| Program started at: ", a,":",a,":",a,2x, a,"/",a,"/",a, "||")') &
time(1:2),time(3:4),time(5:8),date(5:6),date(7:8),date(1:4)
call system('mkdir temp') !pasta temporária para armazenar os resultados
! call linked2vec(malha,domx,domy,nxv,aux1)
t = 0
call vec2csv(x,N,2,'position',0,t,nimpre,start, .true.)
call vec2csv(v,N,2,'velocity',0,t,nimpre,start, .true.)
print*, "Begin"
! print*, interv
T_loc = Tc + x(:,1)*((Th-Tc)/dimx)
do while (t < t_fim)
call comp_F(F,Gfield,x,v,vp,T_loc,Tc,St0,Pe0,Kn0,rhof,N,dt,scorr,tauc)
call comp_v(F,v, vp,dt,Pe0)
call comp_x(x,v,dimx,dimy,N,dt,wall)
T_loc = Tc + x(:,1)*((Th-Tc)/dimx)
if (jprint == 1) then
print*, "Avg velocity:", sum(sqrt(v(:,1)**2 + v(:,2)**2))/N
print*, "Avg displacement:", dt*sum(sqrt(v(:,1)**2 + v(:,2)**2))/N
end if
if (jprint == interv(step+1)) then
call vec2csv(v,N,2,'velocity',step,t,nimpre,start)
call vec2csv(x,N,2,'position',step,t,nimpre,start)
step = step + 1
end if
jprint = jprint + 1
t = t + dt
end do
call system_clock(ic1,cpu_countrate)
finish = real(ic1)/real(cpu_countrate,kind(0.d0))
print '("Time = ",f10.3," seconds.")',(finish-start)
open(unit=22,file='settings.txt',status="old", position="append", action="write")
write(22,'("#:Time to complete: ",f10.3," secounds.")') (finish-start)
write(22,'("#:Execution date: ",a,"/",a,"/",a,2x,a,":",a,":",a)') &
date(5:6),date(7:8),date(1:4),time(1:2),time(3:4),time(5:8)
close(22)
call system("python csv2vtk_particles.py")
end program main