Professor: Andreas Adelmann
maximal period is
- initial sequence at least
$c$ bits - usually use congruential RNG to obtain seed sequence
When $|j| = 2$
$$
x_{i+1} = (x_{i-c}+x_{i-d}) mod ~ 2
\
c,d\in{1,\cdots, i-1}
$$
max period:
Zierler-Trinomial condition
- square test:$(s_i, s_{i+1})$
- cubic test:
$(s_i, s_{i+1}, s_{i+2})$
fluctuation of mean value, mean value should be gaussian $$ \chi^2 = \sum_{i=1}^k\frac{N_i-\frac{n}{k}}{\frac{n}{k}} $$
expected error for MC sampling is
error bound in quasi-MC is
$$ D^*N = \underset{0\le v_j \le 1}{max}\left|\frac{1}{N}\sum{i=1}^N\prod_{j=1}^d1_{0\le x_j^i \le v_j} - \prod_{j=1}^dv_j\right| $$
it measure how dense the points distributed inside a given volume
low-discrepancy :
given uniform distribution
- rejection sampling, sample
$X\sim Unif(-a, a), Y\sim Unif(-b,b)$ , accept the points inside ellipse - draw
$X,Y\sim Unif(0,1)$ ,$\psi = atan(\frac{b}{a}tan(2\pi X))$ ,$r = \sqrt Y \frac{ab}{\sqrt{(b cos\psi)^2 + (a\sin\psi)^2}}$ ,$E\sim [rcos\psi, rsin\psi]$
using uniform
-
cirtical point $p_c$: occupation probabilty
$p$ , a phase transition from non-percolated system to percolated system containing an infinitely-sized cluster -
percolation strength $\beta$:
$P(p\gtrsim p_c) \sim |p-p_c|^\beta$ , how fast the transition -
wrapping probability : $W(p) = \begin{cases}0 & 0\leq p<p_c \ 1 & p_c< p\le 1\end{cases}$
-
cluster-size distribution:
$n_s(p)=\underset{L\rightarrow \infin}{lim}\frac{N_s(p,L)}{L}$ ,$N_s(p,L)$ is the number of cluster of size$s$ given occupation probability$p$ and system's side length$L$
def burning_method(lattice):
"""
lattice: np.ndarray[L, L]
0 means empty, 1 means occupied
"""
t = 2
lattice[0, lattice[0, :] == 1] == t
while True:
t += 1
has_changed = False
for node in np.where(lattice == t):
for neighbor in get_neighbors(node):
if lattice[neighbor] == 1:
lattice[neighbor] = t
has_changed = True
at_bottom = (node[0] == lattice.shape[0] - 1).any()
if not has_changed or at_bottom:
break
compute how many clusters
def hoshen_kopelman_algorithm(lattice):
"""
lattice: np.ndarray[L, L]
0 means empty, 1 means occupied
"""
cluster_sizes = [None, None] # starts with 2
k = 2
for i in range(lattice.shape[0]):
for j in range(lattice.shape[1]):
if is_top_and_left_empty(lattice[i, j]): # new cluster
lattice[i, j] = k
cluster_sizes.append(1)
k += 1
else is_top_left_same_cluster(lattice[i, j]): # one neighbor in cluster or neighbors in same cluster
lattice[i, j] = get_top_left_cluster(lattice[i,j])
cluster_sizes[lattice[i, j]] += 1
else: # neighbors in different cluster
k1, k2 = get_top_left_cluster(lattice[i, j])
lattice[i, j] = k1
cluster_sizes[k1] += cluster_sizes[k2]
mark_cluster_size_as_transferred(cluster_sizes, k2)
-
fractal dimension $d_f$: stretch the object by
$a$ , the volume grows$a^{d_f}$ $$ \frac{V_\varepsilon^*}{\varepsilon^d} = \left(\frac{L}{\varepsilon}\right)^{d_f} $$ -
correlation function $c(r)$ : number of filled sites with in sphere
$r$ shell$\Delta r$ normalized by surface
$$ c(r) \propto \begin{cases} C + exp(-\frac{r}{\xi}) & p<p_c\ r^{-(d-2 + \eta)} & p\approx p_c \end{cases} $$$\xi$ is the correlation length $$ \xi \propto |p-p_c|^\nuwhere\nu=\begin{cases}\frac{4}{3}&2d \ 0.88 & 3d\end{cases} $$$$ \eta = \begin{cases} \frac{5}{24} & 2d \ -0.05 & 3d\end{cases} $$
$$ d_f = d - \frac{\beta}{\nu} $$
$\beta$ : percolation strength$d$ : dimension
def sandbox_method(lattice):
"""
lattice: np.ndarray[L, L]
0 means empty, 1 means occupied
"""
R = []
N_R = []
c = lattice.shape[0]/2 - 1 # as python starts from 0
for r in range(1, int(L//2)): # increase the sanbox size over iteration
R.append(r)
N_R.append(sum(lattice[c-r:c+r, c-r:c+r]==1))
plot_log(R, N_R) # the fractal dimension d_f is the slope
def box_counting_method(lattice):
"""
lattice: np.ndarray[L, L]
0 means empty, 1 means occupied
"""
epsilon_inv = []
N_epsilon = []
for epsilon in range(1, lattice.shape[0]):
boxes = maxpool2d(lattice, kernel=np.ones([epsilon, epsilon]), padding=0) # use the pooling to compute box
N_epsilon.append(sum(boxes > 0))
epsilon_inv.append(1 / epsilon)
plot_log(epsilon_inv, N_epsilon) # the fractal dimension d_f is the slope
cellular automata:$(\mathcal L, \psi, R,\mathcal N)$
neighborhoods
- left:Von Neumann neighborhood : 4 (north-east-south-west)
- right:Moore neighborhood : 8 (3x3 region)
boundary conditions
assume x[1:]
is the actual space
- periodic :
x[0] = x[-1]
- fixed :
x[0] = C
- adiabtic :
x[0] = x[1]
- reflection:
x[0] = x[2]
moore neighborhood
-
$n < 2$ : 0 dead because of isolation -
$n = 2$ : stay as before -
$n = 3$ : 1 birth -
$n>3$ : 0 dead because of over population
- enter white cell, turn left and paint cell gray
- enter gray cell, turn right and paint cell white
observation
- chaotic phase of about 10000 steps
- formation highway
- walking on highway
rule \$(\psi_{i-1}\psi_{i}\psi_{i+1})_t$ | 111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
---|---|---|---|---|---|---|---|---|
184 |
1 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
- collision
- propagation
error
Center Limit Theorem $$ \delta Q = (b-a) \frac{\sigma}{\sqrt{N}} = V\frac{\sigma}{\sqrt{N}}\
\sigma^2 = \frac{1}{N-1}\sum_{i=1}^N
\left(g(x_i) - \frac{Q}{N}\right)
$$
the error independent of dimension
cirtical point
$$
N^{-\frac{2}{d}}\overset{crit}{=}\frac{1}{\sqrt{N}}
$$
for
high dimension integration
hard-sphere, overlap
$Var(f-g) < Var(f)$ -
$\int_a^b g(x)dx$ is known
- ergodicity:
$\forall X,Y: W(X\rightarrow Y) > 0 $ - normalization:
$\sum_Y W(X\rightarrow Y) = 1$ - homogeneity:
$\sum_Y p(Y)W(Y\rightarrow X) = p(X)$
Detailed Balance :
- random choose a configuration
$X$ - compute
$\Delta E = E(Y) - E(X)$ - spinflip if
$\Delta E < 0$ else accept iwth probability$exp(-\frac{\Delta E}{k_BT})$
simulate the magnetic properties of a material
$$
\mathcal H = - J \sum_{i,j}S_iS_j - H\sum_i S_i
$$
def ising_model(lattice, M, E, J, beta, steps):
"""
lattice: np.ndarray[L, L]
1 means spin up, -1 means spin down
M: float
magnetic field
E: float
energy
J: float
coupling constant
beta: float
inverse of temperature `beta = 1 / T / kB`
steps: int
"""
L = lattice.shape[0]
for i in range(steps):
x, y = np.random.randint(0, L, [2])
sigma_j = lattice[get_neighbors(lattice, x, y)].sum()
sigma_i = lattice[x, y]
delta_E = 2 * J * sigma_i * sigma_j
accept = min(1., exp(-beta * delta_E)) > rand()
if accpet:
M -= 2*lattice[x, y]
E += delta_E
lattice[x, y] *= -1
return M, E
- random choose a configuration
$X$ - compute
$\Delta E = E(Y) - E(X) = 2J\sigma_i\sigma_j$ - spinflip if
$\Delta E < 0$ else accept with probability$exp(-\frac{\Delta E}{k_BT})$
- input data error
- rounding error
- truncation error
- simplification in mathematical model
- human & machine error
propogation $$ \varepsilon \approx \sqrt{\sum_{i}^n \left(\frac{\partial f}{\partial x_i}\right)^2\varepsilon_i^2} $$
-
parabolic :
$D\frac{\partial ^2 \phi}{\partial ^ 2 x} - \frac{\partial \phi}{\partial t} = 0$ -
hyperbolic :
$\frac{\partial^2 \phi}{\partial ^2 x} - \frac{1}{c}\frac{\partial^2 \phi}{\partial^2 t} = 0$ generate solution is
$\phi(x,t)=\alpha f_0(x-ct)+\beta g_0(x+ct)$ -
elliptic :
$\nabla^2\phi = 0$
Lagrange Derivative : $$ \frac{D\phi}{Dt} = \frac{\partial \phi}{\partial t} + \overrightarrow u \cdot \nabla \phi $$
$$ \begin{aligned} \frac{\partial \phi^{n+1}j}{\partial t} &= \frac{\phi_j^{n+1} - \phi_j^{n}}{\Delta t } + \mathcal O(\Delta t ) \ \frac{\partial \phi^n_j}{\partial x} &= \frac{\phi_j^{n} - \phi{j-1}^{n}}{\Delta x} + \mathcal O(\Delta x) \end{aligned} $$
first order accurate
explicit
second order accurate
implicit
first order accurate
implicit
- Dissipation : smooth out sharp corners, gradients, discontinuities
- Dispersion : dependence of wave speed on wavelength
Lax-Equivalence Theorem
consistency + stability
Courant-Friedrichs-Lewy(CFL) cirterion
$$
C = \frac{u\Delta t}{\Delta x} \le C_{max}
$$
for explicit,
Domain of Dependence(DoD)
- DoD for FTBS
$0\le c \le 1$ - DoD for CTCS
$-1 \le c \le 1$
Von-Neumann Stability Analysis $$ \phi^{n+1} = A\phi^n $$
-
$|A|^2 < 1$ stable and damping -
$|A|^2 = 1$ neutral stable -
$|A|^2 > 1$ unstable and amplyfying
for FTBS
$$
\begin{aligned}
\phi^{n+1}j &= \phi^n_j - c(\phi^n_j -\phi^n{j-1})
\
A^{n+1} e^{ikj\Delta x} &= A^n e^{ekj\Delta x} - cA^n\left(e^{ikj\Delta x}-e^{ik(j-1)\Delta x}\right)
\
A &= 1 - c(1-e^{-ik\Delta x})
\
|A|^2 &= 1 - 2c(1-c)(1-cos k \Delta x)
\end{aligned}
$$
if $u < 0 $ or
for FTCS $$ |A|^2 = 1 + 4c^2 sin^2(k\Delta x) $$ for CTCS $$ \begin{aligned} \phi_j^{n+1} &= \phi_j^{n-1}- c(\phi_{j+1}^n - \phi_{j-1}^n) \ A & = -ic sin(k\Delta x)\pm \sqrt{1 - c^2 sin^2 k\Delta x}\ |A|^2 &= 2c^2sin^2(k\Delta x) - 1 \mp sin(k\Delta x)\sqrt{c^2sin^2(k\Delta x) - 1} \end{aligned} $$
-
$|c| > 1$ unstable -
$|c| \le 1$ stable
there are two solutions ,should ignore the spurious solution
for CTCS, small
where
where
A-Grid(unstaggered)
$$
\frac{\eta^n_j - \eta^{n-1}j}{\Delta t} = - H_0 \frac{u^n{j+1} - u^n_{j-1}}{\Delta x}
\
\frac{u^{n+1}j - u^n_j}{\Delta t} = -g \frac{\eta^n{j+1} - \eta^n_{j-1}}{\Delta x}
$$
courant number
stable for
**C-Grid(Staggered) **
$$
\frac{\eta_j^n- \eta^{n-1}j}{\Delta t} = - H_0\frac{u^n{j+\frac{1}{2}}-u^n_{j-1}}{\Delta x}
\
\frac{u^{n+1}{j+\frac{1}{2}} - u^n{j+\frac{1}{2}}}{\Delta t} = - g \frac{\eta^n_{j+1} - \eta^n_{j-1}}{\Delta x}
$$
stable for
-
truncation error : taylor expansion in euler method,
$\mathcal O(\Delta t^2)$ for each step,$\mathcal O(\Delta t)$ in total -
round-off error : charcteristic number
$\eta$ , the smallest incremental, in euler method$\mathcal O(\eta)$ for each step,$\mathcal O(\frac{\eta}{\Delta t})$ in total -
total error : for euler method,
$\varepsilon \sim \frac{\eta}{\Delta t} + \Delta t$
for ordinary differential equatiion (ODE) $$ \frac{\partial \phi}{\partial t} = f(t, \phi(t))\quad \phi(t_0) = \phi^0 $$
name | order | |||
---|---|---|---|---|
explicit euler | 0 | 0 | 0 | 1 |
implicit euer | 0 | 0 | 1 | 1 |
leapfrog | 0 | 0 | 2 |
truncation error
round-off error
minimum error is smaller with bigger
volume
- left: conserve
- middle: loss energy
- right: gain energy
for Hamiltonian
Valsov-Maxwell-Bolzmann equation
computational plasma
$$
\begin{aligned}
\frac{\partial f_s}{\partial t} + \nabla_x \cdot(\boldsymbol vf_s) + \nabla_{\boldsymbol v}\cdot ((\boldsymbol E + \boldsymbol v \times \boldsymbol B)\frac{q_sf_s}{m_s}) &= (\frac{\partial f_s}{\partial t})c \
\nabla \cdot \boldsymbol E &= \frac{\rho}{\varepsilon_0}\
\nabla \cdot \boldsymbol H &= 0 \
\nabla \times \boldsymbol E + \frac{\partial \boldsymbol H}{\partial t} &= 0\
\nabla \times \boldsymbol H - \mu_0 \varepsilon_0 \frac{\partial \boldsymbol E}{\partial t} &= \mu_0\sum_s q_s \int{-\infin}^{\infin} \boldsymbol vf_s d\boldsymbol v^3
\end{aligned}
$$
where
Boris algorithm
$$
\begin{aligned}
\boldsymbol v^- &= \boldsymbol v^{n-\frac{1}{2}} + \frac{q}{m} \boldsymbol E^n\frac{\Delta t}{2} \
\frac{\boldsymbol v^+ - \boldsymbol v^-}{\Delta t} &= \frac{q}{2m}(\boldsymbol v^+ + \boldsymbol v^-) \times \boldsymbol B^n\
\boldsymbol v^{n+\frac{1}{2}} &= \boldsymbol v^+ + \frac{q}{m}\boldsymbol E^n\frac{\Delta t}{2}
\end{aligned}
$$
without
error minimized by
stability:
-
generate initial condition
$f_0, F^0$ -
for loop
-
force field interpolate from grid to particles
-
push particles
$(x,v)^n_k\rightarrow (x,v)^{n+1}_k$ -
density field interpolation to grid
$(x,v)_k \rightarrow (\rho, J)_j$ -
force field calculation
$F_k^n\rightarrow F_k^{n+1}$ , using FFT$\phi(x) = \int \rho(x') G(x,x')dx' = \mathcal F^{-1}(\mathcal F(\rho) \cdot \mathcal F(G))$
-
$$ G(r) = \underbrace{\frac{1-erf(\alpha r)}{r}}{G{pp}} + \underbrace{\frac{erf(\alpha r)}{r}}{G{pm}} $$