Commit ca56b5a9 by martin.moraga

### improve nv_powerflow_cim

parent 27f10b60
 import numpy as np import math from network import Ymatrix_calc from network import BusType def Ymatrix_calc(system): nodes_num = len(system.nodes) branches_num = len(system.branches) Ymatrix = np.zeros((nodes_num, nodes_num),dtype=np.complex) Adjacencies = [[] for _ in range(nodes_num)] for index in range(branches_num): fr = system.branches[index].start_node.index to = system.branches[index].end_node.index Ymatrix[fr][to] -= system.branches[index].y Ymatrix[to][fr] -= system.branches[index].y Ymatrix[fr][fr] += system.branches[index].y Ymatrix[to][to] += system.branches[index].y Adjacencies[fr].append(to+1) Adjacencies[to].append(fr+1) return Ymatrix, Adjacencies class Results(): def __init__(self): self.V = [] self.I = [] self.Iinj = [] self.S1 = [] self.S2 = [] self.SInj = [] self.num_iter = [] def solve(system): """It performs Power Flow by using rectangular node voltage state variables.""" ... ... @@ -132,4 +128,56 @@ def solve(system): S1=np.append(S1, V[system.branches[i].start_node.index]*(I_conj[i])) S2=np.append(S2, -V[system.branches[i].end_node.index]*(I_conj[i])) return V, I, Iinj, S1, S2, Sinj, num_iter \ No newline at end of file return V, I, Iinj, S1, S2, Sinj, num_iter def calculateI(network, V): """ To calculate the branch currents """ I = np.zeros((len(system.branches)), dtype=np.complex) for idx in range(branches_num): fr = system.branches[idx].start_node.index to = system.branches[idx].end_node.index I[idx] = - (V[fr] - V[to])*Ymatrix[fr][to] def calculateInj(network, I): """ To calculate current injections at a node """ Iinj = np.zeros((len(system.nodes)), dtype=np.complex) for k in range(0, (len(system.nodes))): to=[] fr=[] for m in range(len(system.branches)): if k==system.branches[m].start_node.index: fr.append(m) if k==system.branches[m].end_node.index: to.append(m) Iinj = np.sum(I[to]) - np.sum(I[fr]) return Iinj def calculateS1(system, V, I): """ To calculate powerflow on branches """ S1 = np.zeros((len(system.branches)), dtype=np.complex) for i in range(0, len(system.branches)): S1 = np.append(S1, V[system.branches[i].start_node.index]*(np.conj(I[i]))) return S1 def calculateS2(): """ To calculate powerflow on branches """ S2 = np.zeros((len(system.branches)), dtype=np.complex) for i in range(0, len(system.branches)): S2 = np.append(S2, -V[system.branches[i].end_node.index]*(I_conj[i])) return S2 def calculateSinj(V, Iinj): """ To calculate power injection at a node """ Sinj = np.multiply(V, np.conj(Iinj)) return Sinj \ No newline at end of file