\documentclass[a4paper,12pt]{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{January 9-11, 2024}


\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 former section
%\ref{sec:experiments}, split in separate optional tutorials since 2019 (?) 
%\you can either take a closer look at tracers, or aerosols,
%\or the Orchidee model, or change some parameter of the physics, 
%\or learn how to nudge the model towards (wind) fields from ECMWF reanalysis data.

If you have already installed the model with the script \verb+install_lmdz.sh+  
in Tutorial \#1, go directly below to \textbf{"Setting up a simulation...}". 
Otherwise, start by installing the model as follows (same steps as in Tutorial \#1) :\\

If you don't have a working folder named \verb+LMDZ+ in your \verb+home+ directory, then you create it:
\begin{verbatim}
cd 
mkdir LMDZ
\end{verbatim}

Go in this \verb+~/LMDZ+ folder. Download the script \verb+install_lmdz.sh+,  and run it to install the model in sequential mode (default option "parallel=none" in install\_lmdz.sh), in a folder named LMDZseq. The default resolution is 32x32x39 (equivalent to running \verb+install_lmdz.sh+ with the option \verb+"-d 32x32x39"+ )

\begin{verbatim}
cd ~/LMDZ
wget https://lmdz.lmd.jussieu.fr/pub/install_lmdz.sh
chmod +x install_lmdz.sh
./install_lmdz.sh -rad oldrad -name LMDZseq
\end{verbatim}

\textbf{Setting up a simulation with a (regular or) zoomed grid}
\label{sec:setting-up-case}

\begin{itemize}
\item Go to the directory \verb+~/LMDZ/LMDseq/modipsl/modeles/LMDZ+,
  which contains the files \verb+makelmdz_fcm+, \verb+libf+ etc. In this
  directory, download and unpack the \verb+tutorial.tar+ file, then go in the resulting \verb+TUTORIAL+ folder :
\begin{verbatim}
# Normally you are in your  ~/LMDZ folder
cd LMDseq/modipsl/modeles/LMDZ
wget http://lmdz.lmd.jussieu.fr/pub/Training/tutorial.tar
tar -xf tutorial.tar
cd TUTORIAL
\end{verbatim}
\item Examine the content of the \verb+TUTORIAL+ folder : there are some scripts and a DEF directory, all briefly described in the \verb+Readme+ file.
  In the \verb+DEF+ directory, edit the file \verb+gcm.def+ and examine the 
  different parameters defining the grid. 
  
  By default, the defined grid has the zoomed area centered at (0E,45N) 
  
  (\verb+clon=0., clat=45.+)
  and a zoom factor = 2 both in longitude and latitude :
  
  (\verb+grossismx=2., grossismy=2. +).
  
  In order to place the center of the zoom at your preferred location, you just need to change the 
longitude and latitude of the zoom center, \verb+clon+ and \verb+clat+.

If you want to use a regular grid, set \verb+grossismx=1. and grossismy=1. + .


\item Check the following options in in \verb+init.sh+, and change the default value if needed :
\item[$\ast$] As you installed the model in sequential mode, you must have \verb+parallel=0+.
\item[$\ast$] The option for radiative code must be \verb+rad=oldrad+.
\item[$\ast$] For the time being, you will run LMDZ \textbf{without} the surface scheme Orchidee: 
  you must have the option \verb+veg=CMIP6+ .
  The model will be run with a simplified scheme for surface hydrology: the ``bucket'' scheme.
  
\item Skip this step if you run locally :\\
	You may 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 \verb+init.sh+ does the following :
  
  	- (re)compiles the model (\verb+gcm.e+) with resolution 48x36x39 (remember that in tutorial 1 you've used 32x32x39);
  
  	- compiles the program \verb+ce0l.e+, needed to create initial state and boundary conditions for the chosen grid; 
  
  	- downloads input files for \verb+ce0l.e+ (NetCDF files containing surface orography, sea-surface temperature etc.); 
  
  	- 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 will be used to initialize 
a new simulation in a newly-created directory called \verb+SIMU1+. 

Please check that these 3 files have been created in the directory \verb+SIMU1+. If not, ask for our help.  

\item Now edit the file \verb+SIMU1/config.def+, and look at the section "Controle des sorties" (Eng. "Output control").
In the high-frequency NetCDF output file \#3, \verb+histhf.nc+., you'll want to include the variable \verb+pres+, 
containing the pressure at model levels.
To do that, add the following line :
\begin{verbatim}
flag_pres__00003 =           4
\end{verbatim}

\item You can now go in the SIMU1 directory and run the model by executing the command  
\verb+./gcm.e+ (output on screen) or  \verb+./gcm.e > listing1+ (output in file listing1). 
The simulation should end with the message ``Everything is cool'' and the 
output files \verb+histday.nc+, \verb+histmth.nc+ and \verb+histhf.nc+ should be created. 
Make some plots from one of these files.

\end{itemize}

\end{document}
