# 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 fix bugs
• Stable environment
• Easy to set up

# PyTHTA

Python + THTA + Open Source => High chances to become a good software!

Work in progress

# PyTHTA Stages

1. Replicate the basic THTA features
2. Organise the code
3. Plot charts
5. Create a full library

# PyTHTA Stages

1. Replicate the basic THTA features
2. Organise the code (Under development)
3. Plot charts
5. Create a full library

# PyTHTA Stages

1. Replicate the basic THTA features

The libraries

``````import pandas as pd
import numpy as np
import matplotlib.pyplot as plt``````

# PyTHTA Stages

1. 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

1. Replicate the basic THTA features

Calculate the condutance and map elements

``````for index, row in self.elements.iterrows():
if row == 'R':
resistor = Resistor(row)
self.gkm[index-1] = 1/resistor.value
self.nh = self.nh + 1
elif row == 'C':
capacitor = Capacitor((row*1e-6))
self.gkm[index-1] = 2*capacitor.value/self.dt
self.nh = self.nh + 1
elif row == 'L':
inductor = Inductor((row*1e-3))
self.gkm[index-1] = self.dt/(2*inductor.value)
elif row == 'EDC':
self.ndcvs = self.ndcvs + 1``````

# PyTHTA Stages

1. Replicate the basic THTA features

Build the G matrix

``````self.g_matrix = np.zeros((self.elements.shape, self.elements.shape))
for index, row in self.elements.iterrows():
k = row
m = row
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

1. 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

1. 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

``````

IA, IB, I

VA, VB, V

# What is not (yet) included in this version

1. Switches, non linear elements, current sources
2. Charts
3. Edge cases
4. Automated Tests

# PyTHTA Stages

1. Replicate the basic THTA features
2. Organise the code (Under development)

Classes and object oriented programming (work in progress)

# Article

"Open Source Implementations of Electromagnetic Transient Algorithms "

#### PyTHTA

By Hanneli Tavante (hannelita)

• 934