Skip to content

Commit 1b78865

Browse files
committed
Restore boundary_control_points, and add new functions for iso
1 parent 081d104 commit 1b78865

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/control.jl

+26-4
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,44 @@ function IsoControlPoints(Rs::AbstractVector{T}, Zs::AbstractVector{T}) where {T
134134
end
135135

136136
"""
137-
boundary_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999; Npts::Integer=99)
137+
boundary_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999, ψbound::Real=0.0; Npts::Integer=99)
138+
Return a Vector of FluxControlPoint, each with target `ψbound`, at `Npts` equally distributed `fraction_inside` percent inside the the boundary of `EQfixed`
139+
"""
140+
function boundary_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999, ψbound::Real=0.0; Npts::Integer=99)
141+
ψ0, ψb = MXHEquilibrium.psi_limits(EQfixed)
142+
Sp = MXHEquilibrium.flux_surface(EQfixed, fraction_inside * (ψb - ψ0) + ψ0; n_interp=Npts)
143+
ψtarget = fraction_inside * (ψb - ψ0) + ψ0 - ψb + ψbound
144+
return [FluxControlPoint(Sp.r[k], Sp.z[k], ψtarget, 1.0 / Npts) for k in 1:length(Sp.r)-1]
145+
end
146+
147+
"""
148+
boundary_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999, ψbound::Real=0.0; Npts::Integer=99)
149+
Return a Vector of FluxControlPoint, each with target `ψbound`, at `Npts` equally distributed `fraction_inside` percent inside the the boundary of `shot`
150+
"""
151+
function boundary_control_points(shot::TEQUILA.Shot, fraction_inside::Float64=0.999, ψbound::Real=0.0; Npts::Integer=99)
152+
bnd = MillerExtendedHarmonic.MXH(shot, fraction_inside)
153+
θs = LinRange(0, 2π, Npts + 1)
154+
ψtarget = ψbound + TEQUILA.psi_ρθ(shot, fraction_inside, 0.0)
155+
return [FluxControlPoint(bnd(θ)..., ψtarget, 1.0 / Npts) for θ in θs[1:end-1]]
156+
end
157+
158+
"""
159+
boundary_iso_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999; Npts::Integer=99)
138160
139161
Return a Vector of IsoControlPoints, at `Npts` equally distributed `fraction_inside` percent inside the the boundary of `EQfixed`
140162
"""
141-
function boundary_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999; Npts::Integer=99)
163+
function boundary_iso_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999; Npts::Integer=99)
142164
ψ0, ψb = MXHEquilibrium.psi_limits(EQfixed)
143165
Sp = MXHEquilibrium.flux_surface(EQfixed, fraction_inside * (ψb - ψ0) + ψ0; n_interp=Npts)
144166
return VacuumFields.IsoControlPoints(Sp.r, Sp.z)
145167
end
146168

147169
"""
148-
boundary_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999; Npts::Integer=99)
170+
boundary_iso_control_points(EQfixed::MXHEquilibrium.AbstractEquilibrium, fraction_inside::Float64=0.999; Npts::Integer=99)
149171
150172
Return a Vector of IsoControlPoints, at `Npts` equally distributed `fraction_inside` percent inside the the boundary of `shot`
151173
"""
152-
function boundary_control_points(shot::TEQUILA.Shot, fraction_inside::Float64=0.999; Npts::Integer=99)
174+
function boundary_iso_control_points(shot::TEQUILA.Shot, fraction_inside::Float64=0.999; Npts::Integer=99)
153175
bnd = MillerExtendedHarmonic.MXH(shot, fraction_inside)
154176
θs = LinRange(0, 2π, Npts + 1)
155177
r = [bnd(θ)[1] for θ in θs[1:end-1]]

test/runtests.jl

+14-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ end
130130
println("Testing for COCOS ", cc)
131131
Gfixed = efit(transform_cocos(gfixed, cc0, cc), cc)
132132
Gfree = efit(transform_cocos(gfree, cc0, cc), cc)
133-
flux_cps = boundary_control_points(Gfree, 0.999)
133+
_, ψbound = psi_limits(Gfree)
134+
flux_cps = boundary_control_points(Gfree, 0.999, ψbound)
134135
saddle_cps = [SaddleControlPoint(Rx, Zx)]
135136
currents, _ = find_coil_currents!(coils, Gfixed; flux_cps, saddle_cps, λ_regularize=1e-14)
136137
if cc < 10
@@ -159,12 +160,15 @@ end
159160
Gfixed = efit(transform_cocos(gfixed, cc0, 11), 11)
160161
Gfree = efit(transform_cocos(gfree, cc0, 11), 11)
161162

163+
_, ψbound = psi_limits(Gfree)
164+
Rs, Zs = gfree.r, gfree.z
165+
162166
ix = argmin(gfree.zbbbs)
163167
Rx, Zx = gfree.rbbbs[ix], gfree.zbbbs[ix]
164168

165-
flux_cps = boundary_control_points(Gfree, 0.999)
169+
flux_cps = boundary_control_points(Gfree, 0.999, ψbound)
166170
saddle_cps = [SaddleControlPoint(Rx, Zx)]
167-
fixed2free(Gfixed, coils, gfree.r, gfree.z; flux_cps, saddle_cps);
171+
fixed2free(Gfixed, coils, Rs, Zs; flux_cps, saddle_cps)
168172
end
169173

170174
@testset "current_BtIp" begin
@@ -192,17 +196,23 @@ end
192196

193197
gfree = MXHEquilibrium.readg(EQs_free[i]; set_time=0.0)
194198
Gfree = MXHEquilibrium.efit(gfree, cc)
199+
_, ψbound = psi_limits(Gfree)
195200

196201
# Currents from EFIT
197202
p = plot(C[i, :]; linewidth=3, linecolor=:black)
198203

199204
# Currents with ψbound=0
200-
flux_cps = boundary_control_points(Gfixed, 0.999)
205+
flux_cps = boundary_control_points(Gfixed, 0.999, 0.0)
201206
c0, _ = find_coil_currents!(coils, Gfixed; flux_cps, λ_regularize=1e-14)
202207

203208
plot!(c0; linewidth=3, linecolor=:red)
204209

210+
# Currents with ψbound from EFIT
211+
flux_cps = boundary_control_points(Gfixed, 0.999, ψbound)
212+
cb, _ = find_coil_currents!(coils, Gfixed; flux_cps, λ_regularize=1e-14)
213+
plot!(cb; linewidth=3, linecolor=:blue)
205214
display(p)
215+
206216
end
207217
end
208218

0 commit comments

Comments
 (0)