forked from ImperialCollegeLondon/WInc3D
-
Notifications
You must be signed in to change notification settings - Fork 4
/
probe.f90
349 lines (287 loc) · 11.7 KB
/
probe.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
!==================================================
! Subroutine for sampling the velocity from a point
!==================================================
! Routine that initializes the probe locations
subroutine init_probe
use param
!use variables
use var
implicit none
character(1000) :: ReadLine
integer :: i
open(70,file=Probelistfile)
! Read the Number of Blades
read(70,'(A)') ReadLine
read(ReadLine(index(ReadLine,':')+1:),*) Nprobes
! Allocate the probe locations
allocate(xprobe(Nprobes),yprobe(Nprobes),zprobe(Nprobes),uprobe(Nprobes),vprobe(Nprobes),wprobe(Nprobes))
allocate(uprobe_part(Nprobes),vprobe_part(Nprobes),wprobe_part(Nprobes))
do i=1,Nprobes
read(70,'(A)') ReadLine ! Probe point ...
read(ReadLine,*) xprobe(i), yprobe(i), zprobe(i)
end do
end subroutine init_probe
subroutine init_probe_pencil
USE param
USE decomp_2d
use var
implicit none
NProbes=nx*6 ! or xsize(1) it should be the same
! Allocate the probe locations
allocate(xprobe(Nprobes),yprobe(Nprobes),zprobe(Nprobes),uprobe(Nprobes),vprobe(Nprobes),wprobe(Nprobes))
allocate(uprobe_part(Nprobes),vprobe_part(Nprobes),wprobe_part(Nprobes))
end subroutine init_probe_pencil
subroutine probe_pencil(ux,uy,uz,phi)
USE param
USE decomp_2d
use var
use MPI
implicit none
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: ux,uy,uz,phi
real(mytype) :: xmesh, ymesh, zmesh, dist, min_dist
integer :: ipr, iy, ix, i, j, k, min_i, min_j, min_k, ierr
real(mytype) :: ymin, ymax, zmin,zmax
if (istret.eq.0) then
ymin=(xstart(2)-1)*dy-dy/2.0 ! Add -dy/2.0 overlap
ymax=(xend(2)-1)*dy+dy/2.0 ! Add +dy/2.0 overlap
else
ymin=yp(xstart(2))
ymax=yp(xend(2))
endif
zmin=(xstart(3)-1)*dz-dz/2.0 ! Add a -dz/2.0 overlap
zmax=(xend(3)-1)*dz+dz/2.0 ! Add a +dz/2.0 overlap
do ipr=1,NProbes
ix=mod(ipr,xsize(1))
if (ix==0) ix=xsize(1)
xprobe(ipr)=(ix-1)*dx
iy=ipr/xsize(1)+1
if (mod(ipr,xsize(1))==0) iy=ipr/xsize(1)
yprobe(ipr)=y_loc_pencil(iy)*dy
zprobe(ipr)=z_loc_pencil(iy)*dz
if((yprobe(ipr)>=ymin).and.(yprobe(ipr)<=ymax).and.(zprobe(ipr)>=zmin).and.(zprobe(ipr)<=zmax)) then
min_dist=1e6
do k=1,xsize(3)
zmesh=(k-1)*dz
do j=1,xsize(2)
if (istret.eq.0) ymesh=(j-1)*dy
if (istret.ne.0) ymesh=yp(j)
do i=1,xsize(1)
xmesh=(i-1)*dx
dist = sqrt((xprobe(ipr)-xmesh)**2.+(yprobe(ipr)-ymesh)**2.+(zprobe(ipr)-zmesh)**2.)
if (dist<min_dist) then
min_dist=dist
min_i=i
min_j=j
min_k=k
endif
enddo
enddo
enddo
uprobe_part(ipr)=ux(min_i,min_j,min_k)
vprobe_part(ipr)=uy(min_i,min_j,min_k)
wprobe_part(ipr)=uz(min_i,min_j,min_k)
else
uprobe_part(ipr)=0.0
vprobe_part(ipr)=0.0
wprobe_part(ipr)=0.0
!write(*,*) 'Warning: I do not own this node'
endif
enddo
call MPI_ALLREDUCE(uprobe_part,uprobe,Nprobes,MPI_REAL8,MPI_SUM, &
MPI_COMM_WORLD,ierr)
call MPI_ALLREDUCE(vprobe_part,vprobe,Nprobes,MPI_REAL8,MPI_SUM, &
MPI_COMM_WORLD,ierr)
call MPI_ALLREDUCE(wprobe_part,wprobe,Nprobes,MPI_REAL8,MPI_SUM, &
MPI_COMM_WORLD,ierr)
return
end subroutine probe_pencil
subroutine probe(ux,uy,uz,phi)
use actuator_line_model_utils ! used only for the trilinear interpolation
USE param
USE decomp_2d
!USE variables
use var
use MPI
implicit none
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: ux,uy,uz,phi
integer :: i,j,k, ipr, ierr
real(mytype) :: ymin,ymax,zmin,zmax
real(mytype) :: xmesh,ymesh,zmesh
real(mytype) :: dist, min_dist
real(mytype) :: x0,y0,z0,x1,y1,z1,x,y,z,u000,u100,u001,u101,u010,u110,u011,u111
integer :: min_i,min_j,min_k
integer :: i_lower, j_lower, k_lower, i_upper, j_upper, k_upper
if (istret.eq.0) then
ymin=(xstart(2)-1)*dy-dy/2.0 ! Add -dy/2.0 overlap
ymax=(xend(2)-1)*dy+dy/2.0 ! Add +dy/2.0 overlap
else
ymin=yp(xstart(2))
ymax=yp(xend(2))
endif
zmin=(xstart(3)-1)*dz-dz/2.0 ! Add a -dz/2.0 overlap
zmax=(xend(3)-1)*dz+dz/2.0 ! Add a +dz/2.0 overlap
do ipr=1,Nprobes
min_dist=1e6
if((yprobe(ipr)>=ymin).and.(yprobe(ipr)<=ymax).and.(zprobe(ipr)>=zmin).and.(zprobe(ipr)<=zmax)) then
!write(*,*) 'Warning: I own this node'
do k=xstart(3),xend(3)
zmesh=(k-1)*dz
do j=xstart(2),xend(2)
if (istret.eq.0) ymesh=(j-1)*dy
if (istret.ne.0) ymesh=yp(j)
do i=xstart(1),xend(1)
xmesh=(i-1)*dx
dist = sqrt((xprobe(ipr)-xmesh)**2.+(yprobe(ipr)-ymesh)**2.+(zprobe(ipr)-zmesh)**2.)
if (dist<min_dist) then
min_dist=dist
min_i=i
min_j=j
min_k=k
endif
enddo
enddo
enddo
if(yprobe(ipr)>ymax.or.yprobe(ipr)<ymin) then
write(*,*) 'In processor ', nrank
write(*,*) 'yprobe =', yprobe(ipr),'is not within the', ymin, ymax, 'limits'
stop
endif
if(xprobe(ipr)>(min_i-1)*dx) then
i_lower=min_i
i_upper=min_i+1
else if(xprobe(ipr)<(min_i-1)*dx) then
i_lower=min_i-1
i_upper=min_i
else if(xprobe(ipr)==(min_i-1)*dx) then
i_lower=min_i
i_upper=min_i
endif
if (istret.eq.0) then
if(yprobe(ipr)>(min_j-1)*dy.and.yprobe(ipr)<(xend(2)-1)*dy) then
j_lower=min_j
j_upper=min_j+1
else if(yprobe(ipr)>(min_j-1)*dy.and.yprobe(ipr)>(xend(2)-1)*dy) then
j_lower=min_j
j_upper=min_j
else if(yprobe(ipr)<(min_j-1)*dy.and.yprobe(ipr)>(xstart(2)-1)*dy) then
j_lower=min_j-1
j_upper=min_j
else if(yprobe(ipr)<(min_j-1)*dy.and.yprobe(ipr)<(xstart(2)-1)*dy) then
j_lower=min_j
j_upper=min_j
else if (yprobe(ipr)==(min_j-1)*dy) then
j_lower=min_j
j_upper=min_j
endif
else
if(yprobe(ipr)>yp(min_j)) then
j_lower=min_j
j_upper=min_j+1
else if(yprobe(ipr)<yp(min_j)) then
j_lower=min_j-1
j_upper=min_j
else if (yprobe(ipr)==yp(min_j)) then
j_lower=min_j
j_upper=min_j
endif
endif
if(zprobe(ipr)>(min_k-1)*dz.and.zprobe(ipr)<(xend(3)-1)*dz) then
k_lower=min_k
k_upper=min_k+1
elseif(zprobe(ipr)>(min_k-1)*dz.and.zprobe(ipr)>(xend(3)-1)*dz) then
k_lower=min_k
k_upper=min_k
else if(zprobe(ipr)<(min_k-1)*dz.and.zprobe(ipr)>(xstart(3)-1)*dz) then
k_lower=min_k-1
k_upper=min_k
else if(zprobe(ipr)<(min_k-1)*dz.and.zprobe(ipr)<(xstart(3)-1)*dz) then
k_lower=min_k
k_upper=min_k
else if (zprobe(ipr)==(min_k-1)*dz) then
k_lower=min_k
k_upper=min_k
endif
! Prepare for interpolation
x0=(i_lower-1)*dx
x1=(i_upper-1)*dx
if (istret.eq.0) then
y0=(j_lower-1)*dy
y1=(j_upper-1)*dy
else
y0=yp(j_lower)
y1=yp(j_upper)
endif
z0=(k_lower-1)*dz
z1=(k_upper-1)*dz
x=xprobe(ipr)
y=yprobe(ipr)
z=zprobe(ipr)
! Apply interpolation kernels from 8 neighboring nodes
uprobe_part(ipr)= trilinear_interpolation(x0,y0,z0, &
x1,y1,z1, &
x,y,z, &
ux1(i_lower,j_lower,k_lower), &
ux1(i_upper,j_lower,k_lower), &
ux1(i_lower,j_lower,k_upper), &
ux1(i_upper,j_lower,k_upper), &
ux1(i_lower,j_upper,k_lower), &
ux1(i_upper,j_upper,k_lower), &
ux1(i_lower,j_upper,k_upper), &
ux1(i_upper,j_upper,k_upper))
vprobe_part(ipr)= trilinear_interpolation(x0,y0,z0, &
x1,y1,z1, &
x,y,z, &
uy1(i_lower,j_lower,k_lower), &
uy1(i_upper,j_lower,k_lower), &
uy1(i_lower,j_lower,k_upper), &
uy1(i_upper,j_lower,k_upper), &
uy1(i_lower,j_upper,k_lower), &
uy1(i_upper,j_upper,k_lower), &
uy1(i_lower,j_upper,k_upper), &
uy1(i_upper,j_upper,k_upper))
wprobe_part(ipr)= trilinear_interpolation(x0,y0,z0, &
x1,y1,z1, &
x,y,z, &
uz1(i_lower,j_lower,k_lower), &
uz1(i_upper,j_lower,k_lower), &
uz1(i_lower,j_lower,k_upper), &
uz1(i_upper,j_lower,k_upper), &
uz1(i_lower,j_upper,k_lower), &
uz1(i_upper,j_upper,k_lower), &
uz1(i_lower,j_upper,k_upper), &
uz1(i_upper,j_upper,k_upper))
else
uprobe_part(ipr)=0.0
vprobe_part(ipr)=0.0
wprobe_part(ipr)=0.0
!write(*,*) 'Warning: I do not own this node'
endif
enddo
call MPI_ALLREDUCE(uprobe_part,uprobe,Nprobes,MPI_REAL8,MPI_SUM, &
MPI_COMM_WORLD,ierr)
call MPI_ALLREDUCE(vprobe_part,vprobe,Nprobes,MPI_REAL8,MPI_SUM, &
MPI_COMM_WORLD,ierr)
call MPI_ALLREDUCE(wprobe_part,wprobe,Nprobes,MPI_REAL8,MPI_SUM, &
MPI_COMM_WORLD,ierr)
end subroutine probe
subroutine write_probe(isample)
USE param
USE decomp_2d
!USE variables
use var
implicit none
integer,intent(in) :: isample
integer :: ipr
character(len=20) :: filename, Format1
990 format('probe',I6.6)
write(filename, 990) isample
if (nrank==0) then
open(2019,File=filename)
write(2019,*) 'Probe ID, xprobe, yprobe, zprobe, u_probe, v_probe, z_probe'
Format1="(I5,A,6(E14.7,A))"
do ipr=1,Nprobes
write(2019,Format1) ipr,',',xprobe(ipr), ',', yprobe(ipr),',', zprobe(ipr),',', uprobe(ipr),',', vprobe(ipr),',', wprobe(ipr)
end do
close(2019)
endif
end subroutine