e2nIEE / pandapipes

Compare da3d2d8 ... +60 ... 06d7494

Coverage Reach
pandapipes/component_models/abstract_models/branch_models.py pandapipes/component_models/abstract_models/branch_w_internals_models.py pandapipes/component_models/abstract_models/branch_wo_internals_models.py pandapipes/component_models/abstract_models/const_flow_models.py pandapipes/component_models/abstract_models/branch_wzerolength_models.py pandapipes/component_models/abstract_models/circulation_pump.py pandapipes/component_models/abstract_models/base_component.py pandapipes/component_models/abstract_models/node_models.py pandapipes/component_models/abstract_models/node_element_models.py pandapipes/component_models/abstract_models/__init__.py pandapipes/component_models/auxiliaries/build_system_matrix.py pandapipes/component_models/auxiliaries/derivative_toolbox.py pandapipes/component_models/auxiliaries/component_toolbox.py pandapipes/component_models/auxiliaries/__init__.py pandapipes/component_models/pipe_component.py pandapipes/component_models/pump_component.py pandapipes/component_models/ext_grid_component.py pandapipes/component_models/pressure_control_component.py pandapipes/component_models/junction_component.py pandapipes/component_models/heat_exchanger_component.py pandapipes/component_models/valve_component.py pandapipes/component_models/compressor_component.py pandapipes/component_models/circulation_pump_pressure_component.py pandapipes/component_models/circulation_pump_mass_component.py pandapipes/component_models/__init__.py pandapipes/component_models/sink_component.py pandapipes/component_models/source_component.py pandapipes/plotting/collections.py pandapipes/plotting/patch_makers.py pandapipes/plotting/simple_plot.py pandapipes/plotting/generic_geodata.py pandapipes/plotting/__init__.py pandapipes/plotting/pipeflow_results.py pandapipes/plotting/plotting_toolbox.py pandapipes/multinet/control/controller/multinet_control.py pandapipes/multinet/control/controller/__init__.py pandapipes/multinet/control/run_control_multinet.py pandapipes/multinet/control/__init__.py pandapipes/multinet/timeseries/run_time_series_multinet.py pandapipes/multinet/timeseries/__init__.py pandapipes/multinet/multinet.py pandapipes/multinet/create_multinet.py pandapipes/multinet/__init__.py pandapipes/networks/simple_water_networks.py pandapipes/networks/simple_gas_networks.py pandapipes/networks/simple_heat_transfer_networks.py pandapipes/networks/nw_aux.py pandapipes/networks/__init__.py pandapipes/properties/fluids.py pandapipes/properties/properties_toolbox.py pandapipes/properties/__init__.py pandapipes/create.py pandapipes/pipeflow_setup.py pandapipes/pipeflow.py pandapipes/toolbox.py pandapipes/io/io_utils.py pandapipes/io/file_io.py pandapipes/io/convert_format.py pandapipes/io/__init__.py pandapipes/std_types/std_type.py pandapipes/std_types/std_type_toolbox.py pandapipes/std_types/__init__.py pandapipes/topology/create_graph.py pandapipes/topology/graph_searches.py pandapipes/topology/__init__.py pandapipes/timeseries/run_time_series.py pandapipes/timeseries/__init__.py pandapipes/idx_branch.py pandapipes/pandapipes_net.py pandapipes/internals_toolbox.py pandapipes/idx_node.py pandapipes/control/run_control.py pandapipes/control/__init__.py pandapipes/__init__.py pandapipes/constants.py setup.py

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 19 of 27 files from the diff.

@@ -31,7 +31,7 @@
Loading
31 31
        polys.append(RegularPolygon(centroid_tri1, numVertices=3, radius=size, orientation=-angle,
32 32
                                    ec=col, fc=face_col, lw=lw))
33 33
        polys.append(RegularPolygon(centroid_tri2, numVertices=3, radius=size,
34 -
                                    orientation=-angle+np.pi/3, ec=col, fc=face_col, lw=lw))
34 +
                                    orientation=-angle + np.pi / 3, ec=col, fc=face_col, lw=lw))
35 35
        lines.append([p1, p1 + diff / 2 - vec_size / 2 * 3])
36 36
        lines.append([p2, p1 + diff / 2 + vec_size / 2 * 3])
37 37
    return lines, polys, {"filled"}
@@ -45,16 +45,16 @@
Loading
45 45
    for geodata, col in zip(coords, colors):
46 46
        p1, p2 = np.array(geodata[0]), np.array(geodata[-1])
47 47
        diff = p2 - p1
48 -
        m = 3*size/4
49 -
        direc= diff/np.sqrt(diff[0]**2+diff[1]**2)
48 +
        m = 3 * size / 4
49 +
        direc = diff / np.sqrt(diff[0] ** 2 + diff[1] ** 2)
50 50
        normal = np.array([-direc[1], direc[0]])
51 -
        path1 = (p1 + diff / 2+ direc *m/2) + normal * (size * 9 / 8)
52 -
        path2 = p1 + diff / 2 + direc *m / 2
51 +
        path1 = (p1 + diff / 2 + direc * m / 2) + normal * (size * 9 / 8)
52 +
        path2 = p1 + diff / 2 + direc * m / 2
53 53
        path3 = p1 + diff / 2 + normal * size / 3
54 -
        path4 = p1 + diff / 2 - direc *m/2
55 -
        path5 = (p1 + diff / 2- direc *m/2)  + normal * (size * 9 / 8)
56 -
        path =[path1, path2, path3, path4, path5]
57 -
        radius = size #np.sqrt(diff[0]**2+diff[1]**2)/15
54 +
        path4 = p1 + diff / 2 - direc * m / 2
55 +
        path5 = (p1 + diff / 2 - direc * m / 2) + normal * (size * 9 / 8)
56 +
        path = [path1, path2, path3, path4, path5]
57 +
        radius = size  # np.sqrt(diff[0]**2+diff[1]**2)/15
58 58
59 59
        pa = Path(path)
60 60
        polys.append(Circle(p1 + diff / 2, radius=radius, edgecolor=col, facecolor="w", lw=lw))
@@ -111,15 +111,43 @@
Loading
111 111
        diff = p2 - p1
112 112
        angle = np.arctan2(*diff)
113 113
        vec_size = _rotate_dim2(np.array([0, size]), angle)
114 -
        line1 = _rotate_dim2(np.array([0, size * np.sqrt(2)]), angle - np.pi/4)
115 -
        line2 = _rotate_dim2(np.array([0, size * np.sqrt(2)]), angle + np.pi/4)
114 +
        line1 = _rotate_dim2(np.array([0, size * np.sqrt(2)]), angle - np.pi / 4)
115 +
        line2 = _rotate_dim2(np.array([0, size * np.sqrt(2)]), angle + np.pi / 4)
116 116
        radius = size
117 117
118 118
        polys.append(Circle(p1 + diff / 2, radius=radius, edgecolor=col, facecolor='w', lw=lw))
119 119
120 -
        lines.append([p1+diff/2+vec_size, p1+diff/2-vec_size+line1])
121 -
        lines.append([p1+diff/2+vec_size, p1+diff/2-vec_size+line2])
120 +
        lines.append([p1 + diff / 2 + vec_size, p1 + diff / 2 - vec_size + line1])
121 +
        lines.append([p1 + diff / 2 + vec_size, p1 + diff / 2 - vec_size + line2])
122 122
123 123
        lines.append([p1, p1 + diff / 2 - vec_size])
124 124
        lines.append([p2, p1 + diff / 2 + vec_size])
125 125
    return lines, polys, {}
126 +
127 +
128 +
def pressure_control_patches(coords, size, **kwargs):
129 +
    polys, lines = list(), list()
130 +
    edgecolor = kwargs.pop('patch_edgecolor')
131 +
    colors = get_color_list(edgecolor, len(coords))
132 +
    lw = kwargs.get("linewidths", 2.)
133 +
    for geodata, col in zip(coords, colors):
134 +
        p1, p2 = np.array(geodata[0]), np.array(geodata[-1])
135 +
        diff = p2 - p1
136 +
        angle = np.arctan2(*diff)
137 +
        vec_size = _rotate_dim2(np.array([0, size]), angle)
138 +
        vec_size_or = _rotate_dim2(np.array([0, size * 1.2 / 2]), angle + np.pi / 2)
139 +
        pll = p1 + diff / 2 - vec_size + vec_size_or
140 +
        plr = p1 + diff / 2 - vec_size - vec_size_or
141 +
        pul = p1 + diff / 2 + vec_size + vec_size_or/3
142 +
        pur = p1 + diff / 2 + vec_size - vec_size_or/3
143 +
144 +
        polys.append(Rectangle(pll, 2 * size, size * 1.2, angle=np.rad2deg(-angle + np.pi/2),
145 +
                               edgecolor=col, facecolor='w', lw=lw))
146 +
147 +
        lines.append([p1, p1 + diff / 2 - vec_size])
148 +
        lines.append([p2, p1 + diff / 2 + vec_size])
149 +
150 +
        lines.append([pll, pul])
151 +
        lines.append([plr, pur])
152 +
153 +
    return lines, polys, {}

@@ -8,8 +8,8 @@
Loading
8 8
    _create_node_element_collection, _create_line2d_collection, _create_complex_branch_collection, \
9 9
    add_cmap_to_collection, coords_from_node_geodata
10 10
from pandapower.plotting.patch_makers import load_patches, ext_grid_patches
11 -
from pandapipes.plotting.patch_makers import valve_patches, source_patches, heat_exchanger_patches,\
12 -
    pump_patches
11 +
from pandapipes.plotting.patch_makers import valve_patches, source_patches, heat_exchanger_patches, \
12 +
    pump_patches, pressure_control_patches
13 13
from pandapower.plotting.plotting_toolbox import get_index_array
14 14
15 15
try:
@@ -490,3 +490,59 @@
Loading
490 490
        patch_edgecolor=patch_edgecolor, line_color=line_color, **kwargs)
491 491
492 492
    return lc, pc
493 +
494 +
495 +
def create_pressure_control_collection(net, pcs=None, table_name='press_control',
496 +
                                       size=5., junction_geodata=None,
497 +
                                       color='k', infofunc=None, picker=False, **kwargs):
498 +
    """
499 +
    Creates a matplotlib patch collection of pandapipes junction-junction valves. Valves are
500 +
    plotted in the center between two junctions with a "helper" line (dashed and thin) being drawn
501 +
    between the junctions as well.
502 +
503 +
    :param net: The pandapipes network
504 +
    :type net: pandapipesNet
505 +
    :param valves: The valves for which the collections are created. If None, all valves which have\
506 +
        entries in the respective junction geodata will be plotted.
507 +
    :type valves: list, default None
508 +
    :param size: Patch size
509 +
    :type size: float, default 5.
510 +
    :param junction_geodata: Coordinates to use for plotting. If None, net["junction_geodata"] is used.
511 +
    :type junction_geodata: pandas.DataFrame, default None
512 +
    :param colors: Color or list of colors for every valve
513 +
    :type colors: iterable, float, default None
514 +
    :param infofunc: infofunction for the patch element
515 +
    :type infofunc: function, default None
516 +
    :param picker: Picker argument passed to the patch collection
517 +
    :type picker: bool, default False
518 +
    :param fill_closed: If True, valves with parameter opened == False will be filled and those\
519 +
        with opened == True will have a white facecolor. Vice versa if False.
520 +
    :type fill_closed: bool, default True
521 +
    :param kwargs: Keyword arguments are passed to the patch function
522 +
    :return: lc - line collection, pc - patch collection
523 +
524 +
    """
525 +
    pcs = get_index_array(pcs, net[table_name].index)
526 +
    pc_table = net[table_name].loc[pcs]
527 +
528 +
    coords, pcs_with_geo = coords_from_node_geodata(
529 +
        pcs, pc_table.from_junction.values, pc_table.to_junction.values,
530 +
        junction_geodata if junction_geodata is not None else net["junction_geodata"], table_name,
531 +
        "Junction")
532 +
533 +
    if len(pcs_with_geo) == 0:
534 +
        return None
535 +
536 +
    linewidths = kwargs.pop("linewidths", 2.)
537 +
    linewidths = kwargs.pop("linewidth", linewidths)
538 +
    linewidths = kwargs.pop("lw", linewidths)
539 +
540 +
    infos = list(np.repeat([infofunc(i) for i in range(len(pcs_with_geo))], 2)) \
541 +
        if infofunc is not None else []
542 +
    lc, pc = _create_complex_branch_collection(coords, pressure_control_patches, size, infos,
543 +
                                               picker=picker, linewidths=linewidths,
544 +
                                               patch_edgecolor=color, line_color=color,
545 +
                                               **kwargs)
546 +
547 +
    return lc, pc
548 +

@@ -6,6 +6,7 @@
Loading
6 6
P = 1  # Reference node, pressure is fixed
7 7
L = 2  # All other nodes
8 8
T = 10  # Reference node with fixed temperature, otherwise 0
9 +
PC = 20  # Controlled node with fixed pressure p
9 10
NONE = 3  # None
10 11
11 12
# define the indices

@@ -101,8 +101,8 @@
Loading
101 101
102 102
        :param net: The pandapipes network
103 103
        :type net: pandapipesNet
104 -
        :param branch_component_pit:
105 -
        :type branch_component_pit:
104 +
        :param branch_pit:
105 +
        :type branch_pit:
106 106
        :param node_pit:
107 107
        :type node_pit:
108 108
        :param idx_lookups:
@@ -201,6 +201,7 @@
Loading
201 201
        mass_flow_dv = rho * branch_component_pit[:, AREA]
202 202
        branch_component_pit[:, JAC_DERIV_DV_NODE] = mass_flow_dv
203 203
        branch_component_pit[:, LOAD_VEC_NODES] = mass_flow_dv * v_init
204 +
        return branch_component_pit
204 205
205 206
    @classmethod
206 207
    def calculate_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options):
@@ -370,3 +371,4 @@
Loading
370 371
            _sum_by_group(idx_pit, branch_pit[:, LAMBDA], branch_pit[:, RE])
371 372
        res_table["lambda"].values[placement_table] = lambda_sum / internal_pipes
372 373
        res_table["reynolds"].values[placement_table] = reynolds_sum / internal_pipes
374 +
        return placement_table, res_table, branch_pit, node_pit

@@ -0,0 +1,174 @@
Loading
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 +
import numpy as np
6 +
from numpy import dtype
7 +
from pandapipes.constants import R_UNIVERSAL
8 +
9 +
from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent, get_fluid, \
10 +
    TINIT_NODE
11 +
from pandapipes.idx_branch import D, AREA, PL, TL, \
12 +
    JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, BRANCH_TYPE, FROM_NODE, TO_NODE, VINIT, \
13 +
    LOAD_VEC_NODES, ELEMENT_IDX, LOSS_COEFFICIENT as LC
14 +
from pandapipes.idx_node import PINIT, NODE_TYPE, PC
15 +
from pandapipes.internals_toolbox import _sum_by_group
16 +
from pandapipes.pipeflow_setup import get_lookup, get_net_option
17 +
18 +
19 +
class PressureControlComponent(BranchWZeroLengthComponent):
20 +
    """
21 +
22 +
    """
23 +
24 +
    @classmethod
25 +
    def table_name(cls):
26 +
        return "press_control"
27 +
28 +
    @classmethod
29 +
    def active_identifier(cls):
30 +
        return "in_service"
31 +
32 +
    @classmethod
33 +
    def from_to_node_cols(cls):
34 +
        return "from_junction", "to_junction"
35 +
36 +
    @classmethod
37 +
    def create_pit_node_entries(cls, net, node_pit, node_name):
38 +
        pcs = net[cls.table_name()]
39 +
        controlled = pcs.in_service & pcs.control_active
40 +
        juncts = pcs['controlled_junction'].values[controlled]
41 +
        press = pcs['controlled_p_bar'].values[controlled]
42 +
        junction_idx_lookups = get_lookup(net, "node", "index")[node_name]
43 +
        index_pc = junction_idx_lookups[juncts]
44 +
        node_pit[index_pc, NODE_TYPE] = PC
45 +
        node_pit[index_pc, PINIT] = press
46 +
47 +
    @classmethod
48 +
    def create_pit_branch_entries(cls, net, pc_pit, node_name):
49 +
        """
50 +
        Function which creates pit branch entries with a specific table.
51 +
        :param net: The pandapipes network
52 +
        :type net: pandapipesNet
53 +
        :param pc_pit:
54 +
        :type pc_pit:
55 +
        :param node_name:
56 +
        :type node_name:
57 +
        :return: No Output.
58 +
        """
59 +
        pc_pit = super().create_pit_branch_entries(net, pc_pit, node_name)
60 +
        pc_pit[:, D] = 0.1
61 +
        pc_pit[:, AREA] = pc_pit[:, D] ** 2 * np.pi / 4
62 +
        pc_pit[net[cls.table_name()].control_active.values, BRANCH_TYPE] = PC
63 +
        pc_pit[:, LC] = net[cls.table_name()].loss_coefficient.values
64 +
65 +
    @classmethod
66 +
    def calculate_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
67 +
        press_pit = super().calculate_derivatives_hydraulic(net, branch_pit, node_pit, idx_lookups,
68 +
                                                            options)
69 +
        pc_branch = press_pit[:, BRANCH_TYPE] == PC
70 +
        press_pit[pc_branch, JAC_DERIV_DP] = 0
71 +
        press_pit[pc_branch, JAC_DERIV_DP1] = 0
72 +
        press_pit[pc_branch, JAC_DERIV_DV] = 0
73 +
74 +
    @classmethod
75 +
    def calculate_pressure_lift(cls, net, pc_pit, node_pit):
76 +
        """
77 +
78 +
        :param net: The pandapipes network
79 +
        :type net: pandapipesNet
80 +
        :param pc_pit:
81 +
        :type pc_pit:
82 +
        :param node_pit:
83 +
        :type node_pit:
84 +
        :return: power stroke
85 +
        :rtype: float
86 +
        """
87 +
        pc_pit[:, PL] = 0
88 +
89 +
    @classmethod
90 +
    def calculate_temperature_lift(cls, net, pc_pit, node_pit):
91 +
        """
92 +
93 +
        :param net:
94 +
        :type net:
95 +
        :param pc_pit:
96 +
        :type pc_pit:
97 +
        :param node_pit:
98 +
        :type node_pit:
99 +
        :return:
100 +
        :rtype:
101 +
        """
102 +
        pc_pit[:, TL] = 0
103 +
104 +
    @classmethod
105 +
    def extract_results(cls, net, options, node_name):
106 +
        """
107 +
        Function that extracts certain results.
108 +
109 +
        :param net: The pandapipes network
110 +
        :type net: pandapipesNet
111 +
        :param options:
112 +
        :type options:
113 +
        :param node_name:
114 +
        :type node_name:
115 +
        :return: No Output.
116 +
        """
117 +
118 +
        placement_table, res_table, pc_pit, node_pit = super().extract_results(net, options, node_name)
119 +
120 +
        node_active_idx_lookup = get_lookup(net, "node", "index_active")[node_name]
121 +
        junction_idx_lookup = get_lookup(net, "node", "index")[node_name]
122 +
        from_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
123 +
            net[cls.table_name()]["from_junction"].values[placement_table]]]
124 +
        to_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
125 +
            net[cls.table_name()]["to_junction"].values[placement_table]]]
126 +
127 +
        p_to = node_pit[to_junction_nodes, PINIT]
128 +
        p_from = node_pit[from_junction_nodes, PINIT]
129 +
        res_table['deltap_bar'].values[placement_table] = p_to - p_from
130 +
131 +
        return placement_table, res_table, pc_pit
132 +
133 +
    @classmethod
134 +
    def get_component_input(cls):
135 +
        """
136 +
137 +
        Get component input.
138 +
139 +
        :return:
140 +
        :rtype:
141 +
        """
142 +
        return [("name", dtype(object)),
143 +
                ("from_junction", "u4"),
144 +
                ("to_junction", "u4"),
145 +
                ("controlled_junction", "u4"),
146 +
                ("controlled_p_bar", "f8"),
147 +
                ("control_active", "bool"),
148 +
                ("loss_coefficient", "f8"),
149 +
                ("in_service", 'bool'),
150 +
                ("type", dtype(object))]
151 +
152 +
    @classmethod
153 +
    def get_result_table(cls, net):
154 +
        """
155 +
156 +
        Gets the result table.
157 +
158 +
        :param net: The pandapipes network
159 +
        :type net: pandapipesNet
160 +
        :return: (columns, all_float) - the column names and whether they are all float type. Only
161 +
                if False, returns columns as tuples also specifying the dtypes
162 +
        :rtype: (list, bool)
163 +
        """
164 +
        if get_fluid(net).is_gas:
165 +
            output = ["v_from_m_per_s", "v_to_m_per_s", "v_mean_m_per_s", "p_from_bar", "p_to_bar",
166 +
                      "t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
167 +
                      "vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
168 +
                      "normfactor_to"]
169 +
        else:
170 +
            output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
171 +
                      "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s", "reynolds",
172 +
                      "lambda"]
173 +
        output += ["deltap_bar"]
174 +
        return output, True

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 5 files with coverage changes found.

New file pandapipes/component_models/compressor_component.py
New
Loading file...
New file pandapipes/component_models/pressure_control_component.py
New
Loading file...
Changes in pandapipes/properties/fluids.py
-1
+1
Loading file...
Changes in pandapipes/topology/create_graph.py
-1
+1
Loading file...
Changes in pandapipes/component_models/heat_exchanger_component.py
-1
+1
Loading file...

62 Commits

Hiding 16 contexual commits
+1 Files
+58
+56
+2
Hiding 12 contexual commits
+4 Files
+397
+360
+37
Hiding 20 contexual commits
+9 Files
+237
+216
+21
Hiding 8 contexual commits
-12 Files
-482
-423
-59
Files Coverage
pandapipes 0.45% 91.41%
setup.py 0.00%
Project Totals (76 files) 91.09%
Loading