Skip to content

Commit

Permalink
updating SimpleHeatExchangerDeltaP with new jacobian structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk committed Nov 1, 2023
1 parent 1a64bd6 commit cc22938
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
25 changes: 15 additions & 10 deletions intermediateFoodTests/newComponentsTests/heatex_alone_deltaP.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging


from tespy.components import HeatExchangerSimple, Source, Sink, Merge, Separator
from tespy.components import SimpleHeatExchanger, Source, Sink, Merge, Separator
from tespy.tools import ComponentProperties
from tespy.connections import Connection
from tespy.networks import Network
Expand All @@ -12,22 +12,24 @@
from tespy.tools.data_containers import ComponentProperties as dc_cp
from tespy.tools.data_containers import GroupedComponentProperties as dc_gcp

from tespy.components.newcomponents import HeatExchangerSimpleDeltaP, HeatExchangerSimpleLossFactor,MergeWithPressureLoss,SeparatorWithSpeciesSplits

from tespy.components.newcomponents import SimpleHeatExchangerDeltaP, SimpleHeatExchangerDeltaPLossFactor,MergeWithPressureLoss,SeparatorWithSpeciesSplits

logging.basicConfig(level=logging.DEBUG)

# %%

# caution, must write "Water" (capital W) in INCOMP backend -> CoolProp bug? Intentional?
fluids = ["INCOMP::FoodWater", "INCOMP::FoodProtein"]
nw = Network(fluids=fluids, p_unit="bar", T_unit="C")
#fluids = ["INCOMP::FoodWater", "INCOMP::FoodProtein"]
#nw = Network(p_unit="bar", T_unit="C", iterinfo=True)
nw = Network(m_unit='kg / s', p_unit='bar', T_unit='C',h_unit='kJ / kg', h_range=[-1e2,4e2], iterinfo=True)


so = Source("Source")
# Variant 2: Q is m (h_2 - h_1), Q_total is taking efficiency into account and represents the heat transfer over system
# boundary. For heat transfer into the system: Q = Q_total * eta, for heat transfer from the system: Q_total = Q * eta

#he = HeatExchangerSimpleLossFactor("Heater")
he = HeatExchangerSimpleDeltaP("Heater")
#he = SimpleHeatExchangerLossFactor("Heater")
he = SimpleHeatExchangerDeltaP("Heater")


si = Sink("Sink")
Expand All @@ -38,11 +40,14 @@
nw.add_conns(c1, c2)

# set some generic data for starting values
c1.set_attr(m=1, p=2.2, T=30, fluid={"FoodWater": 0.9, "FoodProtein": 0.1})
c2.set_attr(T=50)
c1.set_attr(fluid={'INCOMP::Water': 0.80,'INCOMP::PHE': 0.15,'INCOMP::S800': 0.05}, m=1, T=30, p=1, mixing_rule="incompressible")
#c1.set_attr(m=1, p=2.2, T=30, fluid={"INCOMP::FoodWater": 0.9, "INCOMP::FoodProtein": 0.1}, mixing_rule="incompressible")
c2.set_attr(T=95) #,p=1)

# set pressure ratios of heater and merge
he.set_attr(deltaP=1)
he.set_attr(deltaP=0.1)
#he.set_attr(pr=1.1)


#he.set_attr(LF=0.1) # MRK so eta is (1-hlf) heat loss factor
#he.set_attr(Q_total=86371.13607253956) # MRK so eta is (1-hlf) heat loss factor
Expand Down
43 changes: 31 additions & 12 deletions src/tespy/components/newcomponents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from tespy.components import HeatExchangerSimple, Merge, Separator, Splitter
from tespy.components import SimpleHeatExchanger, Merge, Separator, Splitter
from tespy.tools.data_containers import ComponentProperties as dc_cp
from tespy.tools.data_containers import GroupedComponentProperties as dc_gcp
from tespy.tools.fluid_properties import T_mix_ph
Expand All @@ -9,7 +9,7 @@

import numpy as np

class DiabaticSimpleHeatExchanger(HeatExchangerSimple):
class DiabaticSimpleHeatExchanger(SimpleHeatExchanger):

@staticmethod
def component():
Expand Down Expand Up @@ -94,24 +94,24 @@ def calc_parameters(self):
self.Q_total.val = self.Q.val - self.Q_loss.val


class HeatExchangerSimpleDeltaP(HeatExchangerSimple):
class SimpleHeatExchangerDeltaP(SimpleHeatExchanger):

@staticmethod
def component():
return 'diabatic simple heat exchanger'
return 'simple heat exchanger with pressure drop'

def get_parameters(self):
variables = super().get_parameters()
variables["deltaP"] = dc_cp(
min_val=0,
deriv=self.pr_deriv,
func=self.pr_func,
deriv=self.deltaP_deriv,
func=self.deltaP_func,
latex=self.pr_func_doc,
num_eq=1,
)
return variables

def pr_func(self):
def deltaP_func(self):
r"""
Equation for pressure drop.
Expand All @@ -127,9 +127,9 @@ def pr_func(self):

return self.inl[0].p.val_SI - self.deltaP.val*1e5 - self.outl[0].p.val_SI

def pr_deriv(self, increment_filter, k):
def deltaP_deriv(self, increment_filter, k, pr='', inconn=0, outconn=0):
r"""
Calculate the partial derivatives for combustion pressure ratio.
Calculate the partial derivatives for pressure drop.
Parameters
----------
Expand All @@ -138,16 +138,35 @@ def pr_deriv(self, increment_filter, k):
k : int
Position of equation in Jacobian matrix.
pr : str
Component parameter to evaluate the pr_func on, e.g.
:code:`pr1`.
inconn : int
Connection index of inlet.
outconn : int
Connection index of outlet.
"""
self.jacobian[k, 0, 1] = 1 #self.pr.val
self.jacobian[k, self.num_i, 1] = -1

deltaP = self.get_attr("deltaP")
i = self.inl[inconn]
o = self.outl[inconn]
if i.p.is_var:
self.jacobian[k, i.p.J_col] = 1
if o.p.is_var:
self.jacobian[k, o.p.J_col] = -1
if deltaP.is_var:
self.jacobian[k, self.pr.J_col] = 1


def calc_parameters(self):
super().calc_parameters()
self.deltaP.val = (self.inl[0].p.val_SI - self.outl[0].p.val_SI)/1e5


class HeatExchangerSimpleDeltaPLossFactor(HeatExchangerSimpleDeltaP):
class SimpleHeatExchangerDeltaPLossFactor(SimpleHeatExchangerDeltaP):

@staticmethod
def component():
Expand Down

0 comments on commit cc22938

Please sign in to comment.