Skip to content

Commit

Permalink
Add more tests and fix the gas only case
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Feb 10, 2025
1 parent 4702469 commit 0ce62d8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 32 deletions.
52 changes: 22 additions & 30 deletions src/tespy/components/turbomachinery/steam_turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
from tespy.components.turbomachinery.turbine import Turbine
from tespy.tools.data_containers import ComponentProperties as dc_cp
from tespy.tools.data_containers import GroupedComponentProperties as dc_gcp
from tespy.tools.document_models import generate_latex_eq
from tespy.tools.fluid_properties import isentropic
from tespy.tools.fluid_properties import h_mix_pQ
from tespy.tools.logger import logger
from tespy.tools.helpers import fluidalias_in_list
from tespy.tools.fluid_properties.helpers import single_fluid


@component_registry
Expand Down Expand Up @@ -155,11 +157,25 @@ def get_parameters(self):
params["eta_s_dry_group"] = dc_gcp(
num_eq=1, elements=["alpha", "eta_s_dry"],
func=self.eta_s_wet_func,
deriv=self.eta_s_wet_deriv,
latex=self.eta_s_wet_func_doc)
deriv=self.eta_s_wet_deriv
)

return params

def preprocess(self, num_nw_vars):

fluid = single_fluid(self.inl[0].fluid_data)
if fluid is None:
msg = "The SteamTurbine can only be used with pure fluids."
logger.error(msg)
raise ValueError(msg)

if not fluidalias_in_list(fluid, ["water"]):
msg = "The SteamTurbine is intended to be used with water only."
logger.warning(msg)

return super().preprocess(num_nw_vars)

def eta_s_wet_func(self):
r"""
Equation for given dry isentropic efficiency of a turbine under wet
Expand Down Expand Up @@ -194,6 +210,9 @@ def eta_s_wet_func(self):
)

else: # superheated vapour
if outl.calc_phase() == "g":
return self.calc_eta_s() - self.eta_s_dry.val

dp = inl.p.val_SI - outl.p.val_SI

# compute the pressure and enthalpy at which the expansion
Expand Down Expand Up @@ -265,30 +284,3 @@ def eta_s_wet_deriv(self, increment_filter, k):
self.jacobian[k, i.h.J_col] = self.numeric_deriv(f, "h", i)
if self.is_variable(o.h, increment_filter):
self.jacobian[k, o.h.J_col] = self.numeric_deriv(f, "h", o)

def eta_s_wet_func_doc(self, label):
r"""
Equation for given dry isentropic efficiency of a turbine.
Parameters
----------
label : str
Label for equation.
Returns
-------
latex : str
LaTeX code of equations applied.
"""
latex = (
r'\begin{split}' + '\n'
r'0 &=-\left(h_\mathrm{out}-h_\mathrm{in}\right)+\left('
r'h_\mathrm{out,s}-h_\mathrm{in}\right)\cdot\eta_\mathrm{s}\\'
+ '\n'
r'\eta_\mathrm{s} &=\eta_\mathrm{s}^\mathrm{dry}\cdot \left( 1 - '
r'\alpha \cdot y_\mathrm{m} \right)\\' + '\n'
r'y_\mathrm{m} &=\frac{\left( 1-x_\mathrm{in} \right)+\left( '
r'1-x_\mathrm{out} \right)}{2}\\' + '\n'
r'\end{split}'
)
return generate_latex_eq(self, latex, label)
40 changes: 38 additions & 2 deletions tests/test_components/test_turbomachinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,46 @@ def test_SteamTurbine(self, tmp_path):
instance = SteamTurbine('turbine')
self.setup_network(instance)
fl = {'H2O': 1}
# start in gas, end in gas
self.c1.set_attr(fluid=fl, m=15, p=100, T=500)
self.c2.set_attr(Td_bp=5)
instance.set_attr(eta_s_dry=0.99, alpha=1)
self.c2.set_attr(Td_bp=1)

eta_s_dry = 0.9
instance.set_attr(eta_s_dry=0.9, alpha=1)

self.nw.solve('design')
self.nw._convergence_check()

eta_s = round(instance.eta_s.val, 4)
msg = (
f"In gas expansion isentropic ({eta_s}) and dry "
f"efficiency ({eta_s_dry}) have to be identical."
)
assert eta_s_dry == eta_s, msg

# end in two phase
self.c2.set_attr(Td_bp=None, x=0.9)
self.nw.solve('design')
self.nw._convergence_check()

eta_s = round(instance.eta_s.val, 4)
msg = (
f"In gas expansion isentropic ({eta_s}) and dry "
f"efficiency ({eta_s_dry}) cannot be identical."
)
assert eta_s_dry != eta_s, msg

# start in two phase
self.c1.set_attr(T=None, x=0.99)
self.nw.solve('design')
self.nw._convergence_check()

eta_s = round(instance.eta_s.val, 4)
msg = (
f"In gas expansion isentropic ({eta_s}) and dry "
f"efficiency ({eta_s_dry}) cannot be identical."
)
assert eta_s_dry != eta_s, msg

def test_Turbomachine(self):
"""Test component properties of turbomachines."""
Expand Down

0 comments on commit 0ce62d8

Please sign in to comment.