Mehr NumMeth-22

This commit is contained in:
2023-01-11 13:45:14 +01:00
parent 020d291e1e
commit 847a1c68e2
+67 -4
View File
@@ -23,6 +23,7 @@
\usepackage[thinc]{esdiff}%derivative-macros
\usepackage{physics}
\usepackage{siunitx}
\usepackage{listings}
\DeclareSIUnit\gauss{G}
\DeclareSIUnit \clight {\text{\ensuremath {c}}}
\sisetup{range-phrase=-}
@@ -6316,7 +6317,7 @@ While this technique is rarely used for large scale astrophysical plasma, it is
\begin{minipage}[t]{0.49\textwidth}
The Boltzmann equation is discretized in order to solve it. A grid in position space is introduced, as well as in velocity space. A two-dimensional space could be discretized using the D2Q9 as shown in this example (details are given in the next section). In the figure the points are position space points, while the arrows represent the probabilities of velocities that are associated with the fluid particle at the grid position.
A fluid particle can move within one time step into an adjacent cell of the square grid or stay where it is. This means it can have nine possible velocities $\vec {c}}_{i}$ where the index $i=0,\dots,8$ marks the direction.
A fluid particle can move within one time step into an adjacent cell of the square grid or stay where it is. This means it can have nine possible velocities $\vec {c}_{i}$ where the index $i=0,\dots,8$ marks the direction.
The algorithm can be split into two steps, with fixed but arbitrary sequence:
\begin{itemize}
@@ -6347,6 +6348,7 @@ where we have defined the average velocity $\vec u(\vec r, t)$ at position $\vec
The BTE describes the total time-rate of change of this probability distribution, $\dd f/\dd t$. We know that for large times $t$ it must relax towards statistical equilibrium, given by the Maxwell velocity distribution function
\begin{align}
f^\text{eq}(\vec v, \rho, \vec u, T) = \frac{\rho}{m}\left( \frac{m}{2\pi k_B T} \right)^{D/2}\exp\left( -\frac{m(\vec v - \vec u)^2}{2 k_B T} \right)
\label{eq:lbm4}
\end{align}
A common approximation is to assume relaxation of $f$ towards $f^\text{eq}$ with a single
characteristic time $\tau$ , as suggested by Bhatnagar, Gross, and Krook (BGK) in 1954
@@ -6355,7 +6357,7 @@ characteristic time $\tau$ , as suggested by Bhatnagar, Gross, and Krook (BGK) i
\end{align}
Eq. \eqref{eq:lbm5} is the BGK-Boltzmann equation. Note that the total differential of $f$ is
\begin{align}
\diff{f}{t} &= \frac{\vec F(\vec r)}{m} \diffp{f(\vec v,\vec r, t)}{\vec v} + \vec v\diffp{f(\vec v,\vec r, t)}{\vec r} + \diffp{f(\vec v,\vec r, t)}{t}
\diff{f}{t} &= \frac{\vec F(\vec r)}{m} \diffp{f(\vec v,\vec r, t)}{ v} + \vec v\diffp{f(\vec v,\vec r, t)}{ r} + \diffp{f(\vec v,\vec r, t)}{t}
\end{align}
where $\vec F(\vec r)$ is an external force acting on the molecules.
@@ -6400,14 +6402,75 @@ where $\rho(\vec{x}_j,t)$ is now the number density, i.e. we assume unit molecul
The discretized BGK-Boltzmann equation then reads
\begin{align}
f_i(\vec{x}_j + \vec{c}_i\cdot \Delta t, t+\Delta t) = f_i(\vec{x}_j,t) - \omega(f_(\vec{x}_j,t) - f_i^\text{eq}(\vec{x}_j,t)
\label{eq:lbm9}
\end{align}
where $ \Delta t$ is a time step used for the discrete dynamical propagation of the occupation numbers. We have introduced the normalized relaxation parameter $\omega = \Delta t /\tau$ and the external force $\vec F(\vec r)$ are set to zero. Note thate the left hand side and the first term on the right hand side of Eq. \eqref{eq:lbm9} is a discretization of the total differential of $f$. The expression for the equilibrium distribution function in the nine directions is
\begin{align}
\vec{f}_i^\text{eq} (\vec{x}_j,t) = w_i \rho(\vec{x}_j,t) \left( 1 + 3 \vec{c}_i\cdot \vec{u}(\vec{x}_j,t) + 9/2 (\vec{c}_i\cdot \vec{u}(\vec{x}_j,t))^2 - 3/2 u^2(\vec{x}_j,t) \right)
\label{eq:lbm10}
\end{align}
with $w_i=4/9,1/9,1/36$ for directions 0, 1-3 and 4-8, respectively. Note that like Eq. \eqref{eq:lbm4} for the continuous distribution function, Eq. \eqref{eq:lbm10} is obtained by applying the maximum entropy principle under the constraint of mass and momentum conservation to the discrete distribution function.
To give a rough idea of how Eq. \eqref{eq:lbm9} propagates the occupation numbers for the individual directions, we describe as an example what happens to $f_5$. Assume we have a finite value for direction $f_i$ including $f_5$, their magnitude given by the length of the green arrows, respectively, and based at the position shown by the blue sport in Fig. \ref{fig:lbm1} b. At time $t$ the r.h.s. of Eq. \eqref{eq:lbm9} relaxes $f_5$ towards the local equilibrium given by the black arrow based at the blue spot, which is commonly called the collision operation. Time propagation is described by the l.h.s. of Eq. \eqref{eq:lbm9}. After on time step $\Delta t$, the occupation $f_5$ will be handed to the red spot and occupy direction 5 there. This is commonly called the streaming step.
% https://publikationen.uni-tuebingen.de/xmlui/bitstream/handle/10900/87663/bwHPC2018-25-Pastewka-Lattice_Boltzmann_with_Python.pdf?sequence=1&isAllowed=y
\section{Numerical algorithm}
\section{Numerical implementation}
\definecolor{mylgrey}{rgb}{0.8,0.8,0.8}
\lstset{
language=Python,
backgroundcolor=\color{mylgrey}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
basicstyle=\footnotesize, % the size of the fonts that are used for the code
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
breaklines=true, % sets automatic line breaking
captionpos=b, % sets the caption-position to bottom
commentstyle=\color{mygreen}, % comment style
deletekeywords={...}, % if you want to delete keywords from the given language
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
firstnumber=1, % start line enumeration with line 1000
frame=single, % adds a frame around the code
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle=\color{blue}, % keyword style
language=Octave, % the language of the code
morekeywords={*,...}, % if you want to add more keywords to the set
numbers=left, % where to put the line-numbers; possible values are (none, left, right)
numbersep=5pt, % how far the line-numbers are from the code
numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces=false, % underline spaces within strings only
showtabs=false, % show tabs within strings adding particular underscores
stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle=\color{mymauve}, % string literal style
tabsize=2, % sets default tabsize to 2 spaces
title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
}
The quantity that specifies the state of our simulation are the occupation num-
bers $f_i(\vec{x}_j )$. We represent these as a single contiguous \texttt{numpy} array called \texttt{f\_ikl}. Note that the suffixes in our specific naming scheme indicate the number of array
dimensions and their function. In the present case, \texttt{ikl} stands for three array dimensions: \texttt{i} is a direction (array dimension of size 9), \texttt{k} is the lattice position in x-direction, and \texttt{l} (size $n_x$) the lattice position in y-direction (size $n_y$). Below we also encounter \texttt{c}, which denotes a Cartesian array dimension (size 2). This naming convention eases readability of the code and translation of formulas containing lin-
ear algebra into \texttt{numpy} operations and is borrowed from the GPAW code (Mortensen
et al., 2005; Enkovaara et al., 2010). Note that because numpy’s default storage order
is row-major, the array \texttt{f\_ikl} is stored in what is commonly called the structure of
arrays (SoA) storage order (Obrecht et al., 2011; Qi, 2017).
The streaming part can be cast into the form listed in Code Listing 1, which
uses the numpy.roll function and automatically takes care of periodic boundary
conditions. numpy.roll rolls the data on the lattice into the direction specified
by axis in the code listing by a distance given by c_ic[i ] . Note that c_ic[i ]
is a one-dimensional array of length 2 that specifies the Cartesian coordinates of
direction i. Taking the example of the f_ikl array, a roll operation on occupation
number 1 and axis 0 with unit distance will assign f1,k,l → f1,k+1,l.
\begin{lstlisting}[frame=single]
import numpy as np
c_ic = np.array([[0, 1, 0, -1, 0, 1, -1, -1, 1],[0, 0, 1, 0, -1, 1, 1, -1, -1]]).T
def stream(f_ikl):
for i in range (1, 9):
f_ikl[i] = np.roll(f_ikl[i], c_ic[i], axis=(0, 1))
\end{lstlisting}
\bibliographystyle{natdin}
\bibliography{./literatur.bib}