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

Commit

Permalink
Merge branch 'debug' into encounter_storage
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 7, 2022
2 parents d09d8c5 + ea48c5f commit 81a4b56
Show file tree
Hide file tree
Showing 39 changed files with 245 additions and 6,161 deletions.
7 changes: 0 additions & 7 deletions examples/Basic_Simulation/cb.in

This file was deleted.

33 changes: 23 additions & 10 deletions examples/Basic_Simulation/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,37 @@

#!/usr/bin/env python3
"""
Generates a set of Swiftest input files from initial conditions.
Generates and runs a set of Swiftest input files from initial conditions with the SyMBA integrator. All simulation
outputs are stored in the /simdata subdirectory.
Returns
-------
Updates sim.data with the simulation data
Input
------
None.
Output
------
bin.nc : A NetCDF file containing the simulation output.
dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation.
dump_param2.in : An ASCII file containing the necessary parameters to restart a simulation.
fraggle.log : An ASCII file containing the information of any collisional events that occured.
init_cond.nc : A NetCDF file containing the initial conditions for the simulation.
param.in : An ASCII file containing the parameters for the simulation.
swiftest.log : An ASCII file containing the information on the status of the simulation as it runs.
"""

import swiftest
import numpy as np
from numpy.random import default_rng

# Initialize the simulation object as a variable
# Initialize the simulation object as a variable. Arguments may be defined here or through the sim.run() method.
sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)

# Add the modern planets and the Sun using the JPL Horizons Database
# Add the modern planets and the Sun using the JPL Horizons Database.
sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"])

# Add 5 user-defined massive bodies
# Add 5 user-defined massive bodies.
npl = 5
density_pl = 3000.0 / (sim.param['MU2KG'] / sim.param['DU2M'] ** 3)

Expand All @@ -47,7 +60,7 @@

sim.add_body(name=name_pl, a=a_pl, e=e_pl, inc=inc_pl, capom=capom_pl, omega=omega_pl, capm=capm_pl, Gmass=GM_pl, radius=R_pl, rhill=Rh_pl, Ip=Ip_pl, rot=rot_pl)

# Add 10 user-defined test particles
# Add 10 user-defined test particles.
ntp = 10

name_tp = ["TestParticle_01", "TestParticle_02", "TestParticle_03", "TestParticle_04", "TestParticle_05", "TestParticle_06", "TestParticle_07", "TestParticle_08", "TestParticle_09", "TestParticle_10"]
Expand All @@ -59,8 +72,8 @@
capm_tp = default_rng().uniform(0.0, 360.0, ntp)

sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp)
# Display the run configuration parameters
# Display the run configuration parameters.
sim.get_parameter()

# Run the simulation
# Run the simulation. Arguments may be defined here or thorugh the swiftest.Simulation() method.
sim.run(tstart=0.0, tstop=1.0e3, dt=0.01, tstep_out=1.0e0, dump_cadence=0)
31 changes: 15 additions & 16 deletions examples/Basic_Simulation/output_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,32 @@
Reads and processes a Swiftest output file.
Input
-------
out.nc : NetCDF file
Swiftest output file.
------
bin.nc : A NetCDF file containing the simulation output.
Returns
-------
output.eps : Encapsulated PostScript file.
A figure containing the eccentricity vs. semi-major axis for all bodies at the start of the simulation.
Output
------
output.eps : Encapsulated PostScript file depicting the eccentricity vs. semi-major axis for all bodies at the start
of the simulation.
"""

import swiftest
import xarray as xr
import matplotlib.pyplot as plt

# Read in the simulation output and store it as an Xarray dataset
ds = swiftest.Simulation(param_file="simdata/param.in", read_old_output_file=True).data
# Read in the simulation output and store it as an Xarray dataset.
sim = swiftest.Simulation(read_old_output_file=True)

# Plot of the data and save the output plot
colors = ['white' if x == 'Massive Body' else 'black' for x in ds['particle_type']]
sizes = [100 if x == 'Massive Body' else 10 for x in ds['particle_type']]
# Plot of the data and save the output plot.
colors = ['white' if x == 'Massive Body' else 'black' for x in sim.data['particle_type']]
sizes = [100 if x == 'Massive Body' else 10 for x in sim.data['particle_type']]

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(5,3))
ax.set(xlabel="Semimajor Axis (AU)", ylabel="Eccentricity", title="Simulation Start")
ax.scatter(ds['a'].isel(time=0), ds['e'].isel(time=0), c=colors, s=sizes, edgecolor='black')
ax.set(xlabel="Semimajor Axis (AU)", ylabel="Eccentricity", title="Simulation Initial Conditions (t=0)")
ax.scatter(sim.data['a'].isel(time=0), sim.data['e'].isel(time=0), c=colors, s=sizes, edgecolor='black')
ax.set_xlim(0, 2.0)
ax.set_ylim(0, 0.4)
ax.text(1.5, 0.35, f"t = {ds['time'].isel(time=0).values} years", size=10, ha="left")
ax.text(1.5, 0.35, f"t = {sim.data['time'].isel(time=0).values} years", size=10, ha="left")
plt.tight_layout()
plt.show()
fig.savefig("output.eps", dpi=300, facecolor='white', transparent=False, bbox_inches="tight")
fig.savefig("output.eps", dpi=300, facecolor='white', transparent=False, bbox_inches="tight")
85 changes: 0 additions & 85 deletions examples/Basic_Simulation/pl.in

This file was deleted.

Loading

0 comments on commit 81a4b56

Please sign in to comment.