-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumGy_LV10.qmd
329 lines (235 loc) · 8.83 KB
/
NumGy_LV10.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
---
title: "Numerical Simulation Methods in Geophysics, Part 10: 2D Helmholtz equation"
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
# jupyter: python3
---
# Recap
* Maxwell equations in time domain
* harmonic approach (or decomposition)<br>
$\Rightarrow$ (complex-valued) Helmholtz equation for $E$ and $B$
* solve 1D Helmholtz equation complex-values
* compare with analytic solution
## Next lectures and exercises
* LV10: 15.01. exercise on 16.01.
* LV11: 22.01. exercise on 23.01.
* LV12: 29.01. exercise on 30.01.
* VL13: 05.02., exercise on 06.02.
* report on 2D Helmholtz equations
## Todo
* solve 2D Helmholtz equation
* use secondary field approach
* use wide range of frequencies
* combine E and H to yield MT sounding curves
* excurse on 3D vectorial Maxwell solvers
* overview on equation solvers and high-performance computing
* outlook to computational fluid dynamics
## Electromagnetic fields in the Earth
Maxwell equations lead to diffusion equation
$$\pdv[2]{\vb B}{z}=\mu_0\sigma\pdv{\vb B}{t}$$
A periodic excitation ($B_0 e^{\imath\omega t}$) leads to (cf. temperature problem)
$$B=B_0 e^{-z/d}\cos(\omega t-z/d)$$
with the skin depth $d=\sqrt{2/(\mu_0 \sigma\omega)}\approx 503\sqrt{\rho/f}$
## Electromagnetic fields in the Earth
Assume E field in x direction
$$E_x=-\frac{1}{\mu_0\sigma}\pdv{B_y}{z}=\frac{B_0}{\mu_0\sigma d}e^{-z/d}\sqrt{2}\cos(\omega t-z/d+\pi/4)$$
$\Rightarrow$ phase shift of 45° ($\pi/4$) between $E_x$ und $B_y$
$$\frac{|E_x|}{|B_y|}=\frac{\sqrt{2}}{\mu_0\sigma d} \Rightarrow \rho=\frac{\mu_0}{\omega}\left|\frac{E_x}{B_y}\right|^2$$
## The magnetotelluric (MT) method
::::{.columns}
:::{.column width="40%"}
{fig-align="center"}
:::
:::{.column width="60%"}
* inductive electromagnetics with $f$=0.001-100\,Hz ($T$=0.01-1000s)
* source in ionosphere (natural source) or on ground (controlled source)
* measure magnetic and electric fields
* analyse (complex) ratio in frequency domain
* depth sounding ($\rho_a$ & $\phi$) with $T$
* MT course of Anna Marti (U Barcelona)
:::
::::
## Magnetotelluric depth sounding
{fig-align="center"}
## 2D/3D Magnetotellurics
{fig-align="center"}
## Helmholtz equations
$$ \curl \mu^{-1} \curl \vb E + \imath\omega\sigma\vb E - \omega^2\epsilon \vb E = - \imath\omega \vb j_s$$
$$ \curl \sigma^{-1} \curl \vb H + \imath\omega\mu\vb H - \omega^2\epsilon\mu/\sigma \vb H=\curl \sigma^{-1}\vb j_s$$
PDEs identical $\vb E$ and $\vb H$ through exchanging $\mu$ and $\sigma$
component perpendicular to modelling frame (E/H polarization)
$$ \curl a \curl = -\div a \grad $$
## Finite element discretization
* weak formulation (for E)
$$ \int_\Omega \mu^{-1}\grad v_i \cdot \grad v_j \dd\Omega + \imath\omega \int_\Omega \sigma v_i v_j \dd\Omega = \int_\Omega v_i f \dd\Omega $$
* stiffness = second derivative $\div\vb v_i$, expressed by 2 gradients
$$ \vb A_{i,j} = \int_\Omega \mu^{-1} \grad v_i \cdot \grad v_j \dd\Omega$$
## Finite element discretization
* weak formulation (for E)
$$ \int_\Omega \mu^{-1}\grad v_i \cdot \grad v_j \dd\Omega + \imath\omega \int_\Omega \sigma v_i v_j \dd\Omega = \int_\Omega v_i f \dd\Omega $$
* mass matrix resembles functions $\vb v_i$
$$ \vb M_{i,j} = \int_\Omega \sigma v_i \cdot v_j \dd\Omega $$
## Complex or real-valued?
Either discretize the complex system
$$(\vb A+\imath\omega\vb M) (\vb u_r + \imath \vb u_i) = \vb b_r + \imath \vb b_i$$
by complex shape functions OR transfer into real
$$\vb A\vb u_r + \imath\vb A \vb u_i + \imath\omega\vb M \vb u_i - \omega\vb M \vb u_i = \vb b_r + \imath \vb b_i$$
$$\mqty(\vb A & -\omega \vb M\\ \omega \vb M & \vb A) \mqty(\vb u_r\\ \vb u_i) = \mqty(\vb b_r\\ \vb b_i) $$
## Secondary field approach
Consider the field to consist of a primary (background) and an secondary (anomalous) field $F=F_0+F_a$ (or $F_p+F_s$)
solution for $F_0$ known, e.g. analytically or 1D (semi-analytically)
$\Rightarrow$ form equations for $F_a$, because
* $F_a$ is weaker or smoother (e.g. $F_0\propto 1/r^n$ at sources)
* boundary conditions easier to set (e.g. homogeneous Dirichlet)
## Example DC resistivity
$$-\div(\sigma\grad u) = \div j_s = I\delta(\vb r-\vb r_s)$$
Problem: point source leads to infinite potential
$$u(\vb r)=\frac{I}{2\pi\sigma}\frac{1}{|\vb r - \vb r_s|}$$
Approach: $u=u_p(\sigma_0) + u_s(\sigma-\sigma_0)$:
$$-\div(\sigma\grad u_s) = \div((\sigma-\sigma_0)\grad u_p)$$
## Example DC resistivity
$$-\div(\sigma\grad u_s) = \div((\sigma-\sigma_0)\grad u_p)$$
discrete form using unit conductivity $\sigma_1=1$S/m
$$\vb A^\sigma \vb u_s = \vb A^{\delta\sigma}\vb u_p = \vb A^\sigma \vb u_p - \sigma_0 \vb A^1 \vb u_p$$
## Secondary field Helmholtz equation
The equation $-\grad^2 F - k^2 F = 0$ is solved by the primary field for $k_0$:
$-\grad^2 F_0 - k_0^2 F_0=0$ and the total field for $k_0+\delta k$:
$$ -\grad^2 (F_0+F_a) -(k_0^2+\delta k^2) (F_0+F_a) = 0 $$
$$ -\grad^2 F_a - k^2 F_a = \delta k^2 F_0 $$
::: {.callout-note}
Same operator, source terms at anomalies, weighted by the primary field.
:::
## Secondary field for EM
Maxwells equations $k^2=-\imath\omega\mu\sigma$
$$-\grad^2 \vb E_0 +\imath\omega\mu\sigma \vb E_0=0$$
leads to
$$ -\grad^2 \vb E_a + \imath\omega\mu\sigma \vb E_a = -\imath\omega\mu\delta\sigma \vb E_0 $$
::: {.callout-note}
Source terms only arise at anomalous conductivities and increase with primary field
:::
## Secondary field for EM
$$ -\grad^2 \vb E_a + \imath\omega\mu\sigma \vb E_a = -\imath\omega\mu\delta\sigma \vb E_0 $$
leads to the discretized form ($\vb A$-stiffness, $\vb M$-mass)
$$ \vb A \vb E_a + \imath\omega\vb M_\sigma E_a = -\imath\omega\vb M_{\delta\sigma} \vb E_0 $$
```{python}
#| echo: true
#| eval: false
A = stiffnessMatrix1DFE(x=z)
M = massMatrix1DFE(x=z, a=w*mu*sigma)
dM = massMatrix1DFE(x=z, a=w*mu*(sigma-sigma0))
u = uAna + solve(A+M*w*1j, dM@uAna * w*1j)
```
# 2D problems
Make use of pyGIMLi
See documentation on [pyGIMLi.org](https://pygimli.org)
## The meshtools module
```{python}
#| echo: true
#| eval: true
import pygimli as pg
import pygimli.meshtools as mt
world = mt.createWorld(start=[-10000, -10000], end=[10000, 0])
pg.show(world)
```
## The meshtools module
```{python}
#| echo: true
#| eval: true
mesh = mt.createMesh(world, quality=34, area=1e5)
pg.show(mesh)
```
## Creating a 2D geometry
```{python}
#| echo: true
#| eval: true
anomaly = mt.createRectangle(start=[0, -8000], end=[1000, -1000], marker=2)
pg.show(world+anomaly)
```
## Creating a 2D mesh
```{python}
#| echo: true
#| eval: true
mesh = mt.createMesh(world+anomaly, quality=34, smooth=True, area=1e5)
pg.show(mesh, markers=True, showMesh=True);
```
## Creating a 2D conductivity model
```{python}
#| echo: true
#| eval: true
sigma0 = 1 / 100 # 100 Ohmm
sigma = mesh.populate("sigma", {1: sigma0, 2: sigma0*10})
pg.show(mesh, "sigma", showMesh=True);
```
## The solver module
```{python}
#| echo: false
#| eval: true
import matplotlib.pyplot as plt
import numpy as np
```
```{python}
#| echo: true
#| eval: true
import pygimli.solver as ps
mesh["my"] = 4 * np.pi * 1e-7
A = ps.createStiffnessMatrix(mesh, a=1/mesh["my"])
M = ps.createMassMatrix(mesh, mesh["sigma"])
fig, ax = plt.subplots(ncols=2)
ax[0].spy(pg.utils.toCSR(A), markersize=1)
ax[1].spy(pg.utils.toCSR(M).todense(), markersize=1)
```
## The complex problem matrix
$$\vb B = \mqty(\vb A & -\omega \vb M\\ \omega \vb M & \vb A)$$
```{python}
#| echo: true
#| eval: true
#| output-location: column
w = 0.1
nd = mesh.nodeCount()
B = pg.BlockMatrix()
B.Aid = B.addMatrix(A)
B.Mid = B.addMatrix(M)
B.addMatrixEntry(B.Aid, 0, 0)
B.addMatrixEntry(B.Aid, nd, nd)
B.addMatrixEntry(B.Mid, 0, nd, scale=-w)
B.addMatrixEntry(B.Mid, nd, 0, scale=w)
pg.show(B)
```
## Sparse matrices
Up to now: regular (dense) array: save every element including 0
Save only non-zero components (e.g. using `scipy.sparse`)
* COO - coordinate format
* CSC/CRS - compressed sparse column/row
* BSR - block sparse row format, ...
## Solve systems of equations
* Gauss elimination (expensive and dense)
* Cholesky (or ILU) decomposition
* Iterative solvers (conjugate gradients)
* incomplete factorizations or factorization of submatrices
## Reordering
