8
8
9
9
Updates profile_old with the scale lengths given by z_transport_grid
10
10
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]`
12
13
"""
13
14
function profile_from_z_transport (
14
15
profile_old:: AbstractVector{<:Real} ,
@@ -17,24 +18,24 @@ function profile_from_z_transport(
17
18
z_transport_grid:: AbstractVector{<:Real} ,
18
19
rho_ped:: Real = 0.0 )
19
20
20
- z = - calc_z (rho, profile_old)
21
+ z = calc_z (rho, profile_old)
21
22
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])
27
29
else
28
- transport_idices = vcat (1 , transport_idices )
30
+ transport_indices = vcat (1 , transport_indices )
29
31
z_transport_grid = vcat (0.0 , z_transport_grid)
30
32
end
31
- rho_transport_grid = rho[transport_idices]
32
33
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 )
34
35
35
36
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 ])
38
39
39
40
return profile_new
40
41
end
0 commit comments