1 |
C $Header: /u/gcmpack/MITgcm/pkg/cost/cost_final.F,v 1.30 2012/08/10 22:57:20 gforget Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "COST_OPTIONS.h" |
5 |
|
6 |
subroutine cost_final( mythid ) |
7 |
|
8 |
c ================================================================== |
9 |
c SUBROUTINE cost_final |
10 |
c ================================================================== |
11 |
c |
12 |
c o Sum of all cost function contributions. |
13 |
c |
14 |
c ================================================================== |
15 |
c SUBROUTINE cost_final |
16 |
c ================================================================== |
17 |
|
18 |
implicit none |
19 |
|
20 |
c == global variables == |
21 |
|
22 |
#include "EEPARAMS.h" |
23 |
#include "SIZE.h" |
24 |
#include "PARAMS.h" |
25 |
|
26 |
#include "cost.h" |
27 |
#ifdef ALLOW_CTRL |
28 |
# include "ctrl.h" |
29 |
#endif |
30 |
#ifdef ALLOW_DIC |
31 |
# include "DIC_COST.h" |
32 |
#endif |
33 |
#ifdef ALLOW_COST_SHELFICE |
34 |
# include "SHELFICE_COST.h" |
35 |
#endif |
36 |
|
37 |
|
38 |
c == routine arguments == |
39 |
|
40 |
integer mythid |
41 |
|
42 |
#ifdef ALLOW_COST |
43 |
c == local variables == |
44 |
|
45 |
integer bi,bj |
46 |
integer itlo,ithi |
47 |
integer jtlo,jthi |
48 |
|
49 |
c == end of interface == |
50 |
|
51 |
jtlo = mybylo(mythid) |
52 |
jthi = mybyhi(mythid) |
53 |
itlo = mybxlo(mythid) |
54 |
ithi = mybxhi(mythid) |
55 |
|
56 |
#ifdef ALLOW_SEAICE |
57 |
if (useSEAICE) CALL SEAICE_COST_FINAL (myThid) |
58 |
#endif |
59 |
|
60 |
#ifdef ALLOW_SHELFICE |
61 |
CALL SHELFICE_COST_FINAL (myThid) |
62 |
#endif |
63 |
|
64 |
print *, 'ph-1 in thsice_cost_final' |
65 |
|
66 |
#ifdef ALLOW_THSICE |
67 |
if (useTHSICE) CALL THSICE_COST_FINAL (myThid) |
68 |
#endif |
69 |
|
70 |
print *, 'ph-3 in thsice_cost_final' |
71 |
|
72 |
#ifdef ALLOW_ECCO |
73 |
CALL ECCO_COST_FINAL (myThid) |
74 |
#endif |
75 |
|
76 |
#ifdef ALLOW_COST_STATE_FINAL |
77 |
CALL COST_STATE_FINAL (myThid) |
78 |
cgf : effectively using this in adjoint requires the |
79 |
c use of adjoint_state_final. That will activate the |
80 |
c objf_state_final vector in place of the fc scalar. |
81 |
c objf_state_final is therefore not added to fc. |
82 |
#endif |
83 |
|
84 |
#ifdef ALLOW_COST_VECTOR |
85 |
cgf : same idea as for ALLOW_COST_STATE_FINAL |
86 |
CALL COST_VECTOR (myThid) |
87 |
#endif |
88 |
|
89 |
# ifdef ALLOW_COST_TEST |
90 |
CALL COST_TEST (myThid) |
91 |
# endif |
92 |
|
93 |
# ifdef ALLOW_COST_ATLANTIC_HEAT |
94 |
CALL COST_ATLANTIC_HEAT (myThid) |
95 |
# endif |
96 |
|
97 |
#ifdef ALLOW_COST_HFLUXM |
98 |
cgf : to compile previous line user is expected to provide cost_hflux.F |
99 |
CALL COST_HFLUX (myThid) |
100 |
#endif |
101 |
|
102 |
#ifdef ALLOW_COST_TEMP |
103 |
CALL COST_TEMP (myThid) |
104 |
cgf : to compile previous line user is expected to provide cost_temp.F |
105 |
#endif |
106 |
|
107 |
c-- Sum up all contributions. |
108 |
do bj = jtlo,jthi |
109 |
do bi = itlo,ithi |
110 |
|
111 |
write(standardmessageunit,'(A,D22.15)') |
112 |
& ' --> objf_test(bi,bj) = ', objf_test(bi,bj) |
113 |
write(standardmessageunit,'(A,D22.15)') |
114 |
& ' --> objf_tracer(bi,bj) = ', objf_tracer(bi,bj) |
115 |
#if ( !defined (ALLOW_ECCO) || !defined (ALLOW_COST_ATLANTIC) ) |
116 |
write(standardmessageunit,'(A,D22.15)') |
117 |
& ' --> objf_atl(bi,bj) = ', objf_atl(bi,bj) |
118 |
#endif |
119 |
#ifdef ALLOW_COST_TEMP |
120 |
write(standardmessageunit,'(A,D22.15)') |
121 |
& ' --> objf_temp_tut(bi,bj) = ', objf_temp_tut(bi,bj) |
122 |
#endif |
123 |
#ifdef ALLOW_COST_HFLUXM |
124 |
write(standardmessageunit,'(A,D22.15)') |
125 |
& ' --> objf_hflux_tut(bi,bj) = ', objf_hflux_tut(bi,bj) |
126 |
#endif |
127 |
#ifdef ALLOW_COST_TRANSPORT |
128 |
write(standardmessageunit,'(A,D22.15)') |
129 |
& ' --> objf_transport(bi,bj) = ', objf_transport(bi,bj) |
130 |
#endif |
131 |
|
132 |
fc = fc |
133 |
& + mult_test * objf_test(bi,bj) |
134 |
& + mult_tracer * objf_tracer(bi,bj) |
135 |
#if ( !defined (ALLOW_ECCO) || !defined (ALLOW_COST_ATLANTIC) ) |
136 |
& + mult_atl * objf_atl(bi,bj) |
137 |
#endif |
138 |
#ifdef ALLOW_COST_TRANSPORT |
139 |
& + mult_transport * objf_transport(bi,bj) |
140 |
#endif |
141 |
#ifdef ALLOW_COST_TEMP |
142 |
& + mult_temp_tut * objf_temp_tut(bi,bj) |
143 |
#endif |
144 |
#ifdef ALLOW_COST_HFLUXM |
145 |
& + mult_hflux_tut * objf_hflux_tut(bi,bj) |
146 |
#endif |
147 |
enddo |
148 |
enddo |
149 |
|
150 |
write(standardmessageunit,'(A,D22.15)') ' local fc = ', fc |
151 |
|
152 |
c-- Do global summation. |
153 |
_GLOBAL_SUM_RL( fc , myThid ) |
154 |
|
155 |
c-- Add contributions from global mean constraints |
156 |
fc = fc +glofc |
157 |
|
158 |
#ifdef ALLOW_DIC_COST |
159 |
cph-- quickly for testing |
160 |
fc = totcost |
161 |
#endif |
162 |
|
163 |
write(standardmessageunit,'(A,D22.15)') ' global fc = ', fc |
164 |
|
165 |
c-- to avoid re-write of output in reverse checkpointing loops, |
166 |
c-- switch off output flag : |
167 |
CALL TURNOFF_MODEL_IO( 0, myThid ) |
168 |
|
169 |
#endif /* ALLOW_COST */ |
170 |
|
171 |
return |
172 |
end |