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 NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/doc/latex/NEMO/subfiles – NEMO

source: NEMO/branches/2019/dev_r10984_HPC-13_IRRMANN_BDY_optimization/doc/latex/NEMO/subfiles/chap_misc.tex @ 11263

Last change on this file since 11263 was 11263, checked in by smasson, 5 years ago

dev_r10984_HPC-13 : merge with trunk@11242, see #2285

File size: 20.6 KB
Line 
1\documentclass[../main/NEMO_manual]{subfiles}
2
3\begin{document}
4% ================================================================
5% Chapter --- Miscellaneous Topics
6% ================================================================
7\chapter{Miscellaneous Topics}
8\label{chap:MISC}
9
10\minitoc
11
12\newpage
13
14% ================================================================
15% Representation of Unresolved Straits
16% ================================================================
17\section{Representation of unresolved straits}
18\label{sec:MISC_strait}
19
20In climate modeling, it often occurs that a crucial connections between water masses is broken as
21the grid mesh is too coarse to resolve narrow straits.
22For example, coarse grid spacing typically closes off the Mediterranean from the Atlantic at
23the Strait of Gibraltar.
24In this case, it is important for climate models to include the effects of salty water entering the Atlantic from
25the Mediterranean.
26Likewise, it is important for the Mediterranean to replenish its supply of water from the Atlantic to
27balance the net evaporation occurring over the Mediterranean region.
28This problem occurs even in eddy permitting simulations.
29For example, in ORCA 1/4\deg several straits of the Indonesian archipelago (Ombai, Lombok...)
30are much narrow than even a single ocean grid-point.
31
32We describe briefly here the three methods that can be used in \NEMO to handle such improperly resolved straits.
33The first two consist of opening the strait by hand while ensuring that the mass exchanges through
34the strait are not too large by either artificially reducing the surface of the strait grid-cells or,
35locally increasing the lateral friction.
36In the third one, the strait is closed but exchanges of mass, heat and salt across the land are allowed.
37Note that such modifications are so specific to a given configuration that no attempt has been made to
38set them in a generic way.
39However, examples of how they can be set up is given in the ORCA 2\deg and 0.5\deg configurations.
40For example, for details of implementation in ORCA2, search: \texttt{IF( cp\_cfg == "orca" .AND. jp\_cfg == 2 )}
41
42% -------------------------------------------------------------------------------------------------------------
43%       Hand made geometry changes
44% -------------------------------------------------------------------------------------------------------------
45\subsection{Hand made geometry changes}
46\label{subsec:MISC_strait_hand}
47
48$\bullet$ reduced scale factor in the cross-strait direction to a value in better agreement with
49the true mean width of the strait (\autoref{fig:MISC_strait_hand}).
50This technique is sometime called "partially open face" or "partially closed cells".
51The key issue here is only to reduce the faces of $T$-cell
52(\ie change the value of the horizontal scale factors at $u$- or $v$-point) but not the volume of the $T$-cell.
53Indeed, reducing the volume of strait $T$-cell can easily produce a numerical instability at
54that grid point that would require a reduction of the model time step.
55The changes associated with strait management are done in \mdl{domhgr},
56just after the definition or reading of the horizontal scale factors.
57
58$\bullet$ increase of the viscous boundary layer thickness by local increase of the fmask value at the coast
59(\autoref{fig:MISC_strait_hand}).
60This is done in \mdl{dommsk} together with the setting of the coastal value of fmask (see  \autoref{sec:LBC_coast}).
61
62%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
63\begin{figure}[!tbp]
64  \begin{center}
65    \includegraphics[width=\textwidth]{Fig_Gibraltar}
66    \includegraphics[width=\textwidth]{Fig_Gibraltar2}
67    \caption{
68      \protect\label{fig:MISC_strait_hand}
69      Example of the Gibraltar strait defined in a $1^{\circ} \times 1^{\circ}$ mesh.
70      \textit{Top}: using partially open cells.
71      The meridional scale factor at $v$-point is reduced on both sides of the strait to account for
72      the real width of the strait (about 20 km).
73      Note that the scale factors of the strait $T$-point remains unchanged.
74      \textit{Bottom}: using viscous boundary layers.
75      The four fmask parameters along the strait coastlines are set to a value larger than 4,
76      \ie "strong" no-slip case (see \autoref{fig:LBC_shlat}) creating a large viscous boundary layer that
77      allows a reduced transport through the strait.
78    }
79  \end{center}
80\end{figure}
81%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
82
83%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
84\begin{figure}[!tbp]
85  \begin{center}
86    \includegraphics[width=\textwidth]{Fig_closea_mask_example}
87    \caption{
88      \protect\label{fig:closea_mask_example}
89      Example of mask fields for the closea module. \textit{Left}: a
90      closea\_mask field; \textit{Right}: a closea\_mask\_rnf
91      field. In this example, if ln\_closea is set to .true., the mean
92      freshwater flux over each of the American Great Lakes will be
93      set to zero, and the total residual for all the lakes, if
94      negative, will be put into the St Laurence Seaway in the area
95      shown.
96    }
97  \end{center}
98\end{figure}
99%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
100
101% ================================================================
102% Closed seas
103% ================================================================
104\section[Closed seas (\textit{closea.F90})]
105{Closed seas (\protect\mdl{closea})}
106\label{sec:MISC_closea}
107
108Some configurations include inland seas and lakes as ocean
109points. This is particularly the case for configurations that are
110coupled to an atmosphere model where one might want to include inland
111seas and lakes as ocean model points in order to provide a better
112bottom boundary condition for the atmosphere. However there is no
113route for freshwater to run off from the lakes to the ocean and this
114can lead to large drifts in the sea surface height over the lakes. The
115closea module provides options to either fill in closed seas and lakes
116at run time, or to set the net surface freshwater flux for each lake
117to zero and put the residual flux into the ocean.
118
119Prior to NEMO 4 the locations of inland seas and lakes was set via
120hardcoded indices for various ORCA configurations. From NEMO 4 onwards
121the inland seas and lakes are defined using mask fields in the
122domain configuration file. The options are as follows.
123
124\begin{enumerate}
125\item{{\bfseries No ``closea\_mask'' field is included in domain configuration
126  file.} In this case the closea module does nothing.}
127
128\item{{\bfseries A field called closea\_mask is included in the domain
129configuration file and ln\_closea=.false. in namelist namcfg.} In this
130case the inland seas defined by the closea\_mask field are filled in
131(turned to land points) at run time. That is every point in
132closea\_mask that is nonzero is set to be a land point.}
133
134\item{{\bfseries A field called closea\_mask is included in the domain
135configuration file and ln\_closea=.true. in namelist namcfg.} Each
136inland sea or group of inland seas is set to a positive integer value
137in the closea\_mask field (see Figure \ref{fig:closea_mask_example}
138for an example). The net surface flux over each inland sea or group of
139inland seas is set to zero each timestep and the residual flux is
140distributed over the global ocean (ie. all ocean points where
141closea\_mask is zero).}
142
143\item{{\bfseries Fields called closea\_mask and closea\_mask\_rnf are
144included in the domain configuration file and ln\_closea=.true. in
145namelist namcfg.} This option works as for option 3, except that if
146the net surface flux over an inland sea is negative (net
147precipitation) it is put into the ocean at specified runoff points. A
148net positive surface flux (net evaporation) is still spread over the
149global ocean. The mapping from inland seas to runoff points is defined
150by the closea\_mask\_rnf field. Each mapping is defined by a positive
151integer value for the inland sea(s) and the corresponding runoff
152points. An example is given in Figure
153\ref{fig:closea_mask_example}. If no mapping is provided for a
154particular inland sea then the residual is spread over the global
155ocean.}
156
157\item{{\bfseries Fields called closea\_mask and closea\_mask\_emp are
158included in the domain configuration file and ln\_closea=.true. in
159namelist namcfg.} This option works the same as option 4 except that
160the nonzero net surface flux is sent to the ocean at the specified
161runoff points regardless of whether it is positive or negative. The
162mapping from inland seas to runoff points in this case is defined by
163the closea\_mask\_emp field.}
164\end{enumerate}
165
166There is a python routine to create the closea\_mask fields and append
167them to the domain configuration file in the utils/tools/DOMAINcfg directory.
168
169% ================================================================
170% Sub-Domain Functionality
171% ================================================================
172\section{Sub-domain functionality}
173\label{sec:MISC_zoom}
174
175\subsection{Simple subsetting of input files via NetCDF attributes}
176
177The extended grids for use with the under-shelf ice cavities will result in redundant rows around Antarctica if
178the ice cavities are not active.
179A simple mechanism for subsetting input files associated with the extended domains has been implemented to
180avoid the need to maintain different sets of input fields for use with or without active ice cavities.
181The existing 'zoom' options are overly complex for this task and marked for deletion anyway.
182This alternative subsetting operates for the j-direction only and works by optionally looking for and
183using a global file attribute (named: \np{open\_ocean\_jstart}) to determine the starting j-row for input.
184The use of this option is best explained with an example:
185consider an ORCA1 configuration using the extended grid bathymetry and coordinate files:
186\vspace{-10pt}
187\ifile{eORCA1\_bathymetry\_v2}
188\ifile{eORCA1\_coordinates}
189\noindent These files define a horizontal domain of 362x332.
190Assuming the first row with open ocean wet points in the non-isf bathymetry for this set is row 42
191(\fortran indexing) then the formally correct setting for \np{open\_ocean\_jstart} is 41.
192Using this value as the first row to be read will result in a 362x292 domain which is the same size as
193the original ORCA1 domain.
194Thus the extended coordinates and bathymetry files can be used with all the original input files for ORCA1 if
195the ice cavities are not active (\np{ln\_isfcav = .false.}).
196Full instructions for achieving this are:
197
198\noindent Add the new attribute to any input files requiring a j-row offset, i.e:
199\vspace{-10pt}
200\begin{cmds}
201ncatted  -a open_ocean_jstart,global,a,d,41 eORCA1_coordinates.nc
202ncatted  -a open_ocean_jstart,global,a,d,41 eORCA1_bathymetry_v2.nc
203\end{cmds}
204 
205\noindent Add the logical switch to \ngn{namcfg} in the configuration namelist and set true:
206%--------------------------------------------namcfg--------------------------------------------------------
207
208\nlst{namcfg}
209%--------------------------------------------------------------------------------------------------------------
210
211\noindent Note the j-size of the global domain is the (extended j-size minus \np{open\_ocean\_jstart} + 1 ) and
212this must match the size of all datasets other than bathymetry and coordinates currently.
213However the option can be extended to any global, 2D and 3D, netcdf, input field by adding the:
214\vspace{-10pt}
215\begin{forlines}
216lrowattr=ln_use_jattr
217\end{forlines}
218optional argument to the appropriate \np{iom\_get} call and the \np{open\_ocean\_jstart} attribute to
219the corresponding input files.
220It remains the users responsibility to set \np{jpjdta} and \np{jpjglo} values in
221the \np{namelist\_cfg} file according to their needs.
222
223%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
224\begin{figure}[!ht]
225  \begin{center}
226    \includegraphics[width=\textwidth]{Fig_LBC_zoom}
227    \caption{
228      \protect\label{fig:LBC_zoom}
229      Position of a model domain compared to the data input domain when the zoom functionality is used.
230    }
231  \end{center}
232\end{figure}
233%>>>>>>>>>>>>>>>>>>>>>>>>>>>>
234
235
236% ================================================================
237% Accuracy and Reproducibility
238% ================================================================
239\section[Accuracy and reproducibility (\textit{lib\_fortran.F90})]
240{Accuracy and reproducibility (\protect\mdl{lib\_fortran})}
241\label{sec:MISC_fortran}
242
243\subsection[Issues with intrinsinc SIGN function (\texttt{\textbf{key\_nosignedzero}})]
244{Issues with intrinsinc SIGN function (\protect\key{nosignedzero})}
245\label{subsec:MISC_sign}
246
247The SIGN(A, B) is the \fortran intrinsic function delivers the magnitude of A with the sign of B.
248For example, SIGN(-3.0,2.0) has the value 3.0.
249The problematic case is when the second argument is zero, because, on platforms that support IEEE arithmetic,
250zero is actually a signed number.
251There is a positive zero and a negative zero.
252
253In \fninety, the processor was required always to deliver a positive result for SIGN(A, B) if B was zero.
254Nevertheless, in \fninety, the processor is allowed to do the correct thing and deliver ABS(A) when
255B is a positive zero and -ABS(A) when B is a negative zero.
256This change in the specification becomes apparent only when B is of type real, and is zero,
257and the processor is capable of distinguishing between positive and negative zero,
258and B is negative real zero.
259Then SIGN delivers a negative result where, under \fninety rules, it used to return a positive result.
260This change may be especially sensitive for the ice model,
261so we overwrite the intrinsinc function with our own function simply performing :   \\
262\verb?   IF( B >= 0.e0 ) THEN   ;   SIGN(A,B) = ABS(A)  ?    \\
263\verb?   ELSE                   ;   SIGN(A,B) =-ABS(A)     ?  \\
264\verb?   ENDIF    ? \\
265This feature can be found in \mdl{lib\_fortran} module and is effective when \key{nosignedzero} is defined.
266We use a CPP key as the overwritting of a intrinsic function can present performance issues with
267some computers/compilers.
268
269
270\subsection{MPP reproducibility}
271\label{subsec:MISC_glosum}
272
273The numerical reproducibility of simulations on distributed memory parallel computers is a critical issue.
274In particular, within NEMO global summation of distributed arrays is most susceptible to rounding errors,
275and their propagation and accumulation cause uncertainty in final simulation reproducibility on
276different numbers of processors.
277To avoid so, based on \citet{he.ding_JS01} review of different technics,
278we use a so called self-compensated summation method.
279The idea is to estimate the roundoff error, store it in a buffer, and then add it back in the next addition.
280
281Suppose we need to calculate $b = a_1 + a_2 + a_3$.
282The following algorithm will allow to split the sum in two
283($sum_1 = a_{1} + a_{2}$ and $b = sum_2 = sum_1 + a_3$) with exactly the same rounding errors as
284the sum performed all at once.
285\begin{align*}
286   sum_1 \ \  &= a_1 + a_2 \\
287   error_1     &= a_2 + ( a_1 - sum_1 ) \\
288   sum_2 \ \  &= sum_1 + a_3 + error_1 \\
289   error_2     &= a_3 + error_1 + ( sum_1 - sum_2 ) \\
290   b \qquad \ &= sum_2 \\
291\end{align*}
292An example of this feature can be found in \mdl{lib\_fortran} module.
293It is systematicallt used in glob\_sum function (summation over the entire basin excluding duplicated rows and
294columns due to cyclic or north fold boundary condition as well as overlap MPP areas).
295The self-compensated summation method should be used in all summation in i- and/or j-direction.
296See \mdl{closea} module for an example.
297Note also that this implementation may be sensitive to the optimization level.
298
299\subsection{MPP scalability}
300\label{subsec:MISC_mppsca}
301
302The default method of communicating values across the north-fold in distributed memory applications (\key{mpp\_mpi})
303uses a \textsc{MPI\_ALLGATHER} function to exchange values from each processing region in
304the northern row with every other processing region in the northern row.
305This enables a global width array containing the top 4 rows to be collated on every northern row processor and then
306folded with a simple algorithm.
307Although conceptually simple, this "All to All" communication will hamper performance scalability for
308large numbers of northern row processors.
309From version 3.4 onwards an alternative method is available which only performs direct "Peer to Peer" communications
310between each processor and its immediate "neighbours" across the fold line.
311This is achieved by using the default \textsc{MPI\_ALLGATHER} method during initialisation to
312help identify the "active" neighbours.
313Stored lists of these neighbours are then used in all subsequent north-fold exchanges to
314restrict exchanges to those between associated regions.
315The collated global width array for each region is thus only partially filled but is guaranteed to
316be set at all the locations actually required by each individual for the fold operation.
317This alternative method should give identical results to the default \textsc{ALLGATHER} method and
318is recommended for large values of \np{jpni}.
319The new method is activated by setting \np{ln\_nnogather} to be true (\ngn{nammpp}).
320The reproducibility of results using the two methods should be confirmed for each new,
321non-reference configuration.
322
323% ================================================================
324% Model optimisation, Control Print and Benchmark
325% ================================================================
326\section{Model optimisation, control print and benchmark}
327\label{sec:MISC_opt}
328%--------------------------------------------namctl-------------------------------------------------------
329
330\nlst{namctl} 
331%--------------------------------------------------------------------------------------------------------------
332
333Options are defined through the  \ngn{namctl} namelist variables.
334
335\subsection{Vector optimisation}
336
337\key{vectopt\_loop} enables the internal loops to collapse.
338This is very a very efficient way to increase the length of vector calculations and thus
339to speed up the model on vector computers.
340 
341% Add here also one word on NPROMA technique that has been found useless, since compiler have made significant progress during the last decade.
342 
343% Add also one word on NEC specific optimisation (Novercheck option for example)
344 
345\subsection{Control print}
346
347The \np{ln\_ctl} switch was originally used as a debugging option in two modes:
348
349\begin{enumerate}
350\item{\np{ln\_ctl}: compute and print the trends averaged over the interior domain in all TRA, DYN, LDF and
351ZDF modules.
352This option is very helpful when diagnosing the origin of an undesired change in model results. }
353
354\item{also \np{ln\_ctl} but using the nictl and njctl namelist parameters to check the source of differences between
355mono and multi processor runs.}
356\end{enumerate}
357
358However, in recent versions it has also been used to force all processors to assume the
359reporting role. Thus when \np{ln\_ctl} is true all processors produce their own versions
360of files such as: ocean.output, layout.dat, etc.  All such files, beyond the the normal
361reporting processor (narea == 1), are named with a \_XXXX extension to their name, where
362XXXX is a 4-digit area number (with leading zeros, if required). Other reporting files
363such as run.stat (and its netCDF counterpart: run.stat.nc) and tracer.stat contain global
364information and are only ever produced by the reporting master (narea == 1). For version
3654.0 a start has been made to return \np{ln\_ctl} to its original function by introducing
366a new control structure which allows finer control over which files are produced. This
367feature is still evolving but it does already allow the user to: select individually the
368production of run.stat and tracer.stat files and to toggle the production of other files
369on processors other than the reporting master. These other reporters can be a simple
370subset of processors as defined by a minimum, maximum and incremental processor number.
371
372Note, that production of the run.stat and tracer.stat files require global communications.
373For run.stat, these are global min and max operations to find metrics such as the gloabl
374maximum velocity. For tracer.stat these are global sums of tracer fields. To improve model
375performance these operations are disabled by default and, where necessary, any use of the
376global values have been replaced with local calculations. For example, checks on the CFL
377criterion are now done on the local domain and only reported if a breach is detected.
378
379Experienced users may wish to still monitor this information as a check on model progress.
380If so, the best compromise will be to activate the files with:
381
382\begin{verbatim}
383     sn_cfctl%l_config = .TRUE.
384       sn_cfctl%l_runstat = .TRUE.
385       sn_cfctl%l_trcstat = .TRUE.
386\end{verbatim}
387
388and to use the new time increment setting to ensure the values are collected and reported
389at a suitably long interval. For example:
390
391\begin{verbatim}     
392       sn_cfctl%ptimincr  = 25
393\end{verbatim}
394
395will carry out the global communications and write the information every 25 timesteps. This
396increment also applies to the time.step file which is otherwise updated every timestep.
397
398% ================================================================
399\biblio
400
401\pindex
402
403\end{document}
Note: See TracBrowser for help on using the repository browser.