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

Commit

Permalink
Browse files Browse the repository at this point in the history
Restructured the Simulation class to accept argument-based parameters. In the new structure, the param dictionary values are set internally by what arguments are passed. This allows for arguments to be sanitized and checked for consistency and compatibility in a more robust way.
  • Loading branch information
daminton committed Nov 8, 2022
1 parent 810f481 commit 585629d
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 138 deletions.
39 changes: 4 additions & 35 deletions examples/Basic_Simulation/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,17 @@
from numpy.random import default_rng

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

# 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))

# 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")
Expand All @@ -95,9 +64,9 @@
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)
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 = 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])
Expand Down
3 changes: 0 additions & 3 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ def read_swiftest_param(param_file_name, param, verbose=True):
param['CHK_CLOSE'] = param['CHK_CLOSE'].upper()
param['RHILL_PRESENT'] = param['RHILL_PRESENT'].upper()
param['FRAGMENTATION'] = param['FRAGMENTATION'].upper()
if param['FRAGMENTATION'] == 'YES' and param['PARTICLE_OUT'] == '':
if param['OUT_TYPE'] == 'REAL8' or param['OUT_TYPE'] == 'REAL4':
param['PARTICLE_OUT'] = 'particle.dat'
param['ROTATION'] = param['ROTATION'].upper()
param['TIDES'] = param['TIDES'].upper()
param['ENERGY'] = param['ENERGY'].upper()
Expand Down
Loading

0 comments on commit 585629d

Please sign in to comment.