51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Evaluation helpers for cycle sensitivity analysis."""
|
|
|
|
from .cycles import BraytonCycle
|
|
|
|
|
|
RC_FIXED_KEYS = ("T_low", "T_high", "p_low", "p_high", "ploss")
|
|
RC_PARAM_KEYS = (
|
|
"x",
|
|
"compressor_eff",
|
|
"recompressor_eff",
|
|
"turbine_eff",
|
|
"recuperator_eff",
|
|
"highT_recuperator_eff",
|
|
)
|
|
|
|
|
|
def _require_keys(data, required_keys, data_name):
|
|
missing = [key for key in required_keys if key not in data]
|
|
if missing:
|
|
missing_text = ", ".join(missing)
|
|
raise ValueError(f"{data_name} missing required keys: {missing_text}")
|
|
|
|
|
|
def evaluate_rc_efficiency(fixed_params, params, refprop_path=None):
|
|
"""Return the recompression Brayton cycle thermal efficiency.
|
|
|
|
The returned efficiency is a decimal value, for example 0.45 means 45%.
|
|
A new cycle instance is created for each evaluation so repeated sensitivity
|
|
runs do not reuse component state from previous cases.
|
|
"""
|
|
fixed = dict(fixed_params)
|
|
cycle_params = dict(params)
|
|
|
|
_require_keys(fixed, RC_FIXED_KEYS, "fixed_params")
|
|
_require_keys(cycle_params, RC_PARAM_KEYS, "params")
|
|
|
|
cycle_kwargs = {"name": "rc efficiency evaluation"}
|
|
if refprop_path is not None:
|
|
cycle_kwargs["refprop_path"] = refprop_path
|
|
|
|
cycle = BraytonCycle(**cycle_kwargs)
|
|
return cycle.RC(
|
|
T_low=fixed["T_low"],
|
|
T_high=fixed["T_high"],
|
|
p_low=fixed["p_low"],
|
|
p_high=fixed["p_high"],
|
|
ploss=fixed["ploss"],
|
|
param=cycle_params,
|
|
)
|