1 |
gforget |
1.35 |
C $Header: /u/gcmpack/MITgcm/pkg/cost/cost_final.F,v 1.34 2014/10/01 12:55:58 gforget Exp $ |
2 |
jmc |
1.16 |
C $Name: $ |
3 |
heimbach |
1.1 |
|
4 |
jmc |
1.29 |
#include "COST_OPTIONS.h" |
5 |
jmc |
1.33 |
#ifdef ALLOW_CTRL |
6 |
|
|
# include "CTRL_OPTIONS.h" |
7 |
|
|
#endif |
8 |
heimbach |
1.1 |
|
9 |
jmc |
1.32 |
SUBROUTINE COST_FINAL( myThid ) |
10 |
heimbach |
1.1 |
|
11 |
|
|
c ================================================================== |
12 |
heimbach |
1.3 |
c SUBROUTINE cost_final |
13 |
heimbach |
1.1 |
c ================================================================== |
14 |
|
|
c |
15 |
|
|
c o Sum of all cost function contributions. |
16 |
|
|
c |
17 |
|
|
c ================================================================== |
18 |
heimbach |
1.3 |
c SUBROUTINE cost_final |
19 |
heimbach |
1.1 |
c ================================================================== |
20 |
|
|
|
21 |
jmc |
1.32 |
IMPLICIT NONE |
22 |
heimbach |
1.1 |
|
23 |
|
|
c == global variables == |
24 |
|
|
#include "EEPARAMS.h" |
25 |
|
|
#include "SIZE.h" |
26 |
heimbach |
1.5 |
#include "PARAMS.h" |
27 |
heimbach |
1.1 |
|
28 |
|
|
#include "cost.h" |
29 |
heimbach |
1.14 |
#ifdef ALLOW_CTRL |
30 |
|
|
# include "ctrl.h" |
31 |
|
|
#endif |
32 |
heimbach |
1.20 |
#ifdef ALLOW_DIC |
33 |
|
|
# include "DIC_COST.h" |
34 |
|
|
#endif |
35 |
heimbach |
1.23 |
#ifdef ALLOW_COST_SHELFICE |
36 |
|
|
# include "SHELFICE_COST.h" |
37 |
|
|
#endif |
38 |
|
|
|
39 |
gforget |
1.35 |
#ifdef ALLOW_PROFILES |
40 |
|
|
# include "PROFILES_SIZE.h" |
41 |
|
|
# include "profiles.h" |
42 |
|
|
#endif |
43 |
|
|
|
44 |
heimbach |
1.1 |
c == routine arguments == |
45 |
jmc |
1.32 |
INTEGER myThid |
46 |
heimbach |
1.1 |
|
47 |
heimbach |
1.2 |
#ifdef ALLOW_COST |
48 |
heimbach |
1.1 |
c == local variables == |
49 |
jmc |
1.32 |
INTEGER bi,bj |
50 |
|
|
_RL glob_fc, loc_fc |
51 |
gforget |
1.35 |
#ifdef ALLOW_PROFILES |
52 |
|
|
integer num_file,num_var |
53 |
|
|
#endif |
54 |
heimbach |
1.1 |
|
55 |
|
|
c == end of interface == |
56 |
|
|
|
57 |
heimbach |
1.13 |
#ifdef ALLOW_SEAICE |
58 |
heimbach |
1.31 |
if (useSEAICE) CALL SEAICE_COST_FINAL (myThid) |
59 |
heimbach |
1.13 |
#endif |
60 |
|
|
|
61 |
mlosch |
1.25 |
#ifdef ALLOW_SHELFICE |
62 |
|
|
CALL SHELFICE_COST_FINAL (myThid) |
63 |
|
|
#endif |
64 |
|
|
|
65 |
jmc |
1.32 |
c print *, 'ph-1 in thsice_cost_final' |
66 |
heimbach |
1.31 |
#ifdef ALLOW_THSICE |
67 |
jmc |
1.33 |
IF (useThSIce) CALL THSICE_COST_FINAL (myThid) |
68 |
heimbach |
1.31 |
#endif |
69 |
jmc |
1.32 |
c print *, 'ph-3 in thsice_cost_final' |
70 |
heimbach |
1.31 |
|
71 |
gforget |
1.28 |
#ifdef ALLOW_ECCO |
72 |
gforget |
1.35 |
IF (useECCO) CALL ECCO_COST_FINAL (myThid) |
73 |
gforget |
1.28 |
#endif |
74 |
heimbach |
1.3 |
|
75 |
gforget |
1.28 |
#ifdef ALLOW_COST_STATE_FINAL |
76 |
heimbach |
1.6 |
CALL COST_STATE_FINAL (myThid) |
77 |
jmc |
1.29 |
cgf : effectively using this in adjoint requires the |
78 |
gforget |
1.28 |
c use of adjoint_state_final. That will activate the |
79 |
|
|
c objf_state_final vector in place of the fc scalar. |
80 |
|
|
c objf_state_final is therefore not added to fc. |
81 |
|
|
#endif |
82 |
heimbach |
1.3 |
|
83 |
gforget |
1.28 |
#ifdef ALLOW_COST_VECTOR |
84 |
|
|
cgf : same idea as for ALLOW_COST_STATE_FINAL |
85 |
|
|
CALL COST_VECTOR (myThid) |
86 |
|
|
#endif |
87 |
heimbach |
1.3 |
|
88 |
heimbach |
1.7 |
# ifdef ALLOW_COST_TEST |
89 |
heimbach |
1.2 |
CALL COST_TEST (myThid) |
90 |
heimbach |
1.7 |
# endif |
91 |
gforget |
1.28 |
|
92 |
heimbach |
1.7 |
# ifdef ALLOW_COST_ATLANTIC_HEAT |
93 |
heimbach |
1.3 |
CALL COST_ATLANTIC_HEAT (myThid) |
94 |
heimbach |
1.7 |
# endif |
95 |
gforget |
1.28 |
|
96 |
dfer |
1.17 |
#ifdef ALLOW_COST_HFLUXM |
97 |
gforget |
1.28 |
cgf : to compile previous line user is expected to provide cost_hflux.F |
98 |
dfer |
1.17 |
CALL COST_HFLUX (myThid) |
99 |
|
|
#endif |
100 |
gforget |
1.28 |
|
101 |
dfer |
1.17 |
#ifdef ALLOW_COST_TEMP |
102 |
|
|
CALL COST_TEMP (myThid) |
103 |
gforget |
1.28 |
cgf : to compile previous line user is expected to provide cost_temp.F |
104 |
dfer |
1.17 |
#endif |
105 |
heimbach |
1.3 |
|
106 |
jmc |
1.32 |
write(standardmessageunit,'(A,D22.15)') ' early fc = ', fc |
107 |
|
|
|
108 |
heimbach |
1.1 |
c-- Sum up all contributions. |
109 |
jmc |
1.32 |
loc_fc = 0. |
110 |
|
|
DO bj = myByLo(myThid), myByHi(myThid) |
111 |
|
|
DO bi = myBxLo(myThid), myBxHi(myThid) |
112 |
heimbach |
1.1 |
|
113 |
gforget |
1.34 |
#ifdef ALLOW_COST_TEST |
114 |
jmc |
1.16 |
write(standardmessageunit,'(A,D22.15)') |
115 |
heimbach |
1.11 |
& ' --> objf_test(bi,bj) = ', objf_test(bi,bj) |
116 |
gforget |
1.34 |
#endif |
117 |
|
|
#ifdef ALLOW_COST_TRACER |
118 |
jmc |
1.16 |
write(standardmessageunit,'(A,D22.15)') |
119 |
heimbach |
1.11 |
& ' --> objf_tracer(bi,bj) = ', objf_tracer(bi,bj) |
120 |
gforget |
1.34 |
#endif |
121 |
gforget |
1.28 |
#if ( !defined (ALLOW_ECCO) || !defined (ALLOW_COST_ATLANTIC) ) |
122 |
gforget |
1.34 |
# ifdef ALLOW_COST_ATLANTIC_HEAT |
123 |
jmc |
1.16 |
write(standardmessageunit,'(A,D22.15)') |
124 |
heimbach |
1.11 |
& ' --> objf_atl(bi,bj) = ', objf_atl(bi,bj) |
125 |
gforget |
1.34 |
# endif |
126 |
gforget |
1.28 |
#endif |
127 |
dfer |
1.17 |
#ifdef ALLOW_COST_TEMP |
128 |
|
|
write(standardmessageunit,'(A,D22.15)') |
129 |
dfer |
1.18 |
& ' --> objf_temp_tut(bi,bj) = ', objf_temp_tut(bi,bj) |
130 |
dfer |
1.17 |
#endif |
131 |
|
|
#ifdef ALLOW_COST_HFLUXM |
132 |
|
|
write(standardmessageunit,'(A,D22.15)') |
133 |
dfer |
1.18 |
& ' --> objf_hflux_tut(bi,bj) = ', objf_hflux_tut(bi,bj) |
134 |
dfer |
1.17 |
#endif |
135 |
heimbach |
1.15 |
#ifdef ALLOW_COST_TRANSPORT |
136 |
jmc |
1.16 |
write(standardmessageunit,'(A,D22.15)') |
137 |
heimbach |
1.15 |
& ' --> objf_transport(bi,bj) = ', objf_transport(bi,bj) |
138 |
|
|
#endif |
139 |
heimbach |
1.1 |
|
140 |
jmc |
1.32 |
tile_fc(bi,bj) = tile_fc(bi,bj) |
141 |
gforget |
1.34 |
#ifdef ALLOW_COST_TEST |
142 |
heimbach |
1.2 |
& + mult_test * objf_test(bi,bj) |
143 |
gforget |
1.34 |
#endif |
144 |
|
|
#ifdef ALLOW_COST_TRACER |
145 |
heimbach |
1.2 |
& + mult_tracer * objf_tracer(bi,bj) |
146 |
gforget |
1.34 |
#endif |
147 |
gforget |
1.28 |
#if ( !defined (ALLOW_ECCO) || !defined (ALLOW_COST_ATLANTIC) ) |
148 |
gforget |
1.34 |
# ifdef ALLOW_COST_ATLANTIC_HEAT |
149 |
heimbach |
1.3 |
& + mult_atl * objf_atl(bi,bj) |
150 |
gforget |
1.34 |
# endif |
151 |
gforget |
1.28 |
#endif |
152 |
heimbach |
1.15 |
#ifdef ALLOW_COST_TRANSPORT |
153 |
|
|
& + mult_transport * objf_transport(bi,bj) |
154 |
|
|
#endif |
155 |
dfer |
1.17 |
#ifdef ALLOW_COST_TEMP |
156 |
dfer |
1.18 |
& + mult_temp_tut * objf_temp_tut(bi,bj) |
157 |
dfer |
1.17 |
#endif |
158 |
|
|
#ifdef ALLOW_COST_HFLUXM |
159 |
dfer |
1.18 |
& + mult_hflux_tut * objf_hflux_tut(bi,bj) |
160 |
dfer |
1.17 |
#endif |
161 |
gforget |
1.35 |
|
162 |
|
|
#ifdef ALLOW_PROFILES |
163 |
|
|
do num_file=1,NFILESPROFMAX |
164 |
|
|
do num_var=1,NVARMAX |
165 |
|
|
tile_fc(bi,bj) = tile_fc(bi,bj) |
166 |
|
|
& + mult_profiles(num_file,num_var) |
167 |
|
|
& *objf_profiles(num_file,num_var,bi,bj) |
168 |
|
|
enddo |
169 |
|
|
enddo |
170 |
|
|
#endif |
171 |
|
|
|
172 |
jmc |
1.32 |
loc_fc = loc_fc + tile_fc(bi,bj) |
173 |
gforget |
1.35 |
|
174 |
jmc |
1.32 |
ENDDO |
175 |
|
|
ENDDO |
176 |
heimbach |
1.1 |
|
177 |
jmc |
1.32 |
write(standardmessageunit,'(A,D22.15)') ' local fc = ', loc_fc |
178 |
heimbach |
1.1 |
|
179 |
|
|
c-- Do global summation. |
180 |
jmc |
1.32 |
CALL GLOBAL_SUM_TILE_RL( tile_fc, glob_fc, myThid ) |
181 |
|
|
_BEGIN_MASTER( myThid ) |
182 |
|
|
fc = fc + glob_fc |
183 |
|
|
_END_MASTER( myThid ) |
184 |
heimbach |
1.3 |
|
185 |
gforget |
1.30 |
c-- Add contributions from global mean constraints |
186 |
jmc |
1.32 |
_BEGIN_MASTER( myThid ) |
187 |
|
|
fc = fc + glofc |
188 |
|
|
_END_MASTER( myThid ) |
189 |
gforget |
1.30 |
|
190 |
heimbach |
1.27 |
#ifdef ALLOW_DIC_COST |
191 |
heimbach |
1.20 |
cph-- quickly for testing |
192 |
|
|
fc = totcost |
193 |
|
|
#endif |
194 |
|
|
|
195 |
heimbach |
1.12 |
write(standardmessageunit,'(A,D22.15)') ' global fc = ', fc |
196 |
heimbach |
1.6 |
|
197 |
jmc |
1.22 |
c-- to avoid re-write of output in reverse checkpointing loops, |
198 |
|
|
c-- switch off output flag : |
199 |
|
|
CALL TURNOFF_MODEL_IO( 0, myThid ) |
200 |
heimbach |
1.1 |
|
201 |
heimbach |
1.2 |
#endif /* ALLOW_COST */ |
202 |
heimbach |
1.1 |
|
203 |
|
|
return |
204 |
|
|
end |