Skip to content

Fixing the build of Princeton-D TF Coils#372

Merged
shimwell merged 3 commits intofusion-energy:mainfrom
Allentro:princetonTF_fix
Aug 4, 2025
Merged

Fixing the build of Princeton-D TF Coils#372
shimwell merged 3 commits intofusion-energy:mainfrom
Allentro:princetonTF_fix

Conversation

@Allentro
Copy link
Contributor

@Allentro Allentro commented Jul 31, 2025

I was trying to build a simple parametric ST with Princeton-D TF coils. When using certain paramaterisations the build would hang and never finish.

Here is the code I was using:

import paramak

tf_style_2 = paramak.toroidal_field_coil_princeton_d(
    r1=5,
    r2=800,
    thickness=50,
    distance=40,
    azimuthal_placement_angles=[0],
    rotation_angle=90,
)

result2 = paramak.spherical_tokamak_from_plasma(
    radial_build=[
        (paramak.LayerType.GAP, 70),
        (paramak.LayerType.SOLID, 10),
        (paramak.LayerType.SOLID, 10),
        (paramak.LayerType.GAP, 50),
        (paramak.LayerType.PLASMA, 300),
        (paramak.LayerType.GAP, 60),
        (paramak.LayerType.SOLID, 10),
        (paramak.LayerType.SOLID, 60),
        (paramak.LayerType.SOLID, 10),
    ],
    elongation=2.5,
    rotation_angle=90,
    triangularity=0.55,
    extra_cut_shapes=[tf_style_2],
)

result2.save("spherical_tokamak_from_plasma_with_prin_tf_coils.step")

I swept r2: 100<=r2<=800.

I have a scan through the source and printed it out. It appeared to be getting stuck on the minimize() function for the error. Digging into this the error is calculating the distance between the guess and the actual value of z_0. To calculate z_0 we want the error to =0. I therefore decided to switch out the minmize function for a bracketed root-finder, where the problem can collapse quickly without being sensitive to the z_0 guess. It should be more robust and take fewer evaluations. This has solved the problem, and with a wide range of TF configurations I can get a build.

There is now a warning showing for the solver:

 lsoda--  warning..internal t (=r1) and h (=r2) are
       such that in the machine, t + h = t on the next step  
       (h = step size). solver will continue anyway
      in above,  r1 =  0.7999999135914D+03   r2 =  0.5342192331493D-13

I was going to set another PR focused on fixing this warning, but wanted to get eyes on this first now that the build completes consistently.

@shimwell
Copy link
Member

@RemDelaporteMathurin just wondering if you have any objection to merging this. I think this shape was one that you made originally.

@RemDelaporteMathurin
Copy link
Member

Sure! Thanks for the improvement Ross!

@Allentro
Copy link
Contributor Author

Allentro commented Jul 31, 2025

No worries. Great work on putting the original piece together, neat feature!

@shimwell
Copy link
Member

shimwell commented Aug 4, 2025

many thanks, sorry this took a while to reveiw

@shimwell shimwell merged commit 8a77d5a into fusion-energy:main Aug 4, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants