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
6 changes: 3 additions & 3 deletions src/expressions/dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ dyexp["core_profiles.global_quantities.beta_tor_norm"] =
(; dd, core_profiles, _...) -> [beta_tor_norm(dd.equilibrium.time_slice[cp1d.time], cp1d) for cp1d in core_profiles.profiles_1d]

dyexp["core_profiles.global_quantities.v_loop"] =
(; dd, _...) -> [v_loop(cp1d) for cp1d in core_profiles.profiles_1d]
(; dd, core_profiles, _...) -> [vloop(cp1d, dd.equilibrium.time_slice[cp1d.time]) for cp1d in core_profiles.profiles_1d]

#= ========= =#
# equilibrium #
Expand Down Expand Up @@ -550,7 +550,7 @@ dyexp["pulse_schedule.nbi.power.reference"] =
(; nbi, _...) -> sum(unit.power.reference for unit in nbi.unit)

dyexp["pulse_schedule.ec.power_launched.reference"] =
(; ec, _...) -> sum(beam.power_launched.reference for beam in ec.unit)
(; ec, _...) -> sum(beam.power_launched.reference for beam in ec.beam)

dyexp["pulse_schedule.ic.power.reference"] =
(; ic, _...) -> sum(antenna.power.reference for antenna in ic.antenna)
Expand Down Expand Up @@ -627,7 +627,7 @@ dyexp["summary.global_quantities.beta_pol_mhd.value"] =
(; dd, summary, _...) -> [dd.equilibrium.time_slice[time0].global_quantities.beta_pol for time0 in summary.time]

dyexp["summary.global_quantities.beta_tor.value"] =
(; dd, summary, _...) -> [beta_tor(dd.equilibrium.time_slice[time0], dd.core_profiles.profiles_1d[time0]) for time0 in summary.time]
(; dd, summary, _...) -> [beta_tor(dd.equilibrium.time_slice[time0], dd.core_profiles.profiles_1d[time0]; norm=false, thermal=false) for time0 in summary.time]

dyexp["summary.global_quantities.beta_tor_mhd.value"] =
(; dd, summary, _...) -> [dd.equilibrium.time_slice[time0].global_quantities.beta_tor for time0 in summary.time]
Expand Down
2 changes: 2 additions & 0 deletions src/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ push!(document[Symbol("Geometry")], :bisector)
polygon_rays(vertices::AbstractVector, extent_a::Float64, extent_b::Float64)

Returns bisecting "rays" (lines) that radiate from vertices of a polygon

NOTE: the k-th ray radiates from vertex k+1 (the last ray radiates from the first vertex)
"""
function polygon_rays(vertices::AbstractVector, extent_a::Float64, extent_b::Float64)
@assert is_open_polygon(vertices)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ else
include("runtests_dual.jl")

include("runtests_profiles.jl")

include("runtests_expressions.jl")
end
47 changes: 47 additions & 0 deletions test/runtests_expressions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using IMAS
using Test

# ---------------------------------------------------------------------------------------------------------------------
# Dynamic expressions: evaluated on the sample data, compared with the functions they call.
# ---------------------------------------------------------------------------------------------------------------------

@testset "expressions" begin
samp = joinpath(dirname(dirname(pathof(IMAS.IMASdd))), "sample")
dd = IMAS.json2imas(joinpath(samp, "omas_sample.json"); show_warnings=false)
fw = IMAS.first_wall(dd.wall)
IMAS.flux_surfaces(dd.equilibrium, fw.r, fw.z)
eqt = dd.equilibrium.time_slice[]
cp1d = dd.core_profiles.profiles_1d[]

@testset "core_profiles.global_quantities.v_loop" begin
empty!(dd.core_profiles.global_quantities, :v_loop)
v_loop = dd.core_profiles.global_quantities.v_loop
@test length(v_loop) == length(dd.core_profiles.profiles_1d)
@test all(isfinite, v_loop)
k = findfirst(x -> x === cp1d, dd.core_profiles.profiles_1d)
@test v_loop[k] == IMAS.vloop(cp1d, eqt)
end

@testset "pulse_schedule.ec.power_launched.reference" begin
ec = dd.pulse_schedule.ec
empty!(ec)
ec.time = [0.0, 1.0]
resize!(ec.beam, 2)
ec.beam[1].power_launched.reference = [1.0e6, 2.0e6]
ec.beam[2].power_launched.reference = [3.0e6, 5.0e6]
@test ec.power_launched.reference == [4.0e6, 7.0e6]
end

@testset "summary.global_quantities.beta_tor.value" begin
empty!(dd.summary)
dd.summary.time = [eqt.time]
beta_tor = dd.summary.global_quantities.beta_tor.value
@test beta_tor == [IMAS.beta_tor(eqt, cp1d; norm=false, thermal=false)]
@test all(isfinite, beta_tor)
# the normalized value is the same pressure average, scaled by a * B0 / ip
beta_tor_norm = dd.summary.global_quantities.beta_tor_norm.value
B0 = eqt.global_quantities.vacuum_toroidal_field.b0
ip = eqt.global_quantities.ip
@test beta_tor_norm[1] ≈ beta_tor[1] * eqt.boundary.minor_radius * abs(B0) / abs(ip / 1e6) * 1.0e2
end
end
Loading