- EC317 - UNIFEI - June, 2018
More about programming than electromagnetic transients
Python + THTA + Open Source => High chances to become a good software!
Work in progress
The libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Importing the file
self.df = pd.read_csv('test.csv', header=None)
For this initial step, we shall use the .csv format
Calculate the condutance and map elements
for index, row in self.elements.iterrows():
if row[0] == 'R':
resistor = Resistor(row[3])
self.gkm[index-1] = 1/resistor.value
self.nh = self.nh + 1
elif row[0] == 'C':
capacitor = Capacitor((row[3]*1e-6))
self.gkm[index-1] = 2*capacitor.value/self.dt
self.nh = self.nh + 1
elif row[0] == 'L':
inductor = Inductor((row[3]*1e-3))
self.gkm[index-1] = self.dt/(2*inductor.value)
elif row[0] == 'EDC':
self.ndcvs = self.ndcvs + 1
Build the G matrix
self.g_matrix = np.zeros((self.elements.shape[0], self.elements.shape[0]))
for index, row in self.elements.iterrows():
k = row[1]
m = row[2]
if m == 0:
self.g_matrix[k,k] = self.g_matrix[k,k] + self.gkm[index-1]
elif k == 0:
self.g_matrix[m,m] = self.g_matrix[m,m] + self.gkm[index-1]
else:
self.g_matrix[k,k] = self.g_matrix[k,k] + self.gkm[index-1]
self.g_matrix[m,m] = self.g_matrix[m,m] + self.gkm[index-1]
self.g_matrix[k,m] = self.g_matrix[k,m] + self.gkm[index-1]
self.g_matrix[m,k] = self.g_matrix[m,k] + self.gkm[index-1]
Build the GAA and GAB matrices
d = self.nodes_qty - self.sources_qty
self.gaa = self.g_matrix[0:d, 0:d]
self.gab = self.g_matrix[0:d, d:self.nodes_qty]
self.gba = self.g_matrix[d:self.nodes_qty, 0:d]
self.gbb = self.g_matrix[d:self.nodes_qty, d:self.nodes_qty]
Simulation (see resolver.py)
CSV
T,2,1,100E-6,50E-6,0,0,0,0,0
EDC,2,0,10,0,0,0,0,0,0
R,2,1,4,0,0,0,0,0,2
C,1,0,7,0,0,0,0,0,2
R,1,0,6,0,0,0,0,0,2
NV,1,2,0,0,0,0,0,0,0
IA, IB, I
VA, VB, V
Classes and object oriented programming (work in progress)
Different languages and paradigms
"Open Source Implementations of Electromagnetic Transient Algorithms "