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

Commit

Permalink
Merge branch 'Simulation_API_improvements' into debug
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Nov 20, 2022
2 parents 83de0fe + c7b7ecb commit 3550bbb
Show file tree
Hide file tree
Showing 17 changed files with 1,745 additions and 162 deletions.
1,451 changes: 1,434 additions & 17 deletions examples/Basic_Simulation/initial_conditions.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/Basic_Simulation/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from numpy.random import default_rng

# Initialize the simulation object as a variable
sim = swiftest.Simulation(tstart=0.0, tstop=1.0e6, dt=0.005, tstep_out=1.0e3, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)
sim = swiftest.Simulation(tstart=0.0, tstop=1.0e3, dt=0.005, tstep_out=1.0e0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)

# 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"])
Expand Down
4 changes: 2 additions & 2 deletions examples/Basic_Simulation/run_from_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import swiftest
sim = swiftest.Simulation()
sim.run(tstop=20.0)
sim = swiftest.Simulation(read_param=True)
sim.run()
66 changes: 59 additions & 7 deletions examples/Basic_Simulation/run_simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "86c845ce-1801-46ca-8a8a-1cabb266e6a6",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"env: OMP_NUM_THREADS=8\n"
]
}
],
"source": [
"import swiftest\n",
"import xarray as xr\n",
Expand All @@ -16,22 +24,66 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "d716c371-8eb4-4fc1-82af-8b5c444c831e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading Swiftest file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/simdata/param.in\n"
]
}
],
"source": [
"sim = swiftest.Simulation()"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "ec7452d6-4c9b-4df3-acc0-b11c32264b91",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing parameter inputs to file /home/daminton/git_debug/swiftest/examples/Basic_Simulation/simdata/param.in\n",
"Running a Swiftest symba run from tstart=0.0 y to tstop=1000.0 y\n",
"\u001b]2;cd /home/daminton/git_debug/swiftest/examples/Basic_Simulation/simdata\u0007\u001b]1;\u0007\u001b]2;/home/daminton/git_debug/swiftest/bin/swiftest_driver symba \u0007\u001b]1;\u0007 Parameter input file is /home/daminton/git_debug/swiftest/examples/Basic_Simulation/simdata/param.in\n",
"\n",
" \n",
"\n",
" OpenMP parameters:\n",
"\n",
" ------------------\n",
"\n",
" Number of threads = 8\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"[======/ ] Time = 6.50000E+01 of 1.00000E+03\r"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_62265/187458869.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msim\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/git_debug/swiftest/python/swiftest/swiftest/simulation_class.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 404\u001b[0m \u001b[0menv\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0menv\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 405\u001b[0m universal_newlines=True) as p:\n\u001b[0;32m--> 406\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mline\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstdout\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 407\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m'['\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mline\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 408\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mline\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreplace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'\\n'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'\\r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mend\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m''\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"sim.run(tstop=10.0)"
"sim.run()"
]
},
{
Expand Down
37 changes: 37 additions & 0 deletions examples/Basic_Simulation/simdata/param.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
! VERSION Swiftest input file
T0 0.0
TSTART 0.0
TSTOP 1000.0
DT 0.005
ISTEP_OUT 200
ISTEP_DUMP 200
NC_IN init_cond.nc
IN_TYPE NETCDF_DOUBLE
IN_FORM EL
BIN_OUT bin.nc
OUT_FORM XVEL
OUT_TYPE NETCDF_DOUBLE
OUT_STAT REPLACE
CHK_QMIN 0.004650467260962157
CHK_RMIN 0.004650467260962157
CHK_RMAX 10000.0
CHK_EJECT 10000.0
CHK_QMIN_COORD HELIO
CHK_QMIN_RANGE 0.004650467260962157 10000.0
MU2KG 1.988409870698051e+30
TU2S 31557600.0
DU2M 149597870700.0
GMTINY 9.869231602224408e-07
FRAGMENTATION YES
MIN_GMFRAG 9.869231602224408e-10
RESTART NO
CHK_CLOSE YES
GR YES
ROTATION YES
ENERGY NO
EXTRA_FORCE NO
BIG_DISCARD NO
RHILL_PRESENT NO
INTERACTION_LOOPS TRIANGULAR
ENCOUNTER_CHECK TRIANGULAR
TIDES NO
35 changes: 35 additions & 0 deletions examples/helio_gr_test/grsim/param.gr.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
! VERSION Swiftest input file
T0 0.0
TSTART 0.0
TSTOP 1000.0
DT 0.005
ISTEP_OUT 2000
ISTEP_DUMP 2000
NC_IN init_cond.nc
IN_TYPE NETCDF_DOUBLE
IN_FORM EL
BIN_OUT bin.gr.nc
OUT_FORM XVEL
OUT_TYPE NETCDF_DOUBLE
OUT_STAT REPLACE
CHK_QMIN 0.004650467260962157
CHK_RMIN 0.004650467260962157
CHK_RMAX 10000.0
CHK_EJECT 10000.0
CHK_QMIN_COORD HELIO
CHK_QMIN_RANGE 0.004650467260962157 10000.0
MU2KG 1.988409870698051e+30
TU2S 31557600.0
DU2M 149597870700.0
FRAGMENTATION NO
RESTART NO
CHK_CLOSE YES
GR YES
ROTATION NO
ENERGY NO
EXTRA_FORCE NO
BIG_DISCARD NO
RHILL_PRESENT NO
INTERACTION_LOOPS TRIANGULAR
ENCOUNTER_CHECK TRIANGULAR
TIDES NO
35 changes: 35 additions & 0 deletions examples/helio_gr_test/nogrsim/param.nogr.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
! VERSION Swiftest input file
T0 0.0
TSTART 0.0
TSTOP 1000.0
DT 0.005
ISTEP_OUT 2000
ISTEP_DUMP 2000
NC_IN init_cond.nc
IN_TYPE NETCDF_DOUBLE
IN_FORM EL
BIN_OUT bin.nogr.nc
OUT_FORM XVEL
OUT_TYPE NETCDF_DOUBLE
OUT_STAT REPLACE
CHK_QMIN 0.004650467260962157
CHK_RMIN 0.004650467260962157
CHK_RMAX 10000.0
CHK_EJECT 10000.0
CHK_QMIN_COORD HELIO
CHK_QMIN_RANGE 0.004650467260962157 10000.0
MU2KG 1.988409870698051e+30
TU2S 31557600.0
DU2M 149597870700.0
FRAGMENTATION NO
RESTART NO
CHK_CLOSE YES
GR NO
ROTATION NO
ENERGY NO
EXTRA_FORCE NO
BIG_DISCARD NO
RHILL_PRESENT NO
INTERACTION_LOOPS TRIANGULAR
ENCOUNTER_CHECK TRIANGULAR
TIDES NO
13 changes: 2 additions & 11 deletions examples/helio_gr_test/swiftest_relativity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim_gr = swiftest.Simulation(param_file=\"param.gr.in\", output_file_name=\"bin.gr.nc\")\n",
"sim_gr = swiftest.Simulation(param_file=\"grsim/param.gr.in\", output_file_name=\"bin.gr.nc\")\n",
"sim_gr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])"
]
},
Expand All @@ -29,7 +29,7 @@
"metadata": {},
"outputs": [],
"source": [
"sim_nogr = swiftest.Simulation(param_file=\"param.nogr.in\", output_file_name=\"bin.nogr.nc\")\n",
"sim_nogr = swiftest.Simulation(param_file=\"nogrsim/param.nogr.in\", output_file_name=\"bin.nogr.nc\")\n",
"sim_nogr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])"
]
},
Expand All @@ -39,7 +39,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"tstep_out = 10.0\n",
"sim_gr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator=\"helio\",general_relativity=True)"
]
Expand All @@ -50,7 +49,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"sim_nogr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator=\"helio\",general_relativity=False)"
]
},
Expand Down Expand Up @@ -138,13 +136,6 @@
"print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion python/swiftest/swiftest/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import astropy.constants as const

# Constants in SI units
GC = const.G.value
GC = const.G.value[()]
AU2M = const.au.value
GMSun = const.GM_sun.value
MSun = const.M_sun.value
Expand Down
3 changes: 2 additions & 1 deletion python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def read_swiftest_param(param_file_name, param, verbose=True):
for f in float_param:
if f in param and type(f) is str:
param[f] = real2float(param[f])

for b in bool_param:
if b in param:
param[b] = str2bool(param[b])
Expand Down Expand Up @@ -427,7 +428,7 @@ def write_labeled_param(param, param_file_name):
'TU2S',
'DU2M',
'GMTINY',
'FRAGMENTATION'
'FRAGMENTATION',
'MIN_GMFRAG',
'RESTART']
ptmp = param.copy()
Expand Down
Loading

0 comments on commit 3550bbb

Please sign in to comment.