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

custom components #658

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
5 changes: 5 additions & 0 deletions src/pandapipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
pd.options.mode.chained_assignment = None # default='warn'
pp_dir = os.path.dirname(os.path.realpath(__file__))


from pandapipes.utils.internals import *
from pandapipes.properties.fluids import *
from pandapipes.component_models.component_registry import *
from pandapipes.component_models import *
from pandapipes.component_init import COMPONENT_REGISTRY, COMPONENT_LIST
from pandapipes.create import *
from pandapipes.io.file_io import *
from pandapipes.pipeflow import *
Expand Down
18 changes: 18 additions & 0 deletions src/pandapipes/component_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020-2024 by Fraunhofer Institute for Energy Economics
# 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.

from pandapipes.component_models.component_registry import ComponentRegistry
from pandapipes.component_models import Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, \
MassStorage, CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer, \
HeatExchanger, ValvePipe


# every high level Component from pandapipes should be initialized here
# if pandapipes implements a new component, it needs to be added to the COMPONENT_LIST

COMPONENT_LIST = [Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage,
CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer,
HeatExchanger, ValvePipe]

COMPONENT_REGISTRY = ComponentRegistry(COMPONENT_LIST).registry
43 changes: 27 additions & 16 deletions src/pandapipes/component_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
# 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.

from pandapipes.component_models.junction_component import *
from pandapipes.component_models.pipe_component import *
from pandapipes.component_models.valve_component import *
from pandapipes.component_models.ext_grid_component import *
from pandapipes.component_models.sink_component import *
from pandapipes.component_models.source_component import *
from pandapipes.component_models.heat_exchanger_component import *
from pandapipes.component_models.pump_component import *
from pandapipes.component_models.circulation_pump_mass_component import *
from pandapipes.component_models.circulation_pump_pressure_component import *
from pandapipes.component_models.pressure_control_component import *
from pandapipes.component_models.compressor_component import *
from pandapipes.component_models.flow_control_component import *
from pandapipes.component_models.mass_storage_component import *
from pandapipes.component_models.heat_consumer_component import *
from pandapipes.component_models.component_toolbox import *
from pandapipes.component_models.component_toolbox import *
from pandapipes.component_models.component_registry import register_component

# junction needs to be imported before node_element_models and branch_models
from pandapipes.component_models._base_component import Component
from pandapipes.component_models._node_models import NodeComponent
from pandapipes.component_models.junction_component import Junction

from pandapipes.component_models._node_element_models import NodeElementComponent
from pandapipes.component_models._branch_models import BranchComponent
from pandapipes.component_models._branch_element_models import BranchElementComponent
from pandapipes.component_models.pipe_component import Pipe

from pandapipes.component_models.valve_component import Valve
from pandapipes.component_models.ext_grid_component import ExtGrid
from pandapipes.component_models.sink_component import Sink
from pandapipes.component_models.source_component import Source
from pandapipes.component_models.heat_exchanger_component import HeatExchanger
from pandapipes.component_models.pump_component import Pump
from pandapipes.component_models.circulation_pump_mass_component import CirculationPumpMass
from pandapipes.component_models.circulation_pump_pressure_component import CirculationPumpPressure
from pandapipes.component_models.pressure_control_component import PressureControlComponent
from pandapipes.component_models.compressor_component import Compressor
from pandapipes.component_models.flow_control_component import FlowControlComponent
from pandapipes.component_models.mass_storage_component import MassStorage
from pandapipes.component_models.heat_consumer_component import HeatConsumer
from pandapipes.component_models.valve_pipe_component import ValvePipe
69 changes: 69 additions & 0 deletions src/pandapipes/component_models/_base_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2020-2024 by Fraunhofer Institute for Energy Economics
# 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.

from abc import ABC, abstractmethod
from pandapipes.utils.internals import init_results_element


class Component(ABC):

@property
@abstractmethod
def table_name(self):
...

Check warning on line 14 in src/pandapipes/component_models/_base_component.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/component_models/_base_component.py#L14

Added line #L14 was not covered by tests

@property
def active_identifier(self):
return "in_service"

@abstractmethod
def extract_results(self, net, options, branch_results, mode):
"""
Function that extracts certain results.

:param net: The pandapipes network
:type net: pandapipesNet
:param options:
:type options:
:param branch_results:
:type branch_results:
:param mode:
:type mode:
:return: No Output.
"""
...

Check warning on line 35 in src/pandapipes/component_models/_base_component.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/component_models/_base_component.py#L35

Added line #L35 was not covered by tests

@abstractmethod
def get_component_input(self):
"""

:return:
:rtype:
"""
...

Check warning on line 44 in src/pandapipes/component_models/_base_component.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/component_models/_base_component.py#L44

Added line #L44 was not covered by tests

@abstractmethod
def get_result_table(self, net):
"""
Get result table.

:param net: a pandapipes net
:type net: pandapipes.pandapipesNet
:return:
:rtype:
"""
...

Check warning on line 56 in src/pandapipes/component_models/_base_component.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/component_models/_base_component.py#L56

Added line #L56 was not covered by tests

def init_results(self, net):
"""
Function that intializes the result table for the component.

:param net: The pandapipes network
:type net: pandapipesNet
:return: No Output.
"""
output, all_float = self.get_result_table(net)
init_results_element(net, self.table_name, output, all_float)
res_table = net["res_" + self.table_name]
return res_table
63 changes: 63 additions & 0 deletions src/pandapipes/component_models/_branch_element_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (c) 2020-2024 by Fraunhofer Institute for Energy Economics
# 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.

from numpy import pi

from pandapipes.component_models._branch_models import BranchComponent
from pandapipes.idx_branch import FROM_NODE, TO_NODE, TOUTINIT, ELEMENT_IDX, ACTIVE, LENGTH, K, TEXT, ALPHA, D, AREA
from pandapipes.idx_node import TINIT as TINIT_NODE
from pandapipes.utils.internals import add_table_lookup


class BranchElementComponent(BranchComponent):
def create_branch_lookups(self, net, ft_lookups, table_lookup, idx_lookups, current_table,
current_start):
"""
Function which creates branch lookups.

:param net: The pandapipes network
:type net: pandapipesNet
:param ft_lookups:
:type ft_lookups:
:param table_lookup:
:type table_lookup:
:param idx_lookups:
:type idx_lookups:
:param current_table:
:type current_table:
:param current_start:
:type current_start:
:return:
:rtype:
"""
end = current_start + len(net[self.table_name])
ft_lookups[self.table_name] = (current_start, end)
add_table_lookup(table_lookup, self.table_name, current_table)
return end, current_table + 1

def create_pit_branch_entries(self, 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.
"""
branch_element_pit, node_pit, from_nodes, to_nodes \
= super().create_pit_branch_entries(net, branch_pit)
branch_element_pit[:, ELEMENT_IDX] = net[self.table_name].index.values
branch_element_pit[:, FROM_NODE] = from_nodes
branch_element_pit[:, TO_NODE] = to_nodes
branch_element_pit[:, TOUTINIT] = node_pit[to_nodes, TINIT_NODE]
branch_element_pit[:, ACTIVE] = net[self.table_name][self.active_identifier].values
##
branch_element_pit[:, LENGTH] = 0
branch_element_pit[:, K] = 1000
branch_element_pit[:, TEXT] = 293.15
branch_element_pit[:, ALPHA] = 0
branch_element_pit[:, D] = 0.1
branch_element_pit[:, AREA] = branch_element_pit[:, D] ** 2 * pi / 4
return branch_element_pit
72 changes: 72 additions & 0 deletions src/pandapipes/component_models/_branch_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) 2020-2024 by Fraunhofer Institute for Energy Economics
# 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.

from abc import abstractmethod
from numpy import array

from pandapipes.component_models._base_component import Component
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import MDOTINIT, branch_cols, TEXT
from pandapipes.utils.internals import get_net_option, get_table_number, get_lookup
from pandapipes.component_models.component_registry import ComponentRegistry


class BranchComponent(Component):

@property
def from_to_node_cols(self):
return "from_junction", "to_junction"

@property
def connected_node_type(self):
return Junction

@abstractmethod
def create_branch_lookups(self, net, ft_lookups, table_lookup, idx_lookups, current_table,
current_start):
"""
Function which creates branch lookups.

:param net: The pandapipes network
:type net: pandapipesNet
:param ft_lookups:
:type ft_lookups:
:param table_lookup:
:type table_lookup:
:param idx_lookups:
:type idx_lookups:
:param current_table:
:type current_table:
:param current_start:
:type current_start:
:return: No Output.
"""
...

Check warning on line 45 in src/pandapipes/component_models/_branch_models.py

View check run for this annotation

Codecov / codecov/patch

src/pandapipes/component_models/_branch_models.py#L45

Added line #L45 was not covered by tests

def create_pit_branch_entries(self, net, branch_pit):
"""
Function which creates pit branch entries.

:param net: The pandapipes network
:type net: pandapipesNet
:param branch_pit:
:type branch_pit:
:return: No Output.
"""
node_pit = net["_pit"]["node"]
f, t = get_lookup(net, "branch", "from_to")[self.table_name]
branch_table_nr = get_table_number(get_lookup(net, "branch", "table"), self.table_name)
branch_component_pit = branch_pit[f:t, :]
if not len(net[self.table_name]):
return branch_component_pit, node_pit, [], []

junction_idx_lookup = get_lookup(net, "node", "index")[
ComponentRegistry.get(self.connected_node_type).table_name]
fn_col, tn_col = self.from_to_node_cols
from_nodes = junction_idx_lookup[net[self.table_name][fn_col].values]
to_nodes = junction_idx_lookup[net[self.table_name][tn_col].values]
branch_component_pit[:, :] = array([branch_table_nr] + [0] * (branch_cols - 1))
branch_component_pit[:, MDOTINIT] = 0.1
branch_component_pit[:, TEXT] = get_net_option(net, 'ambient_temperature')
return branch_component_pit, node_pit, from_nodes, to_nodes
Loading
Loading