-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvert.py
31 lines (25 loc) · 947 Bytes
/
Invert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy
import math
"""
Invert matrix in 1D mdoel
Developed by Mohsen Moradi and Amir A. Aliabadi
Atmospheric Innovations Research (AIR) Laboratory, University of Guelph, Guelph, Canada
Last update: July 2020
Originally developed by Alberto Martilli, Scott Krayenhoff, and Negin Nazarian
"""
# This class is used to invert and resolve a tri-diagonal matrix
class Invert:
def __init__(self,nz,A,RHS):
self.nz = nz
self.A = A
self.RHS = RHS
def Output(self):
X = numpy.zeros(self.nz)
for i in range(self.nz-2,-1,-1):
self.RHS[i] = self.RHS[i]-self.A[i][2]*self.RHS[i+1]/self.A[i+1][1]
self.A[i][1] = self.A[i][1]-self.A[i][2]*self.A[i+1][0]/self.A[i+1][1]
for i in range(1,self.nz):
self.RHS[i] = self.RHS[i]-self.A[i][0]*self.RHS[i-1]/self.A[i-1][1]
for i in range(0,self.nz):
X[i] = self.RHS[i]/self.A[i][1]
return X