/[MITgcm]/manual/s_autodiff/text/doc_ad_2.tex
ViewVC logotype

Diff of /manual/s_autodiff/text/doc_ad_2.tex

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

revision 1.2 by heimbach, Wed Aug 8 22:08:41 2001 UTC revision 1.14 by cnh, Thu Feb 28 19:32:20 2002 UTC
# Line 18  In principle, a variety of derived algor Line 18  In principle, a variety of derived algor
18  can be generated automatically in this way.  can be generated automatically in this way.
19    
20  The MITGCM has been adapted for use with the  The MITGCM has been adapted for use with the
21  Tangent linear and Adjoint Model Compiler (TAMC) and its succssor TAF  Tangent linear and Adjoint Model Compiler (TAMC) and its successor TAF
22  (Transformation of Algorithms in Fortran), developed  (Transformation of Algorithms in Fortran), developed
23  by Ralf Giering (\cite{gie-kam:98}, \cite{gie:99,gie:00}).  by Ralf Giering (\cite{gie-kam:98}, \cite{gie:99,gie:00}).
24  The first application of the adjoint of the MITGCM for senistivity  The first application of the adjoint of the MITGCM for sensitivity
25  studies has been published by \cite{maro-eta:99}.  studies has been published by \cite{maro-eta:99}.
26  \cite{sta-eta:97,sta-eta:01} use the MITGCM and its adjoint  \cite{sta-eta:97,sta-eta:01} use the MITGCM and its adjoint
27  for ocean state estimation studies.  for ocean state estimation studies.
28    In the following we shall refer to TAMC and TAF synonymously,
29    except were explicitly stated otherwise.
30    
31  TAMC exploits the chain rule for computing the first  TAMC exploits the chain rule for computing the first
32  derivative of a function with  derivative of a function with
33  respect to a set of input variables.  respect to a set of input variables.
34  Treating a given forward code as a composition of operations --  Treating a given forward code as a composition of operations --
35  each line representing a compositional element -- the chain rule is  each line representing a compositional element, the chain rule is
36  rigorously applied to the code, line by line. The resulting  rigorously applied to the code, line by line. The resulting
37  tangent linear or adjoint code,  tangent linear or adjoint code,
38  then, may be thought of as the composition in  then, may be thought of as the composition in
39  forward or reverse order, respectively, of the  forward or reverse order, respectively, of the
40  Jacobian matrices of the forward code compositional elements.  Jacobian matrices of the forward code's compositional elements.
41    
42  %**********************************************************************  %**********************************************************************
43  \section{Some basic algebra}  \section{Some basic algebra}
# Line 50  $\vec{u}=(u_1,\ldots,u_m)$ Line 52  $\vec{u}=(u_1,\ldots,u_m)$
52  such as forcing functions) to the $n$-dimensional space  such as forcing functions) to the $n$-dimensional space
53  $V \subset I\!\!R^n$ of  $V \subset I\!\!R^n$ of
54  model output variable $\vec{v}=(v_1,\ldots,v_n)$  model output variable $\vec{v}=(v_1,\ldots,v_n)$
55  (model state, model diagnostcs, objective function, ...)  (model state, model diagnostics, objective function, ...)
56  under consideration,  under consideration,
57  %  %
58  \begin{equation}  \begin{equation}
# Line 105  In contrast to the full nonlinear model Line 107  In contrast to the full nonlinear model
107  $ M $ is just a matrix  $ M $ is just a matrix
108  which can readily be used to find the forward sensitivity of $\vec{v}$ to  which can readily be used to find the forward sensitivity of $\vec{v}$ to
109  perturbations in  $u$,  perturbations in  $u$,
110  but if there are very many input variables $(>>O(10^{6})$ for  but if there are very many input variables $(\gg O(10^{6})$ for
111  large-scale oceanographic application), it quickly becomes  large-scale oceanographic application), it quickly becomes
112  prohibitive to proceed directly as in (\ref{tangent_linear}),  prohibitive to proceed directly as in (\ref{tangent_linear}),
113  if the impact of each component $ {\bf e_{i}} $ is to be assessed.  if the impact of each component $ {\bf e_{i}} $ is to be assessed.
# Line 130  or a measure of some model-to-data misfi Line 132  or a measure of some model-to-data misfi
132  \label{compo}  \label{compo}
133  \end{eqnarray}  \end{eqnarray}
134  %  %
135  The linear approximation of $ {\cal J} $,  The perturbation of $ {\cal J} $ around a fixed point $ {\cal J}_0 $,
136  \[  \[
137  {\cal J} \, \approx \, {\cal J}_0 \, + \, \delta {\cal J}  {\cal J} \, = \, {\cal J}_0 \, + \, \delta {\cal J}
138  \]  \]
139  can be expressed in both bases of $ \vec{u} $ and $ \vec{v} $  can be expressed in both bases of $ \vec{u} $ and $ \vec{v} $
140  w.r.t. their corresponding inner product  w.r.t. their corresponding inner product
# Line 168  transpose of $ A $, Line 170  transpose of $ A $,
170  \[  \[
171  A^{\ast} \, = \, A^T  A^{\ast} \, = \, A^T
172  \]  \]
173  and from eq. (\ref{tangent_linear}), we note that  and from eq. (\ref{tangent_linear}), (\ref{deljidentity}),
174    we note that
175  (omitting $|$'s):  (omitting $|$'s):
176  %  %
177  \begin{equation}  \begin{equation}
# Line 204  the adjoint variable of the model state Line 207  the adjoint variable of the model state
207  $ \delta \vec{u}^{\ast} $ the adjoint variable of the control variable $ \vec{u} $.  $ \delta \vec{u}^{\ast} $ the adjoint variable of the control variable $ \vec{u} $.
208    
209  The {\sf reverse} nature of the adjoint calculation can be readily  The {\sf reverse} nature of the adjoint calculation can be readily
210  seen as follows. Let us decompose ${\cal J}(u)$, thus:  seen as follows.
211    Consider a model integration which consists of $ \Lambda $
212    consecutive operations
213    $ {\cal M}_{\Lambda} (  {\cal M}_{\Lambda-1} (
214    ...... ( {\cal M}_{\lambda} (
215    ......
216    ( {\cal M}_{1} ( {\cal M}_{0}(\vec{u}) )))) $,
217    where the ${\cal M}$'s could be the elementary steps, i.e. single lines
218    in the code of the model, or successive time steps of the
219    model integration,
220    starting at step 0 and moving up to step $\Lambda$, with intermediate
221    ${\cal M}_{\lambda} (\vec{u}) = \vec{v}^{(\lambda+1)}$ and final
222    ${\cal M}_{\Lambda} (\vec{u}) = \vec{v}^{(\Lambda+1)} = \vec{v}$.
223    Let ${\cal J}$ be a cost function which explicitly depends on the
224    final state $\vec{v}$ only
225    (this restriction is for clarity reasons only).
226    %
227    ${\cal J}(u)$ may be decomposed according to:
228  %  %
229  \begin{equation}  \begin{equation}
230  {\cal J}({\cal M}(\vec{u})) \, = \,  {\cal J}({\cal M}(\vec{u})) \, = \,
# Line 215  seen as follows. Let us decompose ${\cal Line 235  seen as follows. Let us decompose ${\cal
235  \label{compos}  \label{compos}
236  \end{equation}  \end{equation}
237  %  %
238  where the ${\cal M}$'s could be the elementary steps, i.e. single lines  Then, according to the chain rule, the forward calculation reads,
239  in the code of the model,  in terms of the Jacobi matrices
 starting at step 0 and moving up to step $\Lambda$, with intermediate  
 ${\cal M}_{\lambda} (\vec{u}) = \vec{v}^{(\lambda+1)}$ and final  
 ${\cal M}_{\Lambda} (\vec{u}) = \vec{v}^{(\Lambda+1)} = \vec{v}$  
 Then, according to the chain rule the forward calculation reads in  
 terms of the Jacobi matrices  
240  (we've omitted the $ | $'s which, nevertheless are important  (we've omitted the $ | $'s which, nevertheless are important
241  to the aspect of {\it tangent} linearity;  to the aspect of {\it tangent} linearity;
242  note also that per definition  note also that by definition
243  $ \langle \, \nabla _{v}{\cal J}^T \, , \, \delta \vec{v} \, \rangle  $ \langle \, \nabla _{v}{\cal J}^T \, , \, \delta \vec{v} \, \rangle
244  = \nabla_v {\cal J} \cdot \delta \vec{v} $ )  = \nabla_v {\cal J} \cdot \delta \vec{v} $ )
245  %  %
# Line 259  M_{\Lambda}^T \cdot \nabla_v {\cal J}^T Line 274  M_{\Lambda}^T \cdot \nabla_v {\cal J}^T
274  %  %
275  clearly expressing the reverse nature of the calculation.  clearly expressing the reverse nature of the calculation.
276  Eq. (\ref{reverse}) is at the heart of automatic adjoint compilers.  Eq. (\ref{reverse}) is at the heart of automatic adjoint compilers.
277  The intermediate steps $\lambda$ in  If the intermediate steps $\lambda$ in
278  eqn. (\ref{compos}) -- (\ref{reverse})  eqn. (\ref{compos}) -- (\ref{reverse})
279  could represent the model state (forward or adjoint) at each  represent the model state (forward or adjoint) at each
280  intermediate time step in which case  intermediate time step as noted above, then correspondingly,
281  $ {\cal M}(\vec{v}^{(\lambda)}) = \vec{v}^{(\lambda+1)} $, and correspondingly,  $ M^T (\delta \vec{v}^{(\lambda) \, \ast}) =
282  $ M^T (\delta \vec{v}^{(\lambda) \, \ast}) = \delta \vec{v}^{(\lambda-1) \, \ast} $,  \delta \vec{v}^{(\lambda-1) \, \ast} $ for the adjoint variables.
283  but they can also be viewed more generally as  It thus becomes evident that the adjoint calculation also
284  single lines of code in the numerical algorithm.  yields the adjoint of each model state component
285  In both cases it becomes evident that the adjoint calculation  $ \vec{v}^{(\lambda)} $ at each intermediate step $ \lambda $, namely
 yields at the same time the adjoint of each model state component  
 $ \vec{v}^{(\lambda)} $ at each intermediate step $ l $, namely  
286  %  %
287  \begin{equation}  \begin{equation}
288  \boxed{  \boxed{
# Line 285  M_{\Lambda}^T |_{\vec{v}^{(\lambda)}} \c Line 298  M_{\Lambda}^T |_{\vec{v}^{(\lambda)}} \c
298  %  %
299  in close analogy to eq. (\ref{adjoint})  in close analogy to eq. (\ref{adjoint})
300  We note in passing that that the $\delta \vec{v}^{(\lambda) \, \ast}$  We note in passing that that the $\delta \vec{v}^{(\lambda) \, \ast}$
301  are the Lagrange multipliers of the model state $ \vec{v}^{(\lambda)}$.  are the Lagrange multipliers of the model equations which determine
302    $ \vec{v}^{(\lambda)}$.
303    
304  In coponents, eq. (\ref{adjoint}) reads as follows.  In components, eq. (\ref{adjoint}) reads as follows.
305  Let  Let
306  \[  \[
307  \begin{array}{rclcrcl}  \begin{array}{rclcrcl}
# Line 308  Let Line 322  Let
322  \end{array}  \end{array}
323  \]  \]
324  denote the perturbations in $\vec{u}$ and $\vec{v}$, respectively,  denote the perturbations in $\vec{u}$ and $\vec{v}$, respectively,
325  and their adjoint varaiables;  and their adjoint variables;
326  further  further
327  \[  \[
328  M \, = \, \left(  M \, = \, \left(
# Line 395  and the shorthand notation for the adjoi Line 409  and the shorthand notation for the adjoi
409  $ \delta v^{(\lambda) \, \ast}_{j} = \frac{\partial}{\partial v^{(\lambda)}_{j}}  $ \delta v^{(\lambda) \, \ast}_{j} = \frac{\partial}{\partial v^{(\lambda)}_{j}}
410  {\cal J}^T $, $ j = 1, \ldots , n_{\lambda} $,  {\cal J}^T $, $ j = 1, \ldots , n_{\lambda} $,
411  for intermediate components, yielding  for intermediate components, yielding
412  \[  \begin{equation}
413  \footnotesize  \small
414    \begin{split}
415  \left(  \left(
416  \begin{array}{c}  \begin{array}{c}
417  \delta v^{(\lambda) \, \ast}_1 \\  \delta v^{(\lambda) \, \ast}_1 \\
# Line 404  for intermediate components, yielding Line 419  for intermediate components, yielding
419  \delta v^{(\lambda) \, \ast}_{n_{\lambda}} \\  \delta v^{(\lambda) \, \ast}_{n_{\lambda}} \\
420  \end{array}  \end{array}
421  \right)  \right)
422  \, = \,  \, = &
423  \left(  \left(
424  \begin{array}{ccc}  \begin{array}{ccc}
425  \frac{\partial ({\cal M}_{\lambda})_1}{\partial v^{(\lambda)}_1}  \frac{\partial ({\cal M}_{\lambda})_1}{\partial v^{(\lambda)}_1}
426  & \ldots &  & \ldots \,\, \ldots &
427  \frac{\partial ({\cal M}_{\lambda})_{n_{\lambda+1}}}{\partial v^{(\lambda)}_1} \\  \frac{\partial ({\cal M}_{\lambda})_{n_{\lambda+1}}}{\partial v^{(\lambda)}_1} \\
428  \vdots & ~ & \vdots \\  \vdots & ~ & \vdots \\
429  \frac{\partial ({\cal M}_{\lambda})_1}{\partial v^{(\lambda)}_{n_{\lambda}}}  \frac{\partial ({\cal M}_{\lambda})_1}{\partial v^{(\lambda)}_{n_{\lambda}}}
430  & \ldots  &  & \ldots \,\, \ldots  &
431  \frac{\partial ({\cal M}_{\lambda})_{n_{\lambda+1}}}{\partial v^{(\lambda)}_{n_{\lambda}}} \\  \frac{\partial ({\cal M}_{\lambda})_{n_{\lambda+1}}}{\partial v^{(\lambda)}_{n_{\lambda}}} \\
432  \end{array}  \end{array}
433  \right)  \right)
 %  
434  \cdot  \cdot
435  %  %
436    \\ ~ & ~
437    \\ ~ &
438    %
439  \left(  \left(
440  \begin{array}{ccc}  \begin{array}{ccc}
441  \frac{\partial ({\cal M}_{\lambda+1})_1}{\partial v^{(\lambda+1)}_1}  \frac{\partial ({\cal M}_{\lambda+1})_1}{\partial v^{(\lambda+1)}_1}
# Line 431  for intermediate components, yielding Line 448  for intermediate components, yielding
448  \frac{\partial ({\cal M}_{\lambda+1})_{n_{\lambda+2}}}{\partial v^{(\lambda+1)}_{n_{\lambda+1}}} \\  \frac{\partial ({\cal M}_{\lambda+1})_{n_{\lambda+2}}}{\partial v^{(\lambda+1)}_{n_{\lambda+1}}} \\
449  \end{array}  \end{array}
450  \right)  \right)
451  \cdot \ldots \ldots \cdot  \cdot \, \ldots \, \cdot
452  \left(  \left(
453  \begin{array}{c}  \begin{array}{c}
454  \delta v^{\ast}_1 \\  \delta v^{\ast}_1 \\
# Line 439  for intermediate components, yielding Line 456  for intermediate components, yielding
456  \delta v^{\ast}_{n} \\  \delta v^{\ast}_{n} \\
457  \end{array}  \end{array}
458  \right)  \right)
459  \]  \end{split}
460    \end{equation}
461    
462  Eq. (\ref{forward}) and (\ref{reverse}) are perhaps clearest in  Eq. (\ref{forward}) and (\ref{reverse}) are perhaps clearest in
463  showing the advantage of the reverse over the forward mode  showing the advantage of the reverse over the forward mode
# Line 450  variables $u$ Line 468  variables $u$
468  {\it all} intermediate states $ \vec{v}^{(\lambda)} $) are sought.  {\it all} intermediate states $ \vec{v}^{(\lambda)} $) are sought.
469  In order to be able to solve for each component of the gradient  In order to be able to solve for each component of the gradient
470  $ \partial {\cal J} / \partial u_{i} $ in (\ref{forward})  $ \partial {\cal J} / \partial u_{i} $ in (\ref{forward})
471  a forward calulation has to be performed for each component seperately,  a forward calculation has to be performed for each component separately,
472  i.e. $ \delta \vec{u} = \delta u_{i} {\vec{e}_{i}} $  i.e. $ \delta \vec{u} = \delta u_{i} {\vec{e}_{i}} $
473  for  the $i$-th forward calculation.  for  the $i$-th forward calculation.
474  Then, (\ref{forward}) represents the  Then, (\ref{forward}) represents the
# Line 460  In contrast, eq. (\ref{reverse}) yields Line 478  In contrast, eq. (\ref{reverse}) yields
478  gradient $\nabla _{u}{\cal J}$ (and all intermediate gradients  gradient $\nabla _{u}{\cal J}$ (and all intermediate gradients
479  $\nabla _{v^{(\lambda)}}{\cal J}$) within a single reverse calculation.  $\nabla _{v^{(\lambda)}}{\cal J}$) within a single reverse calculation.
480    
481  Note, that in case $ {\cal J} $ is a vector-valued function  Note, that if $ {\cal J} $ is a vector-valued function
482  of dimension $ l > 1 $,  of dimension $ l > 1 $,
483  eq. (\ref{reverse}) has to be modified according to  eq. (\ref{reverse}) has to be modified according to
484  \[  \[
# Line 468  M^T \left( \nabla_v {\cal J}^T \left(\de Line 486  M^T \left( \nabla_v {\cal J}^T \left(\de
486  \, = \,  \, = \,
487  \nabla_u {\cal J}^T \cdot \delta \vec{J}  \nabla_u {\cal J}^T \cdot \delta \vec{J}
488  \]  \]
489  where now $ \delta \vec{J} \in I\!\!R $ is a vector of dimenison $ l $.  where now $ \delta \vec{J} \in I\!\!R^l $ is a vector of
490    dimension $ l $.
491  In this case $ l $ reverse simulations have to be performed  In this case $ l $ reverse simulations have to be performed
492  for each $ \delta J_{k}, \,\, k = 1, \ldots, l $.  for each $ \delta J_{k}, \,\, k = 1, \ldots, l $.
493  Then, the reverse mode is more efficient as long as  Then, the reverse mode is more efficient as long as
494  $ l < n $, otherwise the forward mode is preferable.  $ l < n $, otherwise the forward mode is preferable.
495  Stricly, the reverse mode is called adjoint mode only for  Strictly, the reverse mode is called adjoint mode only for
496  $ l = 1 $.  $ l = 1 $.
497    
498  A detailed analysis of the underlying numerical operations  A detailed analysis of the underlying numerical operations
# Line 503  operator onto the $j$-th component ${\bf Line 522  operator onto the $j$-th component ${\bf
522  \paragraph{Example 2:  \paragraph{Example 2:
523  $ {\cal J} = \langle \, {\cal H}(\vec{v}) - \vec{d} \, ,  $ {\cal J} = \langle \, {\cal H}(\vec{v}) - \vec{d} \, ,
524   \, {\cal H}(\vec{v}) - \vec{d} \, \rangle $} ~ \\   \, {\cal H}(\vec{v}) - \vec{d} \, \rangle $} ~ \\
525  The cost function represents the quadratic model vs.data misfit.  The cost function represents the quadratic model vs. data misfit.
526  Here, $ \vec{d} $ is the data vector and $ {\cal H} $ represents the  Here, $ \vec{d} $ is the data vector and $ {\cal H} $ represents the
527  operator which maps the model state space onto the data space.  operator which maps the model state space onto the data space.
528  Then, $ \nabla_v {\cal J} $ takes the form  Then, $ \nabla_v {\cal J} $ takes the form
# Line 534  H \cdot \left( {\cal H}(\vec{v}) - \vec{ Line 553  H \cdot \left( {\cal H}(\vec{v}) - \vec{
553    
554  We note an important aspect of the forward vs. reverse  We note an important aspect of the forward vs. reverse
555  mode calculation.  mode calculation.
556  Because of the locality of the derivative,  Because of the local character of the derivative
557    (a derivative is defined w.r.t. a point along the trajectory),
558  the intermediate results of the model trajectory  the intermediate results of the model trajectory
559  $\vec{v}^{(\lambda+1)}={\cal M}_{\lambda}(v^{(\lambda)})$  $\vec{v}^{(\lambda+1)}={\cal M}_{\lambda}(v^{(\lambda)})$
560  are needed to evaluate the intermediate Jacobian  are needed to evaluate the intermediate Jacobian
561  $M_{\lambda}|_{\vec{v}^{(\lambda)}} \, \delta \vec{v}^{(\lambda)} $.  $M_{\lambda}|_{\vec{v}^{(\lambda)}} \, \delta \vec{v}^{(\lambda)} $.
562  In the forward mode, the intermediate results are required  In the forward mode, the intermediate results are required
563  in the same order as computed by the full forward model ${\cal M}$,  in the same order as computed by the full forward model ${\cal M}$,
564  in the reverse mode they are required in the reverse order.  but in the reverse mode they are required in the reverse order.
565  Thus, in the reverse mode the trajectory of the forward model  Thus, in the reverse mode the trajectory of the forward model
566  integration ${\cal M}$ has to be stored to be available in the reverse  integration ${\cal M}$ has to be stored to be available in the reverse
567  calculation. Alternatively, the model state would have to be  calculation. Alternatively, the complete model state up to the
568  recomputed whenever its value is required.  point of evaluation has to be recomputed whenever its value is required.
569    
570  A method to balance the amount of recomputations vs.  A method to balance the amount of recomputations vs.
571  storage requirements is called {\sf checkpointing}  storage requirements is called {\sf checkpointing}
572  (e.g. \cite{res-eta:98}).  (e.g. \cite{res-eta:98}).
573  It is depicted in Fig. ... for a 3-level checkpointing  It is depicted in \ref{fig:3levelcheck} for a 3-level checkpointing
574  [as concrete example, we give explicit numbers for a 3-day  [as an example, we give explicit numbers for a 3-day
575  integration with a 1-hourly timestep in square brackets].  integration with a 1-hourly timestep in square brackets].
576  \begin{itemize}  \begin{itemize}
577  %  %
# Line 559  integration with a 1-hourly timestep in Line 579  integration with a 1-hourly timestep in
579  In a first step, the model trajectory is subdivided into  In a first step, the model trajectory is subdivided into
580  $ {n}^{lev3} $ subsections [$ {n}^{lev3} $=3 1-day intervals],  $ {n}^{lev3} $ subsections [$ {n}^{lev3} $=3 1-day intervals],
581  with the label $lev3$ for this outermost loop.  with the label $lev3$ for this outermost loop.
582  The model is then integrated over the full trajectory,  The model is then integrated along the full trajectory,
583  and the model state stored only at every $ k_{i}^{lev3} $-th timestep  and the model state stored only at every $ k_{i}^{lev3} $-th timestep
584  [i.e. 3 times, at  [i.e. 3 times, at
585  $ i = 0,1,2 $ corresponding to $ k_{i}^{lev3} = 0, 24, 48 $].  $ i = 0,1,2 $ corresponding to $ k_{i}^{lev3} = 0, 24, 48 $].
586  %  %
587  \item [$lev2$]  \item [$lev2$]
588  In a second step each subsection is itself divided into  In a second step each subsection itself is divided into
589  $ {n}^{lev2} $ subsubsections  $ {n}^{lev2} $ sub-subsections
590  [$ {n}^{lev2} $=4 6-hour intervals per subsection].  [$ {n}^{lev2} $=4 6-hour intervals per subsection].
591  The model picks up at the last outermost dumped state  The model picks up at the last outermost dumped state
592  $ v_{k_{n}^{lev3}} $ and is integrated forward in time over  $ v_{k_{n}^{lev3}} $ and is integrated forward in time along
593  the last subsection, with the label $lev2$ for this    the last subsection, with the label $lev2$ for this  
594  intermediate loop.  intermediate loop.
595  The model state is now stored only at every $ k_{i}^{lev2} $-th  The model state is now stored at every $ k_{i}^{lev2} $-th
596  timestep  timestep
597  [i.e. 4 times, at  [i.e. 4 times, at
598  $ i = 0,1,2,3 $ corresponding to $ k_{i}^{lev2} = 48, 54, 60, 66 $].  $ i = 0,1,2,3 $ corresponding to $ k_{i}^{lev2} = 48, 54, 60, 66 $].
599  %  %
600  \item [$lev1$]  \item [$lev1$]
601  Finally, the mode picks up at the last intermediate dump state  Finally, the model picks up at the last intermediate dump state
602  $ v_{k_{n}^{lev2}} $ and is integrated forward in time over  $ v_{k_{n}^{lev2}} $ and is integrated forward in time along
603  the last subsubsection, with the label $lev1$ for this    the last sub-subsection, with the label $lev1$ for this  
604  intermediate loop.  intermediate loop.
605  Within this subsubsection only, the model state is stored  Within this sub-subsection only, the model state is stored
606  at every timestep  at every timestep
607  [i.e. every hour $ i=0,...,5$ corresponding to  [i.e. every hour $ i=0,...,5$ corresponding to
608  $ k_{i}^{lev1} = 66, 67, \ldots, 71 $].  $ k_{i}^{lev1} = 66, 67, \ldots, 71 $].
609  Thus, the  final state $ v_n = v_{k_{n}^{lev1}} $ is reached  Thus, the  final state $ v_n = v_{k_{n}^{lev1}} $ is reached
610  and the model state of all peceeding timesteps over the last  and the model state of all proceeding timesteps along the last
611  subsubsections are available, enabling integration backwards  sub-subsections are available, enabling integration backwards
612  in time over the last subsubsection.  in time along the last sub-subsection.
613  Thus, the adjoint can be computed over this last  Thus, the adjoint can be computed along this last
614  subsubsection $k_{n}^{lev2}$.  sub-subsection $k_{n}^{lev2}$.
615  %  %
616  \end{itemize}  \end{itemize}
617  %  %
618  This procedure is repeated consecutively for each previous  This procedure is repeated consecutively for each previous
619  subsubsection $k_{n-1}^{lev2}, \ldots, k_{1}^{lev2} $  sub-subsection $k_{n-1}^{lev2}, \ldots, k_{1}^{lev2} $
620  carrying the adjoint computation to the initial time  carrying the adjoint computation to the initial time
621  of the subsection $k_{n}^{lev3}$.  of the subsection $k_{n}^{lev3}$.
622  Then, the procedure is repeated for the previous subsection  Then, the procedure is repeated for the previous subsection
# Line 617  The balance of storage vs. recomputation Line 637  The balance of storage vs. recomputation
637  on the computing resources available.  on the computing resources available.
638    
639  \begin{figure}[t!]  \begin{figure}[t!]
640  \centering  \begin{center}
641  %\psdraft  %\psdraft
642  \psfrag{v_k1^lev3}{\mathinfigure{v_{k_{1}^{lev3}}}}  %\psfrag{v_k1^lev3}{\mathinfigure{v_{k_{1}^{lev3}}}}
643  \psfrag{v_kn-1^lev3}{\mathinfigure{v_{k_{n-1}^{lev3}}}}  %\psfrag{v_kn-1^lev3}{\mathinfigure{v_{k_{n-1}^{lev3}}}}
644  \psfrag{v_kn^lev3}{\mathinfigure{v_{k_{n}^{lev3}}}}  %\psfrag{v_kn^lev3}{\mathinfigure{v_{k_{n}^{lev3}}}}
645  \psfrag{v_k1^lev2}{\mathinfigure{v_{k_{1}^{lev2}}}}  %\psfrag{v_k1^lev2}{\mathinfigure{v_{k_{1}^{lev2}}}}
646  \psfrag{v_kn-1^lev2}{\mathinfigure{v_{k_{n-1}^{lev2}}}}  %\psfrag{v_kn-1^lev2}{\mathinfigure{v_{k_{n-1}^{lev2}}}}
647  \psfrag{v_kn^lev2}{\mathinfigure{v_{k_{n}^{lev2}}}}  %\psfrag{v_kn^lev2}{\mathinfigure{v_{k_{n}^{lev2}}}}
648  \psfrag{v_k1^lev1}{\mathinfigure{v_{k_{1}^{lev1}}}}  %\psfrag{v_k1^lev1}{\mathinfigure{v_{k_{1}^{lev1}}}}
649  \psfrag{v_kn^lev1}{\mathinfigure{v_{k_{n}^{lev1}}}}  %\psfrag{v_kn^lev1}{\mathinfigure{v_{k_{n}^{lev1}}}}
650  \mbox{\epsfig{file=part5/checkpointing.eps, width=0.8\textwidth}}  %\mbox{\epsfig{file=part5/checkpointing.eps, width=0.8\textwidth}}
651    \resizebox{5.5in}{!}{\includegraphics{part5/checkpointing.eps}}
652  %\psfull  %\psfull
653  \caption  \end{center}
654  {Schematic view of intermediate dump and restart for  \caption{
655    Schematic view of intermediate dump and restart for
656  3-level checkpointing.}  3-level checkpointing.}
657  \label{fig:erswns}  \label{fig:3levelcheck}
658  \end{figure}  \end{figure}
659    
660  \subsection{Optimal perturbations}  % \subsection{Optimal perturbations}
661  \label{optpert}  % \label{sec_optpert}
   
   
 \subsection{Error covariance estimate and Hessian matrix}  
 \label{sec_hessian}  
   
 \newpage  
   
 %**********************************************************************  
 \section{AD-specific setup by example: sensitivity of carbon sequestration}  
 \label{sec_ad_setup_ex}  
 %**********************************************************************  
   
 The MITGCM has been adapted to enable AD using TAMC or TAF  
 (we'll refer to TAMC and TAF interchangeably, except where  
 distinctions are explicitly mentioned).  
 The present description, therefore, is specific to the  
 use of TAMC as AD tool.  
 The following sections describe the steps which are necessary to  
 generate a tangent linear or adjoint model of the MITGCM.  
 We take as an example the sensitivity of carbon sequestration  
 in the ocean.  
 The AD-relevant hooks in the code are sketched in  
 \reffig{adthemodel}, \reffig{adthemain}.  
   
 \subsection{Overview of the experiment}  
   
 We describe an adjoint sensitivity analysis of outgassing from  
 the ocean into the atmosphere of a carbon like tracer injected  
 into the ocean interior (see \cite{hil-eta:01}).  
   
 \subsubsection{Passive tracer equation}  
   
 For this work the MITGCM was augmented with a thermodynamically  
 inactive tracer, $C$. Tracer residing in the ocean  
 model surface layer is outgassed according to a relaxation time scale,  
 $\mu$. Within the ocean interior, the tracer is passively advected  
 by the ocean model currents. The full equation for the time evolution  
 %  
 \begin{equation}  
 \label{carbon_ddt}  
 \frac{\partial C}{\partial t} \, = \,  
 -U\cdot \nabla C \, - \, \mu C \, + \, \Gamma(C) \,+ \, S  
 \end{equation}  
 %  
 also includes a source term $S$. This term  
 represents interior sources of $C$ such as would arise due to  
 direct injection.  
 The velocity term, $U$, is the sum of the  
 model Eulerian circulation and an eddy-induced velocity, the latter  
 parameterized according to Gent/McWilliams (\cite{gen:90, dan:95}).  
 The convection function, $\Gamma$, mixes $C$ vertically wherever the  
 fluid is locally statically unstable.  
   
 The outgassing time scale, $\mu$, in eqn. (\ref{carbon_ddt})  
 is set so that \( 1/\mu \sim 1 \ \mathrm{year} \) for the surface  
 ocean and $\mu=0$ elsewhere. With this value, eqn. (\ref{carbon_ddt})  
 is valid as a prognostic equation for small perturbations in oceanic  
 carbon concentrations. This configuration provides a  
 powerful tool for examining the impact of large-scale ocean circulation  
 on $ CO_2 $ outgassing due to interior injections.  
 As source we choose a constant in time injection of  
 $ S = 1 \,\, {\rm mol / s}$.  
   
 \subsubsection{Model configuration}  
   
 The model configuration employed has a constant  
 $4^\circ \times 4^\circ$ resolution horizontal grid and realistic  
 geography and bathymetry. Twenty vertical layers are used with  
 vertical spacing ranging  
 from 50 m near the surface to 815 m at depth.  
 Driven to steady-state by climatalogical wind-stress, heat and  
 fresh-water forcing the model reproduces well known large-scale  
 features of the ocean general circulation.  
   
 \subsubsection{Outgassing cost function}  
   
 To quantify and understand outgassing due to injections of $C$  
 in eqn. (\ref{carbon_ddt}),  
 we define a cost function $ {\cal J} $ that measures the total amount of  
 tracer outgassed at each timestep:  
 %  
 \begin{equation}  
 \label{cost_tracer}  
 {\cal J}(t=T)=\int_{t=0}^{t=T}\int_{A} \mu C \, dA \, dt  
 \end{equation}  
 %  
 Equation(\ref{cost_tracer}) integrates the outgassing term, $\mu C$,  
 from (\ref{carbon_ddt})  
 over the entire ocean surface area, $A$, and accumulates it  
 up to time $T$.  
 Physically, ${\cal J}$ can be thought of as representing the amount of  
 $CO_2$ that our model predicts would be outgassed following an  
 injection at rate $S$.  
 The sensitivity of ${\cal J}$ to the spatial location of $S$,  
 $\frac{\partial {\cal J}}{\partial S}$,  
 can be used to identify regions from which circulation  
 would cause $CO_2$ to rapidly outgas following injection  
 and regions in which $CO_2$ injections would remain effectively  
 sequesterd within the ocean.  
   
 \subsection{Code configuration}  
   
 The model configuration for this experiment resides under the  
 directory {\it verification/carbon/}.  
 The code customisation routines are in {\it verification/carbon/code/}:  
 %  
 \begin{itemize}  
 %  
 \item {\it .genmakerc}  
 %  
 \item {\it COST\_CPPOPTIONS.h}  
 %  
 \item {\it CPP\_EEOPTIONS.h}  
 %  
 \item {\it CPP\_OPTIONS.h}  
 %  
 \item {\it CTRL\_OPTIONS.h}  
 %  
 \item {\it ECCO\_OPTIONS.h}  
 %  
 \item {\it SIZE.h}  
 %  
 \item {\it adcommon.h}  
 %  
 \item {\it tamc.h}  
 %  
 \end{itemize}  
 %  
 The runtime flag and parameters settings are contained in  
 {\it verification/carbon/input/},  
 together with the forcing fields and and restart files:  
 %  
 \begin{itemize}  
 %  
 \item {\it data}  
 %  
 \item {\it data.cost}  
 %  
 \item {\it data.ctrl}  
 %  
 \item {\it data.pkg}  
 %  
 \item {\it eedata}  
 %  
 \item {\it topog.bin}  
 %  
 \item {\it windx.bin, windy.bin}  
 %  
 \item {\it salt.bin, theta.bin}  
 %  
 \item {\it SSS.bin, SST.bin}  
 %  
 \item {\it pickup*}  
 %  
 \end{itemize}  
 %  
 Finally, the file to generate the adjoint code resides in  
 $ adjoint/ $:  
 %  
 \begin{itemize}  
 %  
 \item {\it makefile}  
 %  
 \end{itemize}  
 %  
   
 Below we describe the customisations of this files which are  
 specific to this experiment.  
   
 \subsubsection{File {\it .genmakerc}}  
 This file overwites default settings of {\it genmake}.  
 In the present example it is used to switch on the following  
 packages which are related to automatic differentiation  
 and are disabled by default: \\  
 \hspace*{4ex} {\tt set ENABLE=( autodiff cost ctrl ecco )}  \\  
 Other packages which are not needed are switched off: \\  
 \hspace*{4ex} {\tt set DISABLE=( aim obcs zonal\_filt shap\_filt cal exf )}  
   
 \subsubsection{File {\it COST\_CPPOPTIONS.h,  CTRL\_OPTIONS.h}}  
   
 These files used to contain package-specific CPP-options  
 (see Section \ref{???}).  
 For technical reasons those options have been grouped together  
 in the file {\it ECCO\_OPTIONS.h}.  
 To retain the modularity, the files have been kept and contain  
 the standard include of the {\it CPP\_OPTIONS.h} file.  
   
 \subsubsection{File {\it CPP\_EEOPTIONS.h}}  
   
 This file contains 'wrapper'-specific CPP options.  
 It only needs to be changed if the code is to be run  
 in  parallel environment (see Section \ref{???}).  
   
 \subsubsection{File {\it CPP\_OPTIONS.h}}  
   
 This file contains model-specific CPP options  
 (see Section \ref{???}).  
 Most options are related to the forward model setup.  
 They are identical to the global steady circulation setup of  
 {\it verification/exp2/}.  
 The option specific to this experiment is \\  
 \hspace*{4ex} {\tt \#define ALLOW\_MIT\_ADJOINT\_RUN} \\  
 This flag enables the inclusion of some AD-related fields  
 concerning initialisation, link between control variables  
 and forward model variables, and the call to the top-level  
 forward/adjoint subroutine {\it adthe\_main\_loop}  
 instead of {\it the\_main\_loop}.  
   
 \subsubsection{File {\it ECCO\_OPTIONS.h}}  
   
 The CPP options of several AD-related packages are grouped  
 in this file:  
 %  
 \begin{itemize}  
 %  
 \item  
 Adjoint support package: {\it pkg/autodiff/} \\  
 This package contains hand-written adjoint code such as  
 active file handling, flow directives for files which must not  
 be differentiated, and TAMC-specific header files. \\  
 \hspace*{4ex} {\tt \#define ALLOW\_AUTODIFF\_TAMC} \\  
 defines TAMC-related features in the code. \\  
 \hspace*{4ex} {\tt \#define ALLOW\_TAMC\_CHECKPOINTING} \\  
 enables the checkpointing feature of TAMC  
 (see Section \ref{???}).  
 In the present example a 3-level checkpointing is implemented.  
 The code contains the relevant store directives, common block  
 and tape initialisations, storing key computation,  
 and loop index handling.  
 The checkpointing length at each level is defined in  
 file {\it tamc.h}, cf. below.  
 %  
 \item Cost function package: {\it pkg/cost/} \\  
 This package contains all relevant routines for  
 initialising, accumulating and finalizing the cost function  
 (see Section \ref{???}). \\  
 \hspace*{4ex} {\tt \#define ALLOW\_COST} \\  
 enables all general aspects of the cost function handling,  
 in particular the hooks in the foorward code for  
 initialising, accumulating and finalizing the cost function. \\  
 \hspace*{4ex} {\tt \#define ALLOW\_COST\_TRACER} \\  
 includes the subroutine with the cost function for this  
 particular experiment, eqn. (\ref{cost_tracer}).  
 %  
 \item Control variable package: {\it pkg/ctrl/} \\  
 This package contains all relevant routines for  
 the handling of the control vector.  
 Each control variable can be enabled/disabled with its own flag: \\  
 \begin{tabular}{ll}  
 \hspace*{2ex} {\tt \#define ALLOW\_THETA0\_CONTROL} &  
 initial temperature \\  
 \hspace*{2ex} {\tt \#define ALLOW\_SALT0\_CONTROL} &  
 initial salinity \\  
 \hspace*{2ex} {\tt \#define ALLOW\_TR0\_CONTROL} &  
 initial passive tracer concentration \\  
 \hspace*{2ex} {\tt \#define ALLOW\_TAUU0\_CONTROL} &  
 zonal wind stress \\  
 \hspace*{2ex} {\tt \#define ALLOW\_TAUV0\_CONTROL} &  
 meridional wind stress \\  
 \hspace*{2ex} {\tt \#define ALLOW\_SFLUX0\_CONTROL} &  
 freshwater flux \\  
 \hspace*{2ex} {\tt \#define ALLOW\_HFLUX0\_CONTROL} &  
 heat flux \\  
 \hspace*{2ex} {\tt \#undef ALLOW\_DIFFKR\_CONTROL} &  
 diapycnal diffusivity \\  
 \hspace*{2ex} {\tt \#undef ALLOW\_KAPPAGM\_CONTROL} &  
 isopycnal diffusivity \\  
 \end{tabular}  
 %  
 \end{itemize}  
   
 \subsubsection{File {\it SIZE.h}}  
   
 The file contains the grid point dimensions of the forward  
 model. It is identical to the {\it verification/exp2/}: \\  
 \hspace*{4ex} {\tt sNx = 90} \\  
 \hspace*{4ex} {\tt sNy = 40} \\  
 \hspace*{4ex} {\tt Nr = 20} \\  
 It correpsponds to a single-tile/single-processor setup:  
 {\tt nSx = nSy = 1, nPx = nPy = 1},  
 with standard overlap dimensioning  
 {\tt OLx = OLy = 3}.  
   
 \subsubsection{File {\it adcommon.h}}  
   
 This file contains common blocks of some adjoint variables  
 that are generated by TAMC.  
 The common blocks are used by the adjoint support routine  
 {\it addummy\_in\_stepping} which needs to access those variables:  
   
 \begin{tabular}{ll}  
 \hspace*{4ex} {\tt common /addynvars\_r/} &  
 \hspace*{4ex} is related to {\it DYNVARS.h} \\  
 \hspace*{4ex} {\tt common /addynvars\_cd/} &  
 \hspace*{4ex} is related to {\it DYNVARS.h} \\  
 \hspace*{4ex} {\tt common /adtr1\_r/} &  
 \hspace*{4ex} is related to {\it TR1.h} \\  
 \hspace*{4ex} {\tt common /adffields/} &  
 \hspace*{4ex} is related to {\it FFIELDS.h}\\  
 \end{tabular}  
   
 Note that if the structure of the common block changes in the  
 above header files of the forward code, the structure  
 of the adjoint common blocks will change accordingly.  
 Thus, it has to be made sure that the structure of the  
 adjoint common block in the hand-written file {\it adcommon.h}  
 complies with the automatically generated adjoint common blocks  
 in {\it adjoint\_model.F}.  
   
 \subsubsection{File {\it tamc.h}}  
   
 This routine contains the dimensions for TAMC checkpointing.  
 %  
 \begin{itemize}  
 %  
 \item {\tt \#ifdef ALLOW\_TAMC\_CHECKPOINTING} \\  
 3-level checkpointing is enabled, i.e. the timestepping  
 is divided into three different levels (see Section \ref{???}).  
 The model state of the outermost ({\tt nchklev\_3}) and the  
 itermediate ({\tt nchklev\_2}) timestepping loop are stored to file  
 (handled in {\it the\_main\_loop}).  
 The innermost loop ({\tt nchklev\_1})  
 avoids I/O by storing all required variables  
 to common blocks. This storing may also be necessary if  
 no checkpointing is chosen  
 (nonlinear functions, if-statements, iterative loops, ...).  
 In the present example the dimensions are chosen as follows: \\  
 \hspace*{4ex} {\tt nchklev\_1      =  36 } \\  
 \hspace*{4ex} {\tt nchklev\_2      =  30 } \\  
 \hspace*{4ex} {\tt nchklev\_3      =  60 } \\  
 To guarantee that the checkpointing intervals span the entire  
 integration period the relation \\  
 \hspace*{4ex} {\tt nchklev\_1*nchklev\_2*nchklev\_3 $ \ge $ nTimeSteps} \\  
 where {\tt nTimeSteps} is either specified in {\it data}  
 or computed via \\  
 \hspace*{4ex} {\tt nTimeSteps = (endTime-startTime)/deltaTClock }.  
 %  
 \item {\tt \#undef ALLOW\_TAMC\_CHECKPOINTING} \\  
 No checkpointing is enabled.  
 In this case the relevant counter is {\tt nchklev\_0}.  
 Similar to above, the following relation has to be satisfied \\  
 \hspace*{4ex} {\tt nchklev\_0 $ \ge $ nTimeSteps}.  
 %  
 \end{itemize}  
   
 \subsubsection{File {\it makefile}}  
   
 This file contains all relevant paramter flags and  
 lists to run TAMC.  
 It is assumed that TAMC is available to you, either locally,  
 being installed on your network, or remotely through the 'TAMC Utility'.  
 TAMC is called with the command {\tt tamc} followed by a  
 number of options. They are described in detail in the  
 TAMC manual \cite{gie:99}.  
 Here we briefly discuss the main flags used in the {\it makefile}  
 %  
 \begin{itemize}  
 \item [{\tt tamc}] {\tt  
 -input <variable names>  
 -output <variable name> ... \\  
 -toplevel <S/R name> -reverse <file names>  
 }  
 \end{itemize}  
 %  
 \begin{itemize}  
 %  
 \item {\tt -toplevel <S/R name>} \\  
 Name of the toplevel routine, with respect to which the  
 control flow analysis is performed.  
 %  
 \item {\tt -input <variable names>} \\  
 List of independent variables $ u $ with respect to which the  
 dependent variable $ J $ is differentiated.  
 %  
 \item {\tt -output <variable name>} \\  
 Dependent variable $ J $  which is to be differentiated.  
 %  
 \item {\tt -reverse <file names>} \\  
 Adjoint code is generated to compute the sensitivity of an  
 independent variable w.r.t.  many dependent variables.  
 The generated adjoint top-level routine computes the product  
 of the transposed Jacobian matrix $ M^T $ times  
 the gradient vector $ \nabla_v J $.  
 \\  
 {\tt <file names>} refers to the list of files {\it .f} which are to be  
 analyzed by TAMC. This list is generally smaller than the full list  
 of code to be compiled. The files not contained are either  
 above the top-level routine (some initialisations), or are  
 deliberately hidden from TAMC, either because hand-written  
 adjoint routines exist, or the routines must not (or don't have to)  
 be differentiated. For each routine which is part of the flow tree  
 of the top-level routine, but deliberately hidden from TAMC,  
 a corresponding file {\it .flow} exists containing flow directives  
 for TAMC.  
 %  
 \end{itemize}  
   
   
 \subsubsection{File {\it data}}  
   
 \subsubsection{File {\it data.cost}}  
   
 \subsubsection{File {\it data.ctrl}}  
   
 \subsubsection{File {\it data.pkg}}  
   
 \subsubsection{File {\it eedata}}  
   
 \subsubsection{File {\it topog.bin}}  
   
 \subsubsection{File {\it windx.bin, windy.bin}}  
   
 \subsubsection{File {\it salt.bin, theta.bin}}  
   
 \subsubsection{File {\it SSS.bin, SST.bin}}  
662    
 \subsubsection{File {\it pickup*}}  
663    
664  \subsection{Compiling the model and its adjoint}  % \subsection{Error covariance estimate and Hessian matrix}
665    % \label{sec_hessian}
666    
667  \newpage  \newpage
668    
669  %**********************************************************************  %**********************************************************************
670  \section{TLM and ADM code generation in general}  \section{TLM and ADM generation in general}
671  \label{sec_ad_setup_gen}  \label{sec_ad_setup_gen}
672  %**********************************************************************  %**********************************************************************
673    
# Line 1068  In this section we describe in a general Line 675  In this section we describe in a general
675  the parts of the code that are relevant for automatic  the parts of the code that are relevant for automatic
676  differentiation using the software tool TAMC.  differentiation using the software tool TAMC.
677    
678  \subsection{The cost function (dependent variable)}  \input{part5/doc_ad_the_model}
679    
680    The basic flow is depicted in \ref{fig:adthemodel}.
681    If the option {\tt ALLOW\_AUTODIFF\_TAMC} is defined, the driver routine
682    {\it the\_model\_main}, instead of calling {\it the\_main\_loop},
683    invokes the adjoint of this routine, {\it adthe\_main\_loop},
684    which is the toplevel routine in terms of reverse mode computation.
685    The routine {\it adthe\_main\_loop} has been generated using TAMC.
686    It contains both the forward integration of the full model,
687    any additional storing that is required for efficient checkpointing,
688    and the reverse integration of the adjoint model.
689    The structure of {\it adthe\_main\_loop} has been strongly
690    simplified for clarification; in particular, no checkpointing
691    procedures are shown here.
692    Prior to the call of {\it adthe\_main\_loop}, the routine
693    {\it ctrl\_unpack} is invoked to unpack the control vector,
694    and following that call, the routine {\it ctrl\_pack}
695    is invoked to pack the control vector
696    (cf. Section \ref{section_ctrl}).
697    If gradient checks are to be performed, the option
698    {\tt ALLOW\_GRADIENT\_CHECK} is defined. In this case
699    the driver routine {\it grdchk\_main} is called after
700    the gradient has been computed via the adjoint
701    (cf. Section \ref{section_grdchk}).
702    
703    \subsection{The cost function (dependent variable)
704    \label{section_cost}}
705    
706  The cost function $ {\cal J} $ is referred to as the {\sf dependent variable}.  The cost function $ {\cal J} $ is referred to as the {\sf dependent variable}.
707  It is a function of the input variables $ \vec{u} $ via the composition  It is a function of the input variables $ \vec{u} $ via the composition
# Line 1076  $ {\cal J}(\vec{u}) \, = \, {\cal J}(M(\ Line 709  $ {\cal J}(\vec{u}) \, = \, {\cal J}(M(\
709  The input is referred to as the  The input is referred to as the
710  {\sf independent variables} or {\sf control variables}.  {\sf independent variables} or {\sf control variables}.
711  All aspects relevant to the treatment of the cost function $ {\cal J} $  All aspects relevant to the treatment of the cost function $ {\cal J} $
712  (parameter setting, initialisation, incrementation,  (parameter setting, initialization, accumulation,
713  final evaluation), are controled by the package {\it pkg/cost}.  final evaluation), are controlled by the package {\it pkg/cost}.
714    
715    \input{part5/doc_cost_flow}
716    
717  \subsubsection{genmake and CPP options}  \subsubsection{genmake and CPP options}
718  %  %
# Line 1097  compile list in 3 different ways (cf. Se Line 732  compile list in 3 different ways (cf. Se
732  \begin{enumerate}  \begin{enumerate}
733  %  %
734  \item {\it genmake}: \\  \item {\it genmake}: \\
735  Change the default settngs in the file {\it genmake} by adding  Change the default settings in the file {\it genmake} by adding
736  {\bf cost} to the {\bf enable} list (not recommended).  {\bf cost} to the {\bf enable} list (not recommended).
737  %  %
738  \item {\it .genmakerc}: \\  \item {\it .genmakerc}: \\
# Line 1110  Call {\it genmake} with the option Line 745  Call {\it genmake} with the option
745  {\tt genmake -enable=cost}.  {\tt genmake -enable=cost}.
746  %  %
747  \end{enumerate}  \end{enumerate}
 Since the cost function is usually used in conjunction with  
 automatic differentiation, the CPP option  
 {\bf ALLOW\_ADJOINT\_RUN} should be defined  
 (file {\it CPP\_OPTIONS.h}).  
748  The basic CPP option to enable the cost function is {\bf ALLOW\_COST}.  The basic CPP option to enable the cost function is {\bf ALLOW\_COST}.
749  Each specific cost function contribution has its own option.  Each specific cost function contribution has its own option.
750  For the present example the option is {\bf ALLOW\_COST\_TRACER}.  For the present example the option is {\bf ALLOW\_COST\_TRACER}.
751  All cost-specific options are set in {\it ECCO\_CPPOPTIONS.h}  All cost-specific options are set in {\it ECCO\_CPPOPTIONS.h}
752    Since the cost function is usually used in conjunction with
753    automatic differentiation, the CPP option
754    {\bf ALLOW\_ADJOINT\_RUN} should be defined
755    (file {\it CPP\_OPTIONS.h}).
756    
757  \subsubsection{Initialisation}  \subsubsection{Initialization}
758  %  %
759  The initialisation of the {\it cost} package is readily enabled  The initialization of the {\it cost} package is readily enabled
760  as soon as the CPP option {\bf ALLOW\_ADJOINT\_RUN} is defined.  as soon as the CPP option {\bf ALLOW\_ADJOINT\_RUN} is defined.
761  %  %
762  \begin{itemize}  \begin{itemize}
# Line 1152  Variables: {\it cost\_init} Line 787  Variables: {\it cost\_init}
787  }  }
788  \\  \\
789  This S/R  This S/R
790  initialises the different cost function contributions.  initializes the different cost function contributions.
791  The contribtion for the present example is {\bf objf\_tracer}  The contribution for the present example is {\bf objf\_tracer}
792  which is defined on each tile (bi,bj).  which is defined on each tile (bi,bj).
793  %  %
794  \end{itemize}  \end{itemize}
795  %  %
796  \subsubsection{Incrementation}  \subsubsection{Accumulation}
797  %  %
798  \begin{itemize}  \begin{itemize}
799  %  %
# Line 1206  The total cost function {\bf fc} will be Line 841  The total cost function {\bf fc} will be
841  tamc -output 'fc' ...  tamc -output 'fc' ...
842  \end{verbatim}  \end{verbatim}
843    
844  \begin{figure}[t!]  %%%% \end{document}
 \input{part5/doc_ad_the_model}  
 \label{fig:adthemodel}  
 \caption{~}  
 \end{figure}  
845    
 \begin{figure}  
846  \input{part5/doc_ad_the_main}  \input{part5/doc_ad_the_main}
 \label{fig:adthemain}  
 \caption{~}  
 \end{figure}  
847    
848  \subsection{The control variables (independent variables)}  \subsection{The control variables (independent variables)
849    \label{section_ctrl}}
850    
851  The control variables are a subset of the model input  The control variables are a subset of the model input
852  (initial conditions, boundary conditions, model parameters).  (initial conditions, boundary conditions, model parameters).
853  Here we identify them with the variable $ \vec{u} $.  Here we identify them with the variable $ \vec{u} $.
854  All intermediate variables whose derivative w.r.t. control  All intermediate variables whose derivative w.r.t. control
855  variables don't vanish are called {\sf active variables}.  variables do not vanish are called {\sf active variables}.
856  All subroutines whose derivative w.r.t. the control variables  All subroutines whose derivative w.r.t. the control variables
857  don't vanish are called {\sf active routines}.  don't vanish are called {\sf active routines}.
858  Read and write operations from and to file can be viewed  Read and write operations from and to file can be viewed
# Line 1232  as variable assignments. Therefore, file Line 860  as variable assignments. Therefore, file
860  active variables are written and from which active variables  active variables are written and from which active variables
861  are read are called {\sf active files}.  are read are called {\sf active files}.
862  All aspects relevant to the treatment of the control variables  All aspects relevant to the treatment of the control variables
863  (parameter setting, initialisation, perturbation)  (parameter setting, initialization, perturbation)
864  are controled by the package {\it pkg/ctrl}.  are controlled by the package {\it pkg/ctrl}.
865    
866    \input{part5/doc_ctrl_flow}
867    
868  \subsubsection{genmake and CPP options}  \subsubsection{genmake and CPP options}
869  %  %
# Line 1253  To enable the directory to be included t Line 883  To enable the directory to be included t
883  Each control variable is enabled via its own CPP option  Each control variable is enabled via its own CPP option
884  in {\it ECCO\_CPPOPTIONS.h}.  in {\it ECCO\_CPPOPTIONS.h}.
885    
886  \subsubsection{Initialisation}  \subsubsection{Initialization}
887  %  %
888  \begin{itemize}  \begin{itemize}
889  %  %
# Line 1293  Two important issues related to the hand Line 923  Two important issues related to the hand
923  variables in the MITGCM need to be addressed.  variables in the MITGCM need to be addressed.
924  First, in order to save memory, the control variable arrays  First, in order to save memory, the control variable arrays
925  are not kept in memory, but rather read from file and added  are not kept in memory, but rather read from file and added
926  to the initial (or first guess) fields.  to the initial fields during the model initialization phase.
927  Similarly, the corresponding adjoint fields which represent  Similarly, the corresponding adjoint fields which represent
928  the gradient of the cost function w.r.t. the control variables  the gradient of the cost function w.r.t. the control variables
929  are written to to file.  are written to file at the end of the adjoint integration.
930  Second, in addition to the files holding the 2-dim. and 3-dim.  Second, in addition to the files holding the 2-dim. and 3-dim.
931  control variables and the gradient, a 1-dim. {\sf control vector}  control variables and the corresponding cost gradients,
932    a 1-dim. {\sf control vector}
933  and {\sf gradient vector} are written to file. They contain  and {\sf gradient vector} are written to file. They contain
934  only the wet points of the control variables and the corresponding  only the wet points of the control variables and the corresponding
935  gradient.  gradient.
936  This leads to a significant data compression.  This leads to a significant data compression.
937  Furthermore, the control and the gradient vector can be passed to a  Furthermore, an option is available
938    ({\tt ALLOW\_NONDIMENSIONAL\_CONTROL\_IO}) to
939    non-dimensionalise the control and gradient vector,
940    which otherwise would contain different pieces of different
941    magnitudes and units.
942    Finally, the control and gradient vector can be passed to a
943  minimization routine if an update of the control variables  minimization routine if an update of the control variables
944  is sought as part of a minimization exercise.  is sought as part of a minimization exercise.
945    
# Line 1314  and gradient are generated and initialis Line 950  and gradient are generated and initialis
950    
951  \subsubsection{Perturbation of the independent variables}  \subsubsection{Perturbation of the independent variables}
952  %  %
953  The dependency chain for differentiation starts  The dependency flow for differentiation w.r.t. the controls
954  with adding a perturbation onto the the input variable,  starts with adding a perturbation onto the input variable,
955  thus defining the independent or control variables for TAMC.  thus defining the independent or control variables for TAMC.
956  Three classes of controls may be considered:  Three types of controls may be considered:
957  %  %
958  \begin{itemize}  \begin{itemize}
959  %  %
# Line 1332  Three classes of controls may be conside Line 968  Three classes of controls may be conside
968  Consider as an example the initial tracer distribution  Consider as an example the initial tracer distribution
969  {\bf tr1} as control variable.  {\bf tr1} as control variable.
970  After {\bf tr1} has been initialised in  After {\bf tr1} has been initialised in
971  {\it ini\_tr1} (dynamical variables including  {\it ini\_tr1} (dynamical variables such as
972  temperature and salinity are initialised in {\it ini\_fields}),  temperature and salinity are initialised in {\it ini\_fields}),
973  a perturbation anomaly is added to the field in S/R  a perturbation anomaly is added to the field in S/R
974  {\it ctrl\_map\_ini}  {\it ctrl\_map\_ini}
# Line 1345  u         & = \, u_{[0]} \, + \, \Delta Line 981  u         & = \, u_{[0]} \, + \, \Delta
981  \end{split}  \end{split}
982  \end{equation}  \end{equation}
983  %  %
984  In principle {\bf xx\_tr1} is a 3-dim. global array  {\bf xx\_tr1} is a 3-dim. global array
985  holding the perturbation. In the case of a simple  holding the perturbation. In the case of a simple
986  sensitivity study this array is identical to zero.  sensitivity study this array is identical to zero.
987  However, it's specification is essential since TAMC  However, it's specification is essential in the context
988    of automatic differentiation since TAMC
989  treats the corresponding line in the code symbolically  treats the corresponding line in the code symbolically
990  when determining the differentiation chain and its origin.  when determining the differentiation chain and its origin.
991  Thus, the variable names are part of the argument list  Thus, the variable names are part of the argument list
# Line 1366  dummy variable {\bf xx\_tr1\_dummy} is i Line 1003  dummy variable {\bf xx\_tr1\_dummy} is i
1003  and an 'active read' routine of the adjoint support  and an 'active read' routine of the adjoint support
1004  package {\it pkg/autodiff} is invoked.  package {\it pkg/autodiff} is invoked.
1005  The read-procedure is tagged with the variable  The read-procedure is tagged with the variable
1006  {\bf xx\_tr1\_dummy} enabbling TAMC to recognize the  {\bf xx\_tr1\_dummy} enabling TAMC to recognize the
1007  initialisation of the perturbation.  initialization of the perturbation.
1008  The modified call of TAMC thus reads  The modified call of TAMC thus reads
1009  %  %
1010  \begin{verbatim}  \begin{verbatim}
# Line 1388  Note, that reading an active variable co Line 1025  Note, that reading an active variable co
1025  to a variable assignment. Its derivative corresponds  to a variable assignment. Its derivative corresponds
1026  to a write statement of the adjoint variable.  to a write statement of the adjoint variable.
1027  The 'active file' routines have been designed  The 'active file' routines have been designed
1028  to support active read and corresponding active write  to support active read and corresponding adjoint active write
1029  operations.  operations (and vice versa).
1030  %  %
1031  \item  \item
1032  \fbox{  \fbox{
# Line 1406  with the symbolic perturbation taking pl Line 1043  with the symbolic perturbation taking pl
1043  Note however an important difference:  Note however an important difference:
1044  Since the boundary values are time dependent with a new  Since the boundary values are time dependent with a new
1045  forcing field applied at each time steps,  forcing field applied at each time steps,
1046  the general problem may be be thought of as  the general problem may be thought of as
1047  a new control variable at each time step, i.e.  a new control variable at each time step
1048    (or, if the perturbation is averaged over a certain period,
1049    at each $ N $ timesteps), i.e.
1050  \[  \[
1051  u_{\rm forcing} \, = \,  u_{\rm forcing} \, = \,
1052  \{ \, u_{\rm forcing} ( t_n ) \, \}_{  \{ \, u_{\rm forcing} ( t_n ) \, \}_{
# Line 1432  calendar ({\it cal}~) and external forci Line 1071  calendar ({\it cal}~) and external forci
1071  %  %
1072  This routine is not yet implemented, but would proceed  This routine is not yet implemented, but would proceed
1073  proceed along the same lines as the initial value sensitivity.  proceed along the same lines as the initial value sensitivity.
1074    The mixing parameters {\bf diffkr} and {\bf kapgm}
1075    are currently added as controls in {\it ctrl\_map\_ini.F}.
1076  %  %
1077  \end{itemize}  \end{itemize}
1078  %  %
1079    
1080  \subsubsection{Output of adjoint variables and gradient}  \subsubsection{Output of adjoint variables and gradient}
1081  %  %
1082  Two ways exist to generate output of adjoint fields.  Several ways exist to generate output of adjoint fields.
1083  %  %
1084  \begin{itemize}  \begin{itemize}
1085  %  %
1086  \item  \item
1087  \fbox{  \fbox{
1088  \begin{minipage}{12cm}  \begin{minipage}{12cm}
1089  {\it ctrl\_pack}:  {\it ctrl\_map\_ini, ctrl\_map\_forcing}:
1090  \end{minipage}  \end{minipage}
1091  }  }
1092  \\  \\
 At the end of the forward/adjoint integration, the S/R  
 {\it ctrl\_pack} is called which mirrors S/R {\it ctrl\_unpack}.  
 It writes the following files:  
 %  
1093  \begin{itemize}  \begin{itemize}
1094  %  %
1095  \item {\bf xx\_...}: the control variable fields  \item {\bf xx\_...}: the control variable fields \\
1096    Before the forward integration, the control
1097    variables are read from file {\bf xx\_ ...} and added to
1098    the model field.
1099  %  %
1100  \item {\bf adxx\_...}: the adjoint variable fields, i.e. the gradient  \item {\bf adxx\_...}: the adjoint variable fields, i.e. the gradient
1101  $ \nabla _{u}{\cal J} $ for each control variable,  $ \nabla _{u}{\cal J} $ for each control variable \\
1102    After the adjoint integration the corresponding adjoint
1103    variables are written to {\bf adxx\_ ...}.
1104    %
1105    \end{itemize}
1106    %
1107    \item
1108    \fbox{
1109    \begin{minipage}{12cm}
1110    {\it ctrl\_unpack, ctrl\_pack}:
1111    \end{minipage}
1112    }
1113    \\
1114  %  %
1115  \item {\bf vector\_ctrl}: the control vector  \begin{itemize}
1116  %  %
1117  \item {\bf vector\_grad}: the gradient vector  \item {\bf vector\_ctrl}: the control vector \\
1118    At the very beginning of the model initialization,
1119    the updated compressed control vector is read (or initialised)
1120    and distributed to 2-dim. and 3-dim. control variable fields.
1121    %
1122    \item {\bf vector\_grad}: the gradient vector \\
1123    At the very end of the adjoint integration,
1124    the 2-dim. and 3-dim. adjoint variables are read,
1125    compressed to a single vector and written to file.
1126  %  %
1127  \end{itemize}  \end{itemize}
1128  %  %
# Line 1474  $ \nabla _{u}{\cal J} $ for each control Line 1134  $ \nabla _{u}{\cal J} $ for each control
1134  }  }
1135  \\  \\
1136  In addition to writing the gradient at the end of the  In addition to writing the gradient at the end of the
1137  forward/adjoint integration, many more adjoint variables,  forward/adjoint integration, many more adjoint variables
1138  representing the Lagrange multipliers of the model state  of the model state
1139  w.r.t. the model state  at intermediate times can be written using S/R
 at different times can be written using S/R  
1140  {\it addummy\_in\_stepping}.  {\it addummy\_in\_stepping}.
1141  This routine is part of the adjoint support package  This routine is part of the adjoint support package
1142  {\it pkg/autodiff} (cf.f. below).  {\it pkg/autodiff} (cf.f. below).
# Line 1491  than generated automatically. Line 1150  than generated automatically.
1150  Appropriate flow directives ({\it dummy\_in\_stepping.flow})  Appropriate flow directives ({\it dummy\_in\_stepping.flow})
1151  ensure that TAMC does not automatically  ensure that TAMC does not automatically
1152  generate {\it addummy\_in\_stepping} by trying to differentiate  generate {\it addummy\_in\_stepping} by trying to differentiate
1153  {\it dummy\_in\_stepping}, but rather takes the hand-written routine.  {\it dummy\_in\_stepping}, but instead refers to
1154    the hand-written routine.
1155    
1156  {\it dummy\_in\_stepping} is called in the forward code  {\it dummy\_in\_stepping} is called in the forward code
1157  at the beginning of each  at the beginning of each
# Line 1501  each timestep in the adjoint calculation Line 1161  each timestep in the adjoint calculation
1161  {\it addynamics}.  {\it addynamics}.
1162    
1163  {\it addummy\_in\_stepping} includes the header files  {\it addummy\_in\_stepping} includes the header files
1164  {\it adffields.h, addynamics.h, adtr1.h}.  {\it adcommon.h}.
1165  These header files are also hand-written. They contain  This header file is also hand-written. It contains
1166  the common blocks {\bf /addynvars\_r/}, {\bf /addynvars\_cd/},  the common blocks
1167    {\bf /addynvars\_r/}, {\bf /addynvars\_cd/},
1168    {\bf /addynvars\_diffkr/}, {\bf /addynvars\_kapgm/},
1169  {\bf /adtr1\_r/}, {\bf /adffields/},  {\bf /adtr1\_r/}, {\bf /adffields/},
1170  which have been extracted from the adjoint code to enable  which have been extracted from the adjoint code to enable
1171  access to the adjoint variables.  access to the adjoint variables.
# Line 1521  The gradient $ \nabla _{u}{\cal J} |_{u_ Line 1183  The gradient $ \nabla _{u}{\cal J} |_{u_
1183  with the value of the cost function itself $ {\cal J}(u_{[k]}) $  with the value of the cost function itself $ {\cal J}(u_{[k]}) $
1184  at iteration step $ k $ serve  at iteration step $ k $ serve
1185  as input to a minimization routine (e.g. quasi-Newton method,  as input to a minimization routine (e.g. quasi-Newton method,
1186  conjugate gradient, ...) to compute an update in the  conjugate gradient, ... \cite{gil-lem:89})
1187    to compute an update in the
1188  control variable for iteration step $k+1$  control variable for iteration step $k+1$
1189  \[  \[
1190  u_{[k+1]} \, = \,  u_{[0]} \, + \, \Delta u_{[k+1]}  u_{[k+1]} \, = \,  u_{[0]} \, + \, \Delta u_{[k+1]}
# Line 1535  Tab. \ref{???} sketches the flow between Line 1198  Tab. \ref{???} sketches the flow between
1198  and the minimization routine.  and the minimization routine.
1199    
1200  \begin{eqnarray*}  \begin{eqnarray*}
1201  \footnotesize  \scriptsize
1202  \begin{array}{ccccc}  \begin{array}{ccccc}
1203  u_{[0]} \,\, ,  \,\, \Delta u_{[k]}    & ~ & ~ & ~ & ~ \\  u_{[0]} \,\, ,  \,\, \Delta u_{[k]}    & ~ & ~ & ~ & ~ \\
1204  {\Big\downarrow}  {\Big\downarrow}
# Line 1552  v_{[k]} = M \left( u_{[k]} \right) & Line 1215  v_{[k]} = M \left( u_{[k]} \right) &
1215  {\cal J}_{[k]} = {\cal J} \left( M \left( u_{[k]} \right) \right)} \\  {\cal J}_{[k]} = {\cal J} \left( M \left( u_{[k]} \right) \right)} \\
1216  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\
1217  \hline  \hline
1218    \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~}  \\
1219    \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{{\Big\downarrow}} \\
1220    \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~}  \\
1221  \hline  \hline
1222  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\
1223  \multicolumn{1}{|c}{  \multicolumn{1}{|c}{
1224  \nabla_u {\cal J}_{[k]} (\delta {\cal J}) =  \nabla_u {\cal J}_{[k]} (\delta {\cal J}) =
1225  T\!\!^{\ast} \cdot \nabla_v {\cal J} |_{v_{[k]}} (\delta {\cal J})} &  T^{\ast} \cdot \nabla_v {\cal J} |_{v_{[k]}} (\delta {\cal J})} &
1226  \stackrel{\bf adjoint}{\mathbf \longleftarrow} &  \stackrel{\bf adjoint}{\mathbf \longleftarrow} &
1227  ad \, v_{[k]} (\delta {\cal J}) =  ad \, v_{[k]} (\delta {\cal J}) =
1228  \nabla_v {\cal J} |_{v_{[k]}} (\delta {\cal J}) &  \nabla_v {\cal J} |_{v_{[k]}} (\delta {\cal J}) &
# Line 1565  ad \, v_{[k]} (\delta {\cal J}) = Line 1231  ad \, v_{[k]} (\delta {\cal J}) =
1231  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\
1232  \hline  \hline
1233   ~ & ~ & ~ & ~ & ~ \\   ~ & ~ & ~ & ~ & ~ \\
1234  ~ & ~ &  \hspace*{15ex}{\Bigg\downarrow}  
1235  {\cal J}_{[k]} \qquad {\Bigg\downarrow}  \qquad \nabla_u {\cal J}_{[k]}  \quad {\cal J}_{[k]}, \quad \nabla_u {\cal J}_{[k]}
1236   & ~ & ~ \\   & ~ & ~ & ~ & ~ \\
1237   ~ & ~ & ~ & ~ & ~ \\   ~ & ~ & ~ & ~ & ~ \\
1238  \hline  \hline
1239  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\  \multicolumn{1}{|c}{~} & ~ & ~ & ~ & \multicolumn{1}{c|}{~} \\
# Line 1595  The corresponding I/O flow looks as foll Line 1261  The corresponding I/O flow looks as foll
1261    
1262  \vspace*{0.5cm}  \vspace*{0.5cm}
1263    
1264    {\scriptsize
1265  \begin{tabular}{ccccc}  \begin{tabular}{ccccc}
1266  {\bf vector\_ctrl\_$<$k$>$ } & ~ & ~ & ~ & ~ \\  {\bf vector\_ctrl\_$<$k$>$ } & ~ & ~ & ~ & ~ \\
1267  {\big\downarrow}  & ~ & ~ & ~ & ~ \\  {\big\downarrow}  & ~ & ~ & ~ & ~ \\
# Line 1605  The corresponding I/O flow looks as foll Line 1272  The corresponding I/O flow looks as foll
1272  \cline{3-3}  \cline{3-3}
1273  \multicolumn{1}{l}{\bf xx\_theta0...$<$k$>$} & ~ &  \multicolumn{1}{l}{\bf xx\_theta0...$<$k$>$} & ~ &
1274  \multicolumn{1}{|c|}{~} & ~ & ~ \\  \multicolumn{1}{|c|}{~} & ~ & ~ \\
1275  \multicolumn{1}{l}{\bf xx\_salt0...$<$k$>$} & $\longrightarrow$ &  \multicolumn{1}{l}{\bf xx\_salt0...$<$k$>$} &
1276    $\stackrel{\mbox{read}}{\longrightarrow}$ &
1277  \multicolumn{1}{|c|}{forward integration} & ~ & ~ \\  \multicolumn{1}{|c|}{forward integration} & ~ & ~ \\
1278  \multicolumn{1}{l}{\bf \vdots} & ~ & \multicolumn{1}{|c|}{~}    \multicolumn{1}{l}{\bf \vdots} & ~ & \multicolumn{1}{|c|}{~}  
1279  & ~ & ~ \\  & ~ & ~ \\
1280  \cline{3-3}  \cline{3-3}
1281  ~ & ~ & ~ & ~ & ~ \\  ~ & ~ & $\downarrow$ & ~ & ~ \\
1282  \cline{3-3}  \cline{3-3}
1283  ~ & ~ &  ~ & ~ &
1284  \multicolumn{1}{|c|}{~} & ~ &  \multicolumn{1}{|c|}{~} & ~ &
1285  \multicolumn{1}{l}{\bf adxx\_theta0...$<$k$>$}  \\  \multicolumn{1}{l}{\bf adxx\_theta0...$<$k$>$}  \\
1286  ~ & ~ & \multicolumn{1}{|c|}{adjoint integration} &  ~ & ~ & \multicolumn{1}{|c|}{adjoint integration} &
1287  $\longrightarrow$ &  $\stackrel{\mbox{write}}{\longrightarrow}$ &
1288  \multicolumn{1}{l}{\bf adxx\_salt0...$<$k$>$} \\  \multicolumn{1}{l}{\bf adxx\_salt0...$<$k$>$} \\
1289  ~ & ~ & \multicolumn{1}{|c|}{~}    ~ & ~ & \multicolumn{1}{|c|}{~}  
1290  & ~ & \multicolumn{1}{l}{\bf \vdots} \\  & ~ & \multicolumn{1}{l}{\bf \vdots} \\
# Line 1628  $\longrightarrow$ & Line 1296  $\longrightarrow$ &
1296  ~ & ~ & ~ & ~ &  {\big\downarrow} \\  ~ & ~ & ~ & ~ &  {\big\downarrow} \\
1297  ~ & ~ & ~ & ~ &  {\bf vector\_grad\_$<$k$>$ } \\  ~ & ~ & ~ & ~ &  {\bf vector\_grad\_$<$k$>$ } \\
1298  \end{tabular}  \end{tabular}
1299    }
1300    
1301  \vspace*{0.5cm}  \vspace*{0.5cm}
1302    
1303    
1304  {\it ctrl\_unpack} reads in the updated control vector  {\it ctrl\_unpack} reads the updated control vector
1305  {\bf vector\_ctrl\_$<$k$>$}.  {\bf vector\_ctrl\_$<$k$>$}.
1306  It distributes the different control variables to  It distributes the different control variables to
1307  2-dim. and 3-dim. files {\it xx\_...$<$k$>$}.  2-dim. and 3-dim. files {\it xx\_...$<$k$>$}.
1308  During the forward integration the control variables  At the start of the forward integration the control variables
1309  are read from {\it xx\_...$<$k$>$}.  are read from {\it xx\_...$<$k$>$} and added to the
1310  Correspondingly, the adjoint fields are written  field.
1311    Correspondingly, at the end of the adjoint integration
1312    the adjoint fields are written
1313  to {\it adxx\_...$<$k$>$}, again via the active file routines.  to {\it adxx\_...$<$k$>$}, again via the active file routines.
1314  Finally, {\it ctrl\_pack} collects all adjoint field files  Finally, {\it ctrl\_pack} collects all adjoint files
1315  and writes them to the compressed vector file  and writes them to the compressed vector file
1316  {\bf vector\_grad\_$<$k$>$}.  {\bf vector\_grad\_$<$k$>$}.
   
 \subsection{TLM and ADM generation via TAMC}  
   
   
   
 \subsection{Flow directives and adjoint support routines}  
   
 \subsection{Store directives and checkpointing}  
   
 \subsection{Gradient checks}  
   
 \subsection{Second derivative generation via TAMC}  
   
 \section{Example of adjoint code}  

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.22