Skip to content

Physics dataclass#4268

Open
clmould wants to merge 13 commits into
mainfrom
Physics-Dataclass
Open

Physics dataclass#4268
clmould wants to merge 13 commits into
mainfrom
Physics-Dataclass

Conversation

@clmould
Copy link
Copy Markdown
Collaborator

@clmould clmould commented May 21, 2026

Description

Convert physics_variables to dataclass

Also some var renaming - corrected spelling of the name Tholerus in BetaNormMaxModel Enum and in function calculate_beta_norm_max_tholerus, and to variable beta_norm_max_tholerus, to match correct spelling in physics_variables.py

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.

@clmould clmould force-pushed the Physics-Dataclass branch from 21955d9 to eefc7b7 Compare May 21, 2026 14:37
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 21, 2026

Codecov Report

❌ Patch coverage is 38.65385% with 319 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.52%. Comparing base (c0119fe) to head (354035e).

Files with missing lines Patch % Lines
process/models/physics/plasma_geometry.py 0.00% 55 Missing ⚠️
process/models/stellarator/stellarator.py 7.14% 52 Missing ⚠️
process/models/physics/plasma_profiles.py 45.23% 23 Missing ⚠️
process/models/physics/confinement_time.py 27.27% 16 Missing ⚠️
process/models/physics/fusion_reactions.py 20.00% 16 Missing ⚠️
process/models/stellarator/denisty_limits.py 22.22% 14 Missing ⚠️
process/models/physics/plasma_current.py 7.69% 12 Missing ⚠️
process/core/scan.py 0.00% 11 Missing ⚠️
process/models/build.py 42.10% 11 Missing ⚠️
process/models/physics/l_h_transition.py 28.57% 10 Missing ⚠️
... and 25 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4268      +/-   ##
==========================================
- Coverage   50.13%   49.52%   -0.62%     
==========================================
  Files         151      151              
  Lines       29349    28991     -358     
==========================================
- Hits        14714    14357     -357     
+ Misses      14635    14634       -1     

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

@timothy-nunn timothy-nunn marked this pull request as ready for review May 21, 2026 15:43
@timothy-nunn timothy-nunn requested a review from a team as a code owner May 21, 2026 15:43
@timothy-nunn timothy-nunn marked this pull request as draft May 21, 2026 15:43
@chris-ashe chris-ashe requested a review from Copilot May 21, 2026 15:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR continues the migration away from the global physics_variables module by introducing/using a PhysicsData dataclass under DataStructure.physics, updating model code and unit tests accordingly. It also wires profile and fusion-reaction models into process/main.py so physics calculations consume data via the shared DataStructure.

Changes:

  • Replace many references to physics_variables.* with self.data.physics.* (and update tests/fixtures to monkeypatch *.data.physics).
  • Introduce/use profile and fusion-reaction model instances (NeProfile, TeProfile, FusionReactionRate) and pass them into composite physics models.
  • Update solver plumbing (objectives/iteration vars/scan/logging) to read/write through data.physics.

Reviewed changes

Copilot reviewed 81 out of 82 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/unit/models/tfcoil/test_sctfcoil.py Update tests to patch sctfcoil.data.physics instead of physics_variables.
tests/unit/models/tfcoil/test_resistive_tf_coil.py Update tests to patch resistive_tf_coil.data.physics.
tests/unit/models/test_vacuum.py Update tests to patch vacuum.data.physics.
tests/unit/models/test_pulse.py Update tests to patch pulse.data.physics and remove physics_variables import.
tests/unit/models/test_power.py Update tests to patch power.data.physics.
tests/unit/models/test_pfcoil.py Update tests to patch pfcoil.data.physics / cs_coil.data.physics.
tests/unit/models/test_ife.py Update tests to patch ife.data.physics.
tests/unit/models/test_dcll.py Update tests to patch dcll.data.physics.
tests/unit/models/test_costs_2015.py Update tests to patch costs2015.data.physics.
tests/unit/models/test_costs_1990.py Update tests to patch costs.data.physics and adjust one param default.
tests/unit/models/test_buildings.py Update tests to patch buildings.data.physics.
tests/unit/models/test_build.py Update tests to patch build.data.physics.
tests/unit/models/test_availability.py Update tests to patch availability.data.physics.
tests/unit/models/stellarator/test_stellarator.py Update stellarator tests to use stellarator.data.physics and pass data= where needed.
tests/unit/models/stellarator/test_neoclassics.py Update neoclassics tests to patch neoclassics.data.physics; docstring tweak.
tests/unit/models/physics/test_plasma_profiles.py Update profile tests to use plasmaprofile fixture and data.physics.n_plasma_profile_elements.
tests/unit/models/physics/test_l_h_transition.py Simplify fixture to use process_models.physics.
tests/unit/models/physics/test_fusion_reactions.py Update tests to use process_models.fusion_reaction_rate and pass new arg(s).
tests/unit/models/physics/test_current_drive.py Update tests to write via current_drive.data.physics instead of physics_variables.
tests/unit/models/blankets/test_ccfe_hcpb.py Update tests to patch ccfe_hcpb.data.physics.
tests/unit/models/blankets/test_blanket_library.py Update tests to patch blanket_library.data.physics.
process/models/vacuum.py Switch physics inputs to self.data.physics.*.
process/models/tfcoil/superconducting.py Switch physics inputs to self.data.physics.*.
process/models/tfcoil/resistive.py Switch physics inputs/comments to self.data.physics.*.
process/models/tfcoil/base.py Switch physics inputs/output gating to self.data.physics.*.
process/models/structure.py Switch physics inputs to self.data.physics.*.
process/models/stellarator/initialization.py Initialise stellarator physics values via data.physics.
process/models/stellarator/heating.py Switch physics references to data.physics.*.
process/models/stellarator/divertor.py Switch physics references to data.physics.*.
process/models/stellarator/denisty_limits.py Refactor to use data.physics and add data parameter threading.
process/models/stellarator/coils/quench.py Switch physics geometry inputs to data.physics.*.
process/models/stellarator/build.py Switch build calculations to data.physics.* (currently introduces a syntax error—see comments).
process/models/shield.py Switch physics inputs to self.data.physics.*.
process/models/pulse.py Switch physics inputs to self.data.physics.*.
process/models/power.py Switch physics inputs to self.data.physics.*.
process/models/physics/profiles.py Make profiles Models and size profiles from data.physics.n_plasma_profile_elements.
process/models/physics/plasma_fields.py Switch outputs/logic to self.data.physics.* (one calculation should use the eps parameter—see comments).
process/models/physics/plasma_current.py Switch outputs/logic to self.data.physics.* (qbar calculations should use the eps parameter—see comments).
process/models/physics/l_h_transition.py Convert PlasmaConfinementTransition to a Model and use self.data.physics.*.
process/models/physics/impurity_radiation.py Resize profiles using data.physics.n_plasma_profile_elements; adjust to profile storage changes.
process/models/physics/exhaust.py Switch physics outputs/guards to self.data.physics.*.
process/models/physics/density_limit.py Switch to self.data.physics.* and make get_density_limit_value take the array explicitly.
process/models/pfcoil.py Switch physics inputs to self.data.physics.*.
process/models/ife.py Switch fusion power / wall-load writes to self.data.physics.*.
process/models/fw.py Switch wall-load computations to self.data.physics.*.
process/models/divertor.py Switch plasma power inputs to self.data.physics.*.
process/models/costs/costs.py Switch physics inputs/outputs to self.data.physics.*.
process/models/costs/costs_2015.py Switch physics inputs to self.data.physics.*.
process/models/buildings.py Switch geometry inputs to self.data.physics.*.
process/models/build.py Switch geometry inputs to self.data.physics.*.
process/models/blankets/hcpb.py Switch physics inputs to self.data.physics.*.
process/models/blankets/dcll.py Switch physics inputs to self.data.physics.*.
process/models/blankets/blanket_library.py Switch physics inputs to self.data.physics.*.
process/models/availability.py Switch physics inputs to self.data.physics.*.
process/main.py Wire up NeProfile/TeProfile/FusionReactionRate and add models to the data-structure setup list.
process/core/solver/objectives.py Read objective metrics from data.physics.*.
process/core/solver/iteration_variables.py Point physics iteration variables at data.physics (string module path).
process/core/solver/evaluators.py Switch debug logging to self.data.physics.*.
process/core/scan.py Switch scan mutations to self.data.physics.*.
process/core/output.py Gate “tight aspect ratio” output using data.physics.itart.
process/core/caller.py Gate “tight aspect ratio” model call using data.physics.itart.
process/core/io/plot/summary.py Rename plotted beta-norm key/model label to “Tholerus”.
documentation/source/physics-models/plasma_beta/plasma_beta.md Fix “Tholerus” spelling and referenced function name.
documentation/source/physics-models/fusion_reactions/plasma_reactions.md Update wording around the physics module naming.
documentation/source/eng-models/heating_and_current_drive/RF/culham_lower_hybrid.md Update doc wording to refer to data.physics (currently incomplete—see comments).
documentation/source/eng-models/heating_and_current_drive/RF/culham_electron_cyclotron.md Update doc wording to refer to data.physics.rmajor (currently misnumbered—see comments).
documentation/source/development/add-vars.md Update developer docs to use "physics" and data.physics.* examples.
Comments suppressed due to low confidence (1)

process/models/physics/plasma_current.py:825

  • calculate_plasma_current_peng() takes eps as a parameter but computes qbar using self.data.physics.eps instead. This can silently ignore the caller-provided eps; use the eps parameter in the qbar calculation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 87 to 94
data.build.available_radial_space = (
data.stellarator.r_coil_minor * data.stellarator.f_coil_shape
- physics_variables.rminor
- data.physics.rminor
)
+data.stellarator_config.stella_config_derivative_min_lcfs_coils_dist * (
physics_variables.rminor
data.physics.rminor
- data.stellarator.f_st_rmajor * data.stellarator_config.stella_config_rminor_ref
)
Comment on lines 137 to 144
# Check if parabolic profiles are used:
if physics_variables.i_plasma_pedestal == 0:
if i_plasma_pedestal == 0:
# Parabolic profiles used, use analytical formula:
dlimit_ecrh = ne0_max
else:
logger.error(
"It was used physics_variables.i_plasma_pedestal = 1 in a stellarator routine."
)
logger.error("It was used i_plasma_pedestal = 1 in a stellarator routine.")

return dlimit_ecrh, bt_max
Comment on lines 88 to 93
ff1, ff2, _, _ = self.current.plascar_bpol(aspect, eps, kappa, delta)

# Transform q95 to qbar
qbar = q95 * 1.3e0 * (1.0e0 - physics_variables.eps) ** 0.6e0
qbar = q95 * 1.3e0 * (1.0e0 - self.data.physics.eps) ** 0.6e0

return b_plasma_toroidal_on_axis * (ff1 + ff2) / (2.0 * np.pi * qbar)
Comment on lines 742 to 748
# Use the relation from Peng, Galambos and Shipe (1992) [STAR code] otherwise
ff1, ff2, _, _ = self.plascar_bpol(aspect, eps, kappa, delta)

# Transform q95 to qbar
qbar = q95 * 1.3e0 * (1.0e0 - physics_variables.eps) ** 0.6e0
qbar = q95 * 1.3e0 * (1.0e0 - self.data.physics.eps) ** 0.6e0

return b_plasma_toroidal_on_axis * (ff1 + ff2) / (2.0 * np.pi * qbar)
9. Calculate several intermediate terms, `term01`, `term02`, `term03`, and `term04`, using different formulas involving `nplacc`, `data.physics.zeff`, `tlocal`, `epslh`, and `x`.
10. Calculate the current drive efficiency, `gamlh`, using the formula `term01 * term02 * (1.0e0 - term03 / term04)`.
11. Return the current drive efficiency normalised by the product of `0.1e0 * dlocal` and `physics_variables.rmajor`.
11. Return the current drive efficiency normalised by the product of `0.1e0 * dlocal` and `data.physics`.
$$

7. Calculate the current drive efficiency by dividing `ecgam` by `(dlocal * physics_variables.rmajor)`.
1. Calculate the current drive efficiency by dividing `ecgam` by `(dlocal * data.physics.rmajor)`.
@@ -2335,14 +2332,14 @@ def acc2272(self):
"""
if self.data.ife.ife != 1:
# Previous calculation, using molflow_plasma_fuelling_required in Amps:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Can this comment be deleted?

@timothy-nunn timothy-nunn self-assigned this May 22, 2026
@clmould clmould marked this pull request as ready for review May 22, 2026 10:39
@clmould clmould force-pushed the Physics-Dataclass branch from 3d4b6ce to bc60b96 Compare May 22, 2026 11:59
Comment thread documentation/source/physics-models/fusion_reactions/plasma_reactions.md Outdated
Comment on lines -151 to -153
monkeypatch.setattr(
pv, "f_plasma_fuel_deuterium", setfusionpowersparam.f_plasma_fuel_deuterium
)
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.

This seems to not be patched anymore?

Comment on lines +184 to +188
) = power_at_ignition_point(
self,
self.data.stellarator.max_gyrotron_frequency,
self.data.stellarator.te0_ecrh_achievable,
self.data,
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.

If we are already passing in self, we don't need to pass in self.data too

@clmould clmould requested a review from timothy-nunn May 22, 2026 15:35
@clmould clmould force-pushed the Physics-Dataclass branch from e02030f to 354035e Compare May 22, 2026 16:24
@clmould clmould mentioned this pull request May 22, 2026
69 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants