# Commits

committed 365507a

updated report

• Participants
• Parent commits b1c33b3

# File docs/sm_final_report/sm_final_report.pdf

Binary file modified.

# File docs/sm_final_report/sm_final_report.tex

 \tableofcontents


-\begin{enumerate}
+%\begin{enumerate}
 %  \item problema
 %  \item teoria de oliveira
 %  \item teoria ebner
 %  \item approssimazioni
-  \item algoritmo e implementazione (thread pool)
-  \item risultati (plot vari)
-  \item confronto ebner - de oliveira (fitting potenziale)
-  \item conclusioni (C=2,D=2.2 artificiali per fare il salto)
-\end{enumerate}
+%  \item algoritmo e implementazione (thread pool)
+%  \item risultati (plot vari)
+%  \item confronto ebner - de oliveira (fitting potenziale)
+%  \item conclusioni (C=2,D=2.2 artificiali per fare il salto)
+%\end{enumerate}


 % %%%%%%% %
 \subsection{The Lattice-gas Model}

 The lattice-gas model represents a very useful way for describing the behavior of interacting particles. It consists of a spatial lattice structure $\Lambda$ (squared, HCP, etc.), and for each lattice site $j \in \Lambda$ there is a discrete variable $\sigma_j$ such that $\sigma_j \in \{0, 1\}$; $\sigma_j$ models the fact that a particle is present in the lattice site.
+\begin{figure}[hbt]
+\centering
+  \includegraphics[width=0.4\textwidth]{images/lattice_gas_sample.jpg}
+  \caption{Example of a possible lattice-gas configuration for a model with a simple cubic package. }
+\end{figure}
+
 The total Hamiltonian for the model can be written as:

   H_\sigma = \frac{1}{2} \sum_{i,j}{f(i,j)\sigma_i \sigma_j} + \sum_j g(j)\sigma_j

 % assumptions %
 \subsection{Assumptions}
+\label{section:assumptions}

 De Oliveira and Ebner made slightly different assumption approaching the problem.
 In particular in the paper by De Oliveira and Griffiths it is assumed that:
   \item only the nearest neighbor interactions are considered, and each couple of adjacent occupied cells contribute to the total hamiltonian by an amount $-\epsilon$
   \item the substrate potential is a cubic function, function of the $j$th layer as:

+      \label{math:oliveira_v}
       v_j = \begin{cases} \epsilon D         & j=1 \\
                           \epsilon C/j^{ 3 } & j \ge 2
             \end{cases}
 % formalism %
 % %%%%%%%%% %
 \section{Formalism}
+\label{section:formalism}

 Using a HCP arrangement (refer to \cite{wiki:hcp} for a exhaustive description) the $z$ values of the film layers are:

 it is possible to replace the $\sigma_ni$ by the probability $\rho_n$ that a site in the $n$-th layer is occupied.
 It is then possible to approximate:

+    \label{math:simplified_H}
   H_n \simeq -\frac{1}{2} \epsilon N_n\sum_{n'}{f(n-n') \rho_{n'}} + V_n N_n

 where $f(n-n') = \sum_{i'}f(ni,n'i')$.
 \begin{align}
   y_0 &= \tanh \left[ \frac{1}{2T^*} \left( \frac{f y_0}{2} + \gamma \right) \right] \\
   y_n &= \tanh \left\{ \frac{1}{2T^*} \left[ \frac{1}{2} \sum_{n'=-\infty}^{+\infty}f(n-n')y_{n'} -\left(\tilde{V_n} - \gamma\right) \right] \right\}
+  \label{math:yn_relation}
 \end{align}


 % %%%%%%%%% %
 \section{Algorithm}

-A numerical algorithm has been implemented in C++, to calculate both the isotherm layer coverage and the energy levels of metastable solutions given a target coverage value.
+The equations derived in section \ref{section:formalism} have been implemented in C++.
+The final programs allow to calculate the layer coverage for an isotherm, the energy levels associated to specific coverage ($\theta$) values and the critical temperature diagram (the $\theta - T^*$ plane). They all share some common blocks:
+\begin{itemize}
+  \item the lattice structure representation
+  \item the inter-particle and substrate potentials
+  \item the main algorithm resolution class
+\end{itemize}

-\subsection{HCP class}
-HCP class and limits
+The number of iteration needed to make (\ref{math:yn_relation}) converge can be quite high, especially close to the critical points. Considering also that for each $(T^*,\bar{\mu})$ pair the initial configurations $\{y_{0_n}\}$ must be chosen in a DOE-like approach to allow the algorithm to jump-out' of local minima, it is evident that the problem can be computationally quite taxing.
+
+Fortunately, the problem is also easily parallelizable, by splitting the $[\mu_i , \mu_f]$ range into several, independent, subranges. Each one can then be executed in parallel on a different CPU core. The approach chosen in the programs is the \textit{thread pool} pattern.
+
+% lattice structure %
+\subsection{Lattice structure}
+The lattice site arrangement chosen in both \cite{DeOliveira1978687} and \cite{PhysRevA.22.2776} is the hexagonal closed-packing (\textit{HCP}).
+For a complete explanation of the model, please refer to \cite{wiki:hcp}.
+Since the $f(ni,n'i')$ as used in (\ref{math:simplified_H}) relates a particle in the layer $n$ with all particles at layer $n'$, the class first build an internal representation of the lattice site coordinates, then allow to easily retrieve each particle point given the layer $n$ and the particle index $i$ in the layer.
+The interface is the following:
 
 \begin{lstlisting}
 // HCP lattice, with a set of N layers (A-B-A-B-...);
 \end{lstlisting}
 
 
+% potentials %
 \subsection{Substrate and inter-particle potentials}
-the potentials are implemented by a pure interface class
+
+Since it is needed to investigate both the technique used in \cite{DeOliveira1978687} and \cite{PhysRevA.22.2776}, and they differ essentially in the potentials used (in both range and formulation), a pure interface class has been implemented, exposing the common functionalities. The main algorithm then use that common interface, allowing to simulate both approaches simply replacing the particular potential class instance.
  
 \begin{lstlisting}
 // Pure interface class for the potentials used in the lattice gas models
 class EbnerPotentials:      public Potentials  {...}
 \end{lstlisting}
 
+The derived classes \texttt{DeOliveiraPotentials} and \texttt{EbnerPotentials} then implement the particular potentials as explained in section (\ref{section:assumptions}).
 
+
+% simulation class %
 \subsection{Simulation class}
-and the main class
+
+The main simulation class cal calculate the equilibrium state given the current (normalized) chemical potential $\bar{\mu}/\epsilon$ and the reference (normalized) temperature $T^*$.
+As explained in the previous section, it can be initialized for using either (\ref{math:oliveira_v}) or (\ref{math:ebner_v}) as substrate potential.
 
 \begin{lstlisting}
 // Ebner (generic) approach for solving film formations on a substrate.
 };
 \end{lstlisting}
 
-all functions have been made reentrant, to allow a safe concurrent execution by many threads.
+All the calculation functions have been designed to be reentrant, to allow a safe concurrent execution by many threads.
 
 
+% thread pool %
 \subsection{Thread Pool}
-thread pool implementation
+
+The thread pool pattern consists in a set of worker threads that are created to perform a number of jobs, organized in a queue. 
+As soon as a thread completes its job, it will request the next one from the queue until all tasks have been completed. The thread can then terminate, or sleep until there are new tasks available.
+
+The number of worker threads can be tuned to provide the best performance.
+Figure (\ref{fig:threadpool}) shows the typical structure of a thread pool.
+
 
 The multithread approach is based on a thread pool
 \begin{figure}[hbt]
   \caption{\label{fig:threadpool}Thread pool structure.}
 \end{figure}
 
-the thread pool is filled with jobs to be executed; these jobs are placed in a shared queue, and a set of worker threads continuously execute jobs, until the queue is empty.
-This approach allows the performances to scale (almost) linearly with the number of CPU cores.
+This approach allows the performances to scale (almost) linearly with the number of CPU cores, virtually eliminating the cost associated to the thread context creation/destruction, since the worker thread are created once at the beginning and destroyed at the end of the program.
 
-Each job consists on a function and its supporting data, that have been implemented as in the following fragment.
+Each job consists on a function and its supporting data, that have been implemented as in the following code fragment.
 
 \begin{lstlisting}
 // support struct for the thread job
     SampleData *sd = (SampleData*)data;
     // calc
     double energy = 0.0;
-    double theta = sd->ebner->calc_theta(sd->gamma,300,250,&energy);
-    // set data
+    double theta = sd->ebner->calc_theta(sd->gamma,400,250,&energy);
+    // set final data
     sd->final_theta = theta;
     sd->final_energy = energy;
 }
   \caption{\label{fig:worker_threads}Job distribution on a simulation, split on 8 cores.}
 \end{figure}
 
-In figure (\ref{fig:worker_threads}) there is a graphical representation of a layer coverage simulation, composed by 300 samples. The workload is evenly distributed among 8 threads on a intel i7 quad-core CPU, with 8
+In figure (\ref{fig:worker_threads}) there is a graphical representation of a layer coverage simulation, composed by 300 samples. The workload is evenly distributed among 8 threads on a intel i7 quad-core CPU (each core hosts 2 processing threads).
 The gain in performance, compared to a single-thread execution is approximately 7.5x.
 
-The code is available online, at the address \texttt{https://bitbucket.org/dbacchet/univ} .
-It has been designed to be cross-platform, and tested on Windows7 and Mac OSX 10.8; on Windows, Visual Studio (Express) 2010 or newer and Python 2.7 or newer are required.
 
-An automatic build system takes care of configuring the environment, building the applications and installing the final executables. To run it, type the following commands from a Prompt Shell:
+% code %
+\subsection{Source code repository}
+The source code for all the programs and libraries developed is available online, on a Mercurial SCM repository at the address \texttt{https://bitbucket.org/dbacchet/univ} .
+
+It has been designed to be cross-platform, and tested on Windows7 and Mac OSX 10.8; on Windows, Visual Studio 2010 (or newer) and Python 2.7 (or newer) are required.
+
+An automatic build system takes care of configuring the environment, building the applications and installing the final executables. To run it, type the following commands from a Prompt shell in the repository root directory:
 \begin{verbatim}
   python waf configure
   python waf build install
 For a description of the command line options run a program with the \texttt{--help} flag.
 
 
+%%%%%%%%%%%
+% results %
+%%%%%%%%%%%
+\section{Results}
 
+As described in \cite{PhysRevA.22.2776}, when the substrate potential strength is high both approaches show similar results. The coverage increases from zero in single layer steps, when the chemical potential $\bar{\mu}$ spans the range $[-\infty,0]$.
 
-\section{Results}
-This is the first section.
+It is worth to note, in the figure \ref{fig:t135_sub2}, the effect of the long range inter-particle potentials: the coverage still grow with first-order steps, but the first layer is formed at a smaller $\bar{\mu}$. This is the effect of the balance between the substrate and the particle potentials; stronger inter-particle potentials make more difficult for the substrate to attract particles [AGGIUNGERE??].
+After the first layer is formed, the behavior is very similar.
 
-
-
-
-
-Now a couple of figures, side-by-side.
 \begin{figure}[htb]
 \centering
 \begin{subfigure}{.5\textwidth}
   \centering
   \includegraphics[width=1.0\linewidth]{images/{1_oliveira_isotherm_T1.35_short}.png}
-  \caption{A subfigure}
-  \label{fig:sub1}
+  \caption{De Oliveira}
+  \label{fig:t135_sub1}
 \end{subfigure}%
 \begin{subfigure}{.5\textwidth}
   \centering
   \includegraphics[width=1.0\linewidth]{images/{1b_ebner_isotherm_A2.75_T1.35_comp}.png}
-  \caption{A subfigure}
-  \label{fig:sub2}
+  \caption{Ebner}
+  \label{fig:t135_sub2}
 \end{subfigure}
-\caption{A figure with two subfigures}
-\label{fig:test}
+\caption{Coverage comparison, with strong substrate potential ($\alpha=2.75$ for the Ebner formulation).}
+\label{fig:t135}
 \end{figure}
 
-And those can be referenced ad figure \ref{fig:sub1} and figure \ref{fig:sub2}
+More interesting is the behavior we can observe reducing the substrate potential strength.
+Calculating the isotherm for $T^*=2.0$ and $\alpha=1.75$, the coverage is dramatically different. 
+The short-range potentials produce a coverage that increase continuously for high $\bar{\mu}$, and then progress with first order steps as $\bar{\mu} \to 0$.
+
+Using long-range potentials, the coverage remains fixed to a fraction of a monolayer, and then suddenly jumps to approximately 5 layers. After this point it progress with first order steps.
 
 \begin{figure}[htb]
 \centering
   \includegraphics[width=0.7\linewidth]{images/{2_ebner_isotherm_A1.75_T2.00_comp}.png}
-  \caption{short and long range inter-particle potentials, with ebner at t=2}
+  \caption{Comparison between short and long range inter-particle potentials, with $\alpha=1.75$ and $T^*=2.0$.}
 \end{figure}
 
+This phenomenon can be investigated looking also at the energy levels associated to each possible coverage value, that are represented in figure (\ref{fig:layer-energy-comp}) for 3 values of the temperature $T^*$.
+The energy curves have been obtained by setting the initial $\{y_{0_n}\}$ to the desired configuration $C_L$, and letting the system to evolve; if the system converge to a metastable solution close to the initial value, then the corresponding energy is associated to $C_L$.
 
-Comparison layers and energy levels:
 \begin{figure}[htb]
 \centering
 \begin{subfigure}{.5\textwidth}
   \centering
   \includegraphics[width=1.0\linewidth]{images/{5a_ebner_energy_A1.75_T2.80}.png}
 \end{subfigure}
-\caption{Layer coverage and relative layer-energy tof $T^*=2.0,2.4,2.8$}
+\caption{Layer coverage and corresponding layer-energy for $T^*=2.0,2.4,2.8$}
 \label{fig:layer-energy-comp}
 \end{figure}
 
-Looking at figure (\ref{fig:layer-energy-comp}), it is interesting to note that fot $T^*=2.0$ the configuration corresponding to a single layer is \textit{never} stable; there are no local minima around $\theta \approx 1$ and the system will converge either to a partial adsorbed layer $\theta \approx 0$ or to the metastable solution $\theta \approx 2$.
+It is interesting to note, for example, that for $T^*=2.0$ the configuration corresponding to a single layer is \textit{never} stable; there are no local minima around $\theta \approx 1$ and the system will converge either to a partial adsorbed layer $\theta \approx 0$ or to the metastable solution $\theta \approx 2$.
+
+In general looking at the energies confirms that the sharp step from 0 to 5 layers (for $T^*=0$) is a direct result of 
 
 
 \begin{figure}[htb]
 \end{subfigure}
   
 \caption{Substrate potential fit for $T^*=2.0$}
+\label{math:substr_comp_t20}
 \end{figure}
 
+conclusioni (C=2,D=2.2 artificiali per fare il salto)
 
 \begin{figure}[htb]
 \centering`