Skip to content
Draft
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
3 changes: 3 additions & 0 deletions src/ForceFreeStates/Surfaces/Finding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ function sing_lim!(intr::ForceFreeStatesInternal, ctrl::ForceFreeStatesControl,
profiles.xs[jpsi], Roots.Newton()
)
intr.q1lim = profiles.q_deriv(intr.psilim)
else
# The domain ends at psihigh: pair it with its own q, which lies below qmax when q peaks inside.
intr.qlim = profiles.q_spline(intr.psilim)
end
end

Expand Down
12 changes: 12 additions & 0 deletions test/runtests_sing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ using FastInterpolations: cubic_interp, CubicFit, LinearBinarySearch, Series, Ex
@test intr.psilim <= equil.params.psihigh_resolved
q_at_psilim = equil.profiles.q_spline(intr.psilim)
@test isapprox(q_at_psilim, intr.qlim; atol=1e-6)
# q peaking inside the domain: a qhigh above qmax ends the domain at psihigh, with the q found there.
pr = equil.profiles
q_peak = @. 2 + 3 * pr.xs - 2 * pr.xs^2
equil_peak = deepcopy(equil)
equil_peak.profiles = GeneralizedPerturbedEquilibrium.Equilibrium.ProfileSplines(pr.xs, pr.F_spline.y, pr.P_spline.y, pr.dVdpsi_spline.y, q_peak)
GeneralizedPerturbedEquilibrium.Equilibrium.equilibrium_qfind!(equil_peak)
@test equil_peak.params.qmax > equil_peak.profiles.q_spline(equil_peak.params.psihigh_resolved) + 0.01
intr_peak = GeneralizedPerturbedEquilibrium.ForceFreeStates.ForceFreeStatesInternal()
GeneralizedPerturbedEquilibrium.ForceFreeStates.sing_lim!(intr_peak,
GeneralizedPerturbedEquilibrium.ForceFreeStates.ForceFreeStatesControl(; qhigh=10.0, truncate_at_rational_offset=false), equil_peak)
@test intr_peak.psilim == equil_peak.params.psihigh_resolved
@test isapprox(intr_peak.qlim, equil_peak.profiles.q_spline(intr_peak.psilim); atol=1e-12)
ctrl_dmlim = GeneralizedPerturbedEquilibrium.ForceFreeStates.ForceFreeStatesControl(; qhigh=equil.params.qmax, truncate_at_rational_offset=true)
intr_unresolved = GeneralizedPerturbedEquilibrium.ForceFreeStates.ForceFreeStatesInternal()
@test_throws ErrorException GeneralizedPerturbedEquilibrium.ForceFreeStates.sing_lim!(intr_unresolved, ctrl_dmlim, equil)
Expand Down
Loading