Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
lehrkraefte:snr:informatik:glf4-23:waermeleitung [2024/05/01 09:03] Olaf Schnürer created |
lehrkraefte:snr:informatik:glf4-23:waermeleitung [2024/05/15 16:52] (current) Olaf Schnürer [Wärmeleitungsgleichung simulieren] |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~NOTOC~~ | ||
+ | |||
+ | Falls numpy etc. auf Schulrechnern nicht verfügbar: | ||
+ | |||
+ | https:// | ||
+ | |||
====== Wärmeleitungsgleichung simulieren ====== | ====== Wärmeleitungsgleichung simulieren ====== | ||
+ | Die Mathematik und Formeln für die Iteration sind hier noch nicht dokumentiert (bisher an Tafel erklärt). | ||
+ | Wärmeleitungsgleichung $u_{t}=\Delta u$. | ||
+ | |||
+ | ===== Numpy und Matplotlib: einige Befehle kennenlernen (und eventuell Bibliotheken installieren) ===== | ||
+ | |||
+ | <hidden Bitte Programm ausklappen> | ||
<code python beispiel-fuer-die-verwendung-von-numpy-und-matplotlib.py> | <code python beispiel-fuer-die-verwendung-von-numpy-und-matplotlib.py> | ||
import numpy as np | import numpy as np | ||
Line 29: | Line 41: | ||
plt.show() | plt.show() | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Wärmeausbreitung (1-dimensional) in einem Stab simulieren ===== | ||
+ | |||
+ | {{: | ||
+ | <hidden Bitte Programm ausklappen> | ||
<code python waermeleitung-1d-ort-zeit-diagramm-vorlage.py> | <code python waermeleitung-1d-ort-zeit-diagramm-vorlage.py> | ||
Line 77: | Line 96: | ||
plt.show() | plt.show() | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Beispiel zum Erstellen einer animierten gif-Datei (= kleiner Film) ===== | ||
+ | |||
+ | <hidden Bitte Programm ausklappen> | ||
+ | <code python beispiel-fuer-2d-gif-animation.py> | ||
+ | import numpy as np | ||
+ | from matplotlib import pyplot as plt | ||
+ | from matplotlib import colormaps | ||
+ | import matplotlib.animation as animation | ||
+ | from matplotlib.animation import FuncAnimation | ||
+ | |||
+ | # Grösse des quadratischen Feldes | ||
+ | n = 30 | ||
+ | # Anzahl der Iterationen | ||
+ | iterationen = 40 | ||
+ | |||
+ | # Dreidimensionale Tabelle (Array), erste Koordinate Iterationsnummer (oft = Zeit), zweite Koordinate Zeile, dritte Koordinate Spalte. | ||
+ | u = np.zeros((iterationen + 1, n, n)) | ||
+ | |||
+ | # Temperaturverteilung am Anfang | ||
+ | u[0, 5, 9] = 100 | ||
+ | u[0, 5, 10] = 100 | ||
+ | u[0, 5, n - 10] = 100 | ||
+ | u[0, 5, n - 9] = 100 | ||
+ | |||
+ | # Start der Simulation, i für Iterationsnummer, | ||
+ | for i in range(1, iterationen + 1): | ||
+ | for z in range(1, n - 1): | ||
+ | for s in range(1, n - 1): | ||
+ | u[i, z, s] = (u[i - 1, z - 1, s - 1] + u[i - 1, z - 1, s + 1]) / 2 | ||
+ | |||
+ | def animiere(i): | ||
+ | print(i) | ||
+ | plt.clf() | ||
+ | plt.title(f" | ||
+ | plt.xlabel(" | ||
+ | plt.ylabel(" | ||
+ | plt.pcolormesh(u[i, | ||
+ | plt.colorbar() | ||
+ | # plt.show() | ||
+ | |||
+ | anim = animation.FuncAnimation(plt.figure(), | ||
+ | anim.save(" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Wärmeausbreitung 2-dimensional, | ||
+ | |||
+ | Zum Spass ist am Anfang noch eine Wärmeblase mitten im Raum... | ||
+ | |||
+ | {{: | ||
+ | |||
+ | <hidden Bitte Programm ausklappen> | ||
<code python waermeleitung-2d-gif-animation-vorlage.py> | <code python waermeleitung-2d-gif-animation-vorlage.py> | ||
Line 129: | Line 202: | ||
anim.save(" | anim.save(" | ||
</ | </ | ||
+ | </ | ||
- | <code python > | ||
- | </ | ||