Add DivertorNumberModels enum and refactor i_single_null usage across…#4218
Open
chris-ashe wants to merge 1 commit into
Open
Add DivertorNumberModels enum and refactor i_single_null usage across…#4218chris-ashe wants to merge 1 commit into
enum and refactor i_single_null usage across…#4218chris-ashe wants to merge 1 commit into
Conversation
… models Co-authored-by: Copilot <copilot@github.com>
4db632a to
0cc91ae
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a DivertorNumberModels IntEnum intended to replace the raw i_single_null magic numbers (0/1) and refactors several model call sites to compare against the enum values for improved readability/consistency.
Changes:
- Add
DivertorNumberModelsenum (intended mapping:DOUBLE_NULL=0,SINGLE_NULL=1). - Refactor
i_single_nullcomparisons in TF coil shaping, plasma geometry, divertor heat-load sizing, and build/init validation logic. - Start casting
physics_variables.i_single_nullto the enum in parts ofprocess/models/build.pyandprocess/core/init.py.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| process/models/build.py | Adds DivertorNumberModels and uses it in vertical/radial build logic. |
| process/models/tfcoil/base.py | Uses the enum in TF coil inner shape logic and adds an import for it. |
| process/models/geometry/plasma.py | Uses the enum in plasma boundary generation for single vs double null. |
| process/models/divertor.py | Uses the enum to choose single vs double null divertor area calculation. |
| process/core/init.py | Casts i_single_null to the enum for initialization-time configuration checks. |
Comments suppressed due to low confidence (2)
process/models/build.py:183
- i_single_null is only assigned inside the
if output:block, but it is later used unconditionally (e.g., the divertor coil vertical location logic). Whenoutputis False, this will raise UnboundLocalError. Define/cast i_single_null before theif output:so it is always available.
i_single_null = DivertorNumberModels(physics_variables.i_single_null)
if i_single_null == DivertorNumberModels.DOUBLE_NULL:
process/models/divertor.py:189
- If i_single_null is not SINGLE_NULL or DOUBLE_NULL, neither branch assigns
areadv, but it is used immediately afterwards (pflux_div_heat_load_mw calculation), which will raise UnboundLocalError. Add an explicit else branch that raises ProcessValueError/ProcessValidationError (or otherwise handles unexpected values) so invalid inputs fail with a clear error.
elif i_single_null == DivertorNumberModels.DOUBLE_NULL:
areadv = 2.0 * (a1 + a2 + a3)
if self.data.divertor.i_div_heat_load == 1:
self.data.divertor.pflux_div_heat_load_mw = p_plasma_separatrix_mw / areadv
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+28
to
29
| from process.models.build import DivertorNumberModels | ||
| from process.models.superconductors import SuperconductorModel |
Comment on lines
+25
to
+29
| class DivertorNumberModels(IntEnum): | ||
| """Enum for divertor number models. `i_single_null` is the index for this enum.""" | ||
|
|
||
| DOUBLE_NULL = 0 | ||
| SINGLE_NULL = 1 |
| ) | ||
|
|
||
| if data_structure.physics_variables.i_single_null == 0: | ||
| i_single_null = DivertorNumberModels(data_structure.physics_variables.i_single_null) |
Comment on lines
7
to
13
|
|
||
| import numpy as np | ||
|
|
||
| from process.models.build import DivertorNumberModels | ||
| from process.models.physics.plasma_geometry import PlasmaShapeModelType | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… models
Description
Checklist
I confirm that I have completed the following checks: