Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Commit ce7ed8a

Browse files
committed
FEAT: 1d conduction, fixed BCs
1 parent 4411e02 commit ce7ed8a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

day_6/2023/conduction_v0.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
from tridiagonal import solve_tridiagonal
6+
7+
# ----------------------------------------------------------------------
8+
# Main code
9+
# ----------------------------------------------------------------------
10+
11+
if __name__ == "__main__":
12+
13+
dx = 0.25
14+
15+
# set x with 1 ghost cell on both sides:
16+
x = np.arange(-dx, 10 + 2 * dx, dx)
17+
18+
t_lower = 200.0
19+
t_upper = 1000.0
20+
21+
nPts = len(x)
22+
23+
# set default coefficients for the solver:
24+
a = np.zeros(nPts) + 1
25+
b = np.zeros(nPts) - 2
26+
c = np.zeros(nPts) + 1
27+
d = np.zeros(nPts)
28+
29+
# boundary conditions (bottom - fixed):
30+
a[0] = 0
31+
b[0] = 1
32+
c[0] = 0
33+
d[0] = t_lower
34+
35+
# top - fixed:
36+
a[-1] = 0
37+
b[-1] = 1
38+
c[-1] = 0
39+
d[-1] = t_upper
40+
41+
# solve for Temperature:
42+
t = solve_tridiagonal(a, b, c, d)
43+
44+
# plot:
45+
fig = plt.figure(figsize = (10,10))
46+
ax = fig.add_subplot(111)
47+
48+
ax.plot(x, t)
49+
50+
plotfile = 'conduction_v0.png'
51+
print('writing : ',plotfile)
52+
fig.savefig(plotfile)
53+
plt.close()
54+
55+
56+

0 commit comments

Comments
 (0)