
\documentclass[10pt]{beamer}
%\usepackage{epsfig}             % inkludering av grafikk
\usepackage{graphicx}
\pgfdeclaremask{computer}{plots/th_r2_u}
\usepackage[english]{babel}
\usepackage{supertabular,alltt,verbatim,moreverb,subfigure}
\usepackage{amssymb,wasysym}
\usepackage{epsfig}
\newcommand{\mathbfx}[1]{{\mbox{\boldmath $#1$}}}

\mode<presentation>
%\mode<article>
% %{
%\usetheme{Warsaw}
%   % or ...\newcommand{\eps}{\varepsilon}
\renewcommand{\v}{\mathbf{v}}
\newcommand{\V}{\mathbf{V}}
\renewcommand{\L}{\mathbf{L}}
\renewcommand{\u}{\mathbf{u}}
\newcommand{\w}{\mathbf{w}}
\newcommand{\f}{\mathbf{f}}
\newcommand{\y}{\mathbf{y}}
\newcommand{\g}{\mathbf{g}}
\newcommand{\G}{\mathbf{G}}
\newcommand{\h}{\mathbf{h}}
\renewcommand{\H}{\mathbf{H}}
\newcommand{\n}{\mathbf{n}}
\renewcommand{\k}{\mathbf{k}}
\renewcommand{\l}{\mathbf{l}}
\renewcommand{\r}{\mathbf{r}}
\renewcommand{\t}{\mathbf{t}}
\newcommand{\s}{\mathbf{s}}
\renewcommand{\div}{\operatorname{div}}
%\newcommand{\R}{{\mathbb{R}}}
%\renewcommand{\P}{{\mathbf{\mathbb{P}}}}
%\newcommand{\PP}{{\mathbb{ P}}}
\newcommand{\R}{{\mathbf{R}}}
\renewcommand{\P}{{\mathbf{P}}}
\newcommand{\PP}{{\mathbf{ P}}}
%\usetheme{Darmstadt}
\usetheme{Warsaw}
%\setbeamercovered{transparent}
%   % or whatever (possibly just delete it)
% %}
%
%
% % or whatever

\usepackage{times}
\usepackage[latin1]{inputenc}
\title{SyFi - An Element Matrix Factory, with Emphasis on the Incompressible Navier-Stokes Equations }
\author{Kent-Andre Mardal}

\begin{document}
\begin{frame}
    \titlepage
\end{frame}

%\section{Outline}
%\section{Motivation}
\begin{frame}
\frametitle{Outline - Short Description of SyFi}
\begin{block}{Purpose}
\begin{itemize}
\item SyFi is a tool for defining polygons, polynomial spaces, 
	degrees of freedom, and   finite elements 
\item SyFi makes it easy to define weak forms (differentiation and
      integration of polynomials over polygons)  
\item SyFi computes matrices (element matrices or global matrices) 
\item SyFi generates efficient C++ code for global matrices    
\end{itemize}
\end{block}


\begin{block}{Dependencies}
\begin{itemize}
\item SyFi relies heavily on GiNaC and Swiginac for the symbolic computations 
and code generation 
\item SyFi can generate matrices based on either a Dolfin or a Diffpack mesh (we
plan to include other meshes soon)
\item SyFi can generate either Epetra or PyCC matrices (we plan to include
	other matrices soon).  
\end{itemize}

\end{block}
\end{frame}



%\section{GiNaC/Swiginac}
\begin{frame}
\frametitle{Short Description of GiNaC and Swiginac}
\begin{block}{GiNaC}
\begin{itemize}
\item GiNaC is a C++ library for symbolic mathematics 
\item URL: www.ginac.de  
\item License : GPL 
\end{itemize}
\end{block}

\begin{block}{Swiginac}
\begin{itemize}
\item Swiginac is a Python interface to GiNaC 
\item URL: http://swiginac.berlios.de/ 
\item License: Open 
\end{itemize}
\end{block}
\end{frame}


\begin{frame}[fragile]
\frametitle{Swiginac Code Example}

\begin{verbatim}
from swiginac import *  
x = symbol('x'); y = symbol('y') 

f = sin(x*x*y) 
print "f = ", f 

dfdx = diff(f,x)
print "df/dx = ", dfdx 

g = pow(x,9)*(1-x) 
intg = integral(x,0,1,g)



\end{verbatim}


\end{frame}

\begin{frame}
\frametitle{SyFi Extends GiNaC/Swiginac}
\begin{block}{ GiNaC/Swiginac supports:} 
\begin{itemize}
\item Polynomials 
\item Differentiation with respect to one variable 
\item Integration with respect to one variable 
\end{itemize}
\end{block}
\begin{block}{Basic Extensions in SyFi:}
\begin{itemize}
\item Polynomial spaces (such as Legendre and Bernstein)  
\item Differentiations with respect to several 
variables 
\item Integration over polygons  
\end{itemize}
\end{block}

$\rightarrow$ SyFi extends GiNaC/Swiginac with the ingredients
typically needed in finite element methods  


\end{frame}

\begin{frame}
\frametitle{Elements currently implemented in SyFi}
\begin{block}{Finite Elements}
\begin{itemize}
\item continuous and discontinuous Lagrangian elements (arbitrary order) 
\item Nedelec elements (arbitrary order) 
\item Raviart-Thomas elements (arbitrary order) 
\item Crouzeix-Raviart elements 
\item Hermite elements 
\item Bubble elements 
\end{itemize}
\end{block}
\begin{block}{Matrices/Weak forms}
\begin{itemize}
\item mass matrix  
\item convection matrix   
\item diffusion matrix 
\item divergence matrix   
\end{itemize}
\end{block}
\end{frame}

\begin{frame}
\frametitle{Evaluation of Weak Forms in SyFi}
We will now demonstrate the computation of various element matrices
in SyFi 
\begin{itemize}
\item The divergence matrix with mixed elements:  
\[
\mathbfx{B}_{ij} = \int_T \nabla \cdot \mathbfx{N}_i \, L_j \, dx   
\]
where $\mathbfx{N}_i$ and $L_j$ are the basis functions of the velocity
and pressure elements 
\item The computation of the Jacobian matrix 
\[
\mathbfx{J}_{ij} =  \frac{\partial \mathbfx{F}_i}{\partial u_j } 
\]
in the case of nonlinear convection diffusion
\[
\mathbfx{F}_i = \int_T (\mathbfx{u}\cdot \nabla \mathbfx{u})\cdot \mathbfx{N}_i   
 + \nabla \mathbfx{u}:\nabla \mathbfx{N}_i) \, dx    
\]
\end{itemize}
\end{frame}







\begin{frame}[fragile]
\frametitle{SyFi Code Example : Divergence Matrix }

{
\renewcommand{\baselinestretch}{0.85}\footnotesize
\begin{verbatim}
from swiginac import *
from SyFi import *

polygon = ReferenceTriangle()
v_element = VectorLagrangeFE(polygon,2)
v_element.set_size(2)
v_element.compute_basis_functions()

p_element = LagrangeFE(polygon,1)
p_element.compute_basis_functions()

for i in range(0,v_element.nbf()): 
    for j in range(0,p_element.nbf()): 
        integrand = div(v_element.N(i))*p_element.N(j)
        Aij =  polygon.integrate(integrand)
        print "A[%d,%d]=%s "% (i,j, Aij) 
\end{verbatim}
}


\end{frame}






\begin{frame}[fragile]
\frametitle{SyFi Code Example : Convection-Diffusion Matrix}
{
\renewcommand{\baselinestretch}{0.85}\footnotesize
\begin{verbatim}

.. initialize element 

for i in range(0,fe.nbf()): 

  # compute diffusion term 
  fi_diffusion = inner(grad(u), grad(fe.N(i))) 
  
  # compute convection term 
  uxgradu = (u.transpose()*grad(u)).evalm()  
  fi_convection = inner(uxgradu, fe.N(i), True) 

  fi = fi_diffusion + fi_convection
  Fi = polygon.integrate(fi) 

  for j in range(0,fe.nbf()): 
    # differentiate to get the Jacobian 
    Jij = diff(Fi, uj) 
    print "J[%d,%d]=%s "%(i,j,Jij)

\end{verbatim}
}
\end{frame}


\begin{frame}[fragile]
\frametitle{SyFi Code Example : Convection and Power-law Diffusion }

{
\renewcommand{\baselinestretch}{0.85}\footnotesize
\begin{verbatim}

n = symbol("n") 

for i in range(0,fe.nbf()): 

  # nonlinear power-law diffusion term 
  mu = inner(grad(u), grad(u))
  fi_diffusion = pow(mu,n)*inner(grad(u), grad(fe.N(i))) 
  
  # nonlinear convection term 
  uxgradu = (u.transpose()*grad(u)).evalm()  
  fi_convection = inner(uxgradu, fe.N(i), True) 

  fi = fi_diffusion + fi_convection

  Fi = polygon.integrate(fi) 

  for j in range(0,fe.nbf()): 
    # differentiate to get the Jacobian 
    Jij = diff(Fi, uj) 
    print "J[%d,%d]=%s\n"%(i,j, Jij.evalf().printc())



\end{verbatim}
}


\end{frame}

\begin{frame}[fragile]
\frametitle{Creation of Epetra Matrices}
{
\renewcommand{\baselinestretch}{0.85}\footnotesize
\begin{verbatim}
class EpetraMatrixFactory 
{
public:
  Epetra_Comm       *Comm; 
  Epetra_Map        *Map; 
  MapMatrixFactory  *mapfac; 
  Mesh              *mesh;
  Dof_ptv           *idof,jdof; 
  int order1,order2; 
  
  EpetraMatrixFactory(Mesh *mesh, Epetra_Comm* Comm);
  
  // scalar mass matrix based on Lagrangian elements 
  Epetra_CrsMatrix*  computeMassMatrix();
  
  // scalar stiffness matrix based on Lagrangian elements 
  Epetra_CrsMatrix*  computeStiffnessMatrix(); 
  
  // scalar convection matrix based on Lagrangian elements 
  Epetra_CrsMatrix*  computeConvectionMatrix(VectorFunction& func,); 
  
  // vector div matrix based on vector Lagrangian elements 
  Epetra_CrsMatrix*  computeDivMatrix(); 

};
\end{verbatim}
}
\end{frame}



\begin{frame}
\frametitle{Concluding Remarks}
\begin{block}{Present Use of SyFi}
\begin{itemize}
\item We have implemented a set of simple test examples within SyFi/PyCC
for the Poisson problem, Stokes problem, convection-diffusion problems
and Navier-Stokes equations 
\item We have used SyFi/PyCC in rather advanced applications concerning the
electrical activity of the heart 
\end{itemize}
\end{block}
\begin{block}{Future}
\begin{itemize}
\item Support other meshes and other matrices
\item Implement more elements
\item Develop fluid-structure solvers within PyCC
\end{itemize}
\end{block}

\end{frame}



\end{document}







