Skip to content

Commit 0c189c5

Browse files
committed
fix Rotation Curve
1 parent f37ad06 commit 0c189c5

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AstroLib = "c7932e45-9af1-51e7-9da9-f004cd3a462b"
99
AstroSimBase = "c6a34d98-f626-4d8d-b450-a3f124eaada6"
1010
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
1111
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
12+
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
1213
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1314
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1415
PhysicalConstants = "5ad8b20f-a522-5ce9-bfc9-ddf1d5bda6ab"
@@ -26,6 +27,7 @@ AstroIO = "0.1"
2627
AstroLib = "0.4"
2728
AstroSimBase = "0.1"
2829
BangBang = "0.3, 0.4"
30+
Dierckx = "0.5"
2931
Distributions = "0.25"
3032
DocStringExtensions = "0.8, 0.9"
3133
PhysicalConstants = "0.2"

src/AstroIC.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using Random
1111
using BangBang
1212
using Dates
1313
using StructArrays
14+
using Dierckx
1415

1516
@reexport using PhysicalParticles
1617
@reexport using AstroIO

src/disk.jl

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ function sech2_cdf_inv(u)
116116
return atanh(2*u-1)
117117
end
118118

119+
"""
120+
$(TYPEDSIGNATURES)
121+
Rotate along the positive z-axis.
122+
- `ratio`: rotational motion v.s. random motion. If equals `1`, only rotational component
123+
"""
124+
function rotational_velocity_acc(x, y, z, a, ratio = 1.0)
125+
u = unit(x)
126+
r = sqrt(x^2 + y^2 + z^2)
127+
v = sqrt(a * r)
128+
v_vec = -normalize(PVector(ustrip(u,x), ustrip(u,y), 0.0) × PVector(0.0, 0.0, 1.0)) * v
129+
v_vec = ratio * v_vec + (1-ratio) * randn(PVector{Float64}) * v
130+
end
131+
132+
"""
133+
$(TYPEDSIGNATURES)
134+
Rotate along the positive z-axis.
135+
- `ratio`: rotational motion v.s. random motion. If equals `1`, only rotational component
136+
"""
137+
function rotational_velocity(x, y, v, ratio = 1.0)
138+
u = unit(x)
139+
v_vec = -normalize(PVector(ustrip(u,x), ustrip(u,y), 0.0) × PVector(0.0, 0.0, 1.0)) * v
140+
v_vec = ratio * v_vec + (1-ratio) * randn(PVector{Float64}) * v
141+
end
142+
119143
"""
120144
$(TYPEDSIGNATURES)
121145
@@ -124,9 +148,9 @@ function generate(config::ExponentialDisk, units = uAstro;
124148
RotationCurve = nothing,
125149
MaxRadius = 5 * config.ScaleRadius,
126150
MaxHeight = MaxRadius,
127-
k = 1, # degree of rotation curve interpolation/extrapolation spline (1 = linear, 2 = quadratic, 3 = cubic, up to 5)
151+
k = 2, # degree of rotation curve interpolation/extrapolation spline (1 = linear, 2 = quadratic, 3 = cubic, up to 5)
128152
bc = "nearest", # behavior when evaluating the spline outside the support domain, which is (minimum(x), maximum(x)). The allowed values are "nearest", "zero", "extrapolate", "error"
129-
rotational_ratio = 0,
153+
rotational_ratio = 0.9,
130154
)
131155
uLen = getuLength(units)
132156
uVel = getuVel(units)
@@ -184,9 +208,9 @@ function generate(config::ExponentialDisk, units = uAstro;
184208
vel = [PVector(uVel) for i in 1:NumSamples]
185209
else
186210
xc, vc = RotationCurve
187-
spl = Spline1D(ustrip.(unit(eltype(xc)), xc), vc; k, bc)
188-
v = spl(ustrip.(unit(eltype(R)), R))
189-
vel = rotational_velocity.(pos.x, pos.y, pos.z, v, rotational_ratio)
211+
spl = Spline1D(ustrip.(uLen, xc), ustrip.(uVel, vc); k, bc)
212+
v = spl(ustrip.(uLen, R)) * uVel
213+
vel = rotational_velocity.(pos.x, pos.y, v, rotational_ratio)
190214
end
191215

192216
# Packing

0 commit comments

Comments
 (0)