Skip to content

Commit

Permalink
improving stability and giving hints about possible problems
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRubenDrauz committed Jan 16, 2025
1 parent d3c4c4a commit 5409fba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
19 changes: 15 additions & 4 deletions src/pandapipes/component_models/heat_consumer_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from pandapipes.component_models import (get_fluid, BranchWZeroLengthComponent, get_component_array,
standard_branch_wo_internals_result_lookup)
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import (MDOTINIT, QEXT, JAC_DERIV_DP1, JAC_DERIV_DM,
from pandapipes.idx_branch import (MDOTINIT, QEXT, JAC_DERIV_DP1, JAC_DERIV_DM, FROM_NODE,
JAC_DERIV_DP, LOAD_VEC_BRANCHES, TOUTINIT, JAC_DERIV_DT,
JAC_DERIV_DTOUT, LOAD_VEC_BRANCHES_T, ACTIVE, FLOW_RETURN_CONNECT)
JAC_DERIV_DTOUT, LOAD_VEC_BRANCHES_T, FLOW_RETURN_CONNECT)
from pandapipes.idx_node import TINIT
from pandapipes.pf.internals_toolbox import get_from_nodes_corrected
from pandapipes.pf.pipeflow_setup import get_lookup
Expand Down Expand Up @@ -76,7 +76,18 @@ def create_pit_branch_entries(cls, net, branch_pit):
mdot = net[cls.table_name()].controlled_mdot_kg_per_s.values
hc_pit[~np.isnan(mdot), MDOTINIT] = mdot[~np.isnan(mdot)]
treturn = net[cls.table_name()].treturn_k.values
hc_pit[~np.isnan(treturn), TOUTINIT] = treturn[~np.isnan(treturn)]
mask_tr = ~np.isnan(treturn)
if np.any(mask_tr):
node_pit = net["_pit"]["node"]
fn = hc_pit[:, FROM_NODE].astype(int)
mask_err = treturn + 15 >= node_pit[fn, TINIT]
if np.any(mask_err):
logger.warning(r'The initial temperature of the following heat consumers %s '
r'are below or close to their controlled return temperature. '
r'This might cause a pipeflow failure. '
r'Please adapt the initial temperature accordingly.'
% net.heat_consumer.loc[mask_tr & mask_err].index.tolist())
hc_pit[mask_tr, TOUTINIT] = treturn[mask_tr]
hc_pit[:, FLOW_RETURN_CONNECT] = True
mask_q0 = qext == 0 & np.isnan(mdot)
if np.any(mask_q0):
Expand Down Expand Up @@ -169,7 +180,7 @@ def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_loo
t_out = hc_pit[:, TOUTINIT]

df_dm = - cp * (t_out - t_in)
mask_equal = t_out == t_in
mask_equal = t_out >= t_in
mask_zero = hc_pit[:, QEXT] == 0
mask_ign = mask_equal | mask_zero
hc_pit[mask & mask_ign, MDOTINIT] = 0
Expand Down
3 changes: 2 additions & 1 deletion src/pandapipes/pf/pipeflow_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ def check_infeed_number(node_pit):
node_pit[slack_nodes, INFEED] = True
infeed_nodes = node_pit[:, INFEED]
if np.sum(infeed_nodes) != np.sum(slack_nodes):
raise PipeflowNotConverged(r'The number of infeeding nodes and slacks do not match')
return False
return True


class PipeflowNotConverged(ppException):
Expand Down
8 changes: 5 additions & 3 deletions src/pandapipes/pipeflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,15 @@ def solve_temperature(net):
calculate_derivatives_thermal(net, branch_pit, node_pit, options)
for comp in net['component_list']:
comp.adaption_after_derivatives_thermal(net, branch_pit, node_pit, branch_lookups, options)
check_infeed_number(node_pit)

jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True)

t_init_old = node_pit[:, TINIT].copy()
t_out_old = branch_pit[:, TOUTINIT].copy()

if not check_infeed_number(node_pit):
return [branch_pit[:, TOUTINIT], t_out_old, node_pit[:, TINIT], t_init_old], [np.nan]

jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True)

x = spsolve(jacobian, epsilon)

node_pit[:, TINIT] -= x[:len(node_pit)] * options["alpha"]
Expand Down

0 comments on commit 5409fba

Please sign in to comment.