Skip to content

Commit

Permalink
Clean up diabatic combustion chamber implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Sep 5, 2023
1 parent faafbe8 commit 3147460
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
12 changes: 8 additions & 4 deletions src/tespy/components/combustion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,17 @@ def energy_balance_func(self):
res = 0
for i in self.inl:
i.build_fluid_data()
res += i.m.val_SI * (i.h.val_SI - h_mix_pT(
p_ref, T_ref, i.fluid_data, mixing_rule="forced-gas"))
res += i.m.val_SI * (
i.h.val_SI
- h_mix_pT(p_ref, T_ref, i.fluid_data, mixing_rule="forced-gas")
)

for o in self.outl:
o.build_fluid_data()
res -= o.m.val_SI * (o.h.val_SI - h_mix_pT(
p_ref, T_ref, o.fluid_data, mixing_rule="forced-gas"))
res -= o.m.val_SI * (
o.h.val_SI
- h_mix_pT(p_ref, T_ref, o.fluid_data, mixing_rule="forced-gas")
)

res += self.calc_ti()
return res
Expand Down
52 changes: 30 additions & 22 deletions src/tespy/components/combustion/diabatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,8 @@ def get_parameters(self):

def get_mandatory_constraints(self):
return {
'mass_flow_constraints': {
'func': self.mass_flow_func, 'deriv': self.mass_flow_deriv,
'constant_deriv': True, 'latex': self.mass_flow_func_doc,
'num_eq': 1},
'stoichiometry_constraints': {
'func': self.stoichiometry_func,
'deriv': self.stoichiometry_deriv,
'constant_deriv': False,
'latex': self.stoichiometry_func_doc,
'num_eq': self.num_nw_fluids}
k: v for k, v in super().get_mandatory_constraints().items()
if k in ["mass_flow_constraints", "stoichiometry_constraints"]
}

def pr_func(self):
Expand Down Expand Up @@ -275,8 +267,12 @@ def pr_deriv(self, increment_filter, k):
k : int
Position of equation in Jacobian matrix.
"""
self.jacobian[k, 0, 1] = self.pr.val
self.jacobian[k, 2, 1] = -1
i = self.inl[0]
o = self.outl[0]
if self.is_variable(i.p):
self.jacobian[k, i.p.J_col] = self.pr.val
if self.is_variable(o.p):
self.jacobian[k, o.p.J_col] = -1

def energy_balance_func(self):
r"""
Expand Down Expand Up @@ -315,12 +311,18 @@ def energy_balance_func(self):

res = 0
for i in self.inl:
res += i.m.val_SI * (i.h.val_SI - h_mix_pT(
[0, p_ref, 0, i.fluid.val], T_ref, force_gas=True))
i.build_fluid_data()
res += i.m.val_SI * (
i.h.val_SI
- h_mix_pT(p_ref, T_ref, i.fluid_data, mixing_rule="forced-gas")
)

for o in self.outl:
res -= o.m.val_SI * (o.h.val_SI - h_mix_pT(
[0, p_ref, 0, o.fluid.val], T_ref, force_gas=True))
o.build_fluid_data()
res -= o.m.val_SI * (
o.h.val_SI
- h_mix_pT(p_ref, T_ref, o.fluid_data, mixing_rule="forced-gas")
)

res += self.calc_ti() * self.eta.val
return res
Expand Down Expand Up @@ -364,19 +366,25 @@ def calc_parameters(self):

res = 0
for i in self.inl:
res += i.m.val_SI * (i.h.val_SI - h_mix_pT(
[0, p_ref, 0, i.fluid.val], T_ref, force_gas=True))
i.build_fluid_data()
res += i.m.val_SI * (
i.h.val_SI
- h_mix_pT(p_ref, T_ref, i.fluid_data, mixing_rule="forced-gas")
)

for o in self.outl:
res -= o.m.val_SI * (o.h.val_SI - h_mix_pT(
[0, p_ref, 0, o.fluid.val], T_ref, force_gas=True))
o.build_fluid_data()
res -= o.m.val_SI * (
o.h.val_SI
- h_mix_pT(p_ref, T_ref, o.fluid_data, mixing_rule="forced-gas")
)

self.eta.val = -res / self.ti.val
self.Q_loss.val = -(1 - self.eta.val) * self.ti.val

self.pr.val = self.outl[0].p.val_SI / self.inl[0].p.val_SI
for i in range(self.num_i):
if self.inl[i].p.val < self.outl[0].p.val:
for num, i in enumerate(self.inl):
if i.p.val < self.outl[0].p.val:
msg = (
f"The pressure at inlet {i + 1} is lower than the pressure "
f"at the outlet of component {self.label}."
Expand Down

0 comments on commit 3147460

Please sign in to comment.