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

Annotation 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.13 - (hide annotations) (download) (as text)
Thu Feb 28 18:22:03 2008 UTC (17 years, 4 months ago) by jmc
Branch: MAIN
Changes since 1.12: +2 -2 lines
File MIME type: application/x-tex
fix previous check-in. Allows at least to build the pdf ;
will see if it's enought to get the web to build again (not since Feb 11)

1 jmc 1.13 % $Header: /u/gcmpack/manual/part3/case_studies/global_oce_estimation/global_oce_estimation.tex,v 1.12 2008/02/11 21:39:06 dfer Exp $
2 dfer 1.1 % $Name: $
3    
4 dfer 1.5 \section[Global Ocean State Estimation Example]{Global Ocean State Estimation at $4^\circ$ Resolution}
5 dfer 1.1 \label{www:tutorials}
6     \label{sect:eg-global_state_estimate}
7     \begin{rawhtml}
8     <!-- CMIREDIR:eg-global_state_estimate: -->
9     \end{rawhtml}
10 jmc 1.9 \begin{center}
11     (in directory: {\it verification/tutorial\_global\_oce\_optim/})
12     \end{center}
13 dfer 1.1
14 dfer 1.3 \subsection{Overview}
15    
16 dfer 1.12 This experiment illustrates the optimization capacity of the MITgcm: here,
17     a high level description.
18 dfer 1.1
19 dfer 1.12 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 dfer 1.1
27 dfer 1.10 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 dfer 1.12 method (see, for example, \cite{stam-etal:02} and \cite{fer-eta:05}).
31 dfer 1.1
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 dfer 1.12 \begin{equation}\label{cost_temp}
36 dfer 1.1 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 dfer 1.12 where $\overline{T}_i$ and $\overline{T}_i^{lev}$ are, respectively, the model
39     and observed potential temperature at each
40 dfer 1.10 grid point $i$. The differences are weighted by an {\it a priori} uncertainty
41 dfer 1.12 $\sigma_i^T$ on observations (as provided by \cite{lev:94a}). The error
42 dfer 1.10 $\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 dfer 1.1
48 dfer 1.10 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 dfer 1.1 flux:
51     \begin{equation}
52 dfer 1.10 J_2 = \frac{1}{N} \sum_{i=1}^N \left[\frac{Q_\mathrm{netm}}{\sigma^Q_i} \right]^2
53 dfer 1.1 \end{equation}
54 dfer 1.10 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 dfer 1.12 variability of the NCEP forcing field (Fig \ref{Error}b).
57 dfer 1.1
58 dfer 1.10 The total cost function is defined as $J=\lambda_1 J_1+ \lambda_2 J_2$ where
59 dfer 1.1 $\lambda_1$ and $\lambda_2$ are weights controlling the relative contribution
60 dfer 1.10 of the two components. The adjoint model then yields the sensitivities
61 dfer 1.1 $\partial J/\partial Q_\mathrm{netm}$ of $J$ relative to the 2D fields
62 dfer 1.12 $Q_\mathrm{netm}$. Using a line-searching algorithm (\cite{gil-lem:89}),
63     $Q_\mathrm{netm}$ is adjusted then in the sense to
64 dfer 1.10 reduce $J$ --- the procedure is repeated until convergence.
65    
66 dfer 1.12 %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 dfer 1.10
102     \begin{figure} [tpb]
103     \begin{center}
104     \includegraphics[width=\textwidth,height=.3\textheight]{part3/case_studies/global_oce_estimation/Error.eps}
105 dfer 1.12 \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 dfer 1.10 \label{Error}
109     \end{center}
110     \end{figure}
111 dfer 1.1
112 dfer 1.12 \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 dfer 1.1
126 dfer 1.10 \subsection{Implementation of the control variable and the cost function}
127 dfer 1.1
128 dfer 1.12 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 dfer 1.1
136 dfer 1.3 \subsubsection{The control variable}
137    
138 dfer 1.10 The adjustment $Q_\mathrm{netm}$ is activated by setting
139     ALLOW\_HFLUXM\_CONTROL to "define" in ECCO\_OPTIONS.h.
140 dfer 1.1
141 dfer 1.10 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 dfer 1.1
146 dfer 1.3 \begin{itemize}
147 dfer 1.10 \item ctrl\_init.F where $Q_\mathrm{netm}$ is defined as the control variable
148     number 24,
149 dfer 1.1
150 dfer 1.10 \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 dfer 1.1
154 dfer 1.10 \item ctrl\_unpack.F which reads, at the start of each iteration, the updated
155 dfer 1.12 adjustment as provided by the line-search algorithm,
156 dfer 1.1
157 dfer 1.12 \item ctrl\_map\_forcing.F in which the updated adjustment is added to the
158 dfer 1.10 first guess $Q_\mathrm{netm}$.
159 dfer 1.3 \end{itemize}
160 dfer 1.1
161 dfer 1.10 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 dfer 1.1
164 dfer 1.3 \subsubsection{Cost functions}
165    
166 dfer 1.10 The cost functions are implemented using the {\it cost} package.
167 dfer 1.1
168 dfer 1.3 \begin{itemize}
169 dfer 1.1
170 dfer 1.10 \item The temperature cost function $J_1$ which measures the drift of the mean
171 dfer 1.12 model temperature from the Levitus climatology is implemented in cost\_temp.F.
172 dfer 1.10 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 dfer 1.12 the key ALLOW\_COST\_HFLUXM in ECCO\_OPTIONS.h. The value of the cost
181 dfer 1.10 function is stored in {\it objf\_hfluxm} and its weight $\lambda_2$ in
182     {\it mult\_hfluxm}.
183 dfer 1.1
184 dfer 1.3 \item The subroutine cost\_final.F calls the cost\_functions subroutines
185 dfer 1.10 and make the (weighted) sum of the various contributions.
186 dfer 1.1
187 dfer 1.10 \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 dfer 1.1
191 dfer 1.3 \end{itemize}
192    
193 dfer 1.5
194     \subsection{Code Configuration}
195     \label{www:tutorials}
196     \label{SEC:eg_fourl_code_config}
197    
198 dfer 1.10 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 jmc 1.13 ( experiment {\it tutorial\_global\_oce\_latlon}). Below, we describe some of
203 dfer 1.12 the customizations required for this experiment.
204 dfer 1.10
205     \subsubsection{Compilation-time customizations in {\it code\_ad/}}
206    
207 dfer 1.12 In ECCO\_CPPOPTIONS.h:
208 dfer 1.10
209     \begin{itemize}
210 dfer 1.12 \item define ALLOW\_ECCO\_OPTIMIZATION
211 dfer 1.10
212 dfer 1.12 \item define ALLOW\_COST, ALLOW\_COST\_TEMP, and ALLOW\_COST\_HFLUXM
213 dfer 1.10
214 dfer 1.12 \item define ALLOW\_HFLUXM\_CONTROL
215 dfer 1.10 \end{itemize}
216    
217     \subsubsection{Running-time customizations in {\it input\_ad/}}
218    
219     \begin{itemize}
220    
221 dfer 1.12 \item {\it data}: note the smaller {\it cg2dTargetResidual} than in the
222     forward-only experiment,
223 dfer 1.10
224 dfer 1.12 \item {\it data.optim} specifies the iteration number,
225 dfer 1.10
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 dfer 1.12 variable,
229 dfer 1.10
230 dfer 1.12 \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 dfer 1.10
234 dfer 1.12 \item {\it data.pkg}: note that the Gradient Check package is turned on by
235     default (useGrdchk=.TRUE.),
236 dfer 1.10
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 dfer 1.5
241 dfer 1.10 \end{itemize}
242 dfer 1.5
243 dfer 1.3 \subsection{Compiling}
244 dfer 1.1
245     The optimization experiment requires two executables: 1) the
246 dfer 1.10 MITgcm and its adjoint ({\it mitgcmuv\_ad}) and 2) the line-search
247     algorithm ({\it optim.x}).
248 dfer 1.1
249 edhill 1.6 \subsubsection{Compilation of MITgcm and its adjoint: {\it mitcgmuv\_ad}}
250 dfer 1.1
251     Before compiling, first note that, in the directory code\_ad/, two files
252     must be updated:
253 dfer 1.5 \begin{itemize}
254     \item code\_ad\_diff.list which lists new subroutines to be compiled
255 dfer 1.10 by the TAF software (cost\_temp.F and cost\_hflux.F here),
256 dfer 1.1
257 dfer 1.5 \item the adjoint\_hfluxm files which provides a list of the control variables
258 dfer 1.10 and the name of cost function to the TAF software.
259 dfer 1.5
260     \end{itemize}
261 dfer 1.1
262     Then, in the directory build\_ad/, type:
263 dfer 1.5 \begin{verbatim}
264     % ../../../tools/genmake2 -mods=../code\_ad -adof=../code\_ad/adjoint\_hfluxm
265     % make depend
266     % make adall
267     \end{verbatim}
268 dfer 1.10 to generate the MITgcm executable {\it mitgcmuv\_ad}.
269 dfer 1.1
270 edhill 1.6 \subsubsection{Compilation of the line-search algorithm: {\it optim.x}}
271 dfer 1.1
272 dfer 1.10 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 dfer 1.5 \begin{verbatim}
276     % make all
277     \end{verbatim}
278     (more details in lsopt\_doc.txt)
279 dfer 1.1
280 dfer 1.10 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 dfer 1.5 \begin{verbatim}
285     % make depend
286     \end{verbatim}
287     and
288     \begin{verbatim}
289     % make
290     \end{verbatim}
291 edhill 1.6 to generate the line-search executable {\it optim.x}.
292 dfer 1.1
293 dfer 1.3 \subsection{Running the estimation}
294 dfer 1.1
295 dfer 1.10 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 dfer 1.3 \begin{verbatim}
301     % ./mitgcmuv_ad
302     \end{verbatim}
303 dfer 1.1
304 dfer 1.5 The output files adxx\_hfluxm.0000000000.* and xx\_hfluxm.0000000000.* contain
305 dfer 1.12 the sensitivity of the cost function to $Q_\mathrm{netm}$ and the adjustment
306 dfer 1.10 to $Q_\mathrm{netm}$ (zero at the first iteration), respectively. Two other
307 dfer 1.12 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 dfer 1.10 iteration $n$ and an input of the line-search. The latter returns an updated
315 dfer 1.12 adjustment in ctrlhflux\_tut\_MITgcm.opt$n+1$ to be used as an input of the
316     adjoint model at iteration n+1.
317 dfer 1.10
318 dfer 1.12 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 dfer 1.10 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 dfer 1.4
333     Once this is done, run the line-search algorithm:
334     \begin{verbatim}
335     % ./optim.x
336     \end{verbatim}
337 dfer 1.12 which computes the updated adjustment for iteration 1, ctrlhflux\_tut\_MITgcm.opt0001.
338 dfer 1.4
339 edhill 1.6 The following iterations can be executed automatically using the shell
340 dfer 1.10 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 dfer 1.12 store the outputs, move the costhflux* and ctrlhflux* files, and run the
343 dfer 1.10 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 dfer 1.12

  ViewVC Help
Powered by ViewVC 1.1.22