Skip to content

Ensure i_plasma_pedestal=0 profile does not have 0 elements#4038

Merged
timothy-nunn merged 1 commit intomainfrom
2964-stellarator-divide-by-0-warning
Jan 12, 2026
Merged

Ensure i_plasma_pedestal=0 profile does not have 0 elements#4038
timothy-nunn merged 1 commit intomainfrom
2964-stellarator-divide-by-0-warning

Conversation

@timothy-nunn
Copy link
Copy Markdown
Collaborator

Adds in a check of the profile_y when i_plasma_pedestal=0 to set any 0 elements to be slightly above 0, hence avoiding divide by 0's.

@timothy-nunn timothy-nunn linked an issue Jan 8, 2026 that may be closed by this pull request
@timothy-nunn
Copy link
Copy Markdown
Collaborator Author

Just to clarify this is what the profile looks like
image

Obviously, that was the case before except the final point is now at 1e-8 not 0.0

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.30%. Comparing base (8a4d67c) to head (560284b).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
process/profiles.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4038      +/-   ##
==========================================
- Coverage   46.30%   46.30%   -0.01%     
==========================================
  Files         123      123              
  Lines       28961    28962       +1     
==========================================
  Hits        13411    13411              
- Misses      15550    15551       +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.

Comment thread process/profiles.py Outdated
@timothy-nunn timothy-nunn force-pushed the 2964-stellarator-divide-by-0-warning branch from 46a0131 to 0bcdc2e Compare January 8, 2026 16:55
@grmtrkngtn
Copy link
Copy Markdown
Collaborator

Did this remove the error for you @timothy-nunn ?

Comment thread process/profiles.py Outdated
self.profile_y = n0 * (1 - rho**2) ** alphan
# profile values of 0 cause divide by 0 errors so ensure the profile value is at least 1e-8
# which is small enough that it won't make a difference to any calculations
self.profile_y = np.maximum(n0 * (1 - rho**2) ** alphan, 1e-8)
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 is actually being overwritten by the following code, so the fix isn't applied and the error persists. We should add a return statement after this, then an else or "if physics.variables.i_plasma_pedestal == 1" to ensure the code runs correctly.

Copy link
Copy Markdown
Collaborator

@grmtrkngtn grmtrkngtn left a comment

Choose a reason for hiding this comment

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

Please make the adjustment recommended in profiles.py

@timothy-nunn timothy-nunn force-pushed the 2964-stellarator-divide-by-0-warning branch from 0bcdc2e to 560284b Compare January 9, 2026 13:17
@grmtrkngtn
Copy link
Copy Markdown
Collaborator

One more thing @timothy-nunn the change is only applied to the ne profile but actually the bug occurs with the te profile, we should apply the same solution there.

@timothy-nunn
Copy link
Copy Markdown
Collaborator Author

One more thing @timothy-nunn the change is only applied to the ne profile but actually the bug occurs with the te profile, we should apply the same solution there.

Hi @ym1906 thanks for pointing that out. Should be corrected now.

Copy link
Copy Markdown
Collaborator

@grmtrkngtn grmtrkngtn left a comment

Choose a reason for hiding this comment

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

Yes, looks good to me now. This fix removes the error when I run the helias_5b example file.

@timothy-nunn timothy-nunn merged commit 1c32433 into main Jan 12, 2026
37 of 40 checks passed
@timothy-nunn timothy-nunn deleted the 2964-stellarator-divide-by-0-warning branch January 12, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stellarator divide by 0 warning

3 participants