Merge branch 'master' of masterduck.fspanier.de:fspanier/teaching
This commit is contained in:
@@ -0,0 +1,88 @@
|
|||||||
|
\documentclass[12pt,a4paper]{uebungen}
|
||||||
|
\usepackage{german}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage{epsfig}
|
||||||
|
\usepackage[amssymb]{SIunits}
|
||||||
|
\usepackage{wrapfig}
|
||||||
|
\usepackage{graphics}
|
||||||
|
\usepackage{amsfonts}
|
||||||
|
\usepackage{amssymb}
|
||||||
|
\usepackage{amsmath}
|
||||||
|
\usepackage{pgf}
|
||||||
|
\usepackage{listings}
|
||||||
|
\lstset{language=[ANSI]C++,basicstyle=\ttfamily,commentstyle=\itshape,
|
||||||
|
keywordstyle=\bfseries,extendedchars=true,backgroundcolor=\color{gray}}
|
||||||
|
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
|
%\graphicspath{{../../../GALLERY/}}
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
|
\setlength{\topmargin}{-2.5cm}
|
||||||
|
\setlength{\textheight}{26.0cm}
|
||||||
|
\setlength{\textwidth}{17cm}
|
||||||
|
\setlength{\oddsidemargin}{-0.5cm}
|
||||||
|
\setlength{\evensidemargin}{-0.5cm}
|
||||||
|
\setlength{\parskip}{0pt}
|
||||||
|
\setlength{\parindent}{0pt}
|
||||||
|
\pagestyle{empty}
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
|
\newcommand{\vt}[1]{\vec{#1}}
|
||||||
|
\newcommand{\mt}[1]{\underline{\underline{#1}}}
|
||||||
|
\newcommand{\dt}[1]{\left\vert\underline{\underline{#1}}\right\vert}
|
||||||
|
\newcommand{\mo}{\!\!\!\!\!-1}
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
|
\def\bbbr{{\rm I\!R}}
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
|
\begin{document}
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
|
\thispagestyle{myheadings}
|
||||||
|
\begin{center}
|
||||||
|
{\bf \underline{\Large Exercises in ``Numerical Methods in Plasma Astrophysics''}}\\
|
||||||
|
%\hfill\\
|
||||||
|
%{\bf \large }\\
|
||||||
|
\hfill\\
|
||||||
|
{\bf \large Winter 2022/23 \hfill Exercise 2}\\
|
||||||
|
\end{center}
|
||||||
|
\noindent
|
||||||
|
%
|
||||||
|
\section*{\large Exercise 2: Thermal conduction}\vspace*{-0.0cm}
|
||||||
|
%
|
||||||
|
|
||||||
|
\emph{Previous experience tells me that a tree-code exercise is too excessive\dots we just look at the Poisson equation instead.}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\medskip
|
||||||
|
We return to the 2-dimensional Cartesian rubber duck ocean. The mad scientist
|
||||||
|
and villain Dr. Xilef has the diabolic to to seize world domination world domination, has placed point-shaped immersion heaters in the ocean at several immersion heaters into the ocean, which heat it up with $T=1000K$. The rubber ducks, fearing for their habitat, have then set up refrigerators around the ocean, so that the edge is kept at a comfortable $T_\text{edge}= 300 K$.
|
||||||
|
|
||||||
|
The ocean is slowly heating up according to the thermal conduction equation
|
||||||
|
|
||||||
|
\begin{equation}
|
||||||
|
\frac{\partial}{\partial t} T(\vec{x}) = a \Delta T(\vec{x})
|
||||||
|
\end{equation}
|
||||||
|
|
||||||
|
until it reaches an equilibrium ($\frac{\partial}{\partial
|
||||||
|
t}T = 0$).
|
||||||
|
|
||||||
|
\bigskip
|
||||||
|
|
||||||
|
\textbf{a)} Solve the Poisson equation with given boundary conditions for the temperature distribution in the rubber duck ocean.
|
||||||
|
|
||||||
|
\medskip
|
||||||
|
Use a simple Jacobi iteration
|
||||||
|
|
||||||
|
\bigskip
|
||||||
|
\textbf{b)} Use an advanced - faster - method (multigrid or FFT). Compare the convergence rate by plotting the average temperature to the last step over the run time.
|
||||||
|
|
||||||
|
Since the FFT method has not been discussed in great detail in the lecture here a short discussion:
|
||||||
|
|
||||||
|
For the Poisson equation
|
||||||
|
$$\nabla^2 \varphi(x,y) = f(x,y)$$
|
||||||
|
on a grid with periodic boundary conditions the Fourier transform yields
|
||||||
|
$$-(k_x^2+k_y^2) \hat\varphi(k_x,k_y) = \hat f(k_x,k_y)$$
|
||||||
|
which can readily be solved and transformed back. Dirichlet or von Neumann boundary conditions can be achieved when using only $\sin$ or $\cos$ (in case of Dirichlet: $\sin$ is 0 on the boundary, the solution is known up to a constant value). Discreste sine/cosine transform are readily available.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\end{document}
|
||||||
|
%------------------------------------------------------------------------------
|
||||||
+89
-1
@@ -1317,7 +1317,95 @@ However, by taking advantage of the triangular form of $L_*$, the elements of $x
|
|||||||
x^{(k+1)}_i = \frac{1}{a_{ii}} \left(b_i - \sum_{j=1}^{i-1}a_{ij}x^{(k+1)}_j - \sum_{j=i+1}^{n}a_{ij}x^{(k)}_j \right),\quad i=1,2,\dots,n.
|
x^{(k+1)}_i = \frac{1}{a_{ii}} \left(b_i - \sum_{j=1}^{i-1}a_{ij}x^{(k+1)}_j - \sum_{j=i+1}^{n}a_{ij}x^{(k)}_j \right),\quad i=1,2,\dots,n.
|
||||||
\end{align}
|
\end{align}
|
||||||
|
|
||||||
How does this very theoretical approach now look like when applied to the Poisson equation
|
How does this very theoretical approach now look like when applied to the Poisson equation? In 2D we can formulate the finite-difference equation as
|
||||||
|
\begin{align}
|
||||||
|
\frac{u_{ij+1}-2u_{ij}+u_{ij-1}}{(\Delta x)^2} + \frac{u_{i+1j}-2u_{ij}+u_{i-1j}}{(\Delta x)^2} = f_{ij}
|
||||||
|
\end{align}
|
||||||
|
An iterative solution looks now like
|
||||||
|
\begin{align}
|
||||||
|
u_{ij}^{n+1} = \frac{1}{4}(u_{ij+1}^n + u_{i+1j}^n + u_{ij-1}^{n+1} + u_{i-1j}^{n+1} + (\Delta x)^2 f_{ij})
|
||||||
|
\end{align}
|
||||||
|
This Gauss-Seidel algorithm uses updated values of the solution $u$. This is somewhat advantageous in terms of memory usage, but otherwise pretty slow.
|
||||||
|
|
||||||
|
A slighlty updated version of the Gauss-Seidel scheme is the \emph{Red-Black} scheme: Points are alternating red or black. The update runs over red points first, after all red points are updated, the black points will be updated. The main advantage is that the update only relies on old points (which allows for parallelization).
|
||||||
|
|
||||||
|
While the scheme is extremely simple, it is also horribly slow. One way to speed up things is the \emph{successive over-relaxation}. For
|
||||||
|
\begin{align}
|
||||||
|
A x = f \Rightarrow A = D + L + U
|
||||||
|
\end{align}
|
||||||
|
Where $D$ is the diagonal matrix and $L$ and $U$ are the strictly lower and upper matrix respectively. The relaxation now looks like
|
||||||
|
\begin{align}
|
||||||
|
(D+\omega L) x = \omega f -(\omega U+(\omega-1)D) x
|
||||||
|
\end{align}
|
||||||
|
Where $\omega > 0$ with $\omega=1$ being the Gauss-Seidel case
|
||||||
|
\begin{align}
|
||||||
|
x^{k+1} = (D+\omega L)^{-1}(\omega f - (\omega U + (\omega -1) D)x^k)
|
||||||
|
\end{align}
|
||||||
|
Making use of matrix structure then yields
|
||||||
|
\begin{align}
|
||||||
|
x_i^{k+1} = (1-\omega) x_i^k + \frac{\omega}{a_{ii}}(f_i - \sum{j>i} a_{ij}x_j^k-\sum_{j<i} a_{ij} x_j^{k+1})
|
||||||
|
\end{align}
|
||||||
|
This scheme is convergent for $0<\omega<2$, where $\omega>1$ yields faster convergence and $\omega<1$ yields convergence safely.
|
||||||
|
|
||||||
|
Another scheme used typically is the Jacobi scheme
|
||||||
|
\begin{align}
|
||||||
|
A x =f \Rightarrow A = D + R\\
|
||||||
|
x^{k+1} = D^{-1} (f-R x^k)
|
||||||
|
\end{align}
|
||||||
|
|
||||||
|
\subsection{Multigrid}
|
||||||
|
|
||||||
|
If one looks at previous methods one will notice that methods like Gauss-Seidel are correct on smallest scale, but tend to deviate from the correct solution when larger scales are involved. This is due to the fact that the update only relies on the neighbouring points.
|
||||||
|
|
||||||
|
Before we discuss a strategy to circumvent this problem we need to discuss some terms. We are looking for the correct solution $u$ (which we may or maybe not reach) and approximate this by the iteration $u^n$. The difference these two is the error
|
||||||
|
\begin{align}
|
||||||
|
e = u^n - u
|
||||||
|
\end{align}
|
||||||
|
Again: If we knew the error we would also know the real solution. We will never know the real solution\dots
|
||||||
|
|
||||||
|
What we know is the residual
|
||||||
|
\begin{align}
|
||||||
|
r = f - A u^n
|
||||||
|
\end{align}
|
||||||
|
But since for the exact solution we know
|
||||||
|
\begin{align}
|
||||||
|
A u = f
|
||||||
|
\end{align}
|
||||||
|
we have
|
||||||
|
\begin{align}
|
||||||
|
f - A u^n = A (u-u^n ) = r
|
||||||
|
\end{align}
|
||||||
|
|
||||||
|
Coming back to the original problem: How can we improve our solution on larger levels? One is the so-called Multigrid scheme: Instead of using one fixed grid the data is sampled grids with different resolutions. The ``original'' grid is the finest grid and data is coarsened from there on.
|
||||||
|
|
||||||
|
Using the notation ``superscript describes the coarseness of the grid'' (i.e., $u^n$ is an approximate solution on the finest grid, while $u^{2n}$ is the approximate solution on a grid with double spacing) we need the following ingredients
|
||||||
|
\begin{itemize}
|
||||||
|
\item A restriction matrix $R^h_{2h}$ transfers vectors from the fine grid to the coarse grid.
|
||||||
|
\item The return step to the fine grid is by an interpolation matrix $I = I^h_{2h}$.
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
Possible interpolation:
|
||||||
|
\begin{align}
|
||||||
|
u_{2i,2j} = v_{i,j},\quad u_{2i,2j+1} = \frac{1}{2}(v_{i,j}+v_{i,j+1}
|
||||||
|
\end{align}
|
||||||
|
The restriction is essentially the inversion of this.
|
||||||
|
|
||||||
|
A simple two grid v-cycle looks like this
|
||||||
|
\begin{enumerate}
|
||||||
|
\item Iterate on $A^h u = b^h$ to reach $u^h$ (say 3 Jacobi or Gauss-Seidel steps).
|
||||||
|
\item Restrict the residual $r^h = b^h − A^h u^h$ to the coarse grid by $r^{2h} = R^{2h}_h r^h$.
|
||||||
|
\item Solve $A^{2h} e^{2h} = r^{2h}$ (or come close to $e^{2h}$ by 3 iterations from $e = 0$).
|
||||||
|
\item Interpolate $e^{2h}$ back to $e^h = I^h_{2h} e_{2h}$. Add $e^h$ to $u^h$.
|
||||||
|
\item Iterate 3 more times on $A^h u = b^h$ starting from the improved $u^h + e^h$
|
||||||
|
\end{enumerate}
|
||||||
|
Here we solve the Poisson equation on a fine grid and one coarser grid. This scheme can be extended to ever finer grids.
|
||||||
|
|
||||||
|
\begin{figure}
|
||||||
|
\begin{center}
|
||||||
|
\pgfimage[width=.7\textwidth]{fig_chapter3/multigrid}
|
||||||
|
\end{center}
|
||||||
|
Grapical representation of the multigrid cycle
|
||||||
|
\end{figure}
|
||||||
|
|
||||||
\chapter{Particle-in-Cell}
|
\chapter{Particle-in-Cell}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user