Skip to content

Commit

Permalink
removed xfail for some heat consumer tests, small pep corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohmeier committed Mar 18, 2024
1 parent 8a839ea commit 4a452be
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
46 changes: 25 additions & 21 deletions src/pandapipes/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ def create_mass_storage(net, junction, mdot_kg_per_s, init_m_stored_kg=0, min_m_
:type mdot_kg_per_s: float, default None
:param init_m_stored_kg: The initially stored mass in the storage
:type init_m_stored_kg: float, default None
:param min_m_stored_kg: Minimum amount of fluid that has to remain in the storage unit. (To be used
with controllers)
:param min_m_stored_kg: Minimum amount of fluid that has to remain in the storage unit. (To be
used with controllers)
:type min_m_stored_kg: float
:param max_m_stored_kg: Maximum amount of fluid that can be stored in the storage unit. (To be used
with controllers)
:param max_m_stored_kg: Maximum amount of fluid that can be stored in the storage unit. (To be
used with controllers)
:type max_m_stored_kg: float, default np.inf
:param scaling: An optional scaling factor to be set customly
:type scaling: float, default 1
Expand Down Expand Up @@ -1020,9 +1020,9 @@ def create_flow_control(net, from_junction, to_junction, controlled_mdot_kg_per_
return index


def create_heat_consumer(net, from_junction, to_junction, diameter_m, controlled_mdot_kg_per_s=None,
qext_w=None, deltat_k=None, treturn_k=None, name=None, index=None,
in_service=True, type="heat_consumer", **kwargs):
def create_heat_consumer(net, from_junction, to_junction, diameter_m, qext_w=None,
controlled_mdot_kg_per_s=None, deltat_k=None, treturn_k=None, name=None,
index=None, in_service=True, type="heat_consumer", **kwargs):
"""
Creates a heat consumer element in net["heat_consumer"] from heat consumer parameters.
Expand Down Expand Up @@ -1061,13 +1061,14 @@ def create_heat_consumer(net, from_junction, to_junction, diameter_m, controlled
:rtype: int
:Example:
>>> create_heat_consumer(net,from_junction=0, to_junction=1, diameter_m=40e-3, qext_w=2000)
>>> create_heat_consumer(net,from_junction=0, to_junction=1, diameter_m=40e-3, qext_w=20000,
>>> controlled_mdot_kg_per_s=0.4, name="heat_consumer1")
"""
if deltat_k is not None or treturn_k is not None:
raise NotImplementedError("The models for consumers with fixed temperature difference or "
"fixed return temperature are not implemented yet.")
if ((controlled_mdot_kg_per_s is None) + (qext_w is None) + (deltat_k is None)
+ (treturn_k is None) !=2):
+ (treturn_k is None) != 2):
raise AttributeError(r"Define exactly two varibales from 'controlled_mdot_kg_per_s', "
r"'qext_w' and 'deltat_k' or 'treturn_k' different from None")
if deltat_k is not None and treturn_k is not None:
Expand Down Expand Up @@ -1572,7 +1573,7 @@ def create_pressure_controls(net, from_junctions, to_junctions, controlled_junct
_set_multiple_entries(net, "press_control", index, **entries, **kwargs)

controlled_elsewhere = (controlled_junctions != from_junctions) \
& (controlled_junctions != to_junctions)
& (controlled_junctions != to_junctions)
if np.any(controlled_elsewhere):
controllers_warn = index[controlled_elsewhere]
logger.warning("The pressure controllers %s control the pressure at junctions that they are"
Expand Down Expand Up @@ -1642,8 +1643,9 @@ def create_flow_controls(net, from_junctions, to_junctions, controlled_mdot_kg_p
return index


def create_heat_exchangers(net, from_junctions, to_junctions, diameter_m, qext_w, loss_coefficient=0,
name=None, index=None, in_service=True, type="heat_exchanger", **kwargs):
def create_heat_exchangers(net, from_junctions, to_junctions, diameter_m, qext_w,
loss_coefficient=0, name=None, index=None, in_service=True,
type="heat_exchanger", **kwargs):
"""
Convenience function for creating many heat exchangers at once. Parameters 'from_junctions'\
and 'to_junctions' must be arrays of equal length. Other parameters may be either arrays of the\
Expand All @@ -1670,7 +1672,8 @@ def create_heat_exchangers(net, from_junctions, to_junctions, diameter_m, qext_w
highest already existing index is selected and counted onwards for the amount of heat \
exchangers created.
:type index: Iterable(str) or str, default None
:param in_service: True if the heat exchangers are in service or False if they are out of service
:param in_service: True if the heat exchangers are in service or False if they are out of \
service
:type in_service: Iterable(bool) or bool, default True
:param type: Not used yet
:type type: Iterable(str) or str, default "heat exchanger"
Expand All @@ -1696,8 +1699,8 @@ def create_heat_exchangers(net, from_junctions, to_junctions, diameter_m, qext_w
return index


def create_heat_consumers(net, from_junctions, to_junctions, diameter_m,
controlled_mdot_kg_per_s=None, qext_w=None, deltat_k=None, treturn_k=None,
def create_heat_consumers(net, from_junctions, to_junctions, diameter_m, qext_w=None,
controlled_mdot_kg_per_s=None, deltat_k=None, treturn_k=None,
name=None, index=None, in_service=True, type="heat_consumer", **kwargs):
"""
Creates several heat consumer elements in net["heat_consumer"] from heat consumer parameters.
Expand Down Expand Up @@ -1738,7 +1741,8 @@ def create_heat_consumers(net, from_junctions, to_junctions, diameter_m,
:rtype: int
:Example:
>>> create_heat_consumers(net,from_junctions=[0, 3], to_junctions=[1, 5], diameter_m=40e-3, qext_w=2000)
>>> create_heat_consumers(net,from_junctions=[0, 3], to_junctions=[1, 5], diameter_m=40e-3,
>>> qext_w=20000, controlled_mdot_kg_per_s=[0.5, 0.9])
"""
if np.any(pd.notnull(deltat_k)) or np.any(pd.notnull(treturn_k)):
raise NotImplementedError("The models for consumers with fixed temperature difference or "
Expand All @@ -1748,9 +1752,9 @@ def create_heat_consumers(net, from_junctions, to_junctions, diameter_m,
for i, cv in enumerate(check_vars):
var_sums[i] = np.full_like(from_junctions, pd.isnull(cv)).astype(int)
if np.any(np.sum(var_sums, axis=0) != 2):
raise AttributeError(r"Define exactly two varibales from 'controlled_mdot_kg_per_s', "
r"'qext_w' and 'deltat_k' or 'treturn_k' different from None"
r"for each heat consumer.")
raise AttributeError(r"Define exactly two varibales from 'controlled_mdot_kg_per_s', "
r"'qext_w' and 'deltat_k' or 'treturn_k' different from Nonefor each"
r" heat consumer.")
if np.any(pd.notnull(deltat_k) & pd.notnull(treturn_k)):
raise AttributeError(r"It is not possible to set both 'deltat_k' and 'treturn_k', as the "

Check warning on line 1759 in src/pandapipes/create.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/create.py#L1759

Added line #L1759 was not covered by tests
r"flow temperature is independent of the heat consumer model.")
Expand All @@ -1771,8 +1775,8 @@ def create_heat_consumers(net, from_junctions, to_junctions, diameter_m,
def create_fluid_from_lib(net, name, overwrite=True):
"""
Creates a fluid from library (if there is an entry) and sets net["fluid"] to this value.
Currently, existing fluids in the library are: "hgas", "lgas", "hydrogen", "methane", "water","biomethane_pure",
"biomethane_treated", "air".
Currently, existing fluids in the library are: "hgas", "lgas", "hydrogen", "methane",
"water","biomethane_pure", "biomethane_treated", "air".
:param net: The net for which this fluid should be created
:type net: pandapipesNet
Expand Down
40 changes: 29 additions & 11 deletions src/pandapipes/test/api/test_components/test_heat_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,39 @@ def test_heat_consumer_not_implemented_model(simple_heat_net):
treturn_k=[390, None])


def test_heat_consumer_creation_not_allowed(simple_heat_net):
net = copy.deepcopy(simple_heat_net)
juncs = net.junction.index

with pytest.raises(AttributeError):
# check for less than 2 set parameters
pandapipes.create_heat_consumer(net, juncs[1], juncs[4], 0.1022,
controlled_mdot_kg_per_s=MDOT[0], qext_w=None,
treturn_k=None)
with pytest.raises(AttributeError):
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022,
controlled_mdot_kg_per_s=MDOT, qext_w=[QEXT[0], None])
with pytest.raises(AttributeError):
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022, qext_w=QEXT,
controlled_mdot_kg_per_s=[MDOT[0], None])
with pytest.raises(AttributeError):
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022, qext_w=QEXT,
controlled_mdot_kg_per_s=None)


@pytest.mark.xfail(reason="Can only be tested once models for deltat_k and treturn_k"
" are implemented for heat consumers.")
def test_heat_consumer_creation_not_allowed(simple_heat_net):
def test_heat_consumer_creation_not_allowed_2(simple_heat_net):
net = copy.deepcopy(simple_heat_net)
juncs = net.junction.index
with pytest.raises(AttributeError):
# check for more than 2 set parameters
pandapipes.create_heat_consumer(net, juncs[1], juncs[4], 0.1022,
controlled_mdot_kg_per_s=MDOT[0], qext_w=QEXT[0],
treturn_k=390)
with pytest.raises(AttributeError):
# check for less than 2 set parameters
pandapipes.create_heat_consumer(net, juncs[1], juncs[4], 0.1022,
controlled_mdot_kg_per_s=MDOT[0], qext_w=None,
treturn_k=None)
with pytest.raises(AttributeError):

Check warning on line 130 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L130

Added line #L130 was not covered by tests
# check for deltat_k and treturn_k given
pandapipes.create_heat_consumer(net, juncs[1], juncs[4], 0.1022, deltat_k=20, treturn_k=390)

Check warning on line 132 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L132

Added line #L132 was not covered by tests
Expand All @@ -117,23 +135,23 @@ def test_heat_consumer_creation_not_allowed(simple_heat_net):
# check for more than 2 set parameters
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022,

Check warning on line 136 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L136

Added line #L136 was not covered by tests
deltat_k=[30, 40], treturn_k=[390, 385])
with pytest.raises(NotImplementedError):
with pytest.raises(AttributeError):

Check warning on line 138 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L138

Added line #L138 was not covered by tests
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022,

Check warning on line 140 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L140

Added line #L140 was not covered by tests
controlled_mdot_kg_per_s=MDOT, deltat_k=[20, None])
with pytest.raises(NotImplementedError):
with pytest.raises(AttributeError):

Check warning on line 142 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L142

Added line #L142 was not covered by tests
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022, qext_w=QEXT,

Check warning on line 144 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L144

Added line #L144 was not covered by tests
deltat_k=[20, None])
with pytest.raises(NotImplementedError):
with pytest.raises(AttributeError):

Check warning on line 146 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L146

Added line #L146 was not covered by tests
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022,

Check warning on line 148 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L148

Added line #L148 was not covered by tests
controlled_mdot_kg_per_s=MDOT, treturn_k=[390, None])
with pytest.raises(NotImplementedError):
with pytest.raises(AttributeError):

Check warning on line 150 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L150

Added line #L150 was not covered by tests
# check for less than 2 set parameters in some consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022, qext_w=QEXT,

Check warning on line 152 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L152

Added line #L152 was not covered by tests
treturn_k=[390, None])
with pytest.raises(NotImplementedError):
with pytest.raises(AttributeError):

Check warning on line 154 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L154

Added line #L154 was not covered by tests
# check for less than 2 set parameters in all consumers
pandapipes.create_heat_consumers(net, juncs[[1, 2]], juncs[[4, 3]], 0.1022, qext_w=QEXT,

Check warning on line 156 in src/pandapipes/test/api/test_components/test_heat_consumer.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/test/api/test_components/test_heat_consumer.py#L156

Added line #L156 was not covered by tests
treturn_k=None, controlled_mdot_kg_per_s=None)
Expand Down

0 comments on commit 4a452be

Please sign in to comment.