Skip to content

Commit 7d1c827

Browse files
committed
Merge branch 'fix/#931-component-variables-in-network-export' into dev
2 parents 8645810 + dd60f76 commit 7d1c827

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

docs/whats_new/v0-9-14.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Bug Fixes
66
- When setting a `Ref` for a temperature, the starting value for enthalpy of
77
the connection with the `Ref` specified is updated in preprocessing
88
(`PR #921 <https://github.com/oemof/tespy/pull/921>`__).
9+
- When loading a :code:`Network` from its serialized form the :code:`is_var`
10+
information of component properties being a variable was missing
11+
(`PR #932 <https://github.com/oemof/tespy/pull/932>`__).
912

1013
Other Changes
1114
#############

src/tespy/components/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def set_attr(self, **kwargs):
206206
elif isinstance(data, dc_simple):
207207
data.set_attr(val=kwargs[key], is_set=True)
208208

209-
elif kwargs[key] == 'var' and isinstance(data, dc_cp):
209+
elif kwargs[key] == "var" and isinstance(data, dc_cp):
210210
data.set_attr(is_set=True, is_var=True)
211211

212212
# invalid datatype for keyword

src/tespy/tools/data_containers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,10 @@ def set_unit(self, value):
697697

698698

699699
class ComponentProperties(FluidProperties):
700-
pass
700+
701+
def _serialize(self):
702+
keys = ["val", "val_SI", "is_set", "unit", "is_var"]
703+
return {k: getattr(self, k) for k in keys}
701704

702705

703706
class ScalarVariable(DataContainer):

tests/test_networks/test_network.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ def test_Network_from_dict(self):
193193
)
194194
assert imported_nwk.checked, msg
195195

196+
def test_Network_import_with_component_parameter_as_variable(self):
197+
"""Test if component variables are retained after import."""
198+
pipe = Pipe("pipe")
199+
c1 = Connection(self.source, 'out1', pipe, 'in1', label="c1")
200+
c2 = Connection(pipe, 'out1', self.sink, 'in1', label="c2")
201+
self.nw.add_conns(c1, c2)
202+
c1.set_attr(fluid={"H2O": 1}, m=1, T=25, p=2)
203+
c2.set_attr(p=1.9)
204+
pipe.set_attr(Q=0, D="var", ks=0.00005, L=100)
205+
self.nw.solve("design")
206+
self.nw.assert_convergence()
207+
serialization = self.nw.export()
208+
imported_nwk = Network.from_dict(serialization)
209+
imported_nwk.solve("design")
210+
imported_nwk.assert_convergence()
211+
assert approx(pipe.D.val) == imported_nwk.get_comp("pipe").D.val
212+
196213
def test_Network_reader_unknown_component_class(self, tmp_path):
197214
"""Test notsupported component."""
198215
tmp_path = f"{tmp_path}.json"

0 commit comments

Comments
 (0)