Skip to content

Commit

Permalink
consider new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrauz authored and sdrauz committed Dec 15, 2023
1 parent 1cbed3e commit 150a2d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 42 deletions.
42 changes: 17 additions & 25 deletions pandapipes/component_models/dynamic_circulation_pump_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
# 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 operator import itemgetter

import numpy as np
from numpy import dtype
from operator import itemgetter
from pandapipes.component_models.junction_component import Junction

from pandapipes.component_models.abstract_models.circulation_pump import CirculationPump
from pandapipes.component_models.component_toolbox import set_fixed_node_entries, update_fixed_node_entries
from pandapipes.idx_node import PINIT, NODE_TYPE, P, EXT_GRID_OCCURENCE
from pandapipes.pf.pipeflow_setup import get_lookup, get_net_option
from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, ACTIVE, LOSS_COEFFICIENT as LC, FROM_NODE, \
TINIT, PL, ACTUAL_POS, DESIRED_MV, RHO, TO_NODE, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, LOAD_VEC_BRANCHES
from pandapipes.idx_node import PINIT, PAMB, TINIT as TINIT_NODE, HEIGHT, RHO as RHO_node
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, P_CONVERSION, GRAVITATION_CONSTANT
from pandapipes.properties.fluids import get_fluid
from pandapipes.component_models.component_toolbox import p_correction_height_air
from pandapipes.component_models.component_toolbox import set_fixed_node_entries, \
get_mass_flow_at_nodes
from pandapipes.pf.result_extraction import extract_branch_results_without_internals
from pandapipes.component_models.component_toolbox import update_fixed_node_entries
from pandapipes.component_models.junction_component import Junction
from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT
from pandapipes.idx_branch import ACTIVE, TOUTINIT
from pandapipes.idx_node import PINIT, TINIT as TINIT_NODE, RHO as RHO_node
from pandapipes.pf.pipeflow_setup import get_lookup, get_net_option

try:
import pandaplan.core.pplog as logging
Expand All @@ -29,7 +26,6 @@


class DynamicCirculationPump(CirculationPump):

# class attributes
kwargs = None
prev_act_pos = None
Expand Down Expand Up @@ -67,7 +63,6 @@ def create_pit_node_entries(cls, net, node_pit):
set_fixed_node_entries(net, node_pit, junction, dyn_circ_pump.type.values, p_in, None,
cls.get_connected_node_type(), "p")


@classmethod
def create_pit_branch_entries(cls, net, branch_pit):
"""
Expand Down Expand Up @@ -143,7 +138,7 @@ def plant_dynamics(cls, dt, desired_mv, dyn_pump_tbl):
def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
dt = net['_options']['dt']
circ_pump_tbl = net[cls.table_name()]
junction_lookup = get_lookup(net, "node", "index")[ cls.get_connected_node_type().table_name()]
junction_lookup = get_lookup(net, "node", "index")[cls.get_connected_node_type().table_name()]
fn_col, tn_col = cls.from_to_node_cols()
# get indices in internal structure for flow_junctions in circ_pump tables which are
# "active"
Expand All @@ -162,7 +157,7 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
desired_mv = circ_pump_tbl.desired_mv.values
cur_actual_pos = circ_pump_tbl.actual_pos.values

#if not np.isnan(desired_mv) and get_net_option(net, "time_step") == cls.time_step:
# if not np.isnan(desired_mv) and get_net_option(net, "time_step") == cls.time_step:
if get_net_option(net, "time_step") == cls.time_step:
# a controller timeseries is running
actual_pos = cls.plant_dynamics(dt, desired_mv, circ_pump_tbl)
Expand All @@ -172,7 +167,7 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
circ_pump_tbl.actual_pos = actual_pos
cls.time_step += 1

else: # Steady state analysis
else: # Steady state analysis
actual_pos = circ_pump_tbl.actual_pos.values

std_types_lookup = np.array(list(net.std_types['dynamic_pump'].keys()))
Expand All @@ -181,8 +176,8 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
std_types = np.array(list(net.std_types['dynamic_pump'].keys()))[std_type]
fcts = itemgetter(*std_types)(net['std_types']['dynamic_pump'])
fcts = [fcts] if not isinstance(fcts, tuple) else fcts
m_head = np.array(list(map(lambda x, y, z: x.get_m_head(y, z), fcts, vol_m3_s, actual_pos))) # m head
prsr_lift = np.divide((rho * GRAVITATION_CONSTANT * m_head), P_CONVERSION)[0] # bar
m_head = np.array(list(map(lambda x, y, z: x.get_m_head(y, z), fcts, vol_m3_s, actual_pos))) # m head
prsr_lift = np.divide((rho * GRAVITATION_CONSTANT * m_head), P_CONVERSION)[0] # bar
circ_pump_tbl.p_lift = prsr_lift
circ_pump_tbl.m_head = m_head

Expand All @@ -202,7 +197,6 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
update_fixed_node_entries(net, node_pit, junction, circ_pump_tbl.type.values, (prsr_lift + p_static), t_flow_k,
cls.get_connected_node_type(), "pt")


@classmethod
def get_result_table(cls, net):
"""
Expand Down Expand Up @@ -240,7 +234,6 @@ def get_component_input(cls):
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
pass


@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
"""
Expand Down Expand Up @@ -287,8 +280,7 @@ def extract_results(cls, net, options, branch_results, nodes_connected, branches
return_junctions = circ_pump_tbl[fn_col].values
return_node = junction_lookup[return_junctions]


#res_table["vdot_norm_m3_per_s"] = np.divide(- (sum_mass_flows / counts)[inverse_nodes], rho)
# res_table["vdot_norm_m3_per_s"] = np.divide(- (sum_mass_flows / counts)[inverse_nodes], rho)

return_junctions = circ_pump_tbl[fn_col].values
return_nodes = junction_lookup[return_junctions]
Expand All @@ -297,8 +289,8 @@ def extract_results(cls, net, options, branch_results, nodes_connected, branches
res_table["p_static_bar"].values[in_service] = circ_pump_tbl.p_static_bar.values
res_table["p_flow_bar"].values[in_service] = node_pit[flow_nodes, PINIT]
res_table["deltap_bar"].values[in_service] = deltap_bar[in_service]
res_table["t_from_k"].values[p_grids] = node_pit[return_node, TINIT]
res_table["t_to_k"].values[p_grids] = node_pit[flow_nodes, TINIT]
res_table["t_from_k"].values[p_grids] = node_pit[return_node, TOUTINIT]
res_table["t_to_k"].values[p_grids] = node_pit[flow_nodes, TOUTINIT]
res_table["rho"].values[p_grids] = node_pit[return_node, RHO_node]
res_table["p_lift"].values[p_grids] = circ_pump_tbl.p_lift.values
res_table["m_head"].values[p_grids] = circ_pump_tbl.m_head.values
Expand Down
60 changes: 43 additions & 17 deletions pandapipes/component_models/dynamic_pump_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import numpy as np
from numpy import dtype

from pandapipes.component_models.junction_component import Junction
from pandapipes.component_models.pump_component import Pump
from pandapipes.component_models.abstract_models.branch_wzerolength_models import \
BranchWZeroLengthComponent
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION, \
GRAVITATION_CONSTANT
from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, TL, LOSS_COEFFICIENT as LC, FROM_NODE, \
TINIT, PL, Kv_max, ACTUAL_POS, DESIRED_MV, RHO
from pandapipes.component_models.component_toolbox import get_component_array
from pandapipes.component_models.junction_component import Junction
from pandapipes.constants import NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION, \
GRAVITATION_CONSTANT
from pandapipes.idx_branch import VINIT, D, AREA, TL, LOSS_COEFFICIENT as LC, FROM_NODE, \
TOUTINIT, PL, ACTUAL_POS, DESIRED_MV, RHO
from pandapipes.idx_node import PINIT, PAMB, TINIT as TINIT_NODE
from pandapipes.pf.pipeflow_setup import get_fluid, get_net_option, get_lookup
from pandapipes.pf.result_extraction import extract_branch_results_without_internals
Expand All @@ -35,6 +35,10 @@ class DynamicPump(BranchWZeroLengthComponent):
prev_act_pos = None
time_step = 0

STD_TYPE = 0

internal_cols = 1

@classmethod
def from_to_node_cols(cls):
return "from_junction", "to_junction"
Expand All @@ -51,6 +55,27 @@ def active_identifier(cls):
def get_connected_node_type(cls):
return Junction

@classmethod
def create_component_array(cls, net, component_pits):
"""
Function which creates an internal array of the component in analogy to the pit, but with
component specific entries, that are not needed in the pit.
:param net: The pandapipes network
:type net: pandapipesNet
:param component_pits: dictionary of component specific arrays
:type component_pits: dict
:return:
:rtype:
"""
tbl = net[cls.table_name()]
pump_array = np.zeros(shape=(len(tbl), cls.internal_cols), dtype=np.float64)
std_types_lookup = get_std_type_lookup(net, cls.table_name())
std_type, pos = np.where(net[cls.table_name()]['std_type'].values
== std_types_lookup[:, np.newaxis])
pump_array[pos, cls.STD_TYPE] = std_type
component_pits[cls.table_name()] = pump_array

@classmethod
def create_pit_branch_entries(cls, net, branch_pit):
"""
Expand All @@ -61,11 +86,8 @@ def create_pit_branch_entries(cls, net, branch_pit):
:type branch_pit:
:return: No Output.
"""

pump_pit = super().create_pit_branch_entries(net, branch_pit)
std_types_lookup = np.array(list(net.std_types[cls.table_name()].keys()))
std_type, pos = np.where(net[cls.table_name()]['std_type'].values
== std_types_lookup[:, np.newaxis])
pump_pit[pos, STD_TYPE] = std_type
pump_pit[:, D] = 0.1
pump_pit[:, AREA] = pump_pit[:, D] ** 2 * np.pi / 4
pump_pit[:, LC] = 0
Expand Down Expand Up @@ -126,14 +148,15 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
dyn_pump_tbl = net[cls.table_name()]
pump_pit = branch_pit[f:t, :]
area = pump_pit[:, AREA]
idx = pump_pit[:, STD_TYPE].astype(int)
pump_array = get_component_array(net, cls.table_name())
idx = pump_array[:, cls.STD_TYPE].astype(np.int32)
std_types = np.array(list(net.std_types['dynamic_pump'].keys()))[idx]
from_nodes = pump_pit[:, FROM_NODE].astype(np.int32)
# to_nodes = pump_pit[:, TO_NODE].astype(np.int32)
fluid = get_fluid(net)
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT]
# p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT]
numerator = NORMAL_PRESSURE * pump_pit[:, TINIT]
numerator = NORMAL_PRESSURE * pump_pit[:, TOUTINIT]
v_mps = pump_pit[:, VINIT]
desired_mv = dyn_pump_tbl.desired_mv.values
cur_actual_pos = dyn_pump_tbl.actual_pos.values
Expand All @@ -154,11 +177,10 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
else: # Steady state analysis
actual_pos = dyn_pump_tbl.actual_pos.values


fcts = itemgetter(*std_types)(net['std_types']['dynamic_pump'])
fcts = [fcts] if not isinstance(fcts, tuple) else fcts
m_head = np.array(list(map(lambda x, y, z: x.get_m_head(y, z), fcts, vol_m3_s, actual_pos))) # m head
rho= pump_pit[:, RHO]
rho = pump_pit[:, RHO]
prsr_lift = np.divide((rho * GRAVITATION_CONSTANT * m_head), P_CONVERSION)[0] # bar
dyn_pump_tbl.p_lift = prsr_lift
dyn_pump_tbl.m_head = m_head
Expand Down Expand Up @@ -278,13 +300,17 @@ def get_result_table(cls, net):
"v_from_m_per_s", "v_to_m_per_s",
"p_from_bar", "p_to_bar",
"t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"vdot_norm_m3_per_s", "normfactor_from", "normfactor_to", "desired_mv", "actual_pos"]
"vdot_norm_m3_per_s", "normfactor_from", "normfactor_to", "desired_mv", "actual_pos"]
# TODO: inwieweit sind diese Angaben bei imaginärem Durchmesser sinnvoll?
else:
output = ["deltap_bar", "v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k",
"t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s",
"desired_mv", "actual_pos"]
"desired_mv", "actual_pos"]
if calc_compr_pow:
output += ["compr_power_mw"]

return output, True
return output, True


def get_std_type_lookup(net, table_name):
return np.array(list(net.std_types[table_name].keys()))

0 comments on commit 150a2d8

Please sign in to comment.