diff --git a/examples/helio_gr_test/init_cond.py b/examples/helio_gr_test/init_cond.py new file mode 100755 index 000000000..9e89dc358 --- /dev/null +++ b/examples/helio_gr_test/init_cond.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +import swiftest + +sim = swiftest.Simulation() +sim.param['PL_IN'] = "pl.swiftest.in" +sim.param['TP_IN'] = "tp.swiftest.in" +sim.param['CB_IN'] = "cb.swiftest.in" +sim.param['BIN_OUT'] = "bin.swiftest.nc" + +sim.param['MU2KG'] = swiftest.MSun +sim.param['TU2S'] = swiftest.YR2S +sim.param['DU2M'] = swiftest.AU2M +sim.param['T0'] = 0.0 +sim.param['DT'] = 0.25 * swiftest.JD2S / swiftest.YR2S +sim.param['TSTOP'] = 1000.0 +sim.param['ISTEP_OUT'] = 1461 +sim.param['ISTEP_DUMP'] = 1461 +sim.param['CHK_QMIN_COORD'] = "HELIO" +sim.param['CHK_QMIN'] = swiftest.RSun / swiftest.AU2M +sim.param['CHK_QMIN_RANGE'] = f"{swiftest.RSun / swiftest.AU2M} 1000.0" +sim.param['CHK_RMIN'] = swiftest.RSun / swiftest.AU2M +sim.param['CHK_RMAX'] = 1000.0 +sim.param['CHK_EJECT'] = 1000.0 +sim.param['OUT_STAT'] = "UNKNOWN" +sim.param['IN_FORM'] = "EL" +sim.param['OUT_FORM'] = "XVEL" +sim.param['OUT_TYPE'] = "NETCDF_DOUBLE" +sim.param['RHILL_PRESENT'] = "YES" +sim.param['GR'] = 'YES' + +bodyid = { + "Sun": 0, + "Mercury": 1, + "Venus": 2, + "Earth": 3, + "Mars": 4, + "Jupiter": 5, + "Saturn": 6, + "Uranus": 7, + "Neptune": 8, +} + +for name, id in bodyid.items(): + sim.add(name, idval=id, date="2027-04-30") + +sim.save("param.swiftest.in") + + diff --git a/examples/whm_gr_test/init_cond.py b/examples/whm_gr_test/init_cond.py new file mode 100644 index 000000000..7904eb100 --- /dev/null +++ b/examples/whm_gr_test/init_cond.py @@ -0,0 +1,226 @@ +import numpy as np +import sys +from astroquery.jplhorizons import Horizons +import astropy.constants as const + +#Values from JPL Horizons +AU2M = const.au.value +GMSunSI = const.GM_sun.value +Rsun = const.R_sun.value +GC = const.G.value +JD = 86400 +year = 365.25 * JD +c = 299792458.0 +MSun_over_Mpl = [6023600.0, + 408523.71, + 328900.56, + 3098708., + 1047.3486, + 3497.898, + 22902.98, + 19412.24, + 1.35e8] + +MU2KG = GMSunSI / GC #Conversion from mass unit to kg +DU2M = AU2M #Conversion from radius unit to centimeters +TU2S = year #Conversion from time unit to seconds +GU = GC / (DU2M**3 / (MU2KG * TU2S**2)) + +GMSun = GMSunSI / (DU2M**3 / TU2S**2) + +t_print = 10.e0 * year / TU2S #output interval to print results +deltaT = 0.25 * JD / TU2S #timestep simulation +end_sim = 1.0e3 * year / TU2S + t_print #end time + +# Solar oblatenes values: From Mecheri et al. (2004), using Corbard (b) 2002 values (Table II) +J2 = 2.198e-7 * (Rsun / DU2M)**2 +J4 = -4.805e-9 * (Rsun / DU2M)**4 + +tstart = '2021-01-28' +tend = '2021-01-29' +tstep = '1d' +planetid = { + 'mercury' : '1', + 'venus' : '2', + 'earthmoon' : '3', + 'mars' : '4', + 'jupiter' : '5', + 'saturn' : '6', + 'uranus' : '7', + 'neptune' : '8', + 'plutocharon' : '9' +} +npl = 9 + +#Planet Msun/M ratio +MSun_over_Mpl = { + 'mercury' : 6023600.0, + 'venus' : 408523.71, + 'earthmoon' : 328900.56, + 'mars' : 3098708., + 'jupiter' : 1047.3486, + 'saturn' : 3497.898, + 'uranus' : 22902.98, + 'neptune' : 19412.24, + 'plutocharon' : 1.35e8 +} + +#Planet radii in meters +Rpl = { + 'mercury' : 2439.4e3, + 'venus' : 6051.8e3, + 'earthmoon' : 6371.0084e3, # Earth only for radius + 'mars' : 3389.50e3, + 'jupiter' : 69911e3, + 'saturn' : 58232.0e3, + 'uranus' : 25362.e3, + 'neptune' : 24622.e3, + 'plutocharon' : 1188.3e3 +} + +pdata = {} +plvec = {} +Rhill = {} + +for key,val in planetid.items(): + pdata[key] = Horizons(id=val, id_type='majorbody',location='@sun', + epochs={'start': tstart, 'stop': tend, + 'step': tstep}) + plvec[key] = np.array([pdata[key].vectors()['x'][0], + pdata[key].vectors()['y'][0], + pdata[key].vectors()['z'][0], + pdata[key].vectors()['vx'][0], + pdata[key].vectors()['vy'][0], + pdata[key].vectors()['vz'][0] + ]) + Rhill[key] = pdata[key].elements()['a'][0] * (3 * MSun_over_Mpl[key])**(-1.0 / 3.0) + + +if __name__ == '__main__': + # Convert from AU-day to AU-year just because I find it easier to keep track of the sim progress + for plid in plvec: + plvec[plid][3:] *= year / JD + + # Names of all output files + swifter_input = "param.swifter.in" + swifter_pl = "pl.swifter.in" + swifter_tp = "tp.swifter.in" + swifter_bin = "bin.swifter.dat" + swifter_enc = "enc.swifter.dat" + + swiftest_input = "param.swiftest.in" + swiftest_pl = "pl.swiftest.in" + swiftest_tp = "tp.swiftest.in" + swiftest_cb = "cb.swiftest.in" + swiftest_bin = "bin.swiftest.dat" + swiftest_enc = "enc.swiftest.dat" + + # Simulation start, stop, and output cadence times + t_0 = 0 # simulation start time + end_sim = 1000.0e0 * year / TU2S # simulation end time + deltaT = 0.25 * JD / TU2S # simulation step size + t_print = 1.0 * year / TU2S #output interval to print results + + iout = int(np.ceil(t_print / deltaT)) + rmin = Rsun / DU2M + rmax = 1000.0 + + #Make Swifter files + plfile = open(swifter_pl, 'w') + print(f'{npl+1} ! Planet input file generated using init_cond.py using JPL Horizons data for the major planets (and Pluto) for epoch {tstart}' ,file=plfile) + print(f'1 {GMSun}',file=plfile) + print(f'0.0 0.0 0.0',file=plfile) + print(f'0.0 0.0 0.0',file=plfile) + for i, plid in enumerate(plvec): + print(f'{i + 2} {GMSun / MSun_over_Mpl[plid]} {Rhill[plid]}', file=plfile) + print(f'{Rpl[plid] / DU2M}', file=plfile) + print(f'{plvec[plid][0]} {plvec[plid][1]} {plvec[plid][2]}', file=plfile) + print(f'{plvec[plid][3]} {plvec[plid][4]} {plvec[plid][5]}', file=plfile) + plfile.close() + + tpfile = open(swifter_tp, 'w') + print(0,file=tpfile) + tpfile.close() + + sys.stdout = open(swifter_input, "w") + print(f'! Swifter input file generated using init_cond.py') + print(f'T0 {t_0} ') + print(f'TSTOP {end_sim}') + print(f'DT {deltaT}') + print(f'PL_IN {swifter_pl}') + print(f'TP_IN {swifter_tp}') + print(f'IN_TYPE ASCII') + print(f'ISTEP_OUT {iout:d}') + print(f'ISTEP_DUMP {iout:d}') + print(f'BIN_OUT {swifter_bin}') + print(f'OUT_TYPE REAL8') + print(f'OUT_FORM EL') + print(f'OUT_STAT NEW') + print(f'J2 {J2}') + print(f'J4 {J4}') + print(f'CHK_CLOSE yes') + print(f'CHK_RMIN {rmin}') + print(f'CHK_RMAX {rmax}') + print(f'CHK_EJECT {rmax}') + print(f'CHK_QMIN {rmin}') + print(f'CHK_QMIN_COORD HELIO') + print(f'CHK_QMIN_RANGE {rmin} {rmax}') + print(f'ENC_OUT {swifter_enc}') + print(f'EXTRA_FORCE no') + print(f'BIG_DISCARD no') + print(f'RHILL_PRESENT yes') + print(f'C {c / (DU2M / TU2S)}') + + #Now make Swiftest files + cbfile = open(swiftest_cb, 'w') + print(f'{1.0}',file=cbfile) + print(f'{rmin}',file=cbfile) + print(f'{J2}',file=cbfile) + print(f'{J4}',file=cbfile) + + plfile = open(swiftest_pl, 'w') + print(npl,file=plfile) + + for i, plid in enumerate(plvec): + print(f'{i + 2} {1.0 / MSun_over_Mpl[plid]}', file=plfile) + print(f'{Rpl[plid] / DU2M}', file=plfile) + print(f'{plvec[plid][0]} {plvec[plid][1]} {plvec[plid][2]}', file=plfile) + print(f'{plvec[plid][3]} {plvec[plid][4]} {plvec[plid][5]}', file=plfile) + plfile.close() + tpfile = open(swiftest_tp, 'w') + print(0,file=tpfile) + tpfile.close() + + sys.stdout = open(swiftest_input, "w") + print(f'! Swiftest input file generated using init_cond.py') + print(f'T0 {t_0} ') + print(f'TSTOP {end_sim}') + print(f'DT {deltaT}') + print(f'CB_IN {swiftest_cb}') + print(f'PL_IN {swiftest_pl}') + print(f'TP_IN {swiftest_tp}') + print(f'IN_TYPE ASCII') + print(f'ISTEP_OUT {iout:d}') + print(f'ISTEP_DUMP {iout:d}') + print(f'BIN_OUT {swiftest_bin}') + print(f'OUT_TYPE REAL8') + print(f'OUT_FORM EL') + print(f'OUT_STAT REPLACE') + print(f'CHK_CLOSE yes') + print(f'CHK_RMIN {rmin}') + print(f'CHK_RMAX {rmax}') + print(f'CHK_EJECT {rmax}') + print(f'CHK_QMIN {rmin}') + print(f'CHK_QMIN_COORD HELIO') + print(f'CHK_QMIN_RANGE {rmin} {rmax}') + print(f'ENC_OUT {swiftest_enc}') + print(f'EXTRA_FORCE no') + print(f'BIG_DISCARD no') + print(f'ROTATION no') + print(f'GR yes') + print(f'MU2KG {MU2KG}') + print(f'DU2M {DU2M}') + print(f'TU2S {TU2S}') + + + sys.stdout = sys.__stdout__ diff --git a/examples/whm_gr_test/swiftest_relativity.ipynb b/examples/whm_gr_test/swiftest_relativity.ipynb new file mode 100644 index 000000000..0cd73753f --- /dev/null +++ b/examples/whm_gr_test/swiftest_relativity.ipynb @@ -0,0 +1,1050 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import swiftest\n", + "from astroquery.jplhorizons import Horizons\n", + "import datetime\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Creating the Sun as a central body\n", + "Fetching ephemerides data for Mercury from JPL/Horizons\n", + "Fetching ephemerides data for Venus from JPL/Horizons\n", + "Fetching ephemerides data for Earth from JPL/Horizons\n", + "Fetching ephemerides data for Mars from JPL/Horizons\n", + "Fetching ephemerides data for Jupiter from JPL/Horizons\n", + "Fetching ephemerides data for Saturn from JPL/Horizons\n", + "Fetching ephemerides data for Uranus from JPL/Horizons\n", + "Fetching ephemerides data for Neptune from JPL/Horizons\n", + "Writing initial conditions to file init_cond.nc\n", + "Writing parameter inputs to file /home/daminton/git_debug/swiftest/examples/whm_gr_test/param.gr.in\n" + ] + }, + { + "data": { + "text/html": [ + "
<xarray.Dataset>\n", + "Dimensions: (name: 9, time: 1)\n", + "Coordinates:\n", + " * name (name) <U32 'Sun' 'Mercury' 'Venus' ... 'Uranus' 'Neptune'\n", + " * time (time) float64 0.0\n", + "Data variables: (12/14)\n", + " particle_type (name) <U32 'Central Body' 'Massive Body' ... 'Massive Body'\n", + " id (name) int64 0 1 2 3 4 5 6 7 8\n", + " Gmass (time, name) float64 39.48 6.554e-06 ... 0.001724 0.002034\n", + " radius (time, name) float64 0.00465 1.631e-05 ... 0.0001646\n", + " j2rp2 (time, name) float64 4.754e-12 nan nan nan ... nan nan nan\n", + " j4rp4 (time, name) float64 -2.247e-18 nan nan nan ... nan nan nan\n", + " ... ...\n", + " xhz (time, name) float64 nan -0.002529 ... -0.0407 -0.7287\n", + " vhx (time, name) float64 nan -9.241 3.454 ... -1.315 -0.08755\n", + " vhy (time, name) float64 nan 7.755 6.477 ... 1.932 0.5372 1.149\n", + " vhz (time, name) float64 nan 1.481 -0.1103 ... 0.01905 -0.02168\n", + " ntp (time) int64 0\n", + " npl (time) int64 8
array(['Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn',\n", + " 'Uranus', 'Neptune'], dtype='<U32')
array([0.])
array(['Central Body', 'Massive Body', 'Massive Body', 'Massive Body',\n", + " 'Massive Body', 'Massive Body', 'Massive Body', 'Massive Body',\n", + " 'Massive Body'], dtype='<U32')
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
array([[3.94769264e+01, 6.55370981e-06, 9.66331340e-05, 1.20026936e-04,\n", + " 1.27398020e-05, 3.76922511e-02, 1.12858998e-02, 1.72365895e-03,\n", + " 2.03361005e-03]])
array([[4.65046726e-03, 1.63063818e-05, 4.04537843e-05, 4.25875607e-05,\n", + " 2.26574081e-05, 4.67326170e-04, 3.89256877e-04, 1.69534499e-04,\n", + " 1.64587904e-04]])
array([[4.75358069e-12, nan, nan, nan,\n", + " nan, nan, nan, nan,\n", + " nan]])
array([[-2.2473968e-18, nan, nan, nan,\n", + " nan, nan, nan, nan,\n", + " nan]])
array([[ nan, 0.22527007, 0.64013386, -0.78195044, -1.65001718,\n", + " -4.54078501, 8.901068 , 8.17855335, 29.79419863]])
array([[ nan, 0.22185516, -0.34396282, -0.63468545, -0.02334143,\n", + " 2.86428737, 2.90284887, 17.59478942, 2.04463099]])
array([[ nan, -2.52922505e-03, -4.16625374e-02,\n", + " 4.44514635e-05, 3.99643397e-02, 8.96961900e-02,\n", + " -4.04874151e-01, -4.06951825e-02, -7.28719479e-01]])
array([[ nan, -9.24105838, 3.45369085, 3.8578492 , 0.26241127,\n", + " -1.50370126, -0.74393964, -1.31492768, -0.0875473 ]])
array([[ nan, 7.754686 , 6.47714891, -4.90267373, -4.67368878,\n", + " -2.20463162, 1.93168513, 0.5372287 , 1.14922255]])
array([[ nan, 1.48128538e+00, -1.10257596e-01,\n", + " 2.88870085e-04, -1.04392391e-01, 4.28033174e-02,\n", + " -4.02921477e-03, 1.90517453e-02, -2.16786846e-02]])
array([0])
array([8])
<xarray.Dataset>\n", + "Dimensions: (name: 9, time: 1)\n", + "Coordinates:\n", + " * name (name) <U32 'Sun' 'Mercury' 'Venus' ... 'Uranus' 'Neptune'\n", + " * time (time) float64 0.0\n", + "Data variables: (12/14)\n", + " particle_type (name) <U32 'Central Body' 'Massive Body' ... 'Massive Body'\n", + " id (name) int64 0 1 2 3 4 5 6 7 8\n", + " Gmass (time, name) float64 39.48 6.554e-06 ... 0.001724 0.002034\n", + " radius (time, name) float64 0.00465 1.631e-05 ... 0.0001646\n", + " j2rp2 (time, name) float64 4.754e-12 nan nan nan ... nan nan nan\n", + " j4rp4 (time, name) float64 -2.247e-18 nan nan nan ... nan nan nan\n", + " ... ...\n", + " xhz (time, name) float64 nan -0.002529 ... -0.0407 -0.7287\n", + " vhx (time, name) float64 nan -9.241 3.454 ... -1.315 -0.08755\n", + " vhy (time, name) float64 nan 7.755 6.477 ... 1.932 0.5372 1.149\n", + " vhz (time, name) float64 nan 1.481 -0.1103 ... 0.01905 -0.02168\n", + " ntp (time) int64 0\n", + " npl (time) int64 8
array(['Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn',\n", + " 'Uranus', 'Neptune'], dtype='<U32')
array([0.])
array(['Central Body', 'Massive Body', 'Massive Body', 'Massive Body',\n", + " 'Massive Body', 'Massive Body', 'Massive Body', 'Massive Body',\n", + " 'Massive Body'], dtype='<U32')
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
array([[3.94769264e+01, 6.55370981e-06, 9.66331340e-05, 1.20026936e-04,\n", + " 1.27398020e-05, 3.76922511e-02, 1.12858998e-02, 1.72365895e-03,\n", + " 2.03361005e-03]])
array([[4.65046726e-03, 1.63063818e-05, 4.04537843e-05, 4.25875607e-05,\n", + " 2.26574081e-05, 4.67326170e-04, 3.89256877e-04, 1.69534499e-04,\n", + " 1.64587904e-04]])
array([[4.75358069e-12, nan, nan, nan,\n", + " nan, nan, nan, nan,\n", + " nan]])
array([[-2.2473968e-18, nan, nan, nan,\n", + " nan, nan, nan, nan,\n", + " nan]])
array([[ nan, 0.22527007, 0.64013386, -0.78195044, -1.65001718,\n", + " -4.54078501, 8.901068 , 8.17855335, 29.79419863]])
array([[ nan, 0.22185516, -0.34396282, -0.63468545, -0.02334143,\n", + " 2.86428737, 2.90284887, 17.59478942, 2.04463099]])
array([[ nan, -2.52922505e-03, -4.16625374e-02,\n", + " 4.44514635e-05, 3.99643397e-02, 8.96961900e-02,\n", + " -4.04874151e-01, -4.06951825e-02, -7.28719479e-01]])
array([[ nan, -9.24105838, 3.45369085, 3.8578492 , 0.26241127,\n", + " -1.50370126, -0.74393964, -1.31492768, -0.0875473 ]])
array([[ nan, 7.754686 , 6.47714891, -4.90267373, -4.67368878,\n", + " -2.20463162, 1.93168513, 0.5372287 , 1.14922255]])
array([[ nan, 1.48128538e+00, -1.10257596e-01,\n", + " 2.88870085e-04, -1.04392391e-01, 4.28033174e-02,\n", + " -4.02921477e-03, 1.90517453e-02, -2.16786846e-02]])
array([0])
array([8])