-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60e6b3b
commit b939b0b
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
... Ertekin/Unit 5 Finite-Difference Approximation to Linear-Flow Equations/tdma_implicit.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Tri Diagonal Matrix Algorithm(a.k.a Thomas algorithm) solver | ||
def TDMAsolver(a, b, c, d): | ||
''' | ||
TDMA solver, a b c d can be NumPy array type or Python list type. | ||
solving tridiagonal matrix for implicit (backward-difference) method | ||
''' | ||
import numpy as np | ||
nf = len(d) # number of equations | ||
ac, bc, cc, dc = map(np.array, (a, b, c, d)) # copy arrays | ||
for it in range(1, nf): | ||
mc = ac[it-1]/bc[it-1] | ||
bc[it] = bc[it] - mc*cc[it-1] | ||
dc[it] = dc[it] - mc*dc[it-1] | ||
|
||
xc = bc | ||
xc[-1] = dc[-1]/bc[-1] | ||
|
||
for il in range(nf-2, -1, -1): | ||
xc[il] = (dc[il]-cc[il]*xc[il+1])/bc[il] | ||
|
||
return(xc) |