%
% $Id: adaptation.tex,v 1.2 1997/09/09 21:18:47 prudhomm Exp $
%
% SUMMARY:      
% USAGE:        
%
% AUTHOR:       Christophe Prud'homme
% ORG:           
% E-MAIL:       Christophe.Prudhomme@asci.fr
%
% ORIG-DATE:     8-Feb-97 at 16:46:30
% LAST-MOD:     10-Feb-97 at 23:42:36 by Christophe Prud'homme
%
% DESCRIPTION:  
%
% $Log: adaptation.tex,v $
% Revision 1.2  1997/09/09 21:18:47  prudhomm
% updated some document files
% updated configure.in
%
% Revision 1.1  1997/02/08 16:26:41  prudhomm
% Splitted freefem.tex into parts each parts containing a chapter of the documentation
%
% DESCRIP-END.

\chapter{Mesh adaptation}
\label{cha:adapt}

\index{adapt@\texttt{adaptmesh}}
In \textbf{Gfem} you can use mesh adaptation\index[con]{mesh adaptation} to improve the mesh qualities
according to the solutions(one or more) of a first computing; it is easy to
use this feature of \textbf{Gfem}, all you have to do is to use the
reserved word \verb+adaptmesh+ .

This code was developed by \emph{Manollo J. Castro}. It was ported for
\textbf{Gfem} by \emph{Christophe Prud'homme}.


\section{One example}
In order to simplify the documentation and to go straigth to direct
applications, let's look at one example: the backward step problem with Navier
stokes equations. Here is the \textbf{Gfem} script:

%% node  Example, What does it do?, One example, One example
\subsection{Example}
%%  node-name,  next,  previous,  up

\begin{verbatim}
nowait;
border(1,0,1,6,5)  begin x:=0;      y:=1-t   end;
border(2,0,1,15,2) begin x:=2*t;    y:=0     end;
border(2,0,1,10,2) begin x:=2;      y:=-t    end;
border(2,0,1,20,2) begin x:=2+3*t;  y:=-1    end;
border(2,0,1,35,2) begin x:=5+15*t; y:=-1    end;
border(4,0,1,10,2) begin x:=20;     y:=-1+2*t end;
border(5,0,1,35,5) begin x:=5+15*(1-t); y:=1 end;
border(5,0,1,40,5) begin x:=5*(1-t);y:=1     end;

buildmesh(1500);
nu := 0.001; dt := 0.4;

/* initial values */
u = y*(1-y)*one(y>0);
v = 0;
p = 2*nu*x*one(y>0);
un = u; vn = v; 
i:=1; j:=2; k:=3;count:=1;
iter(500)
begin 
 if (count % 100 == 0) then { /* adapt every 100 iterations */
   adaptmesh(u,p);
   i:=1; j:=2;k:=3;
   wait; /* wait after each displayed solution */
   plot(u);
   plot(v);
   plot(p);
   nowait; /* do not wait anymore */
 };
 /* increment the counter */
 count:=count+1;

 f=convect(un,u,v,dt);  g=convect(vn,u,v,dt);

 solve(u,i){         /*Horizontal velocity*/
          onbdy(1) u = y*(1-y);
          onbdy(2,5) u = 0;
          onbdy(4)dnu(u)=0;
   pde(u) id(u)/dt-laplace(u)*nu = f/dt -dx(p);
 };
 
 solve(v,j){        /* Vertical velocity */
          onbdy(1,2,4,5) v = 0;
   pde(v) id(v)/dt-laplace(v)*nu = g/dt -dy(p);
 };

         solve(p,k) {      /*  Pressure */
          onbdy(1,2,5) dnu(p) = 0;
          onbdy(4) p=0;
   pde(p)  -laplace(p)= -(dx(f) + dy(g))/dt;
  };
 un = u;  vn = v; i:=-1; j:=-2; k:=-3;
 end ;
wait;
plot(u);plot(v);plot(p);
\end{verbatim}



%% node  What does it do?,  , Example, One example
\subsection{What does it do?}
%%  node-name,  next,  previous,  up

As you can see in the example, we are doing 500 iterations and we adapt the
mesh every 100 iterations. This is done with the counter \verb+count+  which is
initialized to 1 before the loop, then it is incremented every iterations
until 100. Then we use the \verb+if-then+  construction to test whether the
counter is equal to 100 or not. If it is the case, we adapt the mesh
according to two functions \verb+u,p+; we put \verb+i,j,k+  to
their positive value so that the matrices will be reconstructed and finally we
reinitialize the counter to \verb+1+ .

After the adpatation, the mesh is automatically redrawn(there is no need
to use a trick like
\begin{verbatim}
w=0;
plot(w);
\end{verbatim}
to visualize the newly adapted mesh.

Note the new argument for \verb+border+ . This last argument is the reference
of the first point of this border(it is optional); this allows to define
precisely the references of each edges of the boundary. It is \textbf{strongly}
advised to use this when you do mesh adaptation\index[con]{mesh adaptation}, otherwise you will have
undefined edges and vertices references.

%% node  The options,  , One example, Mesh adaptation
\section{The options}
%%  node-name,  next,  previous,  up

As you have certainly felt \textbf{FreeFEM} is not user-friendly, so if you
want to change certain options of this utility, you will haver to change the
code and recompile it.

However in  \textbf{XGfem} this tool is competely integrated via a dialog
box. All you have to do is to click on the menu \texttt{Execute} , then
choose the \texttt{Adaptation mesh setup} . A dialog box will be popped up.
The options are selected by default like in \textbf{FreeFEM}.


\subsection{Anisotropy?}

You can choose between isotropic\index[con]{isotropic mesh} or
anisotropic\index[con]{anisotropic mesh} meshes. One will generate
meshes with no main stretching direction, the other will have one so that the
triangle will be stretched along the stream.


\subsection{Interpolation}

The mesh tool offers four kind of interpolation\index[con]{interpolation}
\begin{itemize}
\item
Classic P1
\item
P1/Local L2
\item
P1/Global L2
\item
P1/Local L1
\end{itemize}

%% node  Advanced parameters,  , Interpolation, The options
\subsection{Advanced parameters}
%%  node-name,  next,  previous,  up

They are parameters which are not often changed, their value by default are
good. However you might want to change them as long as you know what you are
doing.

\begin{itemize}
\item
Initial regularisation: regularise the mesh before any adaptation, this
is mainly edges swapping.
\item
Final regularisation: like the previous one it does edge swapping to
clean up the mesh; moreover it deletes edges, triangles or vertices so that
the mesh fully respects the metric and the parameters.
\end{itemize}
You can type the minimal angle to determine where are the corners;
There are others options, but it is better to leave these untouched.

%
%%%%%%%%%%%%% Some Settings for emacs and auc-TeX
% Local Variables:
% TeX-master: "freefem"
% TeX-parse-self: t
% TeX-auto-save: t
% TeX-auto-regexp-list: TeX-auto-full-regexp-list
% End:
% 

