Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'encounter_storage' into debug
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 6, 2022
2 parents 64c61fa + dd30791 commit abe5b6c
Show file tree
Hide file tree
Showing 24 changed files with 1,183 additions and 890 deletions.
60 changes: 3 additions & 57 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*
# Now, whitelist anything that's a directory
!*/
!*/python
# whitelist only the files that ever need to be tracked
!*.f90
!*.sh
Expand All @@ -13,72 +12,19 @@
!paper/paper.md
!paper/paper.bib
!README.swifter
!*.in
dump*
!example/cleanup
!example/swifter_symba_omp
!Makefile
src/*/Makefile
!Makefile.Defines
src/*/Makefile.Defines
!.gitignore
!**/.gitignore
!*.py
!*.ipynb
!examples/**
*ipynb_checkpoints

#fxdr library
!fxdr*/*.c
!fxdr*/*.F
!fxdr*/*.3f
!fxdr*/*.h
!fxdr*/*.inc
!fxdr*/cxdrreal64
!fxdr*/test.orig.xdr
!fxdr*/test_read_only.xdr
!fxdr*/configure/
!fxdr*/README*
!fxdr*/Makefile.bak
!fxdr*/Makefile.fxdr
!fxdr*/Makefile.tmpl
!fxdr*/Defines.*

#collresolve
!collresolve/*.c
!collresolve/*.h
!collresolve/*.py
!collresolve/Makefile.am
!collresolve/configure.ac
!collresolve/cambioni2019/*.h
!collresolve/cambioni2019/*.c
collresolve/config.h


**/.DS_Store

#Documentation
!docs/*
!docs/*/*
!docs/*/*/*
!README_figs/*

python/swiftest/tests/convert_code_type/swift2swifter/pl.swift2swifter.in

python/swiftest/tests/convert_code_type/swift2swifter/tp.swift2swifter.in

python/swiftest/tests/convert_code_type/swift2swiftest/cb.swift2swiftest.in

python/swiftest/tests/convert_code_type/swift2swiftest/pl.swift2swiftest.in

python/swiftest/tests/convert_code_type/swift2swiftest/tp.swift2swiftest.in

python/swiftest/tests/convert_code_type/swifter2swiftest/cb.swifter2swiftest.in

python/swiftest/tests/convert_code_type/cb.swifter2swiftest.in

python/swiftest/tests/convert_code_type/swifter2swiftest/pl.swifter2swiftest.in

python/swiftest/tests/convert_code_type/swifter2swiftest/tp.swifter2swiftest.in

!python/swiftest/requirements.txt

bin/
build/*
10 changes: 6 additions & 4 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*/param.*
*/simdata/*
*/*/simdata/*

*
!.gitignore
!Basic_Simulation/*
!Fragmentation/*
!helio_gr_test/*
!whm_gr_test/*
6 changes: 6 additions & 0 deletions examples/Basic_Simulation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!.gitignore
!initial_conditions.py
!output_reader.py
!run_from_file.py
!read_old_run.py
3 changes: 3 additions & 0 deletions examples/Fragmentation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!Fragmentation_Movie.py
99 changes: 43 additions & 56 deletions examples/Fragmentation/Fragmentation_Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
movie_titles = dict(zip(available_movie_styles, movie_title_list))

# These initial conditions were generated by trial and error
pos_vectors = {"disruption_headon" : [np.array([1.0, -1.807993e-05, 0.0]),
np.array([1.0, 1.807993e-05 ,0.0])],
pos_vectors = {"disruption_headon" : [np.array([1.0, -2.807993e-05, 0.0]),
np.array([1.0, 2.807993e-05 ,0.0])],
"supercatastrophic_off_axis": [np.array([1.0, -4.2e-05, 0.0]),
np.array([1.0, 4.2e-05, 0.0])],
"hitandrun" : [np.array([1.0, -2.0e-05, 0.0]),
Expand Down Expand Up @@ -84,7 +84,9 @@ class AnimatedScatter(object):
"""An animated scatter plot using matplotlib.animations.FuncAnimation."""

def __init__(self, sim, animfile, title, nskip=1):
nframes = int(sim.data['time'].size)
tgood = sim.enc.where(sim.enc['Gmass'] > 9e-8).time
self.ds = sim.enc.sel(time=tgood)
nframes = int(self.ds['time'].size)
self.sim = sim
self.title = title
self.body_color_list = {'Initial conditions': 'xkcd:windows blue',
Expand All @@ -106,13 +108,14 @@ def setup_plot(self):
fig = plt.figure(figsize=figsize, dpi=300)
plt.tight_layout(pad=0)


# Calculate the distance along the y-axis between the colliding bodies at the start of the simulation.
# This will be used to scale the axis limits on the movie.
scale_frame = abs(sim.data['xhy'].isel(time=0, name=1).values) \
+ abs( sim.data['xhy'].isel(time=0, name=2).values)
rhy1 = self.ds['rh'].sel(name="Body1",space='y').isel(time=0).values[()]
rhy2 = self.ds['rh'].sel(name="Body2",space='y').isel(time=0).values[()]

scale_frame = abs(rhy1) + abs(rhy2)
ax = plt.Axes(fig, [0.1, 0.1, 0.8, 0.8])
self.ax_pt_size = figsize[0] * 0.8 * 72 / scale_frame
self.ax_pt_size = figsize[0] * 0.8 * 72 / (2 * scale_frame)
ax.set_xlim(-scale_frame, scale_frame)
ax.set_ylim(-scale_frame, scale_frame)
ax.set_xticks([])
Expand All @@ -131,19 +134,20 @@ def center(Gmass, x, y):
x = x[~np.isnan(x)]
y = y[~np.isnan(y)]
Gmass = Gmass[~np.isnan(Gmass)]
x = x[Gmass]
x_com = np.sum(Gmass * x) / np.sum(Gmass)
y_com = np.sum(Gmass * y) / np.sum(Gmass)
y_com = #np.sum(Gmass * y) / np.sum(Gmass)
return x_com, y_com

Gmass, rh, point_rad = next(self.data_stream(frame))
x_com, y_com = center(Gmass, rh[:,1], rh[:,2])
self.scatter_artist.set_offsets(np.c_[x - x_com, y - y_com])
self.scatter_artist.set_sizes(point_rad)
#x_com, y_com = center(Gmass, rh[:,0], rh[:,1])
self.scatter_artist.set_offsets(np.c_[rh[:,0] - x_com, rh[:,1] - y_com])
self.scatter_artist.set_sizes(point_rad**2)
return self.scatter_artist,

def data_stream(self, frame=0):
while True:
ds = self.sim.data.isel(time=frame)
ds = self.ds.isel(time=frame)
ds = ds.where(ds['name'] != "Sun", drop=True)
radius = ds['radius'].values
Gmass = ds['Gmass'].values
Expand All @@ -153,47 +157,30 @@ def data_stream(self, frame=0):

if __name__ == "__main__":

print("Select a fragmentation movie to generate.")
print("1. Head-on disruption")
print("2. Off-axis supercatastrophic")
print("3. Hit and run")
print("4. All of the above")
user_selection = int(input("? "))

if user_selection > 0 and user_selection < 4:
movie_styles = [available_movie_styles[user_selection-1]]
else:
print("Generating all movie styles")
movie_styles = available_movie_styles.copy()

for style in movie_styles:
bin_file = Path(style) / "bin.nc"
if bin_file.exists():
user_selection = input(f"An older simulation of {movie_titles[style]} exists. Do you want to re-run it? [y/N] ")
if user_selection == "":
run_new = False
else:
try:
run_new = swiftest.io.str2bool(user_selection)
except:
run_new = False
else:
run_new = True

movie_filename = f"{style}.mp4"

# Pull in the Swiftest output data from the parameter file and store it as a Xarray dataset.
if run_new:
sim = swiftest.Simulation(simdir=style, rotation=True, init_cond_format = "XV", compute_conservation_values=True)
sim.add_solar_system_body("Sun")
sim.add_body(Gmass=body_Gmass[style], radius=body_radius[style], rh=pos_vectors[style], vh=vel_vectors[style]) #, rot=rot_vectors[style])

# Set fragmentation parameters
minimum_fragment_gmass = 0.2 * body_Gmass[style][1] # Make the minimum fragment mass a fraction of the smallest body
gmtiny = 0.99 * body_Gmass[style][1] # Make GMTINY just smaller than the smallest original body. This will prevent runaway collisional cascades
sim.set_parameter(fragmentation = True, gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False)
sim.run(dt=2e-5, tstop=2.e-5)
else:
sim = swiftest.Simulation(param_file=param_file, read_old_output_file=True)

anim = AnimatedScatter(sim,movie_filename,movie_titles[style],nskip=10)
print("Select a fragmentation movie to generate.")
print("1. Head-on disruption")
print("2. Off-axis supercatastrophic")
print("3. Hit and run")
print("4. All of the above")
user_selection = int(input("? "))

if user_selection > 0 and user_selection < 4:
movie_styles = [available_movie_styles[user_selection-1]]
else:
print("Generating all movie styles")
movie_styles = available_movie_styles.copy()

for style in movie_styles:
movie_filename = f"{style}.mp4"
# Pull in the Swiftest output data from the parameter file and store it as a Xarray dataset.
sim = swiftest.Simulation(simdir=style, rotation=True, init_cond_format = "XV", compute_conservation_values=True)
sim.add_solar_system_body("Sun")
sim.add_body(Gmass=body_Gmass[style], radius=body_radius[style], rh=pos_vectors[style], vh=vel_vectors[style]) #, rot=rot_vectors[style])
#
# Set fragmentation parameters
minimum_fragment_gmass = 0.2 * body_Gmass[style][1] # Make the minimum fragment mass a fraction of the smallest body
gmtiny = 0.99 * body_Gmass[style][1] # Make GMTINY just smaller than the smallest original body. This will prevent runaway collisional cascades
sim.set_parameter(fragmentation=True, fragmentation_save="TRAJECTORY", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False)
sim.run(dt=1e-4, tstop=2.0e-3, istep_out=1, dump_cadence=0)

anim = AnimatedScatter(sim,movie_filename,movie_titles[style],nskip=1)
3 changes: 3 additions & 0 deletions examples/helio_gr_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!helio_gr_test.py
3 changes: 3 additions & 0 deletions examples/whm_gr_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!whm_gr_test.py
Loading

0 comments on commit abe5b6c

Please sign in to comment.