simsaver.py¶
- class ESaveArray(value)[source]¶
Bases:
EnumEnumeration setting the file type to save arrays as either numpy, delimited plain text or both.
- NPY = 1¶
- TXT = 2¶
- BOTH = 3¶
- save_array(save_file, data, save_format, txt_header='', txt_delimiter=',', txt_ext='.csv')[source]¶
Wrapper function to save a numpy array to disk in binary npy, delimited plain text or both formats.
- Parameters:
save_file (
Path) – Path including file name to save the numpy arrays to.data (
np.ndarray) – Array to save to disk.save_format (
ESaveArray) – Enumeration specifying to save the array in binary numpy, delimited plain text or both formats.txt_header (
str, optional) – String specifying the headers for text files, by default “”.txt_delimiter (
str, optional) – Delimiter for text file array output, by default “,”txt_ext (
str, optional) – Extension for text file output, by default “.csv”
- Raises:
FileExistsError – The parent directory where the array files to be saved does not exist.
- class ESaveFieldOpt(value)[source]¶
Bases:
EnumEnumeration specifying how to save physics fields as: - ‘BY_TIME’: One array per time step where the first dimension is the nodal
coordinates and the second dimension is the field component.
- ‘BY_FIELD’: A single array per nodal field where the first dimension is
the coordinate and the second dimension is the time step.
‘BOTH’: Save in both formats.
- BY_TIME = 1¶
- BY_FIELD = 2¶
- BOTH = 3¶
- class SimDataSaveOpts(fields_save_by=ESaveFieldOpt.BY_TIME, array_format=ESaveArray.TXT, sim_tag='', coords_name='coords', connect_name='connect', time_name='time', glob_name='glob', node_field_name='node_field', elem_field_name='elem_field')[source]¶
Bases:
objectOptions for saving sim data objects to disk.
- fields_save_by¶
Enumeration specifying the data structure for the physics fields.
- array_format¶
Enumeration specifying the file format to save the output files in.
- sim_tag¶
String tag that will appear as a prefix to all saved output file names.
- coords_name¶
String that will be used after the ‘sim_tag’ prefix for the coordinates file.
- connect_name¶
String that will be used after the ‘sim_tag’ prefix for the connectivity table file names. Note that there will be one connectivity table per mesh and there will be labelled ‘connect_nameX’ where X is an integer.
- time_name¶
String that will be used after the ‘sim_tag’ prefix for the time step data file.
- glob_name¶
String that will be used after the ‘sim_tag’ prefix for the global variable output file.
- node_field_name¶
String that will be used after the ‘sim_tag’ prefix for the output node field variable files.
- elem_field_name¶
String that will be used after the ‘sim_tag’ prefix for the output element field variable files.
- __init__(fields_save_by=ESaveFieldOpt.BY_TIME, array_format=ESaveArray.TXT, sim_tag='', coords_name='coords', connect_name='connect', time_name='time', glob_name='glob', node_field_name='node_field', elem_field_name='elem_field')¶
- get_coord_name()[source]¶
Assembles the file name for the coordinates. If the ‘sim_tag’ prefix is empty it just returns the specified string name for the coordinate file.
- Returns:
str– Assemebled filename for the coordinates.
- get_connect_name_by_key(key)[source]¶
Assembles the connectivity file name using the connectivity dictionary key taken from the SimData object.
- Parameters:
key (
str) – String key from the connectivity dictionary in the SimData object.- Returns:
str– Assembled file name for the specified connectivity table.
- get_connect_name_by_block(block)[source]¶
Assembles the connectivity file name using the specified block and connectvity name.
- Parameters:
block (
int) – Integer to identify the connectivity table.- Returns:
str– Assembled file name for the specified connectivity table.
- get_time_name()[source]¶
Assembles the file name for the time steps.
- Returns:
str– Assembled file name for the simulation time steps.
- get_glob_name()[source]¶
Assembles the file name for the global output variables.
- Returns:
str– Assembled file name for the global simulation variables.
- save_sim_data_to_arrays(output_path, sim_data, save_opts=None)[source]¶
Saves the simulation data to a series of output files in delimited plain text and/or binary numpy arrays.
- Parameters:
output_path (
Path) – Path to the directory where the simulation files will be saved.sim_data (
mh.SimData) – Simulation data object containing the data to save to disk.save_opts (
SimDataSaveOpts | None, optional) – Options for how the simulation data should be saved, by default None.
- Raises:
FileExistsError – The specified output Path is not a directory.