Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/tespy/connections/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,29 +1507,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.
Expand Down
53 changes: 0 additions & 53 deletions src/tespy/connections/powerconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 0 additions & 56 deletions src/tespy/networks/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down