Skip to content

Commit

Permalink
Merge pull request #563 from SimonRubenDrauz/global_thermal
Browse files Browse the repository at this point in the history
calling 'calculate_derivatives_thermal' once
  • Loading branch information
SimonRubenDrauz authored Nov 13, 2023
2 parents 7d82b3f + 2aae8dc commit b7963eb
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 306 deletions.
46 changes: 9 additions & 37 deletions pandapipes/component_models/abstract_models/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo
def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
pass

@classmethod
def adaption_before_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options):
pass

@classmethod
def adaption_after_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options):
pass


@classmethod
def create_node_lookups(cls, net, ft_lookups, table_lookup, idx_lookups, current_start,
current_table, internal_nodes_lookup):
Expand Down Expand Up @@ -166,40 +175,3 @@ def create_pit_branch_entries(cls, net, branch_pit):
"""
pass

@classmethod
def calculate_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
"""
Function which creates derivatives.
:param net: The pandapipes network
:type net: pandapipesNet
:param branch_pit:
:type branch_pit:
:param node_pit:
:type node_pit:
:param idx_lookups:
:type idx_lookups:
:param options:
:type options:
:return: No Output.
"""
pass

@classmethod
def calculate_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options):
"""
Function which creates derivatives.
:param net: The pandapipes network
:type net: pandapipesNet
:param branch_pit:
:type branch_pit:
:param node_pit:
:type node_pit:
:param idx_lookups:
:type idx_lookups:
:param options:
:type options:
:return: No Output.
"""
pass
69 changes: 1 addition & 68 deletions pandapipes/component_models/abstract_models/branch_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import numpy as np

from pandapipes.component_models.abstract_models.base_component import Component
from pandapipes.idx_branch import LENGTH, D, AREA, RHO, VINIT, ALPHA, QEXT, TEXT, branch_cols, \
T_OUT, CP, VINIT_T, FROM_NODE_T, TL, \
JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE, LOAD_VEC_BRANCHES_T, LOAD_VEC_NODES_T
from pandapipes.idx_node import TINIT as TINIT_NODE
from pandapipes.idx_branch import VINIT, branch_cols
from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup

try:
Expand Down Expand Up @@ -94,70 +91,6 @@ def create_pit_branch_entries(cls, net, branch_pit):
branch_component_pit[:, VINIT] = 0.1
return branch_component_pit, node_pit, from_nodes, to_nodes

@classmethod
def calculate_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options):
"""
Function which creates derivatives of the temperature.
:param net:
:type net:
:param branch_pit:
:type branch_pit:
:param node_pit:
:type node_pit:
:param idx_lookups:
:type idx_lookups:
:param options:
:type options:
:return: No Output.
"""
f, t = idx_lookups[cls.table_name()]
branch_component_pit = branch_pit[f:t, :]
cp = branch_component_pit[:, CP]
rho = branch_component_pit[:, RHO]
v_init = branch_component_pit[:, VINIT_T]
from_nodes = branch_component_pit[:, FROM_NODE_T].astype(np.int32)
t_init_i = node_pit[from_nodes, TINIT_NODE]
t_init_i1 = branch_component_pit[:, T_OUT]
t_amb = branch_component_pit[:, TEXT]
area = branch_component_pit[:, AREA]
length = branch_component_pit[:, LENGTH]
alpha = branch_component_pit[:, ALPHA] * np.pi * branch_component_pit[:, D]
cls.calculate_temperature_lift(net, branch_component_pit, node_pit)
tl = branch_component_pit[:, TL]
qext = branch_component_pit[:, QEXT]
t_m = (t_init_i1 + t_init_i) / 2

branch_component_pit[:, LOAD_VEC_BRANCHES_T] = \
-(rho * area * cp * v_init * (-t_init_i + t_init_i1 - tl)
- alpha * (t_amb - t_m) * length + qext)

branch_component_pit[:, JAC_DERIV_DT] = - rho * area * cp * v_init + alpha / 2 * length
branch_component_pit[:, JAC_DERIV_DT1] = rho * area * cp * v_init + alpha / 2 * length

branch_component_pit[:, JAC_DERIV_DT_NODE] = rho * v_init * branch_component_pit[:, AREA]
branch_component_pit[:, LOAD_VEC_NODES_T] = rho * v_init * branch_component_pit[:, AREA] \
* t_init_i1

@classmethod
def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
pass

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""
:param net:
:type net:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pandapipes.component_models.abstract_models.branch_models import BranchComponent
from pandapipes.component_models.component_toolbox import set_entry_check_repeat
from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT, RHO, ETA, CP, ELEMENT_IDX
from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, RHO, ETA, CP, ELEMENT_IDX, TOUTINIT
from pandapipes.idx_node import L, node_cols, TINIT as TINIT_NODE
from pandapipes.pf.pipeflow_setup import add_table_lookup, get_lookup, get_table_number
from pandapipes.properties.fluids import get_fluid
Expand Down Expand Up @@ -196,13 +196,12 @@ def create_pit_branch_entries(cls, net, branch_pit):
internal_pipe_number, has_internals)
branch_w_internals_pit[:, FROM_NODE] = from_nodes
branch_w_internals_pit[:, TO_NODE] = to_nodes
branch_w_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[
to_nodes, TINIT_NODE]) / 2
branch_w_internals_pit[:, TOUTINIT] = node_pit[to_nodes, TINIT_NODE]
tm = (node_pit[from_nodes, TINIT_NODE] + branch_w_internals_pit[:, TOUTINIT]) / 2
fluid = get_fluid(net)
branch_w_internals_pit[:, RHO] = fluid.get_density(branch_w_internals_pit[:, TINIT])
branch_w_internals_pit[:, ETA] = fluid.get_viscosity(branch_w_internals_pit[:, TINIT])
branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(branch_w_internals_pit[:, TINIT])

branch_w_internals_pit[:, RHO] = fluid.get_density(tm)
branch_w_internals_pit[:, ETA] = fluid.get_viscosity(tm)
branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(tm)
return branch_w_internals_pit, internal_pipe_number

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

from pandapipes.component_models.abstract_models.branch_models import BranchComponent

from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE
from pandapipes.idx_branch import FROM_NODE, TO_NODE, TOUTINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE
from pandapipes.idx_node import TINIT as TINIT_NODE

from pandapipes.pf.pipeflow_setup import add_table_lookup
Expand Down Expand Up @@ -82,12 +82,12 @@ def create_pit_branch_entries(cls, net, branch_pit):
branch_wo_internals_pit[:, ELEMENT_IDX] = net[cls.table_name()].index.values
branch_wo_internals_pit[:, FROM_NODE] = from_nodes
branch_wo_internals_pit[:, TO_NODE] = to_nodes
branch_wo_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE]
+ node_pit[to_nodes, TINIT_NODE]) / 2
branch_wo_internals_pit[:, TOUTINIT] = node_pit[to_nodes, TINIT_NODE]
tm = (node_pit[from_nodes, TINIT_NODE] + branch_wo_internals_pit[:, TOUTINIT]) / 2
fluid = get_fluid(net)
branch_wo_internals_pit[:, RHO] = fluid.get_density(branch_wo_internals_pit[:, TINIT])
branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(branch_wo_internals_pit[:, TINIT])
branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(branch_wo_internals_pit[:, TINIT])
branch_wo_internals_pit[:, RHO] = fluid.get_density(tm)
branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(tm)
branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(tm)
branch_wo_internals_pit[:, ACTIVE] = net[cls.table_name()][cls.active_identifier()].values
return branch_wo_internals_pit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def create_pit_branch_entries(cls, net, branch_pit):
circ_pump_pit[:, AREA] = circ_pump_pit[:, D] ** 2 * np.pi / 4
circ_pump_pit[:, ACTIVE] = False

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, mode):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,3 @@ def create_pit_node_entries(cls, net, node_pit):
index = junction_idx_lookups[juncts]
node_pit[index, LOAD] += loads_sum

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,3 @@ def create_pit_node_entries(cls, net, node_pit):
p_in = press - circ_pump.plift_bar.values
set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_in, None,
cls.get_connected_node_type(), "p")

@classmethod
def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
pass
20 changes: 1 addition & 19 deletions pandapipes/component_models/flow_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pandapipes.component_models.component_toolbox import \
standard_branch_wo_internals_result_lookup, get_component_array
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import D, AREA, TL, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, VINIT, \
from pandapipes.idx_branch import D, AREA, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, VINIT, \
RHO, LOAD_VEC_BRANCHES
from pandapipes.pf.result_extraction import extract_branch_results_without_internals

Expand Down Expand Up @@ -72,9 +72,6 @@ def create_component_array(cls, net, component_pits):
fc_pit[:, cls.CONTROL_ACTIVE] = tbl.control_active.values
component_pits[cls.table_name()] = fc_pit

@classmethod
def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
pass

@classmethod
def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
Expand All @@ -89,21 +86,6 @@ def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_loo
fc_branch_pit[active, JAC_DERIV_DV] = 1
fc_branch_pit[active, LOAD_VEC_BRANCHES] = 0

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""
:param net:
:type net:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, mode):
required_results_hyd, required_results_ht = standard_branch_wo_internals_result_lookup(net)
Expand Down
18 changes: 2 additions & 16 deletions pandapipes/component_models/heat_exchanger_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pandapipes.component_models.abstract_models.branch_wzerolength_models import \
BranchWZeroLengthComponent
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import TL, ALPHA, TEXT, QEXT, T_OUT, D, AREA, LOSS_COEFFICIENT as LC
from pandapipes.idx_branch import ALPHA, TEXT, QEXT, D, AREA, LOSS_COEFFICIENT as LC, TOUTINIT
from pandapipes.pf.pipeflow_setup import get_fluid
from pandapipes.pf.result_extraction import extract_branch_results_without_internals

Expand Down Expand Up @@ -58,7 +58,7 @@ def create_pit_branch_entries(cls, net, branch_pit):
heat_exchanger_pit[:, ALPHA] = 0
heat_exchanger_pit[:, QEXT] = net[cls.table_name()].qext_w.values
heat_exchanger_pit[:, TEXT] = 293.15
heat_exchanger_pit[:, T_OUT] = 307
heat_exchanger_pit[:, TOUTINIT] = 307

@classmethod
def extract_results(cls, net, options, branch_results, mode):
Expand All @@ -81,20 +81,6 @@ def extract_results(cls, net, options, branch_results, mode):
extract_branch_results_without_internals(net, branch_results, required_results_hyd,
required_results_ht, cls.table_name(), mode)

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""
:param net:
:type net:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
branch_component_pit[:, TL] = 0

@classmethod
def get_component_input(cls):
Expand Down
20 changes: 1 addition & 19 deletions pandapipes/component_models/pipe_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pandapipes.component_models.junction_component import Junction
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE
from pandapipes.idx_branch import FROM_NODE, TO_NODE, LENGTH, D, AREA, K, \
VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, T_OUT, TL
VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC
from pandapipes.idx_node import PINIT, HEIGHT, TINIT as TINIT_NODE, \
RHO as RHO_NODES, PAMB, ACTIVE as ACTIVE_ND
from pandapipes.pf.pipeflow_setup import get_fluid, get_lookup
Expand Down Expand Up @@ -151,26 +151,8 @@ def create_pit_branch_entries(cls, net, branch_pit):
set_entry_check_repeat(
pipe_pit, LC, net[tbl].loss_coefficient.values, internal_pipe_number, has_internals)

node_pit = net["_pit"]["node"]
to_nodes = pipe_pit[:, TO_NODE].astype(np.int32)
pipe_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE]
pipe_pit[:, AREA] = pipe_pit[:, D] ** 2 * np.pi / 4

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""
:param net:
:type net:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, mode):
res_nodes_from_hyd = [("p_from_bar", "p_from"), ("mdot_from_kg_per_s", "mf_from")]
Expand Down
17 changes: 1 addition & 16 deletions pandapipes/component_models/pressure_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pandapipes.component_models.abstract_models.branch_wzerolength_models import \
BranchWZeroLengthComponent
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import D, AREA, TL, \
from pandapipes.idx_branch import D, AREA, \
JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, BRANCH_TYPE, LOSS_COEFFICIENT as LC
from pandapipes.idx_node import PINIT, NODE_TYPE, PC
from pandapipes.pf.pipeflow_setup import get_lookup
Expand Down Expand Up @@ -79,21 +79,6 @@ def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_loo
press_pit[pc_branch, JAC_DERIV_DP1] = 0
press_pit[pc_branch, JAC_DERIV_DV] = 0

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
"""
:param net:
:type net:
:param branch_component_pit:
:type branch_component_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, mode):
"""
Expand Down
Loading

0 comments on commit b7963eb

Please sign in to comment.