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

Commit

Permalink
Fixed issues saving param.in and initial conditions files to the prop…
Browse files Browse the repository at this point in the history
…er place when simdir changes. Also some typos
  • Loading branch information
daminton committed Jan 15, 2023
1 parent d0b1075 commit d49a2e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
30 changes: 11 additions & 19 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,26 +313,17 @@ def __init__(self,read_param: bool = False, read_old_output: bool = False, simdi
self._getter_column_width = self._swiftest_configuration['getter_column_width']
self._shell = Path(self._swiftest_configuration['shell'])
self._shell_full = Path(self._swiftest_configuration['shell_full'])
self.verbose = kwargs.pop("verbose",True)

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

self.simdir = Path(simdir)
if self.simdir.exists():
if not self.simdir.is_dir():
msg = f"Cannot create the {self.simdir.resolve()} directory: File exists."
msg += "\nDelete the file or change the location of param_file"
raise NotADirectoryError(msg)
else:
if read_old_output or read_param:
raise NotADirectoryError(f"Cannot find directory {self.simdir.resolve()} ")

# Set the location of the parameter input file, choosing the default if it isn't specified.
param_file = kwargs.pop("param_file",Path.cwd() / self.simdir / "param.in")
self.verbose = kwargs.pop("verbose",True)
self.simdir = Path.cwd() / Path(simdir)
param_file = Path(kwargs.pop("param_file", "param.in"))

# Parameters are set in reverse priority order. First the defaults, then values from a pre-existing input file,
# then using the arguments passed via **kwargs.
Expand Down Expand Up @@ -794,13 +785,13 @@ def set_parameter(self, verbose: bool = True, **kwargs):
"encounter_check_loops": "TRIANGULAR",
"ephemeris_date": "MBCL",
"restart": False,
"encounter_save" : "NONE"
"encounter_save" : "NONE",
"simdir" : self.simdir
}
param_file = kwargs.pop("param_file",None)

# Extract the simulation directory and create it if it doesn't exist
if param_file is not None:
self.param_file = Path.cwd() / param_file
self.param_file = param_file

# If no arguments (other than, possibly, verbose) are requested, use defaults
if len(kwargs) == 0:
Expand Down Expand Up @@ -1245,6 +1236,7 @@ def set_feature(self,
raise NotADirectoryError(msg)
self.binary_path = self.simdir.resolve()
self.driver_executable = self.binary_path / "swiftest_driver"
self.param_file = Path(kwargs.pop("param_file","param.in"))

self.param["TIDES"] = False

Expand Down Expand Up @@ -2587,7 +2579,7 @@ def read_param(self,
True if the parameter file exists and is read correctly. False otherwise.
"""
if param_file is None:
param_file = self.param_file
param_file = self.simdir / self.param_file
if read_init_cond is None:
read_init_cond = True
if codename is None:
Expand Down Expand Up @@ -2661,7 +2653,7 @@ def write_param(self,
verbose = self.verbose

if verbose:
print(f"Writing parameter inputs to file {param_file}")
print(f"Writing parameter inputs to file {str(self.simdir / param_file)}")
param['! VERSION'] = f"{codename} input file"

self.simdir.mkdir(parents=True, exist_ok=True)
Expand All @@ -2673,9 +2665,9 @@ def write_param(self,
param.pop("CB_IN", None)
param.pop("PL_IN", None)
param.pop("TP_IN", None)
io.write_labeled_param(param, param_file)
io.write_labeled_param(param, self.simdir / param_file)
elif codename == "Swift":
io.write_swift_param(param, param_file)
io.write_swift_param(param, self.simdir / param_file)
else:
warnings.warn('Cannot process unknown code type. Call the read_param method with a valid code name. Valid options are "Swiftest", "Swifter", or "Swift".',stacklevel=2)
return
Expand Down
2 changes: 1 addition & 1 deletion src/collision/collision_regime.f90
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ end function calc_b
function calc_c_star(Rc1) result(c_star)
!! author: David A. Minton
!!
!! Calculates c_star as a function of impact equivalent radius. It inteRpolates between 5 for ~1 km sized bodies to
!! Calculates c_star as a function of impact equivalent radius. It interpolates between 5 for ~1 km sized bodies to
!! 1.8 for ~10000 km sized bodies. See LS12 Fig. 4 for details.
!!
implicit none
Expand Down

0 comments on commit d49a2e9

Please sign in to comment.