Organizational Entities and financial flows between them#21
Organizational Entities and financial flows between them#21jimrojerTNO wants to merge 10 commits intomainfrom
Conversation
…rier at every port in the network and instantiating the required revenue and cost variables
… we need to give it the correct sign
… now add variables and constriants for computing the profit on owner level
|
@jimrojerTNO create some comment block in creating revenue variables in financial mixin. Afterwards review Femke/Kobus |
FJanssen-TNO
left a comment
There was a problem hiding this comment.
I've commented some suggestion on how to generalise/improve the code, to speed it up and make less copies of code due to different commodities.
Maybe we should discuss this.
src/mesido/esdl/esdl_heat_model.py
Outdated
| ids = dict() | ||
| try: | ||
| carrier = asset.global_properties["carriers"][asset.in_ports[0].carrier.id] | ||
| id_number = carrier["id_number_mapping"] | ||
| port = f"{carrier['type'].capitalize()}In" | ||
| ids[port] = dict(carrier_id=id_number) | ||
| carrier = asset.global_properties["carriers"][asset.out_ports[0].carrier.id] | ||
| id_number = carrier["id_number_mapping"] | ||
| port = f"{carrier['type'].capitalize()}Out" | ||
| ids[port] = dict(carrier_id=id_number) | ||
| except: | ||
| try: | ||
| carrier = asset.global_properties["carriers"][asset.in_ports[0].carrier.id] | ||
| id_number = carrier["id_number_mapping"] | ||
| port = f"{carrier['type'].capitalize()}In" | ||
| ids[port] = dict(carrier_id=id_number) | ||
| except: | ||
| carrier = asset.global_properties["carriers"][asset.out_ports[0].carrier.id] | ||
| id_number = carrier["id_number_mapping"] | ||
| port = f"{carrier['type'].capitalize()}Out" | ||
| ids[port] = dict(carrier_id=id_number) | ||
| return ids |
There was a problem hiding this comment.
Add option for three ports (e.g. A/W HP with electric connection)
| else: | ||
| ids = dict() | ||
| for k in range(0, n): | ||
| try: | ||
| carrier = asset.global_properties["carriers"][asset.in_ports[0].carrier.id] | ||
| id_number = carrier["id_number_mapping"] | ||
| port = f"{carrier['type'].capitalize()}Conn[{k+1}]" | ||
| ids[port] = dict(carrier_id=id_number) | ||
| except: | ||
| pass | ||
| try: | ||
| carrier = asset.global_properties["carriers"][asset.out_ports[0].carrier.id] | ||
| id_number = carrier["id_number_mapping"] | ||
| port = f"{carrier['type'].capitalize()}Conn[{k+1}]" | ||
| ids[port] = dict(carrier_id=id_number) | ||
| except: | ||
| pass | ||
| return ids |
There was a problem hiding this comment.
remove as node carrier ids are set differently
| # This is something extra I created. It is a nested list in the form of: | ||
| # [[asset1.HeatIn, asset2.HeatOut], [asset3.HeatIn, asset4.HeatOut], ...] | ||
| conn = self.get_connections() |
There was a problem hiding this comment.
Instead of this list, you could potentially create a dict:
{"asset1.HeatIn": "asset2.HeatOut",
"asset3.HeatIn": "asset4.HeatOut"], ...
There was a problem hiding this comment.
and create asset_con_dict = {"asset1": ["asset2"], "asset3": ["asset4", "asset5"]}
which just states the asset and to which it conects, can be deducted from previous list/dict.
There was a problem hiding this comment.
and a dict listing the asset ports for each asset:
asset_port_dict = {"asset1": [HeatIn, HeatOut], "asset2": ["HeatIn", "HeatOut"], "asset3": ["Primary.HeatIn", "Primary.HeatOut", "Secondary.HeatIn", "Secondary.HeatOut"], ....}
| for asset in assets: | ||
| # This is something extra I created. It is a nested list in the form of: | ||
| # [[asset1.HeatIn, asset2.HeatOut], [asset3.HeatIn, asset4.HeatOut], ...] | ||
| conn = self.get_connections() |
There was a problem hiding this comment.
This line could be before the assets loop
src/mesido/financial_mixin.py
Outdated
| for connection in conn: | ||
| # Here we check if our asset is in the connection hence we find a connected asset | ||
| if asset == connection[0].split(".")[0] or asset == connection[1].split(".")[0]: | ||
| other_asset = ( | ||
| connection[0].split(".")[0] | ||
| if asset == connection[1].split(".")[0] | ||
| else connection[1].split(".")[0] | ||
| ) | ||
| # This bit of code is used to go from for example: | ||
| # HeatExchanger.Secondary.HeatIn -> Secondary.HeatIn | ||
| temp = ( | ||
| connection[1].split(".")[1:] | ||
| if asset == connection[1].split(".")[0] | ||
| else connection[0].split(".")[1:] | ||
| ) | ||
| port = temp[0] | ||
| for x in temp[1:]: | ||
| port = port + "." + x | ||
|
|
||
| # Here we check that the connected asset is not also owned by the same entity. |
There was a problem hiding this comment.
this could be skipped and one could loop over the connected assets named other_asset from asset_con_dict[asset]
| # to represent the cashflow associated with the energy exchanged between the two | ||
| # organizations. | ||
| if other_asset not in assets: | ||
| var_name = f"{asset}__revenue_{port}" |
There was a problem hiding this comment.
possible ports could now be retrieved from: asset_port_dict[asset]
looping over these possible ports (poss_port), one can check which port relates to this connection:
if conn[f"{asset}.{poss_port}].split(".")[0] == other_asset
| var_name = f"{asset}__revenue_{port}" | ||
| nominal_power = None | ||
| carrier_name = None | ||
| for _id, attr in self.get_electricity_carriers().items(): |
There was a problem hiding this comment.
Potentially to generalise for commodities:
we could create a map commodity_var_map = {"heat": "Heat", "gas": "Q", "electricity": "Power"}
we could loop over the commodities = ["heat", "gas", "electricity"]
then a nested loop for this line could be done like:
for id, attr in getattr(self, f"get{commodity}_carriers")().items():
with the Power, Q and Heat replaced by commodity_var_map[commodity].
This can also be done for the ccreation of the variables line 119 to 147
This PR is still in draft state
This PR is meant to do the following: