Add IMAS↔InputGACODE round-trip conversion (dd! / IMAS.dd)#7
Open
Add IMAS↔InputGACODE round-trip conversion (dd! / IMAS.dd)#7
Conversation
Adds `dd!(dd, ig)` and `IMAS.dd(ig)` — the inverse of the existing `InputGACODE(dd)` constructor — enabling lossless round-trips between GACODE input files and IMAS data structures. Key changes: - New `dd!` function populates equilibrium, core_profiles, and core_sources from an InputGACODE, with correct COCOS 2 sign conventions via CoordinateConventions.transform_cocos / @cocos2 - Two-pass ion merge: thermal+fast rows of the same species share one IMAS ion entry, matching OMFIT to_omas behavior - `InputGACODE(dd)` extended with fpol, MXH shape harmonics (profiles_2d grid_type 57), vtor via rotation_frequency_tor, current profiles (johm, jbs, jbstor, sigmapar), and RF/NB currents - `update_hcd` rewritten with lazy accumulation (missing instead of zeros); adds qione/qioni/qcxi sources; guards empty profiles_1d - ptot uses directly stored cp1d.pressure when available, falls back to species reconstruction - Type fields narrowed from Union{Real/AbstractString} to Union{Float64/String} for type stability - Ion type tokens canonicalized: [therm]/[thermal]/thermal → "therm" - load() handles missing optional fields gracefully; legacy "qpar" alias for "qpar_beam" supported - New deps: CoordinateConventions, Statistics - Comprehensive round-trip tests added (file→dd→ig, synthetic full-field, file-level save/load) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
This PR adds full round-trip conversion between
InputGACODEstructs and IMASddobjects, enabling GACODE input files to be used seamlessly within IMAS-based workflows.New API
dd!(dd, ig::InputGACODE)— populates an existing IMASddfrom anInputGACODEIMAS.dd(ig::InputGACODE)— convenience constructor returning a newddInputGACODE(dd::IMAS.dd)constructorWhat's covered in the round-trip
profiles_2dgrid_type 57to_omas, vtor viarotation_frequency_tor, vpol, zeff, w0, ptotOther improvements
transform_cocos/@cocos2(replaces hard-coded-1.0 *)update_hcdrewritten with lazy accumulation (missinginstead of pre-zeroed arrays); addsqione/qioni/qcxi; guards emptyprofiles_1dUnion{Real/AbstractString}toUnion{Float64/String}for type stability[therm]/[thermal]/thermal→"therm"load()handles missing optional fields gracefully; legacy"qpar"alias for"qpar_beam"supportedCoordinateConventions,StatisticsTest plan
GACODE round-trip: file -> dd -> InputGACODE— loads the sampleinput.gacode, converts toddand back, asserts field-level equalityGACODE round-trip: synthetic full-field coverage— constructs a fully-populatedInputGACODE, round-trips throughIMAS.ddandInputGACODE(dd), verifies all fields survive losslesslyGACODE round-trip: file-level save/load after conversion— converts file → dd → ig → saved file → reloaded, checks equality🤖 Generated with Claude Code