Skip to content

♻️ Refactor CS coil#4262

Open
chris-ashe wants to merge 36 commits into
mainfrom
refactor_cs
Open

♻️ Refactor CS coil#4262
chris-ashe wants to merge 36 commits into
mainfrom
refactor_cs

Conversation

@chris-ashe
Copy link
Copy Markdown
Collaborator

@chris-ashe chris-ashe commented May 19, 2026

This pull request makes significant improvements to the documentation and data structures for the central solenoid (CS) in the engineering models, as well as updates the plotting and cost calculation code to support new geometry and stress parameters. The main focus is on clarifying and expanding the CS geometry and stress calculations, adding new physical variables, and ensuring these are reflected throughout the codebase and documentation.

Documentation and Model Improvements:

  • Major expansion and clarification of the central solenoid (CS) geometry and stress calculation documentation, including new equations, definitions, and references.
  • Addition of new physical variables and parameters to the CS and PF coil data structures, such as inner/outer radii, toroidal area, steel area, cable space area, various stress profiles, and operating temperature.

Plotting and Visualization Enhancements:

  • Updates to CS coil structure and stress profile plots to include new parameters (e.g., toroidal area, hoop and radial stress profiles), and improved labeling and layout for clarity.

Cost Model Adjustments:

  • Cost calculations for PF coils now use the new a_cs_cable_space variable instead of the old awpoh, ensuring consistency with the revised data structure.

Documentation and Model Updates

  • Expanded and clarified the CS geometry and stress calculation documentation, including new sections on turn geometry, bore/peak field calculations, and explicit equations for radial and hoop stresses with referenced literature.
  • Added new variables to PFCoilData for inner/outer radius, upper/lower/middle z locations, toroidal area, steel area, cable space area, bore field, outer midplane field, and detailed stress profiles.
  • Clarified and renamed variables in BuildData for better consistency (e.g., specifying "radial" thickness).
  • Added temp_cs_superconductor_operating as a new input and data variable for CS operating temperature.

Plotting and Visualization

  • Updated CS coil structure plots to display the new toroidal area and improved axis/label formatting for stress plots.
  • Enhanced the main plot routine to include new subplots for radial and hoop stress profiles using the updated CSCoil and CsFatigue models.

Cost Model

  • Updated cost calculations for PF coil conductor and superconductor to use the new a_cs_cable_space variable, replacing the deprecated awpoh.

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.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 20, 2026

Codecov Report

❌ Patch coverage is 68.61314% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.18%. Comparing base (6a55d75) to head (2923f21).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/models/pfcoil.py 67.56% 36 Missing ⚠️
process/core/io/plot/summary.py 22.22% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4262      +/-   ##
==========================================
+ Coverage   50.14%   50.18%   +0.04%     
==========================================
  Files         151      151              
  Lines       29355    29451      +96     
==========================================
+ Hits        14719    14780      +61     
- Misses      14636    14671      +35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chris-ashe chris-ashe force-pushed the refactor_cs branch 3 times, most recently from 29f4622 to 035b649 Compare May 27, 2026 09:01
@chris-ashe chris-ashe requested a review from geograham May 27, 2026 09:32
@chris-ashe chris-ashe marked this pull request as ready for review May 27, 2026 09:32
@chris-ashe chris-ashe requested a review from a team as a code owner May 27, 2026 09:32
Copilot AI review requested due to automatic review settings May 27, 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 refactors the Central Solenoid (CS) engineering model by introducing clearer CS geometry/turn-geometry data structures, expanding CS-related variables (geometry, stress, temperature), and updating outputs, plotting, and cost calculations to use the new fields.

Changes:

  • Refactors CS geometry and EU-DEMO turn geometry routines to return dataclasses and propagates new CS geometry variables through the PF/CS model.
  • Replaces legacy CS conductor+void area variable (awpoh) with a_cs_cable_space across models, costs, and tests; adds CS operating temperature input/variable.
  • Extends CS plotting and documentation to cover new geometry and stress quantities (including radial/hoop stress profiles and toroidal area).

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/unit/models/test_pfcoil.py Updates CS-related unit tests for new dataclass returns and updated CS stress/area APIs.
tests/unit/models/test_costs_1990.py Updates cost-model tests to use a_cs_cable_space instead of awpoh.
process/models/pfcoil.py Implements CS dataclasses, new CS stress/geometry fields, updated outputs, and adds CS stress plotting helpers.
process/models/costs/costs.py Switches PF/CS cost calculations from awpoh to a_cs_cable_space.
process/data_structure/pfcoil_variables.py Adds/renames CS data fields (geometry, areas, stress profiles, operating temperature).
process/data_structure/build_variables.py Clarifies CS build-variable docstrings (radial thickness naming).
process/core/io/plot/summary.py Updates summary plotting to include new CS stress subplots and CS toroidal area annotation.
process/core/input.py Adds new input variable temp_cs_superconductor_operating.
documentation/source/eng-models/central-solenoid.md Expands CS documentation with new geometry/stress sections and equations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread process/models/pfcoil.py
Comment on lines 3 to 16
@@ -10,6 +12,7 @@
from process.core import constants
from process.core import process_output as op
from process.core.exceptions import ProcessValueError
from process.core.io.mfile import MFile
from process.core.model import DataStructure, Model
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py
Comment on lines +4115 to +4134
Parameters
----------
r_stress_point : float/np.ndarray
Radial location at which to calculate the hoop stress (m)
r_cs_inner : float
Inner radius of the central solenoid (m)
r_cs_outer : float
Outer radius of the central solenoid (m)
j_cs : float
Current density in the central solenoid (A/m^2)
b_cs_inner : float
Magnetic field at the inner radius of the central solenoid (T)
f_poisson_cs_structure : float
Poisson's ratio of the central solenoid structure (dimensionless)

Returns
-------
float
radial stress at the specified radial location (MPa)

Comment thread documentation/source/eng-models/central-solenoid.md Outdated
Comment thread documentation/source/eng-models/central-solenoid.md Outdated
Comment thread documentation/source/eng-models/central-solenoid.md Outdated
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py Outdated
Comment on lines +4101 to +4109
def calculate_cs_radial_stress(
self,
r_stress_point: float | np.ndarray,
r_cs_inner: float,
r_cs_outer: float,
j_cs: float,
b_cs_inner: float,
f_poisson_cs_structure: float,
) -> float:
@timothy-nunn timothy-nunn self-assigned this May 29, 2026
Copy link
Copy Markdown
Collaborator

@geograham geograham left a comment

Choose a reason for hiding this comment

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

A few minor things and worth looking through the copilot suggestions.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  1. The time labels on the currents profile over time plot are currently overlapping.
  2. The red dot on the CS poloidal x-section plot is unlabelled.

Comment thread process/models/pfcoil.py
- If the calculated conduit thickness is negative or too small, it is set to a minimum value of 1 mm.
- The calculation assumes a stadium-shaped cross-section for the CS turn.
- If the calculated conduit thickness is negative or too small, it is set
to a minimum value of 1 mm.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why 1 mm?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was here when I got to the issue, I'm assuming this is to force it to a minimum viable value to prevent divide by zero errors.

Switch `iohcl` controls whether a central solenoid is present. A value of 1 denotes that this coil
is present, and should be assigned a non-zero thickness `dr_cs`. A value of `iohcl` = 0 denotes
that no central solenoid is present, in which case the thickness `dr_cs` should be zero. No PF
coils should be located at positions defined by `i_pf_location(j)` = 1 if no central solenoid is present.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could explain what i_pf_location(j) = 1 means.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is outside the PR. I will actually write an enum for that asap


The turn geometry is calculated as follows:

1. The vertical height of the turn is given by:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am getting some errors for the equations below, are they displaying ok for you?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You normally need to just refresh the page and they load

chris-ashe and others added 23 commits June 3, 2026 09:56
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

5 participants