diff --git a/src/pandapipes/__init__.py b/src/pandapipes/__init__.py index 0605dcf0..c2986794 100644 --- a/src/pandapipes/__init__.py +++ b/src/pandapipes/__init__.py @@ -18,7 +18,7 @@ from pandapipes.properties.fluids import * from pandapipes.component_models.component_registry import * from pandapipes.component_models import * -from pandapipes.component_init import COMPONENT_REGISTRY +from pandapipes.component_init import COMPONENT_REGISTRY, COMPONENT_LIST from pandapipes.create import * from pandapipes.io.file_io import * from pandapipes.pipeflow import * diff --git a/src/pandapipes/component_init.py b/src/pandapipes/component_init.py index a3032b39..dbf39dd1 100644 --- a/src/pandapipes/component_init.py +++ b/src/pandapipes/component_init.py @@ -7,10 +7,11 @@ MassStorage, CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer, \ HeatExchanger, ValvePipe -""" -every high level Component from pandapipes should be initialized here -""" -COMPONENT_REGISTRY = ComponentRegistry( - [Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage, - CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer, - HeatExchanger, ValvePipe]).registry + +# every high level Component from pandapipes should be initialized here + +COMPONENT_LIST = [Junction, Pipe, ExtGrid, Sink, Source, Valve, Pump, PressureControlComponent, MassStorage, + CirculationPumpMass, CirculationPumpPressure, Compressor, FlowControlComponent, HeatConsumer, + HeatExchanger, ValvePipe] + +COMPONENT_REGISTRY = ComponentRegistry(COMPONENT_LIST).registry diff --git a/src/pandapipes/converter/stanet/stanet2pandapipes.py b/src/pandapipes/converter/stanet/stanet2pandapipes.py index 5c86cf5b..8b8de6b7 100644 --- a/src/pandapipes/converter/stanet/stanet2pandapipes.py +++ b/src/pandapipes/converter/stanet/stanet2pandapipes.py @@ -14,7 +14,6 @@ create_sinks_meters, create_sinks_from_nodes, create_control_components, \ create_sinks_from_customers, create_pipes_house_connections from pandapipes.create import create_empty_network -from pandapipes.component_init import COMPONENT_REGISTRY try: import pandaplan.core.pplog as logging diff --git a/src/pandapipes/converter/stanet/valve_pipe_component/create_valve_pipe.py b/src/pandapipes/converter/stanet/valve_pipe_component/create_valve_pipe.py index c82d851d..6fa60303 100644 --- a/src/pandapipes/converter/stanet/valve_pipe_component/create_valve_pipe.py +++ b/src/pandapipes/converter/stanet/valve_pipe_component/create_valve_pipe.py @@ -6,7 +6,7 @@ from pandapipes.component_models.valve_pipe_component import ValvePipe from pandapipes.create import _check_branch, _check_std_type -from pandapipes.pandapipes_net import pandapipesNet, add_new_component +from pandapipes.pandapipes_net import add_new_component def create_valve_pipe(net, from_junction, to_junction, std_type, length_km, k_mm=0.15e-3, diff --git a/src/pandapipes/toolbox.py b/src/pandapipes/toolbox.py index 4270ff64..2a6dec18 100644 --- a/src/pandapipes/toolbox.py +++ b/src/pandapipes/toolbox.py @@ -23,7 +23,7 @@ from pandapipes.pandapipes_net import pandapipesNet from pandapipes.topology import create_nxgraph from pandapipes.utils.internals import get_lookup -from pandapipes.component_init import COMPONENT_REGISTRY +from pandapipes.component_init import COMPONENT_REGISTRY, COMPONENT_LIST try: import pandaplan.core.pplog as logging @@ -110,10 +110,6 @@ def element_junction_tuples(include_node_elements=True, include_branch_elements= :return: set of tuples with element names and column names :rtype: set """ - from pandapipes.component_models import Sink, Source, ExtGrid, Pipe, Valve, Pump, \ - CirculationPumpMass, CirculationPumpPressure, HeatExchanger, PressureControlComponent, \ - Compressor, FlowControlComponent, ValvePipe - from pandapipes.component_models import Junction, MassStorage, HeatConsumer # todo: wieso sind diese Komponenten da nicht mit drinne? special_elements_junctions = [("press_control", "controlled_junction")] move_elements = {"n2b": [], "b2n": []} node_elements = [] @@ -121,11 +117,7 @@ def element_junction_tuples(include_node_elements=True, include_branch_elements= if net is not None: all_tables = {table_name: COMPONENT_REGISTRY[table_name].__class__ for table_name in net.component_list} else: - comp_list = [Sink, Source, ExtGrid, Pipe, Valve, Pump, CirculationPumpMass, - CirculationPumpPressure, HeatExchanger, PressureControlComponent, Compressor, - FlowControlComponent, ValvePipe] - all_tables = {COMPONENT_REGISTRY[comp].table_name: comp for comp in comp_list} - # todo: from_json anpassen, damit Netze die so geladen werden nicht die Klassen, sondern die Tabellennamen haben + all_tables = {COMPONENT_REGISTRY[comp].table_name: comp for comp in COMPONENT_LIST} ejts = set() if include_node_elements: node_elements = [tbl for tbl, comp in all_tables.items() if diff --git a/src/pandapipes/utils/result_extraction.py b/src/pandapipes/utils/result_extraction.py index e9967e7b..a02edd04 100644 --- a/src/pandapipes/utils/result_extraction.py +++ b/src/pandapipes/utils/result_extraction.py @@ -102,7 +102,7 @@ def get_gas_vel_numba(node_pit, branch_pit, comp_from, comp_to, comp_mean, p_abs v_gas_from, v_gas_to, v_gas_mean, normfactor_from, normfactor_to, normfactor_mean = \ [np.empty_like(v_mps) for _ in range(6)] from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) - for i in range(len(v_mps)): + for i, _ in enumerate(v_mps): t_from = node_pit[from_nodes[i], TINIT_NODE] t_to = branch_pit[i, TOUTINIT] tm = (t_from + t_to) / 2 diff --git a/tutorials/circular_flow_in_a_district_heating_grid.ipynb b/tutorials/circular_flow_in_a_district_heating_grid.ipynb index 0a57948e..4e04d31a 100644 --- a/tutorials/circular_flow_in_a_district_heating_grid.ipynb +++ b/tutorials/circular_flow_in_a_district_heating_grid.ipynb @@ -192,7 +192,8 @@ "outputs": [], "source": [ "from pandapipes.component_models import Pipe\n", - "pipe_results = Pipe.get_internal_results(net, [0])" + "from pandapipes.component_init import COMPONENT_REGISTRY\n", + "pipe_results = COMPONENT_REGISTRY[Pipe].get_internal_results(net, [0])" ] }, { @@ -227,7 +228,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -241,9 +242,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.12.7" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/tutorials/temperature_calculation.ipynb b/tutorials/temperature_calculation.ipynb index 092634e7..84cbf42d 100644 --- a/tutorials/temperature_calculation.ipynb +++ b/tutorials/temperature_calculation.ipynb @@ -39,7 +39,8 @@ "outputs": [], "source": [ "import pandapipes\n", - "from pandapipes.component_models import Pipe" + "from pandapipes.component_models import Pipe\n", + "from pandapipes.component_init import COMPONENT_REGISTRY" ] }, { @@ -167,7 +168,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipe_1_results = Pipe.get_internal_results(net, [0])" + "pipe_1_results = COMPONENT_REGISTRY[Pipe].get_internal_results(net, [0])" ] }, { @@ -217,7 +218,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -231,9 +232,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.12.7" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }