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

Commit

Permalink
Lots of refactoring. Changed bin.nc to data.nc. Changed .ic to .init_…
Browse files Browse the repository at this point in the history
…cond. Changed the way encounter and collisions are read in (always read the files in if they exist)
  • Loading branch information
daminton committed Dec 13, 2022
1 parent 52ecbef commit 92f1d8e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/Basic_Simulation/initial_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Output
------
bin.nc : A NetCDF file containing the simulation output.
data.nc : A NetCDF file containing the simulation output.
dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation.
Expand Down
2 changes: 1 addition & 1 deletion examples/Basic_Simulation/output_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Input
------
bin.nc : A NetCDF file containing the simulation output.
data.nc : A NetCDF file containing the simulation output.
Output
------
Expand Down
6 changes: 3 additions & 3 deletions examples/Fragmentation/swiftest_fragmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Output
------
disruption/bin.nc : A NetCDF file containing the simulation output.
disruption/data.nc : A NetCDF file containing the simulation output.
disruption/dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
disruption/dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
disruption/dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation.
Expand All @@ -30,7 +30,7 @@
disruption/init_cond.nc : A NetCDF file containing the initial conditions for the simulation.
disruption/param.in : An ASCII file containing the parameters for the simulation.
disruption/swiftest.log : An ASCII file containing the information on the status of the simulation as it runs.
hitandrun/bin.nc : A NetCDF file containing the simulation output.
hitandrun/data.nc : A NetCDF file containing the simulation output.
hitandrun/dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
hitandrun/dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
hitandrun/dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation.
Expand All @@ -39,7 +39,7 @@
hitandrun/init_cond.nc : A NetCDF file containing the initial conditions for the simulation.
hitandrun/param.in : An ASCII file containing the parameters for the simulation.
hitandrun/swiftest.log : An ASCII file containing the information on the status of the simulation as it runs.
supercat/bin.nc : A NetCDF file containing the simulation output.
supercat/data.nc : A NetCDF file containing the simulation output.
supercat/dump_bin1.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
supercat/dump_bin2.nc : A NetCDF file containing the necessary inputs to restart a simulation from t!=0.
supercat/dump_param1.in : An ASCII file containing the necessary parameters to restart a simulation.
Expand Down
4 changes: 2 additions & 2 deletions examples/helio_gr_test/helio_gr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
helio_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/data.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/data.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.
Expand Down
4 changes: 2 additions & 2 deletions examples/whm_gr_test/whm_gr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
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/data.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/data.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.
Expand Down
47 changes: 23 additions & 24 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def __init__(self,read_param: bool = False, read_old_output: bool = False, simdi
Parameter input file equivalent: `OUT_TYPE`
output_file_name : str or path-like, optional
Name of output file to generate. If not supplied, then one of the default file names are used, depending on
the value passed to `output_file_type`. If one of the NetCDF types are used, the default is "bin.nc".
Otherwise, the default is "bin.dat".
the value passed to `output_file_type`. The default is "data.nc".
Parameter input file equivalent: `BIN_OUT`
output_format : {"XV","XVEL"}, default "XVEL"
Specifies the format for the data saved to the output file. If "XV" then cartesian position and velocity
Expand Down Expand Up @@ -312,7 +311,7 @@ def __init__(self,read_param: bool = False, read_old_output: bool = False, simdi

self.param = {}
self.data = xr.Dataset()
self.ic = xr.Dataset()
self.init_cond = xr.Dataset()
self.encounters = xr.Dataset()
self.collisions = xr.Dataset()

Expand Down Expand Up @@ -1508,7 +1507,7 @@ def set_output_files(self,
* Swift: Only "REAL4" supported.
output_file_name : str or path-like, optional
Name of output file to generate. If not supplied, then one of the default file names are used, depending on
the value passed to `output_file_type`. If one of the NetCDF types are used, the default is "bin.nc".
the value passed to `output_file_type`. If one of the NetCDF types are used, the default is "data.nc".
Otherwise, the default is "bin.dat".
output_format : {"XV","XVEL"}, optional
Specifies the format for the data saved to the output file. If "XV" then cartesian position and velocity
Expand Down Expand Up @@ -1568,7 +1567,7 @@ def set_output_files(self,
self.param['OUT_TYPE'] = output_file_type
if output_file_name is None:
if output_file_type in ["NETCDF_DOUBLE", "NETCDF_FLOAT"]:
self.param['BIN_OUT'] = "bin.nc"
self.param['BIN_OUT'] = "data.nc"
else:
self.param['BIN_OUT'] = "bin.dat"
else:
Expand Down Expand Up @@ -2157,7 +2156,7 @@ def add_solar_system_body(self,
if dsnew['npl'] > 0 or dsnew['ntp'] > 0:
self.save(verbose=False)

self.ic = self.data.copy(deep=True)
self.init_cond = self.data.copy(deep=True)

return

Expand Down Expand Up @@ -2456,7 +2455,7 @@ def input_to_array_3d(val,n=None):

dsnew = self._combine_and_fix_dsnew(dsnew)
self.save(verbose=False)
self.ic = self.data.copy(deep=True)
self.init_cond = self.data.copy(deep=True)

return

Expand Down Expand Up @@ -2563,7 +2562,7 @@ def read_param(self,
param_tmp = self.param.copy()
param_tmp['BIN_OUT'] = init_cond_file
self.data = io.swiftest2xr(param_tmp, verbose=self.verbose)
self.ic = self.data.copy(deep=True)
self.init_cond = self.data.copy(deep=True)
else:
warnings.warn(f"Initial conditions file file {init_cond_file} not found.", stacklevel=2)
else:
Expand Down Expand Up @@ -2706,29 +2705,22 @@ def read_output_file(self,read_init_cond : bool = True):
# This is done to handle cases where the method is called from a different working directory than the simulation
# results

if "ENCOUNTER_SAVE" in self.param:
read_encounters = self.param["ENCOUNTER_SAVE"] != "NONE"
else:
read_encounters = False

param_tmp = self.param.copy()
param_tmp['BIN_OUT'] = os.path.join(self.simdir, self.param['BIN_OUT'])
if self.codename == "Swiftest":
self.data = io.swiftest2xr(param_tmp, verbose=self.verbose)
if self.verbose: print('Swiftest simulation data stored as xarray DataSet .data')
if read_init_cond:
if self.verbose:
print("Reading initial conditions file as .ic")
print("Reading initial conditions file as .init_cond")
if "NETCDF" in self.param['IN_TYPE']:
param_tmp['BIN_OUT'] = self.simdir / self.param['NC_IN']

self.ic = io.swiftest2xr(param_tmp, verbose=self.verbose)
self.init_cond = io.swiftest2xr(param_tmp, verbose=False)
else:
self.ic = self.data.isel(time=0)
if read_encounters:
self.read_encounters()
if read_collisions:
self.read_collisions()
self.init_cond = self.data.isel(time=0)

self.read_encounters()
self.read_collisions()

elif self.codename == "Swifter":
self.data = io.swifter2xr(param_tmp, verbose=self.verbose)
Expand All @@ -2740,9 +2732,13 @@ def read_output_file(self,read_init_cond : bool = True):
return

def read_encounters(self):
enc_files = glob(f"{self.simdir}{os.path.sep}encounter_*.nc")
if len(enc_files) == 0:
return

if self.verbose:
print("Reading encounter history file as .encounters")
enc_files = glob(f"{self.simdir}{os.path.sep}encounter_*.nc")

enc_files.sort()

# This is needed in order to pass the param argument down to the io.process_netcdf_input function
Expand All @@ -2760,10 +2756,13 @@ def _preprocess(ds, param):


def read_collisions(self):
if self.verbose:
print("Reading collision history file as .collisions")
col_files = glob(f"{self.simdir}{os.path.sep}collision_*.nc")
if len(col_files) == 0:
return

col_files.sort()
if self.verbose:
print("Reading collision history file as .collisions")

# This is needed in order to pass the param argument down to the io.process_netcdf_input function
def _preprocess(ds, param):
Expand Down
2 changes: 1 addition & 1 deletion src/modules/swiftest_globals.f90
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module swiftest_globals
character(*), parameter :: PL_INFILE = 'pl.in'
character(*), parameter :: TP_INFILE = 'tp.in'
character(*), parameter :: NC_INFILE = 'in.nc'
character(*), parameter :: BIN_OUTFILE = 'bin.nc'
character(*), parameter :: BIN_OUTFILE = 'data.nc'
integer(I4B), parameter :: BINUNIT = 20 !! File unit number for the binary output file
integer(I4B), parameter :: PARTICLEUNIT = 44 !! File unit number for the binary particle info output file
integer(I4B), parameter :: LUN = 42 !! File unit number for files that are opened and closed within a single subroutine call, and therefore should not collide
Expand Down

0 comments on commit 92f1d8e

Please sign in to comment.