Skip to content

Commit

Permalink
convert sources + calculate
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Salemink <[email protected]>
  • Loading branch information
petersalemink95 committed Nov 9, 2023
1 parent d401744 commit 2d1370d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/run_power_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from src.pgm_service.power_grid.cgmes_pgm_converter import System

from power_grid_model import PowerGridModel

logging.basicConfig(filename='run_powerflow.log', level=logging.INFO, filemode='w')

def download_grid_data(name, url):
Expand Down Expand Up @@ -42,5 +44,9 @@ def download_grid_data(name, url):
system = System()
system.load_cim_data(res)
pgm_input = system.create_pgm_input()
print(pgm_input)

pgm = PowerGridModel(input_data=pgm_input)
results = pgm.calculate_power_flow()

print(pgm_input)
print(results["node"])
36 changes: 34 additions & 2 deletions src/pgm_service/power_grid/cgmes_pgm_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@


FREQUENCY = 50.0

DEFAULT_SOURCE_SHORT_CIRCUIT_POWER = 1e20

class System():
def __init__(self):
self.nodes = []
self.voltages = []
self.lines = {}
self.sources = {}

def load_cim_data(self, res):
"""
Expand All @@ -32,6 +33,7 @@ def load_cim_data(self, res):
# elem.ConductingEquipment.__class__.__name__ == "EnergySource"]
# list_Terminals_EC = [elem for elem in list_Terminals if
# elem.ConductingEquipment.__class__.__name__ == "EnergyConsumer"]
list_Source = [elem for elem in res['topology'].values() if elem.__class__.__name__ == "ExternalNetworkInjection"]

# create nodes
for TPNode in list_TPNode:
Expand All @@ -54,6 +56,15 @@ def load_cim_data(self, res):
"tan1": ACLineSegment.gch / ACLineSegment.bch}
# TODO: check if there is a multiplier for r1/x1, c1, tan1, i_n

for source in list_Source:
connected_node = self._get_node(list_Terminals, source.mRID)
node_id = next(iter(connected_node))
status = connected_node[node_id]
self.sources[source.mRID] = {"node": self.nodes.index(node_id),
"status": status,
"u_ref": 1.0,
"sk": DEFAULT_SOURCE_SHORT_CIRCUIT_POWER}

def create_pgm_input(self):
id_counter = 0
node = initialize_array("input", "node", len(self.nodes))
Expand All @@ -71,9 +82,18 @@ def create_pgm_input(self):
line["x1"] = [line_param["x1"] for line_param in self.lines.values()]
line["c1"] = [line_param["c1"] for line_param in self.lines.values()]
line["tan1"] = [line_param["tan1"] for line_param in self.lines.values()]
id_counter += len(self.lines)

source = initialize_array("input", "source", len(self.sources))
source["id"] = range(id_counter, id_counter + len(self.sources))
source["node"] = [source_param["node"] for source_param in self.sources.values()]
source["status"] = [source_param["status"] for source_param in self.sources.values()]
source["u_ref"] = [source_param["u_ref"] for source_param in self.sources.values()]
source["sk"] = [source_param["sk"] for source_param in self.sources.values()]

return {"node": node,
"line": line}
"line": line,
"source": source}

def _get_nodes(self, list_Terminals, elem_uuid):
start_node_uuid = None
Expand All @@ -94,3 +114,15 @@ def _get_nodes(self, list_Terminals, elem_uuid):


return {start_node_uuid: start_node_connected, end_node_uuid: end_node_connected}

def _get_node(self, list_Terminals, elem_uuid):
node_uuid = None
node_connected = None

for terminal in list_Terminals:
if terminal.ConductingEquipment.mRID != elem_uuid:
continue
node_uuid = terminal.TopologicalNode.mRID
node_connected = terminal.connected

return {node_uuid: node_connected}

0 comments on commit 2d1370d

Please sign in to comment.