Skip to content

Commit

Permalink
Add wrapper registry
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Apr 30, 2024
1 parent 245776e commit 5d8e2b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/tespy/components/basics/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import numpy as np

from tespy.components.component import Component
from tespy.components.component import component_registry


from tespy.components.component import component_registry
@component_registry
class Source(Component):
r"""
Expand Down
15 changes: 2 additions & 13 deletions src/tespy/networks/network_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from tespy.tools.data_containers import ComponentCharacteristics as dc_cc
from tespy.tools.data_containers import DataContainer as dc
from tespy.tools.data_containers import FluidProperties as dc_prop
from tespy.tools.fluid_properties.wrappers import wrapper_registry
from tespy.tools.helpers import modify_path_os


Expand Down Expand Up @@ -256,17 +257,6 @@ def load_network(path):
return nw


def _get_target_class(class_name, module_name, module):
if hasattr(module, class_name):
return getattr(module, class_name)
else:
msg = (
f"The class {class_name} is not availble as import in the "
f"{module_name} module."
)
logger.warning(msg)


def _construct_components(target_class, data):
r"""
Create TESPy component from class name and set parameters.
Expand Down Expand Up @@ -368,8 +358,7 @@ def _construct_connections(data, comps):
conns[label].set_attr(**{arg: conn[arg]})

for f, engine in conn["fluid"]["engine"].items():
target_class = _get_target_class(engine, module_name, module)
conn["fluid"]["engine"][f] = target_class
conn["fluid"]["engine"][f] = wrapper_registry.items[engine]

conns[label].fluid.set_attr(**conn["fluid"])
conns[label]._create_fluid_wrapper()
Expand Down
12 changes: 12 additions & 0 deletions src/tespy/tools/fluid_properties/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
from tespy.tools.global_vars import ERR


def wrapper_registry(type):
wrapper_registry.items[type.__name__] = type
return type


wrapper_registry.items = {}


class SerializableAbstractState(CP.AbstractState):

def __init__(self, back_end, fluid_name):
Expand All @@ -26,6 +34,7 @@ def __reduce__(self):
return (self.__class__, (self.back_end, self.fluid_name))


@wrapper_registry
class FluidPropertyWrapper:

def __init__(self, fluid, back_end=None) -> None:
Expand Down Expand Up @@ -106,6 +115,7 @@ def s_pT(self, p, T):
self._not_implemented()


@wrapper_registry
class CoolPropWrapper(FluidPropertyWrapper):

def __init__(self, fluid, back_end=None) -> None:
Expand Down Expand Up @@ -248,6 +258,7 @@ def s_pT(self, p, T):
return self.AS.smass()


@wrapper_registry
class IAPWSWrapper(FluidPropertyWrapper):


Expand Down Expand Up @@ -366,6 +377,7 @@ def s_pT(self, p, T):
return self.AS(P=p / 1e6, T=T).s * 1e3


@wrapper_registry
class PyromatWrapper(FluidPropertyWrapper):

def __init__(self, fluid, back_end=None) -> None:
Expand Down

0 comments on commit 5d8e2b5

Please sign in to comment.