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

Commit

Permalink
Browse files Browse the repository at this point in the history
Wrote consolidated get_parameters and set_parameters methods.
  • Loading branch information
daminton committed Nov 10, 2022
1 parent c7ab062 commit 69807af
Showing 1 changed file with 54 additions and 14 deletions.
68 changes: 54 additions & 14 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def __init__(self,
verbose = False)



if read_old_output_file:
binpath = os.path.join(self.sim_dir,self.param['BIN_OUT'])
if os.path.exists(binpath):
Expand Down Expand Up @@ -448,7 +447,7 @@ def set_simulation_time(self,

return time_dict

def get_simulation_time(self, arg_list: str | List[str] | None = None, verbose: bool | None = None):
def get_simulation_time(self, arg_list: str | List[str] | None = None, verbose: bool | None = None, **kwargs):
"""
Returns a subset of the parameter dictionary containing the current simulation time parameters.
Expand All @@ -462,6 +461,10 @@ def get_simulation_time(self, arg_list: str | List[str] | None = None, verbose:
["t0", "tstart", "tstop", "dt", "istep_out", "tstep_out", "istep_dump"]
verbose: bool, optional
If passed, it will override the Simulation object's verbose flag
**kwargs
A dictionary of additional keyword argument. This allows this method to be called by the more general
get_parameters method, which takes all possible Simulation parameters as arguments, so these are ignored.
Returns
-------
Expand Down Expand Up @@ -522,13 +525,33 @@ def set_parameters(self, **kwargs):
param : A dictionary of all Simulation parameters that changed
"""
self.set_unit_system(**kwargs)
self.set_distance_range(**kwargs)
self.set_feature(**kwargs)
self.set_init_cond_files(**kwargs)
self.set_output_files(**kwargs)
self.set_simulation_time(**kwargs)
param_dict = self.set_unit_system(**kwargs)
param_dict.update(self.set_distance_range(**kwargs))
param_dict.update(self.set_feature(**kwargs))
param_dict.update(self.set_init_cond_files(**kwargs))
param_dict.update(self.set_output_files(**kwargs))
param_dict.update(self.set_simulation_time(**kwargs))

def get_parameters(self, **kwargs):
"""
Setter for all possible parameters. Calls each of the specialized setters using keyword arguments
Parameters
----------
**kwargs : [TODO: write this documentation]
Returns
-------
param : A dictionary of all Simulation parameters requested
"""
param_dict = self.get_simulation_time(**kwargs)
param_dict.update(self.get_init_cond_files(**kwargs))
param_dict.update(self.get_output_files(**kwargs))
param_dict.update(self.get_distance_range(**kwargs))
param_dict.update(self.get_unit_system(**kwargs))
param_dict.update(self.get_feature(**kwargs))

return param_dict

def set_feature(self,
close_encounter_check: bool | None = None,
Expand Down Expand Up @@ -681,7 +704,7 @@ def set_feature(self,
return feature_dict


def get_feature(self, arg_list: str | List[str] | None = None, verbose: bool | None = None):
def get_feature(self, arg_list: str | List[str] | None = None, verbose: bool | None = None, **kwargs: Any):
"""
Returns a subset of the parameter dictionary containing the current value of the feature boolean values.
Expand All @@ -694,6 +717,9 @@ def get_feature(self, arg_list: str | List[str] | None = None, verbose: bool | N
["close_encounter_check", "general_relativity", "fragmentation", "rotation", "compute_conservation_values"]
verbose: bool, optional
If passed, it will override the Simulation object's verbose flag
**kwargs
A dictionary of additional keyword argument. This allows this method to be called by the more general
get_parameters method, which takes all possible Simulation parameters as arguments, so these are ignored.
Returns
-------
Expand All @@ -712,7 +738,7 @@ def get_feature(self, arg_list: str | List[str] | None = None, verbose: bool | N
"rhill_present": "RHILL_PRESENT",
"restart" : "RESTART",
"interaction_loops" : "INTERACTION_LOOPS",
"encounter_check_loops" : "ENCOUNTER_CHECK_LOOPS"
"encounter_check_loops" : "ENCOUNTER_CHECK"
}

valid_arg, feature_dict = self._get_valid_arg_list(arg_list, valid_var)
Expand Down Expand Up @@ -861,7 +887,7 @@ def ascii_file_input_error_msg(codename):
return init_cond_file_dict


def get_init_cond_files(self, arg_list: str | List[str] | None = None, verbose: bool | None = None):
def get_init_cond_files(self, arg_list: str | List[str] | None = None, verbose: bool | None = None, **kwargs):
"""
Returns a subset of the parameter dictionary containing the current initial condition file parameters
Expand All @@ -875,6 +901,10 @@ def get_init_cond_files(self, arg_list: str | List[str] | None = None, verbose:
["init_cond_file_type", "init_cond_file_name", "init_cond_format"]
verbose: bool, optional
If passed, it will override the Simulation object's verbose flag
**kwargs
A dictionary of additional keyword argument. This allows this method to be called by the more general
get_parameters method, which takes all possible Simulation parameters as arguments, so these are ignored.
Returns
-------
Expand Down Expand Up @@ -1025,7 +1055,7 @@ def set_output_files(self,
return output_file_dict


def get_output_files(self, arg_list: str | List[str] | None = None, verbose: bool | None = None):
def get_output_files(self, arg_list: str | List[str] | None = None, verbose: bool | None = None, **kwargs):
"""
Returns a subset of the parameter dictionary containing the current output file parameters
Expand All @@ -1039,6 +1069,10 @@ def get_output_files(self, arg_list: str | List[str] | None = None, verbose: boo
["output_file_type", "output_file_name", "output_format"]
verbose: bool, optional
If passed, it will override the Simulation object's verbose flag
**kwargs
A dictionary of additional keyword argument. This allows this method to be called by the more general
get_parameters method, which takes all possible Simulation parameters as arguments, so these are ignored.
Returns
-------
Expand Down Expand Up @@ -1241,7 +1275,7 @@ def set_unit_system(self,

return unit_dict

def get_unit_system(self, arg_list: str | List[str] | None = None, verbose: bool | None = None):
def get_unit_system(self, arg_list: str | List[str] | None = None, verbose: bool | None = None, **kwargs):
"""
Returns a subset of the parameter dictionary containing the current simulation unit system.
Expand All @@ -1253,6 +1287,9 @@ def get_unit_system(self, arg_list: str | List[str] | None = None, verbose: bool
A single string or list of strings containing the names of the simulation unit system
Default is all of:
["MU", "DU", "TU"]
**kwargs
A dictionary of additional keyword argument. This allows this method to be called by the more general
get_parameters method, which takes all possible Simulation parameters as arguments, so these are ignored.
Returns
-------
Expand Down Expand Up @@ -1398,7 +1435,7 @@ def set_distance_range(self,
return range_dict


def get_distance_range(self, arg_list: str | List[str] | None = None, verbose: bool | None = None):
def get_distance_range(self, arg_list: str | List[str] | None = None, verbose: bool | None = None, **kwargs: Any):
"""
Returns a subset of the parameter dictionary containing the current values of the distance range parameters.
Expand All @@ -1409,6 +1446,9 @@ def get_distance_range(self, arg_list: str | List[str] | None = None, verbose: b
arg_list: str | List[str], optional
A single string or list of strings containing the names of the features to extract. Default is all of:
["rmin", "rmax"]
**kwargs
A dictionary of additional keyword argument. This allows this method to be called by the more general
get_parameters method, which takes all possible Simulation parameters as arguments, so these are ignored.
Returns
-------
Expand Down

0 comments on commit 69807af

Please sign in to comment.