Commit a7bc3d7d authored by Steffen Müthing's avatar Steffen Müthing
Browse files

Initial commit to import SVN data

parents
# Stuff to ignore recursively
*.la
*.lo
*.o
*~
.deps/
.libs/
Makefile
Makefile.in
semantic.cache
# Stuff to ignore in this directory only
/aclocal.m4
/autom4te.cache/
/build-cmake/
/compile
/config.guess
/config.h
/config.h.in
/config.log
/config.lt
/config.status
/config.sub
/configure
/configure
/configure.lineno
/depcomp
/dependencies.m4
/dune-common-*.tar.gz
/dune-common-?.?
/dune-common.pc
/dune.css
/install-sh
/libtool
/ltmain.sh
/missing
/mkinstalldirs
/stamp-h1
/test-driver
\NeedsTeXFormat{LaTeX2e}
\def\@anim@version{2012/03/09}
\ProvidesPackage{animtikz}
\RequirePackage{animate}
\RequirePackage{tikz}
\newwrite\@animfile
\let\orignewlilne\newline%
\let\orignewframe\newframe%
\let\origincludegraphics\includegraphics%
\def\animfirstframe#1{%
\immediate\write\@animfile{#1}%
}%
\def\animframe#1{%
\animfirstframe{%
\noexpand\newframe%
#1}%
}%
\newenvironment{animatewrite}[2][]%
{%
\immediate\openout\@animfile animtikz.tmp%
\def\newframe{\noexpand\newframe}%
\def\newline{\noexpand\newline}%
\def\includegraphics{\noexpand\includegraphics}%
\immediate\write\@animfile{\noexpand\begin{animateinline}[#1]{#2}}
}%
{%
\immediate\write\@animfile{\noexpand\end{animateinline}}%
\immediate\closeout\@animfile%
\let\newframe\orignewframe%
\let\newline\orignewline%
\let\includegraphics\origincludegraphics%
}
\newcommand{\animatefile}{%
\input{animtikz.tmp}%
}
\newenvironment{animatetikz}[2][]%
{\begin{animatewrite}[#1]{#2}}%
{\end{animatewrite}%
\animatefile}
\newenvironment{animatetikzXXX}[2][]%
{%
\immediate\openout\@animfile animtikz.tmp%
\def\newframe{\noexpand\newframe}%
\def\newline{\noexpand\newline}%
\def\includegraphics{\noexpand\includegraphics}%
\immediate\write\@animfile{\noexpand\begin{animateinline}[#1]{#2}}
}%
{%
\immediate\write\@animfile{\noexpand\end{animateinline}}%
\immediate\closeout\@animfile%
\let\newframe\orignewframe%
\let\newline\orignewline%
\let\includegraphics\origincludegraphics%
\input{animtikz.tmp}%
}
\documentclass[a4paper,10pt,twoside]{scrartcl}
\typearea{12}
%\setcounter{page}{0}
%% beamer magic
\newcommand{\amode}[2]{#1}
\newcommand{\pmode}[2]{#2}
\usepackage{beamerarticle}
\usepackage{hyperref}
\setjobnamebeamerversion{lectures-beamer}
\parindent0pt
\parskip1ex
\usepackage{scrpage2}
\pagestyle{scrheadings}
\lehead{DUNE Course, Heidelberg 2014}
\cehead{}
\rehead{\headmark}
\lohead{\headmark}
\cohead{}
\rohead{}
\automark[section]{part}
\usepackage{etex}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{url}
\usepackage{mathe}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{multicol}
\usepackage{tikz}
%\usepackage{natbib}
\usepackage[english]{babel}
\usepackage{multibib}
\usepackage{animate}
\usepackage{animtikz}
% PDELAB Howto includes
\usepackage{amscd}
\usepackage{multimedia}
\usetikzlibrary{shapes,arrows}
\usepackage{curves}
\usepackage{listings}
\usepackage{picinpar}
\usepackage{enumerate}
%\usepackage{algorithmic}
%\usepackage{algorithm}
\usepackage{bm}
\usepackage{nicefrac}
\usepackage{hyperref}
\setkomafont{pagenumber}{\normalfont\scshape}
\setkomafont{pagehead}{\normalfont\scshape}
\lstset{language=C++, basicstyle=\small\ttfamily,
keywordstyle=\bfseries, tabsize=4, stringstyle=\ttfamily,
commentstyle=\it, extendedchars=true, escapeinside={/*@}{@*/}}
%\lstset{language=C++, basicstyle=\small\ttfamily,
% tabsize=4, stringstyle=\ttfamily,
% keywordstyle=\color{violet},
% commentstyle=\color{darkgray},
% stringstyle=\color{orange},
% emph={bool,int,unsigned,char,true,false,void}, emphstyle=\color{blue},
% emph={[2]\#include,\#define,\#ifdef,\#endif}, emphstyle={[2]\color{violet}},
% emph={[3]Dune,Grid,GridView,LeafGridView,LevelGridView,SomeGrid,TheGrid,LeafIterator,Iterator,LevelIterator,LeafIntersectionIterator,LevelIntersectionIterator,IntersectionIterator,LeafMultipleCodimMultipleGeomTypeMapper,Geometry,Entity,EntityPointer,Codim,FieldVector,FieldMatrix}, emphstyle={[3]\color{blue}},
% extendedchars=true, escapeinside={/*@}{@*/}}
%The theorems
\mode<article>
{
\newtheoremstyle{mystyle}%
{3pt}%
{3pt}%
{}%
{}%
{\sffamily\bfseries}%
{.}%
{.5em}%
{}%
\theoremstyle{mystyle}
}
\theoremstyle{definition}
\newtheorem{Def}{Definition}%[section]
\newtheorem{Exm}[Def]{Example}
\newtheorem{Lem}[Def]{Lemma}
\newtheorem{Rem}[Def]{Remark}
\newtheorem{Rul}[Def]{Rule}
\newtheorem{Thm}[Def]{Theorem}
\newtheorem{Cor}[Def]{Corollary}
\newtheorem{Obs}[Def]{Observation}
\newtheorem{Ass}[Def]{Assumption}
\newtheorem{Pro}[Def]{Property}
\newtheorem{Alg}[Def]{Algorithm}
\newtheorem{Prp}[Def]{Proposition}
\newtheorem{Lst}[Def]{Listing}
% end
%% math symbols
\newcommand{\C}{\mathbb{C}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\K}{\mathbb{K}}
\newcommand{\blue}{\color[rgb]{0,0,1}}
\newcommand{\green}{\color[rgb]{0,1,0}}
\newcommand{\red}{\color[rgb]{1,0,0}}
\newcommand{\violet}{\color[rgb]{1,0,1}}
\renewcommand{\uu}{\mathbf{u}}
\renewcommand{\nn}{\mathbf{n}}
\newlength{\tmplen}
\def\clap#1{\hbox to 0pt{\hss#1\hss}}
\definecolor{dunedarkblue}{rgb}{0.22, 0.29, 0.49}
\definecolor{dunemediumblue}{rgb}{0.35, 0.45, 0.71}
\definecolor{dunelightblue}{rgb}{0.61, 0.68, 0.85}
\definecolor{duneorange}{rgb}{0.91, 0.56, 0.25}
%% some math commands
\DeclareMathOperator{\dist}{dist}
\newcommand{\lt}{\left}
\newcommand{\rt}{\right}
\newcommand{\cl}[1]{\overline{#1}}
\newcommand{\Oi}{\Omega_i}
\newcommand{\Oj}{\Omega_j}
\newcommand{\hOi}{\hat\Omega_i}
\newcommand{\hOj}{\hat\Omega_j}
\newcommand{\cOi}{\overline{\Omega_i}}
\newcommand{\cOj}{\overline{\Omega_j}}
% number equations within sections in article mode
%\numberwithin{equation}{section}
% math symbols
\newcommand{\diffd}{\,d}
% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
% \AtBeginSection[]
% {
% \begin{frame}<beamer>
% \frametitle{Outline}
% \tableofcontents[currentsection]
% \end{frame}
% }
\begin{document}
%% ------------------------------------ BEGIN C++ exercises ---------------------------
\section*{C++ Exercise 1 - Templates}
\subsection*{Introduction}
\begin{onlyenv}<article>
As presented in the lecture templates are a common generic
programming technique. They allow the design of algorithms independent on
a specific datatype.\\
In these exercises:
\begin{itemize}
\item Template classes and functions
\item Inheritance from template classes
\end{itemize}
\end{onlyenv}
\begin{frame}[fragile]
\frametitle{Templates}
Matrices are a central data structure in numerics and therefore used very often.
Suppose we have the following situation:
\begin{itemize}
\item We already have an implementation of a class \lstinline!MatrixClass!
representing 2D matrices of elements of type \lstinline!double!
\item In our applications we often want to have matrices of other
types of elements (\lstinline!int!, \lstinline!complex!, \ldots)
\begin{itemize}
\item One possibility is to implement a \lstinline!MatrixClass! for each type of
element. This results in a lot of (redundant) code that is not easily
maintainable.
\item We want therefore to create a template class \lstinline!MatrixClass!\\
($\rightarrow$ better code reuse, easier to maintain).
\end{itemize}
\end{itemize}
\begin{block}{}
In this exercise you will change a given implementation of \lstinline!MatrixClass!
for elements of type \lstinline!double! into a template
class \lstinline!MatrixClass! to represents matrices of any type of elements
(\lstinline!double!, \lstinline!int!, \ldots).
\end{block}
\end{frame}
%-----------------------------------------------------------------------------
\begin{frame}[fragile]
\frametitle{MatrixClass for double elements : Basic features}
\begin{itemize}
\item Matrix elements stored in a vector of vectors\\
\lstinline!vector<vector<double> > a_;!
\item Methods to access the matrix elements
\begin{itemize}
\item \lstinline!double &operator()(int i, int j);!
\item \lstinline!double operator()(int i, int j) const;!
\end{itemize}
\item Arithmetic operations on matrices:
\begin{itemize}
\item Multiplication by a value\\
\lstinline!MatrixClass &operator*=(double x);!
\item Addition with another matrix
\lstinline!MatrixClass &operator+=(const MatrixClass &b);!
\end{itemize}
\end{itemize}
\vspace*{5pt}
More (non-class) operators for matrices that internally use the
arithmetic operations \lstinline!*=! and \lstinline!+=!:
\begin{itemize}
\item \lstinline!operator*(const MatrixClass &a, double x);!
\item \lstinline!operator*(double x,const MatrixClass &a);!
\item \lstinline!operator+(const MatrixClass &a, const MatrixClass &b);!
\end{itemize}
\end{frame}
%-----------------------------------------------------------------------------
\clearpage
\begin{frame}[fragile]
\frametitle{MatrixClass (matrix\_double.h)}
\lstinputlisting[basicstyle=\scriptsize\ttfamily]
{../../c++-exercise1/matrix_double/matrix_double.h}
\end{frame}
%-----------------------------------------------------------------------------
\clearpage
\begin{frame}[fragile]
\frametitle{Test the implementation (test\_matrix\_double.cc)}
\lstinputlisting[basicstyle=\scriptsize\ttfamily]
{../../c++-exercise1/matrix_double/test_matrix_double.cc}
\end{frame}
%-----------------------------------------------------------------------------
\subsection*{Part I -- Template classes and functions}
\begin{frame}[fragile]
% \frametitle{Part I}
\begin{block}{}
Change the given implementation of the \lstinline!MatrixClass! for elements of
type \lstinline!double! into a template matrix class that allows handling of
different types of elements. Adapt the main routine to test your
implementation.\\
Note: The non-class functions
\begin{itemize}
\item \lstinline!operator*(const MatrixClass &a, double x)!
\item \lstinline!operator*(double x,const MatrixClass &a)! and
\item \lstinline!operator+(const MatrixClass &a, const MatrixClass &b)!
\end{itemize}
have to be changed into template functions.
\emph{Hint}: If you encounter problems linking your application, you might want to have
a glimpse at the last paragraph on this website:
\href{http://www.cplusplus.com/doc/tutorial/templates/}{http://www.cplusplus.com/doc/tutorial/templates/}
\end{block}
\end{frame}
%-----------------------------------------------------------------------------
\subsection*{Part II -- Inheritance from template classes}
\begin{frame}[fragile]
% \frametitle{Exercise 1 - Part II}
\begin{block}{}
Split up the templated \lstinline!MatrixClass! into two classes:\\
\begin{itemize}
\item A non-numeric matrix class \lstinline!MatrixClass! representing a matrix of
elements (of different type) in general that provides:
\begin{itemize}
\item Constructors (as in \lstinline!MatrixClass!)
\item \lstinline!operator()(int i, int j)! to access the matrix elements
\item Resize and print- methods (as in \lstinline!MatrixClass!)
\end{itemize}
\item A numeric matrix class \lstinline!NumMatrixClass! that erives from
\lstinline!MatrixClass! representing a numerical matrix allowing the arithmetic
operations on matrices.
\end{itemize}
Adapt the non-class functions and the main routine and test your implementation.
\end{block}
\end{frame}
%% ------------------------------------ END C++ exercises ---------------------------
\end{document}
\usepackage{amsfonts, amsmath, amscd, amssymb, amsthm}
\usepackage{eucal,graphicx}
\usepackage{eucal, longtable}
%\usepackage[all]{xy}
%%% Mathematische Symbole ------------------------------------------------------
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\spn}[1]{\mbox{$<$} #1 \mbox{$>$}}
\newcommand{\scp}[1]{\langle #1 \rangle}
\newcommand{\norm}[1]{\left\Vert #1 \right\Vert}
\newcommand{\ton}[1]{#1_1,\dots,#1_n}
\newcommand{\map}[3]{\ensuremath{#1\mbox{:}\ #2\rightarrow#3}}
\newcommand{\mapl}[5]{\ensuremath{#1\mbox{:}\ #2\rightarrow#3,\ #4\mapsto#5}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\DD}{\mathbb{D}}
\newcommand{\FF}{\mathbb{F}}
\newcommand{\HH}{\mathbb{H}}
\newcommand{\II}{\mathbb{I}}
\newcommand{\KK}{\mathbb{K}}
\newcommand{\MM}{\mathbb{M}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\UU}{\mathbb{U}}
\newcommand{\WW}{\mathbb{W}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\ds}{\displaystyle}
\DeclareMathOperator{\im}{im}
\DeclareMathOperator{\id}{id}
\DeclareMathOperator{\cond}{cond}
\DeclareMathOperator*{\dirsum}{\bigoplus}
\DeclareMathOperator{\grad}{grad}
\DeclareMathOperator{\Aut}{Aut}
\DeclareMathOperator{\Res}{Res}
\DeclareMathOperator{\SL}{SL}
\DeclareMathOperator{\SO}{SO}
\DeclareMathOperator{\Or}{O}
\DeclareMathOperator{\diverg}{div}
\DeclareMathOperator{\tr}{tr}
\renewcommand{\Re}{\operatorname{Re}}
\renewcommand{\Im}{\operatorname{Im}}
\renewcommand{\phi}{\varphi}
\renewcommand{\epsilon}{\varepsilon}
\newcommand{\del}[1]{\frac{\partial}{\partial #1}}
\newcommand{\dell}[1]{\frac{\partial^2}{\partial #1^2}}
\newcommand{\smatrix}[1]{\big(\begin{smallmatrix} #1 \end{smallmatrix}\big)}
%%% Pfeile ---------------------------------------------------------------------
\newcommand{\ra}{\rightarrow}
\newcommand{\la}{\leftarrow}
\newcommand{\lra}{\longrightarrow}
\newcommand{\lla}{\longleftarrow}
\newcommand{\Ra}{\Rightarrow}
\newcommand{\La}{\Leftarrow}
\newcommand{\Lra}{\Leftrightarrow}
\newcommand{\lRa}{\Longrightarrow}
\newcommand{\lLa}{\Longleftarrow}
\newcommand{\lLra}{\Longleftrightarrow}
\newcommand{\inject}{\hookrightarrow}
%%% Sonstiges ------------------------------------------------------------------
\newcommand{\uu}{\mathbf{u}}
\newcommand{\nn}{\mathbf{n}}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "theta"
%%% End:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Definitionen und Einstellungen fuer LaTeX und pdfLaTeX
\RequirePackage{ifthen}
\textwidth=170mm
\textheight=245mm
\headheight0pt
\topmargin-2mm
\headsep=-12mm
\textfloatsep15mm
%\parindent0mm
\parskip11pt
\oddsidemargin-5mm
\evensidemargin-5mm
\pagestyle{plain}
\newcommand{\institute}[1]{\def\@institute{#1}}
\institute{}
\newcommand{\abgabetitle}[1]{\def\@abgabetitle{#1}}
\abgabetitle{Abgabetermin: }
\newcommand{\abgabeinfo}[1]{\def\@abgabeinfo{#1}}
\abgabeinfo{}
\newcommand{\dozent}[1]{\def\@dozent{#1}}
\dozent{Dr. Seltsam}
\newcommand{\semester}[1]{\def\@semester{#1}}
\newcommand{\uebungslabel}[1]{\def\@uebungslabel{#1}}
\uebungslabel{\"{U}bung}
\newcommand{\blattlabel}[1]{\def\@blattlabel{#1}}
\blattlabel{Aufgabenblatt}
\newcounter{blatt}
\setcounter{blatt}{0}
\newcommand{\blatt}[3][auto]{
\cleardoublepage\setcounter{footnote}{1}
\ifthenelse{\equal{#1}{auto}}{\stepcounter{blatt}}{\setcounter{blatt}{#1}}
\noindent \@institute \hfill \@semester \par
\noindent \@blattlabel \hfill {#2}\par
\begin{center}
\@title \par
\@dozent
\end{center}
\noindent
\@abgabetitle{} {#3}\@abgabeinfo\\
\rule{\textwidth}{1pt}
\bigskip
}
\newcounter{Uctr}
\newsavebox{\Upunkte}
\newenvironment{uebung}[2][0]
{\stepcounter{Uctr}%
\sbox{\Upunkte}{%
\ifthenelse{\not\equal{#1}{0}}{%
\ifthenelse{\equal{#1}{1}}{%
\textit{#1~Punkt}}{\textit{#1~Punkte}}%
}%
}%
\medskip%
\noindent\textsc{\@uebungslabel~\arabic{Uctr}\hspace{1em}#2\nopagebreak}%
\nopagebreak\par\nopagebreak\noindent\hspace*{0mm}\nopagebreak}
{\hspace*{\fill}\nolinebreak\hspace*{\fill}%
\usebox{\Upunkte}\par}
%}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\parindent0pt
\parskip1ex
#include "matrix_double.h"
#include <cstdlib>
#include <iomanip>
#include <iostream>
// Set number of matrix rows and columns and
// initialize matrix elements with a given double value
void MatrixClass::Resize(int numRows, int numCols, const double &value)
{
a_.resize(numRows);
for (int i=0;i<a_.size();++i)
{
a_[i].resize(numCols);
for (int j=0;j<a_[i].size();++j)
a_[i][j]=value;
}
numRows_=numRows;
numCols_=numCols;
}
// Access matrix element at position (i,j)
double &MatrixClass::operator()(int i, int j)
{
if ((i<0)||(i>=numRows_))
{
std::cerr << "Illegal row index " << i;
std::cerr << " valid range is (0:" << numRows_-1 << ")";
std::cerr << std::endl;
exit(EXIT_FAILURE);
}
if ((j<0)||(j>=numCols_))
{
std::cerr << "Illegal column index " << j;
std::cerr << " valid range is (0:" << numCols_-1 << ")";
std::cerr << std::endl;
exit(EXIT_FAILURE);
}
return a_[i][j];
}
// Access matrix element at position (i,j)
double MatrixClass::operator()(int i,int j) const
{
if ((i<0)||(i>=numRows_))
{
std::cerr << "Illegal row index " << i;
std::cerr << " valid range is (0:" << numRows_-1 << ")";
std::cerr << std::endl;
exit(EXIT_FAILURE);
}
if ((j<0)||(j>=numCols_))
{
std::cerr << "Illegal column index " << j;
std::cerr << " valid range is (0:" << numCols_-1 << ")";
std::cerr << std::endl;
exit(EXIT_FAILURE);
}
return a_[i][j];
}
// Output matrix content
void MatrixClass::Print() const
{
std::cout << "(" << numRows_ << "x";
std::cout << numCols_ << ") matrix:" << std::endl;
for (int i=0;i<numRows_;++i)
{
std::cout << std::setprecision(3);
for (int j=0;j<numCols_;++j)
std::cout << std::setw(5) << a_[i][j] << " ";
std::cout << std::endl;
}
std::cout << std::endl;
}
// Arithmetic functions
// Multiplication by value x
MatrixClass &MatrixClass::operator*=(double x)
{
for (int i=0;i<numRows_;++i)
for (int j=0;j<numCols_;++j)