-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumGy_LV09.qmd
275 lines (207 loc) · 7.84 KB
/
NumGy_LV09.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
---
title: "Numerical Simulation Methods in Geophysics, Part 9: 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
Done:
* finite difference method for Poisson (1D) and heat transfer
* wave equation modelling in 1D
* finite element method for Poisson equation
* weak form decreases order of derivatives
* Maxwell equations lead to Helmholtz equation
## The next lectures and exercises
* today (LV09): 08.01.25, no exercise on 09.01. (dies academicus)
* LV10: 15.01.25, exercise on 16.01.
* LV11: 22.01.25, exercise on 23.01.
* LV12: 29.01.25, exercise on 30.01.
* last VL13: 05.02.25, exercise on 06.02.
* report on 2D Helmholtz equations
<!-- ## Recap -->
<!-- Todo:
* solving Helmholtz equation for 1D and 2D
* complex-valued problem
* secondary field approach -->
## Helmholtz equation for E
Maxwell equation in frequency domain (see also [Theory EM](https://ruboerner.github.io/ThEM/mtfields.html))
$$ \curl \vb H = \imath\omega\epsilon\vb E + \vb j \qquad (\vb j = \sigma\vb E + \vb j_s) $$
$$ \curl\vb E = -\imath\omega\mu\vb H \Rightarrow \vb H = \imath \frac{1}{\mu\omega} \curl\vb E $$
$$ \curl\vb H = \imath\omega^{-1} \curl \mu^{-1}\curl\vb E = (\imath\omega\epsilon+\sigma)\vb E + \vb j_s $$
$$ \curl\mu^{-1}\curl\vb E + (\imath\sigma\omega-\omega^2\epsilon)\vb E =-\imath\omega\vb j_s $$
Quasistatic approximation ($\omega\epsilon\ll\sigma$): neglect $\epsilon$ term
## Helmholtz equation for H
Maxwell equation in frequency domain (see also [Theory EM](https://ruboerner.github.io/ThEM/mtfields.html))
$$ \curl\vb E = -\imath\omega\mu\vb H $$
$$ \curl \vb H = \sigma\vb E + \vb j_s \Rightarrow \vb E = \sigma^{-1}\curl\vb H - \sigma^{-1}\vb j_s $$
$$ \curl\vb E = \imath\omega\epsilon\vb E + \curl \sigma^{-1}\curl\vb H - \curl\sigma^{-1}\vb j_s = -\imath\omega\mu\vb H $$
$$ \curl\sigma^{-1}\curl\vb H + \imath\mu\omega\vb H = \curl\sigma^{-1}\vb j_s $$
Quasistatic approximation ($\omega\epsilon\ll\sigma$)
neglect $\epsilon$ term
## 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 $$
## Next steps
* solve 1D Helmholtz equation complex-values
* compare with analytic solution
* 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
## 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 u_i + \imath\omega\vb M \vb b_i - \omega\vb M \vb b_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)
## 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)
```