Skip to content

Conversation

@chris-ashe
Copy link
Collaborator

@chris-ashe chris-ashe commented Jan 20, 2026

This pull request introduces a new PlasmaBeta class to centralize and standardize plasma beta calculations across the codebase. The changes refactor existing code to use this class, update dependencies, and add new unit tests for its methods. The most important changes are grouped below:

Core Refactoring and Architecture:

  • Added a new PlasmaBeta class to process.physics and refactored the codebase to use this class for all plasma beta-related calculations, replacing previous standalone functions.

  • Updated the initialization of major classes (main.py, stellarator.py) to instantiate and pass PlasmaBeta objects where needed, ensuring consistent access to beta calculations throughout the application.
    Code Cleanup and Removal:

  • Removed the now-obsolete fast_alpha_beta function from process/physics_functions.py, migrating its logic to the new PlasmaBeta class.

  • Updated all usages of beta calculation functions to use the new class methods, including replacing calls in the Stellarator model.

Testing and Validation:

  • Refactored unit tests in test_physics.py and test_stellarator.py to use the new PlasmaBeta class and its methods, ensuring all previous tests remain valid and comprehensive.
  • Added new unit tests for additional PlasmaBeta methods, such as calculate_normalised_beta and calculate_plasma_energy_from_beta, to improve coverage and reliability.

Dependency and Import Updates:

  • Cleaned up imports in affected files to remove unused beta calculation functions and ensure all references point to the new PlasmaBeta class.

These changes improve maintainability by centralizing plasma beta logic, reduce code duplication, and enhance test coverage.## 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 self-assigned this Jan 20, 2026
@chris-ashe chris-ashe added Physics Relating to the physics models Refactor labels Jan 20, 2026
@chris-ashe chris-ashe force-pushed the create_beta_class branch 2 times, most recently from 20e44af to ce7c700 Compare January 20, 2026 15:02
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 37.24138% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.49%. Comparing base (6ba13ca) to head (a68cdac).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
process/physics.py 36.61% 90 Missing ⚠️
process/main.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4053      +/-   ##
==========================================
+ Coverage   46.47%   46.49%   +0.02%     
==========================================
  Files         123      124       +1     
  Lines       28902    28955      +53     
==========================================
+ Hits        13432    13464      +32     
- Misses      15470    15491      +21     

☔ 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_beta_class branch 5 times, most recently from 00a9ee6 to ec47444 Compare January 21, 2026 09:08
@chris-ashe chris-ashe marked this pull request as ready for review January 21, 2026 10:11
@chris-ashe chris-ashe requested a review from a team as a code owner January 28, 2026 10:01
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.

I still think some more calculations can be moved into the new class

Comment on lines 1597 to 1603
# Normalised beta from Troyon beta limit
physics_variables.beta_norm_total = self.beta.calculate_normalised_beta(
beta=physics_variables.beta_total_vol_avg,
rminor=physics_variables.rminor,
c_plasma=physics_variables.plasma_current,
b_field=physics_variables.b_plasma_toroidal_on_axis,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can go into the Beta.run section

Comment on lines 2521 to 2524
physics_variables.beta_norm_max_wesson = (
self.beta.calculate_beta_norm_max_wesson(
ind_plasma_internal_norm=physics_variables.ind_plasma_internal_norm
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this calculation

# Original scaling law
physics_variables.beta_norm_max_original_scaling = (
self.calculate_beta_norm_max_original(eps=physics_variables.eps)
self.beta.calculate_beta_norm_max_original(eps=physics_variables.eps)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this one

physics_variables.beta_norm_max_menard = self.calculate_beta_norm_max_menard(
eps=physics_variables.eps
physics_variables.beta_norm_max_menard = (
self.beta.calculate_beta_norm_max_menard(eps=physics_variables.eps)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this one

Comment on lines 2538 to 2543
physics_variables.beta_norm_max_thloreus = (
self.beta.calculate_beta_norm_max_thloreus(
c_beta=physics_variables.c_beta,
pres_plasma_on_axis=physics_variables.pres_plasma_thermal_on_axis,
pres_plasma_vol_avg=physics_variables.pres_plasma_thermal_vol_avg,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this one

Comment on lines 2547 to 2550
physics_variables.beta_norm_max_stambaugh = (
self.calculate_beta_norm_max_stambaugh(
self.beta.calculate_beta_norm_max_stambaugh(
f_c_plasma_bootstrap=current_drive_variables.f_c_plasma_bootstrap,
kappa=physics_variables.kappa,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this one

Comment on lines 2556 to 2570
try:
model = BetaNormMaxModel(int(physics_variables.i_beta_norm_max))
physics_variables.beta_norm_max = self.beta.get_beta_norm_max_value(model)
except ValueError:
raise ProcessValueError(
"Illegal value of i_beta_norm_max",
i_beta_norm_max=physics_variables.i_beta_norm_max,
)
) from None

# calculate_beta_limit() returns the beta_vol_avg_max for beta
physics_variables.beta_vol_avg_max = calculate_beta_limit(
physics_variables.b_plasma_toroidal_on_axis,
physics_variables.beta_norm_max,
physics_variables.plasma_current,
physics_variables.rminor,
physics_variables.beta_vol_avg_max = self.beta.calculate_beta_limit_from_norm(
b_plasma_toroidal_on_axis=physics_variables.b_plasma_toroidal_on_axis,
beta_norm_max=physics_variables.beta_norm_max,
plasma_current=physics_variables.plasma_current,
rminor=physics_variables.rminor,
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this bit?

@timothy-nunn timothy-nunn merged commit e827793 into main Feb 11, 2026
10 checks passed
@timothy-nunn timothy-nunn deleted the create_beta_class branch February 11, 2026 14:51
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants