/[MITgcm]/MITgcm/pkg/ecco/cost_drifter.F
ViewVC logotype

Contents of /MITgcm/pkg/ecco/cost_drifter.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Tue Nov 24 21:23:47 2015 UTC (8 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +1 -1 lines
FILE REMOVED
- retire old codes to the Attic.

1 C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_drifter.F,v 1.9 2014/10/18 18:15:44 gforget Exp $
2 C $Name: $
3
4 #include "ECCO_OPTIONS.h"
5
6
7 subroutine cost_drifter(
8 I myiter,
9 I mytime,
10 I mythid
11 & )
12
13 c ==================================================================
14 c SUBROUTINE cost_drifter
15 c ==================================================================
16 c
17 c o Evaluate cost function contribution of temperature.
18 c
19 c started: Christian Eckert eckert@mit.edu 30-Jun-1999
20 c
21 c changed: Christian Eckert eckert@mit.edu 25-Feb-2000
22 c
23 c - Restructured the code in order to create a package
24 c for the MITgcmUV.
25 c
26 c changed: Patrick Heimbach heimbach@mit.edu 27-May-2000
27 c
28 c - set ladinit to .true. to initialise adubar file
29 c
30 c ==================================================================
31 c SUBROUTINE cost_drifter
32 c ==================================================================
33
34 implicit none
35
36 c == global variables ==
37
38 #ifdef ALLOW_DRIFTER_COST_CONTRIBUTION
39 #include "EEPARAMS.h"
40 #include "SIZE.h"
41 #include "GRID.h"
42 #include "DYNVARS.h"
43
44 #include "cal.h"
45 #include "ecco_cost.h"
46 #include "CTRL_SIZE.h"
47 #include "ctrl.h"
48 #include "ctrl_dummy.h"
49 #include "optim.h"
50 #ifdef ALLOW_AUTODIFF_TAMC
51 # include "tamc.h"
52 # include "tamc_keys.h"
53 #endif /* ALLOW_AUTODIFF_TAMC */
54 #endif
55
56 c == routine arguments ==
57
58 integer myiter
59 _RL mytime
60 integer mythid
61
62 #ifndef ALLOW_AUTODIFF_WHTAPEIO
63 #ifdef ALLOW_DRIFTER_COST_CONTRIBUTION
64
65 c == local variables ==
66
67 integer bi,bj
68 integer i,j,k
69 integer itlo,ithi
70 integer jtlo,jthi
71 integer jmin,jmax
72 integer imin,imax
73 integer i6min,i6max
74 integer iglomin
75 integer irec
76 integer ilu
77
78 _RL fctile_drift
79 _RL fcthread_drift
80 _RL www (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
81 _RL wud (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
82 _RL wvd (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
83 _RL uddat (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
84 _RL u6bar (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
85 _RL vddat (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
86 _RL v6bar (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
87 _RL udmod (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
88 _RL vdmod (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
89 _RL mask13c(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
90 _RL mask6c (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
91 _RL masktmp(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
92
93 character*(80) fnameud
94 character*(80) fnamevd
95
96 logical doglobalread
97 logical ladinit
98
99 character*(MAX_LEN_MBUF) msgbuf
100
101 c == external functions ==
102
103 integer ilnblnk
104 external ilnblnk
105
106 c == end of interface ==
107
108 jtlo = mybylo(mythid)
109 jthi = mybyhi(mythid)
110 itlo = mybxlo(mythid)
111 ithi = mybxhi(mythid)
112 jmin = 1
113 jmax = sny
114 imin = 1
115 imax = snx
116
117 c-- Read tiled data.
118 doglobalread = .false.
119 ladinit = .false.
120
121 if (optimcycle .ge. 0) then
122 ilu = ilnblnk( ubarfile )
123 write(fnameud(1:80),'(2a,i10.10)')
124 & ubarfile(1:ilu),'.',optimcycle
125 ilu = ilnblnk( vbarfile )
126 write(fnamevd(1:80),'(2a,i10.10)')
127 & vbarfile(1:ilu),'.',optimcycle
128 endif
129
130 fcthread_drift = 0. _d 0
131
132 do bj = jtlo,jthi
133 do bi = itlo,ithi
134
135 #ifdef ALLOW_AUTODIFF_TAMC
136 act1 = bi - myBxLo(myThid)
137 max1 = myBxHi(myThid) - myBxLo(myThid) + 1
138 act2 = bj - myByLo(myThid)
139 max2 = myByHi(myThid) - myByLo(myThid) + 1
140 act3 = myThid - 1
141 max3 = nTx*nTy
142 act4 = 0
143 ikey = (act1 + 1) + act2*max1
144 & + act3*max1*max2
145 & + act4*max1*max2*max3
146 #endif /* ALLOW_AUTODIFF_TAMC */
147
148 k = 2
149 do irec = 1,nmonsrec
150
151 c-- Read time averages and the monthly mean data.
152 call active_read_xyz( fnameud, ubar, irec,
153 & doglobalread, ladinit,
154 & optimcycle, mythid,
155 & xx_ubar_mean_dummy )
156
157 call active_read_xyz( fnamevd, vbar, irec,
158 & doglobalread, ladinit,
159 & optimcycle, mythid,
160 & xx_vbar_mean_dummy )
161
162 do j = jmin,jmax
163 do i = imin,imax
164 if(irec.eq.1)then
165 udmod(i,j,bi,bj)=ubar(i,j,k,bi,bj)
166 vdmod(i,j,bi,bj)=vbar(i,j,k,bi,bj)
167 elseif(irec.eq.nmonsrec)then
168 udmod(i,j,bi,bj)=udmod(i,j,bi,bj)/float(nmonsrec)
169 vdmod(i,j,bi,bj)=vdmod(i,j,bi,bj)/float(nmonsrec)
170 else
171 udmod(i,j,bi,bj)=udmod(i,j,bi,bj)+ubar(i,j,k,bi,bj)
172 vdmod(i,j,bi,bj)=vdmod(i,j,bi,bj)+vbar(i,j,k,bi,bj)
173 endif
174 enddo
175 enddo
176 enddo
177
178 c-- Read drifter data
179 call mdsreadfield( udriftfile, 32, 'RL', 1, udriftdat, 1,
180 & mythid)
181 call mdsreadfield( vdriftfile, 32, 'RL', 1, vdriftdat, 1,
182 & mythid)
183 c-- Read error data
184 call mdsreadfield( udrifterrfile, 32, 'RL', 1, wudrift, 1,
185 & mythid)
186 call mdsreadfield( vdrifterrfile, 32, 'RL', 1, wvdrift, 1,
187 & mythid)
188
189 fctile_drift = 0. _d 0
190
191 c-- Calculate mask for tracer cells (0 => land, 1 => water)
192 do j = jmin,jmax
193 do i = imin,imax
194 mask13c(i,j,bi,bj) = 1. _d 0
195 if (_hFacC(i,j,k,bi,bj) .eq. 0.)
196 & mask13c(i,j,bi,bj) = 0. _d 0
197
198 cph(
199 cph print *, 'WARNING: SPECIFIC SETUP FOR ECCO'
200 cph below statement could be replaced by following
201 cph to make it independnet of Nr:
202 cph
203 cph if ( rC(K) .GT. -1000. ) then
204 cph)
205 c set mask13c=0 in areas shallower than 1000m
206 if (_hFacC(i,j,13,bi,bj) .eq. 0.) then
207 mask13c(i,j,bi,bj) = 0. _d 0
208 endif
209
210 enddo
211 enddo
212
213 i6min=1
214
215 do j = jmin,jmax-1,2
216 do i = i6min,imax-5,6
217 masktmp(i,j,bi,bj) =
218 & (mask13c(i,j,bi,bj)+mask13c(i+1,j,bi,bj)
219 & +mask13c(i+2,j,bi,bj)+mask13c(i+3,j,bi,bj)
220 & +mask13c(i+4,j,bi,bj)+mask13c(i+5,j,bi,bj)
221 & +mask13c(i,j+1,bi,bj)+mask13c(i+1,j+1,bi,bj)
222 & +mask13c(i+2,j+1,bi,bj)+mask13c(i+3,j+1,bi,bj)
223 & +mask13c(i+4,j+1,bi,bj)+mask13c(i+5,j+1,bi,bj))
224 if ( masktmp(i,j,bi,bj) .eq. 0.0 ) then
225 u6bar(i,j,bi,bj) = 0.0
226 else
227 u6bar(i,j,bi,bj) = (
228 & udmod(i,j,bi,bj)*mask13c(i,j,bi,bj)
229 & + udmod(i+1,j,bi,bj)*mask13c(i+1,j,bi,bj)
230 & + udmod(i+2,j,bi,bj)*mask13c(i+2,j,bi,bj)
231 & + udmod(i+3,j,bi,bj)*mask13c(i+3,j,bi,bj)
232 & + udmod(i+4,j,bi,bj)*mask13c(i+4,j,bi,bj)
233 & + udmod(i+5,j,bi,bj)*mask13c(i+5,j,bi,bj)
234 & + udmod(i,j+1,bi,bj)*mask13c(i,j+1,bi,bj)
235 & + udmod(i+1,j+1,bi,bj)*mask13c(i+1,j+1,bi,bj)
236 & + udmod(i+2,j+1,bi,bj)*mask13c(i+2,j+1,bi,bj)
237 & + udmod(i+3,j+1,bi,bj)*mask13c(i+3,j+1,bi,bj)
238 & + udmod(i+4,j+1,bi,bj)*mask13c(i+4,j+1,bi,bj)
239 & + udmod(i+5,j+1,bi,bj)*mask13c(i+5,j+1,bi,bj) )
240 & / ( masktmp(i,j,bi,bj) )
241 endif
242 enddo
243 enddo
244
245 do j = jmin,jmax-1,2
246 do i = i6min,imax-5,6
247 masktmp(i,j,bi,bj) =
248 & (mask13c(i,j,bi,bj)+mask13c(i+1,j,bi,bj)
249 & +mask13c(i+2,j,bi,bj)+mask13c(i+3,j,bi,bj)
250 & +mask13c(i+4,j,bi,bj)+mask13c(i+5,j,bi,bj)
251 & +mask13c(i,j+1,bi,bj)+mask13c(i+1,j+1,bi,bj)
252 & +mask13c(i+2,j+1,bi,bj)+mask13c(i+3,j+1,bi,bj)
253 & +mask13c(i+4,j+1,bi,bj)+mask13c(i+5,j+1,bi,bj))
254 if ( masktmp(i,j,bi,bj) .eq.0.0 ) then
255 v6bar(i,j,bi,bj) = 0.0
256 else
257 v6bar(i,j,bi,bj) = (
258 & vdmod(i,j,bi,bj)*mask13c(i,j,bi,bj)
259 & + vdmod(i+1,j,bi,bj)*mask13c(i+1,j,bi,bj)
260 & + vdmod(i+2,j,bi,bj)*mask13c(i+2,j,bi,bj)
261 & + vdmod(i+3,j,bi,bj)*mask13c(i+3,j,bi,bj)
262 & + vdmod(i+4,j,bi,bj)*mask13c(i+4,j,bi,bj)
263 & + vdmod(i+5,j,bi,bj)*mask13c(i+5,j,bi,bj)
264 & + vdmod(i,j+1,bi,bj)*mask13c(i,j+1,bi,bj)
265 & + vdmod(i+1,j+1,bi,bj)*mask13c(i+1,j+1,bi,bj)
266 & + vdmod(i+2,j+1,bi,bj)*mask13c(i+2,j+1,bi,bj)
267 & + vdmod(i+3,j+1,bi,bj)*mask13c(i+3,j+1,bi,bj)
268 & + vdmod(i+4,j+1,bi,bj)*mask13c(i+4,j+1,bi,bj)
269 & + vdmod(i+5,j+1,bi,bj)*mask13c(i+5,j+1,bi,bj) )
270 & / ( masktmp(i,j,bi,bj) )
271 endif
272 enddo
273 enddo
274
275 do j = jmin,jmax-1,2
276 do i = i6min,imax-5, 6
277 c-- change unit from cm/s to m/s
278 uddat(i,j,bi,bj) = 0.01*udriftdat(i,j,bi,bj)
279 vddat(i,j,bi,bj) = 0.01*vdriftdat(i,j,bi,bj)
280 c-- 5 cm/s lower limit
281 wud(i,j,bi,bj) = 1e4*max(wudrift(i,j,bi,bj),5.D0)**(-2)
282 wvd(i,j,bi,bj) = 1e4*max(wvdrift(i,j,bi,bj),5.D0)**(-2)
283 c wud(i,j,bi,bj) = 1.0
284 c wvd(i,j,bi,bj) = 1.0
285 mask6c(i,j,bi,bj) = 1.0
286 if ( uddat(i,j,bi,bj).eq.0.0) mask6c(i,j,bi,bj)=0.0
287 if ( abs(uddat(i,j,bi,bj)).gt.900) mask6c(i,j,bi,bj)=0.0
288 if ( vddat(i,j,bi,bj).eq.0.0) mask6c(i,j,bi,bj)=0.0
289 if ( abs(vddat(i,j,bi,bj)).gt.900) mask6c(i,j,bi,bj)=0.0
290 enddo
291 enddo
292
293 CADJ STORE wud(:,:,bi,bj)
294 CADJ & = tapelev_ini_bibj_k, key=ikey, byte=isbyte
295 CADJ STORE wvd(:,:,bi,bj)
296 CADJ & = tapelev_ini_bibj_k, key=ikey, byte=isbyte
297 CADJ STORE u6bar(:,:,bi,bj)
298 CADJ & = tapelev_ini_bibj_k, key=ikey, byte=isbyte
299 CADJ STORE v6bar(:,:,bi,bj)
300 CADJ & = tapelev_ini_bibj_k, key=ikey, byte=isbyte
301
302 c-- Compute model data misfit and cost function term for
303 c drifters.
304 do j = jmin,jmax-1,2
305 do i = i6min,imax-5, 6
306 fctile_drift = fctile_drift
307 & + (wud(i,j,bi,bj)*cosphi(i,j,bi,bj)*
308 & mask6c(i,j,bi,bj)*
309 & (u6bar(i,j,bi,bj) - uddat(i,j,bi,bj))*
310 & (u6bar(i,j,bi,bj) - uddat(i,j,bi,bj)) )
311 & + (wvd(i,j,bi,bj)*cosphi(i,j,bi,bj)*
312 & mask6c(i,j,bi,bj)*
313 & (v6bar(i,j,bi,bj) - vddat(i,j,bi,bj))*
314 & (v6bar(i,j,bi,bj) - vddat(i,j,bi,bj)) )
315 if ( cosphi(i,j,bi,bj)*mask6c(i,j,bi,bj) .ne. 0. ) then
316 if ( wud(i,j,bi,bj) .ne. 0. )
317 & num_drift(bi,bj) = num_drift(bi,bj) + 1. _d 0
318 if ( wvd(i,j,bi,bj) .ne. 0. )
319 & num_drift(bi,bj) = num_drift(bi,bj) + 1. _d 0
320 endif
321 enddo
322 enddo
323
324 fcthread_drift = fcthread_drift + fctile_drift
325 objf_drift(bi,bj) = objf_drift(bi,bj) + fctile_drift
326
327 #ifdef ECCO_VERBOSE
328 c-- Print cost function for each tile in each thread.
329 write(msgbuf,'(a)') ' '
330 call print_message( msgbuf, standardmessageunit,
331 & SQUEEZE_RIGHT , mythid)
332 write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)')
333 & ' cost_drifter: irec,bi,bj = ',irec,bi,bj
334 call print_message( msgbuf, standardmessageunit,
335 & SQUEEZE_RIGHT , mythid)
336 write(msgbuf,'(a,d22.15)')
337 & ' cost function (temperature) = ',
338 & fctile_drift
339 call print_message( msgbuf, standardmessageunit,
340 & SQUEEZE_RIGHT , mythid)
341 #endif
342
343 enddo
344 enddo
345
346 #ifdef ECCO_VERBOSE
347 c-- Print cost function for all tiles.
348 _GLOBAL_SUM_RL( fcthread_drift , myThid )
349 write(msgbuf,'(a)') ' '
350 call print_message( msgbuf, standardmessageunit,
351 & SQUEEZE_RIGHT , mythid)
352 write(msgbuf,'(a,i8.8)')
353 & ' cost_drift: irec = ',irec
354 call print_message( msgbuf, standardmessageunit,
355 & SQUEEZE_RIGHT , mythid)
356 write(msgbuf,'(a,a,d22.15)')
357 & ' global cost function value',
358 & ' (drifters) = ',fcthread_drift
359 call print_message( msgbuf, standardmessageunit,
360 & SQUEEZE_RIGHT , mythid)
361 write(msgbuf,'(a)') ' '
362 call print_message( msgbuf, standardmessageunit,
363 & SQUEEZE_RIGHT , mythid)
364 #endif
365
366 #endif /* ALLOW_AUTODIFF_WHTAPEIO */
367
368 #endif
369
370 return
371 end
372

  ViewVC Help
Powered by ViewVC 1.1.22