Index: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/doc/latex/NEMO/subfiles/apdx_DOMAINcfg.tex
===================================================================
--- NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/doc/latex/NEMO/subfiles/apdx_DOMAINcfg.tex	(revision 14200)
+++ NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/doc/latex/NEMO/subfiles/apdx_DOMAINcfg.tex	(revision 14644)
@@ -6,8 +6,4 @@
 \label{apdx:DOMCFG}
 
-%    {\em 4.0} & {\em Andrew Coward} & {\em Created at v4.0 from materials removed from chap\_DOM that are still relevant to the \forcode{DOMAINcfg} tool and which illustrate and explain the choices to be made by the user when setting up new domains }  \\
-
-\thispagestyle{plain}
-
 \chaptertoc
 
@@ -16,10 +12,10 @@
 {\footnotesize
   \begin{tabularx}{\textwidth}{l||X|X}
-    Release & Author(s) & Modifications \\
-    \hline
-    {\em   4.0} & {\em ...} & {\em ...} \\
-    {\em   3.6} & {\em ...} & {\em ...} \\
-    {\em   3.4} & {\em ...} & {\em ...} \\
-    {\em <=3.4} & {\em ...} & {\em ...}
+    Release     & Author(s)            & Modifications                                                 \\
+    \hline
+    {\em  next} & {\em Pierre Mathiot} & {\em Add ice shelf and closed sea option description        } \\
+    {\em   4.0} & {\em  Andrew Coward} & {\em Creation from materials removed from \autoref{chap:DOM}
+                                              that are still relevant to the DOMAINcfg tool
+                                              when setting up new domains                            }
   \end{tabularx}
 }
@@ -46,5 +42,4 @@
 
 \begin{listing}
-%  \nlst{namdom_domcfg}
   \begin{forlines}
 !-----------------------------------------------------------------------
@@ -91,5 +86,5 @@
  \item [{\np{jphgr_mesh}{jphgr\_mesh}=0}]  The most general curvilinear orthogonal grids.
   The coordinates and their first derivatives with respect to $i$ and $j$ are provided
-  in a input file (\ifile{coordinates}), read in \rou{hgr\_read} subroutine of the domhgr module.
+  in a input file (\textit{coordinates.nc}), read in \rou{hgr\_read} subroutine of the domhgr module.
   This is now the only option available within \NEMO\ itself from v4.0 onwards.
 \item [{\np{jphgr_mesh}{jphgr\_mesh}=1 to 5}] A few simple analytical grids are provided (see below).
@@ -156,6 +151,6 @@
 The reference coordinate transformation $z_0(k)$ defines the arrays $gdept_0$ and
 $gdepw_0$ for $t$- and $w$-points, respectively. See \autoref{sec:DOMCFG_sco} for the
-S-coordinate options.  As indicated on \autoref{fig:DOM_index_vert} \jp{jpk} is the number of
-$w$-levels.  $gdepw_0(1)$ is the ocean surface.  There are at most \jp{jpk}-1 $t$-points
+S-coordinate options.  As indicated on \autoref{fig:DOM_index_vert} \texttt{jpk} is the number of
+$w$-levels.  $gdepw_0(1)$ is the ocean surface.  There are at most \texttt{jpk}-1 $t$-points
 inside the ocean, the additional $t$-point at $jk = jpk$ is below the sea floor and is not
 used.  The vertical location of $w$- and $t$-levels is defined from the analytic
@@ -167,5 +162,5 @@
 
 It is possible to define a simple regular vertical grid by giving zero stretching
-(\np[=0]{ppacr}{ppacr}).  In that case, the parameters \jp{jpk} (number of $w$-levels)
+(\np[=0]{ppacr}{ppacr}).  In that case, the parameters \texttt{jpk} (number of $w$-levels)
 and \np{pphmax}{pphmax} (total ocean depth in meters) fully define the grid.
 
@@ -179,5 +174,5 @@
 \end{gather}
 
-where $k = 1$ to \jp{jpk} for $w$-levels and $k = 1$ to $k = 1$ for $t-$levels.  Such an
+where $k = 1$ to \texttt{jpk} for $w$-levels and $k = 1$ to $k = 1$ for $t-$levels.  Such an
 expression allows us to define a nearly uniform vertical location of levels at the ocean
 top and bottom with a smooth hyperbolic tangent transition in between (\autoref{fig:DOMCFG_zgr}).
@@ -227,5 +222,5 @@
 \end{equation}
 
-With the choice of the stretching $h_{cr} = 3$ and the number of levels \jp{jpk}~$= 31$,
+With the choice of the stretching $h_{cr} = 3$ and the number of levels \texttt{jpk}~$= 31$,
 the four coefficients $h_{sur}$, $h_0$, $h_1$, and $h_{th}$ in
 \autoref{eq:DOMCFG_zgr_ana_2} have been determined such that \autoref{eq:DOMCFG_zgr_coef}
@@ -245,5 +240,5 @@
   Values from $3$ to $10$ are usual.
 \item \np{ppkth}{ppkth}~$= h_{th}$: is approximately the model level at which maximum stretching occurs
-  (nondimensional, usually of order 1/2 or 2/3 of \jp{jpk})
+  (nondimensional, usually of order 1/2 or 2/3 of \texttt{jpk})
 \item \np{ppdzmin}{ppdzmin}: minimum thickness for the top layer (in meters).
 \item \np{pphmax}{pphmax}: total depth of the ocean (meters).
@@ -251,5 +246,5 @@
 
 As an example, for the $45$ layers used in the DRAKKAR configuration those parameters are:
-\jp{jpk}~$= 46$, \np{ppacr}{ppacr}~$= 9$, \np{ppkth}{ppkth}~$= 23.563$, \np{ppdzmin}{ppdzmin}~$= 6~m$,
+\texttt{jpk}~$= 46$, \np{ppacr}{ppacr}~$= 9$, \np{ppkth}{ppkth}~$= 23.563$, \np{ppdzmin}{ppdzmin}~$= 6~m$,
 \np{pphmax}{pphmax}~$= 5750~m$.
 
@@ -346,5 +341,5 @@
   This is meant for the "EEL-R5" configuration, a periodic or open boundary channel with a seamount.
 \item [{\np[=1]{nn_bathy}{nn\_bathy}}]: read a bathymetry and ice shelf draft (if needed).
-  The \ifile{bathy\_meter} file (Netcdf format) provides the ocean depth (positive, in meters) at
+  The \textit{bathy\_meter.nc} file (Netcdf format) provides the ocean depth (positive, in meters) at
   each grid point of the model grid.
   The bathymetry is usually built by interpolating a standard bathymetry product (\eg\ ETOPO2) onto
@@ -352,9 +347,4 @@
   Defining the bathymetry also defines the coastline: where the bathymetry is zero,
   no wet levels are defined (all levels are masked).
-
-  The \ifile{isfdraft\_meter} file (Netcdf format) provides the ice shelf draft (positive, in meters) at
-  each grid point of the model grid.
-  This file is only needed if \np[=.true.]{ln_isfcav}{ln\_isfcav}.
-  Defining the ice shelf draft will also define the ice shelf edge and the grounding line position.
 \end{description}
 
@@ -396,8 +386,8 @@
 bathymetry varies by less than one level thickness from one grid point to the next).  The
 reference layer thicknesses $e_{3t}^0$ have been defined in the absence of bathymetry.
-With partial steps, layers from 1 to \jp{jpk}-2 can have a thickness smaller than
+With partial steps, layers from 1 to \texttt{jpk-2} can have a thickness smaller than
 $e_{3t}(jk)$.
 
-The model deepest layer (\jp{jpk}-1) is allowed to have either a smaller or larger
+The model deepest layer (\texttt{jpk-1}) is allowed to have either a smaller or larger
 thickness than $e_{3t}(jpk)$: the maximum thickness allowed is $2*e_{3t}(jpk - 1)$.
 
@@ -418,5 +408,4 @@
 
 \begin{listing}
-%  \nlst{namzgr_sco_domcfg}
   \caption{\forcode{&namzgr_sco_domcfg}}
   \label{lst:namzgr_sco_domcfg}
@@ -592,4 +581,145 @@
 This option is described in the Report by Levier \textit{et al.} (2007), available on the \NEMO\ web site.
 
+\section{Ice shelf cavity definition}
+\label{subsec:zgrisf}
+
+  If the under ice shelf seas are opened (\np{ln_isfcav}{ln\_isfcav}), the depth of the ice shelf/ocean interface has to be include in 
+  the \textit{isfdraft\_meter} file (Netcdf format). This file need to include the \textit{isf\_draft} variable. 
+  A positive value will mean ice shelf/ocean or ice shelf bedrock interface below the reference 0m ssh. 
+  The exact shape of the ice shelf cavity (grounding line position and minimum thickness of the water column under an ice shelf, ...) can be specify in \nam{zgr_isf}{zgr\_isf}.
+
+\begin{listing}
+  \caption{\forcode{&namzgr_isf}}
+  \label{lst:namzgr_isf}
+  \begin{forlines}
+!-----------------------------------------------------------------------
+&namzgr_isf    !   isf cavity geometry definition                       (default: OFF)
+!-----------------------------------------------------------------------
+   rn_isfdep_min    = 10.         ! minimum isf draft tickness (if lower, isf draft set to this value)
+   rn_glhw_min      = 1.e-3       ! minimum water column thickness to define the grounding line
+   rn_isfhw_min     = 10          ! minimum water column thickness in the cavity once the grounding line defined.
+   ln_isfchannel    = .false.     ! remove channel (based on 2d mask build from isfdraft-bathy)
+   ln_isfconnect    = .false.     ! force connection under the ice shelf (based on 2d mask build from isfdraft-bathy)
+      nn_kisfmax       = 999         ! limiter in level on the previous condition. (if change larger than this number, get back to value before we enforce the connection)
+      rn_zisfmax       = 7000.       ! limiter in m     on the previous condition. (if change larger than this number, get back to value before we enforce the connection)
+   ln_isfcheminey   = .false.     ! close cheminey
+   ln_isfsubgl      = .false.     ! remove subglacial lake created by the remapping process
+      rn_isfsubgllon   =    0.0      !  longitude of the seed to determine the open ocean
+      rn_isfsubgllat   =    0.0      !  latitude  of the seed to determine the open ocean
+/
+  \end{forlines}
+\end{listing}
+
+   The options available to define the shape of the under ice shelf cavities are listed in \nam{zgr_isf}{zgr\_isf} (\texttt{DOMAINcfg} only, \autoref{lst:namzgr_isf}).
+
+\subsection{Model ice shelf draft definition}
+\label{subsec:zgrisf_isfd}
+
+First of all, the tool make sure, the ice shelf draft ($h_{isf}$) is sensible and compatible with the bathymetry.
+There are 3 compulsory steps to achieve this:
+
+\begin{description}
+\item{\np{rn_isfdep_min}{rn\_isfdep\_min}:} this is the minimum ice shelf draft. This is to make sure there is no ridiculous thin ice shelf. If \np{rn_isfdep_min}{rn\_isfdep\_min} is smaller than the surface level, \np{rn_isfdep_min}{rn\_isfdep\_min} is set to $e3t\_1d(1)$. 
+  Where $h_{isf} < MAX(e3t\_1d(1),rn\_isfdep\_min)$, $h_{isf}$ is set to \np{rn_isfdep_min}{rn\_isfdep\_min}.
+
+\item{\np{rn_glhw_min}{rn\_glhw\_min}:} This parameter is used to define the grounding line position.
+  Where the difference between the bathymetry and the ice shelf draft is smaller than \np{rn_glhw_min}{rn\_glhw\_min}, the cell are grounded (ie masked). 
+  This step is needed to take into account possible small mismatch between ice shelf draft value and bathymetry value (sources are coming from different grid, different data processes, rounding error, ...).
+
+\item{\np{rn_isfhw_min}{rn\_isfhw\_min}:} This parameter is the minimum water column thickness in the cavity. 
+  Where the water column thickness is lower than \np{rn_isfhw_min}{rn\_isfhw\_min}, the ice shelf draft is adjusted to match this criterion. 
+  If for any reason, this adjustement break the minimum ice shelf draft allowed (\np{rn_isfdep_min}{rn\_isfdep\_min}), the cell is masked.
+\end{description}
+
+Once all these adjustements are made, if the water column thickness contains one cell wide channels, these channels can be closed using \np{ln_isfchannel}{ln\_isfchannel}.  
+ 
+\subsection{Model top level definition}
+After the definition of the ice shelf draft, the tool defines the top level. 
+The compulsory criterion is that the water column needs at least 2 wet cells in the water column at U- and V-points.
+To do so, if there one cell wide water column, the tools adjust the ice shelf draft to fillful the requierement.\\
+
+The process is the following:
+\begin{description}
+\item{step 1:} The top level is defined in the same way as the bottom level is defined.
+\item{step 2:} The isolated grid point in the bathymetry are filled (as it is done in a domain without ice shelf)
+\item{step 3:} The tools make sure, the top level is above or equal to the bottom level
+\item{step 4:} If the water column at a U- or V- point is one wet cell wide, the ice shelf draft is adjusted. So the actual top cell become fully open and the new
+  top cell thickness is set to the minimum cell thickness allowed (following the same logic as for the bottom partial cell). This step is iterated 4 times to ensure the condition is fullfill along the 4 sides of the cell.
+\end{description}
+
+In case of steep slope and shallow water column, it likely that 2 cells are disconnected (bathymetry above its neigbourging ice shelf draft). 
+The option \np{ln_isfconnect}{ln\_isfconnect} allow the tool to force the connection between these 2 cells.
+Some limiters in meter or levels on the digging allowed by the tool are available (respectively, \np{rn_zisfmax}{rn\_zisfmax} or \np{rn_kisfmax}{rn\_kisfmax}).
+This will prevent the formation of subglacial lakes at the expense of long vertical pipe to connect cells at very different levels.
+
+\subsection{Subglacial lakes}
+Despite careful setting of your ice shelf draft and bathymetry input file as well as setting described in \autoref{subsec:zgrisf_isfd}, some situation are unavoidable.
+For exemple if you setup your ice shelf draft and bathymetry to do ocean/ice sheet coupling, 
+you may decide to fill the whole antarctic with a bathymetry and an ice shelf draft value (ice/bedrock interface depth when grounded). 
+If you do so, the subglacial lakes will show up (Vostock for example). An other possibility is with coarse vertical resolution, some ice shelves could be cut in 2 parts: 
+one connected to the main ocean and an other one closed which can be considered as a subglacial sea be the model.\\
+
+The namelist option \np{ln_isfsubgl}{ln\_isfsubgl} allow you to remove theses subglacial lakes.
+This may be useful for esthetical reason or for stability reasons:
+
+\begin{description}
+\item $\bullet$ In a subglacial lakes, in case of very weak circulation (often the case), the only heat flux is the conductive heat flux through the ice sheet. 
+  This will lead to constant freezing until water reaches -20C. 
+  This is one of the defitiency of the 3 equation melt formulation (for details on this formulation, see: \autoref{sec:isf}).
+\item $\bullet$ In case of coupling with an ice sheet model, 
+  the ssh in the subglacial lakes and the main ocean could be very different (ssh initial adjustement for example), 
+  and so if for any reason both a connected at some point, the model is likely to fall over.\\
+\end{description}
+
+\section{Closed sea definition}
+\label{sec:clocfg}
+
+\begin{listing}
+  \caption{\forcode{&namclo}}
+  \label{lst:namdom_clo}
+  \begin{forlines}
+!-----------------------------------------------------------------------
+&namclo ! (closed sea : need ln_domclo = .true. in namcfg)
+!-----------------------------------------------------------------------
+   rn_lon_opnsea = -2.0     ! longitude seed of open ocean
+   rn_lat_opnsea = -2.0     ! latitude  seed of open ocean
+   nn_closea = 8           ! number of closed seas ( = 0; only the open_sea mask will be computed)
+   !                name   ! lon_src ! lat_src ! lon_trg ! lat_trg ! river mouth area   ! net evap/precip correction scheme ! radius tgt   ! id trg
+   !                       ! (degree)! (degree)! (degree)! (degree)! local/coast/global ! (glo/rnf/emp)                     !     (m)      !
+   ! North American lakes
+   sn_lake(1) = 'superior' ,  -86.57 ,  47.30  , -66.49  , 50.45   , 'local'            , 'rnf'                             ,   550000.0 , 2    
+   sn_lake(2) = 'michigan' ,  -87.06 ,  42.74  , -66.49  , 50.45   , 'local'            , 'rnf'                             ,   550000.0 , 2    
+   sn_lake(3) = 'huron'    ,  -82.51 ,  44.74  , -66.49  , 50.45   , 'local'            , 'rnf'                             ,   550000.0 , 2    
+   sn_lake(4) = 'erie'     ,  -81.13 ,  42.25  , -66.49  , 50.45   , 'local'            , 'rnf'                             ,   550000.0 , 2    
+   sn_lake(5) = 'ontario'  ,  -77.72 ,  43.62  , -66.49  , 50.45   , 'local'            , 'rnf'                             ,   550000.0 , 2    
+   ! African Lake
+   sn_lake(6) = 'victoria' ,   32.93 ,  -1.08  ,  30.44  , 31.37   , 'coast'            , 'emp'                             ,   100000.0 , 3    
+   ! Asian Lakes
+   sn_lake(7) = 'caspian'  ,   50.0  ,  44.0   ,   0.0   ,  0.0    , 'global'           , 'glo'                             ,        0.0 , 1     
+   sn_lake(8) = 'aral'     ,   60.0  ,  45.0   ,   0.0   ,  0.0    , 'global'           , 'glo'                             ,        0.0 , 1    
+/
+   \end{forlines}
+\end{listing}
+
+The options available to define the closed seas and how closed sea net fresh water input will be redistributed by NEMO are listed in \nam{dom_clo}{dom\_clo} (\texttt{DOMAINcfg} only).
+The individual definition of each closed sea is managed by \np{sn_lake}{sn\_lake}. In this fields the user needs to define:\\
+   \begin{description}
+   \item $\bullet$    the name of the closed sea (print output purposes).
+   \item $\bullet$    the seed location to define the area of the closed sea (if seed on land because not present in this configuration, this closed sea will be ignored).\\
+   \item $\bullet$    the seed location for the target area.
+   \item $\bullet$    the type of target area ('local','coast' or 'global'). See point 6 for definition of these cases.
+   \item $\bullet$    the type of redistribution scheme for the net fresh water flux over the closed sea (as a runoff in a target area, as emp in a target area, as emp globally). For the runoff case, if the net fwf is negative, it will be redistribut globally.
+   \item $\bullet$    the radius of the target area (not used for the 'global' case). So the target defined by a 'local' target area of a radius of 100km, for example, correspond to all the wet points within this radius. The coastal case will return only the coastal point within the specifid radius.
+   \item $\bullet$    the target id. This target id is used to group multiple lakes into the same river ouflow (Great Lakes for example).
+   \end{description}
+
+The closed sea module defines a number of masks in the \textit{domain\_cfg} output:
+   \begin{description}
+   \item[\textit{mask\_opensea}:] a mask of the main ocean without all the closed seas closed. This mask is defined by a flood filling algorithm with an initial seed (localisation defined by \np{rn_lon_opnsea}{rn\_lon\_opnsea} and \np{rn_lat_opnsea}{rn\_lat\_opnsea}).
+   \item[\textit{mask\_csglo}, \textit{mask\_csrnf}, \textit{mask\_csemp}:] a mask of all the closed seas defined in the namelist by \np{sn_lake}{sn\_lake} for each redistribution scheme. The total number of defined closed seas has to be defined in \np{nn_closea}{nn\_closea}.
+   \item[\textit{mask\_csgrpglo}, \textit{mask\_csgrprnf}, \textit{mask\_csgrpemp}:] a mask of all the closed seas and targets grouped by target id for each type of redistribution scheme.
+   \item[\textit{mask\_csundef}:] a mask of all the closed sea not defined in \np{sn_lake}{sn\_lake}. This will allows NEMO to mask them if needed or to inform the user of potential minor issues in its bathymetry.
+   \end{description}
+   
 \subinc{\input{../../global/epilogue}}
 
