Repository navigation
Conversation
…the develop branch.
| @@ -0,0 +1 @@ | |||
| snu_offshoot No newline at end of file | |||
| bin_bal2=f ! Binary output for bal_flag functions | ||
|
|
||
| netcdf_out=t ! Replicate ascii dcon.out information in a netcdf file | ||
| bernstien_flag=t |
There was a problem hiding this comment.
Please document things as you add features and flags
| ideal_flag=t | ||
| contour_flag=t | ||
|
|
||
| sol_num=1 |
|
|
||
| c----------------------------------------------------------------------- | ||
| c subprogram 2. bernstein_shear. | ||
| c computes local magnetic shear S(ψ, θ) from Eq. (29) of GPEC Notes. |
There was a problem hiding this comment.
Are these notes available to everyone? Can you add them to the repo or cite a publication?
|
@parkjk This branch appears to have completed a clear and finite feature addition. I recommend it be cleaned up no and merged into the develop branch for everyone to enjoy. Not doing so risks sliding into a never ending state of adding features but never finishing them rigorously - which could lead to a permanent split of the SNU code from the rest of the GPEC source. |
|
@jaesun57, is this branch ready to merge? If not, what is needed and what it the expected timeline? I'd like to not let it live too much longer, as the mission will creep. PR's are best if finite so they do not diverge overmuch from the develop branch. |
|
@logan-nc I'm mainly working on the recon branch right now, and it will take about two more weeks to finish. In the meantime, I'll make sure to keep both recon and snu_offshoot branches updated with the develop branch so they don't diverge too much. As for snu_offshoot, since I didn't create it myself, I'll need to check with @parkjk to see what else needs to be done there. |
|
Thanks for the response @jaesun57. What is the recon branch? Please open a Pull Request for it and make a clear statement of the intent as the opening comment. You can mark the PR and "draft" and that tells people not to bother reviewing the code yet, but it is important to signal what you are doing as it can impact what others are doing (we don't want multiple people accidentally doing the same thing or conflicting things). It looks like you branched off of Similarly, it would be great if you could coordinate with the SNU team to edit the opening comment of this branch with a description of the finite objective, which will clarify whether it is ready to review and merge or not. We don't want infinitely diverging parallel develop branches. Thanks! |
|
Here is AI's summary of the branch: Branch objective (finite)Add a selectable solution-component parameter What it does: Definition of done: It is ready to merge once Questions needing clarification (@parkjk / @jaesun57)
|
|
Your points are good and well taken, though this touches on a big picture conversation we should have separately (a bit too much to get into here). Anyway, @jaesun57 has already committed to opening a PR within the next two weeks, so I'd ask for a little patience on that front. Once it's up, she'll follow the practice closely. |
|
@logan-nc ,All addressed and pushed to Q1 – sol_num: Yes, this is the objective. Q2 – index wording (fixed in 311922c): Standardized on "most unstable" in Q3 – leftovers (reverted to develop in 08ba8bd):
All four leftover diffs vs That said, I still have a few other in-progress changes to wrap up, so I'll do |
|
Thanks @jaesun57 ! @parkjk this looks like a clean feature add rn. Our options are,
Either way, I'm happy to chat about the big picture separately via slack, zoom, etc. or in person Aug 10. |
|
Option 1 sounds good. @jaesun57: Would this be a representing PR name at the moment? "Implement Bernstein's breakdown for the perturbed potential energy" or would you reserve it? Let me know the PR name otherwise and tell me when. Then I will change the name, merge pull, and let you go from there. |
(cherry picked from commit 7ffde74)
(cherry picked from commit 4a146f2)
(cherry picked from commit 8d98987)
…n logic (cherry picked from commit cc25b17)
… section to documentation (cherry picked from commit 557b62c)
…n with convention (cherry picked from commit 1ef3127)
(cherry picked from commit f6a5e27)
(cherry picked from commit a79f3c1)
(cherry picked from commit b13d2e3)
(cherry picked from commit e9cc5d5)
- range-check sol_num against mpert (read from euler.bin at runtime) before indexing wt(:,sol_num); out-of-range values previously read past the array and wrote a garbage eigenfunction silently - same check for mripple against mlow..mhigh on the ripple path - remove the unconditional 'sol_num = ' debug write - ripple_flag ignores sol_num, so write solutions.bin rather than a sol_num-labeled filename in that case Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> (cherry picked from commit 0bf08bf)
Behavior-preserving cleanup of the recon diagnostics from PR #213 review: - gpeq_c: drop dead locals and computations (unused xno_fun/bno_fun copies, z_vec, dphi, q1) and the three unused inverse FFTs of c2v*_mn into cv*_funp - add gpeq_prep_c to build the psi-local perturbed-equilibrium and C state once per surface; gpeq_epf/gpeq_dst/gpeq_epfterms/gpeq_cveri now assume it instead of each rebuilding the full state (halves the state rebuilds in the psifac integration loops) - gpeq_cveri: state-assuming reference implementation is now called from gpout_recon instead of maintaining a duplicated inline copy - gpeq_K/gpeq_epfterms: make chi1 a local instead of silently rewriting the module-level value used by gpeq_sol - gpout: drop the dcon_fac locals; the DCON normalization (mu0*2.0_r8)/psio**2/(chi1*1.0e-3_r8)**2 is written directly at each use site - recon output units become named PARAMETERs in the reserved 72-99 range; renumber gpeq/gpout subprogram banners and contents lists - whitespace: trailing blanks in gpec.f/gpglobal.F; "grad(psi-)" typo in input/gpec.in Verified: make gpec (gfortran, ARM macOS) and a DIIID_ideal_example smoke run with recon_flag/recon_flag3/cveri_flag on mode 1: C verify PASS (max 1.4e-13, rms 3.1e-14), identity_res 5.4e-9, recon1 and recon3 dW_p agree to 8 digits; recon terminal output identical line-for-line before and after the cleanup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
gpeq_sol/contra/cova/normal + gpeq_c were repeated inline at every recon call site; bundle them as gpeq_prep_c(psi) and make the recon kernels (gpeq_cveri, gpeq_epf, gpeq_dst, gpeq_epfterms) assume the state is prepared. gpout_recon now calls gpeq_cveri directly instead of carrying an inlined copy of the identity. Also fix a stray minus in the cveri_flag comment of input/gpec.in. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gpeq_shear, gpeq_curvature and gpeq_K assigned the gpglobal module variables p1/q/q1 through host association. p1 in particular was stored as p' while the rest of GPEC keeps mu0*p' there (idcon.f, gpdiag.f). No reader consumes the stale values today, but shadow them with routine-local declarations so the recon diagnostics leave module state untouched. Results are bit-identical. Also note in gpeq_c that the removed xno/bno and theta-space c2v* fields were development-time verification aids. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Hi @logan-nc What I have done:
All new flags default off, so default runs are unchanged. The self-review comment above lists the cleanup items and known minor points. |
|
@claude review this pr |
|
Claude finished @logan-nc's task in 1m 55s —— View job Review of PR #213: Bernstein breakdown of δW_p (
|
|
I don't love the recon_flag# convention. It is not very descriptive for new users and introduces a new numbering scheme inconsistent with other flags. It would be better to name each one something more descriptive |
|
@jaesun57 please do at least the flag guards and division guards in the above. The others seem like reasonable suggestions as well. |
|
@jaesun57 what do you think of the above requests? Can you let me know if you plan to implement any? Or do you want to advocate for things to be merged just as they are? |
…n gpec.in comments
… in the theory note
|
@logan-nc Sorry for late replies. I updated codes with all of the requests above and also agree that some flag guards and division guards are needed. Could you take another look? |
Summary
This PR adds post-processing diagnostics to GPEC that break the perturbed plasma potential energy δW_p of a DCON free-boundary eigenmode into Bernstein's terms, and compares each reconstruction with the DCON eigenvalue. It also adds a MATCH option,
sol_num, that selects which DCON eigenfunction MATCH reconstructs.Scope (definition of done): the four input flags below, their output files, the MATCH
sol_numoption, the derivation note indocs/tex/recon/, a Sphinx docs entry and one regression example. Every new flag defaults off, so default runs are unchanged. Further SNU work goes on its own purpose-scoped branches offdevelop.The Julia port of the same diagnostics is OpenFUSIONToolkit/GPEC#465 (
[EnergyDecomposition], optionseffective_field_form/standard_form). The flag names here match those options.What is added
GPEC (
gpec_outputnamelist,input/gpec.in)effective_field_flaggpout_recon,gpeq_c,gpeq_shear,gpeq_curvature,gpeq_K,gpeq_epf,gpeq_dststandard_form_flagdocs/tex/recon/main.tex)gpout_recon2,gpeq_firstformeffective_field_terms_flaggpout_recon3,gpeq_epftermscurl_check_flaggpeq_cverirecon_outgpec.logentries; f keeps only the terminal summaryrecon_int"spline""spline"or"trapezoid"Usage:
mode_flag=t,mode=<eigenmode>,coil_flag=f,reg_flag=f(anddata_flag=f,harmonic_flag=f).reg_flagdefaults to true, so it must be set explicitly. GPEC stops at input with a clear message if any of the three energy flags is set otherwise, because the comparison with ep(mode) is only meaningful for a bare DCON eigenmode.Terminal /
gpec.logsummary: each route ends with its δW_p total, the same total in DCON normalization (dW_p(recon-normalize)and analogues),DCON ep(mode), and the ψ range it integrated over next to the DCON range:Outputs (per selected mode,
sol<mode>):gpec_recon_{terms,integration,k,k_sigma_check,shear_fun,curvature,cwfun,cwmn,cvfun,cvmn,cv2fun,cv2mn,qvmn,cveri}_sol*.out,gpec_recon2_{terms,integration}_sol*.outandgpec_recon3_{terms,integration}_sol*.out, with R–Z resolved term densities, Fourier tables and cumulative radial integrals.MATCH (
input/match.in)sol_num(default 1) selects which column of Wt (1 = most unstable)ideal_builduses as the edge condition.sol_num=1writessolutions.binas before;sol_num=n>1writessolutions<n>.bin. It is bounds-checked against 1..mpert,mrippleis range-checked, and the ripple path is unchanged.Documentation
docs/outputs.rst: an "Energy Decomposition Outputs" section (flags, preconditions, output files, printed summary) and a "MATCH Outputs" entry forsolutions<n>.bin; it linksdocs/tex/recon/main.tex.docs/namelists.rst: includesinput/match.in.docs/tex/recon/main.tex(withreferences.bib), "Bernstein–Chance decomposition of the perturbed potential energy in GPEC", is the derivation behind every routine: coordinate and basis conventions; the transformation of δW_F into the Bernstein form in DCON/SI units; the derivation of K; both reconstruction schemes; a code-variable ↔ symbol table; the exact integrand behind every logged quantity, with cross-checks between the three routes.Regression example
docs/examples/regression_solovev_recon_example(Soloviev, inputs copied fromregression_solovev_ideal_example,delta_mlow=delta_mhigh=8) runsdconandgpecwitheffective_field_flag=tandcurl_check_flag=t.check_recon.pypasses when the recon ψ range equals the DCON range,dW_p(recon-normalize)matchesDCON ep(1)within 2%, and the curl check reports PASS. Both CI jobs (gfortran and ifort) run it after the existing Soloviev examples.Validation
Clean
make(gfortran 15, macOS arm64) with no new warnings: the same 16 as the merge base (type mismatches instride/zvode1.fand xdraw linker paths). The regression example also passes in a build with the CI debug flags (-fcheck=all -finit-real=snan …).docs/examples/DIIID_ideal_examplewith default inputs gives the same outputs as the merge base with develop (902faac), apart from the imaginary part of e_P for high modes ingpec_response_n1.out, which also differs between two runs of the unmodified code (pre-existing nondeterminism).develophas moved 155 commits since then (including DCON/EQUIL/VACUUM changes), so a comparison against currentdevelopdiffers for reasons outside this PR. The branch merges intodevelopwithout conflicts.Recon case on DIII-D (
coil_flag=f,mode_flag=t,mode=1,reg_flag=f, all four flags on): the guard, rename, local-scratch, NEWUNIT and psi-range commits leave all 18gpec_recon*.outfiles bit-identical; only the curl-check verdict lines (new relative criterion) and the two new psi-range lines change.Agreement with DCON ep(1):
With the default 8 harmonics the Soloviev effective-field form misses by 21%: C is built in real space and Fourier truncated, so the example widens the band.
recon_int: spline and trapezoid differ by ≤0.1% in all cases above, with no consistent winner, so the default stays"spline"(as in the Julia port). The remaining 0.4–0.9% is an edge-localized offset of the form itself, not quadrature (see #465).Response to review
✳ = written with Claude Code (see "AI assistance" below).
docs/nametag? (2025-10)sol_num(2025-10)input/gpec.inandinput/match.indocument every new input; the abandonedbernstien_flagis gonedocs/tex/recon/main.texis in the repositoryinput/dcon.in,dcon/dcon.F,equil/equil_out.fanddocs/nametagno longer differ from develop; "most unstable" wording made consistent;sol_num/mripplebounds-checkedmode_flag/coil_flag/reg_flag(2026-10-03, required)mode_flag=tandreg_flag,coil_flag,data_flag,harmonic_flagare off; warn ifcurl_check_flagis set withouteffective_field_flagrfac, |∇ψ|² and B² divisors floored at a privaterecon_tinyin the recon kernels;MAX(.,0)inside every reconSQRT(rzphi%f(1))recon_flag#flags (2026-10-03)recon_flag→effective_field_flag,recon_flag2→standard_form_flag,recon_flag3→effective_field_terms_flag,cveri_flag→curl_check_flag; no aliases. Theory note retitled.f,gpeq_shearstep headerjac,jac1,rfac,eta,w,vare local in every recon kernel, andchi1is computed locally ingpeq_firstform/gpeq_shearNEWUNIT=cveri_tolis an absolute threshold on a dimensional quantityrecon_int"spline"after the comparison abovedocs/outputs.rst,docs/namelists.rstdocs/examples/regression_solovev_recon_example+ CI stepsAI assistance
Parts of this PR were written with Claude Code (Anthropic) and reviewed and committed by @jaesun57:
SQRTguards).Co-Authored-By: Claudetrailer, among them 3b14c8a, 6e2c2c2, 0e1f875, a49c79a, 2c03f04, 94547e9, 58173ef and 3f2d03f, plus several recon output and DOCS commits;git log --format='%h %(trailers:key=Co-Authored-By,valueonly)' develop..snu_offshootlists them all.