Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/src/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ field magnitude, ``B`` is the total field magnitude, ``R`` is the major radius,

The powers are set automatically from `jac_type` (`EquilibriumConfig` in
`src/Equilibrium/EquilibriumTypes.jl`) and applied in the field-line Jacobian
(`direct_fieldline_der!` in `src/Equilibrium/DirectEquilibrium.jl`). Setting `jac_type = "other"`
lets you specify the four exponents manually.
(`direct_fieldline_der!` in `src/Equilibrium/DirectEquilibrium.jl`). Setting `jac_type = "custom"`
lets you specify the four exponents manually via `jac_custom_power_bp`, `jac_custom_power_b`,
`jac_custom_power_r`, and `jac_custom_power_rc`.

## Helicity and Handedness

Expand Down
5 changes: 1 addition & 4 deletions examples/DIIID-like_gal_resistive_example/gpec.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[Equilibrium]
eq_filename = "TkMkr_D3Dlike_Hmode.geqdsk" # Path to equilibrium file
eq_type = "efit" # Type of the input 2D equilibrium file
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc)
power_bp = 0 # Poloidal field power exponent for Jacobian
power_b = 0 # Toroidal field power exponent for Jacobian
power_r = 0 # Major radius power exponent for Jacobian
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type (ldp = linear-derivative packing toward rationals)
psilow = 1e-4 # Lower limit of normalized flux coordinate
psihigh = 0.993 # Upper limit of normalized flux coordinate (0.993 stays clear of the separatrix; truncating at ≳0.998 is numerically unreasonable here)
Expand Down
5 changes: 1 addition & 4 deletions examples/DIIID-like_gal_resistive_pe_example/gpec.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[Equilibrium]
eq_filename = "TkMkr_D3Dlike_Hmode.geqdsk" # Path to equilibrium file
eq_type = "efit" # Type of the input 2D equilibrium file
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc)
power_bp = 0 # Poloidal field power exponent for Jacobian
power_b = 0 # Toroidal field power exponent for Jacobian
power_r = 0 # Major radius power exponent for Jacobian
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type (ldp = linear-derivative packing toward rationals)
psilow = 1e-4 # Lower limit of normalized flux coordinate
psihigh = 0.993 # Upper limit of normalized flux coordinate (0.993 stays clear of the separatrix; truncating at ≳0.998 is numerically unreasonable here)
Expand Down
2 changes: 1 addition & 1 deletion examples/DIIID-like_ideal_example/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[Equilibrium]
eq_filename = "TkMkr_D3Dlike_Hmode.geqdsk" # Path to equilibrium file
eq_type = "efit" # Type of the input 2D equilibrium file
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "log_asymptotic" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
2 changes: 1 addition & 1 deletion examples/DIIID-like_ideal_example_IMAS/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[Equilibrium]
eq_type = "imas" # Type of the input 2D equilibrium file
eq_filename = "from_dd" # Path to equilibrium file (placeholder: equilibrium comes from the runtime dd argument)
jac_type = "boozer" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "boozer" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
psilow = 0.01 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
mpsi = 128 # Number of radial grid points (0 = auto-compute from psi_accuracy)
Expand Down
2 changes: 1 addition & 1 deletion examples/LAR_beta_scan/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Equilibrium]
eq_type = "tj_analytic" # TJ-analytic model (inverse pipeline; Fitzpatrick https://github.com/rfitzp/TJ)
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 0.01 # Lower limit of normalized poloidal flux
psihigh = 0.995 # Upper limit of normalized poloidal flux
Expand Down
2 changes: 1 addition & 1 deletion examples/LAR_epsilon_scan/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Equilibrium]
eq_type = "tj_analytic" # TJ-analytic model (inverse pipeline; overridden to "tj_analytic_direct" by run_scan.jl)
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 0.01 # Lower limit of normalized poloidal flux
psihigh = 0.995 # Upper limit of normalized poloidal flux
Expand Down
2 changes: 1 addition & 1 deletion examples/Solovev_ideal_example/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
2 changes: 1 addition & 1 deletion examples/Solovev_ideal_example_3D/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
2 changes: 1 addition & 1 deletion examples/Solovev_ideal_example_multi_n/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
5 changes: 1 addition & 4 deletions examples/Solovev_kinetic_calculated_example/gpec.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
eq_filename = "sol.toml" # Path to equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc)
power_bp = 0 # Poloidal field power exponent for Jacobian
power_b = 0 # Toroidal field power exponent for Jacobian
power_r = 0 # Major radius power exponent for Jacobian
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized flux coordinate
psihigh = 0.9995 # Upper limit of normalized flux coordinate
Expand Down
2 changes: 1 addition & 1 deletion examples/a10_kinetic_example/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[Equilibrium]
eq_filename = "fix_a100_k10_q2_bn010_prof1" # Path to equilibrium file
eq_type = "efit" # Type of the input 2D equilibrium file
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "hamada" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-3 # Lower limit of normalized poloidal flux
psihigh = 0.99 # Upper limit of normalized poloidal flux
Expand Down
33 changes: 26 additions & 7 deletions src/Equilibrium/EquilibriumTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ Bundles all necessary settings originally specified in the equil fortran namelis

- `eq_type::String` - Type of equilibrium file ("efit", "solovev", "lar", etc.)
- `eq_filename::String` - Path to equilibrium input file
- `jac_type::String` - Jacobian coordinate type ("hamada", "pest", "equal_arc", "boozer", "park", "other")
- `power_bp::Int` - Poloidal field power exponent for Jacobian
- `power_b::Int` - Total field power exponent for Jacobian
- `power_r::Int` - Major radius power exponent for Jacobian
- `power_rc::Int` - Minor radius (rfac = √((R-R₀)²+(Z-Z₀)²)) power exponent for Jacobian
- `jac_type::String` - Jacobian coordinate type ("hamada", "pest", "equal_arc", "boozer", "park", "custom")
- `power_bp::Int` - Poloidal field power exponent for Jacobian (internal, derived from `jac_type`; deprecated as a TOML input key)
- `power_b::Int` - Total field power exponent for Jacobian (internal, derived from `jac_type`; deprecated as a TOML input key)
- `power_r::Int` - Major radius power exponent for Jacobian (internal, derived from `jac_type`; deprecated as a TOML input key)
- `power_rc::Int` - Minor radius (rfac = √((R-R₀)²+(Z-Z₀)²)) power exponent for Jacobian (internal, derived from `jac_type`; deprecated as a TOML input key)
- `jac_custom_power_bp::Int` - Poloidal-field exponent for a custom Jacobian `J = Bp^bp · B^b / (R^r · rfac^rc)`; read only when `jac_type = "custom"`, ignored for named types
- `jac_custom_power_b::Int` - Total-field exponent for a custom Jacobian; read only when `jac_type = "custom"`, ignored for named types
- `jac_custom_power_r::Int` - Major-radius exponent for a custom Jacobian; read only when `jac_type = "custom"`, ignored for named types
- `jac_custom_power_rc::Int` - Minor-radius (rfac) exponent for a custom Jacobian; read only when `jac_type = "custom"`, ignored for named types
- `r0exp::Float64` - Major radius normalization for CHEASE/EQDSK [m]
- `b0exp::Float64` - On-axis toroidal field normalization for CHEASE/EQDSK [T]
- `grid_type::String` - Grid type for flux surface discretization ("log_asymptotic", "ldp", "pow1")
Expand All @@ -42,6 +46,11 @@ Bundles all necessary settings originally specified in the equil fortran namelis
power_r::Int = 0
power_rc::Int = 0

jac_custom_power_bp::Int = 0
jac_custom_power_b::Int = 0
jac_custom_power_r::Int = 0
jac_custom_power_rc::Int = 0

grid_type::String = "log_asymptotic"
psilow::Float64 = 1e-2
psihigh::Float64 = 0.9995
Expand All @@ -61,7 +70,11 @@ Bundles all necessary settings originally specified in the equil fortran namelis
"""
Modified internal constructor that enforces self consistency within the inputs
"""
function EquilibriumConfig(eq_type, eq_filename, r0exp, b0exp, jac_type, power_bp, power_b, power_r, power_rc,
# The four `_` slots are the `power_bp/power_b/power_r/power_rc` struct fields, which @kwdef
# forwards positionally. They are always derived below from `jac_type` (or `jac_custom_power_*`),
# so their incoming values are ignored (hence `_`).
function EquilibriumConfig(eq_type, eq_filename, r0exp, b0exp, jac_type, _, _, _, _,
jac_custom_power_bp, jac_custom_power_b, jac_custom_power_r, jac_custom_power_rc,
grid_type, psilow, psihigh, mpsi, psi_accuracy, mtheta, newq0, etol,
force_termination, use_galgrid, imas_cocos)
if jac_type == "hamada"
Expand Down Expand Up @@ -94,7 +107,12 @@ Bundles all necessary settings originally specified in the equil fortran namelis
power_bp = 0
power_r = 0
power_rc = 0
elseif jac_type == "other"
elseif jac_type == "custom"
# Custom Jacobian: the user-facing knobs define the exponents.
power_bp = jac_custom_power_bp
power_b = jac_custom_power_b
power_r = jac_custom_power_r
power_rc = jac_custom_power_rc
# Normalize to a named type when the powers match, so fast paths are taken.
if power_b == 0 && power_bp == 0 && power_r == 0 && power_rc == 0
jac_type = "hamada"
Expand Down Expand Up @@ -122,6 +140,7 @@ Bundles all necessary settings originally specified in the equil fortran namelis
end
psihigh = min(psihigh, 1.0)
return new(eq_type, eq_filename, r0exp, b0exp, jac_type, power_bp, power_b, power_r, power_rc,
jac_custom_power_bp, jac_custom_power_b, jac_custom_power_r, jac_custom_power_rc,
grid_type, psilow, psihigh, mpsi, psi_accuracy, mtheta, newq0, etol,
force_termination, use_galgrid, imas_cocos)
end
Expand Down
16 changes: 9 additions & 7 deletions src/GeneralizedPerturbedEquilibrium.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ using .ForceFreeStates: find_kinetic_singular_surfaces!
using .ForceFreeStates: eulerlagrange_integration, free_run!
using .ForceFreeStates: galerkin_solve, write_galerkin!, GalerkinResult, gal_matched_odestate

const _DEPRECATED_FFS_KEYS = ("mer_flag")
const _DEPRECATED_FFS_KEYS = ("mer_flag",)
const _DEPRECATED_EQUIL_KEYS = ("power_bp", "power_b", "power_r", "power_rc")

# Drop deprecated [ForceFreeStates] keys so legacy gpec.toml files
# keep parsing instead of throwing an unknown-keyword error.
function _drop_deprecated_ffs_keys!(table)
for k in _DEPRECATED_FFS_KEYS
# Drop deprecated keys from a parsed gpec.toml section so legacy files keep parsing
# instead of throwing an unknown-keyword error; warn so the removal is not silent.
function _drop_deprecated_keys!(table, deprecated_keys, section::String)
for k in deprecated_keys
if haskey(table, k)
@warn "`$k` in [ForceFreeStates] is deprecated and ignored please remove it from gpec.toml."
@warn "`$k` in [$section] is deprecated and ignored; please remove it from gpec.toml."
delete!(table, k)
end
end
Expand Down Expand Up @@ -111,6 +112,7 @@ function build_inputs_from_toml(path::String; dd::Union{IMASdd.dd,Nothing}=nothi
inputs = TOML.parsefile(joinpath(path, "gpec.toml"))

haskey(inputs, "Equilibrium") || error("No [Equilibrium] section in gpec.toml")
_drop_deprecated_keys!(inputs["Equilibrium"], _DEPRECATED_EQUIL_KEYS, "Equilibrium")
eq_config = Equilibrium.EquilibriumConfig(inputs["Equilibrium"], path)

# An equilibrium is analytic (sol/lar/tj, parameters from its embedded section),
Expand Down Expand Up @@ -169,7 +171,7 @@ function main_from_inputs(
# Build data structures from inputs
intr = ForceFreeStatesInternal(; dir_path=path)
ffs_table = inputs["ForceFreeStates"]
_drop_deprecated_ffs_keys!(ffs_table)
_drop_deprecated_keys!(ffs_table, _DEPRECATED_FFS_KEYS, "ForceFreeStates")
ctrl = ForceFreeStatesControl(; (Symbol(k) => v for (k, v) in ffs_table)...)
equil = Equilibrium.setup_equilibrium(eq_config, additional_input)

Expand Down
1 change: 1 addition & 0 deletions src/Rerun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ function build_inputs_from_h5(args::Vector{String})
" source: $(abspath(source_h5))\n" *
" output: $(abspath(joinpath(output_dir, output_name)))\n$_BANNER"

_drop_deprecated_keys!(inputs["Equilibrium"], _DEPRECATED_EQUIL_KEYS, "Equilibrium")
eq_config = Equilibrium.EquilibriumConfig(inputs["Equilibrium"], output_dir)
# Clear eq_filename: unused on replay, and a stale absolute path could mislead downstream code.
eq_config.eq_filename = ""
Expand Down
2 changes: 1 addition & 1 deletion test/test_data/regression_solovev_ideal_example/gpec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, other)
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized poloidal flux
psihigh = 0.9995 # Upper limit of normalized poloidal flux
Expand Down
5 changes: 1 addition & 4 deletions test/test_data/regression_solovev_kinetic_nuzero/gpec.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[Equilibrium]
eq_type = "sol" # Type of the input 2D equilibrium file
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc)
power_bp = 0 # Poloidal field power exponent for Jacobian
power_b = 0 # Toroidal field power exponent for Jacobian
power_r = 0 # Major radius power exponent for Jacobian
jac_type = "pest" # Coordinate system (hamada, pest, boozer, equal_arc, park, custom)
grid_type = "ldp" # Radial grid packing type
psilow = 1e-4 # Lower limit of normalized flux coordinate
psihigh = 0.9995 # Upper limit of normalized flux coordinate
Expand Down
Loading