Skip to content

Add option for density pedestal setting#4181

Open
chris-ashe wants to merge 17 commits into
mainfrom
add_option_for_density_pedestal_setting
Open

Add option for density pedestal setting#4181
chris-ashe wants to merge 17 commits into
mainfrom
add_option_for_density_pedestal_setting

Conversation

@chris-ashe
Copy link
Copy Markdown
Collaborator

@chris-ashe chris-ashe commented Apr 13, 2026

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:

  • Introduced a new switch variable i_nd_plasma_pedestal_separatrix to 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.
  • Refactored validation logic in check_process to use the new pedestal/separatrix mode, ensuring correct relationships between densities and their Greenwald fractions depending on the selected method.
  • Updated input variable ranges and iteration variable definitions for f_nd_plasma_pedestal_greenwald and f_nd_plasma_separatrix_greenwald to reflect physically meaningful limits.

Greenwald Limit Fraction Handling and Metadata:

  • Added f_nd_plasma_greenwald as a new physics variable representing the Greenwald fraction of the line-averaged electron density, with initialization, metadata, and I/O updates.
  • Updated the density limit model to compute and assign f_nd_plasma_greenwald for 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_kev to enhance result reporting.
    Documentation Updates:

  • Updated and clarified documentation in plasma_density_profile.md and plasma_profiles.md to reflect the new switch-based approach for setting pedestal and separatrix densities, and removed outdated instructions about negative Greenwald fractions.

Codebase Consistency:

  • Updated all relevant files and function signatures to consistently use the new variables and logic for plasma density profile handling.

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:

  • 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 added Profiles Relating to the plasma profiles Refactor labels Apr 13, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 51.85185% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.15%. Comparing base (6a55d75) to head (737b19f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/models/physics/physics.py 0.00% 13 Missing ⚠️
process/models/physics/profiles.py 60.00% 8 Missing ⚠️
process/core/io/plot/summary.py 0.00% 2 Missing ⚠️
process/core/init.py 80.00% 1 Missing ⚠️
process/models/physics/density_limit.py 0.00% 1 Missing ⚠️
process/models/physics/plasma_profiles.py 50.00% 1 Missing ⚠️
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.
📢 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 requested a review from j-a-foster April 13, 2026 14:28
@chris-ashe chris-ashe marked this pull request as ready for review April 13, 2026 14:28
@chris-ashe chris-ashe requested a review from a team as a code owner April 13, 2026 14:28
Copilot AI review requested due to automatic review settings April 13, 2026 14:28
@chris-ashe
Copy link
Copy Markdown
Collaborator Author

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?

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 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 / DensityProfilePedestalType and centralized pedestal/separatrix density assignment via Greenwald fractions.
  • Added temp_plasma_electron_line_avg_kev computation 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.

Comment thread process/core/input.py Outdated
Comment thread documentation/source/physics-models/profiles/plasma_density_profile.md Outdated
Comment thread process/models/physics/plasma_profiles.py
Comment thread process/models/physics/profiles.py
@timothy-nunn timothy-nunn self-assigned this Apr 14, 2026
Comment thread process/models/physics/profiles.py Outdated
Comment thread documentation/source/physics-models/profiles/plasma_density_profile.md Outdated
@chris-ashe chris-ashe force-pushed the add_option_for_density_pedestal_setting branch from 5c1d9f5 to db349f1 Compare May 21, 2026 09:32
chris-ashe and others added 6 commits May 21, 2026 13:35
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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Comment thread process/models/physics/profiles.py Outdated
Comment thread process/models/physics/profiles.py Outdated
Comment on lines +275 to +314
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,
)
Comment thread process/core/init.py Outdated
Comment thread process/core/input.py Outdated
Comment on lines 217 to 221
expected_nd_electron_line: float = 0.0

expected_temp_plasma_electron_line_avg_kev: float = 0.0

expected_ti: float = 0.0
chris-ashe and others added 2 commits May 21, 2026 14:52
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines -2533 to -2550
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,
)
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.

These variable renames are not obviously listed in the PR body

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.

Have added. They were actually never variables before and calculated in the output 🤢

Comment thread process/core/init.py
if (
data_structure.physics_variables.f_nd_plasma_pedestal_greenwald < 0
or not (
data_structure.numerics.ixc[: data_structure.numerics.nvar] == 145
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.

Why have we stopped checking if itv 145 is active?

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.

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

Comment thread process/core/init.py Outdated
Comment on lines +450 to +476
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,
)
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.

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')

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.

Combined

Comment thread process/core/init.py Outdated
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.
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 they cannot be combined, this comment makes no sense here

@chris-ashe chris-ashe requested a review from timothy-nunn May 21, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Profiles Relating to the plasma profiles Refactor Variable rename

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants