From 0f854065ed0ebddb3b09e82168b0e2b108c51312 Mon Sep 17 00:00:00 2001 From: Francesco Witte Date: Sat, 2 Aug 2025 08:05:04 +0200 Subject: [PATCH] Remove the to_exerpy methods from tespy --- src/tespy/connections/connection.py | 23 ---------- src/tespy/connections/powerconnection.py | 53 ---------------------- src/tespy/networks/network.py | 56 ------------------------ 3 files changed, 132 deletions(-) diff --git a/src/tespy/connections/connection.py b/src/tespy/connections/connection.py index 4600a4d28..64d1ae922 100644 --- a/src/tespy/connections/connection.py +++ b/src/tespy/connections/connection.py @@ -1506,29 +1506,6 @@ def _property_range_message(self, prop): ) return msg - def _to_exerpy(self, pamb, Tamb): - connection_json = {} - - self._get_physical_exergy(pamb, Tamb) - - connection_json[self.label] = { - "source_component": self.source.label, - "source_connector": int(self.source_id.removeprefix("out")) - 1, - "target_component": self.target.label, - "target_connector": int(self.target_id.removeprefix("in")) - 1 - } - connection_json[self.label].update({f"mass_composition": self.fluid.val}) - connection_json[self.label].update({"kind": "material"}) - for param in ["m", "T", "p", "h", "s", "v"]: - connection_json[self.label].update({ - param: self.get_attr(param).val_SI - }) - connection_json[self.label].update( - {"e_T": self.ex_therm, "e_M": self.ex_mech, "e_PH": self.ex_physical} - ) - - return connection_json - def _get_physical_exergy(self, pamb, Tamb): r""" Get the value of a connection's specific physical exergy. diff --git a/src/tespy/connections/powerconnection.py b/src/tespy/connections/powerconnection.py index 1b0fd1058..f68f0b9fb 100644 --- a/src/tespy/connections/powerconnection.py +++ b/src/tespy/connections/powerconnection.py @@ -198,56 +198,3 @@ def _deserialize(self, data, all_connections): container.set_attr(**data[arg]) else: self.set_attr(**{arg: data[arg]}) - - def _to_exerpy(self, pamb, Tamb): - connection_json = {} - - if self.source.__class__.__name__ in ["Motor", "Generator"]: - source_connector = 0 - elif self.source.__class__.__name__ in ["Turbine"]: - source_connector = 1 - elif self.source.__class__.__name__ in ["SimpleHeatExchanger"]: - source_connector = 1 - elif self.source.__class__.__name__ in ["PowerBus"]: - if self.source_id.startswith("power_out"): - s_id = self.source_id.removeprefix("power_out") - source_connector = 0 if s_id == "" else int(s_id) - 1 - elif self.source_id.startswith("power_in"): - s_id = self.source_id.removeprefix("power_in") - source_connector = 0 if s_id == "" else int(s_id) - 1 - else: - source_connector = 999 - - if self.target.__class__.__name__ in ["Motor", "Generator"]: - target_connector = 0 - elif self.target.__class__.__name__ in ["Compressor", "Pump"]: - target_connector = 1 - elif self.target.__class__.__name__ in ["SimpleHeatExchanger"]: - target_connector = 1 - elif self.target.__class__.__name__ in ["PowerBus"]: - if self.target_id.startswith("power_in"): - t_id = self.target_id.removeprefix("power_in") - target_connector = 0 if t_id == "" else int(t_id) - 1 - elif self.target_id.startswith("power_out"): - t_id = self.target_id.removeprefix("power_out") - target_connector = 0 if t_id == "" else int(t_id) - 1 - else: - target_connector = 999 - - connection_json[self.label] = { - "source_component": self.source.label, - "source_connector": source_connector, - "target_component": self.target.label, - "target_connector": target_connector - } - if self.source_id == "heat" or self.target_id == "heat": - kind = "heat" - else: - kind = "power" - - connection_json[self.label].update({ - "kind": kind, - "energy_flow": self.E.val_SI - }) - - return connection_json \ No newline at end of file diff --git a/src/tespy/networks/network.py b/src/tespy/networks/network.py index b642d720b..b875fa290 100644 --- a/src/tespy/networks/network.py +++ b/src/tespy/networks/network.py @@ -3518,62 +3518,6 @@ def export(self, json_file_path=None): return export - def to_exerpy(self, Tamb, pamb, exerpy_mappings): - """Export the network to exerpy - - Parameters - ---------- - Tamb : float - Ambient temperature. - pamb : float - Ambient pressure. - exerpy_mappings : dict - Mappings for tespy components to exerpy components - - Returns - ------- - dict - exerpy compatible input dictionary - """ - component_results = self._save_components() - component_json = {} - for comp_type in self.comps["comp_type"].unique(): - if comp_type not in exerpy_mappings.keys(): - msg = f"Component class {comp_type} not available in exerpy." - logger.warning(msg) - continue - - key = exerpy_mappings[comp_type] - if key not in component_json: - component_json[key] = {} - - result = component_results[comp_type].dropna(axis=1) - - for c in self.comps.loc[self.comps["comp_type"] == comp_type, "object"]: - parameters = {} - if c.label in result.index and not result.loc[c.label].dropna().empty: - parameters = result.loc[c.label].dropna().to_dict() - component_json[key][c.label] = { - "name": c.label, - "type": comp_type, - "parameters": parameters - } - - connection_json = {} - for c in self.conns["object"]: - connection_json.update(c._to_exerpy(pamb, Tamb)) - - return { - "components": component_json, - "connections": connection_json, - "ambient_conditions": { - "Tamb": Tamb, - "Tamb_unit": "K", - "pamb": pamb, - "pamb_unit": "Pa" - } - } - def save(self, json_file_path): r""" Dump the results to a json style output.