forked from xcompact3d/Incompact3d
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCase-Channel.f90
552 lines (474 loc) · 19 KB
/
Case-Channel.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
!Copyright (c) 2012-2022, Xcompact3d
!This file is part of Xcompact3d (xcompact3d.com)
!SPDX-License-Identifier: BSD 3-Clause
module channel
use decomp_2d_constants
use decomp_2d_mpi
use decomp_2d
use variables
use param
implicit none
integer :: FS
character(len=100) :: fileformat
character(len=1),parameter :: NL=char(10) !new line character
PRIVATE ! All functions/subroutines private by default
PUBLIC :: init_channel, boundary_conditions_channel, postprocess_channel, &
visu_channel, visu_channel_init, momentum_forcing_channel, &
geomcomplex_channel
contains
!############################################################################
subroutine init_channel (ux1,uy1,uz1,ep1,phi1)
use decomp_2d_io
use variables
use param
use MPI
use mhd, only : mhd_active, Bm,Bmean
implicit none
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux1,uy1,uz1,ep1
real(mytype),dimension(xsize(1),xsize(2),xsize(3),numscalar) :: phi1
real(mytype) :: y,r,um,r3,x,z,h,ct
real(mytype) :: cx0,cy0,cz0,hg,lg
real(mytype) :: ftent
integer :: k,j,i,fh,ierror,ii,is,it,code, jj
if (idir_stream /= 1 .and. idir_stream /= 3) then
if (nrank == 0) then
write(*,*) '!! ERROR in imposing sorce term for momentum !!'
write(*,*) '!! idir_stream ', idir_stream
write(*,*) '!! idir_stream has to be:'
write(*,*) '!! - 1 for streamwise direction in X'
write(*,*) '!! - 3 for streamwise direction in Z'
write(*,*) '!! Y is not supported and other values do not make sense'
write(*,*) '!! Calculation will be now stop'
endif
call MPI_ABORT(MPI_COMM_WORLD,code,ierror); stop
endif
if (iscalar==1) then
if (nrank==0.and.(mod(itime, ilist) == 0 .or. itime == ifirst .or. itime == ilast)) then
write(*,*) 'Imposing linear temperature profile'
end if
do k=1,xsize(3)
do j=1,xsize(2)
if (istret==0) y=real(j+xstart(2)-2,mytype)*dy
if (istret/=0) y=yp(j+xstart(2)-1)
do i=1,xsize(1)
phi1(i,j,k,:) = one - y/yly
enddo
enddo
enddo
phi1(:,:,:,:) = zero !change as much as you want
if ((nclyS1 == 2).and.(xstart(2) == 1)) then
!! Generate a hot patch on bottom boundary
phi1(:,1,:,:) = one
endif
if ((nclySn == 2).and.(xend(2) == ny)) then
phi1(:,xsize(2),:,:) = zero
endif
endif
!
ux1=zero
uy1=zero
uz1=zero
byx1=zero;byy1=zero;byz1=zero
! if to decide type of initialization to apply
if (iin == 0) then ! laminar flow
do k=1,xsize(3)
do j=1,xsize(2)
if (istret==0) y=real(j+xstart(2)-1-1,mytype)*dy-yly*half
if (istret/=0) y=yp(j+xstart(2)-1)-yly*half
um=exp(-zptwo*y*y)
do i=1,xsize(1)
if (idir_stream == 1) then
ux1(i,j,k)=one-y*y
uy1(i,j,k)=zero
uz1(i,j,k)=sin(real(i-1,mytype)*dx)+cos(real(k-1,mytype)*dz)
else
print *,'test'
uz1(i,j,k)=one-y*y
uy1(i,j,k)=zero
ux1(i,j,k)=zero
endif
enddo
enddo
enddo
elseif (iin <= 2) then ! Traditional init to turbulent flows using random numbers + lam profile
call system_clock(count=code)
if (iin.eq.2) code=0
call random_seed(size = ii)
call random_seed(put = code+63946*(nrank+1)*(/ (i - 1, i = 1, ii) /))
call random_number(ux1)
call random_number(uy1)
call random_number(uz1)
!modulation of the random noise + initial velocity profile
do k=1,xsize(3)
do j=1,xsize(2)
if (istret==0) y=real(j+xstart(2)-1-1,mytype)*dy-yly*half
if (istret/=0) y=yp(j+xstart(2)-1)-yly*half
um=exp(-zptwo*y*y)
do i=1,xsize(1)
if (idir_stream == 1) then
ux1(i,j,k)=init_noise*um*(two*ux1(i,j,k)-one)+one-y*y
uy1(i,j,k)=init_noise*um*(two*uy1(i,j,k)-one)
uz1(i,j,k)=init_noise*um*(two*uz1(i,j,k)-one)
else
uz1(i,j,k)=init_noise*um*(two*ux1(i,j,k)-one)+one-y*y
uy1(i,j,k)=init_noise*um*(two*uy1(i,j,k)-one)
ux1(i,j,k)=init_noise*um*(two*uz1(i,j,k)-one)
endif
enddo
enddo
enddo
elseif (iin == 4) then ! SEM
call sem_init_channel(ux1, uy1, uz1)
endif
!INIT FOR G AND U=MEAN FLOW + NOISE
do k=1,xsize(3)
do j=1,xsize(2)
do i=1,xsize(1)
ux1(i,j,k)=ux1(i,j,k)+bxx1(j,k)
uy1(i,j,k)=uy1(i,j,k)+bxy1(j,k)
uz1(i,j,k)=uz1(i,j,k)+bxz1(j,k)
enddo
enddo
enddo
if(mhd_active) then
Bmean(:,:,:,1)=zero
Bmean(:,:,:,2)=one
Bmean(:,:,:,3)=zero
Bm(:,:,:,1)=zero
Bm(:,:,:,2)=zero
Bm(:,:,:,3)=zero
if(nrank==0) print*,'** magnetic field initialised'
endif
return
end subroutine init_channel
!############################################################################
!############################################################################
subroutine boundary_conditions_channel (ux,uy,uz,phi)
use param
use var, only : di2
use variables
use mhd, only : Bm, mhd_active, mhd_equation
implicit none
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux,uy,uz
real(mytype),dimension(xsize(1),xsize(2),xsize(3),numscalar) :: phi
if (.not. cpg ) then ! if not constant pressure gradient
if (idir_stream == 1) then
call channel_cfr(ux,two/three)
else
call channel_cfr(uz,two/three)
endif
end if
if (iscalar /= 0) then
if (iimplicit <= 0) then
if ((nclyS1 == 2).and.(xstart(2) == 1)) then
!! Generate a hot patch on bottom boundary
phi(:,1,:,:) = one
endif
if ((nclySn == 2).and.(xend(2) == ny)) THEN
phi(:,xsize(2),:,:) = zero
endif
else
!
! Implicit boundary conditions are usually given in input file
! It is possible to modify g_sc here
! It is not possible to modify alpha_sc and beta_sc here
!
! Bottom temperature if alpha_sc(:,1)=1 and beta_sc(:,1)=0 (default)
!if (nclyS1.eq.2) g_sc(:,1) = one
! Top temperature if alpha_sc(:,2)=1 and beta_sc(:,2)=0 (default)
!if (nclySn.eq.2) g_sc(:,2) = zero
endif
endif
if( mhd_active .and. iimplicit<=0 .and. mhd_equation ) then
! FIXME add a test
! This is valid only when nclyB*1 = 2
if (xstart(2) == 1) then
Bm(:,1,:,1) = zero
Bm(:,1,:,2) = zero
Bm(:,1,:,3) = zero
endif
! FIXME add a test
! This is valid only when nclyB*n = 2
if (xend(2) == ny) then
Bm(:,xsize(2),:,1) = zero
Bm(:,xsize(2),:,2) = zero
Bm(:,xsize(2),:,3) = zero
endif
endif
end subroutine boundary_conditions_channel
!############################################################################
!!
!! SUBROUTINE: channel_cfr
!! AUTHOR: Kay Schäfer
!! DESCRIPTION: Inforces constant flow rate without need of data transposition
!!
!############################################################################
subroutine channel_cfr (ux, constant)
use MPI
implicit none
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: ux
real(mytype), intent(in) :: constant
integer :: code, i, j, k, jloc
real(mytype) :: can, ub, uball, coeff
ub = zero
uball = zero
coeff = dy / (yly * real(xsize(1) * zsize(3), kind=mytype))
do k = 1, xsize(3)
do jloc = 1, xsize(2)
j = jloc + xstart(2) - 1
do i = 1, xsize(1)
ub = ub + ux(i,jloc,k) / ppy(j)
enddo
enddo
enddo
ub = ub * coeff
call MPI_ALLREDUCE(ub,uball,1,real_type,MPI_SUM,MPI_COMM_WORLD,code)
can = - (constant - uball)
if (nrank==0.and.(mod(itime, ilist) == 0 .or. itime == ifirst .or. itime == ilast)) &
write(*,*) 'UT', uball, can
do k=1,xsize(3)
do j=1,xsize(2)
do i=1,xsize(1)
ux(i,j,k) = ux(i,j,k) - can
enddo
enddo
enddo
end subroutine channel_cfr
!############################################################################
!############################################################################
subroutine postprocess_channel(ux1,uy1,uz1,pp3,phi1,ep1)
use var, ONLY : nzmsize
implicit none
real(mytype), intent(in), dimension(xsize(1),xsize(2),xsize(3)) :: ux1, uy1, uz1, ep1
real(mytype), intent(in), dimension(xsize(1),xsize(2),xsize(3),numscalar) :: phi1
real(mytype), intent(in), dimension(ph1%zst(1):ph1%zen(1),ph1%zst(2):ph1%zen(2),nzmsize,npress) :: pp3
end subroutine postprocess_channel
subroutine visu_channel_init(visu_initialised)
use decomp_2d_io, only : decomp_2d_register_variable
use visu, only : io_name, output2D
use mhd, only : mhd_active
implicit none
logical, intent(out) :: visu_initialised
call decomp_2d_register_variable(io_name, "critq", 1, 0, output2D, mytype)
if (mhd_active) then
call decomp_2d_register_variable(io_name, "J_x", 1, 0, output2D, mytype)
call decomp_2d_register_variable(io_name, "J_y", 1, 0, output2D, mytype)
call decomp_2d_register_variable(io_name, "J_z", 1, 0, output2D, mytype)
call decomp_2d_register_variable(io_name, "B_x", 1, 0, output2D, mytype)
call decomp_2d_register_variable(io_name, "B_y", 1, 0, output2D, mytype)
call decomp_2d_register_variable(io_name, "B_z", 1, 0, output2D, mytype)
endif
visu_initialised = .true.
end subroutine visu_channel_init
!############################################################################
!!
!! SUBROUTINE: visu_channel
!! AUTHOR: FS
!! DESCRIPTION: Performs channel-specific visualization
!!
!############################################################################
subroutine visu_channel(ux1, uy1, uz1, pp3, phi1, ep1, num)
use var, only : ux2, uy2, uz2, ux3, uy3, uz3
use var, only : ta1,tb1,tc1,td1,te1,tf1,tg1,th1,ti1,di1
use var, only : ta2,tb2,tc2,td2,te2,tf2,di2,ta3,tb3,tc3,td3,te3,tf3,di3
use var, ONLY : nzmsize
use visu, only : write_field
use mhd, only : mhd_active,Je, Bm
use ibm_param, only : ubcx,ubcy,ubcz
implicit none
real(mytype), intent(in), dimension(xsize(1),xsize(2),xsize(3)) :: ux1, uy1, uz1
real(mytype), intent(in), dimension(ph1%zst(1):ph1%zen(1),ph1%zst(2):ph1%zen(2),nzmsize,npress) :: pp3
real(mytype), intent(in), dimension(xsize(1),xsize(2),xsize(3),numscalar) :: phi1
real(mytype), intent(in), dimension(xsize(1),xsize(2),xsize(3)) :: ep1
integer, intent(in) :: num
! Write vorticity as an example of post processing
! Perform communications if needed
if (sync_vel_needed) then
call transpose_x_to_y(ux1,ux2)
call transpose_x_to_y(uy1,uy2)
call transpose_x_to_y(uz1,uz2)
call transpose_y_to_z(ux2,ux3)
call transpose_y_to_z(uy2,uy3)
call transpose_y_to_z(uz2,uz3)
sync_vel_needed = .false.
endif
!x-derivatives
call derx (ta1,ux1,di1,sx,ffx,fsx,fwx,xsize(1),xsize(2),xsize(3),0,ubcx)
call derx (tb1,uy1,di1,sx,ffxp,fsxp,fwxp,xsize(1),xsize(2),xsize(3),1,ubcy)
call derx (tc1,uz1,di1,sx,ffxp,fsxp,fwxp,xsize(1),xsize(2),xsize(3),1,ubcz)
!y-derivatives
call dery (ta2,ux2,di2,sy,ffyp,fsyp,fwyp,ppy,ysize(1),ysize(2),ysize(3),1,ubcx)
call dery (tb2,uy2,di2,sy,ffy,fsy,fwy,ppy,ysize(1),ysize(2),ysize(3),0,ubcy)
call dery (tc2,uz2,di2,sy,ffyp,fsyp,fwyp,ppy,ysize(1),ysize(2),ysize(3),1,ubcz)
!!z-derivatives
call derz (ta3,ux3,di3,sz,ffzp,fszp,fwzp,zsize(1),zsize(2),zsize(3),1,ubcx)
call derz (tb3,uy3,di3,sz,ffzp,fszp,fwzp,zsize(1),zsize(2),zsize(3),1,ubcy)
call derz (tc3,uz3,di3,sz,ffz,fsz,fwz,zsize(1),zsize(2),zsize(3),0,ubcz)
!!all back to x-pencils
call transpose_z_to_y(ta3,td2)
call transpose_z_to_y(tb3,te2)
call transpose_z_to_y(tc3,tf2)
call transpose_y_to_x(td2,tg1)
call transpose_y_to_x(te2,th1)
call transpose_y_to_x(tf2,ti1)
call transpose_y_to_x(ta2,td1)
call transpose_y_to_x(tb2,te1)
call transpose_y_to_x(tc2,tf1)
!du/dx=ta1 du/dy=td1 and du/dz=tg1
!dv/dx=tb1 dv/dy=te1 and dv/dz=th1
!dw/dx=tc1 dw/dy=tf1 and dw/dz=ti1
!Q=-0.5*(ta1**2+te1**2+di1**2)-td1*tb1-tg1*tc1-th1*tf1
di1 = zero
di1(:,:,:) = - half*(ta1(:,:,:)**2 + te1(:,:,:)**2 + ti1(:,:,:)**2) &
- td1(:,:,:) * tb1(:,:,:) &
- tg1(:,:,:) * tc1(:,:,:) &
- th1(:,:,:) * tf1(:,:,:)
call write_field(di1, ".", "critq", num, flush = .true.) ! Reusing temporary array, force flush
if (mhd_active) then
call write_field(Je(:,:,:,1), ".", "J_x", num, flush = .true.)
call write_field(Je(:,:,:,2), ".", "J_y", num, flush = .true.)
call write_field(Je(:,:,:,3), ".", "J_z", num, flush = .true.)
call write_field(Bm(:,:,:,1), ".", "B_x", num, flush = .true.)
call write_field(Bm(:,:,:,2), ".", "B_y", num, flush = .true.)
call write_field(Bm(:,:,:,3), ".", "B_z", num, flush = .true.)
endif
end subroutine visu_channel
!############################################################################
!############################################################################
!!
!! SUBROUTINE: momentum_forcing
!! AUTHOR: Paul Bartholomew
!! DESCRIPTION: Applies rotation for t < spinup_time.
!!
!############################################################################
subroutine momentum_forcing_channel(dux1, duy1, duz1, ux1, uy1, uz1)
implicit none
real(mytype), intent(in), dimension(xsize(1), xsize(2), xsize(3)) :: ux1, uy1, uz1
real(mytype), dimension(xsize(1), xsize(2), xsize(3), ntime) :: dux1, duy1, duz1
if (cpg) then
!! fcpg: add constant pressure gradient in streamwise direction
if (idir_stream == 1) then
dux1(:,:,:,1) = dux1(:,:,:,1) + fcpg !* (re/re_cent)**2
else
duz1(:,:,:,1) = duz1(:,:,:,1) + fcpg !* (re/re_cent)**2
endif
endif
! To update to take into account possible flow in z dir
if (itime < spinup_time .and. iin <= 2) then
if (nrank==0.and.(mod(itime, ilist) == 0 .or. itime == ifirst .or. itime == ilast)) &
write(*,*) 'Rotating turbulent channel at speed ',wrotation
dux1(:,:,:,1) = dux1(:,:,:,1) - wrotation*uy1(:,:,:)
duy1(:,:,:,1) = duy1(:,:,:,1) + wrotation*ux1(:,:,:)
endif
end subroutine momentum_forcing_channel
!############################################################################
!############################################################################
subroutine geomcomplex_channel(epsi,nxi,nxf,ny,nyi,nyf,nzi,nzf,yp,remp)
use param, only : zero, one, two, ten
use ibm
implicit none
integer :: nxi,nxf,ny,nyi,nyf,nzi,nzf
real(mytype),dimension(nxi:nxf,nyi:nyf,nzi:nzf) :: epsi
real(mytype),dimension(ny) :: yp
real(mytype) :: remp
integer :: j
real(mytype) :: ym
real(mytype) :: zeromach
real(mytype) :: h
epsi(:,:,:) = zero
h = (yly - two) / two
zeromach=one
do while ((one + zeromach / two) .gt. one)
zeromach = zeromach/two
end do
zeromach = ten*zeromach
do j=nyi,nyf
ym=yp(j)
if ((ym.le.h).or.(ym.ge.(h+two))) then
epsi(:,j,:)=remp
endif
enddo
return
end subroutine geomcomplex_channel
!############################################################################
!############################################################################
subroutine sem_init_channel(ux1, uy1, uz1)
implicit none
! Arguments
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux1,uy1,uz1
! Local variables
integer :: i, j, k, ii, jj
real(mytype) :: x, y, z, ftent, um
integer ( kind = 4 ), parameter :: nsemini = 1000 ! For the moment we fix it but after this can go in the input file
real(mytype), dimension(3,nsemini) :: eddy, posvor
real(mytype) :: volsemini, rrand, ddx, ddy, ddz, lsem, upr, vpr, wpr
real(mytype), dimension(3) :: dim_min, dim_max
dim_min(1) = zero
dim_min(2) = zero
dim_min(3) = zero
dim_max(1) = xlx
dim_max(2) = yly
dim_max(3) = zlz
volsemini = xlx * yly * zlz
! 3 int to get different random numbers
do jj = 1, nsemini
! Vortex Position
do ii = 1, 3
call random_number(rrand)
posvor(ii,jj) = dim_min(ii)+(dim_max(ii)-dim_min(ii))*rrand
enddo
! Eddy intensity
do ii = 1, 3
call random_number(rrand)
if (rrand <= zpfive) then
eddy(ii,jj) = -one
else
eddy(ii,jj) = +one
endif
enddo
enddo
! Loops to apply the fluctuations
do k = 1, xsize(3)
z = real((k+xstart(3)-1-1),mytype)*dz
do j = 1, xsize(2)
if (istret==0) y=real(j+xstart(2)-2,mytype)*dy
if (istret/=0) y=yp(j+xstart(2)-1)
do i = 1, xsize(1)
x = real(i-1,mytype)*dx
lsem = 0.15_mytype ! For the moment we keep it constant
upr = zero
vpr = zero
wpr = zero
do jj = 1, nsemini
ddx = abs(x-posvor(1,jj))
ddy = abs(y-posvor(2,jj))
ddz = abs(z-posvor(3,jj))
if (ddx < lsem .and. ddy < lsem .and. ddz < lsem) then
! coefficients for the intensity of the fluctuation
ftent = (one-ddx/lsem)*(one-ddy/lsem)*(one-ddz/lsem)
ftent = ftent / (sqrt(two/three*lsem))**3
upr = upr + eddy(1,jj) * ftent
vpr = vpr + eddy(2,jj) * ftent
wpr = wpr + eddy(3,jj) * ftent
endif
enddo
upr = upr * sqrt(volsemini/nsemini)
vpr = vpr * sqrt(volsemini/nsemini)
wpr = wpr * sqrt(volsemini/nsemini)
!
um = one-(y-yly*half)**2 ! we can use a better arroximation
if (idir_stream == 1) then
ux1(i,j,k)=upr*sqrt(two/three*init_noise*um) + um
uy1(i,j,k)=vpr*sqrt(two/three*init_noise*um)
uz1(i,j,k)=wpr*sqrt(two/three*init_noise*um)
else
uz1(i,j,k)=upr*sqrt(two/three*init_noise*um) + um
uy1(i,j,k)=vpr*sqrt(two/three*init_noise*um)
ux1(i,j,k)=wpr*sqrt(two/three*init_noise*um)
endif
enddo
enddo
enddo
end subroutine sem_init_channel
!############################################################################
end module channel