PyTHTA
- EC317 - UNIFEI - June, 2018
DISCLAIMER
More about programming than electromagnetic transients
Agenda
- Why Python?
- Developing good software
- PyTHTA
- Future works
Python
- Very popular in science and engineering
- Easy to use and prototype
- Lots of libraries
- Open Source
Good software
- Easy to maintain
- Easy to add features
- Easy to fix bugs
- Stable environment
- Easy to set up
Open source software has a good chance to become good software
PyTHTA
Python + THTA + Open Source => High chances to become a good software!
Work in progress
PyTHTA Stages
- Replicate the basic THTA features
- Organise the code
- Plot charts
- Replicate advanced THTA features
- Create a full library
PyTHTA Stages
- Replicate the basic THTA features
- Organise the code (Under development)
- Plot charts
- Replicate advanced THTA features
- Create a full library
PyTHTA Stages
- Replicate the basic THTA features
The libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
PyTHTA Stages
- Replicate the basic THTA features
Importing the file
self.df = pd.read_csv('test.csv', header=None)
For this initial step, we shall use the .csv format
PyTHTA Stages
- Replicate the basic THTA features
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
PyTHTA Stages
- Replicate the basic THTA features
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]
PyTHTA Stages
- Replicate the basic THTA features
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]
PyTHTA Stages
- Replicate the basic THTA features
Simulation (see resolver.py)
Example
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
G matrix
IA, IB, I
VA, VB, V
What is not (yet) included in this version
- Switches, non linear elements, current sources
- Charts
- Edge cases
- Automated Tests
PyTHTA Stages
- Replicate the basic THTA features
- Organise the code (Under development)
Classes and object oriented programming (work in progress)
Future work
Different languages and paradigms
Article
"Open Source Implementations of Electromagnetic Transient Algorithms "
PyTHTA
By Hanneli Tavante (hannelita)
PyTHTA
- 1,613