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

Flow control model #413

Merged
merged 39 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0ce3b17
implementation of flow control component
dlohmeier Jan 21, 2022
13c0c35
Merge branch 'dev_numba' of https://github.com/e2nIEE/pandapipes into…
dlohmeier Feb 8, 2022
a8e0e7f
corrections of branch result extraction for flow control component
dlohmeier Feb 8, 2022
13696f0
import fix
dlohmeier Feb 8, 2022
6b1708e
new function to create multiple flow control components; small commen…
dlohmeier Feb 24, 2022
6feb91f
slight corrections in strings not containing flow_control
dlohmeier Mar 2, 2022
428ccc0
Merge branch 'dev_numba' into flow_control
dlohmeier May 13, 2022
fd02835
small fixes in create module
dlohmeier May 13, 2022
c62c65f
Merge branch 'dev_numba' into flow_control
dlohmeier May 16, 2022
079ba41
Merge branch 'develop' of https://github.com/e2nIEE/pandapipes into f…
dlohmeier Jun 27, 2022
54146a3
Merge branch 'develop' of https://github.com/e2nIEE/pandapipes into f…
dlohmeier Jul 13, 2022
f8eaa4d
Merge branch 'develop' into flow_control
dlohmeier Jul 22, 2022
67eeee7
Merge branch 'develop' of https://github.com/e2nIEE/pandapipes into f…
dlohmeier Aug 1, 2022
c7c5201
Merge branch 'develop' of https://github.com/e2nIEE/pandapipes into f…
dlohmeier Oct 15, 2022
68e0ea0
Update CHANGELOG.rst
jkisse Oct 20, 2022
715279c
Merge branch 'develop' into flow_control
dlohmeier Oct 21, 2022
c462827
added test for flow control; correction of naming in flow control met…
dlohmeier Oct 21, 2022
810ee23
added flow controls to nx graph creation
dlohmeier Oct 21, 2022
3c56694
refactoring of signature for temperature lift cls method
dlohmeier Oct 21, 2022
3af2563
add plotting for flow_control
jkisse Oct 21, 2022
16bd370
Merge branch 'develop' into flow_control
dlohmeier Oct 25, 2022
4e9033d
implemented control_active behavior for flow_controllers; corrections…
dlohmeier Nov 4, 2022
679465c
correction in collections.py
dlohmeier Nov 4, 2022
39bca6d
small differentiation between flow control and valve in plotting
dlohmeier Nov 4, 2022
9d8e949
added flow controller test with gas
dlohmeier Nov 4, 2022
23d92d0
added flow controllers to plotting test
dlohmeier Nov 4, 2022
54b630c
added flow controllers to plotting test of simple collections
dlohmeier Nov 4, 2022
9adf377
some pep
dlohmeier Nov 4, 2022
750205e
Merge branch 'develop' into flow_control
dlohmeier Dec 5, 2022
3742f32
added compressor back to edges in nxgraph
dlohmeier Dec 5, 2022
6f30800
Merge branch 'develop' into flow_control
SimonRubenDrauz Dec 12, 2022
2af02fa
some corrections in the create function docstrings
dlohmeier Dec 12, 2022
74e2ba8
Merge remote-tracking branch 'pp_fork/flow_control' into flow_control
dlohmeier Dec 12, 2022
a765c6e
change how in_service is considered for FC in simple_plot
jkisse Dec 13, 2022
74fd289
Merge branch 'develop' into flow_control
dlohmeier Dec 14, 2022
fce8744
Merge remote-tracking branch 'e2nIEE_pandapipes/develop' into flow_co…
jkisse Jan 3, 2023
ca5b18c
add documentation for flow control
jkisse Jan 3, 2023
238069a
add documentation for flow control (for real now)
jkisse Jan 3, 2023
68a2dd1
Merge branch 'develop' into flow_control
dlohmeier Jan 4, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Change Log

[upcoming release] - 2023-..-..
-------------------------------
- [ADDED] new component flow controller: a branch component that controls the flow through itself. It adapts the pressure drop between two junctions to reflect the desired flow situation.
- [ADDED] new global variable `__format_version__` that shall only be increased in case of API changes (i.e. if the convert_format function for JSON I/O must be called)
- [ADDED] toolbox function to extract the _pit (pandapipes internal tables) structure for nodes and branches as pandas tables with meaningful names for the stored columns as given in the node_idx and branch_idx files
- [ADDED] new component `mass_storage` and tutorial how to use it
Expand Down
3 changes: 2 additions & 1 deletion doc/source/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ following documentation:
components/circulation_pump_pressure/circ_pump_pressure_component
components/compressor/compressor_component
components/heat_exchanger/heat_exchanger_component
components/storage/storage_component
components/storage/storage_component
components/flow_control/flow_control_component
46 changes: 46 additions & 0 deletions doc/source/components/flow_control/flow_control_component.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
==============
Flow Control
==============

Create Function
===============

.. _create_flow_control:

.. autofunction:: pandapipes.create_flow_control

Physical Model
==============
The flow control component enforces a specific mass flow between two junctions.
This is very helpful to control the mass flow in district heating networks.

.. warning::

It is recommended to use the flow control components only in looped networks.
Using the flow controller in non-looped networks, in particular on stubs, can
likely lead to non-convergence of the pipeflow.


Component Table Data
====================

*net.flow_control*

.. tabularcolumns:: |p{0.10\linewidth}|p{0.10\linewidth}|p{0.25\linewidth}|p{0.40\linewidth}|

.. csv-table::
:file: flow_control_par.csv
:delim: ;
:widths: 10, 10, 25, 40


Result Table Data
=================

*net.res_flow_control*

.. tabularcolumns:: |p{0.15\linewidth}|p{0.10\linewidth}|p{0.55\linewidth}|
.. csv-table::
:file: flow_control_res.csv
:delim: ;
:widths: 15, 10, 55
10 changes: 10 additions & 0 deletions doc/source/components/flow_control/flow_control_par.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Parameter**;**Datatype**;**Value Range**;**Explanation**
net;pandapipesNet;;The pandapipes net object in whose :code:`flow_control` table the new unit will be added
from_junction;integer;:math:`>` 0;Index of junction at which the flow control unit starts
to_junction;integer;:math:`>` 0;Index of junction at which the flow control unit ends
controlled_mdot_kg_per_s;float;;The mass flow set point [kg/s]
diameter;float;> 0;diameter to derive the cross-sectional area
control_active;boolean;;If false, the unit behaves like an open valve
name;string;;Name of the flow control unit
in_service;boolean;True / False;If false, the unit behaves like a closed valve.
type;string;;Type variable to classify different kinds of flow control units (not considered by pandapipes' calculations)
10 changes: 10 additions & 0 deletions doc/source/components/flow_control/flow_control_res.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Parameter**;**Datatype**;**Explanation**
v_mean_m_per_s;float;The mean velocity of fluid in the flow control unit [m/s]
p_from_bar;float;Pressure at "from"-junction [bar]
p_to_bar;float;Pressure at "to"-junction [bar]
t_from_k;float;Temperature at "from"-junction [K]
t_to_k;float;Temperature at "to"-junction [K]
mdot_from_kg_per_s;float;Mass flow into flow control unit [kg/s]
mdot_to_kg_per_s;float;Mass flow out of flow control unit [kg/s]
vdot_norm_m3_per_s;float;Norm volume flow [m^3/s]
reynolds;float;Average Reynolds number
6 changes: 3 additions & 3 deletions pandapipes/component_models/abstract_models/branch_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
pass

@classmethod
def calculate_temperature_lift(cls, net, branch_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""

:param net:
:type net:
:param branch_pit:
:type branch_pit:
:param branch_component_pit:
:type branch_component_pit:
dlohmeier marked this conversation as resolved.
Show resolved Hide resolved
:param node_pit:
:type node_pit:
:return:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
# 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 pandapipes.component_models.abstract_models.branch_models import BranchComponent
from pandapipes.component_models.component_toolbox import set_entry_check_repeat
from pandapipes.idx_branch import ACTIVE
from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT, RHO, ETA, \
CP, ELEMENT_IDX
from pandapipes.idx_node import L, node_cols
from pandapipes.idx_node import TINIT as TINIT_NODE
from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT, RHO, ETA, CP, ELEMENT_IDX
from pandapipes.idx_node import L, node_cols, TINIT as TINIT_NODE
from pandapipes.pf.pipeflow_setup import add_table_lookup, get_lookup, get_table_number
from pandapipes.properties.fluids import get_fluid

Expand Down Expand Up @@ -43,7 +41,7 @@ def active_identifier(cls):
raise NotImplementedError

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
raise NotImplementedError

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def create_pit_branch_entries(cls, net, branch_pit):
return branch_wo_internals_pit

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
raise NotImplementedError

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ def extract_results(cls, net, options, branch_results, nodes_connected, branches
raise NotImplementedError

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
raise NotImplementedError
1 change: 1 addition & 0 deletions pandapipes/component_models/component_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import pandas as pd

from pandapipes.constants import NORMAL_PRESSURE, TEMP_GRADIENT_KPM, AVG_TEMPERATURE_K, \
HEIGHT_EXPONENT

Expand Down
144 changes: 144 additions & 0 deletions pandapipes/component_models/flow_control_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright (c) 2020-2021 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.junction_component import Junction
from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent, get_fluid
from pandapipes.idx_branch import D, AREA, TL, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, VINIT, \
RHO, LOAD_VEC_BRANCHES, ELEMENT_IDX
from pandapipes.pf.result_extraction import extract_branch_results_without_internals


class FlowControlComponent(BranchWZeroLengthComponent):
"""

"""

@classmethod
def table_name(cls):
return "flow_control"

@classmethod
def active_identifier(cls):
return "in_service"

@classmethod
def from_to_node_cols(cls):
return "from_junction", "to_junction"

@classmethod
def get_connected_node_type(cls):
return Junction

@classmethod
def create_pit_branch_entries(cls, net, branch_pit):
"""
Function which creates pit branch entries with a specific table.
:param net: The pandapipes network
:type net: pandapipesNet
:param branch_pit:
:type branch_pit:
:return: No Output.
"""
fc_pit = super().create_pit_branch_entries(net, branch_pit)
fc_pit[:, D] = net[cls.table_name()].diameter_m.values
fc_pit[:, AREA] = fc_pit[:, D] ** 2 * np.pi / 4
fc_pit[:, VINIT] = net[cls.table_name()].controlled_mdot_kg_per_s.values / \
(fc_pit[:, AREA] * fc_pit[:, RHO])
dlohmeier marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
pass
dlohmeier marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
# set all pressure derivatives to 0 and velocity to 1; load vector must be 0, as no change
# of velocity is allowed during the pipeflow iteration
f, t = idx_lookups[cls.table_name()]
fc_pit = branch_pit[f:t, :]
in_service_elm = np.isin(net[cls.table_name()].index.values,
fc_pit[:, ELEMENT_IDX].astype(np.int32))
active = net[cls.table_name()].control_active.values[in_service_elm]
fc_pit[active, JAC_DERIV_DP] = 0
fc_pit[active, JAC_DERIV_DP1] = 0
fc_pit[active, JAC_DERIV_DV] = 1
SimonRubenDrauz marked this conversation as resolved.
Show resolved Hide resolved
fc_pit[active, LOAD_VEC_BRANCHES] = 0
dlohmeier marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""

:param net:
:type net:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
required_results = [
("p_from_bar", "p_from"), ("p_to_bar", "p_to"), ("t_from_k", "temp_from"),
("t_to_k", "temp_to"), ("mdot_to_kg_per_s", "mf_to"), ("mdot_from_kg_per_s", "mf_from"),
("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"), ("reynolds", "reynolds")
]

if get_fluid(net).is_gas:
required_results.extend([
("v_from_m_per_s", "v_gas_from"), ("v_to_m_per_s", "v_gas_to"),
("v_mean_m_per_s", "v_gas_mean"), ("normfactor_from", "normfactor_from"),
("normfactor_to", "normfactor_to")
])
else:
required_results.extend([("v_mean_m_per_s", "v_mps")])

extract_branch_results_without_internals(net, branch_results, required_results,
cls.table_name(), branches_connected)

@classmethod
def get_component_input(cls):
"""

Get component input.

:return:
:rtype:
"""
return [("name", dtype(object)),
("from_junction", "u4"),
("to_junction", "u4"),
("controlled_mdot_kg_per_s", "f8"),
("diameter_m", "f8"),
("control_active", "bool"),
("in_service", 'bool'),
("type", dtype(object))]

@classmethod
def get_result_table(cls, net):
"""

Gets the result table.

: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)
"""
if get_fluid(net).is_gas:
output = ["v_from_m_per_s", "v_to_m_per_s", "v_mean_m_per_s", "p_from_bar", "p_to_bar",
"t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
"normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
"mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s", "reynolds",
"lambda"]
return output, True
8 changes: 4 additions & 4 deletions pandapipes/component_models/heat_exchanger_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ def extract_results(cls, net, options, branch_results, nodes_connected, branches
cls.table_name(), branches_connected)

@classmethod
def calculate_temperature_lift(cls, net, he_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""

:param net:
:type net:
:param he_pit:
:type he_pit:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
he_pit[:, TL] = 0
branch_component_pit[:, TL] = 0

@classmethod
def get_component_input(cls):
Expand Down
8 changes: 4 additions & 4 deletions pandapipes/component_models/pipe_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ def create_pit_branch_entries(cls, net, branch_pit):
pipe_pit[:, AREA] = pipe_pit[:, D] ** 2 * np.pi / 4

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""

:param net:
:type net:
:param pipe_pit:
:type pipe_pit:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
pipe_pit[:, TL] = 0
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
Expand Down
8 changes: 4 additions & 4 deletions pandapipes/component_models/pressure_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_loo
press_pit[pc_branch, JAC_DERIV_DV] = 0

@classmethod
def calculate_temperature_lift(cls, net, pc_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""

:param net:
:type net:
:param pc_pit:
:type pc_pit:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
pc_pit[:, TL] = 0
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
Expand Down
8 changes: 4 additions & 4 deletions pandapipes/component_models/pump_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
pump_pit[:, PL] = pl

@classmethod
def calculate_temperature_lift(cls, net, pump_pit, node_pit):
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""

:param net:
:type net:
:param pump_pit:
:type pump_pit:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
pump_pit[:, TL] = 0
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
Expand Down
Loading