Skip to content

♻️ Refactor CS coil stresses#4262

Merged
clmould merged 54 commits into
mainfrom
refactor_cs
Jun 16, 2026
Merged

♻️ Refactor CS coil stresses#4262
clmould merged 54 commits into
mainfrom
refactor_cs

Conversation

@chris-ashe

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

Copy link
Copy Markdown
Collaborator

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

codecov-commenter commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.86381% with 116 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.86%. Comparing base (0d00ff1) to head (e06a93c).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
process/models/pfcoil.py 54.40% 88 Missing ⚠️
process/core/io/plot/summary.py 12.50% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4262      +/-   ##
==========================================
+ Coverage   48.79%   48.86%   +0.07%     
==========================================
  Files         151      151              
  Lines       29339    29474     +135     
==========================================
+ Hits        14315    14402      +87     
- Misses      15024    15072      +48     

☔ View full report in Codecov by Harness.
📢 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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
from dataclasses import dataclass

import matplotlib.pyplot as plt
import numba
import numpy as np
from scipy import optimize
from scipy.linalg import svd
from scipy.special import ellipe, ellipk

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 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

@geograham geograham left a comment

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.

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

Comment thread process/core/io/plot/summary.py
Comment thread process/models/pfcoil.py
Comment thread documentation/source/eng-models/central-solenoid.md
Comment thread documentation/source/eng-models/central-solenoid.md
@chris-ashe chris-ashe force-pushed the refactor_cs branch 2 times, most recently from e93534e to 058dab8 Compare June 3, 2026 08:59
@timothy-nunn timothy-nunn assigned geograham and unassigned geograham Jun 3, 2026

@timothy-nunn timothy-nunn left a comment

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.

Please also rebase so the tests can run on the CI

Comment thread process/models/pfcoil.py Outdated
@chris-ashe chris-ashe force-pushed the refactor_cs branch 2 times, most recently from c01e3dd to 91e6f7e Compare June 5, 2026 10:33
@chris-ashe chris-ashe requested a review from clmould June 8, 2026 10:30
@chris-ashe chris-ashe force-pushed the refactor_cs branch 2 times, most recently from dfccbf0 to 2f2ce5a Compare June 10, 2026 09:38
Comment thread documentation/source/eng-models/images/cs_eu_demo_turn.PNG
Comment thread documentation/source/eng-models/central-solenoid.md
Comment thread documentation/source/eng-models/central-solenoid.md Outdated
Comment thread process/core/input.py Outdated
Comment thread process/core/io/plot/summary.py Outdated
Comment thread tests/unit/models/test_pfcoil.py Outdated
Comment thread tests/unit/models/test_pfcoil.py
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py
chris-ashe and others added 3 commits June 11, 2026 14:32
Co-authored-by: clmould <86794332+clmould@users.noreply.github.com>
@chris-ashe chris-ashe requested a review from clmould June 11, 2026 14:08
@clmould clmould assigned clmould and unassigned timothy-nunn Jun 12, 2026
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 thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py
Comment thread process/models/pfcoil.py Outdated
Comment thread documentation/source/eng-models/images/cs_eu_demo_turn.PNG
Comment thread process/models/pfcoil.py Outdated
Comment thread process/models/pfcoil.py Outdated
Comment thread process/core/io/plot/summary.py Outdated
Comment thread process/core/io/plot/summary.py Outdated
chris-ashe and others added 4 commits June 12, 2026 13:02
Co-authored-by: clmould <86794332+clmould@users.noreply.github.com>
Co-authored-by: clmould <86794332+clmould@users.noreply.github.com>
@chris-ashe chris-ashe changed the title ♻️ Refactor CS coil ♻️ Refactor CS coil stresses Jun 16, 2026
@chris-ashe chris-ashe requested a review from clmould June 16, 2026 08:09
@je-cook

je-cook commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

I've just applied a few suggestions to push this through slightly. hope thats ok

Co-authored-by: clmould <86794332+clmould@users.noreply.github.com>

@clmould clmould left a comment

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'm happy now, will approve when Georgie has approved

Comment thread documentation/source/eng-models/images/cs_eu_demo_turn.PNG
@je-cook je-cook requested a review from geograham June 16, 2026 10:06

@geograham geograham left a comment

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.

Happy for this to go in once it is passing (var name mfile errors in regression tests at the moment).

@je-cook

je-cook commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

For the variables that are in this PR that are used in future PRs is not really ok.
This time it will go in but in future please isolate the PR more explicitly.

@clmould

clmould commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Regression changes justified, merging !

@clmould clmould merged commit e5c6faf into main Jun 16, 2026
8 of 11 checks passed
@clmould clmould deleted the refactor_cs branch June 16, 2026 13:26
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.

7 participants