1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_tau_eddy.F,v 1.12 2012/08/10 19:45:27 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
|
6 |
|
7 |
subroutine cost_tau_eddy( |
8 |
I myiter, |
9 |
I mytime, |
10 |
I mythid |
11 |
& ) |
12 |
|
13 |
C o==========================================================o |
14 |
C | subroutine cost_tau_eddy | |
15 |
C | o eddy stress cost term | |
16 |
C | o now two options: | |
17 |
C | ECCO standard or as in Ferreira and Marshall. | |
18 |
C o==========================================================o |
19 |
|
20 |
implicit none |
21 |
|
22 |
c == global variables == |
23 |
|
24 |
#include "EEPARAMS.h" |
25 |
#include "SIZE.h" |
26 |
#include "GRID.h" |
27 |
#include "DYNVARS.h" |
28 |
|
29 |
#include "ecco_cost.h" |
30 |
#include "CTRL_SIZE.h" |
31 |
#include "ctrl.h" |
32 |
#include "ctrl_dummy.h" |
33 |
#include "optim.h" |
34 |
|
35 |
c == routine arguments == |
36 |
|
37 |
integer myiter |
38 |
_RL mytime |
39 |
integer mythid |
40 |
|
41 |
c == local variables == |
42 |
|
43 |
integer bi,bj |
44 |
integer i,j,k |
45 |
integer itlo,ithi |
46 |
integer jtlo,jthi |
47 |
integer jmin,jmax |
48 |
integer imin,imax |
49 |
integer nrec |
50 |
integer irec |
51 |
integer ilfld |
52 |
|
53 |
_RL locfc |
54 |
_RL tau2_max, tau2_temp |
55 |
|
56 |
_RL fctile |
57 |
_RL fcthread |
58 |
_RL tmpx |
59 |
|
60 |
logical doglobalread |
61 |
logical ladinit |
62 |
|
63 |
character*(80) fnamefld |
64 |
|
65 |
character*(MAX_LEN_MBUF) msgbuf |
66 |
|
67 |
c == external functions == |
68 |
|
69 |
integer ilnblnk |
70 |
external ilnblnk |
71 |
|
72 |
c == end of interface == |
73 |
|
74 |
|
75 |
#ifdef ALLOW_EDDYPSI_COST_CONTRIBUTION |
76 |
C------------------------------------------------------ |
77 |
C Cost function consistent with ECCO standards |
78 |
C------------------------------------------------------ |
79 |
|
80 |
jtlo = mybylo(mythid) |
81 |
jthi = mybyhi(mythid) |
82 |
itlo = mybxlo(mythid) |
83 |
ithi = mybxhi(mythid) |
84 |
jmin = 1 |
85 |
jmax = sny |
86 |
imin = 1 |
87 |
imax = snx |
88 |
|
89 |
c-- Read state record from global file. |
90 |
doglobalread = .false. |
91 |
ladinit = .false. |
92 |
|
93 |
irec = 1 |
94 |
|
95 |
fcthread = 0. _d 0 |
96 |
|
97 |
if (optimcycle .ge. 0) then |
98 |
ilfld = ilnblnk( xx_edtaux_file ) |
99 |
write(fnamefld(1:80),'(2a,i10.10)') |
100 |
& xx_edtaux_file(1:ilfld),'.',optimcycle |
101 |
endif |
102 |
call active_read_xyz( fnamefld, tmpfld3d, irec, doglobalread, |
103 |
& ladinit, optimcycle, mythid |
104 |
& , xx_edtaux_dummy ) |
105 |
c-- Loop over this thread tiles. |
106 |
do bj = jtlo,jthi |
107 |
do bi = itlo,ithi |
108 |
c-- Determine the weights to be used. |
109 |
fctile = 0. _d 0 |
110 |
do k = 1,nr |
111 |
do j = jmin,jmax |
112 |
do i = imin,imax |
113 |
if (_hFacC(i,j,k,bi,bj) .ne. 0.) then |
114 |
tmpx = tmpfld3d(i,j,k,bi,bj) |
115 |
IF ( .NOT.ctrlSmoothCorrel3D ) THEN |
116 |
fctile = fctile |
117 |
& + wedtauxFld(i,j,k,bi,bj)*cosphi(i,j,bi,bj) |
118 |
& *tmpx*tmpx |
119 |
ELSE !IF ( .NOT.ctrlSmoothCorrel3D ) THEN |
120 |
fctile = fctile + tmpx*tmpx |
121 |
ENDIF !IF ( .NOT.ctrlSmoothCorrel3D ) THEN |
122 |
endif |
123 |
enddo |
124 |
enddo |
125 |
enddo |
126 |
|
127 |
objf_eddytau(bi,bj) = objf_eddytau(bi,bj) + fctile |
128 |
fcthread = fcthread + fctile |
129 |
enddo |
130 |
enddo |
131 |
|
132 |
if (optimcycle .ge. 0) then |
133 |
ilfld = ilnblnk( xx_edtauy_file ) |
134 |
write(fnamefld(1:80),'(2a,i10.10)') |
135 |
& xx_edtauy_file(1:ilfld),'.',optimcycle |
136 |
endif |
137 |
call active_read_xyz( fnamefld, tmpfld3d, irec, doglobalread, |
138 |
& ladinit, optimcycle, mythid |
139 |
& , xx_edtauy_dummy ) |
140 |
c-- Loop over this thread tiles. |
141 |
do bj = jtlo,jthi |
142 |
do bi = itlo,ithi |
143 |
c-- Determine the weights to be used. |
144 |
fctile = 0. _d 0 |
145 |
do k = 1,nr |
146 |
do j = jmin,jmax |
147 |
do i = imin,imax |
148 |
if (_hFacC(i,j,k,bi,bj) .ne. 0.) then |
149 |
tmpx = tmpfld3d(i,j,k,bi,bj) |
150 |
IF ( .NOT.ctrlSmoothCorrel3D ) THEN |
151 |
fctile = fctile |
152 |
& + wedtauyFld(i,j,k,bi,bj)*cosphi(i,j,bi,bj) |
153 |
& *tmpx*tmpx |
154 |
ELSE !IF ( .NOT.ctrlSmoothCorrel3D ) THEN |
155 |
fctile = fctile + tmpx*tmpx |
156 |
ENDIF !IF ( .NOT.ctrlSmoothCorrel3D ) THEN |
157 |
endif |
158 |
enddo |
159 |
enddo |
160 |
enddo |
161 |
|
162 |
objf_eddytau(bi,bj) = objf_eddytau(bi,bj) + fctile |
163 |
fcthread = fcthread + fctile |
164 |
|
165 |
#ifdef ECCO_VERBOSE |
166 |
c-- Print cost function for each tile in each thread. |
167 |
write(msgbuf,'(a)') ' ' |
168 |
call print_message( msgbuf, standardmessageunit, |
169 |
& SQUEEZE_RIGHT , mythid) |
170 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
171 |
& ' cost_tau_eddy: irec,bi,bj = ',irec,bi,bj |
172 |
call print_message( msgbuf, standardmessageunit, |
173 |
& SQUEEZE_RIGHT , mythid) |
174 |
write(msgbuf,'(a,d22.15)') |
175 |
& ' cost function (dT(0)) = ', |
176 |
& fctile |
177 |
call print_message( msgbuf, standardmessageunit, |
178 |
& SQUEEZE_RIGHT , mythid) |
179 |
#endif |
180 |
enddo |
181 |
enddo |
182 |
|
183 |
#ifdef ECCO_VERBOSE |
184 |
c-- Print cost function for all tiles. |
185 |
_GLOBAL_SUM_RL( fcthread , myThid ) |
186 |
write(msgbuf,'(a)') ' ' |
187 |
call print_message( msgbuf, standardmessageunit, |
188 |
& SQUEEZE_RIGHT , mythid) |
189 |
write(msgbuf,'(a,i8.8)') |
190 |
& ' cost_: irec = ',irec |
191 |
call print_message( msgbuf, standardmessageunit, |
192 |
& SQUEEZE_RIGHT , mythid) |
193 |
write(msgbuf,'(a,d22.15)') |
194 |
& ' global cost function value = ', |
195 |
& fcthread |
196 |
call print_message( msgbuf, standardmessageunit, |
197 |
& SQUEEZE_RIGHT , mythid) |
198 |
write(msgbuf,'(a)') ' ' |
199 |
call print_message( msgbuf, standardmessageunit, |
200 |
& SQUEEZE_RIGHT , mythid) |
201 |
#endif |
202 |
|
203 |
|
204 |
|
205 |
|
206 |
#elif (defined (ALLOW_COST_TAU_EDDY)) |
207 |
C------------------------------------------------------ |
208 |
C Cost function as a distance to max. value |
209 |
C------------------------------------------------------ |
210 |
C |
211 |
C maximum autorized value of the Eddy stress (squared) |
212 |
C from D. Ferreira |
213 |
C values beyond will be penalized; |
214 |
C values below are not penalized |
215 |
tau2_max = 0.4**2 |
216 |
locfc = 0.0 |
217 |
c |
218 |
DO bj=myByLo(myThid),myByHi(myThid) |
219 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
220 |
c |
221 |
#ifdef ALLOW_AUTODIFF_TAMC |
222 |
act1 = bi - myBxLo(myThid) |
223 |
max1 = myBxHi(myThid) - myBxLo(myThid) + 1 |
224 |
act2 = bj - myByLo(myThid) |
225 |
max2 = myByHi(myThid) - myByLo(myThid) + 1 |
226 |
act3 = myThid - 1 |
227 |
ikey = (act1 + 1) + act2*max1 |
228 |
& + act3*max1*max2 |
229 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
230 |
c |
231 |
do j=1,sNy |
232 |
do i=1,sNx |
233 |
do k=2,Nr |
234 |
tau2_temp = ( rhonil*eddyPsiX(i,j,k,bi,bj) |
235 |
& *0.5*(_fCori(i,j,bi,bj)+_fCori(i-1,j,bi,bj)) )**2 |
236 |
if ( tau2_temp .gt. tau2_max) then |
237 |
locfc = locfc + maskW(i,j,k,bi,bj)* |
238 |
& ( tau2_temp - tau2_max ) |
239 |
endif |
240 |
tau2_temp = ( rhonil*eddyPsiY(i,j,k,bi,bj) |
241 |
& *0.5*(_fCori(i,j,bi,bj)+_fCori(i,j-1,bi,bj)) )**2 |
242 |
if ( tau2_temp .gt. tau2_max) then |
243 |
locfc = locfc + maskS(i,j,k,bi,bj)* |
244 |
& ( tau2_temp - tau2_max ) |
245 |
endif |
246 |
enddo |
247 |
enddo |
248 |
enddo |
249 |
c |
250 |
objf_eddytau(bi,bj) = locfc |
251 |
print*,'objf_eddytau =',locfc |
252 |
c |
253 |
ENDDO |
254 |
ENDDO |
255 |
|
256 |
|
257 |
#else |
258 |
|
259 |
fctile = 0. _d 0 |
260 |
fcthread = 0. _d 0 |
261 |
|
262 |
#ifdef ECCO_VERBOSE |
263 |
_BEGIN_MASTER( mythid ) |
264 |
write(msgbuf,'(a)') ' ' |
265 |
call print_message( msgbuf, standardmessageunit, |
266 |
& SQUEEZE_RIGHT , mythid) |
267 |
write(msgbuf,'(a)') |
268 |
& ' cost_tau_eddy : no contribution to cost function' |
269 |
call print_message( msgbuf, standardmessageunit, |
270 |
& SQUEEZE_RIGHT , mythid) |
271 |
write(msgbuf,'(a)') ' ' |
272 |
call print_message( msgbuf, standardmessageunit, |
273 |
& SQUEEZE_RIGHT , mythid) |
274 |
_END_MASTER( mythid ) |
275 |
#endif |
276 |
|
277 |
#endif |
278 |
|
279 |
|
280 |
|
281 |
return |
282 |
end |
283 |
|
284 |
|