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

Commit

Permalink
Merge remote-tracking branch 'origin/Simulation_API_improvements' int…
Browse files Browse the repository at this point in the history
…o debug
  • Loading branch information
daminton committed Nov 21, 2022
2 parents a2cdc04 + c4424c5 commit bd77020
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ def select_active_from_frame(ds, param, framenum=-1):

return frame

def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,framenum=-1):
def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,framenum=-1,verbose=True):
"""
Writes a set of Swiftest input files from a single frame of a Swiftest xarray dataset
Expand Down Expand Up @@ -1101,7 +1101,8 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram
if infile_name is None:
infile_name = param['NC_IN']
frame = unclean_string_values(frame)
print(f"Writing initial conditions to file {infile_name}")
if verbose:
print(f"Writing initial conditions to file {infile_name}")
frame.to_netcdf(path=infile_name)
return frame

Expand Down
25 changes: 19 additions & 6 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,7 @@ def add_solar_system_body(self,
J2=J2, J4=J4, t=t)

dsnew = self._combine_and_fix_dsnew(dsnew)
self.save()
self.save(verbose=False)

return dsnew

Expand Down Expand Up @@ -2352,7 +2352,7 @@ def input_to_array(val,t,n=None):
J2=J2, J4=J4,t=t)

dsnew = self._combine_and_fix_dsnew(dsnew)
self.save()
self.save(verbose=False)

return dsnew

Expand Down Expand Up @@ -2483,7 +2483,14 @@ def write_param(self,
param_file = self.param_file
if param is None:
param = self.param
print(f"Writing parameter inputs to file {param_file}")

if "verbose" in kwargs:
verbose = kwargs['verbose']
else:
verbose = self.verbose

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

# Check to see if the parameter type matches the output type. If not, we need to convert
Expand Down Expand Up @@ -2649,6 +2656,12 @@ def save(self,
-------
None
"""

if "verbose" in kwargs:
verbose = kwargs['verbose']
else:
verbose = self%verbose

if codename is None:
codename = self.codename
if param_file is None:
Expand All @@ -2658,15 +2671,15 @@ def save(self,

if codename == "Swiftest":
infile_name = Path(self.sim_dir) / param['NC_IN']
io.swiftest_xr2infile(ds=self.data, param=param, in_type=self.param['IN_TYPE'], infile_name=infile_name, framenum=framenum)
self.write_param(param_file=param_file)
io.swiftest_xr2infile(ds=self.data, param=param, in_type=self.param['IN_TYPE'], infile_name=infile_name, framenum=framenum, verbose=verbose)
self.write_param(param_file=param_file,**kwargs)
elif codename == "Swifter":
if codename == "Swiftest":
swifter_param = io.swiftest2swifter_param(param)
else:
swifter_param = param
io.swifter_xr2infile(self.data, swifter_param, framenum)
self.write_param(param_file, param=swifter_param)
self.write_param(param_file, param=swifter_param,**kwargs)
else:
warnings.warn(f'Saving to {codename} not supported',stacklevel=2)

Expand Down

0 comments on commit bd77020

Please sign in to comment.