-
Notifications
You must be signed in to change notification settings - Fork 62
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
Water Tower Component #107
Open
SimonRubenDrauz
wants to merge
11
commits into
e2nIEE:develop
Choose a base branch
from
SimonRubenDrauz:slowlow/develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fb7261e
Added component: reservoir. Create: e.g. create_reservoir(net, juncti…
lstarost 1a08646
Added test for reservoir. Needs to be change!
lstarost c4467d1
removed density from constants and read it from net.fluid for pressur…
lstarost d31f837
adaption reservoir:
02b28d8
bugfix in water tower
40601d3
bugfix
abf213d
only considering height of the water column
5e99548
adaptions water tower: adding an explaination of the water tower mode…
7e0176b
PEP 8
5363a98
removing water tower as own component and introducing a toolbox to co…
e044b08
small bugfix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# Copyright (c) 2020 by Fraunhofer Institute for Energy Economics | ||
# and Energy System Technology (IEE), Kassel. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
|
||
import numpy as np | ||
from numpy import dtype | ||
|
||
from pandapipes.component_models.abstract_models import NodeElementComponent | ||
from pandapipes.constants import GRAVITATION_CONSTANT, P_CONVERSION | ||
from pandapipes.idx_branch import FROM_NODE, TO_NODE, LOAD_VEC_NODES | ||
from pandapipes.idx_node import PINIT, LOAD, NODE_TYPE, P, EXT_GRID_OCCURENCE | ||
from pandapipes.internals_toolbox import _sum_by_group | ||
from pandapipes.pipeflow_setup import get_lookup | ||
|
||
try: | ||
import pplog as logging | ||
except ImportError: | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WaterTower(NodeElementComponent): | ||
""" | ||
The water tower is similiar to an external grid. Based on the water column height the relative pressure | ||
is determined. This pressure is fixed, i.e. the capacity of the water tower is infinitem and its level is constant. | ||
""" | ||
|
||
@classmethod | ||
def table_name(cls): | ||
return "water_tower" | ||
|
||
@classmethod | ||
def sign(cls): | ||
return 1. | ||
|
||
@classmethod | ||
def create_pit_node_entries(cls, net, node_pit, node_name): | ||
""" | ||
Function which creates pit node entries. | ||
|
||
:param net: The pandapipes network | ||
:type net: pandapipesNet | ||
:param node_pit: | ||
:type node_pit: | ||
:return: No Output. | ||
""" | ||
water_towers = net[cls.table_name()] | ||
density = net.fluid.get_density(water_towers.t_k.values) | ||
junction_idx_lookups = get_lookup(net, "node", "index")[node_name] | ||
junction = cls.get_connected_junction(net) | ||
press = density * water_towers.height_m.values * \ | ||
GRAVITATION_CONSTANT / P_CONVERSION * water_towers.in_service.values | ||
juncts_p, press_sum, number = _sum_by_group(junction.values, press, | ||
np.ones_like(press, dtype=np.int32)) | ||
index_p = junction_idx_lookups[juncts_p] | ||
node_pit[index_p, PINIT] = press_sum / number | ||
node_pit[index_p, NODE_TYPE] = P | ||
node_pit[index_p, EXT_GRID_OCCURENCE] += number | ||
|
||
net["_lookups"]["water_tower"] = \ | ||
np.array(list(set(np.concatenate([net["_lookups"]["water_tower"], index_p])))) if \ | ||
"water_tower" in net['_lookups'] else index_p | ||
return water_towers, press | ||
|
||
@classmethod | ||
def extract_results(cls, net, options, node_name): | ||
""" | ||
Function that extracts certain results. | ||
|
||
:param net: The pandapipes network | ||
:type net: pandapipesNet | ||
:param options: | ||
:type options: | ||
:return: No Output. | ||
""" | ||
water_towers = net[cls.table_name()] | ||
|
||
if len(water_towers) == 0: | ||
return | ||
|
||
res_table = super().extract_results(net, options, node_name) | ||
|
||
branch_pit = net['_pit']['branch'] | ||
node_pit = net["_pit"]["node"] | ||
|
||
junction = cls.get_connected_junction(net) | ||
index_juncts = junction.values | ||
junct_uni = np.array(list(set(index_juncts))) | ||
index_nodes = get_lookup(net, "node", "index")[node_name][junct_uni] | ||
eg_from_branches = np.isin(branch_pit[:, FROM_NODE], index_nodes) | ||
eg_to_branches = np.isin(branch_pit[:, TO_NODE], index_nodes) | ||
from_nodes = branch_pit[eg_from_branches, FROM_NODE] | ||
to_nodes = branch_pit[eg_to_branches, TO_NODE] | ||
mass_flow_from = branch_pit[eg_from_branches, LOAD_VEC_NODES] | ||
mass_flow_to = branch_pit[eg_to_branches, LOAD_VEC_NODES] | ||
press = node_pit[index_nodes, PINIT] | ||
loads = node_pit[index_nodes, LOAD] | ||
counts = node_pit[index_nodes, EXT_GRID_OCCURENCE] | ||
all_index_nodes = np.concatenate([from_nodes, to_nodes, index_nodes]) | ||
all_mass_flows = np.concatenate([-mass_flow_from, mass_flow_to, -loads]) | ||
nodes, sum_mass_flows = _sum_by_group(all_index_nodes, all_mass_flows) | ||
|
||
# positive results mean that the ext_grid feeds in, negative means that the ext grid | ||
# extracts (like a load) | ||
res_table["mdot_kg_per_s"].values[:] = np.repeat(cls.sign() * sum_mass_flows / counts, | ||
counts.astype(int)) | ||
res_table["p_bar"].values[:] = press | ||
return res_table, water_towers, index_nodes, node_pit, branch_pit | ||
|
||
@classmethod | ||
def get_connected_junction(cls, net): | ||
junction = net[cls.table_name()].junction | ||
return junction | ||
|
||
@classmethod | ||
def get_component_input(cls): | ||
""" | ||
|
||
:return: | ||
""" | ||
|
||
return [("name", dtype(object)), | ||
("junction", "u4"), | ||
("height_m", "f8"), | ||
("t_k", "f8"), | ||
("in_service", "bool"), | ||
('type', dtype(object))] | ||
|
||
@classmethod | ||
def get_result_table(cls, net): | ||
""" | ||
|
||
:param net: The pandapipes network | ||
:type net: pandapipesNet | ||
:return: (columns, all_float) - the column names and whether they are all float type. Only | ||
if False, returns columns as tuples also specifying the dtypes | ||
:rtype: (list, bool) | ||
""" | ||
return ["mdot_kg_per_s", "p_bar"], True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) 2020 by Fraunhofer Institute for Energy Economics | ||
# and Energy System Technology (IEE), Kassel. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
|
||
import os | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import pandapipes as pp | ||
from pandapipes.test.pipeflow_internals import internals_data_path | ||
|
||
|
||
def test_water_tower(): | ||
""" | ||
|
||
:rtype: | ||
""" | ||
net = pp.create_empty_network(fluid="water") | ||
|
||
junction1 = pp.create_junction(net, pn_bar=1.0, tfluid_k=293.15, name="Connection to Water Tower") | ||
junction2 = pp.create_junction(net, pn_bar=1.0, tfluid_k=293.15, name="Junction 2") | ||
|
||
pp.create_water_tower(net, junction1, height_m=30, name="Water Tower") | ||
|
||
pp.create_pipe_from_parameters(net, from_junction=junction1, to_junction=junction2, length_km=10, diameter_m=0.075, | ||
name="Pipe 1") | ||
|
||
pp.create_sink(net, junction=junction2, mdot_kg_per_s=0.545, name="Sink 1") | ||
|
||
pp.pipeflow(net, stop_condition="tol", iter=3, friction_model="nikuradse", | ||
mode="hydraulics", transient=False, nonlinear_method="automatic", | ||
tol_p=1e-4, | ||
tol_v=1e-4) | ||
|
||
data = pd.read_csv(os.path.join(internals_data_path, "test_water_tower.csv"), sep=';') | ||
|
||
res_junction = net.res_junction.p_bar.values | ||
res_pipe = net.res_pipe.v_mean_m_per_s.values | ||
|
||
p_diff = np.abs(1 - res_junction / data['p'].dropna().values) | ||
v_diff = np.abs(1 - res_pipe / data['v'].dropna().values) | ||
|
||
assert np.all(p_diff < 0.01) | ||
assert np.all(v_diff < 0.01) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
v;p | ||
0.123588;2.937630 | ||
;2.442159 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure whether this is physically possible. The effect of communicating vessels (dt: "kommunizierende Röhren") is not considered, is it?
I'd suggest limiting the number of water towers to 1 per net or raise a warning when towers with different water height are connected.