Skip to content

Commit

Permalink
- introduced the ComponentRegistry, a central container whioch holds …
Browse files Browse the repository at this point in the history
…the instances of the components

- starting to restructure some low level helper functions for better capsulation of modules
  • Loading branch information
mfranz13 committed Nov 8, 2024
1 parent 78594f1 commit bc9eea5
Show file tree
Hide file tree
Showing 35 changed files with 129 additions and 90 deletions.
1 change: 1 addition & 0 deletions src/pandapipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
pp_dir = os.path.dirname(os.path.realpath(__file__))

from pandapipes.properties.fluids import *
from pandapipes.component_models.component_registry import *
from pandapipes.create import *
from pandapipes.io.file_io import *
from pandapipes.pipeflow import *
Expand Down
13 changes: 12 additions & 1 deletion src/pandapipes/component_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
# 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_toolbox import *

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

from pandapipes.component_models._node_element_models import *
from pandapipes.component_models._branch_models import *
from pandapipes.component_models._branch_element_models 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 *
Expand All @@ -17,4 +27,5 @@
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_registry import *
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import pi

from pandapipes.component_models.abstract_models.branch_models import BranchComponent
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import abstractmethod
from numpy import array

from pandapipes.component_models.abstract_models.base_component import Component
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.pf.pipeflow_setup import get_table_number, get_lookup, get_net_option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import pi, int32

from pandapipes.component_models.abstract_models.branch_element_models import BranchElementComponent
from pandapipes.component_models._branch_element_models import BranchElementComponent
from pandapipes.component_models.component_toolbox import set_fixed_node_entries, standard_branch_wo_internals_result_lookup
from pandapipes.idx_branch import D, AREA, BRANCH_TYPE, CIRC, LOAD_VEC_BRANCHES_T, TO_NODE
from pandapipes.idx_node import MDOTSLACKINIT, VAR_MASS_SLACK, JAC_DERIV_MSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
from numpy import dtype
from pandapipes.component_models.abstract_models.node_element_models import NodeElementComponent
from pandapipes.component_models._node_element_models import NodeElementComponent
from pandapipes.idx_node import LOAD, ELEMENT_IDX
from pandapipes.pf.internals_toolbox import _sum_by_group
from pandapipes.pf.pipeflow_setup import get_lookup, get_net_option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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 pandapipes.component_models.abstract_models.base_component import Component
from pandapipes.component_models._base_component import Component
from pandapipes.component_models.junction_component import Junction

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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 pandapipes.component_models.abstract_models.base_component import Component
from pandapipes.component_models._base_component import Component


class NodeComponent(Component):
Expand Down
11 changes: 0 additions & 11 deletions src/pandapipes/component_models/abstract_models/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import dtype

from pandapipes.component_models.abstract_models.circulation_pump import CirculationPump
from pandapipes.component_models._circulation_pump import CirculationPump
from pandapipes.idx_branch import JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DM, MDOTINIT, \
LOAD_VEC_BRANCHES

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import dtype

from pandapipes.component_models.abstract_models.circulation_pump import CirculationPump
from pandapipes.component_models._circulation_pump import CirculationPump
from pandapipes.idx_branch import JAC_DERIV_DP, JAC_DERIV_DP1, PL


Expand Down
43 changes: 43 additions & 0 deletions src/pandapipes/component_models/component_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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.
"""
jede Komponente die nicht abstrakt und im PF genutzt werden soll, muss im componentregistry registriert werden.
Interne Komponenten werden automatisch hinzugefügt
"""

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


class ComponentRegistry(object):

registry = dict()

def __init__(self):
for comp in [Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage,
CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer,
HeatExchanger]:
comp.__iscustom__ = False
comp_instance = comp()
self.registry[comp_instance.table_name] = comp_instance
self.registry[comp] = comp_instance

@classmethod
def register(cls):
def wrapper(wrapped_class):
wrapped_class.__iscustom__ = True
wrapped_class.__path_from_home__ = os.path.relpath(__file__, os.path.expanduser("~"))
wrapped_instance = wrapped_class()
cls.registry[wrapped_instance.table_name] = wrapped_instance
cls.registry[wrapped_class] = wrapped_instance
return wrapped_class
return wrapper

def register_component(cls):
return ComponentRegistry.register()(cls)


COMPONENT_REGISTRY = ComponentRegistry().registry
37 changes: 0 additions & 37 deletions src/pandapipes/component_models/component_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,43 +92,6 @@ def init_results_element(net, element, output, all_float):
columns=net[res_element].columns)


def add_new_component(net, component, overwrite=False):
"""
:param net:
:type net:
:param component:
:type component:
:param overwrite:
:type overwrite:
:return:
:rtype:
"""
name = component.table_name()
if not overwrite and name in net:
# logger.info('%s is already in net. Try overwrite if you want to get a new entry' %name)
return
else:
if hasattr(component, 'geodata'):
geodata = component.geodata()
else:
geodata = None

comp_input = component.get_component_input()
if name not in net:
net['component_list'].append(component)
net.update({name: comp_input})
if isinstance(net[name], list):
net[name] = pd.DataFrame(np.zeros(0, dtype=net[name]), index=[])
# init_empty_results_table(net, name, component.get_result_table(net))

if geodata is not None:
net.update({name + '_geodata': geodata})
if isinstance(net[name + '_geodata'], list):
net[name + '_geodata'] = pd.DataFrame(np.zeros(0, dtype=net[name + '_geodata']),
index=[])


def set_entry_check_repeat(pit, column, entry, repeat_number, repeated=True):
if repeated:
pit[:, column] = np.repeat(entry, repeat_number)
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/ext_grid_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import dtype, isin, unique

from pandapipes.component_models.abstract_models.node_element_models import NodeElementComponent
from pandapipes.component_models._node_element_models import NodeElementComponent
from pandapipes.component_models.component_toolbox import set_fixed_node_entries
from pandapipes.pf.pipeflow_setup import get_lookup
from pandapipes.idx_node import MDOTSLACKINIT, VAR_MASS_SLACK, JAC_DERIV_MSL
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/flow_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import dtype, bool_, float64, zeros

from pandapipes.component_models.abstract_models import BranchElementComponent
from pandapipes.component_models import BranchElementComponent
from pandapipes.properties import get_fluid
from pandapipes.component_models.component_toolbox import \
standard_branch_wo_internals_result_lookup, get_component_array
Expand Down
4 changes: 2 additions & 2 deletions src/pandapipes/component_models/heat_consumer_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def create_pit_branch_entries(self, net, branch_pit):
if any_(mask_q0):
hc_pit[mask_q0, ACTIVE] = False
logger.warning(r'qext_w is equals to zero for heat consumers with index %s. '
r'Therefore, the defined temperature control cannot be maintained.' \
%net[self.table_name].index[mask_q0])
r'Therefore, the defined temperature control cannot be maintained.' %
net[self.table_name].index[mask_q0])
return hc_pit

def create_component_array(self, net, component_pits):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numpy import dtype

from pandapipes.component_models import standard_branch_wo_internals_result_lookup
from pandapipes.component_models.abstract_models.branch_element_models import BranchElementComponent
from pandapipes.component_models._branch_element_models import BranchElementComponent
from pandapipes.idx_branch import QEXT, LOSS_COEFFICIENT as LC
from pandapipes.pf.pipeflow_setup import get_fluid
from pandapipes.pf.result_extraction import extract_branch_results_without_internals
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/junction_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
from numpy import dtype
from pandapipes.component_models.abstract_models.node_models import NodeComponent
from pandapipes.component_models._node_models import NodeComponent
from pandapipes.component_models.component_toolbox import p_correction_height_air
from pandapipes.idx_node import L, ELEMENT_IDX, PINIT, node_cols, HEIGHT, TINIT, PAMB, \
ACTIVE as ACTIVE_ND
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/mass_storage_component.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.

from pandapipes.component_models.abstract_models import ConstFlow
from pandapipes.component_models import ConstFlow
from numpy import dtype


Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/pipe_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from numpy import dtype

from pandapipes.component_models.abstract_models import BranchComponent
from pandapipes.component_models import BranchComponent
from pandapipes.component_models.component_toolbox import set_entry_check_repeat, vinterp, p_correction_height_air
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE
from pandapipes.idx_branch import FROM_NODE, TO_NODE, LENGTH, D, AREA, K, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numpy import dtype

from pandapipes.component_models.abstract_models.branch_element_models import BranchElementComponent
from pandapipes.component_models._branch_element_models import BranchElementComponent
from pandapipes.component_models import standard_branch_wo_internals_result_lookup
from pandapipes.idx_branch import JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DM, \
BRANCH_TYPE, LOSS_COEFFICIENT as LC, PC as PC_BRANCH
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/pump_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from numpy import dtype, zeros, where, newaxis, float64, int32, array, divide, abs as abs_

from pandapipes.component_models.abstract_models.branch_element_models import BranchElementComponent
from pandapipes.component_models._branch_element_models import BranchElementComponent
from pandapipes.component_models import standard_branch_wo_internals_result_lookup
from pandapipes.component_models.component_toolbox import get_component_array
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/sink_component.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.

from pandapipes.component_models.abstract_models.const_flow_models import ConstFlow
from pandapipes.component_models._const_flow_models import ConstFlow


class Sink(ConstFlow):
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/source_component.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.

from pandapipes.component_models.abstract_models.const_flow_models import ConstFlow
from pandapipes.component_models._const_flow_models import ConstFlow


class Source(ConstFlow):
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/valve_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numpy import dtype, pi

from pandapipes.component_models.component_toolbox import standard_branch_wo_internals_result_lookup
from pandapipes.component_models.abstract_models.branch_element_models import BranchElementComponent
from pandapipes.component_models._branch_element_models import BranchElementComponent
from pandapipes.idx_branch import D, AREA, LOSS_COEFFICIENT as LC
from pandapipes.pf.result_extraction import extract_branch_results_without_internals
from pandapipes.properties.fluids import get_fluid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

from pandapower.create import _get_index_with_check, load_std_type, _set_entries

from pandapipes.component_models.component_toolbox import add_new_component
from pandapipes.converter.stanet.valve_pipe_component.valve_pipe_component import ValvePipe
from pandapipes.create import _check_branch, _check_std_type
from pandapipes.pandapipes_net import pandapipesNet
from pandapipes.pandapipes_net import pandapipesNet, add_new_component


def create_valve_pipe(net, from_junction, to_junction, std_type, length_km, k_mm=0.15e-3,
Expand Down
3 changes: 1 addition & 2 deletions src/pandapipes/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@

from pandapipes.component_models import Junction, Sink, Source, Pump, Pipe, ExtGrid, HeatExchanger, Valve, \
CirculationPumpPressure, CirculationPumpMass, PressureControlComponent, Compressor, MassStorage
from pandapipes.component_models.component_toolbox import add_new_component
from pandapipes.component_models.flow_control_component import FlowControlComponent
from pandapipes.component_models.heat_consumer_component import HeatConsumer
from pandapipes.pandapipes_net import pandapipesNet, get_basic_net_entries, add_default_components
from pandapipes.pandapipes_net import pandapipesNet, get_basic_net_entries, add_default_components, add_new_component
from pandapipes.properties import call_lib
from pandapipes.properties.fluids import Fluid, _add_fluid_to_net
from pandapipes.std_types.std_type_class import regression_function, PumpStdType
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/io/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pandapower.io_utils import with_signature, to_serializable, JSONSerializableClass, \
isinstance_partial as ppow_isinstance, FromSerializableRegistry, PPJSONDecoder

from pandapipes.component_models.abstract_models.branch_models import Component
from pandapipes.component_models._branch_models import Component
from pandapipes.multinet.create_multinet import MultiNet, create_empty_multinet
from pandapipes.pandapipes_net import pandapipesNet, get_basic_net_entries

Expand Down
Loading

0 comments on commit bc9eea5

Please sign in to comment.