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
4 changes: 2 additions & 2 deletions src/GeneralizedGradients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module GeneralizedGradients
using HDF5, OffsetArrays, Dates, EnumX
using LinearAlgebra, Printf

# Package-wide constants (referenced by the helpers in helpers.jl and the
# Package-wide constants (referenced by the helpers in low_level.jl and the
# evaluation / field-grid code).

# Working size for the truncated (x,y) coefficient arrays. The gg_coef table
Expand All @@ -19,7 +19,7 @@ module GeneralizedGradients
include(_TABLE_FILE)

include("struct.jl")
include("helpers.jl")
include("low_level.jl")
include("gg_eval.jl")
include("gg_fit.jl")
include("gg_utils.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/field_grid_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ end
# both succeed. On read, HDF5.jl likewise hands back a (nx,ny,nz) array == the
# field, so no transpose is needed.
#
# The underscore-prefixed read/write helpers used below live in src/helpers.jl.
# The underscore-prefixed read/write helpers used below live in src/low_level.jl.
# ---------------------------------------------------------------------------

# openPMD complex field samples are a compound type with real ("r") and
Expand Down
42 changes: 38 additions & 4 deletions src/gg_eval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# derivative order ( ∂_s a(n,m) = a(n,m+1), etc. ) — exactly as for the field.
#
# The underscore-prefixed evaluation/interpolation helpers used below live in
# src/helpers.jl.
# src/low_level.jl.

# The gg_coef tables (Bx_a … As_bs), `_NMAX`, and the other package constants are
# defined in GeneralizedGradients.jl; read_gg_fit lives in gg_utils.jl.
Expand Down Expand Up @@ -100,7 +100,7 @@ end
#---------------------------------------------------------------------------------------------------

"""
field_and_potential_evaluate_at(fit, x::Real, y::Real, s::Real) -> (B, A, dA)
field_and_potential_evaluate_at(fit::GGCoefs, x::Real, y::Real, s::Real) -> (B, A, dA)

Evaluate at an arbitrary `(x, y, s)` point.

Expand All @@ -126,9 +126,43 @@ holds at `s` as before.
- `s` — absolute longitudinal coordinate.

Returns `(B, A, dA)` exactly as `field_and_potential_evaluate`.

Uses a type-stable evaluation plan compiled once per `fit` and cached by object
identity (see low_level.jl); this is what makes it fast enough for tracking.
The plan assumes `fit` is not mutated after its first evaluation — changing
`fit.a`/`fit.b`/`fit.bs`/`fit.g_ref` afterward leaves the cached plan stale.
"""
function field_and_potential_evaluate_at(fit, x::Real, y::Real, s::Real)
return field_and_potential_evaluate(_interp_gg_fit(fit, s), 1, x, y)
function field_and_potential_evaluate_at(fit::GGCoefs, x::Real, y::Real, s::Real)
plan = _get_eval_plan(fit)
xr = float(x) - plan.origin[1]
yr = float(y) - plan.origin[2]

gvals = zeros(Float64, plan.ngvals)
upow = Vector{Float64}(undef, plan.maxdeg + 1)
_fill_gvals!(gvals, upow, plan, s)

xp = Vector{Float64}(undef, plan.pmax + 1); xp[1] = 1.0
@inbounds for i in 1:plan.pmax; xp[i+1] = xp[i] * xr; end
yq = Vector{Float64}(undef, plan.qmax + 1); yq[1] = 1.0
@inbounds for i in 1:plan.qmax; yq[i+1] = yq[i] * yr; end

c = plan.comps
Bx = _comp_value(c[1], gvals, xp, yq)
By = _comp_value(c[2], gvals, xp, yq)
Bs = _comp_value(c[3], gvals, xp, yq)
Axv, Axx, Axy = _comp_full(c[4], gvals, xp, yq)
Ayv, Ayx, Ayy = _comp_full(c[5], gvals, xp, yq)
Asv, Asx, Asy = _comp_full(c[6], gvals, xp, yq)
dAxv = _comp_value(c[7], gvals, xp, yq)
dAyv = _comp_value(c[8], gvals, xp, yq)
dAsv = _comp_value(c[9], gvals, xp, yq)

B = [Bx, By, Bs]
A = [Axv, Ayv, Asv]
dA = [Axx Axy dAxv;
Ayx Ayy dAyv;
Asx Asy dAsv]
return B, A, dA
end

#---------------------------------------------------------------------------------------------------
Expand Down
Loading
Loading