Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4086 +/- ##
==========================================
+ Coverage 47.84% 47.97% +0.12%
==========================================
Files 141 142 +1
Lines 29754 29883 +129
==========================================
+ Hits 14236 14335 +99
- Misses 15518 15548 +30 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
935e8f0 to
660cc7c
Compare
248115d to
632de11
Compare
- Updated test_physics.py to instantiate PlasmaCurrent for calculating plasma current and related methods. - Replaced direct calls to calculate_plasma_current_peng and calculate_current_coefficient_hastie with PlasmaCurrent class methods. - Modified test_stellarator.py to include PlasmaCurrent in the stellarator setup.
…r improved readability and maintainability
…ed clarity and maintainability
…ated tests for consistency
…calculations in PlasmaCurrent class
…PlasmaCurrent class
…lot_proc and update data structure in PlasmaCurrent class
539add7 to
92b344d
Compare
timothy-nunn
left a comment
There was a problem hiding this comment.
There are an awful many changes in the conventional aspect ratio cases, I suspect there is a big somewhere
2026-03-19T15:48:41.5813756Z FAILED tests/regression/test_process_input_files.py::test_input_file[large_tokamak_nof] - AssertionError: �[0;32m 8593 differences: the reference MFile contains different values for some of the variables. See the warnings for a breakdown of the differences.�[0m
2026-03-19T15:48:41.5813858Z assert 8593 == 0
2026-03-19T15:48:41.5815860Z + where 8593 = len([MFileVariableDifference(name='pfc1t4', ref=287728.4430610426, new=-2272946.4289503414, percentage_change=-889.962370341026), MFileVariableDifference(name='i_plasma_current', ref=4.0, new=9.0, percentage_change=125.0), MFileVariableDifference(name='f_c_plasma_hcd_primary', ref=0.027082630195024323, new=0.0, percentage_change=-100.0), MFileVariableDifference(name='f_c_plasma_auxiliary', ref=0.027082630195024326, new=0.0, percentage_change=-100.0), MFileVariableDifference(name='c_hcd_primary_driven', ref=453313.9488936291, new=0.0, percentage_change=-100.0), MFileVariableDifference(name='p_hcd_injected_current_total_mw', ref=9.81398334505902, new=0.0, percentage_change=-100.0), ...])
2026-03-19T15:48:41.5816768Z FAILED tests/regression/test_process_input_files.py::test_input_file[large_tokamak_eval] - AssertionError: �[0;32m 8614 differences: the reference MFile contains different values for some of the variables. See the warnings for a breakdown of the differences.�[0m
2026-03-19T15:48:41.5816850Z assert 8614 == 0
2026-03-19T15:48:41.5818785Z + where 8614 = len([MFileVariableDifference(name='pfc0t4', ref=-543745.9921847769, new=-2804442.4944127165, percentage_change=-415.7633407364417), MFileVariableDifference(name='i_plasma_current', ref=4.0, new=9.0, percentage_change=125.0), MFileVariableDifference(name='f_c_plasma_hcd_primary', ref=0.010312341172393658, new=0.0, percentage_change=-100.0), MFileVariableDifference(name='f_c_plasma_auxiliary', ref=0.010312341172393658, new=0.0, percentage_change=-100.0), MFileVariableDifference(name='c_hcd_primary_driven', ref=165936.8656852688, new=0.0, percentage_change=-100.0), MFileVariableDifference(name='p_hcd_injected_current_total_mw', ref=3.413518735361287, new=0.0, percentage_change=-100.0), ...])
2026-03-19T15:48:41.5819795Z FAILED tests/regression/test_process_input_files.py::test_input_file[low_aspect_ratio_DEMO] - AssertionError: �[0;32m 7988 differences: the reference MFile contains different values for some of the variables. See the warnings for a breakdown of the differences.�[0m
2026-03-19T15:48:41.5819868Z assert 7988 == 0
2026-03-19T15:48:41.5822069Z + where 7988 = len([MFileVariableDifference(name='pfc1t4', ref=-66468.16490802169, new=-2160158.9627523157, percentage_change=-3149.915152225931), MFileVariableDifference(name='cs_t3', ref=8023669.20057866, new=37198927.57899087, percentage_change=363.6149204195521), MFileVariableDifference(name='cs_t2', ref=8023669.20057866, new=37198927.57899087, percentage_change=363.6149204195521), MFileVariableDifference(name='f_j_cs_start_end_flat_top', ref=-0.04323663015144943, new=-0.20045146846873732, percentage_change=-363.6149204195497), MFileVariableDifference(name='big_q_plasma', ref=33.05921861558781, new=95.42180776169131, percentage_change=188.63902946786166), MFileVariableDifference(name='i_plasma_current', ref=4.0, new=9.0, percentage_change=125.0), ...])
There was a problem hiding this comment.
Can you get someone to check the formula changes here
| expected_bp=0.96008591022564971, | ||
| expected_qstar=2.900802902105021, |
There was a problem hiding this comment.
Any way of making another test that checks these calculations are still correct?
| Triangularity at 95% of the plasma boundary. | ||
| Returns | ||
| ------- | ||
| float |
There was a problem hiding this comment.
| Triangularity at 95% of the plasma boundary. | |
| Returns | |
| ------- | |
| float | |
| Triangularity at 95% of the plasma boundary. | |
| Returns | |
| ------- | |
| float |
| Cylindrical safety factor (dimensionless). | ||
| Notes |
There was a problem hiding this comment.
| Cylindrical safety factor (dimensionless). | |
| Notes | |
| Cylindrical safety factor (dimensionless). | |
| Notes |
| po.ovarrf( | ||
| self.outfile, | ||
| "Current density profile factor", | ||
| "\nCurrent density profile factor", |
There was a problem hiding this comment.
This strikes me as something that will cause problems in the MFile. What is the purpose anyway?
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def calculate_cylindrical_safety_factor( |
There was a problem hiding this comment.
Could probably be jit'ed
| except ValueError: | ||
| raise ProcessValueError( | ||
| "Illegal value of i_plasma_current", | ||
| i_plasma_current=physics_variables.i_plasma_current, | ||
| ) from None |
There was a problem hiding this comment.
| except ValueError: | |
| raise ProcessValueError( | |
| "Illegal value of i_plasma_current", | |
| i_plasma_current=physics_variables.i_plasma_current, | |
| ) from None | |
| except ValueError as e: | |
| raise ProcessValueError( | |
| "Illegal value of i_plasma_current", | |
| i_plasma_current=physics_variables.i_plasma_current, | |
| ) from e |
| physics_variables.c_plasma_peng_analytic = plasma_currents.get( | ||
| PlasmaCurrentModel.PENG_ANALYTIC_FIT | ||
| ) | ||
| physics_variables.c_plasma_peng_double_null = plasma_currents.get( | ||
| PlasmaCurrentModel.PENG_DIVERTOR_SCALING | ||
| ) | ||
| physics_variables.c_plasma_cyclindrical = plasma_currents.get( | ||
| PlasmaCurrentModel.ITER_SCALING | ||
| ) | ||
| physics_variables.c_plasma_ipdg89 = plasma_currents.get( | ||
| PlasmaCurrentModel.IPDG89_SCALING | ||
| ) | ||
| physics_variables.c_plasma_todd_empirical_i = plasma_currents.get( | ||
| PlasmaCurrentModel.TODD_EMPIRICAL_SCALING_I | ||
| ) | ||
| physics_variables.c_plasma_todd_empirical_ii = plasma_currents.get( | ||
| PlasmaCurrentModel.TODD_EMPIRICAL_SCALING_II | ||
| ) | ||
| physics_variables.c_plasma_connor_hastie = plasma_currents.get( | ||
| PlasmaCurrentModel.CONNOR_HASTIE_MODEL | ||
| ) | ||
| physics_variables.c_plasma_sauter = plasma_currents.get( | ||
| PlasmaCurrentModel.SAUTER_SCALING | ||
| ) | ||
| physics_variables.c_plasma_fiesta_st = plasma_currents.get( | ||
| PlasmaCurrentModel.FIESTA_ST_SCALING | ||
| ) |
There was a problem hiding this comment.
If these are only being calculated in output_plasma_current_models is it required to create new variables to hold their values? Surely these new variables won't be used anywhere else in the code
This pull request introduces significant improvements to how plasma current is modeled, calculated, and visualized throughout the codebase and documentation. It refactors the plasma current logic into a dedicated
PlasmaCurrentclass, updates the documentation for clarity and accuracy, expands the set of tracked plasma current variables, and adapts plotting and testing to use the new structure.Key changes include:
Refactoring and Integration of Plasma Current Calculations:
PlasmaCurrentclass, centralizing all plasma current calculations, and integrated it throughout the codebase, including in the main application logic (process/main.py), plotting (process/core/io/plot_proc.py), and unit tests (tests/unit/test_physics.py).Enhancements to Data Structure:
physics_variablesto include a comprehensive set of plasma current calculation results from different empirical and analytic models, with initialization and documentation for each new variable.Documentation Improvements:
Plotting Updates:
PlasmaCurrent, adjusted subplot indexing to accommodate new plots, and increased the number of figure pages accordingly.Testing Adaptation:
PlasmaCurrentclass and removed outdated test parameters and checks, ensuring alignment with the updated calculation interface.Checklist
I confirm that I have completed the following checks: