D3plot¶
- Ressources:
-
class
qd.cae.dyna.
D3plot
(filepath, read_states=[], use_femzip=False)¶ - Parameters
- filepathstr
path to the d3plot
- read_statesstr or list of str
read state information directly (saves time), see the function
read_states
- use_femzipbool
whether the file shall be decompressed with femzip.
- Returns
- D3plot d3plotinstance
- Raises
- ValueError
in case of an invalid filepath or locked file
- RuntimeError
if anything goes wrong (internal checks) during reading
Notes
If LS-Dyna writes multiple files (one for each timestep), give the filepath to the first file. The library finds all other files. Please read state information with the read_states flag in the constructor or with the member function.
Examples
Read the plain geometry data
>>> d3plot = D3plot("path/to/d3plot")
Read a compressed d3plot
>>> d3plot = D3plot("path/to/d3plot.fz", use_femzip=True)
Read d3plot with state data at once.
>>> d3plot = D3plot("path/to/d3plot", read_states=["mises_stress max"])
Methods
clear
(vars)- Parameters
compare_scatter
(self, filepath_list, …[, …])Compare the scatter between mutliple d3plot files
get_elementByIndex
(element_type, index)- Parameters
get_element_coords
(element_filter)- Parameters
get_element_energy
(element_filter)- Parameters
get_element_history_vars
(element_type)- Parameters
get_element_ids
(element_filter)- Parameters
get_element_node_ids
(element_type, n_nodes)- Parameters
get_element_plastic_strain
(element_filter)- Parameters
get_element_strain
(element_filter)- Parameters
get_element_stress
(element_filter)- Parameters
get_element_stress_mises
(element_filter)- Parameters
get_elements
([element_filter])- Parameters
- Returns
get_nElements
([element_filter])- Parameters
- Returns
- Returns
Get the number of timesteps of the d3plot.
get_nodeByID
(id)- Parameters
get_nodeByIndex
(index)- Parameters
- Returns
- Returns
- Returns
- Returns
- Returns
get_partByID
(id)- Parameters
get_partByIndex
(index)- Parameters
get_partByName
(name)- Parameters
- Returns
Get the simulation time of the written states.
Get the title of the d3plot, which is part of the header data.
info
()Prints a summary of the header data of the D3plot, which involves node info, element info, written state data and so forth.
plot
(self[, iTimestep, element_result, …])Plot the D3plot, currently shells only!
plot_parts
(parts[, iTimestep, …])Plot a selected group of parts.
read_states
(vars)- Parameters
get_elementByID
-
__init__
(filepath, read_states=[], use_femzip=False)¶ - Parameters
- filepathstr
path to the d3plot
- read_statesstr or list of str
read state information directly (saves time), see the function
read_states
- use_femzipbool
whether the file shall be decompressed with femzip.
- Returns
- D3plot d3plotinstance
- Raises
- ValueError
in case of an invalid filepath or locked file
- RuntimeError
if anything goes wrong (internal checks) during reading
Notes
If LS-Dyna writes multiple files (one for each timestep), give the filepath to the first file. The library finds all other files. Please read state information with the read_states flag in the constructor or with the member function.
Examples
Read the plain geometry data
>>> d3plot = D3plot("path/to/d3plot")
Read a compressed d3plot
>>> d3plot = D3plot("path/to/d3plot.fz", use_femzip=True)
Read d3plot with state data at once.
>>> d3plot = D3plot("path/to/d3plot", read_states=["mises_stress max"])
-
clear
(vars)¶ - Parameters
- varsstr or list(str)
variable or list of variables to delete
Notes
This function may be used if one wants to clear certain state data from the memory. Valid variable names are:
disp
vel
accel
strain
stress
stress_mises
plastic_strain
history [(optional) shell or solid]
The specification of shell or solid for history is optional. Deletes all history variables if none given.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="strain inner") >>> elem = d3plot.get_elementByID(Element.shell, 1) >>> len( elem.get_strain() ) 34 >>> # clear specific field >>> d3plot.clear("strain") >>> len( elem.get_strain() ) 0 >>> # reread some data >>> d3plot.read_states("strain outer") >>> len( elem.get_strain() ) 34 >>> d3plot.clear() # clear all >>> len( elem.get_strain() ) 0
-
compare_scatter
(self, filepath_list, element_result, pid_filter_list=None, kMappingNeighbors=4, export_filepath=None, **kwargs)¶ Compare the scatter between mutliple d3plot files
- Parameters
- filepath_listlist(str)
list of filepaths of d3plot for comparison
- element_resultstr or function(element)
element results to compare. Either specify a user defined function or use predefined results. Available are disp, plastic_strain or energy.
- pid_filter_listlist(int)
list of pids to filter for optionally
- kMappingNeighborsint
number of neighbors used for nearest neighbor mapping
- export_filepathstr
optional filepath for saving. If none, the model is exported to a temporary file and shown in the browser.
- **kwargsfurther arguments
additional arguments passed on to d3plot constructor (e.g. read_states)
Notes
The file calling the function will be the basis for the comparison. The other files results will be mapped onto this mesh. The scatter is computed between all runs as maximum difference.
Examples
>>> # Settings (don't forget to load the correct vars!) >>> state_vars = ["stress_mises max"] >>> other_files = ["path/to/d3plot_2", "path/to/d3plot_3"] >>> >>> # Element eval function (used for scatter computation) >>> def elem_eval_fun(elem): >>> result = elem.get_stress_mises() >>> if len(result): >>> return result[-1] >>> return 0. >>> >>> # load base file >>> d3plot = D3plot("path/to/d3plot", read_states=state_vars) >>> >>> # compute and plot scatter >>> d3plot.compare_scatter(other_files, elem_eval_fun, read_states=state_vars)
-
get_elementByIndex
(element_type, index)¶ - Parameters
- element_typeElement.type
type of the element. Must be beam, shell or solid.
- indexint or list(int)
element index or list of indexes
- Returns
- elementElement
Element(s) depending on the arguments
- Raises
- ValueError
if invalid
element_type
is given orindex
does not exist
Examples
>>> # single element >>> elem = femfile.get_elementByIndex(Element.shell, 0) >>> # multiple elements >>> list_of_shells = femfile.get_elementByID(Element.shell, [0,1,2]) >>> >>> femfile.get_elementByIndex(Element.beam, 1).get_type() type.beam >>> femfile.get_elementByIndex(Element.solid, 1).get_type() type.solid >>> femfile.get_elementByIndex(Element.tshell, 1).get_type() type.tshell
-
get_element_coords
(element_filter)¶ - Parameters
- element_filterElement.type
optional type for filtering
- Returns
- fieldnp.ndarray
coords vector of the elements (nElems x nTimesteps x 3)
Notes
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="coords") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> d3plot.get_element_coords(Element.shell).shape (4969, 32. 3)
-
get_element_energy
(element_filter)¶ - Parameters
- element_filterElement.type
optional type for filtering
- Returns
- fieldnp.ndarray
energy of the elements (nElems x nTimesteps)
Notes
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="energy mean") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> d3plot.get_element_energy(Element.shell).shape (4969, 32)
-
get_element_history_vars
(element_type)¶ - Parameters
- element_typeElement.type
type of the element
- Returns
- fieldnp.ndarray
history_vars vector of the elements (nElems x nTimesteps x nHistoryVars)
Notes
IMPORTANT: You can not query the history vars without specifying an element type. In LS-Dyna e.g. history var 7 is different between shells and beams. To prevent wrong usage and bugginess, we enforce this policy here. We didn’t mess this one up!
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="shell history 7 max") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> # Element type is required here! >>> d3plot.get_element_history_vars(Element.shell).shape (4969, 32. 10)
-
get_element_ids
(element_filter)¶ - Parameters
- element_filterElement.type
optional element type for filtering
- Returns
- element_idsnp.ndarray
Ids of the elements
Notes
If the ids for all elements are queried (
Element.none
as filter type) then the returned order is:Element.beam
Element.shell
Element.solid
Element.tshell
Examples
>>> d3plot = D3plot("path/to/d3plot") >>> # get all ids (beam, shell, solid, tshell) >>> d3plot.get_element_ids() array([4687, 4688, 4689, 4690, ...]) >>> # filter only beams >>> d3plot.get_element_ids(Element.beam) array([9545, 9546, 9547, 9511, ...])
-
get_element_node_ids
(element_type, n_nodes)¶ - Parameters
- element_typeElement.type
type of the element
- n_nodesint
number of nodes
- Returns
- element_node_idsnp.ndarray
ids of the nodes for every element (shape elems x n_nodes).
Notes
The number of nodes must be specified since elements of one type may have different number of nodes which would result in a non-uniform matrix.
Examples
>>> d3plot = D3plot("path/to/d3plot") >>> d3plot.get_element_node_ids(Element.shell, 4) array([[347, 354, 343, 344], [354, 355, 342, 343], [349, 352, 356, 348]], dtype=int32)
-
get_element_plastic_strain
(element_filter)¶ - Parameters
- element_filterElement.type
optional type for filtering
- Returns
- fieldnp.ndarray
effective plastic strain of the elements (nElems x nTimesteps)
Notes
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="plastic_strain max") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> d3plot.get_plastic_strain(Element.shell).shape (4969, 32)
-
get_element_strain
(element_filter)¶ - Parameters
- element_filterElement.type
optional type for filtering
- Returns
- fieldnp.ndarray
strain vector of the elements (nElems x nTimesteps x 6)
Notes
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="strain mean") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> d3plot.get_element_strain(Element.shell).shape (4969, 32. 6)
-
get_element_stress
(element_filter)¶ - Parameters
- element_filterElement.type
optional type for filtering
- Returns
- fieldnp.ndarray
stress vector of the elements (nElems x nTimesteps x 6)
Notes
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="stress mean") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> d3plot.get_element_stress(Element.shell).shape (4969, 32. 6)
-
get_element_stress_mises
(element_filter)¶ - Parameters
- element_filterElement.type
optional type for filtering
- Returns
- fieldnp.ndarray
mises stress of the elements (nElems x nTimesteps)
Notes
If an element does not have the respective result, 0 is set as default value.
Examples
>>> d3plot = D3plot("path/to/d3plot", read_states="stress_mises mean") >>> d3plot.get_nElements(Element.shell) 4969 >>> d3plot.get_nTimesteps() 32 >>> d3plot.get_element_stress_mises(Element.shell).shape (4969, 32)
-
get_elements
(element_filter=Element.none)¶ - Parameters
- element_filterElement.type
Optional element type filter. May be beam, shell or solid.
- Returns
- elementslist(Element)
list of Elements
- Raises
- ValueError
if invalid
element_filter
is given.
Notes
Get the elements of the femfile. One may use a filter by type.
Examples
>>> all_elements = femfile.get_elements() >>> shell_elements = femfile.get_elements(Element.shell)
-
get_filepath
()¶ - Returns
- filepathstr
Filepath of the femfile.
Examples
>>> femfile.get_filepath() "path/to/femfile"
-
get_nElements
(element_filter=Element.none)¶ - Parameters
- element_filterElement.type
Optional element type filter. May be beam, shell or solid.
- Returns
- nElementsint
number of elements
- Raises
- ValueError
if invalid
element_filter
is given.
Examples
>>> femfile.get_nElements() 43156
-
get_nNodes
()¶ - Returns
- nNodesint
number of nodes in the file
Examples
>>> femfile.get_nNodes() 43145
-
get_nParts
()¶ - Returns
- nPartsint
number of parts in the database
Examples
>>> femfile.get_nParts() 7
-
get_nTimesteps
()¶ Get the number of timesteps of the d3plot.
- Returns
- nTimestepsint
number of timesteps
Examples
>>> d3plot = D3plot("path/to/d3plot") >>> d3plot.get_nTimesteps() 32
-
get_nodeByID
(id)¶ - Parameters
- idint or list(int)
node id or list of node ids
- Returns
- nodeNode or list(Node)
requested Node(s)
- Raises
- ValueError
if
idx
does not exist.
Examples
>>> # get by single id >>> node = femfile.get_nodeByID(1) >>> # get a list of nodes at once >>> list_of_nodes = femfile.get_nodeByID( [1,2,3] )
-
get_nodeByIndex
(index)¶ - Parameters
- indexint or list(int)
internal node index or list inf indexes
- Returns
- nodeNode or list(Node)
Node(s)
- Raises
- ValueError
if
index
largerfemfile.get_nNodes()
.
Notes
The internal index starts at 0 and ends at
femfile.get_nNodes()
.Examples
>>> # single index >>> node = femfile.get_nodeByIndex(1) >>> # get a list of nodes at once >>> list_of_nodes = femfile.get_nodeByIndex( [1,2,3] )
-
get_node_acceleration
()¶ - Returns
- node_accelerationnp.ndarray
Accelration of all nodes
Examples
>>> d3plot.get_node_acceleration().shape (4915,1,3)
-
get_node_coords
()¶ - Returns
- node_coordsnp.ndarray
coordinates of all nodes
Examples
>>> d3plot.get_node_coords().shape (4915, 3)
-
get_node_ids
()¶ - Returns
- node_idsnp.ndarray
Ids of all nodes
Examples
>>> d3plot.get_node_ids().shape (100001)
-
get_node_velocity
()¶ - Returns
- node_velocitynp.ndarray
Velocity of all nodes
Examples
>>> d3plot.get_node_velocity().shape (4915,1,3)
-
get_nodes
()¶ - Returns
- nodeslist(Node)
list of node objects
Examples
>>> list_of_nodes = femfile.get_nodes()
-
get_partByID
(id)¶ - Parameters
- idint or list of int
id or ids of the part in the file
- Returns
- partsPart or list of Parts
output depending on arguments
- Raises
- ValueError
if some
id
does not exist.
Examples
>>> part = femfile.get_partByID(1)
-
get_partByIndex
(index)¶ - Parameters
- indexint or list of int
index or indexes of the part in the file
- Returns
- partsPart or list of Parts
output depending on arguments
- Raises
- ValueError
if some
index
does not exist.
Examples
>>> part = femfile.get_partByIndex(0)
-
get_partByName
(name)¶ - Parameters
- namestr
name of the part
- Returns
- partsPart
part with the given name
- Raises
- ValueError
if a part with
name
does not exist.
Examples
>>> part = femfile.get_partByName("Lower Bumper")
-
get_parts
()¶ - Returns
- partslist(Part)
list of all parts in the file
Examples
>>> list_of_all_parts = femfile.get_parts()
-
get_timesteps
()¶ Get the simulation time of the written states.
- Returns
- timestepsnp.ndarray
state timesteps of the D3plot
Examples
>>> d3plot = D3plot("path/to/d3plot") >>> time = d3plot.get_timesteps()
-
get_title
()¶ Get the title of the d3plot, which is part of the header data.
- Returns
- titlestr
the title of the d3plot
Examples
>>> d3plot = D3plot("path/to/d3plot") >>> d3plot.get_title() "Barrier Impact"
-
info
()¶ Prints a summary of the header data of the D3plot, which involves node info, element info, written state data and so forth.
Examples
>>> d3plot = D3plot("path/to/d3plot") >>> d3plot.info()
-
plot
(self, iTimestep=0, element_result=None, fringe_bounds=[None, None], export_filepath=None)¶ Plot the D3plot, currently shells only!
- Parameters
- iTimestepint
timestep at which to plot the D3plot
- element_resultstr or function
which type of results to use as fringe None means no fringe is used. When using string as arg you may use plastic_strain or energy. Function shall take elem as input and return a float value (for fringe)
- fringe_boundslist(float,float) or tuple(float,float)
bounds for the fringe, default will use min and max value
- export_filepathstr
optional filepath for saving. If none, the model is exported to a temporary file and shown in the browser.
Examples
Load a d3plot and plot it’s geometry
>>> d3plot = D3plot("path/to/d3plot") >>> d3plot.plot() # just geometry
Read the state data and plot in deformed state
>>> # read state data >>> d3plot.read_states(["disp","plastic_strain max"]) >>> d3plot.plot(iTimestep=-1) # last state
Use a user-defined element evaluation function for fringe colors.
>>> # User defined evaluation function >>> def eval_fun(element): >>> res = element.get_plastic_strain() >>> if len(res): # some elements may miss plastic strain >>> return res[-1] # last timestep >>> >>> d3plot.plot(iTimestep=-1, element_result=eval_fun, fringe_bounds=[0, 0.05])
-
static
plot_parts
(parts, iTimestep=0, element_result=None, fringe_bounds=[None, None], export_filepath=None)¶ Plot a selected group of parts.
- Parameters
- partsPart or list(Part)
parts to plot. May be from different files.
- iTimestepint
timestep at which to plot the D3plot
- element_resultstr or function
which type of results to use as fringe None means no fringe is used When using string as arg you may use plastic_strain or energy. Function shall take elem as input and return a float value (for fringe)
- fringe_boundslist(float,float) or tuple(float,float)
bounds for the fringe, default will use min and max value
- export_filepathstr
optional filepath for saving. If none, the model is exported to a temporary file and shown in the browser.
Notes
Can be applied to parts, coming from different files.
Examples
For a full description of plotting functionality, see d3plot.plot. Load a d3plot and plot a part from it:
>>> d3plot_1 = D3plot("path/to/d3plot_1") >>> part_1 = d3plot_1.get_partByID(1) >>> D3plot.plot_parts( [part_1] ) # static function!
Read a second d3plot and plot both parts at once
>>> d3plot_2 = D3plot("path/to/d3plot_2") # different file! >>> part_2 = d3plot_2.get_partByID(14) >>> D3plot.plot_parts( [part_1, part_2] )
-
read_states
(vars)¶ - Parameters
- varsstr or list(str)
variable or list of variables to read (see Notes below)
Notes
Read a variable from the state files. If this is not done, the nodes and elements return empty vectors when requesting a result. The variables available are:
disp (displacement)
vel (velocity)
accel (acceleration)
strain [(optional) mode]
stress [(optional) mode]
stress_mises [(optional) mode]
plastic_strain [(optional) mode]
history [id1] [id2] [shell or solid] [(optional) mode]
There is an optional mode for the element results. The results are only given at the center of an element. Since shell elements have multiple layers of results, the optional mode determines the treatment of these layers:
inner (first layer)
mid (middle)
outer (last layer)
mean
max
min
Examples
>>> d3plot = D3plot("path/to/d3plot") # just geometry >>> node = d3plot.get_nodeByID(1) >>> len( node.get_disp() ) # no disps loaded 0 >>> # Read displacements >>> d3plot.read_states("disp") >>> len( node.get_disp() ) # here they are 31 >>> # multi-loading, already loaded will be skipped >>> d3plot.read_states(["disp","vel","stress_mises max","shell history 1 mean"]) >>> # most efficient way, load the results directly when opening >>> D3plot("path/to/d3plot", read_states=["disp","vel","plastic_strain max"])