Skip to content

WIP: TF Temperature margin improvements: calculation and de-discombobulation - #4689

Open
CoronelBuendia wants to merge 29 commits into
mainfrom
matti/4628-alternative-T-margin
Open

CoronelBuendia wants to merge 29 commits into
mainfrom
matti/4628-alternative-T-margin

Conversation

@CoronelBuendia

@CoronelBuendia CoronelBuendia commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #4628, changing T_margin > T_margin_min to j_tf_wp < j_tf_wp_temp_margin
Closes #4687, removing duplicate/obsolete variables, and removing the inconsistent calculation of T margin and critical current density in CROCO TF coils.
Closes #3674 (for my naïve updating of obsolete variables in the input file given in the issue, this PR does not run into the error, but does fail to converge pretty quickly. Needs more testing to prove it works better.)

  • fails_supercon.IN.DAT.txt Error not encountered, fails to converge VMCON error code = 5 (SolverOutputCondition.NO_SOLUTION)
  • STEP_supercon_fail.IN.DAT.txt Error not encountered during optimisation (but would be if i_plant_availability > 1), and errors in post-processing. The required current density in the superconductor is significantly above the critical current at the first iteration, and it never recovers. Zero or negative TF turn area appears likely. VMCON error code = 5 (SolverOutputCondition.NO_SOLUTION). For this case I find no feasible solution with the warning "superconducting.py:2280) Superconductor current density residual for temperature margin calculation is not sufficiently close to zero: -0.909335 (normalised tolerance: 1e-10)"

Summary of naming / refactoring changes:

  • Removes the duplicated temp_margin variable on tfcoil
  • Deprecates the tmargmin variable (applied to both CS and TF coils)
  • Centres all TF coil temperature margin terms on:
    • temp_tf_superconductor_margin_min (input) temperature margin associated with constraint 36
    • temp_tf_superconductor_margin actual temperature margin
  • Adds j_tf_wp_temp_margin : allowable TF coil winding pack current density, for specified temperature margin (A/m²), in line with j_tf_wp_critical (eqcon 33) and j_tf_wp_quench_heat_max(eqcon 35)
  • Refactors some functions in superconducting TF (apologies, I just couldn't)

Summary of technical changes:

  • Changes constraint equation 35 (T_margin > T_margin_min) to the numerical cheaper and more robust (j_tf_wp < j_tf_wp_temp_margin), bringing it in line with the formulations in constraint equations 33 and 35.
  • Only explicitly calculates temperature margin in post-processing, or if availability_model >= 2
    • This is basically to avoid the root-finding operation for the current-sharing temperature at all costs
    • This is only necessary at present because:
      • of the availability models which require temperature margin.
      • we had discussed beforehand not to introduce a new iteration variable. If the availability models are heavily used, it would be wiser numerically to add a temperature margin variable, because this side-steps the need for calculating the temperature margin altogether. Constraint 33 only calculates the critical current at operational temperature, so no root-finding required
      • If the temperature margin calculation fails in post-processing (usually degenerate cases, np.nan is returned)
  • Changes the implementation of calculate_superconductor_temperature_margin from an unbounded Newton root-finding to a bounded least squares optimisation with a check on the minimum value ~ 0.
  • Removes the inconsistent use of superconducting current density parameterisations in CROCO TF coil (here and here).

I have not looked at the CS coil, but it may benefit from similar treatment.

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.

@CoronelBuendia
CoronelBuendia requested a review from a team as a code owner October 15, 2026 15:23
@github-actions

Copy link
Copy Markdown

⚠️ improve_quality_job warning!

Files changed by this PR have introduced 1 more linting errors when compared to main

Please fix these

To check what these are, run hatch run lint:fmt_extra on your branch and on main

@CoronelBuendia CoronelBuendia added TF Coil Toroidal field coil Bug Something isnt working labels Oct 16, 2026
@codecov-commenter

codecov-commenter commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.50877% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.25%. Comparing base (493ed99) to head (7eb346c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/models/tfcoil/superconducting.py 44.68% 52 Missing ⚠️
process/models/availability.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4689      +/-   ##
==========================================
- Coverage   50.28%   50.25%   -0.03%     
==========================================
  Files         181      181              
  Lines       30532    30627      +95     
==========================================
+ Hits        15353    15392      +39     
- Misses      15179    15235      +56     

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

@CoronelBuendia
CoronelBuendia force-pushed the matti/4628-alternative-T-margin branch from d5a5cc4 to b431ce8 Compare October 16, 2026 13:09
@CoronelBuendia CoronelBuendia changed the title WIP: Temperature margin improvements: calculation and de-discombobulation WIP: TF Temperature margin improvements: calculation and de-discombobulation Oct 16, 2026
@CoronelBuendia

Copy link
Copy Markdown
Contributor Author

I can't yet explain the stellarator regression failures.

I thought all I did there was rename tmargmin... still investigating

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

Labels

Bug Something isnt working TF Coil Toroidal field coil

Projects

None yet

2 participants