sdynpy.core.sdynpy_geometry.Geometry

class Geometry(node=   Index, ID, X, Y, Z, DefCS, DisCS ----------- Empty -------------, coordinate_system=   Index, ID, Name, Color, Type ----------- Empty -------------, traceline=   Index, ID, Description, Color, # Nodes ----------- Empty -------------, element=   Index, ID, Type, Color, # Nodes ----------- Empty -------------)[source]

Bases: object

Container for nodes, coordinate systems, tracelines, and elements

Geometry is the class that is most useful for working with the positioning and spatial visualization of test or analysis data. It contains functions to plot and animate 3D geometry

__init__(node=   Index, ID, X, Y, Z, DefCS, DisCS ----------- Empty -------------, coordinate_system=   Index, ID, Name, Color, Type ----------- Empty -------------, traceline=   Index, ID, Description, Color, # Nodes ----------- Empty -------------, element=   Index, ID, Type, Color, # Nodes ----------- Empty -------------)[source]

Initialize a geometry object with nodes, coordinate systems, tracelines, and elements.

All input arguments will be flattened when passed to the Geometry, as the geometry does not support multi-dimensional object arrays.

Parameters
  • node (NodeArray, optional) – The set of nodes in the geometry. The default is NodeArray((0,)), an empty NodeArray.

  • coordinate_system (CoordinateSystemArray, optional) – The set of coordinate systems in the geometry. The default is CoordinateSystemArray((0,)), an empty CoordinateSystemArray

  • traceline (TracelineArray, optional) – The set of tracelines defined in the geometry. The default is TracelineArray((0,)), an empty TracelineArray

  • element (ElementArray, optional) – The set of elements defined in the geometry. The default is ElementArray((0,)), an empty element array.

Return type

None.

Methods

__init__([node, coordinate_system, ...])

Initialize a geometry object with nodes, coordinate systems, tracelines, and elements.

add_element(elem_type, connectivity[, id, color])

add_traceline(connectivity[, id, ...])

Adds a traceline to the geometry

camera_visualization(K, RT, image_size[, ...])

Create a geometry used to visualize a camera specified with K and RT

compress_ids([compress_nodes, ...])

Compresses ID numbers to make node, element, etc.

copy()

Return's a copy of the current Geometry

from_exodus(exo[, blocks, local, ...])

Generate a geometry from exodus file data

from_imat_struct(imat_fem_struct)

Constructs a Geometry from an imat_fem class saved to a Matlab structure

from_uff(unv_dict)

Create a geometry from universal file format data from readunv

from_unv(unv_dict)

Create a geometry from universal file format data from readunv

global_deflection(coordinate_array)

Direction of local deflection in the global coordinate system

global_node_coordinate([node_ids])

Position of the Geometry's nodes in the global coordinate system

load(filename)

Loads a geometry from a numpy .npz or .unv file

map_ids([node_id_map, traceline_id_map, ...])

Maps id numbers from an original set of ids to a new set of ids.

modify_ids([node_change, traceline_change, ...])

Shifts the id numbers in the geometry

node_by_global_position(global_position_array)

Select node by closest position

overlay_geometries(geometries[, ...])

Combines several geometries, offsetting the id numbers to avoid conflicts

plot([node_size, line_width, opacity, ...])

Plots the geometry in an interactive 3D window.

plot_coordinate([coordinates, arrow_scale, ...])

Plots coordinate arrows on the geometry

plot_deflection_shape(deflection_shape_data)

Plot deflection shapes shapes on the geometry

plot_shape(shape[, plot_kwargs, ...])

Plot mode shapes on the geometry

plot_transient(displacement_data[, ...])

Create a TransientPlotter object to plot displacements over time

reduce(node_list)

Reduce the geometry to only contain nodes in node_list

rigid_body_shapes(coordinates[, mass, ...])

Creates a set of shapes corresponding to the rigid body motions

save(filename)

Saves the geometry to a numpy .npz file

write_to_unv(filename[, write_nodes, ...])

Write the geometry to a unversal file format file

add_element(elem_type, connectivity, id=None, color=1)[source]
add_traceline(connectivity, id=None, description='', color=1)[source]

Adds a traceline to the geometry

Parameters
  • connectivity (iterable) – Iterable containing the node_ids to connect with the traceline

  • id (TYPE, optional) – The id number of the new traceline. The default is None, which results in the new traceline having an id of one greater than the current maximum traceline it.

  • description (str, optional) – A string description of the new traceline. The default is ‘’.

  • color (int, optional) – An integer corresponding to the color of the new traceline. The default is 1.

Return type

None. Modifications are made in-place to the current geometry.

classmethod camera_visualization(K, RT, image_size, size=1, colors=1)[source]

Create a geometry used to visualize a camera specified with K and RT

Parameters
  • K (ndarray) – A (…,3,3) matrix containing the intrinsic parameters of the cameras

  • RT (ndarray) – A (…,3,4) matrix containing the extrinsic parameters of the cameras

  • image_size (ndarray) – A (…,2) matrix containing the width,height of each camera

  • size (float) – The distance that the rays will project from the pinhole of the camera

  • colors (int or ndarray) – The colors assigned to each camera

Returns

geometry – A geoemtry containing the cameras that can be used for visualization

Return type

cls

compress_ids(compress_nodes=True, compress_elements=True, compress_tracelines=True, compress_cs=True, return_maps=False)[source]

Compresses ID numbers to make node, element, etc. contiguous

Parameters
  • compress_nodes (bool, optional) – If True, compress the node ids. The default is True.

  • compress_elements (bool, optional) – If True, compress the element ids. The default is True.

  • compress_tracelines (bool, optional) – If True, compress the traceline ids. The default is True.

  • compress_cs (bool, optional) – If True, compress the coordinate system ids. The default is True.

  • return_maps (bool, optional) – If True, return id maps for nodes, elements, tracelines, and coordinate systems. Maps will be equal to None if no compression was done on that field. The default is False.

Returns

  • mapped_geometry (Geometry) – Geometry with contiguous id numbers for the selected fields.

  • node_map (id_map or None) – Mapping from the old set of nodes to the new set of nodes, only returned if return_maps is True. If compress_nodes is False, this will be None.

  • traceline_map (id_map or None) – Mapping from the old set of tracelines to the new set of tracelines, only returned if return_maps is True. If compress_tracelines is False, this will be None.

  • element_map (id_map or None) – Mapping from the old set of elements to the new set of elements, only returned if return_maps is True. If compress_elements is False, this will be None.

  • cs_map (id_map or None) – Mapping from the old set of coordinate systems to the new set of coordinate systems, only returned if return_maps is True. If compress_cs is False, this will be None.

copy()[source]

Return’s a copy of the current Geometry

Changes to the copy will not also be applied to the original geometry

Returns

A copy of the current Geometry

Return type

Geometry

classmethod from_exodus(exo: Exodus, blocks=None, local=False, preferred_local_orientation=array([0., 0., 1.]), secondary_preferred_local_orientation=array([1., 0., 0.]), local_nodes=None)[source]

Generate a geometry from exodus file data

Parameters
  • exo (Exodus or ExodusInMemory) – The exodus data from which geometry will be created.

  • blocks (iterable, optional) – Iterable containing a set of block ids to import when creating the geometry. The default is None, which uses all blocks in the model.

  • local (bool, optional) – Flag to specify whether or not to create local coordinate systems for each node in the model. This can be useful when creating instrumnetation positions from a finite element model, where the sensor will be oriented perpendicular to the surface it is mounted on. The default is False, which returns all data in a single global coordinate system.

  • preferred_local_orientation (np.ndarray, optional) – A preferred direction for the local coordinate system. The first constraint is that the local Z+ axis is perpendicular to the surface. The coordinate system will then try to align itself as much as it can with this direction. The default is np.array((0.0,0.0,1.0)), which points the local coordinate systems along the global Z+ axis.

  • secondary_preferred_local_orientation (np.ndarray, optional) – A secondary preferred direction is only used if the surface normal direction is parallel to the primary preferred_local_orientation. The default is np.array((1.0,0.0,0.0)), which points the local coordinate system along the local Z+ axis.

  • local_nodes (np.ndarray, optional) – If specified, only create local coordinate systems at the specified nodes.

Returns

A geometry consisting of the finite element nodes and element connectivity.

Return type

Geometry

classmethod from_imat_struct(imat_fem_struct)[source]

Constructs a Geometry from an imat_fem class saved to a Matlab structure

In IMAT, a structure can be created from an imat_fem by using the get() function. This can then be saved to a .mat file and loaded using scipy.io.loadmat. The output from loadmat can be passed into this function

Parameters

imat_fem_struct (np.ndarray) – structure from loadmat containing data from an imat_fem

Returns

Geometry constructed from the data in the imat structure

Return type

Geometry

classmethod from_uff(unv_dict)

Create a geometry from universal file format data from readunv

Parameters

unv_dict (dict) – Dictionary containing data from read_unv

Returns

Geometry object read from the unv data

Return type

Geometry

classmethod from_unv(unv_dict)[source]

Create a geometry from universal file format data from readunv

Parameters

unv_dict (dict) – Dictionary containing data from read_unv

Returns

Geometry object read from the unv data

Return type

Geometry

global_deflection(coordinate_array)[source]

Direction of local deflection in the global coordinate system

Parameters

coordinate_array (CoordinateArray) – A list of coordinates for which the global deformation direction will be computed

Returns

global_deflections – numpy array with shape (n,3) where n is the number of coordinates in the specified coordinate_array. This array contains the 3d direction of motion for each coordinate in the global coordinate system.

Return type

np.ndarray

global_node_coordinate(node_ids=None)[source]

Position of the Geometry’s nodes in the global coordinate system

Parameters

node_ids (np.ndarray) – An array of node id numbers to keep in the output coordinate. If not specified, all nodes will be returned in the order they are in the model.

Returns

numpy array with shape (n,3) where n is the number of nodes in the geometry. This array contains the 3d position of each node in the global coordinate system.

Return type

np.ndarray

classmethod load(filename)[source]

Loads a geometry from a numpy .npz or .unv file

The .npz file must have fields ‘node’, ‘coordinate_system’, ‘element’, and ‘traceline’, with each field storing the respective portion of the geometry

The .unv file will need to have the proper datasets specified to define a geometry

Parameters

filename (str) – Filename to load the geometry from.

Raises

AttributeError – Raised if the calling class does not have a from_unv method defined

Returns

Geometry constructed from the data in the loaded file

Return type

Geometry

map_ids(node_id_map=None, traceline_id_map=None, element_id_map=None, coordinate_system_id_map=None)[source]

Maps id numbers from an original set of ids to a new set of ids.

This function accepts id_map classes defining “from” and “to” ids Existing ids found in the “from” set are transformed to the corresponding id in the “to” set.

Parameters
  • node_id_map (id_map, optional) – An id_map defining the mapping applied to node ids. The default is None, which results in the ids being unchanged

  • traceline_id_map (id_map, optional) – An id_map defining the mapping applied to traceline ids. The default is None, which results in the ids being unchanged

  • element_id_map (id_map, optional) – An id_map defining the mapping applied to element ids. The default is None, which results in the ids being unchanged

  • coordinate_system_id_map (id_map, optional) – An id_map defining the mapping applied to coordinate system ids. The default is None, which results in the ids being unchanged

Returns

geom_out – A copy of the original geometry with id numbers modified

Return type

Geometry

modify_ids(node_change=0, traceline_change=0, element_change=0, coordinate_system_change=0)[source]

Shifts the id numbers in the geometry

Parameters
  • node_change (int, optional) – The amount to shift the node ids. The default is 0.

  • traceline_change (int, optional) – The amount to shift the traceline ids.. The default is 0.

  • element_change (int, optional) – The amount to shift the element ids. The default is 0.

  • coordinate_system_change (int, optional) – The amount to shift the coordinate system ids. The default is 0.

Returns

geom_out – A copy of the original geometry with id numbers modified

Return type

Geometry

node_by_global_position(global_position_array)[source]

Select node by closest position

Parameters

global_position_array (np.ndarray) – A (…,3) shape array containing positions of nodes to keep

Returns

NodArray containing nodes that were closest to the positions in position_array.

Return type

NodeArray

static overlay_geometries(geometries, color_override=None, return_node_id_offset=False)[source]

Combines several geometries, offsetting the id numbers to avoid conflicts

Parameters
  • geometries (iterable) – An iterable of geometry objects that will be combined into a single geometry

  • color_override (iterable, optional) – An iterble of integers specifying colors, which will override the existing geometry colors. This should have the same length as the geometries input. The default is None, which keeps the original geometry colors.

  • return_node_id_offset (bool, optional) – Specifies whether or not the applied node offset should be returned, which is useful if the new node numbers are to be mapped to the old node numbers. The default is False, which only returns the combined geometry.

Returns

  • Geometry – A geometry consisting of a combination of the specified geometries

  • node_offset – An integer specifying the node id offset applied to avoid conflicts

plot(node_size: int = 5, line_width: int = 1, opacity=1.0, view_up=None, view_from=None, plotter=None, show_edges=False)[source]

Plots the geometry in an interactive 3D window.

Parameters
  • node_size (int, optional) – Size to display the nodes in pixels. Set to 0 to not display nodes. The default is 5.

  • line_width (int, optional) – Width to display tracelines and element edges in pixels. Set to 0 to not show tracelines or edges. The default is 1.

  • opacity (float, optional) – A float between 0 and 1 to specify the transparency of the geometry. Set to 1 for completely opaque, and 0 for completely transparent (invisible). The default is 1.0, no transparency.

  • view_up (np.ndarray, optional) – Set the “up” direction in the plot by passing in a size-3 numpy array. The default is None.

  • view_from (np.ndarray, optional) – Specify the direction from which the geometry is viewed. The default is None.

  • plotter (BackgroundPlotter, optional) – A plotter can be specified to plot the geometry in an existing plot. The default is None, which creates a new window and plot.

  • show_edges (bool, optional) – Specify whether or not to draw edges on elements. The default is False.

Raises
  • KeyError – If referenced id numbers are not found in the corresponding object, for example if a traceline references node 11 but there is no node 11 in the NodeArray

  • ValueError – If an invalid or unknown element type is used

Returns

  • plotter (BackgroundPlotter) – A reference to the plotter object that the geometry was plotted in

  • face_mesh (TYPE) – A reference to the mesh used to plot surface elements

  • point_mesh (TYPE) – A reference to the mesh used to plot nodes and tracelines

  • solid_mesh (TYPE) – A reference to the mesh used to plot volume elements

plot_coordinate(coordinates: Optional[CoordinateArray] = None, arrow_scale=0.1, arrow_scale_type='bbox', label_dofs=False, label_font_size=16, opacity=1.0, arrow_ends_on_node=False, plot_kwargs={})[source]

Plots coordinate arrows on the geometry

Parameters
  • coordinates (CoordinateArray, optional) – Coordinates to draw on the geometry. If no coordinates are specified, all translation degrees of freedom at each node will be plotted.

  • arrow_scale (float, optional) – Size of the arrows in proportion to the length of the diagonal of the bounding box of the Geometry if arrow_scale_type is ‘bbox’, otherwise the raw length of the arrow. The default is 0.1.

  • arrow_scale_type (str, optional) – Specifies how to compute the size of the arrows. If ‘bbox’, then the arrow is scaled based on the size of the geometry. Otherwise, the arrow size is the specified length. The default is ‘bbox’.

  • label_dofs (bool, optional) – Specify whether or not to label the coordinates with strings. The default is False.

  • label_font_size (int, optional) – Specifies the font size for the node labels. Default is 16.

  • opacity (float, optional) – A float between 0 and 1 to specify the transparency of the geometry. Set to 1 for completely opaque, and 0 for completely transparent (invisible). The default is 1.0, no transparency.

  • arrow_ends_on_node (bool, optional) – If True, arrow tip ends at the node, otherwise the arrow begins at node. Defualt is False

  • plot_kwargs (dict, optional) – Any additional keywords that should be passed to the Geometry.plot function. The default is {}.

Returns

plotter – A reference to the window the geometry was plotted in.

Return type

BackgroundPlotter

plot_deflection_shape(deflection_shape_data, plot_kwargs={}, background_plotter_kwargs={'editor': False}, undeformed_opacity=0.25, deformed_opacity=1.0, starting_scale=1.0)[source]

Plot deflection shapes shapes on the geometry

Parameters
  • deflection_shape_data (NDDataArray) – Data array containing the deflection shapes to plot

  • plot_kwargs (dict, optional) – Any additional keywords that should be passed to the Geometry.plot function. The default is {}.

  • background_plotter_kwargs (dict, optional) – Any additional arguments that should be passed to the BackgroundPlotter initializer. The default is {‘editor’:False}.

  • undeformed_opacity (float, optional) – A float between 0 and 1 to specify the transparency of the undeformed geometry. Set to 1 for completely opaque, and 0 for completely transparent (invisible). The default is 0.25.

  • deformed_opacity (float, optional) – A float between 0 and 1 to specify the transparency of the deformed geometry. Set to 1 for completely opaque, and 0 for completely transparent (invisible). The default is 1.0.

  • starting_scale (float, optional) – The starting scale factor of the animation. The default is 1.0.

Returns

A reference to the deflection_shape_data object that is created to plot the animated shapes

Return type

deflection_shape_data

plot_shape(shape, plot_kwargs={}, background_plotter_kwargs={'editor': False}, undeformed_opacity=0.25, deformed_opacity=1.0, starting_scale=1.0)[source]

Plot mode shapes on the geometry

Parameters
  • shape (ShapeArray) – The set of shapes to plot

  • plot_kwargs (dict, optional) – Any additional keywords that should be passed to the Geometry.plot function. The default is {}.

  • background_plotter_kwargs (dict, optional) – Any additional arguments that should be passed to the BackgroundPlotter initializer. The default is {‘editor’:False}.

  • undeformed_opacity (float, optional) – A float between 0 and 1 to specify the transparency of the undeformed geometry. Set to 1 for completely opaque, and 0 for completely transparent (invisible). The default is 0.25.

  • deformed_opacity (float, optional) – A float between 0 and 1 to specify the transparency of the deformed geometry. Set to 1 for completely opaque, and 0 for completely transparent (invisible). The default is 1.0.

  • starting_scale (float, optional) – The starting scale factor of the animation. The default is 1.0.

Returns

A reference to the ShapePlotter class that is created to plot the animated shapes

Return type

ShapePlotter

plot_transient(displacement_data, displacement_scale=1.0, frames_per_second=20, undeformed_opacity=0.0, deformed_opacity=1.0, plot_kwargs={}, transformation_shapes=None, num_curves=50, show: bool = True, app=None, window_size=None, off_screen=None, allow_quit_keypress=True, toolbar=True, menu_bar=True, editor=False, update_app_icon=None, **kwargs)[source]

Create a TransientPlotter object to plot displacements over time

Parameters
  • displacement_data (TimeHistoryArray) – Transient displacement data that will be applied

  • displacement_scale (float, optional) – Scale factor applied to displacements. The default is 1.0.

  • frames_per_second (float, optional) – Number of time steps to plot per second while the displacement is animating. Default is 20.

  • undeformed_opacity (float, optional) – Opacity of the undeformed geometry. The default is 0.0, or completely transparent.

  • deformed_opacity (float, optional) – Opacity of the deformed geometry. The default is 1.0, or completely opaque.

  • plot_kwargs (dict, optional) – Keyword arguments passed to the Geometry.plot function

  • transformation_shapes (ShapeArray) – Shape matrix that will be used to expand the data. Must be the same size as the displacement_data

  • num_curves (int, optional) – Maximum number of curves to plot on the time selector. Default is 50.

  • show (bool, optional) – Show the plotting window. If False, show this window by running show(). The default is True.

  • app (QApplication, optional) – Creates a QApplication if left as None. The default is None.

  • window_size (list of int, optional) – Window size in pixels. Defaults to [1024, 768]

  • off_screen (TYPE, optional) – Renders off screen when True. Useful for automated screenshots or debug testing. The default is None.

  • allow_quit_keypress (bool, optional) – Allow user to exit by pressing "q". The default is True.

  • toolbar (bool, optional) – If True, display the default camera toolbar. Defaults to True.

  • menu_bar (bool, optional) – If True, display the default main menu. Defaults to True.

  • editor (TYPE, optional) – If True, display the VTK object editor. Defaults to False.

  • update_app_icon (bool, optional) – If True, update_app_icon will be called automatically to update the Qt app icon based on the current rendering output. If None, the logo of PyVista will be used. If False, no icon will be set. Defaults to None. The default is None.

  • title (str, optional) – Title of plotting window.

  • multi_samples (int, optional) – The number of multi-samples used to mitigate aliasing. 4 is a good default but 8 will have better results with a potential impact on performance.

  • line_smoothing (bool, optional) – If True, enable line smothing

  • point_smoothing (bool, optional) – If True, enable point smothing

  • polygon_smoothing (bool, optional) – If True, enable polygon smothing

  • auto_update (float, bool, optional) – Automatic update rate in seconds. Useful for automatically updating the render window when actors are change without being automatically Modified. If set to True, update rate will be 1 second.

Return type

TransientPlotter

reduce(node_list)[source]

Reduce the geometry to only contain nodes in node_list

Elements and tracelines will only be kept if all nodes in each element or traceline are in node_list. Coordinate systems will only be kept if they are required by a node in node_list

Parameters

node_list (iterable) – An iterable of integer node id numbers.

Returns

A geometry only containing the nodes in node_list

Return type

Geometry

rigid_body_shapes(coordinates, mass=1, inertia=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), cg=array([0., 0., 0.]), principal_axes=False)[source]

Creates a set of shapes corresponding to the rigid body motions

Rigid body translation and rotation shapes are computed analytically from the Geoemtry

Parameters
  • coordinates (CoordinateArray) – coordinates at which to compute deformations

  • mass (float, optional) – The mass of the geometry used to scale the rigid body translation shapes. The default is 1.

  • inertia (np.ndarray, optional) – A 3x3 array consisting of the mass moments of inertia, used to scale the rotation shapes. The default is np.eye(3).

  • cg (np.ndarray, optional) – The center of gravity of the Geometry about which the rotations occur. The default is np.zeros(3).

  • principal_axes (bool, optional) – If True, compute the principal axes of the test article and perform rotations about those axes. The default is False.

Returns

output_shape – A set of rigid body shapes for the current geometry

Return type

ShapeArray

save(filename)[source]

Saves the geometry to a numpy .npz file

The .npz file will have fields ‘node’, ‘coordinate_system’, ‘element’, and ‘traceline’, with each field storing the respective portion of the geometry

Parameters

filename (str) – Filename to save the geometry to. If the filename doesn’t end with .npz, it will be appended.

Return type

None.

write_to_unv(filename, write_nodes=True, write_coordinate_systems=True, write_tracelines=True, write_elements=True, dataset_2412_kwargs={}, dataset_2420_kwargs={})[source]

Write the geometry to a unversal file format file

Parameters
  • filename (str) – Filename to which the geometry will be written. If None, a unv data dictionary will be returned instead, similar to that obtained from the readunv function in sdynpy

  • write_nodes (bool, optional) – If True, write the geometry’s nodes to dataset 2411 in the output file. The default is True.

  • write_coordinate_systems (True, optional) – If True, write the geometry’s coordinate systems to dataset 2420 in the output file. The default is True.

  • write_tracelines (bool, optional) – If True, write the geometry’s tracelines to dataset 82 in the output file. The default is True.

  • write_elements (TYPE, optional) – If True, write the geometry’s elements to dataset 2412 in the output file. The default is True.

  • dataset_2412_kwargs (dict, optional) – Allows users to specify additional element parameters not stored by the Geometry. The default is {}.

  • dataset_2420_kwargs (dict, optional) – Allows users to specify additional coordinate system parameters not stored by the Geometry. The default is {}.

Returns

unv_dict – Dictionary containing unv information, similar to that obtained from readunv. Only returned if filename is None.

Return type

dict