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

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

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


Revision 1.9 - (show annotations) (download)
Tue Oct 9 00:02:50 2007 UTC (16 years, 7 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint60, checkpoint61, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint59m, checkpoint59l, checkpoint59o, checkpoint59n, checkpoint59i, checkpoint59k, checkpoint59j, checkpoint61f, checkpoint61g, checkpoint61d, checkpoint61e, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61l, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i
Changes since 1.8: +10 -9 lines
add missing cvs $Header:$ or $Name:$

1 C $Header: $
2 C $Name: $
3
4 #include "COST_CPPOPTIONS.h"
5
6
7 subroutine cost_forcing_gen(
8 I myiter,
9 I mytime,
10 I startrec,
11 I endrec,
12 I xx_gen_file,
13 I xx_gen_dummy,
14 I xx_gen_period,
15 I wmean_gen,
16 I wgen,
17 O num_gen_anom,
18 O num_gen_mean,
19 O objf_gen_anom,
20 O objf_gen_mean,
21 O objf_gen_smoo,
22 I xx_gen_remo_intercept,
23 I xx_gen_remo_slope,
24 I genmask,
25 I mythid
26 & )
27
28 c ==================================================================
29 c SUBROUTINE cost_forcing_gen
30 c ==================================================================
31 c
32 c o Generic routine for all forcing penalty terms (flux and bulk)
33 c
34 c ==================================================================
35 c SUBROUTINE cost_forcing_gen
36 c ==================================================================
37
38 implicit none
39
40 c == global variables ==
41
42 #include "EEPARAMS.h"
43 #include "SIZE.h"
44 #include "PARAMS.h"
45 #include "GRID.h"
46
47 #include "ecco_cost.h"
48 #include "ctrl.h"
49 #include "ctrl_dummy.h"
50 #include "optim.h"
51
52 c == routine arguments ==
53
54 integer myiter
55 _RL mytime
56 integer startrec
57 integer endrec
58 character*(MAX_LEN_FNAM) xx_gen_file
59 _RL xx_gen_dummy
60 _RL xx_gen_period
61 _RL wmean_gen
62 _RL wgen(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
63 _RL num_gen_anom(nsx,nsy)
64 _RL num_gen_mean(nsx,nsy)
65 _RL num_gen_smoo(nsx,nsy)
66 _RL objf_gen_anom(nsx,nsy)
67 _RL objf_gen_mean(nsx,nsy)
68 _RL objf_gen_smoo(nsx,nsy)
69 _RL xx_gen_remo_intercept
70 _RL xx_gen_remo_slope
71 _RS genmask(1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy)
72 integer mythid
73
74 c == local variables ==
75
76 integer bi,bj
77 integer i,j,kk
78 integer itlo,ithi
79 integer jtlo,jthi
80 integer jmin,jmax
81 integer imin,imax
82 integer nrec
83 integer irec
84 integer ilfld
85
86 _RL fctile
87 _RL fctilem
88 _RL fctilemm
89 _RL tmpx
90 _RL sumcos
91 _RL lengthscale
92
93 _RL xx_mean(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
94
95 logical doglobalread
96 logical ladinit
97
98 character*(80) fnamefld
99
100 character*(MAX_LEN_MBUF) msgbuf
101
102 c == external functions ==
103
104 integer ilnblnk
105 external ilnblnk
106
107 c == end of interface ==
108
109 jtlo = mybylo(mythid)
110 jthi = mybyhi(mythid)
111 itlo = mybxlo(mythid)
112 ithi = mybxhi(mythid)
113 jmin = 1
114 jmax = sny
115 imin = 1
116 imax = snx
117
118 lengthscale = 1. _d 0
119
120 c-- Read state record from global file.
121 doglobalread = .false.
122 ladinit = .false.
123
124 c Number of records to be used.
125 nrec = endrec-startrec+1
126
127 if (optimcycle .ge. 0) then
128 ilfld=ilnblnk( xx_gen_file )
129 write(fnamefld(1:80),'(2a,i10.10)')
130 & xx_gen_file(1:ilfld),'.',optimcycle
131 endif
132
133 c-- >>> Loop 1 to compute mean forcing:
134 do bj = jtlo,jthi
135 do bi = itlo,ithi
136 do j = jmin,jmax
137 do i = imin,imax
138 xx_mean(i,j,bi,bj) = 0. _d 0
139 enddo
140 enddo
141 num_gen_anom(bi,bj) = 0. _d 0
142 num_gen_mean(bi,bj) = 0. _d 0
143 num_gen_smoo(bi,bj) = 0. _d 0
144 objf_gen_anom(bi,bj) = 0. _d 0
145 objf_gen_mean(bi,bj) = 0. _d 0
146 objf_gen_smoo(bi,bj) = 0. _d 0
147 enddo
148 enddo
149
150 #ifndef ALLOW_SMOOTH_CORREL2D
151 do irec = 1,nrec
152
153 call active_read_xy(
154 & fnamefld, tmpfld2d, irec, doglobalread,
155 & ladinit, optimcycle, mythid, xx_gen_dummy )
156
157 c-- Loop over this thread tiles.
158 do bj = jtlo,jthi
159 do bi = itlo,ithi
160 do j = jmin,jmax
161 do i = imin,imax
162 xx_mean(i,j,bi,bj) = xx_mean(i,j,bi,bj)
163 & + tmpfld2d(i,j,bi,bj)
164 & - ( xx_gen_remo_intercept +
165 & xx_gen_remo_slope*(irec-1)*xx_gen_period )
166 enddo
167 enddo
168 enddo
169 enddo
170
171 enddo
172
173 if ( wmean_gen .NE. 0. ) then
174 do bj = jtlo,jthi
175 do bi = itlo,ithi
176 c-- Determine the weights to be used.
177 kk = 1
178 fctilem = 0. _d 0
179 do j = jmin,jmax
180 do i = imin,imax
181 xx_mean(i,j,bi,bj)
182 & = xx_mean(i,j,bi,bj)/float(nrec)
183 tmpx = xx_mean(i,j,bi,bj)/wmean_gen
184 if (genmask(i,j,kk,bi,bj) .ne. 0.) then
185 if ( ABS(R_low(i,j,bi,bj)) .LT. 100. )
186 & tmpx = tmpx*ABS(R_low(i,j,bi,bj))/100.
187 fctilem = fctilem + cosphi(i,j,bi,bj)*tmpx*tmpx
188 if ( cosphi(i,j,bi,bj) .ne. 0. )
189 & num_gen_mean(bi,bj) = num_gen_mean(bi,bj) + 1. _d 0
190 endif
191 enddo
192 enddo
193 objf_gen_mean(bi,bj) = objf_gen_mean(bi,bj) + fctilem
194 enddo
195 enddo
196 endif
197 #endif
198
199 c-- >>> Loop 2 over records.
200 do irec = 1,nrec
201
202 call active_read_xy(
203 & fnamefld, tmpfld2d, irec, doglobalread,
204 & ladinit, optimcycle, mythid, xx_gen_dummy )
205
206 c-- Loop over this thread tiles.
207 do bj = jtlo,jthi
208 do bi = itlo,ithi
209
210 c-- Determine the weights to be used.
211 kk = 1
212 fctile = 0. _d 0
213 do j = jmin,jmax
214 do i = imin,imax
215 if (genmask(i,j,kk,bi,bj) .ne. 0.) then
216 #ifndef ALLOW_SMOOTH_CORREL2D
217 tmpx = tmpfld2d(i,j,bi,bj)-xx_mean(i,j,bi,bj)
218 & - ( xx_gen_remo_intercept +
219 & xx_gen_remo_slope*(irec-1)*xx_gen_period )
220 if ( ABS(R_low(i,j,bi,bj)) .LT. 100. )
221 & tmpx = tmpx*ABS(R_low(i,j,bi,bj))/100.
222 fctile = fctile
223 & + wgen(i,j,bi,bj)*cosphi(i,j,bi,bj)
224 & *tmpx*tmpx
225 #else
226 tmpx = tmpfld2d(i,j,bi,bj)
227 fctile = fctile + tmpx*tmpx
228 #endif
229 if ( wgen(i,j,bi,bj)*cosphi(i,j,bi,bj) .ne. 0. )
230 & num_gen_anom(bi,bj) = num_gen_anom(bi,bj)
231 & + 1. _d 0
232 endif
233 enddo
234 enddo
235
236 objf_gen_anom(bi,bj) = objf_gen_anom(bi,bj) + fctile
237
238 enddo
239 enddo
240
241 c-- End of loop over records.
242 enddo
243
244 #ifndef ALLOW_SMOOTH_CORREL2D
245 #ifdef ALLOW_SMOOTH_BC_COST_CONTRIBUTION
246
247 c-- >>> Loop 2 over records.
248 do irec = 1,nrec
249
250 call active_read_xy(
251 & fnamefld, tmpfld2d, irec, doglobalread,
252 & ladinit, optimcycle, mythid, xx_gen_dummy )
253
254 _EXCH_XY_R8(tmpfld2d, mythid)
255
256 c-- Loop over this thread tiles.
257 do bj = jtlo,jthi
258 do bi = itlo,ithi
259
260 c-- Determine the weights to be used.
261 kk = 1
262 fctile = 0. _d 0
263 do j = jmin,jmax
264 do i = imin,imax
265 if (genmask(i,j,kk,bi,bj) .ne. 0.) then
266 tmpx =
267 & ( tmpfld2d(i+2,j,bi,bj)-tmpfld2d(i+1,j,bi,bj) )
268 & *maskW(i+1,j,kk,bi,bj)*maskW(i+2,j,kk,bi,bj)
269 & + ( tmpfld2d(i+1,j,bi,bj)-tmpfld2d(i,j,bi,bj) )
270 & *maskW(i+1,j,kk,bi,bj)
271 & + ( tmpfld2d(i,j+2,bi,bj)-tmpfld2d(i,j+1,bi,bj) )
272 & *maskS(i,j+1,kk,bi,bj)*maskS(i,j+2,kk,bi,bj)
273 & + ( tmpfld2d(i,j+1,bi,bj)-tmpfld2d(i,j,bi,bj) )
274 & *maskS(i,j+1,kk,bi,bj)
275 if ( ABS(R_low(i,j,bi,bj)) .LT. 100. )
276 & tmpx = tmpx*ABS(R_low(i,j,bi,bj))/100.
277 fctile = fctile
278 & + wgen(i,j,bi,bj)*cosphi(i,j,bi,bj)
279 * *0.0161*lengthscale/4.0
280 & *tmpx*tmpx
281 if ( wgen(i,j,bi,bj)*cosphi(i,j,bi,bj) .ne. 0. )
282 & num_gen_smoo(bi,bj) = num_gen_smoo(bi,bj)
283 & + 1. _d 0
284 endif
285 enddo
286 enddo
287
288 objf_gen_smoo(bi,bj) = objf_gen_smoo(bi,bj) + fctile
289
290 enddo
291 enddo
292
293 c-- End of loop over records.
294 enddo
295
296 #endif
297 #endif
298
299 return
300 end
301

  ViewVC Help
Powered by ViewVC 1.1.22