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'
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Nov 16, 2022
2 parents 53bd4e7 + 51d0e28 commit 47423d6
Show file tree
Hide file tree
Showing 14 changed files with 3,349 additions and 881 deletions.
9 changes: 0 additions & 9 deletions examples/Basic_Simulation/cb.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
!! 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.

Sun
39.476926408897626
0.004650467260962157
Expand Down
94 changes: 19 additions & 75 deletions examples/Basic_Simulation/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,111 +15,55 @@
Returns
-------
param.in : ASCII text file
Swiftest parameter input file.
pl.in : ASCII text file
Swiftest massive body input file.
tp.in : ASCII text file
Swiftest test particle input file.
cb.in : ASCII text file
Swiftest central body input file.
Updates sim.data with the simulation data
"""

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

# Initialize the simulation object as a variable
sim = swiftest.Simulation()

# Add parameter attributes to the simulation object
sim.param['T0'] = 0.0
sim.param['TSTOP'] = 10
sim.param['DT'] = 0.005
sim.param['ISTEP_OUT'] = 200
sim.param['ISTEP_DUMP'] = 200
sim.param['OUT_FORM'] = 'XVEL'
sim.param['OUT_TYPE'] = 'NETCDF_DOUBLE'
sim.param['OUT_STAT'] = 'REPLACE'
sim.param['IN_FORM'] = 'EL'
sim.param['IN_TYPE'] = 'ASCII'
sim.param['PL_IN'] = 'pl.in'
sim.param['TP_IN'] = 'tp.in'
sim.param['CB_IN'] = 'cb.in'
sim.param['BIN_OUT'] = 'out.nc'
sim.param['CHK_QMIN'] = swiftest.RSun / swiftest.AU2M
sim.param['CHK_RMIN'] = swiftest.RSun / swiftest.AU2M
sim.param['CHK_RMAX'] = 1000.0
sim.param['CHK_EJECT'] = 1000.0
sim.param['CHK_QMIN_COORD'] = 'HELIO'
sim.param['CHK_QMIN_RANGE'] = f'{swiftest.RSun / swiftest.AU2M} 1000.0'
sim.param['MU2KG'] = swiftest.MSun
sim.param['TU2S'] = swiftest.YR2S
sim.param['DU2M'] = swiftest.AU2M
sim.param['EXTRA_FORCE'] = 'NO'
sim.param['BIG_DISCARD'] = 'NO'
sim.param['CHK_CLOSE'] = 'YES'
sim.param['GR'] = 'YES'
sim.param['INTERACTION_LOOPS'] = 'ADAPTIVE'
sim.param['ENCOUNTER_CHECK'] = 'ADAPTIVE'
sim.param['RHILL_PRESENT'] = 'YES'
sim.param['FRAGMENTATION'] = 'YES'
sim.param['ROTATION'] = 'YES'
sim.param['ENERGY'] = 'YES'
sim.param['GMTINY'] = 1e-6
sim.param['MIN_GMFRAG'] = 1e-9

# Set gravitational units of the system
GU = swiftest.GC / (sim.param['DU2M'] ** 3 / (sim.param['MU2KG'] * sim.param['TU2S'] ** 2))
sim = swiftest.Simulation(tstart=0.0, tstop=10.0, dt=0.005, tstep_out=1.0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)
sim.get_parameter()

# Add the modern planets and the Sun using the JPL Horizons Database
sim.add("Sun", idval=0, date="2022-08-08")
sim.add("Mercury", idval=1, date="2022-08-08")
sim.add("Venus", idval=2, date="2022-08-08")
sim.add("Earth", idval=3, date="2022-08-08")
sim.add("Mars", idval=4, date="2022-08-08")
sim.add("Jupiter", idval=5, date="2022-08-08")
sim.add("Saturn", idval=6, date="2022-08-08")
sim.add("Uranus", idval=7, date="2022-08-08")
sim.add("Neptune", idval=8, date="2022-08-08")
sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"])

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

id_pl = np.array([9, 10, 11, 12, 13])
name_pl = np.array(["MassiveBody_01", "MassiveBody_02", "MassiveBody_03", "MassiveBody_04", "MassiveBody_05"])
name_pl = ["MassiveBody_01", "MassiveBody_02", "MassiveBody_03", "MassiveBody_04", "MassiveBody_05"]
a_pl = default_rng().uniform(0.3, 1.5, npl)
e_pl = default_rng().uniform(0.0, 0.3, npl)
inc_pl = default_rng().uniform(0.0, 90, npl)
capom_pl = default_rng().uniform(0.0, 360.0, npl)
omega_pl = default_rng().uniform(0.0, 360.0, npl)
capm_pl = default_rng().uniform(0.0, 360.0, npl)
GM_pl = (np.array([6e23, 8e23, 1e24, 3e24, 5e24]) / sim.param['MU2KG']) * GU
R_pl = np.full(npl, (3 * (GM_pl / GU) / (4 * np.pi * density_pl)) ** (1.0 / 3.0))
Rh_pl = a_pl * ((GM_pl) / (3 * GU)) ** (1.0 / 3.0)
Ip1_pl = np.array([0.4, 0.4, 0.4, 0.4, 0.4])
Ip2_pl = np.array([0.4, 0.4, 0.4, 0.4, 0.4])
Ip3_pl = np.array([0.4, 0.4, 0.4, 0.4, 0.4])
rotx_pl = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
roty_pl = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
rotz_pl = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
GM_pl = (np.array([6e23, 8e23, 1e24, 3e24, 5e24]) / sim.param['MU2KG']) * sim.GU
R_pl = np.full(npl, (3 * (GM_pl / sim.GU) / (4 * np.pi * density_pl)) ** (1.0 / 3.0))
Rh_pl = a_pl * ((GM_pl) / (3 * sim.GU)) ** (1.0 / 3.0)
Ip1_pl = [0.4, 0.4, 0.4, 0.4, 0.4]
Ip2_pl = [0.4, 0.4, 0.4, 0.4, 0.4]
Ip3_pl = [0.4, 0.4, 0.4, 0.4, 0.4]
rotx_pl = [0.0, 0.0, 0.0, 0.0, 0.0]
roty_pl = [0.0, 0.0, 0.0, 0.0, 0.0]
rotz_pl = [0.0, 0.0, 0.0, 0.0, 0.0]

sim.addp(id_pl, name_pl, a_pl, e_pl, inc_pl, capom_pl, omega_pl, capm_pl, GMpl=GM_pl, Rpl=R_pl, rhill=Rh_pl, Ip1=Ip1_pl, Ip2=Ip2_pl, Ip3=Ip3_pl, rotx=rotx_pl, roty=roty_pl, rotz=rotz_pl)
sim.add_body(name_pl, a_pl, e_pl, inc_pl, capom_pl, omega_pl, capm_pl, GMpl=GM_pl, Rpl=R_pl, rhill=Rh_pl, Ip1=Ip1_pl, Ip2=Ip2_pl, Ip3=Ip3_pl, rotx=rotx_pl, roty=roty_pl, rotz=rotz_pl)

# Add 10 user-defined test particles
ntp = 10

id_tp = np.array([14, 15, 16, 17, 18, 19, 20, 21, 22, 23])
name_tp = np.array(["TestParticle_01", "TestParticle_02", "TestParticle_03", "TestParticle_04", "TestParticle_05", "TestParticle_06", "TestParticle_07", "TestParticle_08", "TestParticle_09", "TestParticle_10"])
name_tp = ["TestParticle_01", "TestParticle_02", "TestParticle_03", "TestParticle_04", "TestParticle_05", "TestParticle_06", "TestParticle_07", "TestParticle_08", "TestParticle_09", "TestParticle_10"]
a_tp = default_rng().uniform(0.3, 1.5, ntp)
e_tp = default_rng().uniform(0.0, 0.3, ntp)
inc_tp = default_rng().uniform(0.0, 90, ntp)
capom_tp = default_rng().uniform(0.0, 360.0, ntp)
omega_tp = default_rng().uniform(0.0, 360.0, ntp)
capm_tp = default_rng().uniform(0.0, 360.0, ntp)

sim.addp(id_tp, name_tp, a_tp, e_tp, inc_tp, capom_tp, omega_tp, capm_tp)
sim.add_body(name_tp, a_tp, e_tp, inc_tp, capom_tp, omega_tp, capm_tp)

# Save everything to a set of initial conditions files
sim.save('param.in')
# Run the simulation
sim.run()
49 changes: 20 additions & 29 deletions examples/Basic_Simulation/param.in
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
!! 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.

! VERSION Swiftest parameter input
! VERSION Swiftest input file
T0 0.0
TSTOP 10
TSTART 0.0
TSTOP 10.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
IN_TYPE ASCII
PL_IN pl.in
TP_IN tp.in
CB_IN cb.in
BIN_OUT out.nc
CHK_QMIN 0.004650467260962157
CHK_RMIN 0.004650467260962157
CHK_RMAX 1000.0
CHK_EJECT 1000.0
CHK_RMAX 10000.0
CHK_EJECT 10000.0
CHK_QMIN_COORD HELIO
CHK_QMIN_RANGE 0.004650467260962157 1000.0
CHK_QMIN_RANGE 0.004650467260962157 10000.0
MU2KG 1.988409870698051e+30
TU2S 31557600.0
DU2M 149597870700.0
IN_FORM EL
EXTRA_FORCE NO
BIG_DISCARD NO
GMTINY 9.869231602224408e-07
RESTART NO
CHK_CLOSE YES
RHILL_PRESENT YES
GR YES
FRAGMENTATION YES
ROTATION YES
ENERGY NO
EXTRA_FORCE NO
BIG_DISCARD NO
RHILL_PRESENT NO
INTERACTION_LOOPS TRIANGULAR
ENCOUNTER_CHECK TRIANGULAR
TIDES NO
ENERGY YES
GR YES
INTERACTION_LOOPS ADAPTIVE
ENCOUNTER_CHECK ADAPTIVE
GMTINY 1e-06
MIN_GMFRAG 1e-09
MIN_GMFRAG 9.869231602224408e-10
163 changes: 80 additions & 83 deletions examples/Basic_Simulation/pl.in
Original file line number Diff line number Diff line change
@@ -1,88 +1,85 @@
!! 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.

13
Mercury 6.553709809565314146e-06 0.0014751262621647182575
1.6306381826061645943e-05
0.38709864823618972407 0.20562513690973019398 7.0036250456070128223
48.30204974520415817 29.18823342267911869 114.9720047697775982
0.0 0.0 0.34599999999999997424
3.5734889863322150192 -18.38008501876561206 34.361513668512199956
Venus 9.6633133995815381836e-05 0.006759085242739840662
4.0453784346544178454e-05
0.72332603580811538624 0.0067486079191121668003 3.394406261149808035
76.61738837179606776 54.777760273590551776 315.37095689555837907
0.0 0.0 0.4000000000000000222
0.17650282045605921225 -3.6612475825356215592 8.702866268072763821
Earth 0.000120026935827952456416 0.010044668314295209318
4.25875607065040958e-05
0.9999943732711822353 0.016707309394717231171 0.0028984767436730000077
174.05498211951208987 289.04709044403989537 213.07530468023790604
0.0 0.0 0.33069999999999999396
5.002093202481912218 0.055213529850334066125 2301.2110537292529557
Mars 1.2739802010675941808e-05 0.007246950762048707243
2.265740805092889601e-05
1.5237812078483019551 0.0935087708803710449 1.8479353068000929916
49.489305419773351957 286.70300191753761965 24.878418068365981242
0.0 0.0 0.3644000000000000017
997.9357048213454125 -909.4072592492943007 1783.4501726537997323
Jupiter 0.03769225108898567778 0.3552222491747608486
0.00046732617030490929307
5.2028063728088866924 0.048395118271449058533 1.3035670146561249005
100.516498130230701236 273.44233262595901124 346.26538105843917492
0.0 0.0 0.27560000000000001164
-80.96619889339111482 -2388.0060524649362916 5008.7314931237953832
Saturn 0.01128589982009127331 0.43757948578866074266
0.00038925687730393611812
9.580020069168169172 0.053193613750490406633 2.4864365613724639381
113.597044717589099605 335.10179422401358806 237.66485199561481068
0.0 0.0 0.22000000000000000111
441.93538182505989814 378.5284220382117538 5135.9110455622733884
Uranus 0.001723658947826773068 0.4705353566089944894
0.00016953449859497231466
19.272143108769419939 0.043779687288749750962 0.7707536154556786645
74.077748995180698444 93.42271392662131291 242.37685081109759722
0.0 0.0 0.23000000000000000999
-677.3000258209181323 -3008.109907190578637 -836.301326618569835
Neptune 0.0020336100526728302882 0.78184929587893868845
0.000164587904124493665
30.305539399096510067 0.014544938874222059638 1.7686697746048700708
131.73604731224671127 249.9779420269553043 332.54824537252648042
0.0 0.0 0.23000000000000000999
1231.1804455066093229 -2178.0887091151860042 2329.6411363603121418
MassiveBody_01 1.1912109366578087428e-05 0.0016092923734511708263
2.425055692051244981e-05
0.3460404950890429432 0.2093906512182220625 0.11109012870384793459
114.31328763688792094 347.82259114762894114 96.0534391561842682
0.4000000000000000222 0.4000000000000000222 0.4000000000000000222
14
Mercury 6.553709809565314e-06
1.6306381826061646e-05
0.3870985843095394 0.2056234010897001 7.003302508001384
48.29611837378607 29.20442403952454 338.3394874682879
0.0 0.0 0.346
3.573018077015318 -18.380317085416586 34.36143850429876
Venus 9.663313399581537e-05
4.0453784346544176e-05
0.7233297579736101 0.006717605698865438 3.394439273342282
76.60235891771119 54.96037946082961 200.4789339550648
0.0 0.0 0.4
0.17650282045605922 -3.6612475825356214 8.702866268072764
Earth 0.00012002693582795245
4.25875607065041e-05
0.9999904874543223 0.01671400376545858 0.003637862608863003
175.025172600231 287.9619628812575 114.3482934042427
0.0 0.0 0.3307
6.157239621449141 0.057224133705898524 2301.2082528350797
Mars 1.2739802010675942e-05
2.2657408050928896e-05
1.523711925589535 0.09344151133508208 1.847441673557901
49.4728572124747 286.7379771285891 209.3396773477138
0.0 0.0 0.3644
997.9224351226384 -909.5549030011778 1783.3823046046184
Jupiter 0.037692251088985676
0.0004673261703049093
5.2027278008516 0.04824497711637968 1.303631134570075
100.5192588433081 273.5898402882514 129.5536700659942
0.0 0.0 0.2756
-80.9864396731672 -2388.0246092955053 5008.722318533006
Saturn 0.011285899820091273
0.00038925687730393614
9.532011952667288 0.05486329870433341 2.487906363280301
113.6305781676206 339.5467356402391 290.8995806568904
0.0 0.0 0.22
441.95954822014636 378.52638822638795 5135.909115928892
Uranus 0.001723658947826773
0.00016953449859497232
19.24498838290236 0.04796174942301296 0.7730102596086205
74.0125809801658 93.59554912280227 262.8658637277515
0.0 0.0 0.23
-677.3000258209181 -3008.1099071905787 -836.3013266185699
Neptune 0.0020336100526728304
0.00016458790412449367
30.03895991152209 0.008955570138096731 1.771119354296142
131.8221159748827 284.4748429674216 308.4513720536233
0.0 0.0 0.23
1232.224106980634 -2177.3040821077648 2329.8227878119233
Pluto 2.924216771029454e-07
7.943294877391593e-06
39.36791814672583 0.2487178537481577 17.1705505990969
110.3314332962701 113.0826635900664 55.11416408345664
0.0 0.0 0.4
-243.59404988903637 261.28663002814227 -38.57352022187049
MassiveBody_01 1.1912109366578089e-05
2.425055692051245e-05
0.7452368716298337 0.0633011418780484 0.11151363780595558
203.01823417718037 284.9353898127118 266.79344592519305
0.4 0.4 0.4
0.0 0.0 0.0
MassiveBody_02 1.5882812488770779849e-05 0.0016802531895603555184
2.6691191565570073646e-05
0.32826188156947710972 0.27866488696288682636 77.21223337306255985
251.99014895640269174 53.772702227560969845 165.6085387284213084
0.4000000000000000222 0.4000000000000000222 0.4000000000000000222
MassiveBody_02 1.5882812488770783e-05
2.6691191565570074e-05
0.7671203280602826 0.10149029388964753 53.46706656938751
61.74738152068808 68.20565593722856 271.3352706902475
0.4 0.4 0.4
0.0 0.0 0.0
MassiveBody_03 1.9853515610963475658e-05 0.004324919007577881884
2.8752214513575297366e-05
0.7843689028022314824 0.06176128116947356833 78.74144231136708072
286.63765100951468412 347.55933571120488068 266.36960496595537506
0.4000000000000000222 0.4000000000000000222 0.4000000000000000222
MassiveBody_03 1.985351561096348e-05
2.8752214513575297e-05
1.4698824276418418 0.13621250684495437 23.635498327264845
38.071905339231236 283.134612455057 250.67457601578352
0.4 0.4 0.4
0.0 0.0 0.0
MassiveBody_04 5.9560546832890430362e-05 0.0056765613035874530265
4.146786902759040254e-05
0.7138176832994267418 0.28016098557400787028 22.725690778108500467
203.41845532080247949 219.74297850728484605 14.730732982803269593
0.4000000000000000222 0.4000000000000000222 0.4000000000000000222
MassiveBody_04 5.9560546832890444e-05
4.14678690275904e-05
0.9741731590760117 0.1519713326893784 20.51335588582416
350.53780805624825 304.05941264938997 142.62713592644738
0.4 0.4 0.4
0.0 0.0 0.0
MassiveBody_05 9.9267578054817388455e-05 0.010382929139161686458
4.916559523190238318e-05
1.101215402063684401 0.076651567404004070094 52.41961577462824806
142.90070862650665617 293.70542448390904156 318.5666754758643151
0.4000000000000000222 0.4000000000000000222 0.4000000000000000222
MassiveBody_05 9.926757805481742e-05
4.916559523190238e-05
0.6633500122731075 0.13550930562584215 10.680323453316653
328.45970148163457 49.93948991697533 316.2109831817007
0.4 0.4 0.4
0.0 0.0 0.0
3 changes: 3 additions & 0 deletions examples/Basic_Simulation/run_from_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import swiftest
sim = swiftest.Simulation()
sim.run(tstop=20.0)
Loading

0 comments on commit 47423d6

Please sign in to comment.