Compute and emit fluxes for isw_calc_Er=2 prescribed Om_tE#85
Open
krystophny wants to merge 2 commits into
Open
Compute and emit fluxes for isw_calc_Er=2 prescribed Om_tE#85krystophny wants to merge 2 commits into
krystophny wants to merge 2 commits into
Conversation
The prescribed-Er path already recovers Om_tE and sets MtOvR_spec (#84), but never called compute_Gamma, compute_Qflux, compute_ParFlow or compute_TphiNA. That left Gamma_AX_spec, TphiNA_spec, etc. uninitialized and write_multispec_output_a then gated the h5_add writes on isw_calc_Er == 1 to avoid emitting them. Result: runs with an externally prescribed Om_tE produced only D-matrices plus MtOvR and could not be used for NTV/transport comparisons. Extend the isw_calc_Er == 2 branch in write_multispec_output_a to: - recover Er from Om_tE using Er = Om_tE * aiota * sqrtg*B^phi / c (exact inverse of the forward map in compute_Er); - set avEparB_ov_avb2 = 0 because no inductive parallel-field solve is performed on the prescribed path; - replay compute_VthtB_and_VphiB(_b), compute_Gamma, compute_Qflux, compute_ParFlow and compute_TphiNA for both single-species and multi-species cases, including the Ware-pinch variants which fall out naturally at zero avEparB. Split the output gate at the Er/flux block: move Er, VthtB_spec, VphiB_spec, Gamma_*_spec, Qflux_*_spec, ParFlow_*_spec and TphiNA_spec to an isw_calc_Er >= 1 gate so both paths emit them. Keep Vphi_*_prof and the Ware-only fields on isw_calc_Er == 1 because no Vphi solve is performed for isw_calc_Er == 2. Widen the particle-flux ambipolarity diagnostic in check_ambipolarity_particle_flux to isw_calc_Er >= 1 so prescribed runs also report the residual charge sum.
Extracts the compute_Gamma / compute_Qflux / compute_ParFlow / compute_TphiNA chain and the VthtB/VphiB reconstruction out of both isw_calc_Er branches into an internal helper compute_species_fluxes_at_Er(row_ind_ptr, col_ind_ptr, Er, avEparB_ov_avb2). The helper lives in the contains block of write_multispec_output_a so it inherits the local D_AX/D_NA and Gamma/Qflux/ParFlow arrays by lexical scope, without adding a new parameter list. Each branch now only handles its own Er resolution: - isw_calc_Er == 1 calls get_Er / compute_Er_and_A3norm / compute_Vphi_profile and then dispatches. - isw_calc_Er == 2 maps Om_tE back to Er, pins avEparB_ov_avb2 = 0 and dispatches. The flux h5 write gate is also widened so that all flux and Ware-pinch fields are written under isw_calc_Er >= 1. Only the Vphi-profile arrays (R_Vphi_prof, Z_Vphi_prof, Vphi_prof_spec, Vtht_prof_spec, Vphi_prof_woWare_spec, Vtht_prof_woWare_spec) stay gated at isw_calc_Er == 1 because they come from compute_Vphi_profile which the prescribed-Er branch does not invoke. Adds TEST/test_er_rotation.f90::test_er_om_te_forward_inverse_round_trip which composes the forward map Om_tE = c * Er / (aiota * sqrtg*B^phi) with the inverse used in the isw_calc_Er=2 branch and asserts exact round-trip for a grid of AUG-like geometry samples.
This was referenced Apr 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isw_calc_Er = 2now populates all AX/NA flux outputs (Gamma_*_spec,Qflux_*_spec,ParFlow_*_spec,TphiNA_spec,VthtB_spec,VphiB_spec) plus the Ware-pinch variants fornum_spec > 1, by recoveringErfromOm_tEvia the inverse of the forward map incompute_Erand running the same flux chain asisw_calc_Er = 1compute_species_fluxes_at_Er, an internal helper shared by both branches, so each branch only owns its own Er resolution (get_Er/compute_Er_and_A3normon the Vphi path;Om_tE -> Eron the prescribed path) and the duplicated per-speciescompute_Gamma/Qflux/ParFlow/TphiNAblock is goneEr, the AX/NA flux fields and the Ware-pinch fields are now emitted underisw_calc_Er >= 1whileR_Vphi_prof,Z_Vphi_prof,Vphi_prof_spec,Vtht_prof_specand the woWare Vphi profiles remain gated atisw_calc_Er == 1because they come fromcompute_Vphi_profilewhich the prescribed branch does not invokecheck_ambipolarity_particle_fluxwidened toisw_calc_Er >= 1so prescribed-Er runs also report the residualsum Z * GammaTEST/test_er_rotation::test_er_om_te_forward_inverse_round_tripcomposes the forward and inverse maps over an AUG-like grid of(Er, aiota, sqrtg*B^phi)samplesMotivation
PR #84 made
MtOvR_spectrack prescribedOm_tEbut left every flux/torque output uninitialized on theisw_calc_Er = 2path. Downstream tooling (NTV benchmarks against SFINCS, force-balance fits against Martitsch 2016) cannot run at a prescribedErwithout those fields, so the prescribed-Er path on main produces a schema that is missingEr,Gamma_*_spec,TphiNA_spec, etc.Verification
Test fails on main (the new round-trip case does not exist there):
main passes trivially because
test_er_om_te_forward_inverse_round_triponly exists on this branch; it is the new coverage this PR introduces.Test passes on this branch:
End-to-end smoke against main (no schema coverage): AUG 30835 single-surface prescribed-Er run with
ISW_CALC_ER=2on main produces an HDF5 containing onlyD*_AX,D*_NA,Om_tE,MtOvR. On this branch the same run additionally containsEr,Gamma_AX_spec,Gamma_NA_spec,Qflux_*_spec,ParFlow_*_spec,TphiNA_spec,TphiNA_tot,VthtB_spec,VphiB_specplus the Ware-pinch variants (Gamma_*_Ware_spec, etc.) fornum_spec > 1. That script lives atfile:///home/ert/data/AUG/NEO-2/30835/2016_controlled_fusion_rmp90_benchmark/prescribed_er_scan/run_prescribed_er.pyand can be re-run per Martitsch NTV benchmark surface.Notes
isw_calc_Er == 1executable path is byte-identical to the pre-patch main: sameget_Eriteration, samecompute_Vphi_profilecalls, same flux output. The refactor only moves the shared compute chain into the helper.isw_calc_Er = 2are the zero-inductive-field reduction of the self-consistent formulas (avEparB_ov_avb2 = 0), not garbage or zero across the board..EQ. 1only, as documented in the new block comment atNEO-2-QL/ntv_mod.f90around the output gate split. Downstream code that reads those keys only whenisw_calc_Er == 1keeps working unchanged.Test plan
cmake --build build -jclean build on main + this patchctest --test-dir build -R er_rotation_testpasses (all 7 cases, including the new round-trip)es_0p25271prescribed-Er run producesneo2_multispecies_out.h5withGamma_AX_spec,TphiNA_spec,ParFlow_AX_spec, and the NA counterpartsbenchmark/neo2_vs_sfincsbranch ofplasma/data)