pyexodus

Pure Python (still requires h5py and numpy) package to write exodus files. It emulates the Python API of the official Python exodus wrapper but is much much easier to get going. Additionally it manages to avoid the installation of two very large C/C++ libraries (netCDF and exodus) that are potentially tricky to install, and is also easy to install on Windows.

Additionally it is quite a bit faster (I guess due to more direct memory to file paths), uses less memory, and supports Python 2.7, 3.4, 3.5, and 3.6.

Don’t expect this to be complete anytime soon - we will add stuff as soon as we need it.

Installation

$ conda install -c conda-forge numpy h5netcdf pip pytest
$ git clone https://github.com/SalvusHub/pyexodus.git
$ cd pyexodus
$ pip install -v -e .
# Run the tests to make sure everything works.
$ py.test

API

Deviations from the official API

By and large pyexodus aims to be fully compatible with the official Python exodus API. Deviations are listed here.

class pyexodus.exodus(file, mode='r', array_type='numpy', title=None, numDims=None, numNodes=None, numElems=None, numBlocks=None, numNodeSets=None, numSideSets=None, io_size=0, compression=None)[source]

Create a new Exodus file. Can also be used as a context manager.

Parameters:
  • file (str) – Filename
  • mode (str) – File mode. Must currently be "r", "a", or "w".
  • array_type (str) – Must be "numpy".
  • title (str) – The title of the mesh.
  • numDims (int) – The number of dimensions.
  • numNodes (int) – The number of nodes.
  • numElems (int) – The number of elements.
  • numBlocks (int) – The number of element blocks.
  • numNodeSets (int) – The number of node side sets.
  • numSideSets (int) – The number of element side sets.
  • io_size (int) –

    Determines how floating point variables are stored in the file. Inputs will be converted if required.

    • 0: machine precision
    • 4: single precision
    • 8: double precision
  • compression (tuple) – Turn on compression. Pass a tuple of (method, option), e.g. ("gzip", 2). Slows down writing a lot but the resulting files are potentially much smaller.
get_coord(i)[source]

Get x, y, z of i-th node in the exodus file.

Parameters:i (int or array/list of ints) – Node index or indices. 1-based. The official exodus API can only take single indices - pyexodus can take a list of indices. In that case it will still return a three-tuple, but each now contains multiple variables.
get_coords()[source]

Returns all nodes in x, y, z.

get_elem_connectivity(id, indices=None)[source]

Get the connectivity for a certain element block.

Returns a tuple with three things: The actual connectivity as an array of node indices, the number of elements in this block, and the number of nodes per elements in this block.

Parameters:
  • id (int) – Id of the element block.
  • indices (numpy.ndarray) – If given, only get the connectivity of the specified element indices relative to the element block. These are 1-based indices in accordance with the exodus convention! Note that the second and third returned item are always stats for the whole connectivity array regardless of this argument. This parameter is not part of the official exodus Python API.
get_elem_type_for_block(id)[source]

Return the element type for an element block as a string.

Note

This method does not have a counter part in the official exodus Python API.

Parameters:id (int) – The element block id.
get_element_variable_names()[source]

Get list of element variable names in exodus file.

get_element_variable_values(blockId, name, step)[source]

Get values from element block id and variable name at step.

Parameters:
  • blockId (int) – The block id.
  • name (str) – The name of the variable.
  • step (int) – The time step at which to put the values.

Return values: The actual values.

get_global_variable_names()[source]

Get list of global variable names in exodus file.

get_global_variable_values(name)[source]

Get global variables values within an exodus file.

get_node_variable_names()[source]

Get list of node variable names in exodus file.

get_node_variable_number()[source]

Get number of node variables in the file.

get_node_variable_values(name, step)[source]

Get the node variable values for a a certain step.

Parameters:
  • name (str) – The name of the variable.
  • step (int) – The time step at which to get the values.
get_side_set(id)[source]

Get element and side ids for a certain side set.

Returns a tuple of two arrays. The first are the element indices, the second the side ids in these elements.

Parameters:id (int) – The id of the side set.
get_side_set_ids()[source]

Get a list of side set ids in the exodus file.

get_side_set_names()[source]

Get a list of the side set names in the exodus file.

get_side_set_node_list(id)[source]

Get the nodes for a certain side set.

Returns a tuple of two arrays. The first contains the number of nodes on each face the the seconds are the local node ids for the side set in the exodus file.

Parameters:id (int) – The id of the side set.
num_dims

Number of dimensions in the exodus file.

put_coords(xCoords, yCoords, zCoords)[source]

Put coordinates in the exodus file.

Parameters:
  • xCoords (numpy.ndarray) – The X coordiantes.
  • yCoords (numpy.ndarray) – The Y coordinates.
  • zCoords (numpy.ndarray) – The Z coordinates.
put_elem_blk_info(id, elemType, numElems, numNodesPerElem, numAttrsPerElem)[source]

Set the details of an element block.

Parameters:
  • id (int) – The id of the element block.
  • elemType (str) – The name of the element block.
  • numElems (int) – The number of elements in the block.
  • numNodesPerElem (int) – The number of nodes per element.
  • numAttrsPerElem (int) – The number of attributes per element.
put_elem_connectivity(id, connectivity, shift_indices=0, chunk_size_in_mb=128)[source]

Set the element connectivity array for all elements in a block.

The information for this block must have already been set by calling e.put_elem_blk_info() on this block.

Parameters:
  • id (int) – The id of the element block.
  • connectivity (numpy.ndarray) – The connectivity. Must be equal to the number of of elements times the number of nodes per element for any given block.
  • shift_indices (int) – Not available in the official exodus Python API! This value will be added to all indices before they are written to the file. This is useful if you for example internally work with a 0-based indexing scheme but exodus requires a 1-based indexing scheme.
  • chunk_size_in_mb (int) – If shift_indices != 0 values will be written in chunks of this size. This is also the maximum memory usage of this method. If shift_indices == 0, all indices will be written directly from memory and no additional memory is required.
put_element_variable_name(name, index)[source]

Element variable with name at index into exodus file.

Parameters:
  • name (str) – The name of the element variable.
  • index (int) – The index of the element variable. Starts with 1!
put_element_variable_values(blockId, name, step, values)[source]

Put values into element block id and variable name at step.

Parameters:
  • blockId (int) – The block id.
  • name (str) – The name of the variable.
  • step (int) – The time step at which to put the values.
  • values (numpy.ndarray) – The actual values.
put_global_variable_name(name, index)[source]

Put global variable with name at index into exodus file.

Parameters:
  • name (str) – The name of the variable.
  • index (int) – The index of the global variable. First is 1!
put_global_variable_value(name, step, value)[source]

Put global variable value and variable name at time step into exodus file.

Parameters:
  • name (str) – The name of the variable.
  • step (int) – The index of the time step. First is 1.
  • value (float) – The actual time at that index.
put_info_records(info)[source]

Puts the info records into the exodus file.

Does currently not do anything.

Parameters:info (list of str) – The strings to save.
put_node_variable_name(name, index)[source]

Node variable with name at index into exodus file.

Parameters:
  • name (str) – The name of the element variable.
  • index (int) – The index of the element variable. Starts with 1!
put_node_variable_values(name, step, values)[source]

Put node values into variable name at step into exodus file

Parameters:
  • name (str) – The name of the variable.
  • step (int) – The time step at which to put the values.
  • values (numpy.ndarray) – The actual values.
put_side_set(id, sideSetElements, sideSetSides)[source]

Set the id, element ids, and side ids for a side set (creates the side set).

Parameters:
  • id (int) – The id of the side set.
  • sideSetElements (numpy.ndarray) – The side set elements.
  • sideSetSides (numpy.ndarray) – The side set sides.
put_side_set_name(id, name)[source]

Write side set name for side set “id” in exodus file

Parameters:
  • id (int) – The id of the side set.
  • name (str) – The string of the side set.
put_side_set_params(id, numSetSides, numSetDistFacts)[source]

Set ID, num elements, and num nodes of a sideset

Parameters:
  • id (int) – The id of the side set.
  • numSetSides (int) – The number of elements for a side set.
  • numSetDistFacts (int) – The number of nodes for the side set.
put_time(step, value)[source]

Put time step and value into exodus file.

Parameters:
  • step (int) – The index of the time step. First is 1.
  • value (float) – The actual time at that index.
set_element_variable_number(number)[source]

Set number of element variables in exodus file.

Parameters:number (int) – The number of variables per element.
set_global_variable_number(number)[source]

Set number of global variables in exodus file.

Parameters:number (int) – The number of global variables.
set_node_variable_number(number)[source]

Set number of node variables in exodus file.

Parameters:number (int) – The number of node variables.

Note

Acknowledgements