Skip to content

Commit

Permalink
ADD first chapter qmd
Browse files Browse the repository at this point in the history
  • Loading branch information
halbmy committed Dec 19, 2024
1 parent 5b589d3 commit 022ecb2
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 0 deletions.
142 changes: 142 additions & 0 deletions 01_introduction.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
title: "Introduction"
---

## Differential operators

* single derivative in space $\pdv{x}$ or time $\pdv t$

* gradient $\grad=(\pdv x, \pdv y, \pdv z)^T$

* divergence $\div \vb F = \pdv{F_x}{x} + \pdv{F_y}{y} + \pdv{F_z}{z}$

::::: {.fragment}
:::: {.columns}
::: {.column width="70%"}
Gauss': *what's in (volume) comes out (surface)*
$$\int_V \div\vb F\ dV = \iint_S \vb F \vdot \vb n\ dS$$
:::
::: {.column width="25%"}
![Gauss's theorem in EM](pics/Divergence_theorem_in_EM.svg)
:::
::::
:::::

## Curl (rotation)

* curl $\curl \vb F = (\pdv{F_z}{y}-\pdv{F_y}{z}, \pdv{F_x}{z}-\pdv{F_z}{x}, \pdv{F_y}{x}-\pdv{F_x}{y})^T$

::::: {.fragment}
:::: {.columns}
::: {.column width="70%"}
Stoke: *what goes around comes around*
$$\int_S \curl \vb F \vdot \vb dS = \iint_S \vb F \vdot \vb dl$$
:::
::: {.column width="25%"}
![Stokes' theorem in EM](pics/Curl_theorem_in_EM.svg)
:::
::::
:::::

:::{.fragment}
* curls have no divergence: $\div (\curl \vb F)=0$
:::

:::{.fragment}
* potential fields have no curl $\curl (\grad u)=0$
:::

## Numerical simulation

Mostly: solution of partial differential equations (PDEs) for either scalar (potentials) or vectorial (fields) quantities

PDE Types ($u$-function, $f$-source, $a$/$c$-parameter):

* elliptic PDE: $-\nabla^2 u=f$ (Poisson) or $\nabla^2 u + k^2 u = f$ (Helmholtz)
* parabolic PDE $-\nabla^2 u + a \frac{\partial u}{\partial t}=f$
* hyperbolic $-\nabla^2 u + c^2 \frac{\partial^2 u}{\partial t^2}=f$ (plus diffusive term)
$$\frac{\partial^2\ u}{{\partial x}^2} - c^2\frac{\partial^2 u}{\partial t^2} = 0$$
* coupled $\nabla\cdot u=f$ & $u = K \nabla p=0$ (Darcy flow)
* nonlinear $(\nabla u)^2=s^2$ (Eikonal equation)

## Poisson equation
potential field $u$ generates field $\vec{F}=-\nabla u$

causes some flow $\vec{j}=a \vec{F}$

$a$ is some sort of conductivity (electric, hydraulic, thermal)

continuity of flow: divergence of total current $\vb j + \vb j_s$ is zero

$$ \div (a \nabla u) = - \div \vb j_s $$

## Darcy's law

:::: {.columns}
::: {.column width="50%"}

volumetric flow rate $Q$ caused by gradient of pressure $p$

$$ Q = \frac{k A}{\mu L} \Delta p $$

$$\vb q = -\frac{k}{\mu} \nabla p $$

$$\div\vb q = -\div (k/\mu \grad p) = 0$$

:::
::: {.column width="45%"}
![Darcy's law](pics/darcy_law.svg)
:::
::::

## The heat equation in 1D

sought: Temperature $T$ as a function of space and time

heat flux density $\vb q = \lambda\grad T$

$q$ in W/m², $\lambda$ - heat conductivity/diffusivity in W/(m.K)

Fourier's law: $\pdv{T}{t} - a \nabla^2 T = s$ ($s$ - heat source)

temperature conduction $a=\frac{\lambda}{\rho c}$ ($\rho$ - density, $c$ - heat capacity)

## Stokes equation

$$ \mu \nabla^2 \vb v - \grad p + f = 0 $$

$$\div\vb v = 0 $$

## Navier-Stokes equations
(incompressible, uniform viscosity)

$$ \pdv{\vb u}{t} +(\vb u \vdot \grad) \vb u = \nu \nabla^2 \vb u - 1/\rho \grad p + f $$

## Maxwell's equations

* Faraday's law: currents & varying electric fields $\Rightarrow$ magnetic field
$$ \curl \vb H = \pdv{\vb D}{t} + \vb j $$
* Ampere's law: time-varying magnetic fields induce electric field
$$ \curl\vb E = -\pdv{\vb B}{t}$$
* $\div\vb D = \varrho$ (charge $\Rightarrow$), $\div\vb B = 0$ (no magnetic charge)
* material laws $\vb D = \epsilon \vb E$ and $\vec B = \mu \vb H$

## Helmholtz equations

$$ \nabla^2 u + k^2 u = f $$

results from wavenumber decomposition of diffusion or wave equations

approach: $\vb F = \vb{F_0}e^{\imath\omega t} \quad\Rightarrow\quad \pdv{\vb F}{t}=\imath\omega\vb F \quad\Rightarrow\quad \pdv[2]{\vb F}{t}=-\omega^2\vb F$

$$ \nabla^2 \vb F - a \nabla_t \vb F - c^2 \nabla^2_t \vb F = 0 $$

$$ \Rightarrow \nabla^2\vb F - a\imath\omega\vb F + c^2 \omega^2\vb F = 0 $$

## The eikonal equation

Describes first-arrival times $t$ as a function of velocity ($v$) or slowness ($s$)

$$ |\grad t| = s = 1/v $$

![](pics/tt4.png){.fragment width="458" height="420"}
118 changes: 118 additions & 0 deletions 02_finite-differences.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: "Finite Differences"
jupyter: python3
---





## Helmholtz equations

e.g. from Fourier assumption $u=u_0 e^{\imath\omega t}$

$$ \div (a\grad u) + k^2 u = f $$

* Poisson operator assembled in stiffness matrix $\vb A$
* additional terms with $u_i$ $\Rightarrow$ mass matrix $\vb M$

$$ \Rightarrow \vb A + \vb M = \vb b $$

## Hyberbolic equations

Acoustic wave equation in 1D
$$ \pdv[2]{u}{t} - c^2\pdv[2]{u}{x} = 0 $$

$u$..pressure/velocity/displacement, $c$..velocity

Damped (mixed parabolic-hyperbolic) wave equation
$$ \pdv[2]{u}{t} - a\pdv{u}{t} - c^2\pdv[2]{u}{x} = 0 $$


## Discretization

:::: {.columns}
::: {.column}
$$ \pdv[2]{u}{t}^{n} \approx \frac{u^{n+1}-u^n}{\Delta t} - \frac{u^{n}-u^{n-1}}{\Delta t}
$$

$$ = \frac{u^{n+1}+u^{n-1}-2 u^n}{\Delta t^2} = c^2\pdv[2]{u}{x}^n $$


$$ u^{n+1} = c^2 \Delta t^2 \pdv[2]{u}{x}^{n} + 2 u^n - u^{n-1} $$

<!-- \frac{1}{\Delta t} -->

$$ \vb M \vb u^{n+1} = (\vb A + 2\vb M) \vb u^n - \vb M \vb u^{n-1} $$
:::
::: {.column}
![Second derivative](pics/dtsecond.svg)
:::
::::

## Example: velocity distribution

```{python}
#| output-location: column-fragment
#| eval: true
#| echo: true
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(0, 600.01, 0.5)
c = 1.0*np.ones_like(x) # velocity in m/s
c[100:300] = 1 + np.arange(0,0.5,0.0025)
c[900:1100] = 0.5 # low velocity zone
# Plot velocity distribution.
plt.plot(x,c,'k')
plt.xlabel('x [m]')
plt.ylabel('c [m/s]')
plt.grid()
```


## Initial displacement

Derivative of Gaussian (Ricker wavelet)
```{python}
#| output-location: column-fragment
#| eval: true
#| echo: true
l=5.0
# Initial displacement field [m].
u=(x-300.0)*np.exp(-(x-300.0)**2/l**2)
# Plot initial displacement field.
plt.plot(x,u,'k')
plt.xlabel('x [m]')
plt.ylabel('u [m]')
plt.title('initial displacement field')
plt.show()
```

## Time propagation

```{python}
#| output-location: column-fragment
#| eval: true
#| echo: true
u_last=u
dt = 0.5
ddu = np.zeros_like(u)
dx = np.diff(x)
for i in range(100):
dudx = np.diff(u)/dx
ddu[1:-1] = np.diff(dudx)/dx[:-1]
u_next = 2*u-u_last+ddu*c**2 * dt**2
u_last = u
u = u_next
plt.plot(x,u,'k')
```

<video autoplay="true" loop="true">
<source src="notebooks/wave.mp4">
</video>
<!-- <video data-autoplay src="notebooks/wave.mp4"></video> -->
<!-- {{< video notebooks/wave.mp4 video="true">}} -->

124 changes: 124 additions & 0 deletions 03_finite-elements.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
title: "Finite Elements"
jupyter: python3
---

## History and background

* [1943] Courant: Variational Method
* [1956] Turner, Clough, Martin, Topp: Stiffness
* [1960] Clough: Finite Elements for static elasticity
* [1970-80] extension to structural, thermic and fluid dynamics
* [1990] computational improvements
* now main method for almost all PDE types

Geophysics: Poisson equation in 1970s, revival in 1990s and predominant in 2000s up to now

## Variational formulation of Poisson equation

$$ -\div a \grad u = f $$

::: {.fragment}
Multiplication with test function $w$ and integration $\Rightarrow$ weak form

$$ -\int_\Omega w \div a \grad u \dd\Omega = \int_\Omega w f \dd\Omega $$
:::

::: {.fragment}
$$ \div(b\vb c) = b\div \vb c + \grad b \cdot \vb c $$
:::

::: {.fragment}
$$ \int_\Omega \grad w a \grad u \dd\Omega - \int_\Omega \div(w a \grad u) \dd\Omega = \int_\Omega w f \dd\Omega $$
:::

## Variational formulation of Poisson equation

$$ \int_\Omega \grad w a \grad u \dd\Omega - \int_\Omega \div(w a \grad u) \dd\Omega = \int_\Omega w f \dd\Omega $$

::: {.fragment}
use Gauss' law $\int_\Omega \div \vb A = \int_\Gamma \vb A \cdot \vb n$

$$ \int_\Omega a \grad w \grad u \dd\Omega - \int_\Gamma a w \grad u \dd\Gamma = \int_\Omega fw \dd\Omega $$
:::

::: {.fragment}
Let $u$ be constructed by shape functions $v$: $u=\sum_i u_i v_i$

$$ \int_\Omega a \grad w \grad v_i \dd\Omega - \int_\Gamma a w \grad v_i \dd\Gamma = \int_\Omega fw \dd\Omega $$
:::

## Galerkins method

$$ \int_\Omega a \grad w \grad v_i \dd\Omega - \int_\Gamma a w \grad v_i \dd\Gamma = \int_\Omega fw \dd\Omega $$

::: {.fragment}
Test functions equal shape (trial) functions $w_i=v_i$

$$ \int_\Omega a \grad v_i \grad v_j \dd\Omega - \int_\Gamma a w \grad v_j \dd\Gamma = \int_\Omega f v_j \dd\Omega $$
:::

::: {.fragment}
* choose $v_i$ so that $\grad v_i$ is simple and $\grad v_i \grad v_j$ mostly 0
* divide subsurface in sub-volumes $\Omega_i$ with constant $a_i$ and $\grad v_j$
:::

## Hat functions

![](pics/shapefunctions1d.svg){width="100%"}

## Gradients for hat functions
Every element is surrounded by two nodes "carrying" a hat.

The gradients are piece-wise constant $\pm 1/\Delta x_i$

$$ \Rightarrow \int_\Omega a \grad v_i \grad v_{i+1} \dd\Omega = -\frac{a_i}{\Delta x_i^2} \cdot \Delta x_i = -\frac{a_i}{\Delta x_i}$$

$$ -\int_\Omega a \grad v_i \grad v_i \dd\Omega = \frac{a_{i-1}}{\Delta x_{i-1}^2}\Delta x_{i-1} + \frac{a_i}{\Delta x_i^2}\Delta x_i = \frac{a_{i-1}}{\Delta x_{i-1}} + \frac{a_i}{\Delta x_i} $$

$$ -\int_\Omega a \grad v_i \grad v_{i+2} \dd\Omega = 0 $$

# System (stiffness) matrix

Matrix integrating gradient of base functions for neighbors
$A$
$$ \vb A_{i, i+1} = -\frac{a_i}{\Delta x_i^2} \cdot \Delta x_i $$

$$ A_{i,i} = \int_\Omega a \grad v_i \grad v_i \dd\Omega = -A_{i,i+1} + A_{i+1,i} $$

$\Rightarrow$ matrix-vector equation $\vb A \vb u = \vb b$
$\Rightarrow$

## Boundary conditions

second term
$$ - \int_\Gamma a v_i \grad v_j \dd\Gamma $$




## Right-hand side vector

The right-hand-side vector $b=\int v_i f \dd\Omega$ also scales with $\Delta x$

e.g. $f=\div j_s$ $\Rightarrow$ $b=\int v_i \div j_s \dd\Omega = \int_\Gamma $

system identical to FD for $\Delta x=$const

:::{.callout-tip icon="false" title="Difference of FE to FD"}
Any source function $f(x)$ can be integrated on the whole space!
:::

## Solution

$\vb v$ holds the coefficient $u_i$ creating $u=\sum u_i v_i(x)$

:::{.callout-tip icon="false" title="Difference of FE to FD"}
$u$ is described on the whole space and approximates the solution, not the PDE!
:::

Hat functions: $u_i$ potentials on nodes, $u$ piece-wise linear

:::{.callout-tip icon="false" title="Generality of FE"}
Arbitrary base functions $v_i$ can be used to describe $u$
:::

0 comments on commit 022ecb2

Please sign in to comment.