/[MITgcm]/manual/s_examples/global_oce_optim/global_oce_estimation.tex
ViewVC logotype

Contents of /manual/s_examples/global_oce_optim/global_oce_estimation.tex

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


Revision 1.14 - (show annotations) (download) (as text)
Fri Feb 29 22:55:13 2008 UTC (16 years, 2 months ago) by dfer
Branch: MAIN
Changes since 1.13: +2 -2 lines
File MIME type: application/x-tex
*** empty log message ***

1 % $Header: /u/gcmpack/manual/part3/case_studies/global_oce_estimation/global_oce_estimation.tex,v 1.13 2008/02/28 18:22:03 jmc Exp $
2 % $Name: $
3
4 \section[Global Ocean State Estimation Example]{Global Ocean State Estimation at $4^\circ$ Resolution}
5 \label{www:tutorials}
6 \label{sect:eg-global_state_estimate}
7 \begin{rawhtml}
8 <!-- CMIREDIR:eg-global_state_estimate: -->
9 \end{rawhtml}
10 \begin{center}
11 (in directory: {\it verification/tutorial\_global\_oce\_optim/})
12 \end{center}
13
14 \subsection{Overview}
15
16 This experiment illustrates the optimization capacity of the MITgcm: here,
17 a high level description.
18
19 In this tutorial, a very simple case is used to illustrate the optimization
20 capacity of the MITgcm. Using an ocean configuration with realistic geography
21 and bathymetry on a $4\times4^\circ$ spherical polar grid, we estimate a
22 time-independent surface heat flux adjustment $Q_\mathrm{netm}$ that attempts
23 to bring the model climatology into consistency with observations (Levitus
24 dataset, \cite{lev:94a}). The files for this experiment can be found in the
25 verification directory under tutorial\_global\_oce\_optim.
26
27 This adjustment $Q_\mathrm{netm}$ (a 2D field only function of longitude and
28 latitude) is the control variable of an optimization problem. It is inferred
29 by an iterative procedure using an `adjoint technique' and a least-squares
30 method (see, for example, \cite{stam-etal:02} and \cite{fer-eta:05}).
31
32 The ocean model is run forward in time and the quality of the solution is
33 determined by a cost function, $J_1$, a measure of the departure of the model
34 climatology from observations:
35 \begin{equation}\label{cost_temp}
36 J_1=\frac{1}{N}\sum_{i=1}^N \left[ \frac{\overline{T}_i-\overline{T}_i^{lev}}{\sigma_i^T}\right]^2
37 \end{equation}
38 where $\overline{T}_i$ and $\overline{T}_i^{lev}$ are, respectively, the model
39 and observed potential temperature at each
40 grid point $i$. The differences are weighted by an {\it a priori} uncertainty
41 $\sigma_i^T$ on observations (as provided by \cite{lev:94a}). The error
42 $\sigma_i^T$ is only a function of depth and varies from 0.5 at the surface to
43 0.05~K at the bottom of the ocean, mainly reflecting the decreasing
44 temperature variance with depth (Fig. \ref{Error}a). A value of $J_1$ of
45 order 1 means that the model is, on average, within observational
46 uncertainties.
47
48 The cost function also places constraints on the adjustment to insure it is
49 "reasonable", i.e. of order of the uncertainties on the observed surface heat
50 flux:
51 \begin{equation}
52 J_2 = \frac{1}{N} \sum_{i=1}^N \left[\frac{Q_\mathrm{netm}}{\sigma^Q_i} \right]^2
53 \end{equation}
54 where $\sigma^Q_i$ are the {\it a priori} errors on the observed heat flux as
55 estimated by Stammer et al. (2002) from 30\% of local root-mean-square
56 variability of the NCEP forcing field (Fig \ref{Error}b).
57
58 The total cost function is defined as $J=\lambda_1 J_1+ \lambda_2 J_2$ where
59 $\lambda_1$ and $\lambda_2$ are weights controlling the relative contribution
60 of the two components. The adjoint model then yields the sensitivities
61 $\partial J/\partial Q_\mathrm{netm}$ of $J$ relative to the 2D fields
62 $Q_\mathrm{netm}$. Using a line-searching algorithm (\cite{gil-lem:89}),
63 $Q_\mathrm{netm}$ is adjusted then in the sense to
64 reduce $J$ --- the procedure is repeated until convergence.
65
66 %The configuration is identical
67 %to the ``Global Ocean circulation'' tutorial where more details can be found.
68
69 Fig. \ref{Results} shows the results of such an optimization. The
70 model is started from rest and from January-mean temperature and salinity
71 initial conditions taken from the Levitus dataset. The experiment is run a year
72 and the averaged temperature over the whole run (i.e. annual mean) is used
73 in the cost function (\ref{cost_temp}) to evaluate the model. Only the
74 top 2 levels are used. The first guess $Q_\mathrm{netm}$ is chosen to be
75 zero. The weights $\lambda_1$ and $\lambda_2$ are set to 1 and 2, respectively.
76 The total cost function converges after 15 iterations, decreasing from 6.1 to
77 2.7 (the temperature contribution decreases from 6.1 to 1.8 while the heat
78 flux one increases from 0 to 0.42). The right panels of Fig. (\ref{Results})
79 illustrate the evolution of the temperature error at the surface from
80 iteration 0 to iteration 15. Unsurprisingly, the largest errors at iteration 0
81 (up to 6$^\circ$C, top left panels) are found in the Western boundary
82 currents. After optimization, the departure of the model temperature from
83 observations is reduced to 1$^\circ$C or less almost everywhere except in the
84 Pacific Equatorial Cold Tongue. Comparison of the initial temperature
85 error (top, right) and heat flux adjustment (bottom, left) shows that the
86 system basically increased the heat flux out of the ocean where temperatures
87 were too warm and vice-versa. Obviously, heat flux uncertainties are not the
88 sole responsible for temperature errors and the heat flux adjustment partly
89 compensates the poor representation of narrow currents (Western boundary
90 currents, Equatorial currents) at $4\times4^\circ$ resolution. This is
91 allowed by the large {\it a priori} error on the heat flux (Fig. \ref{Error}).
92 The Pacific Cold Tongue is a counter example: there, heat fluxes uncertainties
93 are fairly small (about 20~W.m$^2$), and a large temperature errors
94 remains after optimization.
95
96 In the following, section 2 describes in details the implementation of the
97 control variable $Q_\mathrm{netm}$, the cost function $J$ and the I/O required
98 for the communication between the model and the line-search. Instructions to
99 compile the MITgcm and its adjoint and the line-search algorithm are given in
100 section 3. The method used to run the experiment is described in section 4.
101
102 \begin{figure} [tpb]
103 \begin{center}
104 \includegraphics[width=\textwidth,height=.3\textheight]{part3/case_studies/global_oce_estimation/Error.eps}
105 \caption{{\it A priori} errors on potential temperature (left, in $^\circ$C) and
106 surface heat flux (right, in W~m$^{-2}$) used to compute the cost
107 terms $J_1$ and $J_2$, respectively.}
108 \label{Error}
109 \end{center}
110 \end{figure}
111
112 \begin{figure} [tpb]
113 \begin{center}
114 \includegraphics[width=\textwidth,height=.3\textheight]{part3/case_studies/global_oce_estimation/Tutorial_fig.eps}
115 \caption{Initial annual mean surface heat flux (top right in W.m$^{-2}$) and
116 adjustment obtained at iteration 15 (bottom right). Averaged difference
117 between model and observed potential temperatures at the surface (in $^\circ$C)
118 before optimization (iteration 0, top right) and after optimization
119 (iteration 15, bottom right). Contour intervals for heat flux and temperature
120 are 25~W.m$^{-2}$ and 1$^\circ$C, respectively. A positive flux is out of the
121 ocean.}
122 \label{Results}
123 \end{center}
124 \end{figure}
125
126 \subsection{Implementation of the control variable and the cost function}
127
128 One of the goal of this tutorial is to illustrate how to implement a new
129 control variable. Most of this is fairly generic and is done in the ctrl
130 and cost packages found in the pkg/ directory. The modifications can be
131 tracked by the CPP option ALLOW\_HFLUXM\_CONTROL or the comment
132 cHFLUXM\_CONTROL. The more specific modifications required for the experiment
133 are found in verification/tutorial\_global\_oce\_optim/code\_ad. Here follows
134 a brief description of the implementation.
135
136 \subsubsection{The control variable}
137
138 The adjustment $Q_\mathrm{netm}$ is activated by setting
139 ALLOW\_HFLUXM\_CONTROL to "define" in ECCO\_OPTIONS.h.
140
141 It is first implemented as a ``normal'' forcing variable. It is defined in
142 FFIELDS.h, initialized to zero in ini\_forcing.F, and then used in
143 external\_forcing\_surf.F. $Q_\mathrm{netm}$ is made a control variable in
144 the ctrl package by modifying the following subroutines:
145
146 \begin{itemize}
147 \item ctrl\_init.F where $Q_\mathrm{netm}$ is defined as the control variable
148 number 24,
149
150 \item ctrl\_pack.F which writes, at the end of each iteration, the sensitivity
151 of the cost function $\partial J/\partial Q_\mathrm{netm}$ in to a file to be
152 used by the line-search algorithm,
153
154 \item ctrl\_unpack.F which reads, at the start of each iteration, the updated
155 adjustment as provided by the line-search algorithm,
156
157 \item ctrl\_map\_forcing.F in which the updated adjustment is added to the
158 first guess $Q_\mathrm{netm}$.
159 \end{itemize}
160
161 Note also some minor changes in ctrl.h, ctrl\_readparams.F, and ctrl\_dummy.h
162 (xx\_hfluxm\_file, fname\_hfluxm, xx\_hfluxm\_dummy).
163
164 \subsubsection{Cost functions}
165
166 The cost functions are implemented using the {\it cost} package.
167
168 \begin{itemize}
169
170 \item The temperature cost function $J_1$ which measures the drift of the mean
171 model temperature from the Levitus climatology is implemented in cost\_temp.F.
172 It is activated by ALLOW\_COST\_TEMP in ECCO\_OPTIONS.h. It requires the mean
173 temperature of the model which is obtained by accumulating the temperature in
174 cost\_tile.F (called at each time step).
175 The value of the cost function is stored in {\it objf\_temp} and its weight
176 $\lambda_1$ in {\it mult\_temp}.
177
178 \item The heat flux cost function, penalizing the departure of the surface
179 heat flux from observations is implemented in cost\_hflux.F, and activated by
180 the key ALLOW\_COST\_HFLUXM in ECCO\_OPTIONS.h. The value of the cost
181 function is stored in {\it objf\_hfluxm} and its weight $\lambda_2$ in
182 {\it mult\_hfluxm}.
183
184 \item The subroutine cost\_final.F calls the cost\_functions subroutines
185 and make the (weighted) sum of the various contributions.
186
187 \item The various weights used in the cost functions are read in
188 cost\_weights.F. The weight of the cost functions are read in
189 cost\_readparams.F from the input file data.cost.
190
191 \end{itemize}
192
193
194 \subsection{Code Configuration}
195 \label{www:tutorials}
196 \label{SEC:eg_globest_code_config}
197
198 The model configuration for this experiment resides under the directory
199 {\it verification/tutorial\_global\_oce\_optim/}. The experiment files in
200 code\_ad/ and input\_ad/ contain the code customizations and parameter
201 settings. Most of them are identical to those used in the Global Ocean
202 ( experiment {\it tutorial\_global\_oce\_latlon}). Below, we describe some of
203 the customizations required for this experiment.
204
205 \subsubsection{Compilation-time customizations in {\it code\_ad/}}
206
207 In ECCO\_CPPOPTIONS.h:
208
209 \begin{itemize}
210 \item define ALLOW\_ECCO\_OPTIMIZATION
211
212 \item define ALLOW\_COST, ALLOW\_COST\_TEMP, and ALLOW\_COST\_HFLUXM
213
214 \item define ALLOW\_HFLUXM\_CONTROL
215 \end{itemize}
216
217 \subsubsection{Running-time customizations in {\it input\_ad/}}
218
219 \begin{itemize}
220
221 \item {\it data}: note the smaller {\it cg2dTargetResidual} than in the
222 forward-only experiment,
223
224 \item {\it data.optim} specifies the iteration number,
225
226 \item {\it data.ctrl} is used, in particular, to specify the
227 name of the sensitivity and adjustment files associated to a control
228 variable,
229
230 \item {\it data.cost}: parameters of the cost functions, in particular
231 {\it lastinterval} specifies the length of time-averaging for the model
232 temperature to be used in the cost function (\ref{cost_temp}),
233
234 \item {\it data.pkg}: note that the Gradient Check package is turned on by
235 default (useGrdchk=.TRUE.),
236
237 \item {\it Err\_hflux.bin} and {\it Err\_levitus\_15layer.bin} are the
238 files containing the heat flux and potential temperature uncertainties,
239 respectively.
240
241 \end{itemize}
242
243 \subsection{Compiling}
244
245 The optimization experiment requires two executables: 1) the
246 MITgcm and its adjoint ({\it mitgcmuv\_ad}) and 2) the line-search
247 algorithm ({\it optim.x}).
248
249 \subsubsection{Compilation of MITgcm and its adjoint: {\it mitcgmuv\_ad}}
250
251 Before compiling, first note that, in the directory code\_ad/, two files
252 must be updated:
253 \begin{itemize}
254 \item code\_ad\_diff.list which lists new subroutines to be compiled
255 by the TAF software (cost\_temp.F and cost\_hflux.F here),
256
257 \item the adjoint\_hfluxm files which provides a list of the control variables
258 and the name of cost function to the TAF software.
259
260 \end{itemize}
261
262 Then, in the directory build\_ad/, type:
263 \begin{verbatim}
264 % ../../../tools/genmake2 -mods=../code\_ad -adof=../code\_ad/adjoint\_hfluxm
265 % make depend
266 % make adall
267 \end{verbatim}
268 to generate the MITgcm executable {\it mitgcmuv\_ad}.
269
270 \subsubsection{Compilation of the line-search algorithm: {\it optim.x}}
271
272 This is done from the directories lsopt/ and optim/ (under MITgcm/). In lsopt/,
273 unzip the blash1 library adapted to your platform, and change the Makefile
274 accordingly. Compile with:
275 \begin{verbatim}
276 % make all
277 \end{verbatim}
278 (more details in lsopt\_doc.txt)
279
280 In optim/, the path of the directory where {\it mitgcm\_ad} was compiled
281 must be specified in the Makefile in the variable INCLUDEDIRS. The file name
282 of the control variable (xx\_hfluxm\_file here) must be added to the name list
283 read by optim\_num.F. Then use
284 \begin{verbatim}
285 % make depend
286 \end{verbatim}
287 and
288 \begin{verbatim}
289 % make
290 \end{verbatim}
291 to generate the line-search executable {\it optim.x}.
292
293 \subsection{Running the estimation}
294
295 Copy the {\it mitgcmuv\_ad} executable to input\_ad/ and {\it optim.x} to the
296 subdirectory input\_ad/OPTIM/. Move into input\_ad/. The first iteration is
297 somewhat particular and is best done "by hand" while the following iterations
298 can be run automatically (see below). Check that the iteration number is set
299 to 0 in data.optim and run the MITgcm:
300 \begin{verbatim}
301 % ./mitgcmuv_ad
302 \end{verbatim}
303
304 The output files adxx\_hfluxm.0000000000.* and xx\_hfluxm.0000000000.* contain
305 the sensitivity of the cost function to $Q_\mathrm{netm}$ and the adjustment
306 to $Q_\mathrm{netm}$ (zero at the first iteration), respectively. Two other
307 files called costhflux\_tut\_MITgcm.opt0000 and ctrlhflux\_tut\_MITgcm.opt0000
308 are also generated. They essentially contain the same information as the
309 adxx\_.hfluxm* and xx\_hfluxm* files, but in a compressed format. These two files
310 are the only ones involved in the communication between the adjoint model
311 {\it mitgcmuv\_ad} and the line-search algorithm {\it optim.x}. Only at the first
312 iteration, are they both generated by {\it mitgcmuv\_ad}. Subsenquently,
313 costhflux\_tut\_MITgcm.opt$n$ is an output of the adjoint model at
314 iteration $n$ and an input of the line-search. The latter returns an updated
315 adjustment in ctrlhflux\_tut\_MITgcm.opt$n+1$ to be used as an input of the
316 adjoint model at iteration n+1.
317
318 At the first iteration, move costhflux\_tut\_MITgcm.opt0000 and
319 ctrlhflux\_tut\_MITgcm.opt0000 to OPTIM/, move into this directory and link data.optim
320 and data.ctrl locally:
321 \begin{verbatim}
322 % cd OPTIM/
323 % ln -s ../data.optim .
324 % ln -s ../data.ctrl .
325 \end{verbatim}
326 The target cost function {\it fmin} needs to be specified too: as a rule of thumb,
327 it should be about 0.95-0.90 times the value of the cost function at
328 the first iteration. This value is only used at the first iteration and does
329 not need to be updated afterward. However, it implicitly specifies the
330 ``pace'' at which the cost function is going down (if you are lucky and it does
331 indeed diminish!). More in the ECCO section maybe ?
332
333 Once this is done, run the line-search algorithm:
334 \begin{verbatim}
335 % ./optim.x
336 \end{verbatim}
337 which computes the updated adjustment for iteration 1, ctrlhflux\_tut\_MITgcm.opt0001.
338
339 The following iterations can be executed automatically using the shell
340 script {\it cycsh} found in input\_ad/. This script will take care of changing
341 the iteration numbers in the data.optim, launch the adjoint model, clean and
342 store the outputs, move the costhflux* and ctrlhflux* files, and run the
343 line-search algorithm. Edit {\it cycsh} to specify the prefix of the
344 directories used to store the outputs and the maximum number of iteration.
345

  ViewVC Help
Powered by ViewVC 1.1.22