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

Commit

Permalink
Merge branch 'debug'
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jan 15, 2023
2 parents 58723d5 + 324e47c commit a70c3df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
50 changes: 22 additions & 28 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 @@ -387,14 +378,7 @@ def _run_swiftest_driver(self):
# Get current environment variables

env = os.environ.copy()
driver_script = os.path.join(self.binary_path, "swiftest_driver.sh")
with open(driver_script, 'w') as f:
f.write(f"#{self._shell_full} -l\n")
f.write(f"source ~/.{self._shell}rc\n")
f.write(f"cd {self.simdir}\n")
f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n")

cmd = f"{env['SHELL']} -l {driver_script}"
cmd = f"{env['SHELL']} -l {self.driver_script}"

def _type_scrub(output_data):
int_vars = ["ILOOP","NPL","NTP","NPLM"]
Expand Down Expand Up @@ -494,7 +478,7 @@ def run(self,**kwargs):
warnings.warn(msg,stacklevel=2)
return
else:
shutil.copy(self.binary_source, self.driver_executable)
shutil.copy2(self.binary_source, self.driver_executable)

if not self.restart:
self.clean()
Expand Down Expand Up @@ -794,13 +778,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 +1229,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 +2572,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 +2646,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,11 +2658,20 @@ 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)

# Generate executable script
self.driver_script = os.path.join(self.simdir, "swiftest_driver.sh")
with open(self.driver_script, 'w') as f:
f.write(f"#{self._shell_full}\n")
f.write(f"source ~/.{self._shell}rc\n")
f.write(f"cd {self.simdir}\n")
f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n")

return

def convert(self, param_file, newcodename="Swiftest", plname="pl.swiftest.in", tpname="tp.swiftest.in",
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 a70c3df

Please sign in to comment.