exodusreader.py

class ExodusReader(output_file)[source]

Bases: OutputReader

Class to read exodus files output by MOOSE using the netCDF package. This class handles extracting the data from the exodus file and creates a SimData object with the required data. Most used cases are covered with by creating an ExodusReader and then calling either read_sim_data() or read_all_sim_data() specified at the bottom of the class.

__init__(output_file)[source]

__init__: Construct class by reading the exodus file using the netCDF package. The exodus file must exist.

Args:

output_file (Path): path to the exodus file to read

Raises:

FileNotFoundError: the specified exodus file does not exist

get_names(key)[source]

get_names: Extract a list of variable names from the dataset. Useful for getting node/element/sideset/global variables names.

Parameters:

key (str | None) – string key used to extract a list of names from the dataset e.g. ‘node_var_names’. If key is None returns None.

Returns:

np.ndarray | None – numpy array of strings representing the names that correspond to the variables in the dataset. Returns None if the specified key does not exist in the dataset.

get_var(key, time_inds=None)[source]

get_var: Extract a numeric variable from the dataset.

Parameters:
  • key (str :) – key corresponding to the variable in the dataset. e.g. ‘time_whole’

  • key

  • time_inds (np.ndarray | None :) – (Default value = None)

Returns:

np.ndarray – numpy numeric array containing the variable data.

get_key(name, all_names, key_tag)[source]

get_key: builds the key required to extract a given variable from the exodus dataset.

Parameters:
  • all_names (np.ndarray :) – all possible name keys extracted using the get names function.

  • name (str :) – the specific name key that the user wants to extract

  • key_tag (str :) – the string tag that is prepended to get the variable from the dataset.

  • name

  • all_names

  • key_tag

Returns:

str | None – the string key in the dataset to get the variable

get_connectivity_names()[source]

get_connectivity_names: gets the connectivity names in the exodus dataset. These are of the form ‘connect1’, ‘connect2’ etc.

Returns:

np.ndarray – array of element connectivity keys as strings of the form connectX where X is an integer of 1 or greater e.g. connect1.

get_connectivity()[source]

get_connectivity: returns the connectivity table as a dictionary keyed with the name ‘connectX’ and the table itseld as numpy array.

Returns:

dict[str,np.ndarray] – dictionary containing the element connectivity tables based on keys related to the subdomain e.g. key ‘connect1’ returns the element connectivity table for subdomain 1. The table has dimensions N by n_e where N is the total number of nodes in the subdomain and n_e is the number of nodes per element.

get_sideset_names()[source]

get_sideset_names: returns the sideset names as a numpy array of strings.

Returns:

np.ndarray | None – numpy array of strings corresponding to the sideset names specified in the simulation. Returns None if no sideset names are found.

get_sidesets(names)[source]

get_sidesets: returns the sidesets as a dictionary keyed by a tuple of (‘sideset_name’, ‘node’ | ‘elem’). Gives either the list of node numbers or element numbers based on the specified key.

Parameters:

names (np.ndarray | None) – numpy array of strings specifying the sideset names to extract from the dataset. If None return None.:

Returns:

dict[tuple[str,str], np.ndarray] | None – dictionary of sideset nodes and element sets by name. The key is a tuple with the first string being the sideset name and the second being either ‘node’ or ‘elem’. Returns None if no sidesets found.

get_all_sidesets()[source]

get_all_sidesets: returns all sidesets as a dictionary keyed by a tuple of (‘sideset_name’, ‘node’ | ‘elem’). Gives either the list of node numbers or element numbers based on the specified key.

Returns:

dict[tuple[str,str], np.ndarray] | None – dictionary of sideset nodes and element sets by name. The key is a tuple with the first string being the sideset name and the second being either ‘node’ or ‘elem’. Returns None if no sidesets found.

get_node_var_names()[source]

get_node_var_names: gets the nodal variable names as a numpy array of strings e.g. np.array([‘disp_x’,’disp_y’])

Returns:

np.ndarray | None – numpy array of strings containing the nodal variable names. Returns None if no nodal variables are found.

get_node_vars(names, time_inds=None)[source]

get_node_vars: gets the specified nodal variables as a dictionary keyed by the variable name (e.g. ‘disp_x’) where the nodal variable is given as a numpy array of dimensions NxT where N is the number of nodes and T is the number of time steps in the simulation.

Parameters:
  • names (np.ndarray | None) – numpy array of strings that are the variables to be extracted from the exodus dataset.

  • time_inds (np.ndarray | None :) – (Default value = None)

Returns:

dict[str,np.ndarray] | None – dictionary of requested nodal variables. Keys are nodal variable names e.g. ‘disp_x’ and the variable data is given as a numpy array. returns None if no nodal variables are found.

get_all_node_vars()[source]

get_all_node_vars: as get_node_vars but returns all nodal variables found in the dataset. Gets all specified nodal variables as a dictionary keyed by the variable name (e.g. ‘disp_x’) where the nodal variable is given as a numpy array of dimensions NxT where N is the number of nodes and T is the number of time steps in the simulation.

Returns:

dict[str, np.ndarray] | None – dictionary of requested nodal variables. Keys are nodal variable names e.g. ‘disp_x’ and the variable data is given as a numpy array. returns None if no nodal variables are found.

get_elem_var_names()[source]

get_elem_var_names: gets the element variable names as a numpy array of strings if they exist. Note that there are several cases where the element variables may be interpolated to nodes and stored as nodal data

Returns:

np.ndarray | None – element variable names as a numpy array of strings. An example variable name is ‘strain_xx’. Returns None if no element variable names exist in the dataset.

get_num_elem_blocks()[source]

get_num_elem_blocks: gets the number of element blocks (i.e. sub-domains) in the simulation. These are used to partition the element data.

Returns:

int – number of element blocks/sub-domains in the simulation.

get_elem_var_names_and_blocks()[source]

get_elem_var_names_and_blocks: returns a list of all possible combinations of element variables names and block numbers present in the dataset.

Returns:

list[tuple[str,int]] | None – list of tuples containing the element variable names and block numbers. Returns None if there are no element variable name or element blocks.

get_elem_vars(names_blocks, time_inds=None)[source]

get_elem_vars: gets the element variables as a dictionary keyed by tuples which containg the element variable name and the block number. For example: (‘strain_xx’,1). The element data is given as a numpy array with dimensions E_bxT where E_b is the number of element in the block and T is the number of time steps.

Parameters:
  • names_blocks (list[tuple[str,int]] | None :) – list of tuples containing the combination of element variables names and blocks to be extracted from the dataset.

  • time_inds (np.ndarray | None :) – (Default value = None)

Returns:

dict[tuple[str,int],np.ndarray] | None – contains the variables requested keyed using the input names_blocks with the data given as a numpy array.

get_all_elem_vars()[source]

get_all_elem_vars: gets all element variables as a dictionary keyed by tuples which containg the element variable name and the block number. For example: (‘strain_xx’,1). The element data is given as a numpy array with dimensions E_bxT where E_b is the number of element in the block and T is the number of time steps.

Returns:

dict[tuple[str,int], np.ndarray] | None – contains the variables requested keyed using the input names_blocks with the data given as a numpy array.

get_glob_var_names()[source]

get_glob_var_names: gets the names of all global variables in the dataset. Global variables include the output of all MOOSE post- processors.

Returns:

np.ndarray | None – numpy array containing the global variable names as strings.

get_glob_vars(names, time_inds=None)[source]

get_glob_vars: gets the specified global variables as a dictionary keyed by the variable name specified in the MOOSE input file. The data is given as a numpy array of T dimensions where T is the number of time steps.

Parameters:
  • names (np.ndarray | None) – numpy array of strings specifying the global variable names to extract from the dataset. If this is None then return None.

  • time_inds (np.ndarray | None :) – (Default value = None)

Returns:

dict[str, np.ndarray] | None – dictionary keyed with the global variable names requested giving the data as a numpy array.

get_all_glob_vars()[source]

get_all_glob_vars: gets all global variables as a dictionary keyed by the variable name specified in the MOOSE input file. The data is given as a numpy array of T dimensions where T is the number of time steps.

Returns:

dict[str, np.ndarray] | None – dictionary keyed with all global variable names giving the data as numpy arrays.

get_coords()[source]

Gets the nodal coordinates in each spatial dimension setting any undefined dimensions to zeros.

Returns:

np.array – returns the nodal coordinates as an array with shape (N,3) where N is the number of nodes and the three columns are the (x,y,z) spatial dimensions.

Raises:

RuntimeError – no spatial dimensions found.

get_time(time_inds=None)[source]

Get a vector of simulation time steps.

Parameters:

time_inds (np.ndarray | None :) – (Default value = None)

Returns:

np.array – returns an array with shape (T,) where T is the number of time steps and the values of the elements are the simulation time and each time step.

print_vars()[source]

Prints all variable strings in the exodus file to console.

get_read_config()[source]

get_read_config: constructs a SimReadConfig object by extracting all the variable names found in the exodus dataset. Useful for creating a mostly populated SimReadConfig and removing variables that are unwanted.

Returns:

SimReadConfig – data class containing names of variables to be extracted from the exodus dataset. See mooseherder.simdata.

read_sim_data(read_config)[source]

read_sim_data: reads the simulation data based on the specified SimReadConfig object.

Parameters:
  • read_config (SimReadConfig :) – data class containing the names of the variables that are to be extracted from the exodus dataset.

  • read_config

Returns:

SimData – data class containing data from the simulation.

read_all_sim_data()[source]

read_all_sim_data: gets all simulation data from the exodus dataset.

Returns:

SimData – data class containing the data from the simulation.