1 |
C $Header: /u/gcmpack/MITgcm/pkg/flt/flt_bilinear.F,v 1.1 2001/09/13 17:43:55 adcroft Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "FLT_CPPOPTIONS.h" |
5 |
|
6 |
subroutine flt_bilinear( |
7 |
I xp, |
8 |
I yp, |
9 |
O uu, |
10 |
I kp, |
11 |
I u, |
12 |
I nu, |
13 |
I bi, |
14 |
I bj |
15 |
& ) |
16 |
|
17 |
c ================================================================== |
18 |
c SUBROUTINE flt_bilinear |
19 |
c ================================================================== |
20 |
c |
21 |
c o Bilinear scheme to find u of particle at given xp,yp location |
22 |
c |
23 |
c ================================================================== |
24 |
c SUBROUTINE flt_bilinear |
25 |
c ================================================================== |
26 |
|
27 |
c == global variables == |
28 |
|
29 |
#include "SIZE.h" |
30 |
|
31 |
c == routine arguments == |
32 |
|
33 |
_RL xp, yp |
34 |
_RL uu |
35 |
integer nu, kp, bi, bj |
36 |
_RL u (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
37 |
|
38 |
c == local variables == |
39 |
|
40 |
INTEGER nnx, nny, nfx, nfy, nfxp, nfyp |
41 |
_RL dx, dy, ddx, ddy |
42 |
integer ip |
43 |
_RL xx, yy, phi, scalex, scaley |
44 |
_RL u11, u12, u22, u21 |
45 |
|
46 |
c == end of interface == |
47 |
|
48 |
nnx = int(xp) |
49 |
nny = int(yp) |
50 |
dx = xp - float(nnx) |
51 |
dy = yp - float(nny) |
52 |
c |
53 |
c to choose the u box in which the particle is found |
54 |
c nu=1 for T, S |
55 |
c nu=2 for u |
56 |
c nu=3 for v |
57 |
c nu=4 for w |
58 |
c |
59 |
if (nu.eq.1.or.nu.eq.4) then |
60 |
nfx = nnx |
61 |
nfy = nny |
62 |
ddx = dx |
63 |
ddy = dy |
64 |
endif |
65 |
c |
66 |
if (nu.eq.2) then |
67 |
if (dx.le.0.5) then |
68 |
nfx = nnx |
69 |
ddx = dx + 0.5 |
70 |
else |
71 |
nfx = nnx + 1 |
72 |
ddx = dx - 0.5 |
73 |
endif |
74 |
nfy = nny |
75 |
ddy = dy |
76 |
endif |
77 |
c |
78 |
if (nu.eq.3) then |
79 |
if (dy.le.0.5) then |
80 |
nfy = nny |
81 |
ddy = dy + 0.5 |
82 |
else |
83 |
nfy = nny + 1 |
84 |
ddy = dy - 0.5 |
85 |
endif |
86 |
nfx = nnx |
87 |
ddx = dx |
88 |
endif |
89 |
c |
90 |
c |
91 |
cab change start |
92 |
c was correct only for global? |
93 |
c if(nfx.gt.nx) nfx=nfx-nx |
94 |
if(nfx.gt.nx) nfx=nx |
95 |
cab change end |
96 |
if(nfy.gt.ny) nfy=ny |
97 |
nfxp = nfx + 1 |
98 |
nfyp = nfy + 1 |
99 |
cab change start |
100 |
c if (nfx.eq.nx) nfxp = 1 |
101 |
if (nfx.eq.nx) nfxp = nfx |
102 |
cab change end |
103 |
if (nfy.eq.ny) nfyp = nfy |
104 |
|
105 |
if (nu.lt.4) then |
106 |
u11 = u(nfx,nfy,kp,bi,bj) |
107 |
u21 = u(nfxp,nfy,kp,bi,bj) |
108 |
u22 = u(nfxp,nfyp,kp,bi,bj) |
109 |
u12 = u(nfx,nfyp,kp,bi,bj) |
110 |
endif |
111 |
if (nu.eq.4) then |
112 |
caw This may be incorrect. |
113 |
u11 = u(nfx,nfy,kp,bi,bj)+u(nfx,nfy,kp-1,bi,bj) |
114 |
u21 = u(nfxp,nfy,kp,bi,bj)+u(nfxp,nfy,kp-1,bi,bj) |
115 |
u22 = u(nfxp,nfyp,kp,bi,bj)+u(nfxp,nfyp,kp-1,bi,bj) |
116 |
u12 = u(nfx,nfyp,kp,bi,bj)+u(nfx,nfyp,kp-1,bi,bj) |
117 |
endif |
118 |
|
119 |
c |
120 |
c |
121 |
c bilinear interpolation (from numerical recipes) |
122 |
uu = (1-ddx)*(1-ddy)*u11 + ddx*(1-ddy)*u21 + ddx*ddy*u22 |
123 |
. + (1-ddx)*ddy*u12 |
124 |
c |
125 |
c |
126 |
return |
127 |
end |
128 |
|
129 |
subroutine flt_trilinear( |
130 |
I xp, |
131 |
I yp, |
132 |
I zp, |
133 |
O uu, |
134 |
I u, |
135 |
I nu, |
136 |
I bi, |
137 |
I bj |
138 |
& ) |
139 |
|
140 |
c ================================================================== |
141 |
c SUBROUTINE flt_trilinear |
142 |
c ================================================================== |
143 |
c |
144 |
c o Trilinear scheme to find u of particle at a given xp,yp,zp |
145 |
c location. This routine is a straight forward generalization of the |
146 |
c bilinear interpolation scheme. |
147 |
c |
148 |
c started: 2004.05.28 Antti Westerlund (antti.westerlund@fimr.fi) |
149 |
c and Sergio Jaramillo (sju@eos.ubc.ca). |
150 |
c (adopted from subroutine bilinear by Arne Biastoch) |
151 |
c |
152 |
c ================================================================== |
153 |
c SUBROUTINE flt_trilinear |
154 |
c ================================================================== |
155 |
|
156 |
c == global variables == |
157 |
|
158 |
#include "SIZE.h" |
159 |
|
160 |
c == routine arguments == |
161 |
|
162 |
_RL xp, yp, zp |
163 |
_RL uu |
164 |
integer nu, bi, bj |
165 |
_RL u (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
166 |
|
167 |
c == local variables == |
168 |
|
169 |
INTEGER nnx, nny, nnz, nfx, nfy, nfz, nfxp, nfyp, nfzp |
170 |
_RL dx, dy, dz, ddx, ddy, ddz |
171 |
integer ip |
172 |
_RL xx, yy, zz, phi, scalex, scaley, scalez |
173 |
_RL u111, u121, u221, u211, u112, u122, u222, u212 |
174 |
|
175 |
c == end of interface == |
176 |
|
177 |
c Round xp,yp,zp down to find a grid point. |
178 |
nnx = int(xp) |
179 |
nny = int(yp) |
180 |
nnz = int(zp) |
181 |
|
182 |
c Find out the distance from the gridpoint. |
183 |
dx = xp - float(nnx) |
184 |
dy = yp - float(nny) |
185 |
dz = zp - float(nnz) |
186 |
c |
187 |
c to choose the u box in which the particle is found |
188 |
c nu=1 for T, S |
189 |
c nu=2 for u |
190 |
c nu=3 for v |
191 |
c nu=4 for w |
192 |
c |
193 |
c Velocities are face quantities and must therefore be treated differently |
194 |
c |
195 |
c if the variable is T,S |
196 |
if (nu.eq.1) then |
197 |
nfx = nnx |
198 |
ddx = dx |
199 |
nfy = nny |
200 |
ddy = dy |
201 |
nfz = nnz |
202 |
ddz = dz |
203 |
endif |
204 |
c if the variable is u |
205 |
if (nu.eq.2) then |
206 |
if (dx.le.0.5) then |
207 |
nfx = nnx |
208 |
ddx = dx + 0.5 |
209 |
else |
210 |
nfx = nnx + 1 |
211 |
ddx = dx - 0.5 |
212 |
endif |
213 |
nfy = nny |
214 |
ddy = dy |
215 |
nfz = nnz |
216 |
ddz = dz |
217 |
endif |
218 |
c if the variable is v |
219 |
if (nu.eq.3) then |
220 |
nfx = nnx |
221 |
ddx = dx |
222 |
if (dy.le.0.5) then |
223 |
nfy = nny |
224 |
ddy = dy + 0.5 |
225 |
else |
226 |
nfy = nny + 1 |
227 |
ddy = dy - 0.5 |
228 |
endif |
229 |
nfz = nnz |
230 |
ddz = dz |
231 |
endif |
232 |
c if the variable is w |
233 |
if (nu.eq.4) then |
234 |
nfx = nnx |
235 |
ddx = dx |
236 |
nfy = nny |
237 |
ddy = dy |
238 |
if (dz.le.0.5) then |
239 |
nfz = nnz |
240 |
ddz = dz + 0.5 |
241 |
else |
242 |
nfz = nnz + 1 |
243 |
ddz = dz - 0.5 |
244 |
endif |
245 |
endif |
246 |
c |
247 |
c if we are near or over the edge, limit nfx/y/z |
248 |
if(nfx.gt.nx) nfx=nx |
249 |
if(nfy.gt.ny) nfy=ny |
250 |
if(nfz.gt.nr) nfz=nr |
251 |
if(nfz.le.1) nfz=1 |
252 |
c We should possibly check something else too... |
253 |
c |
254 |
c the coordinates for the other grid points |
255 |
nfxp = nfx + 1 |
256 |
nfyp = nfy + 1 |
257 |
nfzp = nfz + 1 |
258 |
c if we are near the edge, also limit nf?p |
259 |
if (nfx.eq.nx) nfxp = nfx |
260 |
if (nfy.eq.ny) nfyp = nfy |
261 |
if (nfz.eq.nr) nfzp = nfz |
262 |
|
263 |
c Values of the field at relevant grid points |
264 |
u111 = u(nfx,nfy,nfz,bi,bj) |
265 |
u211 = u(nfxp,nfy,nfz,bi,bj) |
266 |
u221 = u(nfxp,nfyp,nfz,bi,bj) |
267 |
u121 = u(nfx,nfyp,nfz,bi,bj) |
268 |
u112 = u(nfx,nfy,nfzp,bi,bj) |
269 |
u212 = u(nfxp,nfy,nfzp,bi,bj) |
270 |
u222 = u(nfxp,nfyp,nfzp,bi,bj) |
271 |
u122 = u(nfx,nfyp,nfzp,bi,bj) |
272 |
|
273 |
c Trilinear interpolation, a straight forward generalization |
274 |
c of the bilinear interpolation scheme. |
275 |
uu = (1-ddx)*(1-ddy)*(1-ddz)*u111 + ddx*(1-ddy)*(1-ddz)*u211 |
276 |
& + ddx*ddy*(1-ddz)*u221 + (1-ddx)*ddy*(1-ddz)*u121 |
277 |
& + (1-ddx)*(1-ddy)*ddz*u112 + ddx*(1-ddy)*ddz*u212 |
278 |
& + ddx*ddy*ddz*u222 + (1-ddx)*ddy*ddz*u122 |
279 |
c |
280 |
c |
281 |
return |
282 |
end |
283 |
|
284 |
subroutine flt_bilinear2d( |
285 |
I xp, |
286 |
I yp, |
287 |
O uu, |
288 |
I u, |
289 |
I nu, |
290 |
I bi, |
291 |
I bj |
292 |
& ) |
293 |
|
294 |
c ================================================================== |
295 |
c SUBROUTINE flt_bilinear2d |
296 |
c ================================================================== |
297 |
c |
298 |
c o Bilinear scheme to find u of particle at given xp,yp location |
299 |
c o For 2D fields |
300 |
c |
301 |
c started: Arne Biastoch abiastoch@ucsd.edu 13-Jan-2000 |
302 |
c (adopted from subroutine bilinear) |
303 |
c |
304 |
c ================================================================== |
305 |
c SUBROUTINE flt_bilinear2d |
306 |
c ================================================================== |
307 |
|
308 |
c == global variables == |
309 |
|
310 |
#include "SIZE.h" |
311 |
|
312 |
c == routine arguments == |
313 |
|
314 |
_RL xp, yp |
315 |
_RL uu |
316 |
integer nu, bi, bj |
317 |
_RL u (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
318 |
|
319 |
c == local variables == |
320 |
|
321 |
INTEGER nnx, nny, nfx, nfy, nfxp, nfyp |
322 |
_RL dx, dy, ddx, ddy |
323 |
integer ip |
324 |
_RL xx, yy, phi, scalex, scaley |
325 |
_RL u11, u12, u22, u21 |
326 |
|
327 |
c == end of interface == |
328 |
|
329 |
nnx = int(xp) |
330 |
nny = int(yp) |
331 |
dx = xp - float(nnx) |
332 |
dy = yp - float(nny) |
333 |
c |
334 |
c to choose the u box in which the particle is found |
335 |
c nu=1 for T, S |
336 |
c nu=2 for u |
337 |
c nu=3 for v |
338 |
c nu=4 for w |
339 |
c |
340 |
if (nu.eq.1.or.nu.eq.4) then |
341 |
nfx = nnx |
342 |
nfy = nny |
343 |
ddx = dx |
344 |
ddy = dy |
345 |
endif |
346 |
c |
347 |
if (nu.eq.2) then |
348 |
if (dx.le.0.5) then |
349 |
nfx = nnx |
350 |
ddx = dx + 0.5 |
351 |
else |
352 |
nfx = nnx + 1 |
353 |
ddx = dx - 0.5 |
354 |
endif |
355 |
nfy = nny |
356 |
ddy = dy |
357 |
endif |
358 |
c |
359 |
if (nu.eq.3) then |
360 |
if (dy.le.0.5) then |
361 |
nfy = nny |
362 |
ddy = dy + 0.5 |
363 |
else |
364 |
nfy = nny + 1 |
365 |
ddy = dy - 0.5 |
366 |
endif |
367 |
nfx = nnx |
368 |
ddx = dx |
369 |
endif |
370 |
c |
371 |
cab change start |
372 |
c was correct only for global? |
373 |
c if(nfx.gt.nx) nfx=nfx-nx |
374 |
if(nfx.gt.nx) nfx=nx |
375 |
cab change end |
376 |
if(nfy.gt.ny) nfy=ny |
377 |
nfxp = nfx + 1 |
378 |
nfyp = nfy + 1 |
379 |
cab change start |
380 |
c if (nfx.eq.nx) nfxp = 1 |
381 |
if (nfx.eq.nx) nfxp = nfx |
382 |
cab change end |
383 |
if (nfy.eq.ny) nfyp = nfy |
384 |
|
385 |
if (nu.lt.4) then |
386 |
u11 = u(nfx,nfy,bi,bj) |
387 |
u21 = u(nfxp,nfy,bi,bj) |
388 |
u22 = u(nfxp,nfyp,bi,bj) |
389 |
u12 = u(nfx,nfyp,bi,bj) |
390 |
endif |
391 |
if (nu.eq.4) then |
392 |
caw This may be incorrect. |
393 |
u11 = u(nfx,nfy,bi,bj)+u(nfx,nfy,bi,bj) |
394 |
u21 = u(nfxp,nfy,bi,bj)+u(nfxp,nfy,bi,bj) |
395 |
u22 = u(nfxp,nfyp,bi,bj)+u(nfxp,nfyp,bi,bj) |
396 |
u12 = u(nfx,nfyp,bi,bj)+u(nfx,nfyp,bi,bj) |
397 |
endif |
398 |
c |
399 |
c |
400 |
c bilinear interpolation (from numerical recipes) |
401 |
uu = (1-ddx)*(1-ddy)*u11 + ddx*(1-ddy)*u21 + ddx*ddy*u22 |
402 |
. + (1-ddx)*ddy*u12 |
403 |
c |
404 |
c |
405 |
return |
406 |
end |
407 |
|