Add option for density pedestal setting#4181
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4181 +/- ##
==========================================
+ Coverage 50.14% 50.15% +0.01%
==========================================
Files 151 151
Lines 29355 29378 +23
==========================================
+ Hits 14719 14735 +16
- Misses 14636 14643 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Have taken the liberty to add the line averaged density and temp values here. @j-a-foster Can you please check the sanity of the line averaged calcs and also the output changes? |
There was a problem hiding this comment.
Pull request overview
This PR adds a switchable mechanism for setting pedestal/separatrix electron densities (user-input vs Greenwald-fraction) and extends profile reporting by computing and outputting line-averaged electron temperature.
Changes:
- Introduced
i_nd_plasma_pedestal_separatrix/DensityProfilePedestalTypeand centralized pedestal/separatrix density assignment via Greenwald fractions. - Added
temp_plasma_electron_line_avg_kevcomputation and surfaced it in outputs and summary plots. - Updated input validation/ranges and refreshed related documentation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
process/models/physics/profiles.py |
Adds DensityProfilePedestalType and NeProfile.set_pedestal_and_separatrix_values() to centralize pedestal/separatrix density setting. |
process/models/physics/plasma_profiles.py |
Computes/stores line-averaged electron temperature for both parabolic and pedestal parameterisations. |
process/models/physics/physics.py |
Routes pedestal/separatrix density setup through the new NeProfile method; outputs line-averaged Te; updates output gating to use the new switch. |
process/data_structure/physics_variables.py |
Adds i_nd_plasma_pedestal_separatrix and temp_plasma_electron_line_avg_kev to the data structure + initialization defaults. |
process/core/solver/iteration_variables.py |
Adjusts iteration-variable bounds for Greenwald-fraction inputs. |
process/core/io/plot/summary.py |
Displays line-averaged density and temperature in profile summary plots. |
process/core/input.py |
Updates input ranges for Greenwald-fraction variables and attempts to add the new switch (currently with a naming bug). |
process/core/init.py |
Updates density validation logic to use the new switch when interpreting manual pedestal/separatrix densities. |
documentation/source/physics-models/profiles/plasma_profiles.md |
Removes outdated guidance for toggling Greenwald-fraction behavior via negative inputs. |
documentation/source/physics-models/profiles/plasma_density_profile.md |
Documents the new switch and the Greenwald-fraction method (contains an iteration-variable index typo). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5c1d9f5 to
db349f1
Compare
…ptions and calculations for Greenwald fractions
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ofile.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… and update tests
…ations and documentation
| if ( | ||
| DensityProfilePedestalType(physics_variables.i_nd_plasma_pedestal_separatrix) | ||
| == DensityProfilePedestalType.USER_INPUT | ||
| ): | ||
| physics_variables.f_nd_plasma_pedestal_greenwald = ( | ||
| physics_variables.nd_plasma_pedestal_electron | ||
| / ( | ||
| PlasmaDensityLimit.calculate_greenwald_density_limit( | ||
| c_plasma=physics_variables.plasma_current, | ||
| rminor=physics_variables.rminor, | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| physics_variables.f_nd_plasma_separatrix_greenwald = ( | ||
| physics_variables.nd_plasma_separatrix_electron | ||
| / ( | ||
| PlasmaDensityLimit.calculate_greenwald_density_limit( | ||
| c_plasma=physics_variables.plasma_current, | ||
| rminor=physics_variables.rminor, | ||
| ) | ||
| ) | ||
| ) | ||
| elif ( | ||
| DensityProfilePedestalType(physics_variables.i_nd_plasma_pedestal_separatrix) | ||
| == DensityProfilePedestalType.GREENWALD_FRACTION | ||
| ): | ||
| physics_variables.nd_plasma_pedestal_electron = ( | ||
| physics_variables.f_nd_plasma_pedestal_greenwald | ||
| * PlasmaDensityLimit.calculate_greenwald_density_limit( | ||
| c_plasma=physics_variables.plasma_current, | ||
| rminor=physics_variables.rminor, | ||
| ) | ||
| ) | ||
| physics_variables.nd_plasma_separatrix_electron = ( | ||
| physics_variables.f_nd_plasma_separatrix_greenwald | ||
| * PlasmaDensityLimit.calculate_greenwald_density_limit( | ||
| c_plasma=physics_variables.plasma_current, | ||
| rminor=physics_variables.rminor, | ||
| ) |
| expected_nd_electron_line: float = 0.0 | ||
|
|
||
| expected_temp_plasma_electron_line_avg_kev: float = 0.0 | ||
|
|
||
| expected_ti: float = 0.0 |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| po.ovarre( | ||
| self.outfile, | ||
| "Pedestal Greenwald fraction", | ||
| "(fgwped_out)", | ||
| fgwped_out, | ||
| ) | ||
| po.ovarre( | ||
| self.outfile, | ||
| "Electron density at separatrix (nₑ,ₛₑₚ) (/m³)", | ||
| "(nd_plasma_separatrix_electron)", | ||
| physics_variables.nd_plasma_separatrix_electron, | ||
| ) | ||
| po.ovarre( | ||
| self.outfile, | ||
| "Separatrix Greenwald fraction", | ||
| "(fgwsep_out)", | ||
| fgwsep_out, | ||
| ) |
There was a problem hiding this comment.
These variable renames are not obviously listed in the PR body
There was a problem hiding this comment.
Have added. They were actually never variables before and calculated in the output 🤢
| if ( | ||
| data_structure.physics_variables.f_nd_plasma_pedestal_greenwald < 0 | ||
| or not ( | ||
| data_structure.numerics.ixc[: data_structure.numerics.nvar] == 145 |
There was a problem hiding this comment.
Why have we stopped checking if itv 145 is active?
There was a problem hiding this comment.
As checking if the f_nd_plasma_pedestal_greenwald is an iteration is detached from setting the values. The user may want to input direct values than dont iterate. In essence the new switch means the user ever inputs or has iterating either the true pedestal density value or its Greenwald fraction value
| data_structure.physics_variables.i_nd_plasma_pedestal_separatrix | ||
| ) | ||
| == DensityProfilePedestalType.USER_INPUT | ||
| and data_structure.physics_variables.nd_plasma_pedestal_electron | ||
| < data_structure.physics_variables.nd_plasma_separatrix_electron | ||
| ): | ||
| # Issue #589 Pedestal density is set manually using nd_plasma_pedestal_electron but it is less than nd_plasma_separatrix_electron. | ||
| if ( | ||
| data_structure.physics_variables.nd_plasma_pedestal_electron | ||
| < data_structure.physics_variables.nd_plasma_separatrix_electron | ||
| ): | ||
| raise ProcessValidationError( | ||
| "Density pedestal is lower than separatrix density", | ||
| nd_plasma_pedestal_electron=data_structure.physics_variables.nd_plasma_pedestal_electron, | ||
| nd_plasma_separatrix_electron=data_structure.physics_variables.nd_plasma_separatrix_electron, | ||
| ) | ||
| raise ProcessValidationError( | ||
| "Density pedestal is lower than separatrix density", | ||
| nd_plasma_pedestal_electron=data_structure.physics_variables.nd_plasma_pedestal_electron, | ||
| nd_plasma_separatrix_electron=data_structure.physics_variables.nd_plasma_separatrix_electron, | ||
| ) | ||
|
|
||
| if ( | ||
| DensityProfilePedestalType( | ||
| data_structure.physics_variables.i_nd_plasma_pedestal_separatrix | ||
| ) | ||
| == DensityProfilePedestalType.GREENWALD_FRACTION | ||
| and data_structure.physics_variables.f_nd_plasma_pedestal_greenwald | ||
| < data_structure.physics_variables.f_nd_plasma_separatrix_greenwald | ||
| ): | ||
| # Issue #589 Pedestal density is set manually using nd_plasma_pedestal_electron but it is less than nd_plasma_separatrix_electron. | ||
| raise ProcessValidationError( | ||
| "Density pedestal is lower than separatrix density", | ||
| f_nd_plasma_pedestal_greenwald=data_structure.physics_variables.f_nd_plasma_pedestal_greenwald, | ||
| f_nd_plasma_separatrix_greenwald=data_structure.physics_variables.f_nd_plasma_separatrix_greenwald, | ||
| ) |
There was a problem hiding this comment.
Can these two if checks and errors be merged into one since they are raising an error about the same thing ('Density pedestal is lower than separatrix density')
| and data_structure.physics_variables.f_nd_plasma_pedestal_greenwald | ||
| < data_structure.physics_variables.f_nd_plasma_separatrix_greenwald | ||
| ): | ||
| # Issue #589 Pedestal density is set manually using nd_plasma_pedestal_electron but it is less than nd_plasma_separatrix_electron. |
There was a problem hiding this comment.
If they cannot be combined, this comment makes no sense here
This pull request introduces significant improvements to how plasma density pedestal and separatrix values are set, validated, and documented throughout the codebase and user documentation. The changes standardize the handling of Greenwald limit fractions, clarify user input options, and enhance plotting and metadata consistency. The most important changes are grouped below:
Plasma Density Profile Calculation and Validation:
i_nd_plasma_pedestal_separatrixto control whether pedestal and separatrix densities are set by user input or as fractions of the Greenwald limit, with corresponding updates to documentation and input handling.check_processto use the new pedestal/separatrix mode, ensuring correct relationships between densities and their Greenwald fractions depending on the selected method.f_nd_plasma_pedestal_greenwaldandf_nd_plasma_separatrix_greenwaldto reflect physically meaningful limits.Greenwald Limit Fraction Handling and Metadata:
f_nd_plasma_greenwaldas a new physics variable representing the Greenwald fraction of the line-averaged electron density, with initialization, metadata, and I/O updates.f_nd_plasma_greenwaldfor use in plots and further calculations.Plotting and Output Improvements:
Standardized plot labels and text boxes to use the new Greenwald fraction variable names and added more detailed density and temperature profile information (including line-averaged values).
Added new output variables such as
temp_plasma_electron_line_avg_kevto enhance result reporting.Documentation Updates:
Updated and clarified documentation in
plasma_density_profile.mdandplasma_profiles.mdto reflect the new switch-based approach for setting pedestal and separatrix densities, and removed outdated instructions about negative Greenwald fractions.Codebase Consistency:
These changes together improve the clarity, robustness, and usability of the plasma density profile modeling in the codebase.
Checklist
I confirm that I have completed the following checks: