Mercurial > fem-fenics-eugenio
changeset 205:17b92c718a2b
Presentation for the seminar at MOX
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Thu, 30 Jan 2014 09:14:35 +0100 |
parents | 0faaf956bd3a |
children | 72633d939a81 |
files | doc/presentation/Mox_30_01/Makefile doc/presentation/Mox_30_01/beamerthemeOctave.sty doc/presentation/Mox_30_01/esempi/classe.cc doc/presentation/Mox_30_01/esempi/func.cc doc/presentation/Mox_30_01/esempi/generate_fs.m doc/presentation/Mox_30_01/esempi/import_ufl_FunctionSpace.m doc/presentation/Mox_30_01/fem-library.tex doc/presentation/Mox_30_01/func.png doc/presentation/Mox_30_01/hyper.png doc/presentation/Mox_30_01/inst.png doc/presentation/Mox_30_01/mixed.png doc/presentation/Mox_30_01/ns.png doc/presentation/Mox_30_01/octave-header.png doc/presentation/Mox_30_01/octfem.png doc/presentation/Mox_30_01/pois.png doc/presentation/Mox_30_01/pois2.png doc/presentation/Mox_30_01/wiki.png |
diffstat | 17 files changed, 461 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/Makefile Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,14 @@ +SLIDES=fem-library.pdf + +all: $(SLIDES) + +%.pdf: %.tex beamerthemeOctave.sty octave-header.png + pdflatex $*.tex + pdflatex $*.tex + pdflatex $*.tex + +clean: + $(RM) -f *.aux *.log *.nav *.out *.snm *.toc *~ *.backup *.vrb + +distclean: clean + $(RM) -f $(SLIDES)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/beamerthemeOctave.sty Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,72 @@ +\usetheme{Rochester} + +\RequirePackage{pgf} + +\pgfdeclareimage[width=1.0\paperwidth]{octave-header}{octave-header} + +\pgfdeclareimage[height=0.03\paperwidth]{cc-header}{cc-header} + +\setbeamertemplate{blocks}[rounded][shadow=true] + +\beamer@headheight=0.13\paperwidth + +\definecolor{octaveorange}{HTML}{F7800A} +\definecolor{octavegray}{HTML}{686868} +\definecolor{octavelightgray}{HTML}{EEEEEE} +\definecolor{octaveblue}{HTML}{236EAF} +\setbeamercolor*{Title bar}{fg=octaveblue} +\setbeamercolor*{Location bar}{fg=octaveorange,bg=octavelightgray} +\setbeamercolor*{frametitle}{parent=Title bar} +\setbeamercolor*{block title}{bg=octaveblue,fg=white} +\setbeamercolor*{block body}{bg=octavelightgray,fg=octavegray} +\setbeamercolor*{normal text}{bg=white,fg=octavegray} +\setbeamercolor*{section in head/foot}{bg=octaveblue,fg=white} + +\usecolortheme[named=octaveblue]{structure} + +\setbeamerfont{section in head/foot}{size=\tiny,series=\normalfont} +\setbeamerfont{frametitle}{size=\Large,series=\bfseries} + +\setbeamertemplate{title page}[default][colsep=-4bp,rounded=true,shadow=true,header=false] +%\setbeamertemplate{headline} +\setbeamertemplate{frametitle} +{ + \vskip-0.125\beamer@headheight + \vskip-\baselineskip + \vskip-0.2cm + \hskip1.0cm\usebeamerfont*{frametitle}\insertframetitle + \vskip-0.10em + \hskip1.0cm\usebeamerfont*{framesubtitle}\insertframesubtitle +} + +\setbeamertemplate{headline} +{ + \pgfuseimage{octave-header} + \vskip -1.95cm + \linethickness{0.0pt} + + \framelatex{ + \begin{beamercolorbox}[wd=\paperwidth,ht=0.3\beamer@headheight]{Title bar} + \usebeamerfont{section in head/foot}% + \insertsectionnavigationhorizontal{0pt}{\hskip1.2cm}{}% + \end{beamercolorbox}} + + \framelatex{ + \begin{beamercolorbox}[wd=\paperwidth,ht=0.7\beamer@headheight]{Title bar} + \end{beamercolorbox}} +} + +\setbeamertemplate{footline} +{ + % \pgfuseimage{cc-header} + \linethickness{0.25pt} + \framelatex{ + \begin{beamercolorbox}[leftskip=.3cm,wd=\paperwidth,ht=0.3\beamer@headheight,sep=0.1cm]{Location bar} + \usebeamerfont{section in head/foot}% + \insertshortauthor~|~\insertshorttitle + \hfill + \insertframenumber/\inserttotalframenumber + \end{beamercolorbox}} +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/esempi/classe.cc Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,72 @@ +#include <dolfin.h> +#include <octave/oct.h> +class mesh : public octave_base_value +{ + public: + mesh () : octave_base_value () {} + + mesh (Array<double>& p, Array<octave_idx_type>& e, + Array<octave_idx_type>& t); + + ~mesh(void) {} + + bool is_defined (void) const { return true; } + + const dolfin::Mesh & get_msh (void) const { return *pmsh; } + + private: + boost::shared_ptr<const dolfin::Mesh> pmsh; + + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; + DECLARE_OCTAVE_ALLOCATOR; +}; +static bool mesh_type_loaded = false; + + + + + +#define DECLARE_OCTAVE_ALLOCATOR \ + public: \ + void *operator new (size_t size, void *p) \ + { return ::operator new (size, p); } \ + void operator delete (void *p, void *) \ + { ::operator delete (p); } \ + void *operator new (size_t size) { return allocator.alloc (size); } \ + void operator delete (void *p, size_t size) { allocator.free (p, size); } \ + private: \ + static octave_allocator allocator; + + +#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA(VIRTUAL) \ + public: \ + VIRTUAL int type_id (void) const { return t_id; } \ + VIRTUAL std::string type_name (void) const { return t_name; } \ + VIRTUAL std::string class_name (void) const { return c_name; } \ + static int static_type_id (void) { return t_id; } \ + static std::string static_type_name (void) { return t_name; } \ + static std::string static_class_name (void) { return c_name; } \ + static void register_type (void); \ + \ + private: \ + static int t_id; \ + static const std::string t_name; \ + static const std::string c_name; + + +DEFINE_OCTAVE_ALLOCATOR (mesh); +//#define DEFINE_OCTAVE_ALLOCATOR(t) \ +// octave_allocator t::allocator (sizeof (t)) + + +DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (mesh, "mesh", "mesh"); +// #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \ +// int t::t_id (-1); \ +// const std::string t::t_name (n); \ +// const std::string t::c_name (c); \ +// void t::register_type (void) \ +// { \ +// static t exemplar; \ +// octave_value v (&exemplar, true); \ +// t_id = octave_value_typeinfo::register_type (t::t_name, t::c_name, v); \ +// }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/esempi/func.cc Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,29 @@ +DEFUN_DLD (FunctionSpace, args, , "initialize a FunctionSpace from a mesh") +{ +int nargin = args.length (); +octave_value retval; + +if (! mesh_type_loaded) + { + mesh::register_type (); + mesh_type_loaded = true; + mlock (); + } + +if (args(0).type_id () == mesh::static_type_id ()) + { + // 1 read data + const mesh & msho = static_cast<const mesh&>(args(0).get_rep ()); + + // 2 extract the data stored in the Octave class as a DOLFIN obj + const dolfin::Mesh & mshd = msho.get_msh () + + // 3 build a new object using DOLFIN + boost::shared_ptr <const dolfin::FunctionSpace> g + (new Poisson::FunctionSpace (mshd)); + + // 4 convert the new object from DOLFIN to Octave and return it + retval = new functionspace (g); + return retval; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/esempi/generate_fs.m Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,22 @@ +function output = generate_fs (ufl_name) + +STRING ="\n\ +#include <fem-fenics/functionspace.h>\n\ +#include <fem-fenics/mesh.h>\n\ +#include ""@@UFL_NAME@@.h""\n\ +\n\ +DEFUN_DLD (@@UFL_NAME@@_FunctionSpace, args, , ""initialize a fs"")\n\ +{\n\ + ...\n\ + const mesh & msho = static_cast<const mesh&> (args(0).get_rep ());\n\ + const dolfin::Mesh & mshd = msho.get_msh ();\n\ + boost::shared_ptr <const dolfin::FunctionSpace> g (new @@UFL_NAME@@::FunctionSpace (mshd));\n\ + ...\n\ + retval = new functionspace(g);\n\ + return retval;\n\ +}"; + +STRING = strrep (STRING, "@@UFL_NAME@@", ufl_name); + +fid = fopen (sprintf ("%s_FunctionSpace.cc", ufl_name), ); +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/esempi/import_ufl_FunctionSpace.m Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,19 @@ +function import_ufl_FunctionSpace (var_prob) + ... + + % funzione che scrive il file .cc includendo l header specifico + output = generate_fs (var_prob); + % funzione che scrive il makefile per + % 1) Compilare l header Poisson.ufl + % 2) Compila Poisson_FunctionSpace.cc + output += generate_makefile (var_prob, private); + if output != 0 + error ("Compilation failed"); + else + % il makefile viene eseguito in un terminale + [output, textfile] = system (sprintf ("make -f Makefile_%s fs", var_prob)); + [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); + + endif + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/presentation/Mox_30_01/fem-library.tex Thu Jan 30 09:14:35 2014 +0100 @@ -0,0 +1,233 @@ +\documentclass[10pt]{beamer} + + +\usetheme{Octave} +\usepackage{thumbpdf} +\usepackage{wasysym} +\usepackage{ucs} +\usepackage[utf8]{inputenc} +\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade} +\usepackage{verbatim} +\usepackage{listings} +\usepackage{attachfile} +\usepackage{mathtools} +\usepackage{parcolumns} +\usepackage[framemethod=TikZ]{mdframed} +\usepackage[strict]{changepage} + + +\lstset{ + language=C++, + keywordstyle=\bfseries\ttfamily\color[rgb]{0,0,1}, + identifierstyle=\ttfamily, + commentstyle=\color[rgb]{0.133,0.545,0.133}, + stringstyle=\ttfamily\color[rgb]{0.627,0.126,0.941}, + showstringspaces=false, + basicstyle=\scriptsize, + numberstyle=\tiny, + numbers=left, + stepnumber=1, + numbersep=10pt, + tabsize=2, + breaklines=true, + prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, + breakatwhitespace=false, + aboveskip={1.5\baselineskip}, + columns=fixed, + upquote=true, + extendedchars=true, +} + + + + +\title{Fem-fenics} +\subtitle{Una libreria di elementi finiti per Octave} +\author[Marco Vassallo]{\bf Marco Vassallo } +\date{30 Gennaio 2014} +\begin{document} + +\frame[plain]{\titlepage} + +\section*{} +\begin{frame} + \frametitle{Outline} + \tableofcontents[section=2] +\end{frame} + +\AtBeginSection[] +{\frame<handout:0>{\frametitle{Outline}\tableofcontents[currentsection]}} + +%\AtBeginSubsection[] +%{\frame<handout:0>{\frametitle{Outline}\tableofcontents[sectionstyle=show/hide,subsectionstyle=show/shaded/hide]}} + +\newcommand<>{\highlighton}[1]{% +\alt#2{\structure{#1}}{{#1}}} + +\newcommand{\icon}[1]{\pgfimage[height=1em]{#1}} + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%% Content starts here %%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\section{Una libreria di elementi finiti per Octave} +\subsection{Introduzione} +\begin{frame}[fragile]{Why?} + \begin{itemize} + \item Non vi è una libreria generica in Octave (msh, fpl, bim, ..) + \item Lasciare all'utente la scelta di utilizzare il linguaggio che preferisce + \item Sfruttare le potenzialità di Octave per la risoluzione di sistemi lineari + e sistemi di o.d.e + \item Migliorare i punti deboli dell'interfaccia Python + \end{itemize} + +\end{frame} + +\begin{frame} +\frametitle{Installazione, Documentazione, Wiki, ...} +\only<1>{ +\texttt{pkg install fem-fenics -forge} +\begin{center} +\includegraphics[width=.9\linewidth]{inst.png} +\end{center} +} + + +\only<2>{ +\url{http://wiki.octave.org/Fem-fenics} +\begin{center} +\includegraphics[width=.9\linewidth]{wiki.png} +\end{center} +} + + +\only<3>{ +\url{http://octave.sourceforge.net/fem-fenics/overview.html} +\begin{center} +\includegraphics[width=.9\linewidth]{func.png} +\end{center} +} +\end{frame} + +\subsection{Esempi} + +\begin{frame}[fragile]{Poisson} +\scriptsize +\only<1>{ +\includegraphics[width=1.\linewidth]{pois.png}} + +\only<2>{ +\includegraphics[width=1.\linewidth]{pois2.png}} + +\end{frame} + +\begin{frame}[fragile]{Navier Stokes} +\scriptsize +\includegraphics[width=1.\linewidth]{ns.png} +\end{frame} + +\begin{frame}[fragile]{Mixed Poisson} +\scriptsize +\includegraphics[width=1.\linewidth]{mixed.png} + +\end{frame} + +\begin{frame}[fragile]{Elasticity} +\scriptsize +\includegraphics[width=1.\linewidth]{hyper.png} +\end{frame} + +\section{Implementazione} + +\begin{frame}[fragile]{Octave e C++} + \begin{itemize} + \item Octave è principalmente scritto in C++ (script, Fortran) + \item Octave offre un'interfaccia per includere codice C++ come ``dinamically linked extension'' + \item Una volta compilato (\texttt{mkoctfile}) il codice può essere chiamato dall' ``interpreter'' come + ogni altra funzione + \item Octave offre la possibilità di aggiungere nuove classi all'``interpreter'' + \end{itemize} +\end{frame} + +\begin{frame}[fragile]{Il problema} +\includegraphics[width=1.\linewidth]{octfem.png} +\end{frame} + +\begin{frame}[fragile]{Class design} +\only<1>{\lstinputlisting[language=C++,linerange=1-23,firstnumber=1]{./esempi/classe.cc}} +\only<2>{\lstinputlisting[language=C++,linerange=41-54,firstnumber=last]{./esempi/classe.cc}} +\only<3>{\lstinputlisting[language=C++,linerange=29-38,firstnumber=last]{./esempi/classe.cc}} +%\only<4>{\lstinputlisting[language=C++,linerange=57-72,firstnumber=last]{./esempi/classe.cc}} +\pause +%\attachfile[icon=Paperclip]{./esempi/classe.cc}{source code of the example} +\end{frame} + +\begin{frame}[fragile]{Funzioni dinamiche in Octave} +\only<1>{\lstinputlisting[language=C++,linerange=1-17,firstnumber=1]{./esempi/func.cc}} +\only<2>{\lstinputlisting[language=C++,linerange=18-29,firstnumber=last]{./esempi/func.cc}} +\pause +%\attachfile[icon=Paperclip]{./esempi/func.cc}{source code of the example} +\end{frame} + +\begin{frame}[fragile]{Perchè abbiamo due file ?} +Come funziona Fenics in C++ +\begin{itemize} + \item Problema risolto in due file: \texttt{Poisson.ufl} e \texttt{Poisson.cc} + \item Problema astratto definito dall'utente nel file \texttt{Poisson.ufl} . + \item Il file viene compilato dall'utente e viene generato l'header \texttt{Poisson.h} + \item \texttt{Poisson.h} contiene la definizione della classe Poisson e dei costruttori delle forme + (bi)lineari e dello spazio funzionale + \item L'header viene incluso nel file \texttt{Poisson.cc} e il problema risolto + \begin{lstlisting} +#include "Poisson.h" +int main() +{ + UnitSquareMesh mesh(32, 32); + Poisson::FunctionSpace V(mesh); + Poisson::BilinearForm a(V, V); + Poisson::LinearForm L(V); + ... + \end{lstlisting} + +\end{itemize} +\end{frame} + +\begin{frame}[fragile]{Code on the fly} +\lstinputlisting[language=C++,linerange=1-22,firstnumber=1]{./esempi/import_ufl_FunctionSpace.m} +%\only<2>{\lstinputlisting[language=C++,linerange=1-32,firstnumber=1]{./esempi/generate_fs.m}} +%\pause +%\attachfile[icon=Paperclip]{./esempi/func.cc}{source code of the example} +\end{frame} + + +\begin{frame}[fragile]{Code on the fly} +\lstinputlisting[language=C++,linerange=1-22,firstnumber=1]{./esempi/generate_fs.m} +%\attachfile[icon=Paperclip]{./esempi/func.cc}{source code of the example} +\end{frame} + +\begin{frame}[fragile]{Implementzione} + Altri aspetti implementativi descritti nella documentazione + \begin{itemize} + \item Conversione da (p, e, t) a dolfin xml + \item Estensione del pkg msh con la funzione \texttt{mshm\_refine ()} + \item Conversione da csc a csr + \item Polimorfismo (save, plot) + \item Autoconf, Automake e la generazione del pkg + \end{itemize} +\end{frame} + +\begin{frame}[fragile]{Conclusione} +La prima versione del pkg è stata rilasciata, ma ancora del +lavoro resta da fare + \begin{itemize} + \item TODO sulla wiki + \item Aggiungere funzioni disponibili in Fenics + \item Estendere con nuovi esempi + \item Migliorare la gestione delle matrici + \item Controllare che tutto funzioni anche con le nuove versioni di Octave e Fenics + \item ... + \end{itemize} +\end{frame} +\end{document}