From 189abeb4ce209c7f17e4553f1f64caec058bdf76 Mon Sep 17 00:00:00 2001 From: Carlisle Wishard Date: Tue, 6 Dec 2022 13:29:58 -0500 Subject: [PATCH] added a header and some comments to the whm_gr_test example --- examples/whm_gr_test/whm_gr_test.py | 51 ++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/examples/whm_gr_test/whm_gr_test.py b/examples/whm_gr_test/whm_gr_test.py index 2061e251b..ab397c464 100644 --- a/examples/whm_gr_test/whm_gr_test.py +++ b/examples/whm_gr_test/whm_gr_test.py @@ -1,18 +1,65 @@ -#!/usr/bin/env python +""" + Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh + This file is part of Swiftest. + Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with Swiftest. + If not, see: https://www.gnu.org/licenses. +""" + +#!/usr/bin/env python3 +""" +Generates and runs two sets of Swiftest input files from initial conditions with the WHM integrator. All simulation +outputs for the general relativity run are stored in the /gr subdirectory while all simulation outputs for the run +without general reelativity are stored in the /nogr subdirectory. + +Input +------ +None + +Output +------ +whm_gr_mercury_precession.png : Portable Network Graphic file depicting the precession of Mercury's perihelion over time + with data sourced from the JPL Horizons database, Swiftest run with general relativity, + and Swiftest run without general relativity. +gr/bin.nc : A NetCDF file containing the simulation output. +gr/dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0. +gr/dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0. +gr/dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation. +gr/dump_param2.in : An ASCII file containing the necessary parameters to restart a simulation. +gr/init_cond.nc : A NetCDF file containing the initial conditions for the simulation. +gr/param.in : An ASCII file containing the parameters for the simulation. +gr/swiftest.log : An ASCII file containing the information on the status of the simulation as it runs. +nogr/bin.nc : A NetCDF file containing the simulation output. +nogr/dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0. +nogr/dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0. +nogr/dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation. +nogr/dump_param2.in : An ASCII file containing the necessary parameters to restart a simulation. +nogr/init_cond.nc : A NetCDF file containing the initial conditions for the simulation. +nogr/param.in : An ASCII file containing the parameters for the simulation. +nogr/swiftest.log : An ASCII file containing the information on the status of the simulation as it runs. +""" + import swiftest from astroquery.jplhorizons import Horizons import datetime import numpy as np import matplotlib.pyplot as plt +# Initialize the simulation object as a variable. Define the directory in which the output will be placed. sim_gr = swiftest.Simulation(simdir="gr") sim_gr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) +# Initialize the simulation object as a variable. Define the directory in which the output will be placed. sim_nogr = swiftest.Simulation(simdir="nogr") sim_nogr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) +# Define a set of arguments that apply to both runs. For a list of possible arguments, see the User Manual. run_args = {"tstop":1000.0, "dt":0.005, "tstep_out":10.0, "dump_cadence": 0,"integrator":"whm"} +# Run both simulations. sim_gr.run(**run_args,general_relativity=True) sim_nogr.run(**run_args,general_relativity=False) @@ -38,6 +85,7 @@ dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out'] dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100 +# Plot of the data and save the output plot fig, ax = plt.subplots() ax.plot(t, varpi_obs, label="JPL Horizons",linewidth=2.5) @@ -48,6 +96,7 @@ ax.legend() plt.savefig("whm_gr_mercury_precession.png",dpi=300) +# Print the data to the terminal. print('Mean precession rate for Mercury long. peri. (arcsec/100 y)') print(f'JPL Horizons : {np.mean(dvarpi_obs)}') print(f'Swiftest No GR : {np.mean(dvarpi_nogr)}')