Skip to content

Add DivertorNumberModels enum and refactor i_single_null usage across…#4218

Open
chris-ashe wants to merge 1 commit into
mainfrom
add_i_single_null_enum
Open

Add DivertorNumberModels enum and refactor i_single_null usage across…#4218
chris-ashe wants to merge 1 commit into
mainfrom
add_i_single_null_enum

Conversation

@chris-ashe
Copy link
Copy Markdown
Collaborator

… models

Description

Checklist

I confirm that I have completed the following checks:

  • My changes follow the PROCESS style guide
  • I have justified any large differences in the regression tests caused by this pull request in the comments.
  • I have added new tests where appropriate for the changes I have made.
  • If I have had to change any existing unit or integration tests, I have justified this change in the pull request comments.
  • If I have made documentation changes, I have checked they render correctly.
  • I have added documentation for my change, if appropriate.

… models

Co-authored-by: Copilot <copilot@github.com>
@chris-ashe chris-ashe force-pushed the add_i_single_null_enum branch from 4db632a to 0cc91ae Compare May 19, 2026 09:31
@chris-ashe chris-ashe marked this pull request as ready for review May 19, 2026 09:32
@chris-ashe chris-ashe requested a review from a team as a code owner May 19, 2026 09:32
Copilot AI review requested due to automatic review settings May 19, 2026 09:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DivertorNumberModels enum (intended mapping: DOUBLE_NULL=0, SINGLE_NULL=1).
  • Refactor i_single_null comparisons in TF coil shaping, plasma geometry, divertor heat-load sizing, and build/init validation logic.
  • Start casting physics_variables.i_single_null to the enum in parts of process/models/build.py and process/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). When output is False, this will raise UnboundLocalError. Define/cast i_single_null before the if 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 thread process/models/build.py
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
Comment thread process/core/init.py
)

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants