mpacts.io. datasave_new

In order to be able to use this module import it like this:

import mpacts.io.datasave_new
#or assign it to a shorter name
import mpacts.io.datasave_new as dat

DataFrameReader

class mpacts.io.datasave_new.DataFrameReader(fname, index, dataslice=None)

Bases: object

Standardized interface for reading Mpacts save files stored with DataSaveCommand

Parameters:
  • fname (str) – file name of data save file that needs to be read (will be opened in read-only mode)
  • index (int) – Assign an index to this data frame
Note:
In most instances, a DataReader should be used to automatically handle multiple data frames.
DataFrameReader(name, parent, **kwargs)
apply_slice(val)

DataReader

class mpacts.io.datasave_new.DataReader(simname, folder='.')

Bases: object

Standardized interface for reading collections of Mpacts save files stored with DataSaveCommand

Parameters:
  • simname (str) – Name of the root node of the simulation, specifying the ‘base name’ of a list of mpactsd save files
  • folder (str) – Optional folder in which the DataReader should read save files

Example usage:

import mpacts.io.datasave as ds
reader = ds.DataReader("simulation", folder='./')

#Last saved frame of a simulation:
dr = reader[-1]

#Access to regular arrays
x = dr('spheres/x')
v = dr('spheres/v')

#Access to arrays in complex data structures:
vil = dr('box/RigidQuads/vertexIndices')
xctrl = dr('box/controlPoints/x')

#Access to any property in a 'tree':
g = dr('simulation/loop_cmds/body_force_cmds/GravityCmd/g')

#Access to Variables:
E = dr('simulation/params/E')
Note:
The example above directly extracts data from a simulation. For advanced post-processing, it is often useful to organize data access and processing over multiple frames using postprocessing operators. See: DEMutilities.postprocessing.operators.operators.
DataReader(name, parent, **kwargs)
set_slice(dataslice)

DataSaveCommand

class mpacts.io.datasave_new.DataSaveCommand(name, parent=None, **kwargs)

Bases: mpacts.core.command.PythonCommand

Saves all data contained in a simulation tree to output files in a save format intended for postprocessing. The main goal is to provide a uniform interface to access data from the simulation while leaving the save files as small as possible.

Parameters:

Optional key word arguments:

  • root: Root node of the simulation that will be saved. If not specified, ‘parent’ will be used.
  • gate: Optional mpacts gate for conditional execution
  • exclude_arrays: If True, Array objects will not be saved, dramatically reducing the size of saved files.
  • directory: (optional) directory in which the output will be saved. Default=’./’
  • filename: (optional) name of the files prefix. Default = name of the root
  • exclude_paths : (optional) one path or a list of paths (from given root) that will be omitted from saving
Note:
Data files saved with this command do not contain sufficient information to reconstruct the ‘full’ state of a simulation, hence they can not be used to load and restart a previous simulation. For this, the more encompassing SaveCommand should be used.
DataSaveCommand(name, parent, **kwargs)
execute()
mpacts.io.datasave_new.compounded_name(basename, number)
mpacts.io.datasave_new.json_serialise_data(data)
mpacts.io.datasave_new.json_unserialise_data(string)
mpacts.io.datasave_new.serialise_data(data)
mpacts.io.datasave_new.unserialise_data(string)