Skip to content

Commit

Permalink
Merge pull request #628 from SimonRubenDrauz/bugfix/bidirectional
Browse files Browse the repository at this point in the history
Bugfix/bidirectional
  • Loading branch information
SimonRubenDrauz authored Nov 7, 2024
2 parents 941ee4d + 7e029c0 commit 5d182b7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/flow_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DM, MDOTINIT, LOAD_VEC_BRANCHES
from pandapipes.idx_branch import JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DM, MDOTINIT, LOAD_VEC_BRANCHES
from pandapipes.pf.result_extraction import extract_branch_results_without_internals


Expand Down
16 changes: 14 additions & 2 deletions src/pandapipes/component_models/heat_consumer_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
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 (D, AREA, MDOTINIT, QEXT, JAC_DERIV_DP1, JAC_DERIV_DM,
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)
JAC_DERIV_DTOUT, LOAD_VEC_BRANCHES_T, ACTIVE)
from pandapipes.idx_node import TINIT
from pandapipes.pf.internals_toolbox import get_from_nodes_corrected
from pandapipes.pf.pipeflow_setup import get_lookup
from pandapipes.pf.result_extraction import extract_branch_results_without_internals
from pandapipes.properties.properties_toolbox import get_branch_cp

try:
import pandaplan.core.pplog as logging
except ImportError:
import logging

logger = logging.getLogger(__name__)

class HeatConsumer(BranchWZeroLengthComponent):
"""
Expand Down Expand Up @@ -71,6 +77,12 @@ def create_pit_branch_entries(cls, net, branch_pit):
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_q0 = qext == 0 & np.isnan(mdot)
if np.any(mask_q0):
hc_pit[mask_q0, ACTIVE] = False
logger.warning(r'qext_w is equals to zero for heat consumers with index %s. '
r'Therefore, the defined temperature control cannot be maintained.' \
%net[cls.table_name()].index[mask_q0])
return hc_pit

@classmethod
Expand Down
1 change: 1 addition & 0 deletions src/pandapipes/pf/derivative_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def calculate_derivatives_hydraulic(net, branch_pit, node_pit, options):


def calculate_derivatives_thermal(net, branch_pit, node_pit, _):
node_pit[:, INFEED] = False
fluid = get_fluid(net)
cp = get_branch_cp(fluid, node_pit, branch_pit)
m_init_i = np.abs(branch_pit[:, MDOTINIT])
Expand Down
4 changes: 3 additions & 1 deletion src/pandapipes/pf/pipeflow_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,10 @@ def reduce_pit(net, mode="hydraulics"):

def check_infeed_number(node_pit):
slack_nodes = node_pit[:, NODE_TYPE_T] == T
if len(node_pit) == 1:
node_pit[slack_nodes, INFEED] = True
infeed_nodes = node_pit[:, INFEED]
if sum(infeed_nodes) != sum(slack_nodes):
if np.sum(infeed_nodes) != np.sum(slack_nodes):
raise PipeflowNotConverged(r'The number of infeeding nodes and slacks do not match')


Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/pipeflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def solve_hydraulics(net):

x = spsolve(jacobian, epsilon)

branch_pit[:, MDOTINIT] -= x[len(node_pit):len(node_pit) + len(branch_pit)]
branch_pit[:, MDOTINIT] -= x[len(node_pit):len(node_pit) + len(branch_pit)] * options["alpha"]
node_pit[:, PINIT] -= x[:len(node_pit)] * options["alpha"]
node_pit[slack_nodes, MDOTSLACKINIT] -= x[len(node_pit) + len(branch_pit):]

Expand Down

0 comments on commit 5d182b7

Please sign in to comment.