diff --git a/examples/run_power_flow.py b/examples/run_power_flow.py index 68b5def..da6052b 100644 --- a/examples/run_power_flow.py +++ b/examples/run_power_flow.py @@ -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): @@ -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) \ No newline at end of file +print(results["node"]) diff --git a/src/pgm_service/power_grid/cgmes_pgm_converter.py b/src/pgm_service/power_grid/cgmes_pgm_converter.py index 1bb0738..d45db7d 100644 --- a/src/pgm_service/power_grid/cgmes_pgm_converter.py +++ b/src/pgm_service/power_grid/cgmes_pgm_converter.py @@ -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): """ @@ -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: @@ -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)) @@ -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 @@ -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}