1
|
|
# Copyright (c) 2020 by Fraunhofer Institute for Energy Economics
|
2
|
|
# and Energy System Technology (IEE), Kassel. All rights reserved.
|
3
|
|
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
4
|
|
|
5
|
1
|
import numpy as np
|
6
|
1
|
import pandas as pd
|
7
|
1
|
from pandapipes.constants import NORMAL_PRESSURE, TEMP_GRADIENT_KPM, AVG_TEMPERATURE_K, \
|
8
|
|
HEIGHT_EXPONENT
|
9
|
|
|
10
|
|
|
11
|
1
|
def p_correction_height_air(height):
|
12
|
|
"""
|
13
|
|
|
14
|
|
:param height:
|
15
|
|
:type height:
|
16
|
|
:return:
|
17
|
|
:rtype:
|
18
|
|
"""
|
19
|
1
|
return NORMAL_PRESSURE * np.power(1 - height * TEMP_GRADIENT_KPM / AVG_TEMPERATURE_K,
|
20
|
|
HEIGHT_EXPONENT)
|
21
|
|
|
22
|
|
|
23
|
1
|
def vinterp(min_vals, max_vals, lengths):
|
24
|
|
"""
|
25
|
|
|
26
|
|
:param min_vals:
|
27
|
|
:type min_vals:
|
28
|
|
:param max_vals:
|
29
|
|
:type max_vals:
|
30
|
|
:param lengths: lengths for each range (same length as starts)
|
31
|
|
:type lengths: numpy.array
|
32
|
|
:return:
|
33
|
|
:rtype:
|
34
|
|
"""
|
35
|
1
|
intervals = (max_vals - min_vals) / (lengths + 1)
|
36
|
1
|
steps = np.repeat(intervals, lengths)
|
37
|
1
|
counter = np.arange(lengths.sum()) - np.repeat(lengths.cumsum() - lengths, lengths) + 1
|
38
|
1
|
return np.repeat(min_vals, lengths) + steps * counter
|
39
|
|
|
40
|
|
|
41
|
1
|
def vrange(starts, lengths):
|
42
|
|
"""
|
43
|
|
Create concatenated ranges of integers for multiple start/length
|
44
|
|
|
45
|
|
:param starts: starts for each range
|
46
|
|
:type starts: numpy.array
|
47
|
|
:param lengths: lengths for each range (same length as starts)
|
48
|
|
:type lengths: numpy.array
|
49
|
|
:return: cat_range - concatenated ranges
|
50
|
|
:rtype: numpy.array
|
51
|
|
|
52
|
|
:Example:
|
53
|
|
>>> starts = np.array([1, 3, 4, 6])
|
54
|
|
>>> lengths = np.array([0, 2, 3, 0])
|
55
|
|
>>> print vrange(starts, lengths)
|
56
|
|
"""
|
57
|
|
# Repeat start position index length times and concatenate
|
58
|
0
|
starting_array = np.repeat(starts, lengths)
|
59
|
|
# Create group counter that resets for each start/length
|
60
|
0
|
length_ranges = np.arange(lengths.sum()) - np.repeat(lengths.cumsum() - lengths, lengths)
|
61
|
|
# Add group counter to group specific starts
|
62
|
0
|
return starting_array + length_ranges
|
63
|
|
|
64
|
|
|
65
|
1
|
def init_results_element(net, element, output, all_float):
|
66
|
|
"""
|
67
|
|
|
68
|
|
:param net: The pandapipes network
|
69
|
|
:type net: pandapipesNet
|
70
|
|
:param element:
|
71
|
|
:type element:
|
72
|
|
:param output:
|
73
|
|
:type output:
|
74
|
|
:param all_float:
|
75
|
|
:type all_float:
|
76
|
|
:return: No Output.
|
77
|
|
"""
|
78
|
1
|
res_element = "res_" + element
|
79
|
1
|
if all_float:
|
80
|
1
|
net[res_element] = pd.DataFrame(np.NAN, columns=output, index=net[element].index,
|
81
|
|
dtype=np.float64)
|
82
|
|
else:
|
83
|
0
|
net[res_element] = pd.DataFrame(np.zeros(0, dtype=output), index=[])
|
84
|
0
|
net[res_element] = pd.DataFrame(np.NaN, index=net[element].index,
|
85
|
|
columns=net[res_element].columns)
|
86
|
|
|
87
|
|
|
88
|
1
|
def add_new_component(net, component, overwrite=False):
|
89
|
|
"""
|
90
|
|
|
91
|
|
:param net:
|
92
|
|
:type net:
|
93
|
|
:param component:
|
94
|
|
:type component:
|
95
|
|
:param overwrite:
|
96
|
|
:type overwrite:
|
97
|
|
:return:
|
98
|
|
:rtype:
|
99
|
|
"""
|
100
|
1
|
name = component.table_name()
|
101
|
1
|
if not overwrite and name in net:
|
102
|
|
# logger.info('%s is already in net. Try overwrite if you want to get a new entry' %name)
|
103
|
1
|
return
|
104
|
|
else:
|
105
|
1
|
if hasattr(component, 'geodata'):
|
106
|
1
|
geodata = component.geodata()
|
107
|
|
else:
|
108
|
1
|
geodata = None
|
109
|
|
|
110
|
1
|
comp_input = component.get_component_input()
|
111
|
1
|
if name not in net:
|
112
|
1
|
net['component_list'].append(component)
|
113
|
1
|
net.update({name: comp_input})
|
114
|
1
|
if isinstance(net[name], list):
|
115
|
1
|
net[name] = pd.DataFrame(np.zeros(0, dtype=net[name]), index=[])
|
116
|
|
# init_empty_results_table(net, name, component.get_result_table(net))
|
117
|
|
|
118
|
1
|
if geodata is not None:
|
119
|
1
|
net.update({name + '_geodata': geodata})
|
120
|
1
|
if isinstance(net[name + '_geodata'], list):
|
121
|
1
|
net[name + '_geodata'] = pd.DataFrame(np.zeros(0, dtype=net[name + '_geodata']),
|
122
|
|
index=[])
|