Add enum for thermal to electric conversion model types and update us…#4209
Add enum for thermal to electric conversion model types and update us…#4209chris-ashe wants to merge 1 commit intomainfrom
enum for thermal to electric conversion model types and update us…#4209Conversation
…age in power calculations Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed IntEnum for the thermal→electric conversion model switch (i_thermal_electric_conversion) and updates the power model logic (and documentation) to use the named enum values instead of raw integers.
Changes:
- Add
ElectricConversionModelTypes(IntEnum) inprocess/models/power.py. - Refactor
component_thermal_powers()andplant_thermal_efficiency()to compare against enum members. - Fix documentation: “User input” corresponds to
i_thermal_electric_conversion = 2.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
process/models/power.py |
Adds enum and updates conversion-model branching logic to use enum members. |
documentation/source/eng-models/power-requirements.md |
Corrects the documented value for the “User input” conversion model. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| elif ( | ||
| i_thermal_electric_conversion | ||
| == ElectricConversionModelTypes.SUPERCRITICAL_CO2_CYCLE | ||
| ): |
There was a problem hiding this comment.
There don’t appear to be unit tests covering the i_thermal_electric_conversion steam Rankine (3) / s-CO2 (4) paths in plant_thermal_efficiency(). Adding focused tests for these options would help catch enum/branch regressions like this one and validate the temperature→efficiency correlations.
| elif fwbs_variables.i_thermal_electric_conversion == 4: | ||
| elif ( | ||
| i_thermal_electric_conversion | ||
| == ElectricConversionModelTypes.SUPERCRITICAL_CO2_CYCLE |
There was a problem hiding this comment.
ElectricConversionModelTypes defines SUPERCRITICAL_CO2_BRAYTON_CYCLE, but this branch compares against ElectricConversionModelTypes.SUPERCRITICAL_CO2_CYCLE, which will raise AttributeError at runtime when i_thermal_electric_conversion == 4. Rename the enum member or update this comparison to use the defined name (and keep naming consistent with the docs: “Supercritical CO2 Brayton Cycle”).
| == ElectricConversionModelTypes.SUPERCRITICAL_CO2_CYCLE | |
| == ElectricConversionModelTypes.SUPERCRITICAL_CO2_BRAYTON_CYCLE |
| i_thermal_electric_conversion = ElectricConversionModelTypes( | ||
| fwbs_variables.i_thermal_electric_conversion | ||
| ) |
There was a problem hiding this comment.
Casting fwbs_variables.i_thermal_electric_conversion to ElectricConversionModelTypes will raise a ValueError for out-of-range values, so the final else branch that logs an out-of-range message can never execute. Either remove that else branch (since input is validated elsewhere) or wrap the enum conversion in try/except ValueError and handle/log invalid values there.
| i_thermal_electric_conversion = ElectricConversionModelTypes( | |
| fwbs_variables.i_thermal_electric_conversion | |
| ) | |
| try: | |
| i_thermal_electric_conversion = ElectricConversionModelTypes( | |
| fwbs_variables.i_thermal_electric_conversion | |
| ) | |
| except ValueError as exc: | |
| logger.error( | |
| "i_thermal_electric_conversion=%s is out of range for " | |
| "ElectricConversionModelTypes", | |
| fwbs_variables.i_thermal_electric_conversion, | |
| ) | |
| raise ProcessValueError( | |
| "Invalid i_thermal_electric_conversion: " | |
| f"{fwbs_variables.i_thermal_electric_conversion}" | |
| ) from exc |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4209 +/- ##
=======================================
Coverage 52.10% 52.11%
=======================================
Files 148 148
Lines 30389 30398 +9
=======================================
+ Hits 15835 15842 +7
- Misses 14554 14556 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…age in power calculations
Description
Checklist
I confirm that I have completed the following checks: