Repository navigation
Dual-typed dd and implicit derivatives for forward-mode AD; include derived-density ions in the thermal pressure - #326
Merged
Merged
Conversation
…it, I/O
- dual.jl: retype (element-type conversion that keeps global_time and aux),
value_dd, partials_dd, replace_values!, seed, InputsTag/InputsDual (outer
tag ordered before all other ForwardDiff tags), JSON/HDF5 output as one
values file plus one file per partial
- resolve the convert(::Type{<:Dual}, ::IDS) ambiguity with ForwardDiff
- line radiation: finite derivative at the clamped ends of the Chebyshev fit
- sawteeth_source!: inversion radius in the element type of the dd
- total_power_time, inscribed wall polygon: element-type generic
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…dy-state ohmic amplitude, lenient replace_values! - sqrt0: the grid volume, area and psi expressions take the square root of quantities that vanish on axis, where the derivative of sqrt is infinite - j_ohmic_steady_state: the condition on the total current is affine in the ohmic amplitude; with dual numbers it is solved in closed form - replace_values! skips leaves that hold data on only one side Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ches - implicit_solution / implicit_argmin: derivative of a root or minimiser that was found on value parts, from the implicit function theorem - blend_core_edge_Hmode: derivative of the exponents for the three kinds of minimum of its cost (vanishing mismatch, exponent at zero, smooth) - blend_core_edge_Lmode: derivative of the exponent from the signed mismatch - pedestal_search_tolerance: the tolerances of these searches, defaults unchanged Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The tracing runs on value parts; contour points, magnetic axis, X-points, surface extrema and the level of the last closed surface are given the displacement that follows from the conditions that define them (implicit function theorem), and the flux-surface averages are computed from them by the existing code, now factored out as _flux_surfaces_from_traced!. Value parts equal the Float64 result. Also: arc_length and the psi interpolant grid are element-type generic, and the trapped-fraction formula has a finite derivative at the field maximum. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-level derivative find_magnetic_axis and find_psi_boundary run on value parts and return the axis and the levels with the derivative of the conditions that define them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…cation Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…l mean inside the bisection bracket A contour traced on the grid changes topology when its level passes a node value or, in a saddle cell, the cell mean. The one inside the bracket found by the bisection is what limits the last closed surface. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…atives, generic beam, field-map, arc-length and shape functions Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…cit_solution holds fixed the unknowns whose condition is not met; lenient value reset Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nd flux surfaces against finite differences Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… with ForwardDiff Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… the X-point The level of the last closed surface is found by a search on the contouring grid, so it is a piecewise function of psi(R,Z): inside one piece it follows a grid node, over any finite change of the inputs it follows the flux at the X-point plus a small offset. The derivative is now that of the X-point flux for a diverted plasma, and the points of that surface are displaced on the smooth interpolant instead of along the grid edges, where the linear interpolation is poor next to the X-point. The test compares with a finite-difference slope fitted over several steps. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A time basis that starts at -Inf gives a decay factor of exactly zero; with a dual-number time constant its derivative part evaluated 0 * Inf. The factor is now an exact zero in that case. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… is derived from the total density pressure_thermal(ions) skipped every ion without a stored density_thermal. After quasi-neutrality is enforced on an ion without fast density, the result is stored in density and density_thermal is an expression, so that ion dropped out of pressure_ion_total, pressure_thermal, pressure and energy_thermal. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Conflict in sawteeth_source!: the dual-number method now passes on the exclude_indexes keyword added on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 13, 2026
Expressions in a data structure that is not Float64 and the selective_delete! fix are available from that release. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tomneiser
marked this pull request as ready for review
November 14, 2026 20:11
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.
Dual-typed data dictionaries and the physics helpers that FUSE's whole-plasma workflows need for forward-mode AD (ForwardDiff), plus one fix to the thermal pressure that also affects Float64 results.
Requires IMASdd 8.6.4 (ProjectTorreyPines/IMASdd.jl#114): the new tests rely on its handling of expressions that return plain floats in a non-Float64 data structure. The compat floor is raised in this PR.
Dual-typed
dd(newsrc/dual.jl)retypeconverts addto another element type, keepingglobal_timeand the auxiliary data. It also resolves an ambiguity with ForwardDiff'sconvert.seed,value_dd,partials_ddandreplace_values!seed inputs and split values from derivatives.InputsTag/InputsDual{N}: an outer tag ordered before every other ForwardDiff tag, so that derivatives taken internally nest inside it.Implicit derivatives
Searches still run on value parts. Their derivatives come from the conditions that define the solution (implicit function theorem):
implicit_solution/implicit_argmin, used by the core–edge blends for H and L mode.src/physics/fluxsurfaces_dual.jl): contour points, magnetic axis, X-points, surface extrema and the level of the last closed surface. Their value parts equal the Float64 result; the flux-surface averages then come from the existing code, factored out as_flux_surfaces_from_traced!.Element-type generic helpers
total_power_time.sqrtfor quantities that vanish on axis, the clamped ends of the radiation fit, the trapped fraction at the field maximum, and beam-power smoothing over an infinite time step.j_ohmic_steady_statesolves its affine condition in closed form for dual numbers.Fix that changes Float64 results
pressure_thermal(ions)skipped every ion without a storeddensity_thermal. After quasi-neutrality is enforced on an ion without fast density, the result is stored indensityanddensity_thermalis an expression. That ion therefore dropped out ofpressure_ion_total,pressure_thermal,pressureandenergy_thermal, which can be most of the thermal energy when it is the main ion. Ions with a stored totaldensityare now included. Newtest/runtests_profiles.jl.Tests
New
test/runtests_dual.jl: dual-typedddhelpers, implicit derivatives, pedestal blends and flux surfaces against finite differences.Pkg.test()passes locally (Julia 1.11.7) with the IMASdd branch, after merging master.Part of a set with ProjectTorreyPines/FUSE.jl#1226, which tests the whole stack in its CI.
🤖 Generated with Claude Code