Skip to content

Commit

Permalink
Merge pull request #300 from e2nIEE/develop
Browse files Browse the repository at this point in the history
release 0.5.0
  • Loading branch information
SimonRubenDrauz authored Jul 29, 2021
2 parents 6f273f3 + da3d2d8 commit 26a343b
Show file tree
Hide file tree
Showing 19 changed files with 473 additions and 138 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
=============

[0.5.0] - 2021-07-29
-------------------------------
- [ADDED] Enabling encryption of pandapipes networks
- [CHANGED] Removing p_scale from default net options
- [FIXED] Input of get_compressibility in fluids.py is pressure, not temperature

[0.4.0] - 2021-03-09
-------------------------------
- [ADDED] Six new tutorials.
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ Institute for Energy Economics and Energy System Technology (IEE), Kassel, and t
Energy Management and Power System Operation, University of Kassel.


.. image:: https://www.uni-kassel.de/eecs/fileadmin/datas/fb16/Fachgebiete/energiemanagement/iee.png
.. image:: https://upload.wikimedia.org/wikipedia/commons/e/ee/FraunhoferIEELogo.gif
:target: https://www.iee.fraunhofer.de/en.html
:width: 300em
:width: 350

|
.. image:: https://www.uni-kassel.de/uni/fileadmin/sys/resources/images/logo/logo-main.svg
:target: https://www.uni-kassel.de/
:width: 300em
:width: 350

|
.. image:: https://www.uni-kassel.de/eecs/fileadmin/datas/fb16/Fachgebiete/energiemanagement/e2n.png
:target: https://www.uni-kassel.de/eecs/en/fachgebiete/e2n/home.html
:width: 200em
.. image:: https://www.uni-kassel.de/eecs/index.php?eID=dumpFile&t=p&p=1674&token=b0509afe2e7c4e41d7cdad83edd0ce49af9fceaa
:target: https://www.uni-kassel.de/eecs/en/sections/energiemanagement-und-betrieb-elektrischer-netze/home
:width: 250

|
Expand Down
2 changes: 1 addition & 1 deletion doc/source/components/pipe/pipe_component.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ The heat losses are described by
:nowrap:
\begin{align*}
Q_\text{loss} &= \alpha \cdot (T - T_\text{ext})\\
Q_\text{loss} &= \alpha \cdot l \cdot \Pi \cdot d \cdot (T - T_\text{ext})\\
\end{align*}
Expand Down
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
# built documents.
#
# The short X.Y version.
version = "0.4"
version = "0.5"
# The full version, including alpha/beta/rc tags.
release = "0.4.0"
release = "0.5.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion pandapipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# and Energy System Technology (IEE), Kassel, and University of Kassel. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

__version__ = '0.4.0'
__version__ = '0.5.0'

import pandas as pd
import os
Expand Down
8 changes: 2 additions & 6 deletions pandapipes/component_models/abstract_models/branch_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ def calculate_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups,
branch_component_pit[:, JAC_DERIV_DP] = -1
branch_component_pit[:, JAC_DERIV_DP1] = 1
else:
# Formulas for gas pressure loss according to laminar version described in STANET 10
# manual, page 1623

# compressibility settings
p_m = np.empty_like(p_init_i_abs)
mask = p_init_i_abs != p_init_i1_abs
Expand Down Expand Up @@ -312,7 +309,6 @@ def extract_results(cls, net, options, node_name):

from_nodes = branch_pit[:, FROM_NODE].astype(np.int32)
to_nodes = branch_pit[:, TO_NODE].astype(np.int32)
p_scale = get_net_option(net, "p_scale")
fluid = get_fluid(net)

v_mps = branch_pit[:, VINIT]
Expand All @@ -328,8 +324,8 @@ def extract_results(cls, net, options, node_name):

if fluid.is_gas:
# derived from the ideal gas law
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] * p_scale
p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] * p_scale
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT]
p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT]
numerator = NORMAL_PRESSURE * branch_pit[:, TINIT]
normfactor_from = numerator * fluid.get_property("compressibility", p_from) \
/ (p_from * NORMAL_TEMPERATURE)
Expand Down
6 changes: 2 additions & 4 deletions pandapipes/component_models/pipe_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,10 @@ def get_internal_results(cls, net, pipe):
gas_mode = fluid.is_gas

if gas_mode:
p_scale = get_net_option(net, "p_scale")

from_nodes = pipe_pit[v_nodes, FROM_NODE].astype(np.int32)
to_nodes = pipe_pit[v_nodes, TO_NODE].astype(np.int32)
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] * p_scale
p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] * p_scale
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT]
p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT]
p_mean = np.where(p_from == p_to, p_from,
2 / 3 * (p_from ** 3 - p_to ** 3) / (p_from ** 2 - p_to ** 2))
numerator = NORMAL_PRESSURE * node_pit[v_nodes, TINIT_NODE]
Expand Down
5 changes: 2 additions & 3 deletions pandapipes/component_models/pump_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ def calculate_pressure_lift(cls, net, pump_pit, node_pit):
area = pump_pit[:, AREA]
idx = pump_pit[:, STD_TYPE].astype(int)
std_types = np.array(list(net.std_type['pump'].keys()))[idx]
p_scale = get_net_option(net, "p_scale")
from_nodes = pump_pit[:, FROM_NODE].astype(np.int32)
# to_nodes = pump_pit[:, TO_NODE].astype(np.int32)
fluid = get_fluid(net)
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] * p_scale
# p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] * p_scale
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT]
# p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT]
numerator = NORMAL_PRESSURE * pump_pit[:, TINIT]
v_mps = pump_pit[:, VINIT]
if fluid.is_gas:
Expand Down
2 changes: 1 addition & 1 deletion pandapipes/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def create_heat_exchanger(net, from_junction, to_junction, diameter_m, qext_w, l
:type diameter_m: float
:param qext_w: External heat flux in [W]. If positive, heat is derived from the network. If
negative, heat is being fed into the network from a heat source.
:type qext_w: float, default 0.0
:type qext_w: float
:param loss_coefficient: An additional pressure loss coefficient, introduced by e.g. bends
:type loss_coefficient: float
:param name: The name of the heat exchanger
Expand Down
28 changes: 20 additions & 8 deletions pandapipes/io/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pandapower.io_utils import PPJSONEncoder, to_dict_with_coord_transform, \
get_raw_data_from_pickle, transform_net_with_df_and_geo, PPJSONDecoder
from pandapower.io_utils import pp_hook
from pandapower.io_utils import pp_hook, encrypt_string, decrypt_string

from pandapipes.io.convert_format import convert_format
from pandapipes.io.io_utils import isinstance_partial, FromSerializableRegistryPpipe
Expand Down Expand Up @@ -42,7 +42,7 @@ def to_pickle(net, filename):
pickle.dump(save_net, f, protocol=2) # use protocol 2 for py2 / py3 compatibility


def to_json(net, filename=None):
def to_json(net, filename=None, encryption_key=None):
"""
Saves a pandapipes Network in JSON format. The index columns of all pandas DataFrames will be
saved in ascending order. net elements which name begins with "_" (internal elements) will not
Expand All @@ -53,20 +53,25 @@ def to_json(net, filename=None):
:param filename: The absolute or relative path to the output file or a writable file-like \
object. If None, a JSON string is returned.
:type filename: str, file-object, default None
:param encryption_key: If given, the pandapipes network is stored as an encrypted json string
:type encryption_key: str, default None
:return: JSON string of the Network (only if filename is None)
:Example:
>>> pandapipes.to_json(net, "example.json")
"""
json_string = json.dumps(net, cls=PPJSONEncoder, indent=2, isinstance_func=isinstance_partial)
if encryption_key is not None:
json_string = encrypt_string(json_string, encryption_key)
if filename is None:
return json.dumps(net, cls=PPJSONEncoder, indent=2, isinstance_func=isinstance_partial)
return json_string
if hasattr(filename, 'write'):
json.dump(net, fp=filename, cls=PPJSONEncoder, indent=2, isinstance_func=isinstance_partial)
filename.write(json_string)
else:
with open(filename, "w") as fp:
json.dump(net, fp=fp, cls=PPJSONEncoder, indent=2, isinstance_func=isinstance_partial)
fp.write(json_string)


def from_pickle(filename):
Expand All @@ -89,7 +94,7 @@ def from_pickle(filename):
return net


def from_json(filename, convert=True):
def from_json(filename, convert=True, encryption_key=None):
"""
Load a pandapipes network from a JSON file or string.
The index of the returned network is not necessarily in the same order as the original network.
Expand All @@ -99,6 +104,8 @@ def from_json(filename, convert=True):
:type filename: str, file-object
:param convert: whether or not to convert the format from earlier versions
:type convert: bool
:param encryption_key: if given, key to decrypt an encrypted pandapower network
:type encryption_key: str
:return: net - The pandapipes network that was saved as JSON
:rtype: pandapipesNet
Expand All @@ -114,10 +121,10 @@ def from_json(filename, convert=True):
else:
with open(filename) as fp:
json_string = fp.read()
return from_json_string(json_string, convert=convert)
return from_json_string(json_string, convert=convert, encryption_key=encryption_key)


def from_json_string(json_string, convert=False):
def from_json_string(json_string, convert=False, encryption_key=None):
"""
Load a pandapipes network from a JSON string.
The index of the returned network is not necessarily in the same order as the original network.
Expand All @@ -127,6 +134,8 @@ def from_json_string(json_string, convert=False):
:type json_string: str
:param convert: whether or not to convert the format from earlier versions
:type convert: bool
:param encryption_key: if given, key to decrypt an encrypted pandapower network
:type encryption_key: str
:return: net - The pandapipes network that was contained in the JSON string
:rtype: pandapipesNet
Expand All @@ -135,6 +144,9 @@ def from_json_string(json_string, convert=False):
>>> net = pandapipes.from_json_string(json_str)
"""
if encryption_key is not None:
json_string = decrypt_string(json_string, encryption_key)

net = json.loads(json_string, cls=PPJSONDecoder, object_hook=partial(pp_hook,
registry_class=FromSerializableRegistryPpipe))

Expand Down
3 changes: 1 addition & 2 deletions pandapipes/multinet/control/run_control_multinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ def run_control(multinet, ctrl_variables=None, max_iter=30, **kwargs):
- run (funct, e.g. pandapower.runpp, pandapipes.pipeflow): function to be used to
conduct a loadflow/pipeflow \n
- initial_run (boolean): Is a initial_run for a net required or not\n
- continue_on_divergence (boolean): What to do if loadflow/pipeflow is not converging,
fires control_repair
- continue_on_divergence (boolean): What to do if loadflow/pipeflow is not converging, fires control_repair
:type ctrl_variables: dict, default: None
:param max_iter: number of iterations for each controller to converge
:type max_iter: int, default: 30
Expand Down
1 change: 1 addition & 0 deletions pandapipes/networks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

from pandapipes.networks.simple_gas_networks import *
from pandapipes.networks.simple_water_networks import *
from pandapipes.networks.simple_heat_transfer_networks import *
18 changes: 9 additions & 9 deletions pandapipes/networks/simple_heat_transfer_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def heat_transfer_delta():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_delta()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_delta()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "delta.json"))
Expand All @@ -35,7 +35,7 @@ def heat_transfer_delta_2sinks():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_delta_2sinks()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_delta_2sinks()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "delta_2sinks.json"))
Expand All @@ -48,7 +48,7 @@ def heat_transfer_heights():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_heights()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_heights()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "heights.json"))
Expand All @@ -61,7 +61,7 @@ def heat_transfer_one_pipe():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_one_pipe()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_one_pipe()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "one_pipe.json"))
Expand All @@ -74,7 +74,7 @@ def heat_transfer_one_source():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_one_source()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_one_source()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "one_source.json"))
Expand All @@ -87,7 +87,7 @@ def heat_transfer_section_variation():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_section_variation()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_section_variation()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "section_variation.json"))
Expand All @@ -100,7 +100,7 @@ def heat_transfer_t_cross():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_t_cross()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_t_cross()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "t_cross.json"))
Expand All @@ -113,7 +113,7 @@ def heat_transfer_two_pipes():
:rtype: pandapipesNet
:Example:
>>> pandapipes.networks.simple_water_networks.heat_transfer_two_pipes()
>>> pandapipes.networks.simple_heat_transfer_networks.heat_transfer_two_pipes()
"""
return from_json(os.path.join(heat_tranfer_modelica_path, "two_pipes.json"))
return from_json(os.path.join(heat_tranfer_modelica_path, "two_pipes.json"))
10 changes: 3 additions & 7 deletions pandapipes/pipeflow_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

default_options = {"friction_model": "nikuradse", "converged": False, "tol_p": 1e-4, "tol_v": 1e-4,
"tol_T": 1e-3, "tol_res": 1e-3, "iter": 10, "error_flag": False, "alpha": 1,
"nonlinear_method": "constant", "p_scale": 1, "mode": "hydraulics",
"nonlinear_method": "constant", "mode": "hydraulics",
"ambient_temperature": 293, "check_connectivity": True,
"max_iter_colebrook": 100, "only_update_hydraulic_matrix": False,
"reuse_internal_data": False,
Expand Down Expand Up @@ -229,12 +229,8 @@ def init_options(net, local_parameters):
same in each iteration) or "automatic", in which case **alpha** is adapted \
automatically with respect to the convergence behaviour.
- **gas_impl** (str): "pandapipes" - Implementation of the gas model. It can be set to\
"pandapipes" with calculations according to "Handbuch der Gasversorgungstechnik"\
or to "STANET" with calculations according to the STANET reference.
- **heat_transfer** (bool): False - Flag to determine if the heat transfer shall be\
calculated.
- **mode** (str): "hydraulics" - Define the calculation mode: what shall be calculated -
solely hydraulics ('hydraulic'), solely heat transfer('heat') or both combined ('all').
- **only_update_hydraulic_matrix** (bool): False - If True, the system matrix is not \
created in every iteration, but only the data is updated according to a lookup that\
Expand Down
14 changes: 7 additions & 7 deletions pandapipes/properties/fluids.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ def get_molar_mass(self):

return self.get_property("molar_mass")

def get_compressibility(self, temperature):
def get_compressibility(self, p_bar):
"""
This function returns the compressibility at a certain temperature.
This function returns the compressibility at a certain pressure.
:param temperature: Temperature at which the compressibility is queried
:type temperature: float
:return: compressibility at the required temperature
:param p_bar: pressure at which the compressibility is queried
:type p_bar: float or array of floats
:return: compressibility at the required pressure
"""

return self.get_property("compressibility", temperature)
return self.get_property("compressibility", p_bar)

def get_der_compressibility(self):
"""
This function returns the derivative of the compressibility.
This function returns the derivative of the compressibility with respect to pressure.
:return: derivative of the compressibility
Expand Down
Loading

0 comments on commit 26a343b

Please sign in to comment.