Physics dataclass#4268
Conversation
21955d9 to
eefc7b7
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4268 +/- ##
==========================================
- Coverage 50.13% 49.56% -0.58%
==========================================
Files 151 151
Lines 29345 28981 -364
==========================================
- Hits 14712 14364 -348
+ Misses 14633 14617 -16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.*withself.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()takesepsas a parameter but computesqbarusingself.data.physics.epsinstead. This can silently ignore the caller-providedeps; use theepsparameter in theqbarcalculation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 | ||
| ) |
| # 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 |
| 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) |
| # 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: | |||
There was a problem hiding this comment.
Can this comment be deleted?
Description
Checklist
I confirm that I have completed the following checks: