diff --git a/pandapipes/component_models/reservoir_component.py b/pandapipes/component_models/reservoir_component.py new file mode 100644 index 00000000..6aff08bb --- /dev/null +++ b/pandapipes/component_models/reservoir_component.py @@ -0,0 +1,36 @@ +from numpy import dtype + +from pandapipes.component_models.ext_grid_component import ExtGrid + + +try: + import pplog as logging +except ImportError: + import logging + +logger = logging.getLogger(__name__) + + +class Reservoir(ExtGrid): + """ + + """ + + @classmethod + def table_name(cls): + return "reservoir" + + @classmethod + def get_component_input(cls): + """ + + :return: + """ + + return [("name", dtype(object)), + ("junction", "u4"), + ("h_m", "f8"), + ("p_bar", "f8"), + ("t_k", "f8"), + ("in_service", "bool"), + ('type', dtype(object))] diff --git a/pandapipes/create.py b/pandapipes/create.py index e9d3456f..8121c57b 100644 --- a/pandapipes/create.py +++ b/pandapipes/create.py @@ -14,6 +14,8 @@ from pandapipes.std_types.std_type_toolbox import regression_function from pandapipes.component_models import Junction, Sink, Source, Pump, Pipe, ExtGrid, \ HeatExchanger, Valve, CirculationPumpPressure, CirculationPumpMass +from pandapipes.component_models.reservoir_component import Reservoir +from pandapipes.constants import GRAVITATION_CONSTANT, P_CONVERSION try: import pplog as logging @@ -303,6 +305,57 @@ def create_ext_grid(net, junction, p_bar, t_k, name=None, in_service=True, index return index +def create_reservoir(net, junction, h_m, t_k=293, name=None, in_service=True, index=None): + """ + + :param net: The net that the reservoir should be connected to + :type net: pandapipesNet + :param junction: The junction to which the reservoir grid is connected + :type junction: int + :param h_m: The height of the reservoir + :type h_m: float + :param t_k: The fixed temperature of the water in the reservoir + :type t_k: float, default 293 + :param name: A name tg for this reservoir + :type name: str, default None + :param in_service: True for in service, false for out of service + :type in_service: bool, default True + :param index: Force a specified ID if it is available. If None, the index is set one higher than the \ + highest already existing index is selected. + :return: index - The unique ID of the created element + :rtype: int + + :Example: create_reservoir(net, junction1, h_m=3, name="Grid reservoir") + + """ + add_new_component(net, Reservoir) + + if junction not in net["junction"].index.values: + raise UserWarning("Cannot attach to junction %s, junction does not exist" % junction) + + if index is not None and index in net["reservoir"].index: + raise UserWarning("An external grid with with index %s already exists" % index) + + if index is None: + index = get_free_id(net["reservoir"]) + + dtypes = net.reservoir.dtypes + + density = net.fluid.get_density(t_k).item() + + p_bar = density * h_m * GRAVITATION_CONSTANT * P_CONVERSION + + # external grid with fixed pressure --> the node acts as a slack node for the mass flow. + type = "p" + + net.reservoir.loc[index, ["name", "junction", "h_m", "p_bar", "t_k", "in_service", "type"]] = \ + [name, junction, h_m, p_bar, t_k, bool(in_service), type] + + # and preserve dtypes + _preserve_dtypes(net.reservoir, dtypes) + return index + + def create_heat_exchanger(net, from_junction, to_junction, diameter_m, qext_w, loss_coefficient=0, name=None, index=None, in_service=True, type="heat_exchanger", **kwargs): """ diff --git a/pandapipes/test/api/test_components/test_reservoir.py b/pandapipes/test/api/test_components/test_reservoir.py new file mode 100644 index 00000000..d3854550 --- /dev/null +++ b/pandapipes/test/api/test_components/test_reservoir.py @@ -0,0 +1,22 @@ +import pandapipes as pp + + +def test_reservoir(): + """ + + :return: + """ + net = pp.create_empty_network(fluid="water") + + junction1 = pp.create_junction(net, pn_bar=1.0, tfluid_k=293.15, name="Connection to External Grid") + junction2 = pp.create_junction(net, pn_bar=1.0, tfluid_k=293.15, name="Junction 2") + + pp.create_reservoir(net, junction1, h_m=3, name="Grid reservoir") + + pp.create_pipe_from_parameters(net, from_junction=junction1, to_junction=junction2, length_km=10, diameter_m=0.3, name="Pipe 1") + + pp.create_sink(net, junction=junction2, mdot_kg_per_s=0.545, name="Sink 1") + + pp.pipeflow(net) + + assert 1 == 1