## Diff of /doc/doc.tex[0316c1] .. [6b82ac] Maximize Restore

### Switch to side-by-side view

--- a/doc/doc.tex
+++ b/doc/doc.tex
@@ -10,22 +10,25 @@
\usepackage{listings}
\usepackage{hyperref}
\usepackage{listings}
-\usepackage{color}
+\usepackage[cmyk]{xcolor}
+\usepackage{import}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
-
+\usepackage[framemethod=TikZ]{mdframed}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
-
-\lstset{frame=tb,
-  language=Octave,
+\definecolor{BlueLUH}{cmyk}{1.0,0.7,0,0}
+\colorlet{LightBlue}{BlueLUH!7!white}
+\lstset{
+  backgroundcolor=\color{LightBlue},
+  basicstyle={\small\ttfamily},
+  language=C++,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
-  basicstyle={\small\ttfamily},
numbers=left,
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
@@ -33,7 +36,7 @@
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true
-  tabsize=3
+  tabsize=2
}

\author{Marco Vassallo}
@@ -48,9 +51,9 @@
\tableofcontents

\chapter{Introduction}
-Fem-Fenics is an open-source package for the resolution of partial differential equations with Octave.
+Fem-fenics is an open source package (pkg) for the resolution of partial differential equations with Octave.
The project has been developed during the Google Summer of Code 2013 with the help and the sustain of the GNU-Octave
-community under the supervision of prof. De Falco.\\
+community under the supervision of prof. De Falco.

The report is structured as follows:
\begin{itemize}
@@ -71,7 +74,7 @@
\begin{center}
\url{http://gedeone-gsoc.blogspot.com/}
\end{center}
-Finally, the API is available at the following address
+Finally, the API is available as Appendix but also at the following address
\begin{center}
\url{http://octave.sourceforge.net/fem-fenics/overview.html}
\end{center}
@@ -83,7 +86,7 @@
successfully installed  on the PC. Furthermore, as Fem-fenics is based on Fenics,
it is also needed a running version of the latter. They can be easily installed following the guidelines provided
on the official Octave \cite{instoctave} and Fenics \cite{instfenics} websites.
-Once that Octave and Fenics are correctly installed, to install Fem-fenics launch Octave (which now is provided with a new
+Once that Octave and Fenics are correctly installed, to install Fem-fenics open Octave (which now is provided with a new
amazing GUI) and type

\begin{verbatim}
@@ -100,15 +103,15 @@
\end{verbatim}

For a description of the examples, look at chapter \ref{exem}.
-\\
-\\
-\textbf{NOTE} For completing the installation process successfully,
+
+
+\paragraph*{NOTE} For completing the installation process successfully,
the form compiler FFC and the header file dolfin.h should also be available on the machine.
They are managed automatically by Fenics if it is installed as a binary package or with Dorsal.
If it has been done manually, please be sure that they are available before starting the
installation of Fem-fenics.

-\section{General layout and first example}
+\section{General layout and first example}\label{genlayout}

A generic problem has to be solved in two steps:
\begin{enumerate}
@@ -131,7 +134,7 @@
u &= 0 \qquad \text{on } \Gamma_{D} \\
\nabla u \cdot n &= g \qquad \text{on } \Gamma_{N}
\end{align*}
-where $f, \, g$ are data which represent the source for and the flux
+where $f, \, g$ are data which represent the source and the flux
of the scalar variable $u$.
A possible variational formulation of the problem is: \\
find $u \in H_{0, \Gamma_{D}}^{1} :$
@@ -143,10 +146,12 @@

The abstract problem can thus be written in the \verb|Poisson.ufl| file immediately.
The only thing that has to be specified at this stage is the space of Finite Elements
- used for the discretization of $H_{0, \Gamma_{D}}^{1}$. In this case,
-we choose the space of continuous lagrangian polynomial of degree one
-\verb|FiniteElement("Lagrange", triangle, 1)|, but many more
-possibilities are available.
+used for the discretization of $H_{0, \Gamma_{D}}^{1}$. In this example,
+we choose the space of continuous lagrangian polynomial of degree one
+\begin{lstlisting}[numbers=none]
+ FiniteElement("Lagrange", triangle, 1)
+\end{lstlisting}
+but many more possibilities are available.
\subparagraph{Poisson.ufl}

\begin{lstlisting}
@@ -162,12 +167,13 @@
L = f*v*dx + g*v*ds
\end{lstlisting}

-It is always a good idea to check if the ufl code is correctly written before importing it into Octave:
-\begin{verbatim}
+It is always a good idea to check if the ufl code is correctly written before importing it into Octave. Typing
+\begin{lstlisting}[numbers=none, language = Octave]
>> ffc -l dolfin Poisson.ufl
-\end{verbatim}
-shouldn't produce any error.
-We can now implement and solve a specific instance of the Poisson problem in Octave.
+\end{lstlisting}
+in the shell shouldn't produce any error.
+
+We can now implement and solve a specific instance of the Poisson problem with Octave.
The parameters are setted as follow
\begin{itemize}
\item $\Omega = [0, 1]\times[0, 1]$
@@ -178,106 +184,94 @@
\end{itemize}

As a first thing we need to load into Octave the pkgs previously installed
-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language = Octave]
-\end{verbatim}
+\end{lstlisting}
The ufl file can thus be imported inside Octave. For every specific element defined inside the ufl file
there is a specific function which stores it for later use
\begin{itemize}
\item \verb$ufl_import_FunctionSpace ('Poisson')$ is a function which looks for the finite element
-    space defined inside the file called Laplace.ufl; if everything is ok, it generates a function
+    space defined inside the file called Poisson.ufl; if everything is ok, it generates a function
which we will use later
\item \verb$ufl_import_BilinearForm ('Poisson')$ is a function which looks for the rhs of the
-    equation, i.e. for the bilinear form defined inside Laplace.ufl;
+    equation, i.e. for the bilinear form defined inside Poisson.ufl
\item \verb$ufl_import_LinearForm ('Poisson')$ is a function which looks for the linear
form.
\end{itemize}

In some cases one could be interested in using these functions separately but if,
as in our example, all the three elements are defined in the same ufl file (and only in this case),
-the \verb$import_ufl_Problem ('Poisson')$ can be used; it generates at once all
+the \verb$import_ufl_Problem ('Poisson')$ can be used, which generates at once all
the three functions described above

-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language = Octave]
ufl_import_Problem ('Poisson');
-\end{verbatim}
+\end{lstlisting}

To set the concrete elements which define the problem,
the first things to do is to create a mesh.
-It can be managed easily using the msh pkg. For a uniform structured mesh
-\begin{verbatim}
+It can be managed easily using the msh pkg. For a structured squared mesh
+\begin{lstlisting}[numbers=none, language = Octave]
x = y = linspace (0, 1, 33);
msho = msh2m_structured_mesh (x, y, 1, 1:4);
-\end{verbatim}
+\end{lstlisting}
Once that the mesh is available, we can thus initialize the
-fem-fenics mesh using the function \verb$Mesh ()$:
-\begin{verbatim}
+Fem-fenics mesh using the function \verb$Mesh ()$:
+\begin{lstlisting}[numbers=none, language = Octave]
mesh = Mesh (msho);
-\end{verbatim}
-If instead of an Octave mesh we had a mesh stored in a different format,
-the program dolfin-convert can try to convert it to the dolfin xml format.
-Furthermore, \verb$Mesh ()$ accepts as arguments also a string with the name of
-the dolfin xml file which contains the mesh. For example, for a mesh saved
-in the gmsh format, do as follows:
-\begin{verbatim}
-    Shell:
-      dolfin-convert msh.gmsh msh.xml
-\end{verbatim}
-and then inside the Octave script:
-\begin{verbatim}
-    mshd = fem_init_mesh ('msh.xml');
-\end{verbatim}
+\end{lstlisting}
+
To initialize the functional space, we have to specify as argument only the fem-fenics mesh,
because the finite element type and the polynomial degree have yet been specified in the ufl file:
-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language = Octave]
V = FunctionSpace('Poisson', mesh);
-\end{verbatim}
+\end{lstlisting}
Essential BC can now be applied using \verb$DirichletBC ()$; this function receives as argument the functional space,
a function handle which specifies the value to set, and the label of the sides where the BC applies.
In this case, homogenous boundary conditions hold on the left and right side of the square
-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language = Octave]
bc = DirichletBC(V, @(x, y) 0.0, [2; 4]);
-\end{verbatim}
+\end{lstlisting}
The last thing to do before solving the problem, is to set the coefficients specified
-in the ufl file. It is important that they are called in the same way as in the ufl file:
-the source term 'f' and the normal flux 'g'.
-To set them, the function \verb$Expression ()$ can be used passing as argument a string,
-which specifies the name of the coefficient, and a function handle with the value required:
-\begin{verbatim}
-    f = Expression ('f',
+in the ufl file.
+To set them, the function \verb$Expression ()$ can be used passing as argument a string
+which specifies the name of the coefficient
+(it is important that they are called in the same way as in the ufl file:
+the source term 'f' and the normal flux 'g'),
+and a function handle with the value prescribed:
+\begin{lstlisting}[numbers=none, language = Octave]
+    ff = Expression ('f',
@(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02));
-    g = Expression ('g', @(x,y) sin (5.0 * x));
-\end{verbatim}
+    gg = Expression ('g', @(x,y) sin (5.0 * x));
+\end{lstlisting}
Another possibility for dealing with the coefficients defined in the ufl file would have been to use
the function \verb$Constant ()$ or \verb$Function ()$.
The coefficients can thus be used together with the FunctionSpace to set
the Bilinear and the Linear form
-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language = Octave]
a = BilinearForm ('Poisson', V, V);
-    L = LinearForm ('Poisson', V, f, g);
-\end{verbatim}
+    L = LinearForm ('Poisson', V, ff, gg);
+\end{lstlisting}
The discretized representation of our operator is obtained using the
functions \verb$assemble ()$ or \verb$assemble_system ()$, which also allow
-to specify the BC(s) to apply.
-Whenever possible, it is better to use the \verb$assemble_system ()$ function
-because it keeps the symmetry of the matrix while setting the entries for the BC:
-\begin{verbatim}
+to specify the BC(s) to apply
+\begin{lstlisting}[numbers=none, language = Octave]
[A, b] = assemble_system (a, L, bc);
-\end{verbatim}
+\end{lstlisting}
Here A is a sparse matrix and b is a column vector. All the
functionalities available within Octave can now be exploited to solve the linear system.
The easisest possibility is the backslash command:
-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language = Octave]
u = A \ b;
-\end{verbatim}
-Once that the solution has been obtained, the vector is converted into a
-fem-fenics function and plotted \verb$plot ()$ or saved \verb$save ()$ in the vtu
-format.
-\begin{verbatim}
+\end{lstlisting}
+Once that the solution has been obtained, the \verb$u$ vector is converted into a
+Fem-fenics function and plotted \verb$plot ()$ or saved \verb$save ()$ in the vtu
+format
+\begin{lstlisting}[numbers=none, language = Octave]
u = Function ('u', V, sol);
save (u, 'poisson')
plot (u);
-\end{verbatim}
+\end{lstlisting}

The complete code for the Poisson problem is reported below, while
in figure \ref{Poissonfig} the output is presented.
@@ -290,7 +284,7 @@
\end{figure}

\subparagraph{Poisson.m}
-\begin{lstlisting}
+\begin{lstlisting}[language=Octave]
#load the pkg and import the ufl problem
import_ufl_Problem ('Poisson')
@@ -302,12 +296,12 @@

# Define boundary condition and source term
bc = DirichletBC(V, @(x, y) 0.0, [2;4]);
-f = Expression ('f', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02));
-g = Expression ('g', @(x,y) sin (5.0 * x));
+ff = Expression ('f', @(x,y) 10*exp(-((x - 0.5)^2 + (y - 0.5)^2) / 0.02));
+gg = Expression ('g', @(x,y) sin (5.0 * x));

#Create the Bilinear and the Linear form
a = BilinearForm ('Poisson', V, V);
-L = LinearForm ('Poisson', V, f, g);
+L = LinearForm ('Poisson', V, ff, gg);

#Extract the matrix and compute the solution
[A, b] = assemble_system (a, L, bc);
@@ -345,22 +339,23 @@
purposes seemed to be the FEniCS project. It is a collection of free, open source, software
components with the common goal to enable automated solution of pde.''
In particular, Dolfin is the C++/Python interface of FEniCS, providing a consistent Problem
-Solving Environment for ODE and PDE. The idea has been to create wrappers in Octave for Dolfin,
+Solving Environment for ODE and PDE. The idea has been to create wrappers in Octave for C++ Dolfin,
in a similar way to what it has been done for Python.
This is a very natural choice, because Octave is mainly written in script language
and in C++. It is in fact possible to implement an Octave interpreter function in C++ through the
-native oct-file interface or, coversely, to use Octave's Matrix/Array Classes in a C++ application.
+native oct-file interface or, conversely, to use Octave's Matrix/Array Classes in a C++ application
+\cite{whatoctave}.

The works can be summirized as follows (fig. \ref{Codelayout}):

the elements already available in Octave for the resolution of PDE (Mesh and Linear
-Algebra) have been exploited, and wrappers to FEniCS functions added.
+Algebra) have been exploited, and wrappers to the other FEniCS functions added.
To allow exchanges between this programs, the necessary functions
for converting an Octave mesh/matrix into a FEniCS one and viceversa have been written.

Two main ideas have guided us throughout the realization of the pkg:
\begin{itemize}
-  \item keep the syntax as close as possible to the original one in Fenics
+  \item keep the syntax as close as possible to the original one in Fenics (Python)
\item make the interface as simple as possible.
\end{itemize}

@@ -371,19 +366,27 @@
\item \textbf{coefficient} stores an expression object which is used for the
evaluation of user defined values
\item \textbf{expression} is needed for internal use only as explained below
-  \item \textbf{form} stores a general dolfin::Form and can be used either for a
-  dolfn::BilinearForm as well as for a dolfin::LinearForm
+  \item \textbf{form} stores a general dolfin::Form and can be used either for
+  a dolfn::BilinearForm as well as for a dolfin::LinearForm
\item \textbf{function} for the dolfin::Function objects
\item \textbf{functionspace} stores the user defined FunctionSpace
\item \textbf{mesh} converts a PDE-tool like mesh structure in a dolfin::Mesh
\end{itemize}
-The general layout of a class is quite simple and its main purpose is the storage
-of the corresponding FEniCS objects. They are managed throughout
-\verb$boost::shared_ptr< >$ to the corresponding FEniCS type.
-All the classes also implement a constructor which takes as argument the corresponding dolfin type,
-and a default constructor which is necessary to register a type in the Octave interpreter.
-All these classes derive from \verb$octave_base_value$. For example, the form class implementation
- follows, while classes which differs from the general layout are presented below.
+
+The classes are written with the usual'' C++ style, but they need to be derived publicly
+from octave\_base\_value and to be added to the Octave interpreter \cite{whatoctave}.
+When a type is used for the first time during a session, it is also temporarily
+registered in the interpreter after all the other basic types (int, double, ...).
+
+The general layout of a class can thus be kept simple and with the main purpose of storing
+the associated FEniCS objects, which is done throughout
+boost::shared\_ptr< > to the corresponding FEniCS type.
+All the classes also implement at least two constructor:
+a default constructor which is necessary to register a type in the Octave interpreter,
+and a constructor which takes as argument the corresponding dolfin type.
+
+As an example, the form class implementation follows, while classes which differs from the general
+layout are presented below in more details.

\begin{lstlisting}
#ifndef _FORM_OCTAVE_
@@ -441,21 +444,56 @@

\end{lstlisting}

-\subsection{mesh}
+\subsection{Shared pointer}
+In all the classes presented above, the private members are stored using
+a boost::shared\_ptr< >  to the corresponding FEniCS type.
+This is done because we have to refer in several places to resources which are built dynamically
+ and we want that it is destroyed only
+when the last references is destroyed \cite{Formaggia_smart}.
+For example, if we have two different functional spaces in the same problem,
+like with Navier-Stokes for the velocity and the pressure, the mesh is shared between
+them and no one has its own copy.
+Furthermore, they are widely supported inside DOLFIN, and it can thus be avoided to have a copy of the
+same object for FEniCS and another one for DOLFIN: there is just one copy which is shared among DOLFIN
+and FEniCS.
+
+
+\subsection{The mesh class}
In addition to usual methods, the mesh class implemens functionalities which allow to deal with meshes
-as they are currently available with the msh pkg, i.e. in the (p, e, t) format.
-Dolfin instead use a xml format for storing informations relative to a mesh.
-We have therefore added a constructor
-\begin{verbatim}
+as they are currently available with the msh pkg, i.e. in the (p, e, t) format, and in Fenics, i.e.
+in the xml Dolfin format.
+It is therefore necessary to have two different constructors
+\begin{lstlisting}[numbers=none]
mesh (Array<double>& p, Array<octave_idx_type>& e,
Array<octave_idx_type>& t);
-\end{verbatim}
-which accept as input a mesh in (p, e, t) format and convert it into a xml one. Before exploring
-the code in more details,the main differences between the two storing formats are presented using
-the very simple but rather instructive example of a unit square mesh with just two elements, fig. \ref{mesh}.
-
+
+ mesh (std::string _filename)
+    : octave_base_value (), pmsh (new dolfin::Mesh(_filename)) {}
+\end{lstlisting}
+
+where the first one accepts as input a mesh in (p, e, t) format and convert it into a xml one, while
+the latter load the mesh stored in the \_filename.xml file.
+
+The constructor are used within the Mesh () function, which therefore accepts as argument
+either a mesh generated with the msh pkg or a string with the name of the file
+where the dolfin mesh is stored.
+
+Furthermore, if a mesh is stored in another different format,
+the program dolfin-convert can try to convert it to the dolfin xml format.
+For example, for a mesh generated with Metis:
+\begin{lstlisting}[numbers=none, language=bash]
+    Shell:
+      >> dolfin-convert msh.gra msh.xml
+\end{lstlisting}
+and then inside the Octave script:
+\begin{lstlisting}[numbers=none, language=Octave]
+    mesh = Mesh ('msh.xml');
+\end{lstlisting}
+Before exploring the code in more details, the main differences between the two storing formats are presented using
+the very simple, but rather instructive, example of a unit square mesh with just two elements, fig. \ref{mesh}.

\paragraph{pet}
+
\begin{figure}
\begin{center}
\includegraphics[height=5 cm,keepaspectratio=true]{./mesh_1.png}
@@ -463,16 +501,18 @@
\label{mesh}
\end{center}
\end{figure}
-A mesh is represented using the three matrices p, e, t, and, using msh,
+
+A mesh is represented using the three matrices $p$, $e$, $t$, and, using msh,
we can easily obtain the mesh for our example typing
-\begin{verbatim}
+\begin{lstlisting}[numbers=none, language=octave]
mesh = msh2m_structured_mesh ([0 1], [0 1], 1, [11 12 12 13])
-\end{verbatim}
-
-The matrix p stores information about the coordinates of the vertices
-\begin{verbatim}
+\end{lstlisting}
+
+The matrix $p$ stores information about the coordinates of the vertices
+\begin{mdframed}[backgroundcolor=LightBlue, outerlinewidth=0.25pt,linecolor=LightBlue]
+\begin{lstlisting}[numbers=none, language=octave]
>> mesh.p
-\end{verbatim}
+\end{lstlisting}

$\begin{array}{rrrrl} @@ -480,14 +520,14 @@ \; 0 & 1 & 0 & 1 & \quad \text{y-coordinates} \\ \end{array}$
-\newline
-\newline
-Thus the vertex in the $n^{th}$ column will be labelled as the vertex number $n$, and so on..
+\end{mdframed}
+Thus the vertex in the $n^{th}$ column is labelled as the vertex number $n$, and so on.

-The matrix t stores information about the connectivity
-\begin{verbatim}
+The matrix $t$ stores information about the connectivity
+\begin{mdframed}[backgroundcolor=LightBlue, outerlinewidth=0.25pt,linecolor=LightBlue]
+\begin{lstlisting}[numbers=none, language=octave]
>> mesh.t
-\end{verbatim}
+\end{lstlisting}

$\begin{array}{rrl} @@ -497,15 +537,17 @@ \; 0 & 0 & \\ \end{array}$
-\newline
-\newline
-The first element is thus the one obtained connecting vertices 1-3-4 and so on..
-
-The matrix e stores information related to every side edge, like the number of the vertices of the boundary elements,  and the number of the geometrical border containing the edge. (This last information could be very useful later in this project, when we will have to find a way to apply boundary conditions to our problem)
-\begin{verbatim}
+\end{mdframed}
+The first element is thus the one obtained connecting vertices 1-3-4 and so on.
+
+The matrix $e$ stores information related to every side edge,
+like the number of the vertices of the boundary elements,
+and the number of the geometrical border containing the edge,
+which is a convinient way to trate boundary conditions in a problem.
+\begin{mdframed}[backgroundcolor=LightBlue, outerlinewidth=0.25pt,linecolor=LightBlue]
+\begin{lstlisting}[numbers=none, language=octave]
>> mesh.e
-\end{verbatim}
-
+\end{lstlisting}
$\begin{array}{rrrrl} \; 1 & 3 & 2 & 1 & \quad \text{first vertex of the side edge} \\ @@ -517,17 +559,16 @@ \; 1 & 1 & 1 & 1 & \text{} \\ \end{array}$
-\newline
-\newline
-The side edge between vertex 1-3 is labelled 11, between 3-4 12...
+\end{mdframed}
+The side edge between vertex 1-3 is labelled 11, between 3-4 is 12...

\paragraph{dolfin xml} A mesh is an object of the dolfin::Mesh class which stores information only about
-the coordinates of the vertices (like p) and the information about the connectivity (like t).
-A mesh can thus be manipulated using the functions and the methods of the class.
-The information about boundaries is not directly stored in the mesh.
-The mesh used in th example is stored as
-
-\begin{verbatim}
+the coordinates of the vertices (like $p$) and the information about the connectivity (like $t$).
+A mesh can thus be manipulated using the functions and the methods of the class, which are presented below.
+Instead, the information about boundaries is not directly stored in the mesh.
+The mesh used in the example is stored as
+
+\begin{lstlisting}[numbers=none, language=xml]
<?xml version="1.0"?>
<dolfin xmlns:dolfin="http://fenicsproject.org">
<mesh celltype="triangle" dim="2">
@@ -543,74 +584,344 @@
</cells>
</mesh>
</dolfin>
-\end{verbatim}
-
-\subsection{Shared pointer}
-This is done for two main reasons:
-    in our program we have to refer in several places to resources which are built dynamically
-    (e.g. a FunctionSpace contain a reference to the Mesh) and we want that it is destroyed only
-    when the last references is destroyed.
-    they are widely used inside DOLFIN and it is thus easier to deal with it if we use the same types.
-
-\iffalse
-\paragraph{functionspace}
+\end{lstlisting}
+
+\paragraph{Conversion between the formats}
+The first necessary step in our way to a package which links Octave and FEniCS
+is to convert a mesh from the $(p, e, t)$ format
+into the dolfin xml one.
+Furthermore, as dolfin provides methods and functions which
+allow to manipulate a mesh and which don't have a conterpart in the msh pkg,
+we have also created wrappers for them (specifically for mesh::refine).
+
+As it has been showed above, the main difference between $(p, e, t)$ and $dolfin xml$
+is the way in which the boundaries are distinguished.
+The former stores all the information in the $e$ matrix, while the latter uses
+the functions and the methods of the dolfin::mesh class to set/get informations about a mesh.
+The most useful classes available in dolfin are recalled
+\begin{itemize}
+\item \textbf{MeshIterator}
+To know whether an edge belongs or not to the boundary, we can iterate over all the
+edges of our mesh using the classes provided by dolfin:
+\begin{lstlisting}[numbers=none]
+  for (dolfin::FacetIterator f (mesh); ! f.end (); ++f)
+    {
+      if ((*f).exterior () == true)
+        {
+          //do something with the boundary cells
+        }
+    }
+\end{lstlisting}
+
+\item \textbf{MeshFunction}
+To store data related to a mesh, dolfin provides the template class MeshFunctions.
+"A MeshFunction is a function that can be evaluated at a set of mesh entities.
+A MeshFunction is discrete and is only defined at the set of mesh entities of a fixed topological dimension.
+A MeshFunction may for example be used to store a global numbering scheme for the entities of a (parallel) mesh,
+marking sub domains or boolean markers for mesh refinement." \cite{meshfunction}
+For example, in the function \verb$mshm_refine$ of the msh package, the list of cells to be refined
+is stored as a MeshFunction, which for every cell says whether or not it has to be refined:
+\begin{lstlisting}[numbers=none]
+  dolfin::CellFunction<bool> cell_markers (mesh);
+  cell_markers.set_all (false);
+
+  for (octave_idx_type i = 0;
+       i < cells_to_refine.length (); ++i)
+    cell_markers.set_value (cells_to_refine (i) , true);
+\end{lstlisting}
+
+
+\item \textbf{MeshValueCollection} "It differs from the MeshFunction class in two ways.
+First, data does not need to be associated with all entities (only a subset).
+Second, data is associated with entities through the corresponding cell index and local entity number
+(relative to the cell), not by global entity index, which means that data may be stored robustly to file."\cite{meshvalue}
+It is thus obvious that it is better to use the MeshValueCollection whenever saving or writing a mesh.
+\end{itemize}
+
+The containers classes presented above can be used by their own,
+but to set/get data from a mesh it is better to use the methods provided by the classes:
+\begin{itemize}
+\item \textbf{MeshDomains} "The class MeshDomains stores the division of a Mesh into subdomains.
+For each topological dimension 0 <= d <= D, where D is the topological dimension of the Mesh,
+a set of integer markers are stored for a subset of the entities of dimension d,
+indicating for each entity in the subset the number of the subdomain.
+It should be noted that the subset does not need to contain all entities of any given dimension;
+entities not contained in the subset are ���unmarked���." \cite{meshdomain}
+\item \textbf{MeshData} "The class MeshData is a container for auxiliary mesh data,
+represented either as MeshFunction over topological mesh entities, arrays or maps.
+Each dataset is identified by a unique user-specified string." \cite{meshdata}
+\end{itemize}
+
+\subparagraph{Geometry from (p, e, t) to xml dolfin}
+Converting the vertices and cells from (p, e, t) in the xml format can be done using the
+dolfin editor, while caution has to be taken for storing information associated with boundaries
+and subdomains, as presented in the next paragraph.
+\begin{lstlisting}[numbers=none]
+      dolfin::MeshEditor editor;
+      boost::shared_ptr<dolfin::Mesh> msh (new dolfin::Mesh ());
+      editor.open (*msh, D, D);
+      editor.init_vertices (p.cols ());
+      editor.init_cells (t.cols ());
+
+      if (D == 2)
+        {
+          for (uint i = 0; i < p.cols (); ++i)
+                               p.xelem (0, i),
+                               p.xelem (1, i));
+
+          for (uint i = 0; i < t.cols (); ++i)
+                             t.xelem (0, i) - 1,
+                             t.xelem (1, i) - 1,
+                             t.xelem (2, i) - 1);
+        }
+
+      if (D == 3)
+        {
+          ...
+        }
+
+      editor.close ();
+
+\end{lstlisting}
+
+\subparagraph{Subdomain markers: from (p, e, t) to dolfin xml}
+There are no fundamental differences between the 2D and 3D case,
+and they are thus treated together referring to the
+general dimension D.
+The subdomain information is contained in the t matrix,
+and is temporarily copyed to a MeshValueCollection.
+For every column of the t matrix, i.e. for every element of the mesh,
+we have to look for the corresponding element in the DOLFIN mesh.
+We use the class MeshIterator for moving around on the DOLFIN mesh:
+
+\begin{lstlisting}[numbers=none]
+  dolfin::MeshValueCollection<uint> my_cell_marker (D);
+
+  for (uint i = 0; i < num_cells; ++i)
+    dolfin::Vertex v (mesh, t(0, i));
+      for (dolfin::CellIterator f (v); ! f.end (); ++f)
+        {
+          if ((*f) == all_vertices_in_the_ith_column)
+            {
+              my_cell_marker.set_value
+                ((*f).index (), t(last_row, i), mesh);
+              break;
+            }
+         }
+\end{lstlisting}
+
+The \verb$all_vertices_in_the_ith_column$ is just like a pseudo code:
+we have to be sure that the Cell pointed by f is the one corresponding
+to the $i^{th}$ column of the matrix, checking one-by-one the vertices:
+
+in $2D$ the cell is a triangle, and we thus have to check $3$ vertices.
+As we don't know the order in which vertices are visited, we have to check all the $3! = 6$
+different combinations:
+\begin{lstlisting}[numbers=none]
+          ...
+          if ((*f).entities(0)[0] == t(0, i)
+              && (*f).entities(0)[1] == t(1, i)
+              && (*f).entities(0)[2] == t(2, i)
+              || ...  check the other 5 possibilities... )
+         ....
+\end{lstlisting}
+
+where the \verb$entities(std::size_t dim)$ method returns an array with the indexes of the elements
+of dimension dim. Thus we use $dim = 0$ as we are looking for vertices.
+
+In the $3D$ case, our cell is a tetrahedron, and we have to check all the $4! = 24$ possibilities,
+each of which is composed by $4$ assertions; in total we have almost one hundred conditions!
+
+Now that the information is stored in our function, it can be associated to the mesh
+
+\begin{lstlisting}[numbers=none]
+    *(mesh.domains ().markers (D)) = my_marked_cell;
+\end{lstlisting}
+
+\subparagraph{Subdomain markers: from dolfin xml to (p, e, t)}
+
+In the DOLFIN .xml file, the information is stored like:
+\begin{lstlisting}[numbers=none]
+ ...
+<mesh_value_collection name="m" type="uint" dim="2" size="2">
+     <value cell_index="0" local_entity="0" value="1"/>
+     <value cell_index="1" local_entity="0" value="2"/>
+ ...
+\end{lstlisting}
+
+When the file is read using DOLFIN, the information is automatically associated with the mesh
+as a MeshValueCollection named \verb$cell_domains$, which can be accessed to extract the information
+using the MeshDomains class.
+Obviously we have to be sure that the information is available within
+the file that we are reading, and that it is related to Cell, i.e. to elements of dimension D,
+before it is associated with the last row of the t matrix:
+
+\begin{lstlisting}[numbers=none]
+  dolfin::MeshFunction<uint> my_cell_marker;
+  if (! mesh.domains ().is_empty ())
+    if (mesh.domains ().num_marked (D) != 0)
+      my_cell_marker = *(mesh.domains ().cell_domains ());
+
+    for (j = 0; j < t.cols (); ++j)
+      t(D + 1, j) = my_cell_marker[j];
+\end{lstlisting}
+
+\subparagraph{Boundary Markers}
+For boundary markers, things work in a similar way, as long as we remember that we are working with objects of
+dimension D - 1.
+In this case, the main difference is in the .xml file: it is no longer enough to say
+to what cell element the label is referred to, but we have to specify to which $D - 1$
+entity (a side or a face) the label is referred.
+For example:
+
+\begin{lstlisting}[numbers=none]
+    ....
+    mesh_value_collection name="m" type="uint" dim="1" size="4">
+         <value cell_index="0" local_entity="0" value="12"/>
+         <value cell_index="0" local_entity="2" value="11"/>
+         <value cell_index="1" local_entity="0" value="12"/>
+         <value cell_index="1" local_entity="2" value="13"/>
+    ...
+\end{lstlisting}
+
+The cell number $"0"$ is a triangle,
+and to the \verb$local_entity$ number $"0"$, i.e. to the side number $"0"$,
+is associated the label $"12"$, while to the side number $"2"$ is associated the label $"11"$.
+To the side number $"1"$, there are no labels associated.
+The number of the \verb$local_entity$ refers to the enumeration of the reference element.
+In any case, it is DOLFIN which takes care of the conversion of indeces from this format to the usual one,
+and we can thus use methods and functions as explained for the subdomain markers.
+
+\subparagraph{Mesh refine}
+Now that it is possible to convert meshes between Octave and DOLFIN,
+the functions availables in the dolfin::mesh class can be used to improve the
+functionality of the msh package.
+For the moment, it has been added the possibility of refining a mesh,
+either uniformly or specifying the list of the vertices we want to be refined.
+The function is now part of the msh pkg\cite{msh}, and a more detailed desciption has been
+provided previously \cite{refine}.
+
+
+
+\subsection{The functionspace class}
A dolfin::FunctionSpace is defined by specifying a mesh and the type of the finite element which we want to use.
-The mesh is handled by our class, while the FE are specified inside the .ufl file. Possible choices are:
-
-    Argyris                                  ARG
-    Arnold���Winther                    AW
-    Brezzi���Douglas���Marini        BDM
-    Crouzeix���Raviart                  CR
-    Discontinuous Lagrange      DG
-    Hermite                                HER
-    Lagrange                              CG
-    Mardal���Tai���Winther             MTW
-    Morley                                  MOR
-    N��d��lec 1st kind H (curl)     N1curl
-    N��d��lec 2nd kind H (curl)    N2curl
-    Raviart���Thomas                   RT
-
-Once that the .ufl file has been compiled, in the output file it is defined a namespace where we can find
-the corresponding FunctionSpace and which only needs a mesh to be initialized.
-
-\paragraph{boundary condition}
-This class is used for dealing with essential BC. We need three elements for the definition of an object of
-type dolfin::DirichletBC :
-
-    a dolfin::FunctionSpace where the BC is defined, which is handled by our class functionspace described above
-    a dolfin::Function or a dolfin::Expression which represents the value that we want to assign.
-    This is done deriving a new class from dolfin::Expression and overloading the eval function.
-    a dolfin::subdomain which specifies where we want to apply the BC.
-\paragraph{coefficient}
-This class is used to store a std::string where we save the name of the coefficient,
-and an object of type expression, which is a class derived from dolfin::Expression.
-The class expression would be explained in more detail in the next post.
-\fi
+The mesh is handled as presented above, while the FE are specified inside the .ufl file. Possible choices are
+\cite{logg2012automated}:
+
+\begin{center}
+\begin{tabular}{  l | l }
+  \hline
+    \textbf{Finite Element Space} & \textbf{Symbol} \\ \hline \hline
+
+
+    Argyris                  &    ARG * \\ \hline
+    Arnold���Winther           &    AW * \\ \hline
+    Brezzi���Douglas���Marini    & BDM\\ \hline
+    Crouzeix���Raviart         &      CR\\ \hline
+    Discontinuous Lagrange   & DG\\ \hline
+    Hermite                  &        HER*\\ \hline
+    Lagrange                 &        CG\\ \hline
+    Mardal���Tai���Winther       &  MTW *\\ \hline
+    Morley                   &            MOR*\\ \hline
+    N��d��lec 1st kind H (curl)   &  N1curl\\ \hline
+    N��d��lec 2nd kind H (curl)   & N2curl\\ \hline
+    Raviart���Thomas              &    RT\\
+\end{tabular}
+
+\end{center}
+
+where the Finite Elements denoted with * are not yet fully supported inside FEniCS.
+
\section{General layout of a function}
-\iffalse
-The functions which we describe below are used to set and get the values for the variable that are commonly
-used in a FEM problem.
-
-The main functions which are available right now are:
-
-    \verb$fem_init_mesh$: this function can take as input either a string which specify
-    the name of the file to read or a mesh produced with the msh pkg
-    \verb$fem_bc$: take as input the functional space, a function handle which specifies
-    the value that we want to set on the boundary, and the label of the boundaries where we want to apply the bc
-    coefficient: take as input the name of one of the coefficients defined in
-    the .ufl file and a function handle with the value that we want to set
-
-The following functions work fine but at the moment are directly compiled including
-the output file obtained from the .ufl file (which should be avoided as discussed below) :
-
-    \verb$fem_fs$: take as input the mesh where we want to define the functional space
-    \verb$fem_rhs$: take as input the function space where the bilinear form is defined,
-    a list of coefficients and a list of BCs that we want to apply. It returns a
-    sparse matrix which contains the discretization of the bilinear operator
-    \verb$fem_lhs$: take the same input as the function \verb$fem_rhs$. If you have essential BC
-    in the problem, you need to pass them also to this function in such a way that
-    the DOF corresponding to essential nodes are set to the right value
-
+There are three general kind of functions in the code: functions which create an abstract problem
+(wrappers to UFL),
+functions which create the specific instance of a problem (wrapper to FEniCS) and functions
+which discretize the problem and genertates the matrices.
+\section{Wrappers to UFL}
+As stated in section \ref{genlayout}, a problem is divided in two files:a \textit{.ufl} file
+where the abstract problem is described in Unified Form Language (UFL),
+and a script file \textit{.m} where a specific problem is implemented and solved.
+We suppose that they are called Poisson.ufl and Poisson.m .
+In order to use the information stored in the UFL file, i.e. the bilinear and the linear form,
+they have to be imported inside Octave.
+When the UFL file is compiled using the ffc compiler, a header file \textit{Poisson.h} is generated.
+In this header file, it is defined the Poisson class, which derives from dolfin::Form,
+and the constructor for the bilinear and linear form are setted.
+This file is thus available only at compilation time, but it has to be included somehow
+in the wrapper function for the Bilinear and the Linear form.
+An easy solution would have been to write a set of pre established problems where the user could only
+change the values of the coefficient for a specific problem;
+but, as we want to let the user free to write its own
+variational problem, a different approach has been adopted.
+The ufl file is compiled at run time and generates an header file.
+Then, a Poisson.cc file is written from a template which take as input the name
+of the header file and is compiled including the Poisson.h file;
+now the corresponding octave functions for the specific problem is available and will be used from
+BilinearForm, LinearForm, FunctionSpace, ... .
+As an example it is presented the import\_ufl\_BilinearForm function.
+
+\begin{lstlisting}[language=Octave]
+ function import_ufl_BilinearForm (var_prob)
+
+ ...
+
+  %the function which writes the var-prob.cc file
+  generate_rhs (var_prob);
+
+  %the function which writes the makefile
+  generate_makefile (var_prob, private);
+
+  % the makefile is executed in a terminal:
+  % 1) generate the header file from ufl
+  %  ffc -l dolfin var_prob.ufl
+  % 2) compile the var_prob.cc
+  %  mkoctfile var_prob.cc -I.
+  system (sprintf ("make -f Makefile_%s rhs", var_prob));
+
+  ...
+
+endfunction
+\end{lstlisting}
+
+\begin{lstlisting}[language=Octave]
+function output = generate_rhs (ufl_name)
+
+  STRING ="
+  #include "@@UFL_NAME@@.h"
+
+  ...
+
+  DEFUN_DLD (@@UFL_NAME@@_BilinearForm, args, , ""A = fem_rhs_@@UFL_NAME@@ (FUNCTIONAL SPACE, COEFF)"")
+  {
+    ...
+
+    const functionspace & fspo1
+      = static_cast<const functionspace&> (args(0).get_rep ());
+    const functionspace & fspo2
+      = static_cast<const functionspace&> (args(1).get_rep ());
+
+    const dolfin::FunctionSpace & U = fspo1.get_fsp ();
+    const dolfin::FunctionSpace & V = fspo2.get_fsp ();
+    @@UFL_NAME@@::BilinearForm a (U, V);
+
+    ...
+
+
+  }";
+
+  STRING =  strrep (STRING, "@@UFL_NAME@@", ufl_name);
+
+  fid = fopen (sprintf ("%s_BilinearForm.cc", ufl_name), 'w');
+  fputs (fid, STRING);
+  output = fclose (fid);
+
+endfunction
+\end{lstlisting}
+
+
+\section{Wrappers to DOLFIN}
The general layout of a function is very simple and is composed of 4 steps which we describe using an example:
\begin{lstlisting}
DEFUN_DLD (fem_fs, args, , "initialize a fs from a mesh")
@@ -628,58 +939,56 @@
\end{lstlisting}
All the functions presented above follow this general structure, and thus here we present
in detail only functions which present some differences.
-
-\paragraph{fem bc and fem coeff}
+\subsection{Sparse Matrices}
+\subsection{Polymorphism}
+\subsection{DirichletBC and Coefficient}
These two functions take as input a function handle which cannot be directly evaluated by
a dolfin function to set, respectively, the value on the boundary or the value of the coefficient.
- We have thus derived from dolfin::Expression a class "expression" which has as private member
+ It has thus been derived from dolfin::Expression a class "expression" which has as private member
an octave function handle and which  overloads the function eval(). In this way, an object of
the class expression can be initialized throughout a function handle and can be used inside dolfin because
- "it is"  a dolfin::Expression.
+ "it is" a dolfin::Expression
\begin{lstlisting}
class expression : public dolfin::Expression
{
-
- public:
-  expression (octave_fcn_handle & _f) :
-             dolfin::Expression (), f (new octave_fcn_handle (_f)) {}
-
-  void eval (dolfin::Array<double>& values, const dolfin::Array<double>& x) const
-  {
-    octave_value_list b;
-    b.resize (x.size ());
-    for (int i = 0; i < x.size (); ++i)
-      b(i) = x[i];
-    octave_value_list res = feval (f->function_value (), b);
-    values[0] = res(0).double_value ();
-  }
+  ...
+
+  void
+  eval (dolfin::Array<double>& values,
+        const dolfin::Array<double>& x) const
+    {
+      octave_value_list b;
+      b.resize (x.size ());
+      for (std::size_t i = 0; i < x.size (); ++i)
+        b(i) = x[i];
+      octave_value_list tmp = feval (f->function_value (), b);
+      Array<double> res = tmp(0).array_value ();
+
+      for (std::size_t i = 0; i < values.size (); ++i)
+        values[i] = res(i);
+    }

private:
octave_fcn_handle * f;
-};
-\end{lstlisting}
-
-\paragraph{fem lhs and fem rhs}
- For these functions, we need to set the possible coefficient of the (bi)linear form  and to apply the BC.
-
-For the coefficient:
-\begin{lstlisting}
-    const coefficient & cf = static_cast <const coefficient&> (args (i).get_rep ());
-    // get the correct position of the coefficient in the declaration of the problem
-    std::size_t n = a.coefficient_number (cf.get_str ());
-    // extract the information.. we use again the expression class descripted above
-    const boost::shared_ptr<const expression> & pexp = cf.get_expr ();
-    //set the coefficient for the (bi)linear form
-    a.set_coefficient (n, pexp);
-\end{lstlisting}
-For the BC
-At the moment we are simply using the method apply() of the class DirichletBC,
-but it does not preserve the symmetry of the matrix. We have thus planned to insert
-later a function which instead of the method apply() calls the function \verb$assemble_system()$ ,
-which preserves the symmetry but which builds together the lhs and the rhs.
-The sparse matrix is then built from the dolfin::Matrix following the general guidelines of Octave.
-
+};
+
+
+\end{lstlisting}
+
+\paragraph{DirichletBC}
+The BC are imposed directly to the mesh setting to zero all the off diagonal elements
+in the corresponding line. This means that we could loose the symmetry of the matrix, if any.
+To avoid this problem, instead of the method apply() it is possible to use the
+function \verb$assemble_system()$ , which preserves the symmetry of the system but which needs to build
+together the lhs and the rhs.
+
+\paragraph{Coefficient}
+The coefficient of the variational problem can be specified using either a Coefficient
+or a Function. They are different objects which behave in different ways: a Coefficient, as exlained above,
+overloads the eval() method of the  dolfin::Expression class and it is evaluated at
+run time using the octave function feval (). A Function instead doesn't need to be evaluated
+because it is assembled copying element-by-element the values contained in the input vector.
+\iffalse

\paragraph{other function}

@@ -696,49 +1005,9 @@
a mesh and the value of the function at every node of the mesh.
This is something which could be useful also outside of fem-fenics.

-
\section{Implementation Details}
The relevant implementation details which the user should know are:

-    all the objects are managed using \verb$boost::shared_ptr <>$.
-    It means that the same resource can be shared by more objects and useless copies
-    should be avoided. For example, if we have two different functional spaces in the same problem,
-    like with Navier-Stokes for the velocity and the pressure, the mesh is shared between
-    them and no one has its own copy.
-    The BC are imposed directly to the mesh setting to zero all the off diagonal elements
-    in the corresponding line. This means that we could loose the symmetry of the matrix, if any.
-    The simmetry is lost because we are using the method apply() of the class dolfin::DirichletBC.
-    We have thus planned to insert later a function which instead of the method apply() calls the
-    function \verb$assemble_system()$ , which preserves the symmetry of the system but which builds
-    together the lhs and the rhs.
-    The coefficient of the variational problem can be specified using either a fem-coefficient
-    or a fem-function. They are different objects which behave in different ways: a fem-coefficient
-    object overloads the eval() method of the  dolfin::Expression class and it is evaluated at
-    run time using the octave function feval (). A fem-function instead doesn't need to be evaluated
-    because it is assembled copying element-by-element the values contained in the input vector.
-
-    The relevant implementation details which the user should know are:
-
-    all the objects are managed using \verb$boost::shared_ptr <>$.
-    It means that the same resource can be shared by more objects and useless copies should be avoided.
-    For example, if we have two different functional spaces in the same problem, like with Navier-Stokes f
-    or the velocity and the pressure, the mesh is shared between them and no one has its own copy.
-
-    The essential BC are imposed directly to the matrix with the command assemble(),
-    which sets to zero all the off diagonal elements in the corresponding line, sets to 1
-    the diagonal element and sets to the exact value the rhs. This means that we could loose
-    the symmetry of the matrix, if any. To avoid this problem and preserve the symmetry of
-    the system it is available the \verb$assemble_system()$ command which builds at once the lhs and the rhs.
-
-    The coefficient of the variational problem can be specified using either
-    an Expression(), a Constant() or a Function(). They are different objects
-    which behave in different ways: an Expession or a Constant object overloads
-    the eval() method of the dolfin::Expression class and it is evaluated at run
-    time using the octave function feval (). A Function instead doesn't need to
-    be evaluated because it is assembled copying element-by-element the values
-    contained in the input vector.
-
-
We have split the construction of the form into two steps:

We set all the coefficients of the form using the function which we create on the fly.
@@ -751,13 +1020,7 @@
This will be illustrated below in the HyperElasticity example.
\fi

-\subsection{Mesh generation and conversion}
-
-\subsection{Sparse Matrices}
-
-\subsection{Polymorphism}
-
-\subsection{Code release}
+\section{Wrapper to FEniCS}

\subsection{Code on the fly}

@@ -768,77 +1031,16 @@
that it was probably enough to use the functions available inside Octave because
the problem was rather simple. The pyton code is however available here, while the
final solution adopted can be found there.
-For the problem related with \verb$fem_init_env ()$, we are still working on it.
\fi

-\subsection{Autoconf}
- In this section we want to discuss how we can write a config.ac and a Makefile.in files which:
-\begin{itemize}
-    \item check if a program is available and stop if it is not
-    \item check if a header file is available and issue a warning if not, but go ahead with the compilation
-\end{itemize}
-
-To reach this goal, we need two components:
-
-\paragraph{configure.ac} Is a file which checks whether the program/header is available or not
-and sets consequently the values of some variables.
-\begin{lstlisting}
-    # Checks if the program mkoctfile is available and sets the variable HAVE_MKOCTFILE consequently
-    AC_CHECK_PROG([HAVE_MKOCTFILE], [mkoctfile], [yes], [no])
-    # if mkoctfile is not available, it issues an error and stops the compilation
-    if [test $HAVE_MKOCTFILE = "no"]; then - AC_MSG_ERROR([mkoctfile required to install$PACKAGE_NAME])
-    fi
-
-    #Checks if the header dolfin.h is available; if it is available, the value of the ac_dolfin_cpp_flags is substituted with -DHAVE_DOLFIN_H, otherwise it is left empty and a warning message is printed
-      [AC_SUBST(ac_dolfin_cpp_flags,-DHAVE_DOLFIN_H)  AC_SUBST(ac_dolfin_ld_flags,-ldolfin)],
-      [AC_MSG_WARN([dolfin headers could not be found, some functionalities will be disabled, don't worry your package will still be working, though.])] ).
-
-    # It generates the Makefile, using the template described below
-    AC_CONFIG_FILES([Makefile])
-\end{lstlisting}
-\paragraph{Makefile.ac} This file is a template for the Makefile, which will be automatically generated when the configure.ac
-file is executed. The values of the variable \verb$ac_dolfin_cpp_flags$ and \verb$ac_dolfin_ld_flags$ are substituted with the
-results obtained above:
-\begin{lstlisting}
-    CPPFLAGS += @ac_dolfin_cpp_flags@
-    LDFLAGS += @ac_dolfin_ld_flags@
-\end{lstlisting}
-In this way, if dolfin.h is available, CPPFLAGS contains also the flag  \verb$-DHAVE_DOLFIN_H.$
-
-\paragraph {program.cc}  Our .cc program, should thus include the header dolfin.h only if
-\verb$-DHAVE_DOLFIN_H$ is defined at compilation time.
-For example
-
-\begin{lstlisting}
-    #ifdef HAVE_DOLFIN_H
-    #include <dolfin.h>
-    #endif
-    int main ()
-    {
-
-    #ifndef HAVE_DOLFIN_H
-        error("program: the program was built without support for dolfin");
-    #else
-      /* Body of your function */
-    #endif
-     return 0;
-    }
-
-\end{lstlisting}
-\paragraph {Warning} If in the Makefile.in you write something like
-\begin{lstlisting}
-    HAVE_DOLFIN_H = @HAVE_DOLFIN_H@
-    ifdef HAVE_DOLFIN_H
-      CPPFLAGS += -DHAVE_DOLFIN_H
-      LIBS += -ldolfin
-    endif
- \end{lstlisting}
- it doesn't work because the variable \verb$HAVE_DOLFIN_H$ seems to be always defined, even if the header is not available.
+

\iffalse
+In the following examples we can see directly in action the classes and the functions presented in the
+chapters before. A comparison with DOLFIN is given only for the first example, while more extensive case can
+be found online. We do not report the code for all the examples but only the relevant parts.
+
With the following examples, we can see directly in action the new features and understand how they work.

Navier-Stokes: we learn how to deal with a vector-field problem and how we can save the solution using the
@@ -854,9 +1056,10 @@
while here we highlight only the  implementation detail relevant for our pkg.
\fi
\section{Navier-Stokes equation with Chorin-Temam projection algorithm}
-
+Navier-Stokes: we learn how to deal with a vector-field problem and how we can save the solution using the
+\verb$fem_save$ () function. We also use the msh pkg to generate a mesh using gmesh.
\paragraph{TentativeVelocity.ufl}
-\begin{lstlisting}
+\begin{lstlisting}[language=Octave]
# Copyright (C) 2010 Anders Logg
# Define function spaces (P2-P1)
V = VectorElement("CG", triangle, 2)
@@ -881,7 +1084,7 @@
\end{lstlisting}

\paragraph{PressureUpdate.ufl}
-\begin{lstlisting}
+\begin{lstlisting}[language=Octave]
# Copyright (C) 2010 Anders Logg
# Define function spaces (P2-P1)
V = VectorElement("CG", triangle, 2)
@@ -902,7 +1105,7 @@
\end{lstlisting}

\paragraph{VelocityUpdate.ufl}
-\begin{lstlisting}
+\begin{lstlisting}[language=Octave]
# Copyright (C) 2010 Anders Logg
# Define function spaces (P2-P1)
V = VectorElement("CG", triangle, 2)
@@ -923,7 +1126,7 @@
\end{lstlisting}

\paragraph{NS.m}
-\begin{lstlisting}
+\begin{lstlisting}[language=Octave]
import_ufl_Problem ("TentativeVelocity");
import_ufl_Problem ("VelocityUpdate");
@@ -993,7 +1196,7 @@
\end{lstlisting}

\paragraph{L-shape-domain.m}
-\begin{lstlisting}
+\begin{lstlisting}[language=Octave]
name = [tmpnam ".geo"];
fid = fopen (name, "w");
fputs (fid,"Point (1)  = {0, 0, 0, 0.1};\n");
@@ -1020,6 +1223,131 @@

\newpage
+\appendix
+\chapter{API reference}
+
+\section{Import problem defined with ufl}
+\subsection*{import\_ufl\_BilinearForm}
+\subimport{latex/}{API/import_ufl_BilinearForm.tex}
+\subsection*{import\_ufl\_LinearForm}
+\subimport{latex/}{API/import_ufl_LinearForm.tex}
+ \subsection*{ import\_ufl\_Functional}
+ \subimport{latex/}{API/import_ufl_Functional.tex}
+ \subsection*{ import\_ufl\_FunctionSpace}
+  \subimport{latex/}{API/import_ufl_FunctionSpace.tex}
+ \subsection*{ import\_ufl\_Problem}
+   \subimport{latex/}{API/import_ufl_Problem.tex}
+\section{Problem geometry and FE space}
+ \subsection*{ Mesh}
+ \subimport{latex/}{API/Mesh.tex}
+ \subsection*{ FunctionSpace}
+  \subimport{latex/}{API/FunctionSpace.tex}
+ \subsection*{ SubSpace}
+   \subimport{latex/}{API/SubSpace.tex}
+\section{Problem variables}
+ \subsection*{ Constant}
+   \subimport{latex/}{API/Constant.tex}
+ \subsection*{ Expression}
+   \subimport{latex/}{API/Expression.tex}
+ \subsection*{ Function}
+  \subimport{latex/}{API/Function.tex}
+ \subsection*{ DirichletBC}
+  \subimport{latex/}{API/DirichletBC.tex}
+\section{Definition of the abstract Variational problem}
+ \subsection*{ BilinearForm}
+  \subimport{latex/}{API/BilinearForm.tex}
+\subsection*{  LinearForm}
+  \subimport{latex/}{API/LinearForm.tex}
+\subsection*{  ResidualForm}
+  \subimport{latex/}{API/ResidualForm.tex}
+ \subsection*{ JacobianForm}
+   \subimport{latex/}{API/JacobianForm.tex}
+ \subsection*{ Functional}
+      \subimport{latex/}{API/Functional.tex}
+\section{Creation of the discretized problem}
+\subsection*{  assemble}
+\subimport{latex/}{API/assemble.tex}
+\subsection*{  assemble\_system}
+\subimport{latex/}{API/assemble_system.tex}
+\section{Post processing}
+\subsection*{  @function/save}
+\subimport{latex/}{API/save.tex}
+\subsection*{  @function/plot}
+\subimport{latex/}{API/plot.tex}
+\subsection*{  @mesh/plot}
+\subimport{latex/}{API/plot_m.tex}
+\subsection*{  @function/feval}
+\subimport{latex/}{API/feval.tex}
+
+
+
+
+\chapter{Autoconf and Automake}
+ In this section we want to discuss how we can write a config.ac and a Makefile.in files which:
+\begin{itemize}
+    \item check if a program is available and stop if it is not
+    \item check if a header file is available and issue a warning if not, but go ahead with the compilation
+\end{itemize}
+
+To reach this goal, we need two components:
+
+\paragraph{configure.ac} Is a file which checks whether the program/header is available or not
+and sets consequently the values of some variables.
+\begin{lstlisting}[language=make]
+    # Checks if the program mkoctfile is available and sets the variable HAVE_MKOCTFILE consequently
+    AC_CHECK_PROG([HAVE_MKOCTFILE], [mkoctfile], [yes], [no])
+    # if mkoctfile is not available, it issues an error and stops the compilation
+    if [test $HAVE_MKOCTFILE = "no"]; then + AC_MSG_ERROR([mkoctfile required to install$PACKAGE_NAME])
+    fi
+
+    #Checks if the header dolfin.h is available; if it is available, the value of the ac_dolfin_cpp_flags is substituted with -DHAVE_DOLFIN_H, otherwise it is left empty and a warning message is printed
+      [AC_SUBST(ac_dolfin_cpp_flags,-DHAVE_DOLFIN_H)  AC_SUBST(ac_dolfin_ld_flags,-ldolfin)],
+      [AC_MSG_WARN([dolfin headers could not be found, some functionalities will be disabled, don't worry your package will still be working, though.])] ).
+
+    # It generates the Makefile, using the template described below
+    AC_CONFIG_FILES([Makefile])
+\end{lstlisting}
+\paragraph{Makefile.ac} This file is a template for the Makefile, which will be automatically generated when the configure.ac
+file is executed. The values of the variable \verb$ac_dolfin_cpp_flags$ and \verb$ac_dolfin_ld_flags$ are substituted with the
+results obtained above:
+\begin{lstlisting}[language=make]
+    CPPFLAGS += @ac_dolfin_cpp_flags@
+    LDFLAGS += @ac_dolfin_ld_flags@
+\end{lstlisting}
+
+In this way, if dolfin.h is available, CPPFLAGS contains also the flag -DHAVE\_DOLFIN\_H.
+
+\paragraph {program.cc}  Our .cc program, should thus include the header dolfin.h only if
+\verb$-DHAVE_DOLFIN_H$ is defined at compilation time.
+For example
+
+\begin{lstlisting}
+    #ifdef HAVE_DOLFIN_H
+    #include <dolfin.h>
+    #endif
+    int main ()
+    {
+
+    #ifndef HAVE_DOLFIN_H
+        error("program: the program was built without support for dolfin");
+    #else
+      /* Body of your function */
+    #endif
+     return 0;
+    }
+
+\end{lstlisting}
+\paragraph {Warning} If in the Makefile.in you write something like
+\begin{lstlisting}[language=make]
+    HAVE_DOLFIN_H = @HAVE_DOLFIN_H@
+    ifdef HAVE_DOLFIN_H
+      CPPFLAGS += -DHAVE_DOLFIN_H
+      LIBS += -ldolfin
+    endif
+ \end{lstlisting}
+ it doesn't work because the variable \verb$HAVE_DOLFIN_H$ seems to be always defined, even if the header is not available.

\bibliographystyle{unsrt}
\bibliography{doc}