Skip to content

Create plasma fields class#4144

Open
chris-ashe wants to merge 14 commits intomainfrom
create_plasma_fields_class
Open

Create plasma fields class#4144
chris-ashe wants to merge 14 commits intomainfrom
create_plasma_fields_class

Conversation

@chris-ashe
Copy link
Copy Markdown
Collaborator

@chris-ashe chris-ashe commented Mar 25, 2026

This pull request introduces a new PlasmaFields model to centralize and clarify the calculation of tokamak plasma magnetic fields. It replaces the previous use of b_plasma_poloidal_average with b_plasma_surface_poloidal_average throughout the codebase and documentation, ensuring consistent terminology and improved accuracy. Additionally, it updates documentation, plotting, and output routines to reflect these changes and provides a new, detailed documentation page for magnetic field calculations.

Key changes:

Magnetic Field Calculation Refactor:

  • Introduced the PlasmaFields model to encapsulate all magnetic field calculations, including toroidal, poloidal, and total magnetic fields. All relevant calculations in physics.py now use this model.

🔄 Renames

  • Replaced all instances of b_plasma_poloidal_average with b_plasma_surface_poloidal_average in the codebase, including variable definitions, initializations, function arguments, and output routines.

Documentation Improvements:

  • Added a new documentation page, plasma_magnetic_fields.md, providing detailed explanations and equations for toroidal and poloidal magnetic fields in tokamaks.

Plotting and Output Updates:

  • Updated plotting routines and output text to use the new b_plasma_surface_poloidal_average variable and improved the layout of magnetic field information on plots.

These changes ensure a more accurate and maintainable approach to magnetic field calculations and documentation in the codebase.## Description

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.

@chris-ashe chris-ashe added Physics Relating to the physics models Refactor labels Mar 25, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 69.49153% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.06%. Comparing base (5d1fa6f) to head (bf65593).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
process/models/physics/plasma_fields.py 68.08% 15 Missing ⚠️
process/models/physics/physics.py 50.00% 2 Missing ⚠️
process/models/physics/plasma_current.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4144      +/-   ##
==========================================
+ Coverage   47.82%   48.06%   +0.23%     
==========================================
  Files         143      144       +1     
  Lines       29991    30133     +142     
==========================================
+ Hits        14342    14482     +140     
- Misses      15649    15651       +2     

☔ 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 create_plasma_fields_class branch from 3c25bc1 to 012c0e7 Compare March 26, 2026 14:21
@chris-ashe chris-ashe marked this pull request as ready for review March 26, 2026 14:22
@chris-ashe chris-ashe requested a review from a team as a code owner March 26, 2026 14:22
@chris-ashe chris-ashe requested a review from j-a-foster March 26, 2026 14:25
@timothy-nunn timothy-nunn self-assigned this Mar 27, 2026
Copy link
Copy Markdown
Collaborator

@j-a-foster j-a-foster left a comment

Choose a reason for hiding this comment

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

Some minor changes to the docs but otherwise happy with the changes.

@chris-ashe chris-ashe force-pushed the create_plasma_fields_class branch from 72ac41d to 2105bd3 Compare March 30, 2026 09:00
Copy link
Copy Markdown
Collaborator

@j-a-foster j-a-foster left a comment

Choose a reason for hiding this comment

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

Happy with changes.

Comment on lines +2045 to +2053
"Plasma surface averaged poloidal field (T)",
"(b_plasma_surface_poloidal_average)",
physics_variables.b_plasma_surface_poloidal_average,
"OP ",
)

po.ovarrf(
self.outfile,
"Total field (sqrt(b_plasma_poloidal_average^2 + b_plasma_toroidal_on_axis^2)) (T)",
"Total field (sqrt(b_plasma_surface_poloidal_average^2 + b_plasma_toroidal_on_axis^2)) (T)",
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.

Can you move the output to the new model (even though, for now, the variable is set in this model while physics is untangled)

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

Labels

Physics Relating to the physics models Refactor Variable rename

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants