Commit f005ca76 authored by martin.moraga's avatar martin.moraga
Browse files

fixed some errors in the last commit

parent 9bb92f9b
__all__ = ["bc_powerflow", "bc_state_estimator", "nv_powerflow", "nv_state_estimator", "network", "nv_powerflow_cim"]
\ No newline at end of file
__all__ = ["bc_powerflow", "bc_state_estimator", "nv_powerflow", "nv_state_estimator", "network", "nv_powerflow_cim", "results"]
\ No newline at end of file
......@@ -84,13 +84,8 @@ class System():
for uuid, element in res.items():
if element.__class__.__name__=="ACLineSegment":
length=element.length
if length==0.0:
length=1.0
bR = element.r*length
bX = element.x*length
self.bR.append(bR)
self.bX.append(bX)
self.bR.append(element.r)
self.bX.append(element.x)
for node in self.nodes:
if element.startNodeID==node.uuid:
startNode = node
......@@ -101,8 +96,10 @@ class System():
break
base_voltage = element.BaseVoltage.nominalVoltage
self.branches.append(Branch(bR, bX, startNode, endNode, base_voltage, base_apparent_power))
self.branches.append(Branch(r=element.r, x=element.x, start_node=startNode,
end_node=endNode, base_voltage=base_voltage,
base_apparent_power=base_apparent_power))
elif element.__class__.__name__=="PowerTransformer":
bR = element.primaryConnection.r
bX = element.primaryConnection.x
......@@ -119,7 +116,8 @@ class System():
#base voltage = high voltage side (=primaryConnection)
base_voltage = element.primaryConnection.BaseVoltage.nominalVoltage
self.branches.append(Branch(bR, bX, startNode, endNode, base_voltage, base_apparent_power))
self.branches.append(Branch(r=bR, x=bX, start_node=startNode, end_node=endNode,
base_voltage=base_voltage, base_apparent_power=base_apparent_power))
else:
continue
......@@ -147,10 +145,10 @@ class System():
for branch in self.branches:
fr = branch.start_node.index
to = branch.end_node.index
self.Ymatrix[fr][to] -= branch.y
self.Ymatrix[to][fr] -= branch.y
self.Ymatrix[fr][fr] += branch.y
self.Ymatrix[to][to] += branch.y
self.Ymatrix[fr][to] -= branch.y_pu
self.Ymatrix[to][fr] -= branch.y_pu
self.Ymatrix[fr][fr] += branch.y_pu
self.Ymatrix[to][to] += branch.y_pu
self.Adjacencies[fr].append(to+1) #to + 1???
self.Adjacencies[to].append(fr+1) #fr + 1???
......
import sys
import math
import numpy as np
from network import BusType
import results
from .network import BusType
from .results import Results
def solve(system):
"""It performs Power Flow by using rectangular node voltage state variables."""
......@@ -19,8 +19,8 @@ def solve(system):
i2 = i + nodes_num
type = system.nodes[i].type
if type is BusType.SLACK:
z[m] = np.real(system.nodes[i].voltage)
z[m+1] = np.imag(system.nodes[i].voltage)
z[m] = np.real(system.nodes[i].voltage_pu)
z[m+1] = np.imag(system.nodes[i].voltage_pu)
H[m][i] = 1
H[m+1][i2] = 1
elif type is BusType.PQ:
......@@ -61,12 +61,12 @@ def solve(system):
h[m] = np.inner(H[m],State)
h[m+1] = np.inner(H[m+1],State)
elif type is BusType.PQ:
z[m] = (np.real(system.nodes[i].power)*np.real(V[i]) + np.imag(system.nodes[i].power)*np.imag(V[i]))/(np.abs(V[i])**2)
z[m+1] = (np.real(system.nodes[i].power)*np.imag(V[i]) - np.imag(system.nodes[i].power)*np.real(V[i]))/(np.abs(V[i])**2)
z[m] = (np.real(system.nodes[i].power_pu)*np.real(V[i]) + np.imag(system.nodes[i].power_pu)*np.imag(V[i]))/(np.abs(V[i])**2)
z[m+1] = (np.real(system.nodes[i].power_pu)*np.imag(V[i]) - np.imag(system.nodes[i].power_pu)*np.real(V[i]))/(np.abs(V[i])**2)
h[m] = np.inner(H[m],State)
h[m+1] = np.inner(H[m+1],State)
elif type is BusType.PV:
z[m] = (np.real(system.nodes[i].power)*np.real(V[i])+ np.imag(system.nodes[i].power)*np.imag(V[i]))(np.abs(V[i])**2)
z[m] = (np.real(system.nodes[i].power_pu)*np.real(V[i])+ np.imag(system.nodes[i].power_pu)*np.imag(V[i]))(np.abs(V[i])**2)
h[m] = np.inner(H[m],State)
h[m+1] = np.abs(V[i])
H[m+1][i] = np.cos(np.angle(V[i]))
......@@ -82,7 +82,7 @@ def solve(system):
num_iter = num_iter+1
# calculate all the other quantities of the grid
powerflow_results = results.Results(system)
powerflow_results = Results(system)
powerflow_results.load_voltages(V)
powerflow_results.calculate_all()
......
import numpy as np
import cmath
import sys
sys.path.append("../../../dataprocessing")
from villas.dataprocessing.readtools import *
from villas.dataprocessing.readtools import read_timeseries_dpsim
class ResultsNode():
def __init__(self, topo_node):
......@@ -190,4 +188,4 @@ class Results():
for test purposes
"""
for node in self.nodes:
print(node.topology_node.uuid + ": " + str(cmath.polar(node.voltage)))
\ No newline at end of file
print(node.topology_node.uuid + " = " + str(cmath.polar(node.voltage)))
\ No newline at end of file
import sys
import logging
sys.path.append("../../acs/state_estimation")
import network
import nv_powerflow_cim
sys.path.append("../../../cimpy")
from acs.state_estimation import network
from acs.state_estimation import nv_powerflow_cim
import cimpy
logging.basicConfig(filename='CIGRE.log', level=logging.INFO, filemode='w')
......@@ -19,24 +15,13 @@ cim_xml_files=[cim_xml_path + r"\Rootnet_FULL_NE_06J16h_DI.xml",
#read cim files and create new network.Systen object
res=cimpy.cimread(cim_xml_files)
system = network.System()
system.load_cim_data(res, 20)
#print node voltages
for node in system.nodes:
print('{}={}'.format(node.uuid, node.voltage))
print()
#print node powers
for node in system.nodes:
print('{}={}'.format(node.uuid, node.power))
base_apparent_power = 25 #MW
system.load_cim_data(res, base_apparent_power)
#Execute power flow analysis
results, num_iter_cim = nv_powerflow_cim.solve(system)
print()
print("voltages:")
#print node voltages
print("results.voltages (pu): ")
for node in results.nodes:
print('{}={}'.format(node.topology_node.uuid, node.voltage))
#results.print_voltages_polar()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment