New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Chap_MISC.tex in branches/2010_and_older/DEV_r2460_v3_3beta_NOL/DOC/TexFiles/Chapters – NEMO

source: branches/2010_and_older/DEV_r2460_v3_3beta_NOL/DOC/TexFiles/Chapters/Chap_MISC.tex @ 4551

Last change on this file since 4551 was 2414, checked in by gm, 14 years ago

v3.3beta: #658 Documentation phasing with the 3.3 - C1D & other minor staff

  • Property svn:executable set to *
File size: 68.9 KB
Line 
1% ================================================================
2% Chapter Ñ Miscellaneous Topics
3% ================================================================
4\chapter{Miscellaneous Topics}
5\label{MISC}
6\minitoc
7
8\newpage
9$\ $\newline    % force a new ligne
10
11% ================================================================
12% Representation of Unresolved Straits
13% ================================================================
14\section{Representation of Unresolved Straits}
15\label{MISC_strait}
16
17In climate modeling, it often occurs that a crucial connections between water masses
18is broken as the grid mesh is too coarse to resolve narrow straits. For example, coarse
19grid spacing typically closes off the Mediterranean from the Atlantic at the Strait of
20Gibraltar. In this case, it is important for climate models to include the effects of salty
21water entering the Atlantic from the Mediterranean. Likewise, it is important for the
22Mediterranean to replenish its supply of water from the Atlantic to balance the net
23evaporation occurring over the Mediterranean region. This problem occurs even in
24eddy permitting simulations. For example, in ORCA 1/4\deg several straits of the Indonesian
25archipelago (Ombai, Lombok...) are much narrow than even a single ocean grid-point.
26
27We describe briefly here the three methods that can be used in \NEMO to handle
28such improperly resolved straits. The first two consist of opening the strait by hand
29while ensuring that the mass exchanges through the strait are not too large by
30either artificially reducing the surface of the strait grid-cells or, locally increasing
31the lateral friction. In the third one, the strait is closed but exchanges of mass,
32heat and salt across the land are allowed.
33Note that such modifications are so specific to a given configuration that no attempt
34has been made to set them in a generic way. However, examples of how
35they can be set up is given in the ORCA 2\deg and 0.5\deg configurations (search for
36\key{orca\_r2} or \key{orca\_r05} in the code).
37
38% -------------------------------------------------------------------------------------------------------------
39%       Hand made geometry changes
40% -------------------------------------------------------------------------------------------------------------
41\subsection{Hand made geometry changes}
42\label{MISC_strait_hand}
43
44$\bullet$ reduced scale factor in the cross-strait direction to a value in better agreement
45with the true mean width of the strait. (Fig.~\ref{Fig_MISC_strait_hand}).
46This technique is sometime called "partially open face" or "partially closed cells".
47The key issue here is only to reduce the faces of $T$-cell ($i.e.$ change the value
48of the horizontal scale factors at $u$- or $v$-point) but not the volume of the $T$-cell.
49Indeed, reducing the volume of strait $T$-cell can easily produce a numerical
50instability at that grid point that would require a reduction of the model time step.
51The changes associated with strait management are done in \mdl{domhgr},
52just after the definition or reading of the horizontal scale factors.
53
54$\bullet$ increase of the viscous boundary layer thickness by local increase of the
55fmask value at the coast (Fig.~\ref{Fig_MISC_strait_hand}). This is done in
56\mdl{dommsk} together with the setting of the coastal value of fmask
57(see Section \ref{LBC_coast})
58
59%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
60\begin{figure}[!tbp]     \begin{center}
61\includegraphics[width=0.80\textwidth]{./TexFiles/Figures/Fig_Gibraltar.pdf}
62\includegraphics[width=0.80\textwidth]{./TexFiles/Figures/Fig_Gibraltar2.pdf}
63\caption{   \label{Fig_MISC_strait_hand} 
64Example of the Gibraltar strait defined in a $1\deg \times 1\deg$ mesh.
65\textit{Top}: using partially open cells. The meridional scale factor at $v$-point
66is reduced on both sides of the strait to account for the real width of the strait
67(about 20 km). Note that the scale factors of the strait $T$-point remains unchanged.
68\textit{Bottom}: using viscous boundary layers. The four fmask parameters
69along the strait coastlines are set to a value larger than 4, $i.e.$ "strong" no-slip
70case (see Fig.\ref{Fig_LBC_shlat}) creating a large viscous boundary layer
71that allows a reduced transport through the strait.}
72\end{center}   \end{figure}
73%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
74
75% -------------------------------------------------------------------------------------------------------------
76% Cross Land Advection
77% -------------------------------------------------------------------------------------------------------------
78\subsection{Cross Land Advection (\mdl{tracla})}
79\label{MISC_strait_cla}
80%--------------------------------------------namcla--------------------------------------------------------
81\namdisplay{namcla} 
82%--------------------------------------------------------------------------------------------------------------
83
84\colorbox{yellow}{Add a short description of CLA staff here or in lateral boundary condition chapter?}
85
86%The problem is resolved here by allowing the mixing of tracers and mass/volume between non-adjacent water columns at nominated regions within the model. Momentum is not mixed. The scheme conserves total tracer content, and total volume (the latter in $z*$- or $s*$-coordinate), and maintains compatibility between the tracer and mass/volume budgets. 
87
88% ================================================================
89% Closed seas
90% ================================================================
91\section{Closed seas (\mdl{closea})}
92\label{MISC_closea}
93
94\colorbox{yellow}{Add here a short description of the way closed seas are managed}
95
96
97% ================================================================
98% Sub-Domain Functionality (\textit{nizoom, njzoom}, namelist parameters)
99% ================================================================
100\section{Sub-Domain Functionality (\jp{jpizoom}, \jp{jpjzoom})}
101\label{MISC_zoom}
102
103The sub-domain functionality, also improperly called the zoom option
104(improperly because it is not associated with a change in model resolution)
105is a quite simple function that allows a simulation over a sub-domain of an
106already defined configuration ($i.e.$ without defining a new mesh, initial
107state and forcings). This option can be useful for testing the user settings
108of surface boundary conditions, or the initial ocean state of a huge ocean
109model configuration while having a small computer memory requirement.
110It can also be used to easily test specific physics in a sub-domain (for example,
111see \citep{Madec_al_JPO96} for a test of the coupling used in the global ocean
112version of OPA between sea-ice and ocean model over the Arctic or Antarctic
113ocean, using a sub-domain). In the standard model, this option does not
114include any specific treatment for the ocean boundaries of the sub-domain:
115they are considered as artificial vertical walls. Nevertheless, it is quite easy
116to add a restoring term toward a climatology in the vicinity of such boundaries
117(see \S\ref{TRA_dmp}).
118
119In order to easily define a sub-domain over which the computation can be
120performed, the dimension of all input arrays (ocean mesh, bathymetry,
121forcing, initial state, ...) are defined as \jp{jpidta}, \jp{jpjdta} and \jp{jpkdta} 
122(\mdl{par\_oce} module), while the computational domain is defined through
123\jp{jpiglo}, \jp{jpjglo} and \jp{jpk} (\mdl{par\_oce} module). When running the
124model over the whole domain, the user sets \jp{jpiglo}=\jp{jpidta} \jp{jpjglo}=\jp{jpjdta} 
125and \jp{jpk}=\jp{jpkdta}. When running the model over a sub-domain, the user
126has to provide the size of the sub-domain, (\jp{jpiglo}, \jp{jpjglo}, \jp{jpkglo}),
127and the indices of the south western corner as \jp{jpizoom} and \jp{jpjzoom} in
128the \mdl{par\_oce} module (Fig.~\ref{Fig_LBC_zoom}).
129
130Note that a third set of dimensions exist, \jp{jpi}, \jp{jpj} and \jp{jpk} which is
131actually used to perform the computation. It is set by default to \jp{jpi}=\jp{jpjglo} 
132and \jp{jpj}=\jp{jpjglo}, except for massively parallel computing where the
133computational domain is laid out on local processor memories following a 2D
134horizontal splitting. % (see {\S}IV.2-c) ref to the section to be updated
135
136%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
137\begin{figure}[!ht]    \begin{center}
138\includegraphics[width=0.90\textwidth]{./TexFiles/Figures/Fig_LBC_zoom.pdf}
139\caption{   \label{Fig_LBC_zoom}
140Position of a model domain compared to the data input domain when the zoom functionality is used.}
141\end{center}   \end{figure}
142%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
143
144
145% ================================================================
146% Accelerating the Convergence
147% ================================================================
148\section{Accelerating the Convergence (\np{nn\_acc} = 1)}
149\label{MISC_acc}
150%--------------------------------------------namdom-------------------------------------------------------
151\namdisplay{namdom} 
152%--------------------------------------------------------------------------------------------------------------
153
154Searching an equilibrium state with an global ocean model requires a very long time
155integration period (a few thousand years for a global model). Due to the size of
156the time step required for numerical stability (less than a few hours),
157this usually requires a large elapsed time. In order to overcome this problem,
158\citet{Bryan1984} introduces a technique that is intended to accelerate
159the spin up to equilibrium. It uses a larger time step in
160the tracer evolution equations than in the momentum evolution
161equations. It does not affect the equilibrium solution but modifies the
162trajectory to reach it.
163
164The acceleration of convergence option is used when \np{nn\_acc}=1. In that case,
165$\rdt=rn\_rdt$ is the time step of dynamics while $\widetilde{\rdt}=rdttra$ is the
166tracer time-step. the former is set from the \np{rn\_rdt} namelist parameter while the latter
167is computed using a hyperbolic tangent profile and the following namelist parameters :
168\np{rn\_rdtmin}, \np{rn\_rdtmax} and \np{rn\_rdth}. Those three parameters correspond
169to the surface value the deep ocean value and the depth at which the transition occurs, respectively.
170The set of prognostic equations to solve becomes:
171\begin{equation} \label{Eq_acc}
172\begin{split}
173\frac{\partial \textbf{U}_h }{\partial t} 
174   &\equiv \frac{\textbf{U}_h ^{t+1}-\textbf{U}_h^{t-1} }{2\rdt} = \ldots \\ 
175\frac{\partial T}{\partial t} &\equiv \frac{T^{t+1}-T^{t-1}}{2 \widetilde{\rdt}} = \ldots \\ 
176\frac{\partial S}{\partial t} &\equiv \frac{S^{t+1} -S^{t-1}}{2 \widetilde{\rdt}} = \ldots \\ 
177\end{split}
178\end{equation}
179
180\citet{Bryan1984} has examined the consequences of this distorted physics.
181Free waves have a slower phase speed, their meridional structure is slightly
182modified, and the growth rate of baroclinically unstable waves is reduced
183but with a wider range of instability. This technique is efficient for
184searching for an equilibrium state in coarse resolution models. However its
185application is not suitable for many oceanic problems: it cannot be used for
186transient or time evolving problems (in particular, it is very questionable
187to use this technique when there is a seasonal cycle in the forcing fields),
188and it cannot be used in high-resolution models where baroclinically
189unstable processes are important. Moreover, the vertical variation of
190$\widetilde{ \rdt}$ implies that the heat and salt contents are no longer
191conserved due to the vertical coupling of the ocean level through both
192advection and diffusion. Therefore \np{rn\_rdtmin} = \np{rn\_rdtmax} should be
193a more clever choice.
194
195% ================================================================
196% Model optimisation, Control Print and Benchmark
197% ================================================================
198\section{Model Optimisation, Control Print and Benchmark}
199\label{MISC_opt}
200%--------------------------------------------namctl-------------------------------------------------------
201\namdisplay{namctl} 
202%--------------------------------------------------------------------------------------------------------------
203
204% \gmcomment{why not make these bullets into subsections?}
205
206
207$\bullet$ Vector optimisation:
208
209\key{vectopt\_loop} enables the internal loops to collapse. This is very
210a very efficient way to increase the length of vector calculations and thus
211to speed up the model on vector computers.
212 
213% Add here also one word on NPROMA technique that has been found useless, since compiler have made significant progress during the last decade.
214 
215% Add also one word on NEC specific optimisation (Novercheck option for example)
216 
217$\bullet$ Control print %: describe here 4 things:
218
2191- \np{ln\_ctl} : compute and print the trends averaged over the interior domain
220in all TRA, DYN, LDF and ZDF modules. This option is very helpful when
221diagnosing the origin of an undesired change in model results.
222
2232- also \np{ln\_ctl} but using the nictl and njctl namelist parameters to check
224the source of differences between mono and multi processor runs.
225
2263- \key{esopa} (to be rename key\_nemo) : which is another option for model
227management. When defined, this key forces the activation of all options and
228CPP keys. For example, all tracer and momentum advection schemes are called!
229Therefore the model results have no physical meaning.
230However, this option forces both the compiler and the model to run through
231all the \textsc{Fortran} lines of the model. This allows the user to check for obvious
232compilation or execution errors with all CPP options, and errors in namelist options.
233
2344- last digit comparison (\np{nn\_bit\_cmp}). In an MPP simulation, the computation of
235a sum over the whole domain is performed as the summation over all processors of
236each of their sums over their interior domains. This double sum never gives exactly
237the same result as a single sum over the whole domain, due to truncation differences.
238The "bit comparison" option has been introduced in order to be able to check that
239mono-processor and multi-processor runs give exactly the same results.
240%THIS is to be updated with the mpp_sum_glo  introduced in v3.3
241% nn_bit_cmp  today only check that the nn_cla = 0 (no cross land advection)
242
243$\bullet$  Benchmark (\np{nn\_bench}). This option defines a benchmark run based on
244a GYRE configuration (see \S\ref{CFG_gyre}) in which the resolution remains the same
245whatever the domain size. This allows a very large model domain to be used, just by
246changing the domain size (\jp{jpiglo}, \jp{jpjglo}) and without adjusting either the time-step
247or the physical parameterisations.
248
249
250% ================================================================
251% Elliptic solvers (SOL)
252% ================================================================
253\section{Elliptic solvers (SOL)}
254\label{MISC_sol}
255%--------------------------------------------namdom-------------------------------------------------------
256\namdisplay{namsol} 
257%--------------------------------------------------------------------------------------------------------------
258
259When the filtered sea surface height option is used, the surface pressure gradient is
260computed in \mdl{dynspg\_flt}. The force added in the momentum equation is solved implicitely.
261It is thus solution of an elliptic equation \eqref{Eq_PE_flt} for which two solvers are available:
262a Successive-Over-Relaxation scheme (SOR) and a preconditioned conjugate gradient
263scheme(PCG) \citep{Madec_al_OM88, Madec_PhD90}. The solver is selected trough the
264the value of \np{nn\_solv} (namelist parameter).
265
266The PCG is a very efficient method for solving elliptic equations on vector computers.
267It is a fast and rather easy method to use; which are attractive features for a large
268number of ocean situations (variable bottom topography, complex coastal geometry,
269variable grid spacing, islands, open or cyclic boundaries, etc ...). It does not require
270a search for an optimal parameter as in the SOR method. However, the SOR has
271been retained because it is a linear solver, which is a very useful property when
272using the adjoint model of \NEMO.
273
274At each time step, the time derivative of the sea surface height at time step $t+1$ 
275(or equivalently the divergence of the \textit{after} barotropic transport) that appears
276in the filtering forced is the solution of the elliptic equation obtained from the horizontal
277divergence of the vertical summation of \eqref{Eq_PE_flt}.
278Introducing the following coefficients:
279\begin{equation}  \label{Eq_sol_matrix}
280\begin{aligned}
281&c_{i,j}^{NS}  &&= {2 \rdt }^2 \; \frac{H_v (i,j) \; e_{1v} (i,j)}{e_{2v}(i,j)}              \\
282&c_{i,j}^{EW} &&= {2 \rdt }^2 \; \frac{H_u (i,j) \; e_{2u} (i,j)}{e_{1u}(i,j)}            \\
283&b_{i,j} &&= \delta_i \left[ e_{2u}M_u \right] - \delta_j \left[ e_{1v}M_v \right]\ ,   \\
284\end{aligned}
285\end{equation}
286the five-point finite difference equation \eqref{Eq_psi_total} can be rewritten as:
287\begin{equation}  \label{Eq_solmat}
288\begin{split}
289       c_{i+1,j}^{NS} D_{i+1,j}  + \;  c_{i,j+1}^{EW} D_{i,j+1}   
290  +   c_{i,j}    ^{NS} D_{i-1,j}   + \;  c_{i,j}    ^{EW} D_{i,j-1}                                          &    \\
291  -    \left(c_{i+1,j}^{NS} + c_{i,j+1}^{EW} + c_{i,j}^{NS} + c_{i,j}^{EW} \right)   D_{i,j}  &=  b_{i,j}
292\end{split}
293\end{equation}
294\eqref{Eq_solmat} is a linear symmetric system of equations. All the elements of
295the corresponding matrix \textbf{A} vanish except those of five diagonals. With
296the natural ordering of the grid points (i.e. from west to east and from
297south to north), the structure of \textbf{A} is block-tridiagonal with
298tridiagonal or diagonal blocks. \textbf{A} is a positive-definite symmetric
299matrix of size $(jpi \cdot jpj)^2$, and \textbf{B}, the right hand side of
300\eqref{Eq_solmat}, is a vector.
301
302Note that in the linear free surface case, the depth that appears in \eqref{Eq_sol_matrix}
303does not vary with time, and thus the matrix can be computed once for all. In non-linear free surface
304(\key{vvl} defined) the matrix have to be updated at each time step.
305
306% -------------------------------------------------------------------------------------------------------------
307%       Successive Over Relaxation
308% -------------------------------------------------------------------------------------------------------------
309\subsection{Successive Over Relaxation (\np{nn\_solv}=2, \mdl{solsor})}
310\label{MISC_solsor}
311
312Let us introduce the four cardinal coefficients:
313\begin{align*}
314a_{i,j}^S &= c_{i,j    }^{NS}/d_{i,j}     &\qquad  a_{i,j}^W &= c_{i,j}^{EW}/d_{i,j}       \\
315a_{i,j}^E &= c_{i,j+1}^{EW}/d_{i,j}    &\qquad   a_{i,j}^N &= c_{i+1,j}^{NS}/d_{i,j}   
316\end{align*}
317where $d_{i,j} = c_{i,j}^{NS}+ c_{i+1,j}^{NS} + c_{i,j}^{EW} + c_{i,j+1}^{EW}$ 
318(i.e. the diagonal of the matrix). \eqref{Eq_solmat} can be rewritten as:
319\begin{equation}  \label{Eq_solmat_p}
320\begin{split}
321a_{i,j}^{N}  D_{i+1,j} +\,a_{i,j}^{E}  D_{i,j+1} +\, a_{i,j}^{S}  D_{i-1,j} +\,a_{i,j}^{W} D_{i,j-1}  -  D_{i,j} = \tilde{b}_{i,j}
322\end{split}
323\end{equation}
324with $\tilde b_{i,j} = b_{i,j}/d_{i,j}$. \eqref{Eq_solmat_p} is the equation actually solved
325with the SOR method. This method used is an iterative one. Its algorithm can be
326summarised as follows (see \citet{Haltiner1980} for a further discussion):
327
328initialisation (evaluate a first guess from previous time step computations)
329\begin{equation}
330D_{i,j}^0 = 2 \, D_{i,j}^t - D_{i,j}^{t-1}
331\end{equation}
332iteration $n$, from $n=0$ until convergence, do :
333\begin{equation} \label{Eq_sor_algo}
334\begin{split}
335R_{i,j}^n  = &a_{i,j}^{N} D_{i+1,j}^n       +\,a_{i,j}^{E}  D_{i,j+1} ^n         
336         +\, a_{i,j}^{S}  D_{i-1,j} ^{n+1}+\,a_{i,j}^{W} D_{i,j-1} ^{n+1}
337                 -  D_{i,j}^n - \tilde{b}_{i,j}                                           \\
338D_{i,j} ^{n+1}  = &D_{i,j} ^{n}   + \omega \;R_{i,j}^n     
339\end{split}
340\end{equation}
341where \textit{$\omega $ }satisfies $1\leq \omega \leq 2$. An optimal value exists for
342\textit{$\omega$} which significantly accelerates the convergence, but it has to be
343adjusted empirically for each model domain (except for a uniform grid where an
344analytical expression for \textit{$\omega$} can be found \citep{Richtmyer1967}).
345The value of $\omega$ is set using \np{rn\_sor}, a \textbf{namelist} parameter.
346The convergence test is of the form:
347\begin{equation}
348\delta = \frac{\sum\limits_{i,j}{R_{i,j}^n}{R_{i,j}^n}}
349                    {\sum\limits_{i,j}{ \tilde{b}_{i,j}^n}{\tilde{b}_{i,j}^n}} \leq \epsilon
350\end{equation}
351where $\epsilon$ is the absolute precision that is required. It is recommended
352that a value smaller or equal to $10^{-6}$ is used for $\epsilon$ since larger
353values may lead to numerically induced basin scale barotropic oscillations.
354The precision is specified by setting \np{rn\_eps} (\textbf{namelist} parameter).
355In addition, two other tests are used to halt the iterative algorithm. They involve
356the number of iterations and the modulus of the right hand side. If the former
357exceeds a specified value, \np{nn\_max} (\textbf{namelist} parameter),
358or the latter is greater than $10^{15}$, the whole model computation is stopped
359and the last computed time step fields are saved in a abort.nc NetCDF file.
360In both cases, this usually indicates that there is something wrong in the model
361configuration (an error in the mesh, the initial state, the input forcing,
362or the magnitude of the time step or of the mixing coefficients). A typical value of
363$nn\_max$ is a few hundred when $\epsilon = 10^{-6}$, increasing to a few
364thousand when $\epsilon = 10^{-12}$.
365The vectorization of the SOR algorithm is not straightforward. The scheme
366contains two linear recurrences on $i$ and $j$. This inhibits the vectorisation.
367\eqref{Eq_sor_algo} can be been rewritten as:
368\begin{equation} 
369\begin{split}
370R_{i,j}^n
371= &a_{i,j}^{N}  D_{i+1,j}^n +\,a_{i,j}^{E}  D_{i,j+1} ^n
372 +\,a_{i,j}^{S}  D_{i-1,j} ^{n}+\,_{i,j}^{W} D_{i,j-1} ^{n} -  D_{i,j}^n - \tilde{b}_{i,j}      \\
373R_{i,j}^n = &R_{i,j}^n - \omega \;a_{i,j}^{S}\; R_{i,j-1}^n                                             \\
374R_{i,j}^n = &R_{i,j}^n - \omega \;a_{i,j}^{W}\; R_{i-1,j}^n
375\end{split}
376\end{equation}
377This technique slightly increases the number of iteration required to reach the convergence,
378but this is largely compensated by the gain obtained by the suppression of the recurrences.
379
380Another technique have been chosen, the so-called red-black SOR. It consist in solving successively
381\eqref{Eq_sor_algo} for odd and even grid points. It also slightly reduced the convergence rate
382but allows the vectorisation. In addition, and this is the reason why it has been chosen, it is able to handle the north fold boundary condition used in ORCA configuration ($i.e.$ tri-polar global ocean mesh).
383
384The SOR method is very flexible and can be used under a wide range of conditions,
385including irregular boundaries, interior boundary points, etc. Proofs of convergence, etc.
386may be found in the standard numerical methods texts for partial differential equations.
387
388% -------------------------------------------------------------------------------------------------------------
389%       Preconditioned Conjugate Gradient
390% -------------------------------------------------------------------------------------------------------------
391\subsection{Preconditioned Conjugate Gradient  (\np{nn\_solv}=1, \mdl{solpcg}) }
392\label{MISC_solpcg}
393
394\textbf{A} is a definite positive symmetric matrix, thus solving the linear
395system \eqref{Eq_solmat} is equivalent to the minimisation of a quadratic
396functional:
397\begin{equation*}
398\textbf{Ax} = \textbf{b} \leftrightarrow \textbf{x} =\text{inf}_{y} \,\phi (\textbf{y})
399\quad , \qquad
400\phi (\textbf{y}) = 1/2 \langle \textbf{Ay},\textbf{y}\rangle - \langle \textbf{b},\textbf{y} \rangle 
401\end{equation*}
402where $\langle , \rangle$ is the canonical dot product. The idea of the
403conjugate gradient method is to search for the solution in the following
404iterative way: assuming that $\textbf{x}^n$ has been obtained, $\textbf{x}^{n+1}$ 
405is found from $\textbf {x}^{n+1}={\textbf {x}}^n+\alpha^n{\textbf {d}}^n$ which satisfies:
406\begin{equation*}
407{\textbf{ x}}^{n+1}=\text{inf} _{{\textbf{ y}}={\textbf{ x}}^n+\alpha^n \,{\textbf{ d}}^n} \,\phi ({\textbf{ y}})\;\;\Leftrightarrow \;\;\frac{d\phi }{d\alpha}=0
408\end{equation*}
409and expressing $\phi (\textbf{y})$ as a function of \textit{$\alpha $}, we obtain the
410value that minimises the functional:
411\begin{equation*}
412\alpha ^n = \langle{ \textbf{r}^n , \textbf{r}^n} \rangle  / \langle {\textbf{ A d}^n, \textbf{d}^n} \rangle
413\end{equation*}
414where $\textbf{r}^n = \textbf{b}-\textbf{A x}^n = \textbf{A} (\textbf{x}-\textbf{x}^n)$ 
415is the error at rank $n$. The descent vector $\textbf{d}^n$ s chosen to be dependent
416on the error: $\textbf{d}^n = \textbf{r}^n + \beta^n \,\textbf{d}^{n-1}$. $\beta ^n$ 
417is searched such that the descent vectors form an orthogonal basis for the dot
418product linked to \textbf{A}. Expressing the condition
419$\langle \textbf{A d}^n, \textbf{d}^{n-1} \rangle = 0$ the value of $\beta ^n$ is found:
420 $\beta ^n = \langle{ \textbf{r}^n , \textbf{r}^n} \rangle  / \langle {\textbf{r}^{n-1}, \textbf{r}^{n-1}} \rangle$.
421 As a result, the errors $ \textbf{r}^n$ form an orthogonal
422base for the canonic dot product while the descent vectors $\textbf{d}^n$ form
423an orthogonal base for the dot product linked to \textbf{A}. The resulting
424algorithm is thus the following one:
425
426initialisation :
427\begin{equation*} 
428\begin{split}
429\textbf{x}^0 &= D_{i,j}^0   = 2 D_{i,j}^t - D_{i,j}^{t-1}       \quad, \text{the initial guess }     \\
430\textbf{r}^0 &= \textbf{d}^0 = \textbf{b} - \textbf{A x}^0       \\
431\gamma_0 &= \langle{ \textbf{r}^0 , \textbf{r}^0} \rangle
432\end{split}
433\end{equation*}
434
435iteration $n,$ from $n=0$ until convergence, do :
436\begin{equation} 
437\begin{split}
438\text{z}^n& = \textbf{A d}^n \\
439\alpha_n &= \gamma_n /  \langle{ \textbf{z}^n , \textbf{d}^n} \rangle \\
440\textbf{x}^{n+1} &= \textbf{x}^n + \alpha_n \,\textbf{d}^n \\
441\textbf{r}^{n+1} &= \textbf{r}^n - \alpha_n \,\textbf{z}^n \\
442\gamma_{n+1} &= \langle{ \textbf{r}^{n+1} , \textbf{r}^{n+1}} \rangle \\
443\beta_{n+1} &= \gamma_{n+1}/\gamma_{n}  \\
444\textbf{d}^{n+1} &= \textbf{r}^{n+1} + \beta_{n+1}\; \textbf{d}^{n}\\
445\end{split}
446\end{equation}
447
448
449The convergence test is:
450\begin{equation}
451\delta = \gamma_{n}\; / \langle{ \textbf{b} , \textbf{b}} \rangle \leq \epsilon
452\end{equation}
453where $\epsilon $ is the absolute precision that is required. As for the SOR algorithm,
454the whole model computation is stopped when the number of iterations, \np{nn\_max}, or
455the modulus of the right hand side of the convergence equation exceeds a
456specified value (see \S\ref{MISC_solsor} for a further discussion). The required
457precision and the maximum number of iterations allowed are specified by setting
458\np{rn\_eps} and \np{nn\_max} (\textbf{namelist} parameters).
459
460It can be demonstrated that the above algorithm is optimal, provides the exact
461solution in a number of iterations equal to the size of the matrix, and that
462the convergence rate is faster as the matrix is closer to the identity matrix,
463$i.e.$ its eigenvalues are closer to 1. Therefore, it is more efficient to solve
464a better conditioned system which has the same solution. For that purpose,
465we introduce a preconditioning matrix \textbf{Q} which is an approximation
466of \textbf{A} but much easier to invert than \textbf{A}, and solve the system:
467\begin{equation} \label{Eq_pmat}
468\textbf{Q}^{-1} \textbf{A x} = \textbf{Q}^{-1} \textbf{b}
469\end{equation}
470
471The same algorithm can be used to solve \eqref{Eq_pmat} if instead of the
472canonical dot product the following one is used:
473${\langle{ \textbf{a} , \textbf{b}} \rangle}_Q = \langle{ \textbf{a} , \textbf{Q b}} \rangle$, and
474if $\textbf{\~{b}} = \textbf{Q}^{-1}\;\textbf{b}$ and $\textbf{\~{A}} = \textbf{Q}^{-1}\;\textbf{A}$ 
475are substituted to \textbf{b} and \textbf{A} \citep{Madec_al_OM88}.
476In \NEMO, \textbf{Q} is chosen as the diagonal of \textbf{ A}, i.e. the simplest form for
477\textbf{Q} so that it can be easily inverted. In this case, the discrete formulation of
478\eqref{Eq_pmat} is in fact given by \eqref{Eq_solmat_p} and thus the matrix and
479right hand side are computed independently from the solver used.
480
481% ================================================================
482% Diagnostics
483% ================================================================
484\section{Diagnostics (DIA, IOM, TRD, FLO)}
485\label{MISC_diag}
486
487% -------------------------------------------------------------------------------------------------------------
488%       Standard Model Output
489% -------------------------------------------------------------------------------------------------------------
490\subsection{Model Output (default or \key{iomput} or \key{dimgout} or \key{netcdf4})}
491\label{MISC_iom}
492
493%to be updated with Seb documentation on the IO
494
495The model outputs are of three types: the restart file, the output listing,
496and the output file(s). The restart file is used internally by the code when
497the user wants to start the model with initial conditions defined by a
498previous simulation. It contains all the information that is necessary in
499order for there to be no changes in the model results (even at the computer
500precision) between a run performed with several restarts and the same run
501performed in one step. It should be noted that this requires that the restart file
502contain two consecutive time steps for all the prognostic variables, and
503that it is saved in the same binary format as the one used by the computer
504that is to read it (in particular, 32 bits binary IEEE format must not be used for
505this file). The output listing and file(s) are predefined but should be checked
506and eventually adapted to the user's needs. The output listing is stored in
507the $ocean.output$ file. The information is printed from within the code on the
508logical unit $numout$. To locate these prints, use the UNIX command
509"\textit{grep -i numout}" in the source code directory.
510
511In the standard configuration, the user will find the model results in
512NetCDF files containing mean values (or instantaneous values if
513\key{diainstant} is defined) for every time-step where output is demanded.
514These outputs are defined in the \mdl{diawri} module.
515When defining \key{dimgout}, the output are written in DIMG format,
516an IEEE output format.
517
518Since version 3.3, support for NetCDF4 chunking and (loss-less) compression has
519been included.  These options build on the standard NetCDF output and allow
520the user control over the size of the chunks via namelist settings. Chunking
521and compression can lead to significant reductions in file sizes for a small
522runtime overhead. For a fuller discussion on chunking and other performance
523issues the reader is referred to the NetCDF4 documentation found
524\href{http://www.unidata.ucar.edu/software/netcdf/docs/netcdf.html#Chunking}{here}.
525
526The new features are only available when the code has been linked with a
527NetCDF4 library (version 4.1 onwards, recommended) which has been built
528with HDF5 support (version 1.8.4 onwards, recommended). Datasets created
529with chunking and compression are not backwards compatible with NetCDF3
530"classic" format but most analysis codes can be relinked simply with the
531new libraries and will then read both NetCDF3 and NetCDF4 files. NEMO
532executables linked with NetCDF4 libraries can be made to produce NetCDF3
533files by setting the \np{ln\_nc4zip} logical to false in the \np{namnc4} 
534namelist:
535
536%------------------------------------------namnc4----------------------------------------------------
537\namdisplay{namnc4}
538%-------------------------------------------------------------------------------------------------------------
539
540If \key{netcdf4} has not been defined, these namelist parameters are not read.
541In this case, \np{ln\_nc4zip} is set false and dummy routines for a few
542NetCDF4-specific functions are defined. These functions will not be used but
543need to be included so that compilation is possible with NetCDF3 libraries.
544
545When using NetCDF4 libraries, \key{netcdf4} should be defined even if the
546intention is to create only NetCDF3-compatible files. This is necessary to
547avoid duplication between the dummy routines and the actual routines present
548in the library. Most compilers will fail at compile time when faced with
549such duplication. Thus when linking with NetCDF4 libraries the user must
550define \key{netcdf4} and control the type of NetCDF file produced via the
551namelist parameter.
552
553Chunking and compression is applied only to 4D fields and there is no
554advantage in chunking across more than one time dimension since previously
555written chunks would have to be read back and decompressed before being
556added to. Therefore, user control over chunk sizes is provided only for the
557three space dimensions. The user sets an approximate number of chunks along
558each spatial axis. The actual size of the chunks will depend on global domain
559size for mono-processors or, more likely, the local processor domain size for
560distributed processing. The derived values are subject to practical minimum
561values (to avoid wastefully small chunk sizes) and cannot be greater than the
562domain size in any dimension. The algorithm used is:
563
564\begin{alltt}  {{\scriptsize 
565\begin{verbatim}
566     ichunksz(1) = MIN( idomain_size,MAX( (idomain_size-1)/nn_nchunks_i + 1 ,16 ) )
567     ichunksz(2) = MIN( jdomain_size,MAX( (jdomain_size-1)/nn_nchunks_j + 1 ,16 ) )
568     ichunksz(3) = MIN( kdomain_size,MAX( (kdomain_size-1)/nn_nchunks_k + 1 , 1 ) )
569     ichunksz(4) = 1
570\end{verbatim}
571}}\end{alltt} 
572
573\noindent As an example, setting:
574\vspace{-20pt}
575\begin{alltt}  {{\scriptsize
576\begin{verbatim}
577     nn_nchunks_i=4, nn_nchunks_j=4 and nn_nchunks_k=31
578\end{verbatim}
579}}\end{alltt} \vspace{-10pt}
580
581\noindent for a standard ORCA2\_LIM configuration gives chunksizes of {\small\tt 46x38x1}
582respectively in the mono-processor case (i.e. global domain of {\small\tt 182x149x31}).
583An illustration of the potential space savings that NetCDF4 chunking and compression
584provides is given in table \ref{Tab_NC4} which compares the results of two short
585runs of the ORCA2\_LIM reference configuration with a 4x2 mpi partitioning. Note
586the variation in the compression ratio achieved which reflects chiefly the dry to wet
587volume ratio of each processing region.
588
589%------------------------------------------TABLE----------------------------------------------------
590\begin{table}  \begin{tabular}{lrrr}
591Filename & NetCDF3 & NetCDF4 & Reduction\\
592         &filesize & filesize & \% \\
593         &(KB)     & (KB)     & \\
594ORCA2\_restart\_0000.nc & 16420 & 8860 & 47\%\\
595ORCA2\_restart\_0001.nc & 16064 & 11456 & 29\%\\
596ORCA2\_restart\_0002.nc & 16064 & 9744 & 40\%\\
597ORCA2\_restart\_0003.nc & 16420 & 9404 & 43\%\\
598ORCA2\_restart\_0004.nc & 16200 & 5844 & 64\%\\
599ORCA2\_restart\_0005.nc & 15848 & 8172 & 49\%\\
600ORCA2\_restart\_0006.nc & 15848 & 8012 & 50\%\\
601ORCA2\_restart\_0007.nc & 16200 & 5148 & 69\%\\
602ORCA2\_2d\_grid\_T\_0000.nc & 2200 & 1504 & 32\%\\
603ORCA2\_2d\_grid\_T\_0001.nc & 2200 & 1748 & 21\%\\
604ORCA2\_2d\_grid\_T\_0002.nc & 2200 & 1592 & 28\%\\
605ORCA2\_2d\_grid\_T\_0003.nc & 2200 & 1540 & 30\%\\
606ORCA2\_2d\_grid\_T\_0004.nc & 2200 & 1204 & 46\%\\
607ORCA2\_2d\_grid\_T\_0005.nc & 2200 & 1444 & 35\%\\
608ORCA2\_2d\_grid\_T\_0006.nc & 2200 & 1428 & 36\%\\
609ORCA2\_2d\_grid\_T\_0007.nc & 2200 & 1148 & 48\%\\
610             ...            &  ... &  ... & ..  \\
611ORCA2\_2d\_grid\_W\_0000.nc & 4416 & 2240 & 50\%\\
612ORCA2\_2d\_grid\_W\_0001.nc & 4416 & 2924 & 34\%\\
613ORCA2\_2d\_grid\_W\_0002.nc & 4416 & 2512 & 44\%\\
614ORCA2\_2d\_grid\_W\_0003.nc & 4416 & 2368 & 47\%\\
615ORCA2\_2d\_grid\_W\_0004.nc & 4416 & 1432 & 68\%\\
616ORCA2\_2d\_grid\_W\_0005.nc & 4416 & 1972 & 56\%\\
617ORCA2\_2d\_grid\_W\_0006.nc & 4416 & 2028 & 55\%\\
618ORCA2\_2d\_grid\_W\_0007.nc & 4416 & 1368 & 70\%\\
619\end{tabular}
620\caption{   \label{Tab_NC4} 
621Filesize comparison between NetCDF3 and NetCDF4 with chunking and compression}
622\end{table}
623%----------------------------------------------------------------------------------------------------
624
625Since version 3.2, an I/O server has been added which provides more
626flexibility in the choice of the fields to be output as well as how the
627writing work is distributed over the processors in massively parallel
628computing. It is activated when \key{iomput} is defined.
629
630When \key{iomput} is activated with \key{netcdf4} chunking and
631compression parameters for fields produced via \np{iom\_put} calls are
632set via an equivalent and identically named namelist to \np{namnc4} in
633\np{xmlio\_server.def}. Typically this namelist serves the mean files
634whilst the \np{ namnc4} in the main namelist file continues to serve the
635restart files. This duplication is unfortunate but appropriate since, if
636using io\_servers, the domain sizes of the individual files produced by the
637io\_server processes may be different to those produced by the invidual
638processing regions and different chunking choices may be desired.
639{ 
640
641% -------------------------------------------------------------------------------------------------------------
642%       Tracer/Dynamics Trends
643% -------------------------------------------------------------------------------------------------------------
644\subsection[Tracer/Dynamics Trends (TRD)]
645                  {Tracer/Dynamics Trends (\key{trdmld}, \key{trdtra}, \key{trddyn}, \key{trdmld\_trc})}
646\label{MISC_tratrd}
647
648%------------------------------------------namtrd----------------------------------------------------
649\namdisplay{namtrd} 
650%-------------------------------------------------------------------------------------------------------------
651
652When \key{trddyn} and/or \key{trddyn} CPP variables are defined, each
653trend of the dynamics and/or temperature and salinity time evolution equations
654is stored in three-dimensional arrays just after their computation ($i.e.$ at the end
655of each $dyn\cdots.F90$ and/or $tra\cdots.F90$ routines). These trends are then
656used in \mdl{trdmod} (see TRD directory) every \textit{nn\_trd } time-steps.
657
658What is done depends on the CPP keys defined:
659\begin{description}
660\item[\key{trddyn}, \key{trdtra}] : a check of the basin averaged properties of the momentum
661and/or tracer equations is performed ;
662\item[\key{trdvor}] : a vertical summation of the moment tendencies is performed,
663then the curl is computed to obtain the barotropic vorticity tendencies which are output ;
664\item[\key{trdmld}] : output of the tracer tendencies averaged vertically 
665either over the mixed layer (\np{nn\_ctls}=0),
666or       over a fixed number of model levels (\np{nn\_ctls}$>$1 provides the number of level),
667or       over a spatially varying but temporally fixed number of levels (typically the base
668of the winter mixed layer) read in \ifile{ctlsurf\_idx} (\np{nn\_ctls}=1).
669\end{description}
670
671The units in the output file can be changed using the \np{nn\_ucf} namelist parameter.
672For example, in case of salinity tendency the units are given by PSU/s/\np{nn\_ucf}.
673Setting \np{nn\_ucf}=86400 ($i.e.$ the number of second in a day) provides the tendencies in PSU/d.
674
675When \key{trdmld} is defined, two time averaging procedure are proposed.
676Setting \np{ln\_trdmld\_instant} to \textit{true}, a simple time averaging is performed,
677so that the resulting tendency is the contribution to the change of a quantity between
678the two instantaneous values taken at the extremities of the time averaging period.
679Setting \np{ln\_trdmld\_instant} to \textit{false}, a double time averaging is performed,
680so that the resulting tendency is the contribution to the change of a quantity between
681two \textit{time mean} values. The later option requires the use of an extra file, \ifile{restart\_mld} 
682(\np{ln\_trdmld\_restart}=true), to restart a run.
683
684
685Note that the mixed layer tendency diagnostic can also be used on biogeochemical models
686via the \key{trdtrc} and \key{trdmld\_trc} CPP keys.
687
688% -------------------------------------------------------------------------------------------------------------
689%       On-line Floats trajectories
690% -------------------------------------------------------------------------------------------------------------
691\subsection{On-line Floats trajectories (FLO) (\key{floats})}
692\label{FLO}
693%--------------------------------------------namflo-------------------------------------------------------
694\namdisplay{namflo} 
695%--------------------------------------------------------------------------------------------------------------
696
697The on-line computation of floats advected either by the three dimensional velocity
698field or constraint to remain at a given depth ($w = 0$ in the computation) have been
699introduced in the system during the CLIPPER project. The algorithm used is based
700either on the work of \cite{Blanke_Raynaud_JPO97} (default option), or on a $4^th$
701Runge-Hutta algorithm (\np{ln\_flork4}=true). Note that the \cite{Blanke_Raynaud_JPO97} 
702algorithm have the advantage of providing trajectories which are consistent with the
703numeric of the code, so that the trajectories never intercept the bathymetry.
704
705See also \href{http://stockage.univ-brest.fr/~grima/Ariane/}{here} the web site describing
706the off-line use of this marvellous diagnostic tool.
707
708% -------------------------------------------------------------------------------------------------------------
709%       Other Diagnostics
710% -------------------------------------------------------------------------------------------------------------
711\subsection{Other Diagnostics (\key{diahth}, \key{diaar5})}
712\label{MISC_diag_others}
713
714
715Aside from the standard model variables, other diagnostics can be computed
716on-line. The available ready-to-add diagnostics routines can be found in directory DIA.
717Among the available diagnostics the following ones are obtained when defining
718the \key{diahth} CPP key:
719
720- the mixed layer depth (based on a density criterion, \citet{de_Boyer_Montegut_al_JGR04}) (\mdl{diahth})
721
722- the turbocline depth (based on a turbulent mixing coefficient criterion) (\mdl{diahth})
723
724- the depth of the 20\deg C isotherm (\mdl{diahth})
725
726- the depth of the thermocline (maximum of the vertical temperature gradient) (\mdl{diahth})
727
728The poleward heat and salt transports, their advective and diffusive component, and
729the meriodional stream function can be computed on-line in \mdl{diaptr} by setting
730\np{ln\_diaptr} to true (see the \textit{namptr} namelist below). 
731When \np{ln\_subbas}~=~true, transports and stream function are computed
732for the Atlantic, Indian, Pacific and Indo-Pacific Oceans (defined north of 30\deg S)
733as well as for the World Ocean. The sub-basin decomposition requires an input file
734(\ifile{subbasins}) which contains three 2D mask arrays, the Indo-Pacific mask
735been deduced from the sum of the Indian and Pacific mask (Fig~\ref{Fig_mask_subasins}).
736
737%------------------------------------------namptr----------------------------------------------------
738\namdisplay{namptr} 
739%-------------------------------------------------------------------------------------------------------------
740%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
741\begin{figure}[!t]     \begin{center}
742\includegraphics[width=1.0\textwidth]{./TexFiles/Figures/Fig_mask_subasins.pdf}
743\caption{   \label{Fig_mask_subasins}
744Decomposition of the World Ocean (here ORCA2) into sub-basin used in to compute
745the heat and salt transports as well as the meridional stream-function: Atlantic basin (red),
746Pacific basin (green), Indian basin (bleue), Indo-Pacific basin (bleue+green).
747Note that semi-enclosed seas (Red, Med and Baltic seas) as well as Hudson Bay
748are removed from the sub-basin. Note also that the Arctic Ocean has been split
749into Atlantic and Pacific basins along the North fold line.  }
750\end{center}   \end{figure}
751%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
752
753In addition, a series of diagnostics has been added in the \mdl{diaar5}.
754They corresponds to outputs that are required for AR5 simulations
755(see Section \ref{MISC_steric} below for one of them).
756Activating those outputs requires to define the \key{diaar5} CPP key.
757
758
759
760% ================================================================
761% Steric effect in sea surface height
762% ================================================================
763\section{Steric effect in sea surface height}
764\label{MISC_steric}
765
766
767Changes in steric sea level are caused when changes in the density of the water
768column imply an expansion or contraction of the column. It is essentially produced
769through surface heating/cooling and to a lesser extent through non-linear effects of
770the equation of state (cabbeling, thermobaricity...).
771Non-Boussinesq models contain all ocean effects within the ocean acting
772on the sea level. In particular, they include the steric effect. In contrast,
773Boussinesq models, such as \NEMO, conserve volume, rather than mass,
774and so do not properly represent expansion or contraction. The steric effect is
775therefore not explicitely represented.
776This approximation does not represent a serious error with respect to the flow field
777calculated by the model \citep{Greatbatch_JGR94}, but extra attention is required
778when investigating sea level, as steric changes are an important
779contribution to local changes in sea level on seasonal and climatic time scales.
780This is especially true for investigation into sea level rise due to global warming.
781
782Fortunately, the steric contribution to the sea level consists of a spatially uniform
783component that can be diagnosed by considering the mass budget of the world
784ocean \citep{Greatbatch_JGR94}.
785In order to better understand how global mean sea level evolves and thus how
786the steric sea level can be diagnosed, we compare, in the following, the
787non-Boussinesq and Boussinesq cases.
788
789Let denote
790$\mathcal{M}$ the total mass of liquid seawater ($\mathcal{M}=\int_D \rho dv$),
791$\mathcal{V}$ the total volume of seawater ($\mathcal{V}=\int_D dv$),
792$\mathcal{A}$ the total surface of the ocean ($\mathcal{A}=\int_S ds$),
793$\bar{\rho}$ the global mean seawater (\textit{in situ}) density ($\bar{\rho}= 1/\mathcal{V} \int_D \rho \,dv$), and
794$\bar{\eta}$ the global mean sea level ($\bar{\eta}=1/\mathcal{A}\int_S \eta \,ds$).
795
796A non-Boussinesq fluid conserves mass. It satisfies the following relations:
797\begin{equation} \label{Eq_MV_nBq} 
798\begin{split} 
799\mathcal{M} &\mathcal{V}  \;\bar{\rho}       \\
800\mathcal{V} &\mathcal{A}  \;\bar{\eta} 
801\end{split}
802\end{equation}
803Temporal changes in total mass is obtained from the density conservation equation :
804\begin{equation}  \label{Eq_Co_nBq}
805\frac{1}{e_3} \partial_t ( e_3\,\rho) + \nabla( \rho \, \textbf{U} ) = \left. \frac{\textit{emp}}{e_3}\right|_\textit{surface}
806\end{equation}
807where $\rho$ is the \textit{in situ} density, and \textit{emp} the surface mass
808exchanges with the other media of the Earth system (atmosphere, sea-ice, land).
809Its global averaged leads to the total mass change
810\begin{equation}  \label{Eq_Mass_nBq}
811\partial_t \mathcal{M} = \mathcal{A} \;\overline{\textit{emp}}
812\end{equation}
813where $\overline{\textit{emp}}=\int_S \textit{emp}\,ds$ is the net mass flux
814through the ocean surface.
815Bringing \eqref{Eq_Mass_nBq} and the time derivative of \eqref{Eq_MV_nBq} 
816together leads to the evolution equation of the mean sea level
817\begin{equation} \label{Eq_ssh_nBq}
818  \partial_t \bar{\eta} =  \frac{\overline{\textit{emp}}}{ \bar{\rho}} 
819               - \frac{\mathcal{V}}{\mathcal{A}}  \;\frac{\partial_t \bar{\rho} }{\bar{\rho}}
820\end{equation}
821The first term in equation \eqref{Eq_ssh_nBq} alters sea level by adding or
822subtracting mass from the ocean.
823The second term arises from temporal changes in the global mean
824density; $i.e.$ from steric effects.
825
826In a Boussinesq fluid, $\rho$ is replaced by $\rho_o$ in all the equation except when $\rho$ 
827appears multiplied by the gravity ($i.e.$ in the hydrostatic balance of the primitive Equations).
828In particular, the mass conservation equation, \eqref{Eq_Co_nBq}, degenerates into
829the incompressibility equation:
830\begin{equation}  \label{Eq_Co_Bq}
831\frac{1}{e_3} \partial_t ( e_3 ) + \nabla( \textbf{U} ) =  \left. \frac{\textit{emp}}{\rho_o \,e_3}\right|_ \textit{surface}
832\end{equation}
833and the global average of this equation now gives the temporal change of the total volume,
834\begin{equation}  \label{Eq_V_Bq}
835  \partial_t \mathcal{V} =   \mathcal{A} \;\frac{\overline{\textit{emp}}}{\rho_o} 
836\end{equation}
837Only the volume is conserved, not mass, or, more precisely, the mass which is conserved is the
838Boussinesq mass, $\mathcal{M}_o = \rho_o \mathcal{V}$. The total volume (or equivalently 
839the global mean sea level) is altered only by net volume fluxes across the ocean surface, 
840not by changes in mean mass of the ocean: the steric effect is missing in a Boussinesq fluid.
841 
842Nevertheless, following \citep{Greatbatch_JGR94}, the steric effect on the volume can be
843diagnosed by considering the mass budget of the ocean.
844The apparent changes in $\mathcal{M}$, mass of the ocean, which are not induced by surface
845mass flux must be compensated by a spatially uniform change in the mean sea level due to
846expansion/contraction of the ocean \citep{Greatbatch_JGR94}. In others words, the Boussinesq
847mass, $\mathcal{M}_o$, can be related to $\mathcal{M}$, the  total mass of the ocean seen
848by the Boussinesq model, via the steric contribution to the sea level, $\eta_s$, a spatially
849uniform variable, as follows:
850\begin{equation}  \label{Eq_M_Bq}
851   \mathcal{M}_o  =  \mathcal{M} + \rho_o \,\eta_s \,\mathcal{A} 
852\end{equation}
853Any change in $\mathcal{M}$ which cannot be explained by the net mass flux through
854the ocean surface is converted into a mean change in sea level. Introducing the total density
855anomaly, $\mathcal{D}= \int_D d_a \,dv$, where $d_a= (\rho -\rho_o ) / \rho_o$ 
856is the density anomaly used in \NEMO (cf. \S\ref{TRA_eos}) in \eqref{Eq_M_Bq}
857leads to a very simple form for the steric height:
858\begin{equation}  \label{Eq_steric_Bq}
859   \eta_s = - \frac{1}{\mathcal{A}} \mathcal{D} 
860\end{equation}
861
862The above formulation of the steric height of a Boussinesq ocean requires four remarks.
863First, one can be tempted to define $\rho_o$ as the initial value of $\mathcal{M}/\mathcal{V}$,
864$i.e.$ set $\mathcal{D}_{t=0}=0$, so that the initial steric height is zero. We do not
865recommend that. Indeed, in this case $\rho_o$ depends on the initial state of the ocean.
866Since $\rho_o$ has a direct effect on the dynamics of the ocean (it appears in the pressure
867gradient term of the momentum equation) it is definitively not a good idea when
868inter-comparing experiments.
869We better recommend to fixe once for all $\rho_o$ to $1035\;Kg\,m^{-3}$. This value is a
870sensible choice for the reference density used in a Boussinesq ocean climate model since,
871with the exception of only a small percentage of the ocean, density in the World Ocean
872varies by no more than 2$\%$ from this value (\cite{Gill1982}, page 47).
873
874Second, we have assumed here that the total ocean surface, $\mathcal{A}$, does not
875change when the sea level is changing as it is the case in all global ocean GCMs
876(wetting and drying of grid point is not allowed).
877 
878Third, the discretisation of \eqref{Eq_steric_Bq} depends on the type of free surface
879which is considered. In the non linear free surface case, $i.e.$ \key{vvl} defined, it is
880given by
881\begin{equation}  \label{Eq_discrete_steric_Bq}
882   \eta_s =  - \frac{ \sum_{i,\,j,\,k} d_a\; e_{1t} e_{2t} e_{3t} }
883                  { \sum_{i,\,j,\,k}         e_{1t} e_{2t} e_{3t} } 
884\end{equation}
885whereas in the linear free surface, the volume above the \textit{z=0} surface must be explicitly taken
886into account to better approximate the total ocean mass and thus the steric sea level:
887\begin{equation}  \label{Eq_discrete_steric_Bq}
888   \eta_s =  - \frac{ \sum_{i,\,j,\,k} d_a\; e_{1t}e_{2t}e_{3t} + \sum_{i,\,j} d_a\; e_{1t}e_{2t} \eta }
889                     {\sum_{i,\,j,\,k} e_{1t}e_{2t}e_{3t} + \sum_{i,\,j}           e_{1t}e_{2t} \eta } 
890\end{equation}
891
892The fourth and last remark concerns the effective sea level and the presence of sea-ice.
893In the real ocean, sea ice (and snow above it)  depresses the liquid seawater through
894its mass loading. This depression is a result of the mass of sea ice/snow system acting
895on the liquid ocean. There is, however, no dynamical effect associated with these depressions
896in the liquid ocean sea level, so that there are no associated ocean currents. Hence, the
897dynamically relevant sea level is the effective sea level, $i.e.$ the sea level as if sea ice
898(and snow) were converted to liquid seawater \citep{Campin_al_OM08}. However,
899in the current version of \NEMO the sea-ice is levitating above the ocean without
900mass exchanges between ice and ocean. Therefore the model effective sea level
901is always given by $\eta + \eta_s$, whether or not there is sea ice present.
902
903In AR5 outputs, the thermosteric sea level is demanded. It is steric sea level due to
904changes in ocean density arising just from changes in temperature. It is given by:
905\begin{equation}  \label{Eq_thermosteric_Bq}
906   \eta_s = - \frac{1}{\mathcal{A}} \int_D d_a(T,S_o,p_o) \,dv
907\end{equation}
908where $S_o$ and $p_o$ are the initial salinity and pressure, respectively.
909
910Both steric and thermosteric sea level are computed in \mdl{diaar5} which needs
911the \key{diaar5} defined to be called.
912
913
914
915\gmcomment{                    % start of gmcomment
916
917
918% ================================================================
919% Diagnostics
920% ================================================================
921\section{Standard model Output (IOM)}
922\label{MISC_iom}
923
924% -------------------------------------------------------------------------------------------------------------
925%       Standard Model Output
926% -------------------------------------------------------------------------------------------------------------
927%\subsection{Model Output (default or \key{iomput} }
928%\label{MISC_iom}
929
930
931
932\subsection{Basic knowledge}
933
934
935\subsubsection{ XML basic rules}
936
937XML tags begin with the less-than character ("$<$") and end with the greater-than character (''$>$'').
938You use tags to mark the start and end of elements, which are the logical units of information
939in an XML document. In addition to marking the beginning of an element, XML start tags also
940provide a place to specify attributes. An attribute specifies a single property for an element,
941using a name/value pair, for example: $<$a b="x" c="y" b="z"$>$ ... $<$/a$>$.
942See \href{http://www.xmlnews.org/docs/xml-basics.html}{here} for more details.
943
944\subsubsection{Structure of the xml file used in NEMO}
945
946The xml file is split into 3 parts:
947
948\textbf{field definition}: define all variables that can be output (all lines between   
949\texttt{$<$field\_definition$>$} and \texttt{$<$/field\_definition$>$})
950
951\textbf{file definition}: define the netcdf files to be created and the variables they will contain
952(all lines between \texttt{ $<$file\_definition$>$} and \texttt{$<$/file\_definition$>$})
953
954\textbf{axis and grid definitions}: define the horizontal and vertical grids (all lines between
955\texttt{$<$axis\_definition$>$} and \texttt{$<$/axis\_definition$>$} and all lines between
956\texttt{$<$grid\_definition$>$} and \texttt{$<$/grid\_definition$>$})
957
958\subsubsection{Inheritance and group }
959
960 Xml extensively uses the concept of inheritance. \\
961\\
962example 1: \\
963\vspace{-30pt}
964\begin{alltt}  {{\scriptsize   
965\begin{verbatim}
966   <field_definition operation="ave(X)" >
967      <field id="sst"                    />   <!-- averaged      sst -->
968      <field id="sss" operation="inst(X)"/>   <!-- instantaneous sss -->
969   </field_definition>
970\end{verbatim}
971}}\end{alltt} 
972
973The field ''sst'' which is part (or a child) of the field\_definition will inherit the value ''ave(X)''
974of the attribute ''operation'' from its parent ''field definition''. Note that a child can overwrite
975the attribute definition inherited from its parents. In the example above, the field ''sss'' will
976therefore output instantaneous values instead of average values.
977
978example 2: Use (or overwrite) attributes value of a field when listing the variables included in a file
979\vspace{-20pt}
980\begin{alltt}  {{\scriptsize
981\begin{verbatim}
982   <field_definition>
983      <field id="sst" description="sea surface temperature" />   
984      <field id="sss" description="sea surface salinity"    /> 
985   </field_definition>     
986
987   <file_definition>
988      <file id="file_1" />   
989            <field ref="sst"                              />  <!-- default def -->
990            <field ref="sss" description="my description" />  <!-- overwrite   -->
991      </file>   
992   </file_definition>
993\end{verbatim}
994}}\end{alltt} 
995
996With the help of the inheritance, the concept of group allow to define a set of attributes
997for several fields or files.
998
999example 3, group of fields: define a group ''T\_grid\_variables'' identified with the name
1000''grid\_T''. By default variables of this group have no vertical axis but, following inheritance
1001rules, ''axis\_ref'' can be redefined for the field ''toce'' that is a 3D variable.
1002\vspace{-30pt}
1003\begin{alltt}  {{\scriptsize
1004\begin{verbatim}
1005   <field_definition>
1006      <group id="grid_T" axis_ref="none" grid_ref="T_grid_variables">
1007            <field id="sst"/> 
1008            <field id="sss"/> 
1009            <field id="toce" axis_ref="deptht"/>  <!-- overwrite axis def -->
1010      </group>
1011   </field_definition>
1012\end{verbatim}
1013}}\end{alltt} 
1014
1015example 4, group of files: define a group of file with the attribute output\_freq equal to 432000 (5 days)
1016\vspace{-30pt}
1017\begin{alltt}  {{\scriptsize
1018\begin{verbatim}
1019   <file_definition>
1020      <group id="5d" output_freq="432000">    <!-- 5d files -->
1021         <file id="5d_grid_T" name="auto">   <!-- T grid file -->
1022         ...
1023         </file>
1024         <file id="5d_grid_U" name="auto">   <!-- U grid file -->
1025         ...
1026         </file>
1027      </group>
1028   </file_definition>
1029\end{verbatim}
1030}}\end{alltt} 
1031
1032\subsubsection{Control of the xml attributes from NEMO}
1033
1034The values of some attributes are automatically defined by NEMO (and any definition
1035given in the xml file is overwritten). By convention, these attributes are defined to ''auto''
1036(for string) or ''0000'' (for integer) in the xml file (but this is not necessary).
1037
1038Here is the list of these attributes: \\
1039
1040%table to be created here....
1041
1042tag ids affected by automatic definition of some of their attributes
1043
1044name attribute
1045attribute value
1046field\_definition
1047freq\_op
1048\np{rn\_rdt} (namelist)
1049SBC
1050freq\_op
1051\np{rn\_rdt} $\times$ \np{nn\_fsbc} (namelist)
10521h, 2h, 3h, 4h, 6h, 12h
10531d, 3d, 5d
10541m, 2m, 3m, 4m, 6m
10551y, 2y, 5y, 10y
1056\_grid\_T, \_grid\_U, \_grid\_V, \_grid\_W, \_icemod, \_ptrc\_T, \_diad\_T, \_scalar
1057name
1058filename defined by a call to rou{dia\_nam} following NEMO nomenclature
1059EqT, EqU, EqW
1060jbegin, ni, name\_suffix
1061according to the grid
1062TAO, RAMA and PIRATA moorings
1063ibegin, jbegin, name\_suffix
1064according to the grid
1065
1066
1067\subsection{ Detailed functionalities }
1068
1069\subsubsection{Tag list}
1070
1071
1072Table might be easier to read:        % table to create
1073
1074Tag
1075Description
1076Accepted attribute
1077Accepted attribute value(s)
1078Parent tag
1079context
1080define the model using the xml file
1081id
1082"nemo" or "n\_nemo" for the nth AGRIF zoom.
1083simulation
1084
1085What do you think, Seb?
1086
1087
1088\begin{description}
1089
1090\item[context]: define the model using the xml file. Id is the only attribute accepted.
1091Its value must be ''nemo'' or ''n\_nemo'' for the nth AGRIF zoom. Child of simulation tag.
1092
1093\item[field]: define the field to be output. Accepted attributes are axis\_ref, description, enable,
1094freq\_op, grid\_ref, id (if child of field\_definition), level, operation, name, ref (if child of file),
1095unit, zoom\_ref. Child of field\_definition, file or group of fields tag.
1096
1097\item[field\_definition]: definition of the part of the xml file corresponding to the field definition.
1098Accept the same attributes as field tag. Child of context tag.
1099
1100\item[group]: define a group of file or field. Accept the same attributes as file or field.
1101
1102\item[file]: define the output fileÕs characteristics. Accepted attributes are description, enable,
1103output\_freq, output\_level, id, name, name\_suffix. Child of file\_definition or group of files tag.
1104
1105\item[file\_definition]: definition of the part of the xml file corresponding to the file definition.
1106Accept the same attributes as file tag. Child of context tag.
1107
1108\item[axis]: definition of the vertical axis. Accepted attributes are description, id, positive, size, unit.
1109Child of axis\_definition tag.
1110
1111\item[axis\_definition]: definition of the part of the xml file corresponding to the vertical axis definition.
1112Accept the same attributes as axis tag. Child of context tag
1113
1114\item[grid]: definition of the horizontal grid. Accepted attributes are description and id.
1115Child of axis\_definition tag.
1116
1117\item[grid\_definition]: definition of the part of the xml file corresponding to the horizontal grid definition.
1118Accept the same attributes as grid tag. Child of context tag
1119
1120\item[zoom]: definition of a subdomain of an horizontal grid. Accepted attributes are description, id,
1121i/jbegin, ni/j. Child of grid tag.
1122
1123\end{description}
1124
1125
1126\subsubsection{Attributes list}
1127
1128Applied to a tag or a group of tags.
1129
1130% table to be added ?
1131Another table, perhaps?
1132
1133%%%%
1134
1135Attribute
1136Applied to?
1137Definition
1138Comment
1139axis\_ref
1140field
1141String defining the vertical axis of the variable. It refers to the id of the vertical axis defined in the axis tag.
1142Use ''non'' if the variable has no vertical axis
1143
1144%%%%%%
1145
1146\begin{description}
1147
1148\item[axis\_ref]: field attribute. String defining the vertical axis of the variable.
1149It refers to the id of the vertical axis defined in the axis tag.
1150Use ''none'' if the variable has no vertical axis
1151
1152\item[description]: this attribute can be applied to all tags but it is used only with the field tag.
1153In this case, the value of description will be used to define, in the output netcdf file,
1154the attributes long\_name and standard\_name of the variable.
1155
1156\item[enabled]: field and file attribute. Logical to switch on/off the output of a field or a file.
1157
1158\item[freq\_op]: field attribute (automatically defined, see part 1.4 (''control of the xml attributes'')).
1159An integer defining the frequency in seconds at which NEMO is calling iom\_put for this variable.
1160It corresponds to the model time step (rn\_rdt in the namelist) except for the variables computed
1161at the frequency of the surface boundary condition (rn\_rdt ? nn\_fsbc in the namelist).   
1162
1163\item[grid\_ref]: field attribute. String defining the horizontal grid of the variable.
1164It refers to the id of the grid tag.
1165
1166\item[ibegin]: zoom attribute. Integer defining the zoom starting point along x direction.
1167Automatically defined for TAO/RAMA/PIRATA moorings (see part 1.4). 
1168
1169\item[id]: exists for all tag. This is a string defining the name to a specific tag that will be used
1170later to refer to this tag. Tags of the same category must have different ids.
1171
1172\item[jbegin]: zoom attribute. Integer defining the zoom starting point along y direction.
1173Automatically defined for TAO/RAMA/PIRATA moorings and equatorial section (see part 1.4).
1174
1175\item[level]: field attribute. Integer from 0 to 10 defining the output priority of a field.
1176See output\_level attribute definition
1177
1178\item[operation]: field attribute. String defining the type of temporal operation to perform on a variable.
1179Possible choices are ''ave(X)'' for temporal mean, ''inst(X)'' for instantaneous, ''t\_min(X)'' for temporal min
1180and ''t\_max(X)'' for temporal max.
1181
1182\item[output\_freq]: file attribute. Integer defining the operation frequency in seconds.
1183For example 86400 for daily mean.
1184
1185\item[output\_level]: file attribute. Integer from 0 to 10 defining the output priority of variables in a file:
1186all variables listed in the file with a level smaller or equal to output\_level will be output.
1187Other variables wonÕt be output even if they are listed in the file. 
1188
1189\item[positive]: axis attribute (always .FALSE.). Logical defining the vertical axis convention used
1190in \NEMO (positive downward). Define the attribute positive of the variable in the netcdf output file.
1191
1192\item[prec]: field attribute. Integer defining the output precision.
1193Not implemented, we always output real4 arrays.
1194
1195\item[name]: field or file attribute. String defining the name of a variable or a file.
1196If the name of a file is undefined, its id is used as a name. 2 files must have different names.
1197Files with specific ids will have their name automatically defined (see part 1.4).
1198Note that is name will be automatically completed by the cpu number (if needed) and ''.nc''
1199
1200\item[name\_suffix]: file attribute. String defining a suffix to be inserted after the name
1201and before the cpu number and the ''.nc'' termination. Files with specific ids have an
1202automatic definition of their suffix (see part 1.4).
1203
1204\item[ni]: zoom attribute. Integer defining the zoom extent along x direction.
1205Automatically defined for equatorial sections (see part 1.4). 
1206
1207\item[nj]: zoom attribute. Integer defining the zoom extent along x direction.
1208
1209\item[ref]: field attribute. String referring to the id of the field we want to add in a file.
1210
1211\item[size]: axis attribute. use unknown...
1212
1213\item[unit]: field attribute. String defining the unit of a variable and the associated
1214attribute in the netcdf output file.
1215
1216\item[zoom\_ref]: field attribute. String defining the subdomain of data on which
1217the file should be written (to ouput data only in a limited area).
1218It refers to the id of a zoom defined in the zoom tag.
1219\end{description}
1220
1221
1222\subsection{IO\_SERVER}
1223
1224\subsubsection{Attached or detached mode?}
1225
1226Iom\_put is based on the io\_server developed by Yann Meurdesoif from IPSL
1227(see \href{http://forge.ipsl.jussieu.fr/ioserver/browser}{here} for the source code or
1228see its copy in NEMOGCM/EXTERNAL directory).
1229This server can be used in ''attached mode'' (as a library) or in ''detached mode''
1230(as an external executable on n cpus). In attached mode, each cpu of NEMO will output
1231its own subdomain. In detached mode, the io\_server will gather data from NEMO
1232and output them split over n files with n the number of cpu dedicated to the io\_server.
1233
1234\subsubsection{Control the io\_server: the namelist file xmlio\_server.def}
1235
1236%
1237%Again, a small table might be more readable?
1238%Name
1239%Type
1240%Description
1241%Comment
1242%Using_server
1243%Logical
1244%Switch to use the server in attached or detached mode
1245%(.TRUE. corresponding to detached mode).
1246
1247The control of the use of the io\_server is done through the namelist file of the io\_server
1248called xmlio\_server.def.
1249
1250\textbf{using\_server}: logical, switch to use the server in attached or detached mode
1251(.TRUE. corresponding to detached mode).
1252
1253\textbf{using\_oasis}: logical, set to .TRUE. if NEMO is used in coupled mode.
1254
1255\textbf{client\_id} = ''oceanx'' : character, used only in coupled mode.
1256Specify the id used in OASIS to refer to NEMO. The same id must be used to refer to NEMO
1257in the \$NBMODEL part of OASIS namcouple in the call of prim\_init\_comp\_proto in cpl\_oasis3f90
1258
1259\textbf{server\_id} = ''ionemo'' : character, used only in coupled mode.
1260Specify the id used in OASIS to refer to the IO\_SERVER when used in detached mode.
1261Use the same id to refer to the io\_server in the \$NBMODEL part of OASIS namcouple.
1262
1263\textbf{global\_mpi\_buffer\_size}: integer; define the size in Mb of the MPI buffer used by the io\_server.
1264
1265\subsubsection{Number of cpu used by the io\_server in detached mode}
1266
1267The number of cpu used by the io\_server is specified only when launching the model.
1268Here is an example of 2 cpus for the io\_server and 6 cpu for opa using mpirun:
1269
1270\texttt{ -p 2 -e ./ioserver}
1271
1272\texttt{ -p 6 -e ./opa }
1273
1274
1275\subsection{Practical issues}
1276
1277\subsubsection{Add your own outputs}
1278
1279It is very easy to add you own outputs with iom\_put. 4 points must be followed.
1280\begin{description}
1281\item[1-] in NEMO code, add a \\
1282\texttt{      CALL iom\_put( 'identifier', array ) } \\
1283where you want to output a 2D or 3D array.
1284
1285\item[2-] don't forget to add \\
1286\texttt{   USE iom            ! I/O manager library }  \\
1287in the list of used modules in the upper part of your module.
1288
1289\item[3-] in the file\_definition part of the xml file, add the definition of your variable using the same identifier you used in the f90 code.
1290\vspace{-20pt}
1291\begin{alltt}  {{\scriptsize
1292\begin{verbatim}
1293   <field_definition>
1294      ...
1295      <field id="identifier" description="blabla" />   
1296      ...
1297   </field_definition>
1298\end{verbatim}
1299}}\end{alltt} 
1300attributes axis\_ref and grid\_ref must be consistent with the size of the array to pass to iom\_put.
1301if your array is computed within the surface module each nn\_fsbc time\_step,
1302add the field definition within the group defined with the id ''SBC'': $<$group id=''SBC''...$>$
1303
1304\item[4-] add your field in one of the output files   \\
1305\vspace{-20pt}
1306\begin{alltt}  {{\scriptsize
1307\begin{verbatim}
1308   <file id="file_1" .../>   
1309      ...
1310      <field ref="identifier" />   
1311      ...
1312   </file>   
1313\end{verbatim}
1314}}\end{alltt} 
1315
1316\end{description}
1317
1318\subsubsection{Several time axes in the output file}
1319
1320If your output file contains variables with different operations (see operation definition),
1321IOIPSL will create one specific time axis for each operation. Note that inst(X) will have
1322a time axis corresponding to the end each output period whereas all other operators
1323will have a time axis centred in the middle of the output periods.
1324
1325\subsubsection{Error/bug messages from IOIPSL}
1326
1327If you get the following error in the standard output file:
1328\vspace{-20pt}
1329\begin{alltt}  {{\scriptsize
1330\begin{verbatim}
1331FATAL ERROR FROM ROUTINE flio_dom_set
1332 --> too many domains simultaneously defined
1333 --> please unset useless domains
1334 --> by calling flio_dom_unset
1335\end{verbatim}
1336}}\end{alltt} 
1337
1338You must increase the value of dom\_max\_nb in fliocom.f90 (multiply it by 10 for example).
1339
1340If you mix, in the same file, variables with different freq\_op (see definition above),
1341like for example variables from the surface module with other variables,
1342IOIPSL will print in the standard output file warning messages saying there may be a bug.
1343\vspace{-20pt}
1344\begin{alltt}  {{\scriptsize
1345\begin{verbatim}
1346WARNING FROM ROUTINE histvar_seq   
1347 --> There were 10 errors in the learned sequence of variables 
1348 --> for file   4
1349 --> This looks like a bug, please report it.
1350\end{verbatim}
1351}}\end{alltt} 
1352
1353Don't worry, there is no bug, everything is properly working!
1354
1355     }      %end  \gmcomment
1356% ================================================================
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
Note: See TracBrowser for help on using the repository browser.