Skip to content

Commit

Permalink
fix Rotation Curve
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Aug 13, 2024
1 parent f37ad06 commit 0c189c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AstroLib = "c7932e45-9af1-51e7-9da9-f004cd3a462b"
AstroSimBase = "c6a34d98-f626-4d8d-b450-a3f124eaada6"
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
PhysicalConstants = "5ad8b20f-a522-5ce9-bfc9-ddf1d5bda6ab"
Expand All @@ -26,6 +27,7 @@ AstroIO = "0.1"
AstroLib = "0.4"
AstroSimBase = "0.1"
BangBang = "0.3, 0.4"
Dierckx = "0.5"
Distributions = "0.25"
DocStringExtensions = "0.8, 0.9"
PhysicalConstants = "0.2"
Expand Down
1 change: 1 addition & 0 deletions src/AstroIC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using Random
using BangBang
using Dates
using StructArrays
using Dierckx

@reexport using PhysicalParticles
@reexport using AstroIO
Expand Down
34 changes: 29 additions & 5 deletions src/disk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ function sech2_cdf_inv(u)
return atanh(2*u-1)
end

"""
$(TYPEDSIGNATURES)
Rotate along the positive z-axis.
- `ratio`: rotational motion v.s. random motion. If equals `1`, only rotational component
"""
function rotational_velocity_acc(x, y, z, a, ratio = 1.0)
u = unit(x)
r = sqrt(x^2 + y^2 + z^2)
v = sqrt(a * r)
v_vec = -normalize(PVector(ustrip(u,x), ustrip(u,y), 0.0) × PVector(0.0, 0.0, 1.0)) * v
v_vec = ratio * v_vec + (1-ratio) * randn(PVector{Float64}) * v
end

"""
$(TYPEDSIGNATURES)
Rotate along the positive z-axis.
- `ratio`: rotational motion v.s. random motion. If equals `1`, only rotational component
"""
function rotational_velocity(x, y, v, ratio = 1.0)
u = unit(x)
v_vec = -normalize(PVector(ustrip(u,x), ustrip(u,y), 0.0) × PVector(0.0, 0.0, 1.0)) * v
v_vec = ratio * v_vec + (1-ratio) * randn(PVector{Float64}) * v
end

"""
$(TYPEDSIGNATURES)
Expand All @@ -124,9 +148,9 @@ function generate(config::ExponentialDisk, units = uAstro;
RotationCurve = nothing,
MaxRadius = 5 * config.ScaleRadius,
MaxHeight = MaxRadius,
k = 1, # degree of rotation curve interpolation/extrapolation spline (1 = linear, 2 = quadratic, 3 = cubic, up to 5)
k = 2, # degree of rotation curve interpolation/extrapolation spline (1 = linear, 2 = quadratic, 3 = cubic, up to 5)
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"
rotational_ratio = 0,
rotational_ratio = 0.9,
)
uLen = getuLength(units)
uVel = getuVel(units)
Expand Down Expand Up @@ -184,9 +208,9 @@ function generate(config::ExponentialDisk, units = uAstro;
vel = [PVector(uVel) for i in 1:NumSamples]
else
xc, vc = RotationCurve
spl = Spline1D(ustrip.(unit(eltype(xc)), xc), vc; k, bc)
v = spl(ustrip.(unit(eltype(R)), R))
vel = rotational_velocity.(pos.x, pos.y, pos.z, v, rotational_ratio)
spl = Spline1D(ustrip.(uLen, xc), ustrip.(uVel, vc); k, bc)
v = spl(ustrip.(uLen, R)) * uVel
vel = rotational_velocity.(pos.x, pos.y, v, rotational_ratio)
end

# Packing
Expand Down

0 comments on commit 0c189c5

Please sign in to comment.