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

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 1, 2022
1 parent 5827b34 commit 43f84b3
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False,
# If the user asks to read in an old parameter file or output file, override any default parameters with values from the file
# If the file doesn't exist, flag it for now so we know to create it
if read_param or read_old_output_file:
#good_param is self.read_param()
if self.read_param():

if self.read_param(read_init_cond = not read_old_output_file):
# We will add the parameter file to the kwarg list. This will keep the set_parameter method from
# overriding everything with defaults when there are no arguments passed to Simulation()
kwargs['param_file'] = self.param_file
Expand Down Expand Up @@ -2556,16 +2556,19 @@ def get_nvals(ds):
def read_param(self,
param_file : os.PathLike | str | None = None,
codename: Literal["Swiftest", "Swifter", "Swift"] | None = None,
read_init_cond : Bool | None = None,
verbose: bool | None = None):
"""
Reads in an input parameter file and stores the values in the param dictionary.
Parameters
----------
param_file : str or path-like, default is the value of the Simulation object's internal `param_file`.
File name of the input parameter file
File name of the input parameter file
codename : {"Swiftest", "Swifter", "Swift"}, default is the value of the Simulation object's internal`codename`
Type of parameter file, either "Swift", "Swifter", or "Swiftest"
Type of parameter file, either "Swift", "Swifter", or "Swiftest"
read_init_cond : bool, optional
If true, will read in the initial conditions file into the data instance variable. Default True
verbose : bool, default is the value of the Simulation object's internal `verbose`
If set to True, then more information is printed by Simulation methods as they are executed. Setting to
False suppresses most messages other than errors.
Expand All @@ -2575,7 +2578,8 @@ def read_param(self,
"""
if param_file is None:
param_file = self.param_file

if read_init_cond is None:
read_init_cond = True
if codename is None:
codename = self.codename

Expand All @@ -2587,14 +2591,17 @@ def read_param(self,

if codename == "Swiftest":
self.param = io.read_swiftest_param(param_file, self.param, verbose=verbose)
if "NETCDF" in self.param['IN_TYPE']:
init_cond_file = self.sim_dir / self.param['NC_IN']
if os.path.exists(init_cond_file):
param_tmp = self.param.copy()
param_tmp['BIN_OUT'] = init_cond_file
self.data = io.swiftest2xr(param_tmp, verbose=self.verbose)
else:
warnings.warn(f"Initial conditions file file {init_cond_file} not found.", stacklevel=2)
if read_init_cond:
if "NETCDF" in self.param['IN_TYPE']:
init_cond_file = self.sim_dir / self.param['NC_IN']
if os.path.exists(init_cond_file):
param_tmp = self.param.copy()
param_tmp['BIN_OUT'] = init_cond_file
self.data = io.swiftest2xr(param_tmp, verbose=self.verbose)
else:
warnings.warn(f"Initial conditions file file {init_cond_file} not found.", stacklevel=2)
else:
warnings.warn("Reading in ASCII initial conditions files in Python is not yet supported")
elif codename == "Swifter":
self.param = io.read_swifter_param(param_file, verbose=verbose)
elif codename == "Swift":
Expand Down

0 comments on commit 43f84b3

Please sign in to comment.