Skip to content

Stellarator module update#4082

Open
jjwalkowiak wants to merge 69 commits intoukaea:mainfrom
IPP-SRS:main
Open

Stellarator module update#4082
jjwalkowiak wants to merge 69 commits intoukaea:mainfrom
IPP-SRS:main

Conversation

@jjwalkowiak
Copy link

Description

Main changes:

  • coil minor radius scaling for stellarators
  • corrected stress equation for vacuum vessel
  • corrected coil height (this was actually more on the pre-process side)
  • stellarator module refactoring

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.

jjwalkowiak and others added 30 commits March 7, 2025 16:45
Copy link
Collaborator

@timothy-nunn timothy-nunn left a comment

Choose a reason for hiding this comment

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

A couple of other things I have noticed.

@timothy-nunn
Copy link
Collaborator

When you have actioned all of the comments please do click the 🔄 icon in the reviewer section to tell me you are ready for the next review.

You might also want to consider adding in a test case to our tests/regression/input_files... this will allow us to check the file runs to completion.

@jjwalkowiak
Copy link
Author

process/stellarator/coils/coils.py:70:23: RUF052 Local dummy variable _tmarg is accessed
I have no idea what _tmarg is doing.
process/stellarator/coils/quench.py:101:5: N802 Function name calculate_vv_max_force_density_from_W7X_scaling should be lowercase
Do you really want to have w7x instead of W7X?

@timothy-nunn
Copy link
Collaborator

process/stellarator/coils/coils.py:70:23: RUF052 Local dummy variable _tmarg is accessed I have no idea what _tmarg is doing. process/stellarator/coils/quench.py:101:5: N802 Function name calculate_vv_max_force_density_from_W7X_scaling should be lowercase Do you really want to have w7x instead of W7X?

  1. Rename _tmarg to tmarg
  2. You can add "W7X" to this list

    PROCESS/pyproject.toml

    Lines 207 to 229 in ca03a41

    ignore-names = [
    "*PROCESS*",
    "*Bt*",
    "*Bp*",
    "*keV*",
    "*MPa*",
    "*H*",
    "*T*",
    "*D*",
    "*He*",
    "*Be*",
    "C",
    "N",
    "O",
    "Ne",
    "Si",
    "Ar",
    "Fe",
    "Ni",
    "Kr",
    "Xe",
    "W",
    ]


def calculate_vv_max_force_density_from_W7X_scaling(rad_vv: float) -> float:
"""Actual VV force density from scaling [MN/m^3]
Based on reference values from W-7X."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Based on reference values from W-7X."""
Based on reference values from W-7X.
"""


f_a: float = None
f_st_i_total: float = None
"""Actual totail coil current to reference value from stella_config file"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Actual totail coil current to reference value from stella_config file"""
"""Actual total coil current to reference value from stella_config file"""

Comment on lines 97 to 103
# This is the old version, left for now for comparison.
# build_variables.available_radial_space = stellarator_variables.f_r * (
# stellarator_configuration.stella_config_derivative_min_lcfs_coils_dist
# * stellarator_configuration.stella_config_rminor_ref
# * (1 / stellarator_variables.f_aspect - 1)
# + stellarator_configuration.stella_config_min_plasma_coil_distance
# )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# This is the old version, left for now for comparison.
# build_variables.available_radial_space = stellarator_variables.f_r * (
# stellarator_configuration.stella_config_derivative_min_lcfs_coils_dist
# * stellarator_configuration.stella_config_rminor_ref
# * (1 / stellarator_variables.f_aspect - 1)
# + stellarator_configuration.stella_config_min_plasma_coil_distance
# )

Comment on lines 211 to 212
# po.write(self.outfile,10)
# 10 format(t43,'Thickness (m)',t60,'Radius (m)')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# po.write(self.outfile,10)
# 10 format(t43,'Thickness (m)',t60,'Radius (m)')

+ current_drive_variables.p_hcd_injected_electrons_mw
) / current_drive_variables.eta_hcd_primary_injector_wall_plug
else:
logger.error(f"isthtr {stellarator_variables.isthtr} \n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logger.error(f"isthtr {stellarator_variables.isthtr} \n")
logger.error(f"isthtr {stellarator_variables.isthtr}")

Comment on lines 233 to 237
# stellarator_variables.f_coil_aspect = (
# (physics_variables.rmajor / stellarator_variables.r_coil_minor) /
# (stellarator_configuration.stella_config_rmajor_ref /
# stellarator_configuration.stella_config_coil_rminor)
# )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# stellarator_variables.f_coil_aspect = (
# (physics_variables.rmajor / stellarator_variables.r_coil_minor) /
# (stellarator_configuration.stella_config_rmajor_ref /
# stellarator_configuration.stella_config_coil_rminor)
# )

surfaces with Fourier coefficients')
"""
physics_variables.vol_plasma = (
# stellarator_variables.f_r * stellarator_variables.f_a**2 * stellarator_configuration.stella_config_plasma_volume
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# stellarator_variables.f_r * stellarator_variables.f_a**2 * stellarator_configuration.stella_config_plasma_volume

Comment on lines 984 to 986
# heat_transport_variables.ipowerflow

# fwbs_variables.blktmodel
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# heat_transport_variables.ipowerflow
# fwbs_variables.blktmodel

physics_variables.p_plasma_rad_mw = (
physics_variables.p_plasma_rad_mw + physics_variables.psolradmw
)
# pden_plasma_rad_mw = physics_variables.p_plasma_rad_mw / physics_variables.vol_plasma # this line OVERWRITES the original definition of pden_plasma_rad_mw, probably shouldn't be defined like that as the core does not lose SOL power.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# pden_plasma_rad_mw = physics_variables.p_plasma_rad_mw / physics_variables.vol_plasma # this line OVERWRITES the original definition of pden_plasma_rad_mw, probably shouldn't be defined like that as the core does not lose SOL power.

Comment on lines 2321 to 2322
# Calculate physics_variables.beta limit. Does nothing atm so commented out
# call stblim(physics_variables.beta_vol_avg_max)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Calculate physics_variables.beta limit. Does nothing atm so commented out
# call stblim(physics_variables.beta_vol_avg_max)

@timothy-nunn timothy-nunn requested a review from ym1906 February 4, 2026 11:31
@timothy-nunn
Copy link
Collaborator

Please also ensure the unit test failures are fixed and that the regression tests stop failing with an error

@jjwalkowiak
Copy link
Author

Please also ensure the unit test failures are fixed and that the regression tests stop failing with an error

I solved most issues with units test, but with regression tests it will be more complicated.

@ym1906
Copy link
Collaborator

ym1906 commented Feb 4, 2026

  1. Coil minor radius scaling

The coil minor radius now scales with major radius via a coil-aspect factor rather than directly with plasma minor radius as before. Could you just explain the motivation for this change?

  1. Vacuum vessel stress equation

Do we have a reference for the W7-X values used? Even if it's an internal document or similar, would be useful to note.

@jjwalkowiak
Copy link
Author

Who created test: tests/unit/test_stellarator.py::test_stbild ?
Either I misunderstand something, or the reference values are contradicting each other.
f_st_rmajor=0.99099099099099097,
f_st_aspect=1,
f_st_rminor=0.99125889880147788,
How can it be, that minor and major radius have different scaling, but aspect ration is not changed?

@jjwalkowiak
Copy link
Author

2. Vacuum vessel stress equation

Do we have a reference for the W7-X values used? Even if it's an internal document or similar, would be useful to note.

https://doi.org/10.1088/1741-4326/ac2dbf

This is the best I can do. I got the correct values by email, there is no official document.

@jjwalkowiak
Copy link
Author

  1. Coil minor radius scaling

The coil minor radius now scales with major radius via a coil-aspect factor rather than directly with plasma minor radius as before. Could you just explain the motivation for this change?

You need to fit plasma-coil distance (which is changing) to blanket thickness (which is constant). If you don't change coil radius, you are not able to really scale down the design with fixed aspect ratio (because the only way to change the plasma-coil distance is by changing major radius). I am preparing a paper where I explain it in more detail.

@jjwalkowiak
Copy link
Author

I corrected the unit tests - probably against the style guidelines, but at least work now. It seems that there was also error in calculation of the nu_star in my code, probably created during some merge. (I am not sure if nu_star is actually used in any way now in stellarator)

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 30.10989% with 954 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.58%. Comparing base (ca03a41) to head (472698e).

Files with missing lines Patch % Lines
process/stellarator/stellarator.py 16.11% 406 Missing ⚠️
process/stellarator/coils/calculate.py 19.37% 104 Missing ⚠️
process/stellarator/coils/output.py 3.44% 84 Missing ⚠️
process/stellarator/coils/coils.py 37.62% 63 Missing ⚠️
process/stellarator/build.py 30.58% 59 Missing ⚠️
process/stellarator/heating.py 11.11% 56 Missing ⚠️
process/stellarator/divertor.py 11.11% 48 Missing ⚠️
process/stellarator/denisty_limits.py 38.09% 39 Missing ⚠️
process/stellarator/neoclassics.py 81.09% 31 Missing ⚠️
process/stellarator/coils/quench.py 40.62% 19 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4082      +/-   ##
==========================================
+ Coverage   46.47%   46.58%   +0.10%     
==========================================
  Files         123      135      +12     
  Lines       28902    29068     +166     
==========================================
+ Hits        13432    13540     +108     
- Misses      15470    15528      +58     

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

Copy link
Collaborator

@timothy-nunn timothy-nunn left a comment

Choose a reason for hiding this comment

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

The pre-commit quality jobs are failing again. You can install pre-commit as a hook by following our guide here https://ukaea.github.io/PROCESS/development/pre-commit/. This will flag any non-compliant code and automatically update it to follow the style guide (in most cases)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am happy with these changes to the unit test file provided you and your team are happy that the numbers have changed for a legitimate reason.

@timothy-nunn
Copy link
Collaborator

Who created test: tests/unit/test_stellarator.py::test_stbild ? Either I misunderstand something, or the reference values are contradicting each other. f_st_rmajor=0.99099099099099097, f_st_aspect=1, f_st_rminor=0.99125889880147788, How can it be, that minor and major radius have different scaling, but aspect ration is not changed?

I believe this was an automatic test. When we converted PROCESS from Fortran to Python, we ran regression tests and scraped data from functions we were converting. This allowed us to test that we hadn't changed the codes' behaviour between Fortran and Python

@timothy-nunn
Copy link
Collaborator

Please also ensure the unit test failures are fixed and that the regression tests stop failing with an error

I solved most issues with units test, but with regression tests it will be more complicated.

Just to clarify that your regression tests don't need to pass, there are several failure mechanisms that a regression test my experience:

  • An error occurs when the input file is run (this is what is happening on this branch). This type of test failure is not ok and must be fixed.
  • An error is raised because the MFile is different from the reference MFile. This is ok, as long as you and the reviewers are happy with the changes. When the PR is merged, it will update the reference MFile.

@jjwalkowiak
Copy link
Author

Please also ensure the unit test failures are fixed and that the regression tests stop failing with an error

I solved most issues with units test, but with regression tests it will be more complicated.

Just to clarify that your regression tests don't need to pass, there are several failure mechanisms that a regression test my experience:

* An error occurs when the input file is run (this is what is happening on this branch). This type of test failure is not ok and must be fixed.

* An error is raised because the MFile is different from the reference MFile. This is ok, as long as you and the reviewers are happy with the changes. When the PR is merged, it will update the reference MFile.

I think it would be best to create new regression test (input+stella_config). I will deal with this after my vacation.

@timothy-nunn
Copy link
Collaborator

Please also ensure the unit test failures are fixed and that the regression tests stop failing with an error

I solved most issues with units test, but with regression tests it will be more complicated.

Just to clarify that your regression tests don't need to pass, there are several failure mechanisms that a regression test my experience:

* An error occurs when the input file is run (this is what is happening on this branch). This type of test failure is not ok and must be fixed.

* An error is raised because the MFile is different from the reference MFile. This is ok, as long as you and the reviewers are happy with the changes. When the PR is merged, it will update the reference MFile.

I think it would be best to create new regression test (input+stella_config). I will deal with this after my vacation.

Hey @jjwalkowiak happy with this solution... as long as the stellarator is well tested I am happy for files to be updated or for new ones to be made.

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.

4 participants