-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumGy_LV07.qmd
278 lines (209 loc) · 6.38 KB
/
NumGy_LV07.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
---
title: "Numerical Simulation Methods in Geophysics, Part 7: Finite Elements"
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 Finite Elements
* weak form of PDE: integral over product with test function $\vb w$
* approximate $u$ with shape functions $u=\sum u_i \vb v_i$
* Galerkin's method: same function space for $\vb w$ and $\vb v$
:::{.callout-tip icon="false" title="Difference of FE to FD"}
Solution $u$ is described on the whole space and approximates the solution, not the PDE!
Any source function $f(x)$ can be integrated on the whole space!
:::
## Recap (cont)
:::{.callout-tip icon="false" title="Generality of FE"}
Arbitrary base functions $v_i$ can be used to describe $u$
:::
* started with piece-wise linear (hat) functions
* system identical to FD for $\Delta x=$const and $a$=const
## Method of weighted residuals
PDE $\mathfrak{L}(u)=f$ $\Rightarrow$ approximated by $u_h$
residual $R=L_h(u)-f$ to be minimized, integrating over modelling domain
$$ \int_\Omega w R \dd\Omega = \int_\Omega w \mathfrak{L}(u_h)\dd\Omega - \int_\Omega w f \dd\Omega = 0 $$
with approximation $u_h(\vb r)=\sum_j^M u_j \vb v_j(\vb r)$
($\vb v$ basis / shape functions, $\vb w$ test / trial functions)
## Bilinear form for Poisson equation
Solve $\vb A \vb x = \vb b$ with $A_{ij}=(\grad v_i, \grad v_j)$ and $b_i=(\vb v_i, f)$, where
$$(\vb a, \vb b)=\int_\Omega \vb a \cdot \vb b\,\dd\Omega = \sum\limits_{c=i}^M \int_{\Omega_c} \vb a \cdot \vb b\,\dd\Omega_c$$
Solve the integrals either analytically or numerically
## The general solution
Solving any integral using (Gaussian) quadrature
$$\int g(x) \dd x \approx \sum_q g(x_q) w_q$$
$$f_i^c=\int_{\Omega_c} v_i f \dd x \approx \sum_q v(x_q^c)f(x_q^c)w_q^c$$
$$a_{ij}^c = \int_c a_c \grad v_i \cdot \grad v_j=\sum a_c \grad v_i(x_q^c)\cdot \grad v_j(x_q^c) w_q^c $$
## Gaussian quadrature
:::: {.columns}
::: {.column width="45%"}
![Quadrature points](pics/triangle_quadrature.svg){width="100%"}
:::
::: {.column width="55%"}
`quadratureRules(c.shape(), 5)`
* optimum quadrature on reference triangle for a given order (5)
:::
::::
## Gaussian quadrature
:::: {.columns}
::: {.column width="45%"}
![Quadrature points](pics/oscar_quadrature_triangle.svg){width="100%"}
:::
::: {.column width="55%"}
`quadratureRules(c, 2)`
* optimum quadrature on arbitrary triangle for order 2
:::
::::
## Coordinate transformation
1D: local coordinate $\xi=\frac{x-x_i}{x_{i+1}-x_i}$ (0..1)
$u(\xi)=c_1+c_2\xi$
$u_0=u(0)=c_1$, $u_1=u(1)=c_1+c_2$ $c_2=u_1-u_0$
$$\Rightarrow u(\xi)=u_0+\xi(u_1-u_0)=u_0(1-\xi)+u_1\xi=u_i v_i + u_1 v_1$$
## Quadratic elements
$u(\xi)=c_1+c_2\xi+c_3\xi^2$
nodes at $x_0$, $x_{1/2}$, $x_1$
$u_i=u(0)=c_1$, $u_1=c_1+c_2+c_3$
$u_{1/2}=c_1+c_2/2+c_3/4$
$$u(\xi)=u_0(1-3\xi+2\xi^2)+u_{1/2}(4\xi-4\xi^2)+u_1(-\xi+2\xi^2)$$
## Quadratic elements
$$u(\xi)=u_0(3\xi+2\xi^2)+u_{1/2}(4\xi-4\xi^2)+u_1(-\xi+2\xi^2)$$
```{python}
#| output-location: column
#| eval: true
#| echo: true
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0, 1, 101)
# Plot velocity distribution.
plt.plot(x, 1-3*x+2*x**2)
plt.plot(x, 4*x-4*x**2)
plt.plot(x, -x+2*x**2)
plt.plot(0, 0, "o", color="C0", ms=8)
plt.plot(0.5, 0, "o", color="C1", ms=8)
plt.plot(1, 0, "o", color="C2", ms=8)
plt.grid()
```
## Cubic elements
<!-- $$u(\xi)=u_0(3\xi+2\xi^2)+u_{1/2}(4\xi-4\xi^2)+u_1(-\xi+2\xi^2)$$ -->
```{python}
#| output-location: column
#| eval: true
#| echo: true
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0, 1, 101)
# Plot velocity distribution.
plt.plot(x, 1-3*x**2+2*x**3)
plt.plot(x, x-2*x**2+x**3)
plt.plot(x, -x**2+x**3)
plt.plot(x, 3*x**2-2*x**3)
for i in range(4):
plt.plot(i/(3), 0, "o",
color=f"C{i}", ms=8)
plt.grid()
```
## Triangles with linear shape functions
:::: {.columns}
::: {.column width="60%"}
$$x=x_1+(x_2-x_1)\xi+(x_3-x_1)\eta$$
$$y=y_1+(y_2-y_1)\xi+(y_3-y_1)\eta$$
:::
::: {.column width="40%"}
```{python}
#| eval: true
#| echo: false
plt.fill_betweenx([1, 0], [0, 1])
plt.text(0.05, 0.05, "P1")
plt.text(1, 0.05, "P2")
plt.text(0.05, 1, "P3")
plt.xlabel(r"$\xi$")
plt.ylabel(r"$\eta$");
```
:::
::::
## Triangle
$$u(\xi)=u_1(1-\xi-\eta)+u_2\xi+u_3\eta$$
```{python}
#| output-location: column
#| eval: true
#| echo: true
import pygimli as pg
import pygimli.meshtools as mt
shape = mt.createPolygon(
[[0, 0], [1, 0],[0, 1]],
isClosed=True)
mesh = mt.createMesh(shape, area=0.01)
mx = pg.x(mesh)
my = pg.y(mesh)
# Plot velocity distribution.
fig, ax = plt.subplots()
pg.show(mesh, 1-mx-my, ax=ax,
nLevs=11, label="u");
```
<!-- ## Triangle
$$u(\xi)=u_1(1-\xi-\eta)+u_2\xi+u_3\eta$$
```{python}
#| output-location: column
#| eval: true
#| echo: true
fig, ax = plt.subplots()
pg.show(mesh, mx, ax=ax, nLevs=11);
```
## Triangle
$$u(\xi)=u_1(1-\xi-\eta)+u_2\xi+u_3\eta$$
```{python}
#| output-location: column
#| eval: true
#| echo: true
fig, ax = plt.subplots()
pg.show(mesh, my, ax=ax, nLevs=11);
```
-->
## Triangle linear shape functions
$$u(\xi)=u_1(1-\xi-\eta)+u_2\xi+u_3\eta$$
```{python}
#| eval: true
#| echo: false
fig, ax = plt.subplots(figsize=(12, 6), ncols=3, sharex=True, sharey=True)
fig.tight_layout()
pg.show(mesh, 1-mx-my, ax=ax[0], nLevs=11);
pg.show(mesh, mx, ax=ax[1], nLevs=11);
pg.show(mesh, my, ax=ax[2], nLevs=11);
```
## Verification
1. Method of Manufactured Solutions (MMS)
* manufacture a smooth u
* generate $f$ matching approximation of $u$
2. Method of Exact Solutions (MES)
* find parameters for which an analytic solution exists
3. Perform convergence tests for increasingly smaller $h$
* approximation error $E(h)\lt C h^n$ test for some $h$
## Green's functions
The Green's function $G$ is the solution for a Dirac source $\delta$
$$ \mathfrak{L} G = \delta $$
The solution can then be obtained by convolution
$$u=G*f$$