\documentclass[a4paper]{article}

                                % Packages

\usepackage[utf8]{inputenc}
\usepackage{ifpdf}

\ifpdf
\else
\usepackage[active]{srcltx}
\fi

\usepackage{amsmath}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{geometry}

\usepackage[np]{numprint}

\usepackage{hyperref}
\ifpdf
\hypersetup{pdftitle={Tutorial \#2}, pdfauthor={LMDZ team},
  hypertexnames=false, pdfstartview=FitBH}
\fi

\author{LMDZ team}
\title{Hands on tutorial \#2: Setting up a simulation}
\date{December 1st, 2017}


\geometry{top=2cm,bottom=2cm,left=2.5cm,right=2.5cm}


                                %---------------

\begin{document}

\maketitle
%\tableofcontents
%\medskip

This tutorial focuses on the various steps required
to set up a 3D simulation, and in particular for a
zoomed configuration of LMDZ.

%This tutorial makes use of a zoomed configuration of LMDZ. Section
%\ref{sec:setting-up-case} is an initialization phase. In section
%\ref{sec:experiments}, you can either take a closer look at tracers,
%or the Orchidee model or switch some parameterizations of the physics
%part of the program. The three experiments in section
%\ref{sec:experiments} are independent. In section \ref{sec:nudging},
%you will nudge the model toward analyzed wind fields.

Start by installing the model with the script \verb+install_lmdz.sh+, if
you have not already done so in tutorial \#1 by using:

\begin{verbatim}
wget http://www.lmd.jussieu.fr/~lmdz/pub/install_lmdz.sh
chmod +x install_lmdz.sh
./install_lmdz.sh -d 32x32x39
\end{verbatim}

\section{Setting up a case with a zoomed grid}
\label{sec:setting-up-case}

\begin{itemize}
\item Go to the directory \verb+LMDZtrunk/modipsl/modeles/LMDZ+,
  which contains files \verb+makelmdz_fcm+, \verb+libf+\dots In this
  directory, download the following tar file :
\begin{verbatim}
wget http://www.lmd.jussieu.fr/~lmdz/pub/Training/tutorial.tar
tar -xf tutorial.tar
cd TUTORIAL
\end{verbatim}
\item In the directory \verb+TUTORIAL+, take a look at the extracted files and at the DEF 
  directory. In this directory, you should edit the file called \verb+gcm.def+ if you want to 
place the center of the zoom at your preferred location. For that you just have to change the 
longitude and latitude of the zoom center, \verb+clon+ and \verb+clat+.
\item For the time being, you will run LMDZ without the surface scheme
  Orchidee, edit the \verb+init.sh+ file and set option
  \verb+veget=0+.The model will be run with
  a simplified scheme for surface hydrology: the ``bucket'' scheme.
\item As you installed the model in sequential mode, put parallel=0 in init.sh
\item Increase the stack memory you can use by typing the following
  command:
\begin{verbatim}
ulimit -Ss unlimited
\end{verbatim}
  or, even better, add this command in you shell start-up file (if you
  use Bash, your start-up file can be \verb+.profile+ or
  \verb+.bash_profile+).
\item Run the script :
\begin{verbatim}
./init.sh
\end{verbatim}
  The script first compiles the model (\verb+gcm.e+) again and also compiles the program
  \verb+ce0l.e+, which creates initial state and boundary
  conditions. \verb+init.sh+ then downloads new NetCDF files which
  contain the surface orography, sea-surface temperature, and so on,
  as well as 3D meteorological files taken from ECMWF analyses at a
  particular date. \verb+init.sh+ then runs \verb+ce0l.e+ which
  creates files \verb+start.nc+, \verb+startphy.nc+ and
  \verb+limit.nc+ in a directory called \verb+INITIAL+. These files are then used to initialize 
a new simulation in a directory called \verb+SIMU1+. You can check that these 3 files have 
actually been   created in the directory \verb+SIMU1+. If not, please ask for our help.  
\item If you have the files \verb+start.nc+, \verb+startphy.nc+ and
  \verb+limit.nc+ in your SIMU1 directory, you are almost done. In the file \verb+config.def+,
  add the line:
\begin{verbatim}
flag_pres__00003 =           4
\end{verbatim}
Thus, the NetCDF variable pres, which contains the pressure at model
layers, will be included in the file \#3, \verb+histhf.nc+.
\item You can now run the model by executing the command
  \verb+./gcm.e+. The simulation should end with this message ``Everything is cool'' and the 
output files \verb+histday.nc+, \verb+histmth.nc+ and \verb+histhf.nc+ should be present. Make
some plots from one of these files.
\end{itemize}

%\section{Experiments}
%\label{sec:experiments}
%
%The three subsections \ref{sec:tracers}, \ref{sec:switch-phys-param}
%and \ref{sec:sens-soil-scheme} are independent.
%
%\input{tracers.tex}
%
%\input{physics.tex}
%
%\input{orchid.tex}

\section{Optional: Nudging}
\label{sec:nudging}

This section focuses on using the nudging capabilty with LMDZ.

\begin{itemize}
\item The program \verb+ce0l.e+ (which was run by \verb+init.sh+ in
  the first part of this tutorial) created the file
  \verb+grilles_gcm.nc+ in the \verb+INITIAL+ directory. \verb+grilles_gcm.nc+ 
  contains the longitudes   and latitudes of the model grids (staggered grids for 
zonal wind,   meridional wind and temperature). You can visualize the orography
  map as seen by the zoomed grid, by opening this file with
  \verb+ferret+, \verb+ncview+ or \verb+grads+ and plotting the variable \verb+phis+
  (which, despite its name, actually contains the surface altitude, in
  m). You can also easily plot the horizontal resolution of the model
  as the square root of the grid mesh area (variable \verb+aire+, in
  m$^2$).
\item We will nudge the model with reanalysis fields. The script
  \verb+get_era.sh+, in the directory \verb+TUTO+, gets the
  reanalysis files. Run the script. It will also interpolate the winds
  on the model grid (by reading the model grid from file
  \verb+grilles_gcm.nc+). You should end up with a directory called \verb+GUIDAGE+ 
(nudging in french) that contains two files, \verb+u.nc+ and
  \verb+v.nc+. Note that for this tutorial
  we have given open access to a subset of the ERA-interim wind
  fields.  ERA-interim files are stored at IDRIS, CCRT and Climserv,
  with restricted access. To access these files at IDRIS or on
  Climserv, you should contact Sophie Bouffies-Cloché (IPSL). For
  access at CCRT, contact Anne Cozic (LSCE). \verb+get_era.sh+ is a
  very simplified script for the tutorial, but more general scripts
  are available on the
Subversion server of 
IGCMG:\url{http://forge.ipsl.jussieu.fr/igcmg/browser/CONFIG/LMDZOR/branches/LMDZOR_v4/CREATE/SCRIPT}.  
The file called \verb+era2gcm.ksh+ interpolates the ERA data on the GCM grid.  This 
script can be called by another script (see \verb+interp_from_era.ksh+ for example) 
on multiple months, if you want to run long simulations.
\item Create a new directory, called for 
example \verb+SIMU1_nudged+, which contains all the files you need to run a new 
simulation:

\begin{verbatim}
mkdir SIMU1_nudged
cd SIMU1_nudged
ln -s ../SIMU1/start.nc .
ln -s ../SIMU1/startphy.nc .
ln -s ../SIMU1/limit.nc .
ln -s ../SIMU0/sechiba_rest_out.nc sechiba_rest_in.nc
cp ../SIMU1/*.def .
rm -f used_*.def
\end{verbatim}

Don't forget to also point to the nudging files:

\begin{verbatim}
ln -s ../GUIDAGE/u.nc .
ln -s ../GUIDAGE/v.nc .
\end{verbatim}


\item Take a look at the file \verb+guide.def+. Nudging is activated for
  variables u and v only (as is often the case). The relaxation time
  is set to 3 hours inside the zoomed area (\verb+tau_max=0.125+ days)
  and half an hour outside (\verb+tau_min+=0.0208333 days). The
  smaller the relaxation time, the stronger the nudging. You can
  change the parameters of this file if you want.
\item Add the line:
\begin{verbatim}
INCLUDEDEF=guide.def
\end{verbatim}
  in \verb+run.def+.
\item Run the model again with nudging:
\begin{verbatim}
../gcm.e > listing
\end{verbatim}
\item Make sure that the nudged simulation worked by comparing the winds of the 
outputs with the winds contained in the \verb+u.nc+ and \verb+v.nc+ files. You should 
see the same patterns, for the same time and altitude of course (for example look at 
the first output of the \verb+histhf.nc+ file at the 500~hPa level and compare with 
the first timestep of the \verb+u.nc+ and \verb+v.nc+ files).

\item Compare the results of the simulations with and without nudging.

\end{itemize}

\end{document}
