Skip to content

Commit 5feffe4

Browse files
committed
Fix traj
1 parent 95fa4f2 commit 5feffe4

File tree

3 files changed

+152
-49
lines changed

3 files changed

+152
-49
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: CI
22

3-
on: [push, pull_request, workflow_dispatch]
3+
# on: [push, pull_request, workflow_dispatch]
4+
on: [pull_request, workflow_dispatch]
45

56
# 64-bit Julia only
67
jobs:
@@ -11,7 +12,7 @@ jobs:
1112
strategy:
1213
matrix:
1314
version:
14-
- '1.11.6'
15+
- '1.12.2'
1516
os:
1617
- ubuntu-latest
1718
#- macOS-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ examples/16-galaxies/dice_spiral.params.*
7575
*.param-usedvalues
7676
examples/16-galaxies/forcetest.dat
7777
Benchmark/thread_time.dat
78+
examples/08-TrajectoryLookback/output*

examples/08-TrajectoryLookback/08-TrajectoryLookback.jl

Lines changed: 148 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
# and converted to Galactocentric coordinates using astropy.
44
# The parameters of LMC are from vasiliev2021tango_MNRAS - Tango for three sagittarius, LMC, and the milky way
55

6+
#=
7+
cd("E:\\JuliaAstroSim\\AstroNbodySim.jl\\examples\\08-TrajectoryLookback")
8+
include("08-TrajectoryLookback.jl")
9+
=#
10+
611
using Unitful, UnitfulAstro
712
using StructArrays
813
using DataFrames, CSV
@@ -21,10 +26,17 @@ df_MW_satellites = AstroIC.load_data_MW_satellites() # load from src/data/MW_sa
2126

2227
##### General parameters
2328

24-
Np = 1000
25-
# Np = 5000
26-
# Np = 10000
27-
# Np = 50000
29+
# outputdir = joinpath(@__DIR__, "output")
30+
# Np = 1000
31+
# Np_LMC = 200
32+
33+
outputdir = joinpath(@__DIR__, "output_high_res")
34+
Np = 50000
35+
Np_LMC = 1000
36+
37+
SofteningLength = 0.1u"kpc"
38+
39+
2840
GravitySolver = Tree()
2941
# GravitySolver = DirectSum()
3042
pids = [1]
@@ -34,12 +46,10 @@ TimeStep = 0.0u"Gyr" # adaptive if zero.
3446
# TimeStep = 1e-5u"Gyr"
3547
TimeBetweenSnapshots = 0.1u"Gyr"
3648

37-
file_LMC = joinpath(@__DIR__, "output/LMC_traj_lookback_Vasiliev2021", "analysis.csv")
49+
file_LMC = joinpath(outputdir, "LMC_traj_lookback_Vasiliev2021", "analysis.csv")
3850
flag_load_LMC = false # If false, re-compute the trajectory of LMC
3951
# flag_load_LMC = true # If true and the file exists, skip trajectory lookback of LMC
40-
Np_LMC = 200
41-
# Np_LMC = 1000
42-
# Np_LMC = 10000
52+
4353

4454
##### Initialize MW model
4555
@info "Initializing MW's baryons"
@@ -73,7 +83,7 @@ spl_pot = Spline1D(ustrip.(u"kpc", MW_table_r), ustrip.(u"kpc^2/Gyr^2", MW_table
7383

7484
### MW background force without LMC
7585
function MW_bg_force(p::AbstractParticle, t;
76-
SofteningLength = 0.01u"kpc",
86+
SofteningLength = SofteningLength,
7787
GravitySolver = Tree(),
7888
# GravitySolver = DirectSum(),
7989
sim_force_baryon = sim_force_baryon,
@@ -95,53 +105,53 @@ analysers = Dict(
95105
)
96106

97107

98-
99108
##### LMC
100109
if flag_load_LMC && isfile(file_LMC)
101110
@info "Loading LMC trajectory from $(file_LMC)"
102111
df_traj_LMC = DataFrame(CSV.File(file_LMC));
103112
else
104113
@info "Simulating LMC..."
105-
### Vasiliev 2021
106-
model_LMC = tNFW(5.2629e6u"Msun/kpc^3", 8.5u"kpc" * 1.38^0.6, 85u"kpc" * 1.38^0.6)
107-
config_LMC = SphericalSystem(STAR, Np_LMC,
108-
x -> GalacticDynamics.density(model_LMC, x) * 4π * x^2,
109-
)
110-
particles_LMC = generate(config_LMC;
111-
MaxRadius = 85.0u"kpc" * 1.38^0.6 * 1.5,
112-
);
113-
particles_LMC.Mass .= 1.38e11u"Msun"/Np_LMC; # make sure the total mass is 1.38e11 Msun
114-
115-
116-
tidal_initial_pos = PVector(-0.6, -41.3, -27.1, u"kpc") # Galactocentric
117-
tidal_initial_vel = -PVector(-63.9, -213.8, 206.6, u"km/s") #? Negative for lookback
118-
119-
test_particles = StructArray([
120-
Star(uAstro; id = 1),
121-
])
122-
test_particles.Pos[1] = tidal_initial_pos
123-
test_particles.Vel[1] = tidal_initial_vel
124-
125-
sim_traj_lookback = Simulation(
126-
deepcopy(test_particles);
127-
bgforce = Function[MW_bg_force],
128-
analysers,
129-
TimeEnd = 6.0u"Gyr",
130-
TimeStep = 0.0u"Gyr", # adaptive if zero.
131-
# TimeStep = 1e-5u"Gyr",
132-
TimeBetweenSnapshots = 0.1u"Gyr",
133-
Realtime = false,
134-
OutputDir = "output/LMC_traj_lookback_Vasiliev2021",
135-
);
136-
run(sim_traj_lookback);
137-
114+
let
115+
### Vasiliev 2021
116+
tidal_initial_pos = PVector(-0.6, -41.3, -27.1, u"kpc") # Galactocentric
117+
tidal_initial_vel = -PVector(-63.9, -213.8, 206.6, u"km/s") #? Negative for lookback
118+
119+
test_particles = StructArray([
120+
Star(uAstro; id = 1),
121+
])
122+
test_particles.Pos[1] = tidal_initial_pos
123+
test_particles.Vel[1] = tidal_initial_vel
124+
125+
sim_traj_lookback = Simulation(
126+
deepcopy(test_particles);
127+
bgforce = Function[MW_bg_force],
128+
analysers,
129+
TimeEnd = 6.0u"Gyr",
130+
TimeStep = 0.0u"Gyr", # adaptive if zero.
131+
# TimeStep = 1e-5u"Gyr",
132+
TimeBetweenSnapshots = 0.1u"Gyr",
133+
Realtime = false,
134+
OutputDir = joinpath(outputdir, "LMC_traj_lookback_Vasiliev2021"),
135+
);
136+
run(sim_traj_lookback);
137+
end
138138

139-
df_traj_LMC = DataFrame(CSV.File(joinpath("output/LMC_traj_lookback_Vasiliev2021", "analysis.csv")));
139+
df_traj_LMC = DataFrame(CSV.File(joinpath(outputdir, "LMC_traj_lookback_Vasiliev2021", "analysis.csv")));
140140
end
141141

142+
### Vasiliev 2021
143+
model_LMC = tNFW(5.2629e6u"Msun/kpc^3", 8.5u"kpc" * 1.38^0.6, 85u"kpc" * 1.38^0.6)
144+
config_LMC = SphericalSystem(STAR, Np_LMC,
145+
x -> GalacticDynamics.density(model_LMC, x) * 4π * x^2,
146+
)
147+
particles_LMC = generate(config_LMC;
148+
MaxRadius = 85.0u"kpc" * 1.38^0.6 * 1.5,
149+
);
150+
particles_LMC.Mass .= 1.38e11u"Msun"/Np_LMC; # make sure the total mass is 1.38e11 Msun
151+
142152

143153
function MW_bg_force_LMC(p::AbstractParticle, t;
144-
SofteningLength = 0.01u"kpc",
154+
SofteningLength = SofteningLength,
145155
GravitySolver = Tree(),
146156
# GravitySolver = DirectSum(),
147157
sim_force_baryon = sim_force_baryon,
@@ -186,7 +196,7 @@ end
186196
TimeStep,
187197
TimeBetweenSnapshots,
188198
Realtime = false,
189-
OutputDir = joinpath(@__DIR__, "output/traj_lookback_$(df_MW_satellites.Galaxy[i])_no_LMC"),
199+
OutputDir = joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[i])_no_LMC"),
190200
);
191201
run(sim_traj_lookback);
192202

@@ -209,10 +219,101 @@ end
209219
TimeStep,
210220
TimeBetweenSnapshots,
211221
Realtime = false,
212-
OutputDir = joinpath(@__DIR__, "output/traj_lookback_$(df_MW_satellites.Galaxy[i])_with_LMC"),
222+
OutputDir = joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[i])_with_LMC"),
213223
);
214224
run(sim_traj_lookback);
215225

216226
#TODO release memory of simulations
217227
end
218228

229+
230+
##### Plot Trajectories
231+
232+
@showprogress for i in eachindex(df_MW_satellites.Galaxy)
233+
Tmax = 6
234+
235+
df_no_LMC = DataFrame(CSV.File(joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[i])_no_LMC/analysis.csv")))
236+
df_with_LMC = DataFrame(CSV.File(joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[i])_with_LMC/analysis.csv")))
237+
238+
fig = Figure(; size = (400, 400))
239+
ax = Axis(fig[1,1];
240+
title = "$(df_MW_satellites.Galaxy[i])",
241+
xlabel = "t [Gyr]",
242+
ylabel = "r [kpc]",
243+
xminorticksvisible = true,
244+
xminorgridvisible = true,
245+
yminorticksvisible = true,
246+
yminorgridvisible = true,
247+
xminorticks = IntervalsBetween(10),
248+
yminorticks = IntervalsBetween(10),
249+
)
250+
Makie.xlims!(ax, -Tmax, 0)
251+
252+
r = sqrt.(df_no_LMC.x.^2 + df_no_LMC.y.^2 + df_no_LMC.z.^2)
253+
l1 = Makie.lines!(ax, -df_no_LMC.time, r; color = :blue)
254+
255+
r = sqrt.(df_with_LMC.x.^2 + df_with_LMC.y.^2 + df_with_LMC.z.^2)
256+
l2 = Makie.lines!(ax, -df_with_LMC.time, r; color = :red)
257+
258+
Makie.save(joinpath(outputdir, "traj_lookback_radius_$(df_MW_satellites.Galaxy[i]).png"), fig)
259+
end
260+
261+
let
262+
Tmax = 6
263+
264+
fig = Figure(; size = (2000, 2400))
265+
@showprogress for i in 1:5, j in 1:6
266+
id = i + (j-1) * 5
267+
df_no_LMC = DataFrame(CSV.File(joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[id])_no_LMC/analysis.csv")))
268+
df_with_LMC = DataFrame(CSV.File(joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[id])_with_LMC/analysis.csv")))
269+
270+
ax = Axis(fig[j,i];
271+
title = "$(df_MW_satellites.Galaxy[id])",
272+
xlabel = "t [Gyr]",
273+
ylabel = "r [kpc]",
274+
xminorticksvisible = true,
275+
xminorgridvisible = true,
276+
yminorticksvisible = true,
277+
yminorgridvisible = true,
278+
xminorticks = IntervalsBetween(10),
279+
yminorticks = IntervalsBetween(10),
280+
)
281+
Makie.xlims!(ax, -Tmax, 0)
282+
283+
r = sqrt.(df_no_LMC.x.^2 + df_no_LMC.y.^2 + df_no_LMC.z.^2)
284+
l1 = Makie.lines!(ax, -df_no_LMC.time, r; color = :blue)
285+
286+
r = sqrt.(df_with_LMC.x.^2 + df_with_LMC.y.^2 + df_with_LMC.z.^2)
287+
l2 = Makie.lines!(ax, -df_with_LMC.time, r; color = :red)
288+
end
289+
Makie.save(joinpath(outputdir, "traj_lookback_radius_1_30.png"), fig)
290+
Makie.save(joinpath(outputdir, "E:/islentwork/Papers/phd-thesis/islent-phd-thesis/tex/Img/traj_lookback_radius_1_30.png"), fig)
291+
292+
fig = Figure(; size = (2000, 2400))
293+
@showprogress for i in 1:5, j in 1:6
294+
id = i + (j-1) * 5 + 30
295+
df_no_LMC = DataFrame(CSV.File(joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[id])_no_LMC/analysis.csv")))
296+
df_with_LMC = DataFrame(CSV.File(joinpath(outputdir, "traj_lookback_$(df_MW_satellites.Galaxy[id])_with_LMC/analysis.csv")))
297+
298+
ax = Axis(fig[j,i];
299+
title = "$(df_MW_satellites.Galaxy[id])",
300+
xlabel = "t [Gyr]",
301+
ylabel = "r [kpc]",
302+
xminorticksvisible = true,
303+
xminorgridvisible = true,
304+
yminorticksvisible = true,
305+
yminorgridvisible = true,
306+
xminorticks = IntervalsBetween(10),
307+
yminorticks = IntervalsBetween(10),
308+
)
309+
Makie.xlims!(ax, -Tmax, 0)
310+
311+
r = sqrt.(df_no_LMC.x.^2 + df_no_LMC.y.^2 + df_no_LMC.z.^2)
312+
l1 = Makie.lines!(ax, -df_no_LMC.time, r; color = :blue)
313+
314+
r = sqrt.(df_with_LMC.x.^2 + df_with_LMC.y.^2 + df_with_LMC.z.^2)
315+
l2 = Makie.lines!(ax, -df_with_LMC.time, r; color = :red)
316+
end
317+
Makie.save(joinpath(outputdir, "traj_lookback_radius_31_60.png"), fig)
318+
Makie.save(joinpath(outputdir, "E:/islentwork/Papers/phd-thesis/islent-phd-thesis/tex/Img/traj_lookback_radius_31_60.png"), fig)
319+
end

0 commit comments

Comments
 (0)