Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Esdl asset consumer mapper. #196

Merged
merged 8 commits into from
Dec 18, 2024
36 changes: 28 additions & 8 deletions src/omotes_simulator_core/adapter/transforms/esdl_asset_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import numpy as np

from omotes_simulator_core.entities.assets.asset_abstract import AssetAbstract
from omotes_simulator_core.entities.assets.demand_cluster import DemandCluster
from omotes_simulator_core.entities.assets.esdl_asset_object import EsdlAssetObject
from omotes_simulator_core.entities.assets.pipe import Pipe
from omotes_simulator_core.entities.assets.production_cluster import ProductionCluster
Expand All @@ -31,18 +30,25 @@
from omotes_simulator_core.entities.assets.controller.controller_consumer import ControllerConsumer
from omotes_simulator_core.entities.assets.controller.controller_storage import ControllerStorage
from omotes_simulator_core.simulation.mappers.mappers import EsdlMapperAbstract, Entity
from omotes_simulator_core.adapter.transforms.esdl_asset_mappers.EsdlAssetConsumerMapper import (
EsdlAssetConsumerMapper,
)

CONVERSION_DICT: dict[esdl.EnergyAsset, Type[AssetAbstract]] = {

CONVERSION_DICT: dict[type, Type[AssetAbstract]] = {
esdl.Producer: ProductionCluster,
esdl.GenericProducer: ProductionCluster,
esdl.Consumer: DemandCluster,
esdl.GenericConsumer: DemandCluster,
esdl.HeatingDemand: DemandCluster,
esdl.Pipe: Pipe,
esdl.ATES: AtesCluster,
esdl.HeatPump: HeatPump,
}

conversion_dict_mappers = {
esdl.Consumer: EsdlAssetConsumerMapper,
esdl.GenericConsumer: EsdlAssetConsumerMapper,
esdl.HeatingDemand: EsdlAssetConsumerMapper,
}


class EsdlAssetMapper:
"""Creates entity Asset objects based on a PyESDL EnergySystem assets."""
Expand All @@ -60,11 +66,25 @@ def to_entity(model: EsdlAssetObject) -> AssetAbstract:

:return: Entity object of type AssetAbstract.
"""
if not type(model.esdl_asset) in CONVERSION_DICT:
if (
not type(model.esdl_asset) in CONVERSION_DICT
and not type(model.esdl_asset) in conversion_dict_mappers
):
raise NotImplementedError(str(model.esdl_asset) + " not implemented in conversion")
return CONVERSION_DICT[type(model.esdl_asset)](
model.esdl_asset.name, model.esdl_asset.id, model.get_port_ids()

# Use the dictionary to get the appropriate mapper
asset_type = type(model.esdl_asset)
if asset_type in conversion_dict_mappers:
mapper = conversion_dict_mappers[asset_type]()
return mapper.to_entity(model)

converted_asset = CONVERSION_DICT[type(model.esdl_asset)](
model.get_name(),
vanmeerkerk marked this conversation as resolved.
Show resolved Hide resolved
model.get_id(),
model.get_port_ids(),
)
converted_asset.add_physical_data(esdl_asset=model)
return converted_asset


class EsdlAssetControllerProducerMapper(EsdlMapperAbstract):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2023. Deltares & TNO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Module containing the Esdl to Consumer asset mapper class."""

from omotes_simulator_core.entities.assets.demand_cluster import DemandCluster
from omotes_simulator_core.entities.assets.asset_abstract import AssetAbstract
from omotes_simulator_core.entities.assets.esdl_asset_object import EsdlAssetObject
from omotes_simulator_core.simulation.mappers.mappers import EsdlMapperAbstract


class EsdlAssetConsumerMapper(EsdlMapperAbstract):
"""Class to map an ESDL asset to a consumer entity class."""

def to_esdl(self, entity: DemandCluster) -> EsdlAssetObject:
"""Map a Consumer entity to an EsdlAsset."""
raise NotImplementedError("EsdlAssetConsumerMapper.to_esdl()")

def to_entity(self, esdl_asset: EsdlAssetObject) -> AssetAbstract:
"""Method to map an ESDL asset to a consumer entity class.

:param EsdlAssetObject esdl_asset: Object to be converted to a consumer entity.
:return: Consumer object.
"""
consumer_entity = DemandCluster(
asset_name=esdl_asset.esdl_asset.name,
asset_id=esdl_asset.esdl_asset.id,
port_ids=esdl_asset.get_port_ids(),
)

return consumer_entity
1 change: 0 additions & 1 deletion src/omotes_simulator_core/adapter/transforms/mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def _convert_assets(self, network: Network) -> List[AssetAbstract]:
if isinstance(esdl_asset.esdl_asset, esdl_junction):
continue
py_assets_list.append(EsdlAssetMapper.to_entity(esdl_asset))
py_assets_list[-1].add_physical_data(esdl_asset=esdl_asset)
network.add_existing_asset(py_assets_list[-1].solver_asset)
return py_assets_list

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def __init__(self, asset: esdl.Asset) -> None:
"""
self.esdl_asset = asset

def get_name(self) -> str:
"""Get the name of the asset."""
return str(self.esdl_asset.name)

def get_id(self) -> str:
"""Get the id of the asset."""
return str(self.esdl_asset.id)
Expand Down
Loading