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

New Component model: reservoir #101

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pandapipes/component_models/reservoir_component.py
Original file line number Diff line number Diff line change
@@ -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))]
53 changes: 53 additions & 0 deletions pandapipes/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
22 changes: 22 additions & 0 deletions pandapipes/test/api/test_components/test_reservoir.py
Original file line number Diff line number Diff line change
@@ -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