-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
62 lines (54 loc) · 2.37 KB
/
run.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from core import MatrixFunctions,NetlistParser,ComponentFunctions,Solver,ComplexFunctions
import numpy as np
def Main():
print("#"*80)
print("Trabalho de Circuitos Elétricos 2\nAluno Gabriel Parracho dos Santos Leal\nProfessora Fernanda Duarte Vilela Reis de Oliveira")
print("#"*80)
filename=str(input('Insira o nome da netlist a ser analisada (incluindo o .txt): '))
print("#"*80)
#opening file
fileNetlist = NetlistParser.openNetlist(filename)
#creating empty matrix and vector
GmMatrix=MatrixFunctions.makeMatrix(NetlistParser.checkNumberOfNodes(filename))
IVector=MatrixFunctions.makeIVector(NetlistParser.checkNumberOfNodes(filename))
#checking system type trying to get freq
freq=ComplexFunctions.getFreq(fileNetlist)
if freq == None:
operationType = 1
else:
operationType = 2
if operationType == 1: # no frequency components
#adding components
GmMatrix=ComponentFunctions.addResistor(GmMatrix,fileNetlist)
GmMatrix=ComponentFunctions.addCurrentSourceVcontrolled(GmMatrix,fileNetlist)
IVector=ComponentFunctions.addCurrentSource(IVector,fileNetlist)
#fixing ground
GmMatrix,IVector =MatrixFunctions.fixGround(GmMatrix,IVector)
#solving the system
EMatrix= Solver.solveSystem(GmMatrix,IVector)
elif operationType == 2:
#adding passive components
GmMatrix=ComponentFunctions.addResistor(GmMatrix,fileNetlist)
GmMatrix=ComponentFunctions.addCurrentSourceVcontrolled(GmMatrix,fileNetlist)
IVector=ComponentFunctions.addCurrentSource(IVector,fileNetlist)
#adding reactive components
IVector=ComplexFunctions.addSinCurrentSource(IVector,fileNetlist)
GmMatrix=ComplexFunctions.addInductor(GmMatrix,fileNetlist,freq)
GmMatrix=ComplexFunctions.addCapacitor(GmMatrix,fileNetlist,freq)
GmMatrix=ComplexFunctions.addTransformer(GmMatrix,fileNetlist,freq)
#fixing ground
GmMatrix,IVector =MatrixFunctions.fixGround(GmMatrix,IVector)
#solving the system
EMatrix= Solver.solveSystem(GmMatrix,IVector)
#Matrix printing
print("\nGm Matrix:")
print(np.array(GmMatrix),"\n")
print("-"*80)
# print(GmMatrix)
print("I Vector: ")
print(np.array(IVector), "\n")
print("-"*80)
print("e Array: ")
print(np.array(EMatrix), "\n")
print("-"*80)
Main()