-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumGy_LV12.qmd
156 lines (114 loc) · 4.52 KB
/
NumGy_LV12.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
title: "Numerical Simulation Methods in Geophysics, Part 12: Advection problems and the Finite Volume Method"
subtitle: "1. MGPY+MGIN"
author: "[email protected]"
title-slide-attributes:
data-background-image: pics/tubaf-logo.png
data-background-size: 20%
data-background-position: 10% 95%
format:
tubaf-revealjs:
html-math-method: mathjax
chalkboard: true
include-in-header:
- text: |
<script>
window.MathJax = {
loader: {
load: ['[tex]/physics']
},
tex: {
packages: {'[+]': ['physics']}
}
};
</script>
slide-number: c/t
transition: slide
transition-speed: fast
menu:
side: left
---
# Recap
1. The Finite Difference (FD) method
* Poisson equation in 1D, look into 2D/3D
* diffusion equation in 1D, time-stepping
1. Solving the hyperbolic (acoustic) wave equation in 1D
1. The Finite Element (FE) method
* Poisson and diffusion equation in 1D
* (complex) Helmholtz equation in 2D for EM problems
* solving EM problems and computational aspects
## Solution in pyGIMLi
:::: {.columns}
::: {.column}
step by step
```
import pygimli.solver as ps
A = ps.createStiffnessMatrix(mesh, a)
M = ps.createMassMatrix(mesh, b)
f = ps.createLoadVector(mesh, f)
ps.assembleNeumannBC(b, boundaries)
ps.assembleDirichletBC(A, b)
ps.assembleRobinBC(A, boundaries, b)
u = ps.linSolve(A, b)
```
:::
::: {.column}
or shortly
```
bc = {'Dirichlet': {4: 1.0, 3: 0.0},
'Neumann': {2: 1.0}}
u = ps.solveFiniteElements(mesh, a, b, f, bc=bc,
t=times, c)
u = pygimli.physics.seismics.solvePressureWave(
mesh, velocities, times, sourcePos, uSource)
```
:::
::::
$$ c\pdv{u}{t}= \div(a\grad u) + b u + f(\vb r, t)$$
## Advection
Volume elements move with velocity $\vb v$ and take (advectio=move with)
$$\pdv{T}{t} \Rightarrow \pdv{T}{t} + \dv{z}{t}\pdv{T}{z}$$
in 3D $\vb{v}\cdot\grad{T}$ $\Rightarrow$ advection-dispersion equation
$$\pdv{T}{t} = \div a\grad{T} + Q - \vb{v}\cdot\grad{T}$$
## Advection-dispersion equation (general)
$$ \pdv{u}{t}+\vb v\cdot\grad u = \div(a\grad u) + b u + f(\vb r, t)$$
$\vb v\cdot\grad u$ (Advection), $\div(a\grad u)$ (Dispersion=Diffusion)
Solve, e.g., by [`pyGIMLi.solver.solveFiniteVolume` (Link)](https://www.pygimli.org/pygimliapi/_generated/pygimli.solver.html#pygimli.solver.solveFiniteVolume)
```
bc = dict(Dirichlet={4: 1.0, 3: 0.0}, Neumann={2: 1.0})
u = ps.solveFiniteVolume(mesh, a, b, f, bc=bc, t=times, c)
```
## Computational fluid dynamics
Magnetohydrodynamic induction equation
$$\pdv{\vb B}{t} = \curl \frac{1}{\mu\sigma} \curl \vb B + \curl(\vb v \cross \vb B)$$
Forces on fluid (induction, Coriolis, pressure, gravity, Lorentz)
$$ \rho \pdv{\vb v}{t} + \rho (\vb v \cdot \grad) \vb v + \grad p = -2\omega\cross\vb v+\alpha T \vb g + \vb j \cross \vb B / \rho $$
## FE solution for inhomogeneous viscosity
{fig-align="center"}
## Simple 1D advection problem
$$\pdv{u}{t} + \pdv{v(u)}{x}=0$$
Solution $u_i$ at node $i$ represents average value over cell
$$ \overline{u}_i(t) = \frac{1}{x_{i+1/2}-x_{i-1/2}} \int_{x_{i-1/2}}^{x_{i+1/2}} u(x, t)\dd x $$
$$ \int_{t_1}^{t_2} \pdv{u}{t} = u(x, t_2)-u(x, t_1) = - \int_{t_1}^{t_2} \pdv{v(u)}{x} $$
## FV

## Simple 1D advection problem
$$ u(x, t_2) = u(x, t_1) - \int_{t_1}^{t_2} \pdv{v(u)}{x} $$
$$ \overline{u}(t_2) = \frac{1}{x_{i+1/2}-x_{i-1/2}} \int_{x_{i-1/2}}^{x_{i+1/2}}\qty\Big(u(x,t_1) - \int_{t_1}^{t_2} \pdv{v(u)}{x}) $$
$$ \overline{u}(t_2) = \overline{u}(t_1) - \frac{1}{x_{i+1/2}-x_{i-1/2}}
\qty\Big(\int_{t_1}^{t_2} v_{i+1/2} \dd t - \int_{t_1}^{t_2} v_{i-1/2} \dd t) $$
## Result
$$ \pdv{\overline{u}_i}{t} +\frac{1}{\Delta x_i} (v_{i+1/2}-v_{i-1/2}) = 0 $$
::: {.callout-note}
Finite volume schemes are conservative as cell averages change through the edge fluxes. In other words, one cell's loss is always another cell's gain!
:::
## Visualization
{fig-align="center"}
## Similarity to staggered (E, B) grid methods
{fig-align="center"}
## Conservation law (3D) problem
$$\pdv{\vb u}{t} + \div\vb v(u)= 0$$
volume integral over cell, using Gauss' law
$$\int_{\Omega_i} \pdv{\vb u}{t}\dd\Omega+\int_{\Omega_i} \div\vb v(u) \dd\Omega = 0 =
\int_{\Omega_i} \pdv{\vb u}{t}\dd\Omega+\int_{\Gamma_i} \vb v(u) \cdot \vb n \dd{\Gamma} $$
$$\Rightarrow \pdv{\overline{u}}{t} +\frac{1}{V_i}\int_{\Gamma_i}\vb v(u)\cdot \vb n \dd{\Gamma} =0 $$