Skip to content

Commit e1eae53

Browse files
committed
revert using :third_order for calc_z
1 parent 6349e99 commit e1eae53

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/math.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,9 @@ The finite difference `method` of the gradient can be one of [:third_order, :sec
740740
741741
NOTE: the inverse scale length is NEGATIVE for typical density/temperature profiles
742742
"""
743-
function calc_z(x::AbstractVector{<:Real}, f::AbstractVector{<:Real}; method::Symbol=:backward)
744-
return gradient(x, f; method) ./ f
743+
function calc_z(x::AbstractVector{<:Real}, f::AbstractVector{<:Real}; method::Symbol=:third_order)
744+
g = gradient(x, f; method)
745+
return g ./ f
745746
end
746747

747748
"""
@@ -750,16 +751,15 @@ end
750751
Backward integration of inverse scale length vector with given edge boundary condition
751752
"""
752753
function integ_z(rho::AbstractVector{<:Real}, z_profile::AbstractVector{<:Real}, bc::Real)
753-
f = interp1d(rho, z_profile, :cubic)
754754
profile_new = similar(rho)
755755
profile_new[end] = bc
756756
for i in length(rho)-1:-1:1
757757
a = rho[i]
758758
fa = z_profile[i]
759759
b = rho[i+1]
760760
fb = z_profile[i+1]
761-
simpson_integral = (b - a) / 6 * (fa + 4 * f((a + b) * 0.5) + fb)
762-
profile_new[i] = profile_new[i+1] * exp(simpson_integral)
761+
trapz_integral = (b - a) * (fa + fb) / 2.0
762+
profile_new[i] = profile_new[i+1] * exp(trapz_integral)
763763
end
764764
return profile_new
765765
end
@@ -1060,7 +1060,7 @@ function perimeter(r::AbstractVector{T}, z::AbstractVector{T})::T where {T<:Real
10601060
end
10611061

10621062
# If open, add distance from last point to first point
1063-
if is_open_polygon(r,z)
1063+
if is_open_polygon(r, z)
10641064
dx = r[1] - r[end]
10651065
dy = z[1] - z[end]
10661066
perimeter += sqrt(dx^2 + dy^2)

src/physics/transport.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
99
Updates profile_old with the scale lengths given by z_transport_grid
1010
11-
If `rho_ped` > transport_grid[end]` then scale-length is linearly interpolated between `transport_grid[end]` and `rho_ped`
11+
If `rho_ped > transport_grid[end]` then scale-length is linearly interpolated between `transport_grid[end]` and `rho_ped`
12+
if `rho_ped < transport_grid[end]` then scale-length then boundary condition is at `transport_grid[end]`
1213
"""
1314
function profile_from_z_transport(
1415
profile_old::AbstractVector{<:Real},
@@ -17,24 +18,24 @@ function profile_from_z_transport(
1718
z_transport_grid::AbstractVector{<:Real},
1819
rho_ped::Real=0.0)
1920

20-
z = -calc_z(rho, profile_old)
21+
z = calc_z(rho, profile_old)
2122

22-
transport_idices = [argmin(abs.(rho .- rho_x)) for rho_x in transport_grid]
23-
index_nml = argmin(abs.(rho .- rho_ped))
24-
if index_nml > transport_idices[end]
25-
transport_idices = vcat(1, transport_idices, index_nml)
26-
z_transport_grid = vcat(0.0, z_transport_grid, -z[index_nml])
23+
transport_indices = [argmin(abs.(rho .- rho_x)) for rho_x in transport_grid]
24+
index_ped = argmin(abs.(rho .- rho_ped))
25+
index_last = transport_indices[end]
26+
if index_ped > index_last
27+
transport_indices = vcat(1, transport_indices, index_ped)
28+
z_transport_grid = vcat(0.0, z_transport_grid, z[index_ped])
2729
else
28-
transport_idices = vcat(1, transport_idices)
30+
transport_indices = vcat(1, transport_indices)
2931
z_transport_grid = vcat(0.0, z_transport_grid)
3032
end
31-
rho_transport_grid = rho[transport_idices]
3233

33-
z[1:transport_idices[end]] = -interp1d(rho_transport_grid, z_transport_grid).(rho[1:transport_idices[end]])
34+
z[1:index_last] = interp1d(transport_indices, z_transport_grid).(1:index_last)
3435

3536
profile_new = similar(profile_old)
36-
profile_new[transport_idices[end]:end] = profile_old[transport_idices[end]:end]
37-
profile_new[1:transport_idices[end]] = integ_z(rho[1:transport_idices[end]], z[1:transport_idices[end]], profile_new[transport_idices[end]])
37+
profile_new[index_last:end] = @views profile_old[index_last:end]
38+
profile_new[1:index_last] = @views integ_z(rho[1:index_last], -z[1:index_last], profile_new[index_last])
3839

3940
return profile_new
4041
end

0 commit comments

Comments
 (0)