This repository was archived by the owner on Jul 25, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ # Add a source term:
42+ d [((x > 4.0 ) & (x < 7.5 ))] = - 5.0
43+
44+ # solve for Temperature:
45+ t = solve_tridiagonal (a , b , c , d )
46+
47+ # plot:
48+ fig = plt .figure (figsize = (10 ,10 ))
49+ ax = fig .add_subplot (111 )
50+
51+ ax .plot (x , t )
52+
53+ plotfile = 'conduction_v1.png'
54+ print ('writing : ' ,plotfile )
55+ fig .savefig (plotfile )
56+ plt .close ()
57+
58+
59+
You can’t perform that action at this time.
0 commit comments