Skip to content

Unfreeze densities and replay ion density instead of density_thermal#1057

Merged
bclyons12 merged 16 commits intomasterfrom
unfreeze_density
Mar 4, 2026
Merged

Unfreeze densities and replay ion density instead of density_thermal#1057
bclyons12 merged 16 commits intomasterfrom
unfreeze_density

Conversation

@bclyons12
Copy link
Copy Markdown
Collaborator

@bclyons12 bclyons12 commented Feb 19, 2026

Summary

  • Add IMAS.unfreeze! calls throughout actors (fits, pedestal, core transport, EPED profiles, flux matcher) after modifying density_thermal, so that the density expression stays correct
  • Replay ion density instead of density_thermal in replay actors (core transport, flux matcher, pedestal), so that total density remains constant when density_fast changes
  • Add SimpleDFSane as a fallback in the flux matcher basic_polyalg and default GKNN to use basic_polyalg
  • Fix STEP case to unfreeze electron density after initialization

Test plan

  • Run flux matcher with TGLFNN and GKNN models
  • Verify replay actors preserve total ion density when fast particle content changes
  • Run STEP case end-to-end
  • Run existing FUSE test suite

🤖 Generated with Claude Code

- Uses SimpleDFSane if gradient based methods don't converge
- GKNN uses basic_polyalg by default
This allows the density to stay constant if `density_fast` changes
@bclyons12
Copy link
Copy Markdown
Collaborator Author

Companion to ProjectTorreyPines/IMAS.jl#292

@nanshi1177
Copy link
Copy Markdown
Contributor

Screenshot2026_02_20_221740

@bclyons12
Copy link
Copy Markdown
Collaborator Author

@nanshi1177 What shot and mode is this?

nanshi1177 and others added 2 commits February 23, 2026 14:22
…files

CER and Thomson scattering are independent diagnostics that can be
inconsistent at the edge, causing n_imp * Z_imp > ne at some radial
points. This made enforce_quasi_neutrality!(:D) error on the new
unfreeze_density branch which no longer silently allows negative density.

Clip each impurity's density against the remaining electron budget after
accounting for all other impurities, ensuring n_D >= 0 after QN enforcement.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When using Jacobian-based algorithms (e.g. basic_polyalg, broyden,
trust region), a SingularException can occur if the Jacobian becomes
degenerate due to density state changes in the unfreeze_density branch.
Catch any such exception and fall back to SimpleDFSane which is
derivative-free and never inverts the Jacobian.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nanshi1177 nanshi1177 force-pushed the unfreeze_density branch 2 times, most recently from e48ce8a to e8ddbbd Compare February 27, 2026 21:04
nanshi1177 and others added 6 commits February 27, 2026 13:08
- Unfreeze density_thermal after blending ion.density so expression
  recomputes correctly as density - density_fast
- Clamp density_fast to not exceed total density after blending
- Freeze density_thermal to store the computed value
- Remove scale_ion_densities_to_target_zeff! call which conflicts
  with replay density handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Start time set by init!
- Reduce time step
@bclyons12
Copy link
Copy Markdown
Collaborator Author

@nanshi1177 @jmcclena @tomneiser @TimSlendebroek
I reverted making :simple_dfsane the default. Here is timing, convergence, and core Te info for ActorStationaryPlasma on all of our use cases. We don't do :basic_polyalg for full TJLF since it needs gradients. Note that about half the time :simple_dfsane is faster, the other half :basic_polyalg is faster. But :basic_polyalg always converges as or more well. This makes sense because :simple_dfsane is the final fallback for :basic_polyalg now.

Green/red means better/worse than :simple_dfsane for timing and convergence, and "close to"/"far from" for core Te

Screenshot 2026-03-03 at 5 15 33 PM Screenshot 2026-03-03 at 5 15 38 PM Screenshot 2026-03-03 at 5 15 44 PM

@bclyons12 bclyons12 merged commit 15e3c1c into master Mar 4, 2026
2 checks passed
@bclyons12 bclyons12 deleted the unfreeze_density branch March 4, 2026 20:19
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.

2 participants