Skip to content

Instantly share code, notes, and snippets.

@linnil1
Created October 25, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linnil1/ddd94835d73a66646a061374a6d495c9 to your computer and use it in GitHub Desktop.
Save linnil1/ddd94835d73a66646a061374a6d495c9 to your computer and use it in GitHub Desktop.
Heat Transfer mini program
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()
@linnil1
Copy link
Author

linnil1 commented Oct 25, 2018

heat_grid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment