D3plot


class lasso.dyna.D3plot.D3plot(filepath: str = None, use_femzip: bool = False, n_files_to_load_at_once=-1, state_array_filter=None)

Constructor for a D3plot

Parameters
filepathstr

path to a d3plot file

use_femzipbool

whether to use femzip decompression

n_files_to_load_at_onceint

number of d3plot files to load into memory at once. By default -1 means all are loaded

state_array_filterlist of str or None

names of arrays which will be the only ones loaded from state data

Notes
—–

If dyna wrote multiple files for several states, only give the path to the first file.

Attributes
arrays

Dictionary holding all d3plot arrays

header

Dictionary holding all d3plot header information

Methods

compare(self, d3plot2, array_eps, …)

Compare two d3plots and print the info

enable_logger(enable)

Enable the logger for this class

get_part_filter(self, filter_type, part_ids, …)

Get a part filter for different entities

plot(self, i_timestep, field, …)

Plot the d3plot geometry

write_d3plot(self, filepath, block_size_bytes)

Write a d3plot file again

__init__(self, filepath: str = None, use_femzip: bool = False, n_files_to_load_at_once=-1, state_array_filter=None)

Constructor for a D3plot

Parameters
filepathstr

path to a d3plot file

use_femzipbool

whether to use femzip decompression

n_files_to_load_at_onceint

number of d3plot files to load into memory at once. By default -1 means all are loaded

state_array_filterlist of str or None

names of arrays which will be the only ones loaded from state data

Notes
—–

If dyna wrote multiple files for several states, only give the path to the first file.

property arrays

Dictionary holding all d3plot arrays

Notes

The corresponding keys of the dictionary can also be found in lasso.dyna.ArrayTypes, which helps with IDE integration and code safety.

Examples

>>> d3plot = D3plot("some/path/to/d3plot")
>>> d3plot.arrays.keys()
dict_keys(['irbtyp', 'node_coordinates', ...])
>>> # The following is good coding practice
>>> import lasso.dyna.ArrayTypes.ArrayTypes as atypes
>>> d3plot.arrays[atypes.node_displacmeent].shape
compare(self, d3plot2, array_eps: Union[float, NoneType] = None)

Compare two d3plots and print the info

Parameters
d3plot2D3plot

second d3plot

array_epsfloat or None

tolerance for arrays, None by default

Returns
hdr_differencesdict

differences in the header

array_differencesdict

difference between arrays (number of non-matching elements)

static enable_logger(enable: bool)

Enable the logger for this class

Parameters
enablebool

whether to enable logging for this class

get_part_filter(self, filter_type: lasso.dyna.FilterType.FilterType, part_ids: Iterable[int], for_state_array: bool = True) → numpy.ndarray

Get a part filter for different entities

Parameters
filter_type: `lasso.dyna.FilterType` or `str`

the array type to filter (beam, shell, solid, tshell)

part_ids: `Iterable[int]`

part ids to filter out

for_state_array: `bool`

if the filter is meant for a state array. Makes a difference for shells if rigid bodies are in the model (mattyp == 20)

Returns
mask: np.ndarray

mask usable on arrays to filter results

Examples

>>> from lasso.dyna import D3plot, ArrayType, FilterType
>>> d3plot = D3plot("path/to/d3plot")
>>> part_ids = [13, 14]
>>> mask = d3plot.get_part_filter(FilterType.shell)
>>> shell_stress = d3plot.arrays[ArrayType.element_shell_stress]
>>> shell_stress.shape
(34, 7463, 3, 6)
>>> # select only parts from part_ids
>>> shell_stress_parts = shell_stress[:, mask]
property header

Dictionary holding all d3plot header information

Notes

The header contains many informations such as number of elements, etc. The names are the original dyna names, thus sometimes confusing … but that’s dyna.

Examples

>>> d3plot = D3plot("some/path/to/d3plot")
>>> d3plot.header
dict_keys(['title', 'runtime', 'filetype', 'source_version', ...])
>>> # number of shells
>>> d3plot.header['nel4']
85624
plot(self, i_timestep: int = 0, field: Union[numpy.ndarray, NoneType] = None, is_element_field: bool = True, fringe_limits: Union[Tuple[float, float], NoneType] = None, export_filepath: str = '')

Plot the d3plot geometry

Parameters
i_timestepint

timestep index to plot

fieldUnion[np.ndarray, None]

Array containing a field value for every element or node

is_element_fieldbool

if the specified field is for elements or nodes

fringe_limitsUnion[Tuple[float, float], None]

limits for the fringe bar. Set by default to min and max.

export_filepathstr

filepath to export the html to

Notes

Currently only shell elements can be plotted, since for solids the surface needs extraction.

Examples

Plot deformation of last timestep.

>>> d3plot = D3plot("path/to/d3plot")
>>> d3plot.plot(-1)
>>> # get eff. plastic strain
>>> pstrain = d3plot.arrays[ArrayType.element_shell_effective_plastic_strain]
>>> pstrain.shape
(1, 4696, 3)
>>> # mean across all 3 integration points
>>> pstrain = pstrain.mean(axis=2)
>>> pstrain.shape
(1, 4696)
>>> # we only have 1 timestep here but let's take last one in general
>>> last_timestep = -1
>>> d3plot.plot(0, field=pstrain[last_timestep])
>>> # we don't like the fringe, let's adjust
>>> d3plot.plot(0, field=pstrain[last_timestep], fringe_limits=(0, 0.3))
>>> # looks good so let's export it
>>> d3plot.plot(0, field=pstrain[last_timestep], fringe_limits=(0, 0.3), export_filepath="yay.html")
write_d3plot(self, filepath: str, block_size_bytes: int = 2048)

Write a d3plot file again

Parameters
filepathstr

filepath of the new d3plot file

block_size_bytesint

D3plots are originally written in byte-blocks causing zero-padding at the end of files. This can be controlled by this parameter. Set to 0 for no padding.

Examples

Modify an existing d3plot:

>>> d3plot = D3plot("path/to/d3plot")
>>> hvars = d3plot.array[ArrayType.element_shell_history_vars]
>>> hvars.shape
(1, 4696, 3, 19)
>>> new_history_var = np.random.random((1, 4696, 3, 1))
>>> new_hvars = np.concatenate([hvars, new_history_var], axis=3)
>>> d3plot.array[ArrayType.element_shell_history_vars] = new_hvars
>>> d3plot.write_d3plot("path/to/new/d3plot")

Write a new d3plot from scratch:

>>> d3plot = D3plot()
>>> d3plot.arrays[ArrayType.node_coordinates] = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]])
>>> d3plot.arrays[ArrayType.element_shell_node_indexes] = np.array([[0, 2, 1, 1]])
>>> d3plot.arrays[ArrayType.element_shell_part_indexes] = np.array([0])
>>> d3plot.arrays[ArrayType.node_displacement] = np.array([[[0, 0, 0], [1, 0, 0], [0, 1, 0]]])
>>> d3plot.write_d3plot("yay")