Created
October 25, 2018 12:21
-
-
Save linnil1/ddd94835d73a66646a061374a6d495c9 to your computer and use it in GitHub Desktop.
Heat Transfer mini program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
s = [10, 10] | |
grid = np.zeros(s) | |
esp = 1e-3 | |
def init(): | |
grid[:, :] = 650/4 | |
def setBound(): | |
grid[0, :] = 50 | |
grid[:, -1] = 100 | |
grid[-1, :] = 200 | |
grid[:, 0] = 300 | |
# main | |
init() | |
setBound() | |
it = 0 | |
while True: | |
it += 1 | |
print(it) | |
oldgrid = grid.copy() | |
grid = np.mean([ | |
np.roll(grid, 1, axis=0), | |
np.roll(grid, 1, axis=1), | |
np.roll(grid, -1, axis=0), | |
np.roll(grid, -1, axis=1)], axis=0) | |
setBound() | |
# print(grid) | |
if not (np.abs(grid - oldgrid) > esp).any(): | |
break | |
X, Y = np.meshgrid(np.arange(s[0]), np.arange(s[1])) | |
# plt.contourf(X, Y, grid, 10) | |
cont = plt.contour(X, Y, grid, 10) | |
plt.clabel(cont) | |
plt.xticks([]) | |
plt.yticks([]) | |
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, | |
hspace=0, wspace=0) | |
plt.show() |
Author
linnil1
commented
Oct 25, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment