diff --git a/src/PAM.jl b/src/PAM.jl index 512d514..d4b3a2f 100644 --- a/src/PAM.jl +++ b/src/PAM.jl @@ -345,24 +345,22 @@ function dr_dt!(pelt::Pellet, k::Int) Bt_exp = 0 end - # ablation model for the DT pellet - if ("D" in species_list) & ("T" in species_list) - if species_list[1] == "D" - AD = A[1] - AT = A[2] - FD = fractions[1] - FT = fractions[2] - ZD = Z[1] - ZT = Z[2] + # species are identified by element, whatever their label ("Ne" or "Ne20", "C" or "C12") or + # their order in the layer; the hydrogen isotopes are told apart by mass number + iD = findfirst(i -> Z[i] == 1 && round(A[i]) == 2, eachindex(Z)) + iT = findfirst(i -> Z[i] == 1 && round(A[i]) == 3, eachindex(Z)) + iNe = findfirst(==(10), Z) + iC = findfirst(==(6), Z) + elements(indices...) = length(Z) == length(indices) && all(!isnothing, indices) - else - AD = A[2] - AT = A[1] - FD = fractions[2] - FT = fractions[1] - ZD = Z[2] - ZT = Z[1] - end + # ablation model for the DT pellet + if elements(iD, iT) + AD = A[iD] + AT = A[iT] + FD = fractions[iD] + FT = fractions[iT] + ZD = Z[iD] + ZT = Z[iT] # according equation #1 in J.McClenaghan at al Nucl.Fusion 63 (2023) 036015 (two coefficients are missing) and normalization to FUSE units ρ_zero = (1 - FD + FD * AD / AT) * ((1 - FD) / pellet_mass_density("T") + (FD * AD / AT) / pellet_mass_density("D"))^(-1) #[g cm^-3] @@ -397,24 +395,13 @@ function dr_dt!(pelt::Pellet, k::Int) pelt.ablation_rate[k] = GT + GD - elseif ("Ne20" in species_list) & ("D" in species_list) - - if species_list[1] == "Ne" - ANe = A[1] - AD = A[2] - FNe = fractions[1] - FD = fractions[2] - ZNe = Z[1] - ZD = Z[2] - - else - ANe = A[2] - AD = A[1] - FD = fractions[1] - FNe = fractions[2] - ZNe = Z[2] - ZD = Z[1] - end + elseif elements(iNe, iD) + ANe = A[iNe] + AD = A[iD] + FNe = fractions[iNe] + FD = fractions[iD] + ZNe = Z[iNe] + ZD = Z[iD] Wratio = (1 - FD) * ANe / AD + FD @@ -453,11 +440,11 @@ function dr_dt!(pelt::Pellet, k::Int) pelt.ablation_rate[k] = GD + GNe - elseif "C12" in species_list + elseif elements(iC) C0 = 8.146777e-9 - AC = A[1] - ZC = Z[1] + AC = A[iC] + ZC = Z[iC] gamma = 5.0 / 3.0 ZstarPlus1C = 2.86 @@ -546,7 +533,7 @@ function dr_dt!(pelt::Pellet, k::Int) pelt.ablation_rate[k] = G * 6.022e23 / AC * ZC else - error("No ablation model is implemented for such combination of species") + error("No ablation model is implemented for the species $species_list: supported are D-T, D-Ne and C") end return diff --git a/test/runtests.jl b/test/runtests.jl index 4a80f65..1a6d7c1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,6 +26,34 @@ using Test end +@testset "species detection" begin + dd_D3D = IMAS.hdf2imas(joinpath(@__DIR__, "..", "examples", "template_D3D_1layer_2species.h5")) + dd_D3D.pellets.time_slice[].pellet[1].velocity_initial = 200.0 + + function ablation_rate(species) + dd = deepcopy(dd_D3D) + layer = dd.pellets.time_slice[].pellet[1].layer[1] + resize!(layer.species, length(species)) + for (s, (label, fraction)) in zip(layer.species, species) + s.label = label + s.fraction = fraction + end + pellet = PAM.run_PAM(dd; t_start=0.0, t_finish=0.0045, time_step=0.0001, drift_model=:none, Bt_dependance=true, update_plasma=false) + return pellet.ablation_rate + end + + # the order of the species in the layer does not matter + @test ablation_rate([("D", 0.6), ("T", 0.4)]) == ablation_rate([("T", 0.4), ("D", 0.6)]) + rate_DNe = ablation_rate([("D", 0.6), ("Ne20", 0.4)]) + @test maximum(rate_DNe) > 0 + @test ablation_rate([("Ne20", 0.4), ("D", 0.6)]) == rate_DNe + + # nor does the label of the element; "Ne" and "C" carry the natural isotope mix + @test isapprox(ablation_rate([("D", 0.6), ("Ne", 0.4)]), rate_DNe; rtol=2e-2) + @test isapprox(ablation_rate([("C", 1.0)]), ablation_rate([("C12", 1.0)]); rtol=1e-3) + + @test_throws ErrorException ablation_rate([("C12", 0.5), ("D", 0.5)]) + @testset "get_ilayer" begin dd = IMAS.hdf2imas(joinpath(@__DIR__, "..", "examples", "template_D3D_1layer_2species.h5")) eqt = dd.equilibrium.time_slice[]