Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving stability and giving hints about possible problems #686

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/pandapipes/component_models/heat_consumer_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import (MDOTINIT, QEXT, JAC_DERIV_DP1, JAC_DERIV_DM,
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,8 @@ 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)
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 +170,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
9 changes: 6 additions & 3 deletions src/pandapipes/pipeflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,16 @@ 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.array([
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
Loading