ansys.dyna.core.lib.deck_plotter#

Module for plotting decks.

Functions#

get_nid_to_index_mapping(→ numpy.ndarray)

Create array-based node ID to index mapping.

merge_keywords(→ Tuple[pandas.DataFrame, Dict])

Merge mesh keywords.

process_nodes(nodes_df)

Process nodes DataFrame to extract XYZ coordinates as a numpy array.

shell_facet_array(→ numpy.array)

Get the shell facet array from the DataFrame.

solid_array(solids)

Get the solid array from the DataFrame.

line_array(→ numpy.array)

Convert DataFrame to lines array.

map_facet_nid_to_index(→ numpy.array)

Convert node IDs to indices using array-based mapping.

extract_shell_facets(shells, mapping)

Extract shell faces from DataFrame - returns triangles and quads separately.

extract_lines(→ numpy.ndarray)

Extract lines from DataFrame.

extract_solids(solids, mapping)

Extract solid elements from DataFrame (optimized vectorized version).

get_pyvista()

Method to import pyvista, raising an exception if not installed.

is_jupyter_environment()

Check if code is running in a Jupyter notebook environment.

get_polydata(deck[, cwd, extract_surface])

Create the PolyData Object for plotting from a given deck with nodes and elements.

plot_deck(deck, **args)

Plot the deck with automatic Jupyter notebook support.

Module Contents#

ansys.dyna.core.lib.deck_plotter.get_nid_to_index_mapping(nodes) numpy.ndarray[source]#

Create array-based node ID to index mapping.

Returns an array where mapping[nid] = index. This is much faster than dict-based lookup (5000x+ speedup).

ansys.dyna.core.lib.deck_plotter.merge_keywords(deck: ansys.dyna.core.Deck) Tuple[pandas.DataFrame, Dict][source]#

Merge mesh keywords.

Given a deck, merges specific keywords (NODE, ELEMENT_SHELL, ELEMENT_BEAM, ELEMENT_SOLID) and returns tham as data frames.

ansys.dyna.core.lib.deck_plotter.process_nodes(nodes_df)[source]#

Process nodes DataFrame to extract XYZ coordinates as a numpy array.

ansys.dyna.core.lib.deck_plotter.shell_facet_array(facets: pandas.DataFrame) numpy.array[source]#

Get the shell facet array from the DataFrame.

Facets are a pandas frame that is a sequence of integers or NAs with max length of 8. valid rows contain 3,4,6, or 8 items consecutive from the left. we don’t plot quadratic edges so 6/8 collapse to 3/4 invalid rows are ignored, meaning they return an empty array return an array of length 4 or 5 using the pyvista spec for facets which includes a length prefix [1,2,3]=>[3,1,2,3] [1,2,3,0]=>[3,1,2,3] [1,2,3,NA]=>[3,1,2,3]

ansys.dyna.core.lib.deck_plotter.solid_array(solids: pandas.DataFrame)[source]#

Get the solid array from the DataFrame.

Solids are a pandas frame that is a sequence of integers or NAs with max length of 28. valid rows contain 3, 4, 6, or 8 items consecutive from the left. We don’t plot quadratic edges so 6/8 collapse to 3/4 invalid rows are ignored, meaning they return an empty array return an array of length 4 or 5 using the pyvista spec for facets which includes a length prefix [1,2,3]=>[3,1,2,3] [1,2,3,0]=>[3,1,2,3] [1,2,3,NA]=>[3,1,2,3]

ansys.dyna.core.lib.deck_plotter.line_array(lines: pandas.DataFrame) numpy.array[source]#

Convert DataFrame to lines array.

lines is a pandas frame that is a sequence of integers or NAs with max length of 2. valid rows contain 2 items consecutive from the left. invalid rows are ignored, meaning they return an empty array return an array of length 3 using the pyvista spec for facets which includes a length prefix [1,2,]=>[2,1,2] [1,2,3,0]=>[] [1,2,3,NA]=>[]

ansys.dyna.core.lib.deck_plotter.map_facet_nid_to_index(flat_facets: numpy.array, mapping: numpy.ndarray) numpy.array[source]#

Convert node IDs to indices using array-based mapping.

Given a flat list of facets or lines, use the mapping array to convert node IDs to Python indices for PyVista visualization.

The mapping is a numpy array where mapping[nid] = index.

ansys.dyna.core.lib.deck_plotter.extract_shell_facets(shells: pandas.DataFrame, mapping: numpy.ndarray)[source]#

Extract shell faces from DataFrame - returns triangles and quads separately.

Shells table comes in with the form | eid | nid1 | nid2 | nid3 | nid4 | 1 | 10 | 11 | 12 | | 20 | 21 | 22 | 23 | 24

Returns triangles and quads in separate arrays (already prefixed with count): - Triangles: [3, n1, n2, n3, 3, n1, n2, n3, …] - Quads: [4, n1, n2, n3, n4, 4, n1, n2, n3, n4, …]

Elements with fewer than 3 valid nodes are skipped.

Returns:
tuple

(triangles, tri_eids, tri_pids, quads, quad_eids, quad_pids)

ansys.dyna.core.lib.deck_plotter.extract_lines(beams: pandas.DataFrame, mapping: numpy.ndarray) numpy.ndarray[source]#

Extract lines from DataFrame.

Beams table comes in with the form with extra information not supported, | eid | nid1 | nid2 | 1 | 10 | 11 | 20 | 21 | 22

we only care about nid 1 and 2

but the array needed for pyvista polydata is the same as in extract facets of the form where each element is prefixed by the length of the element node list [2,10,11,2,21,22]

Take individual rows, extract the appropriate nid’s and output a flat list of facets for pyvista

ansys.dyna.core.lib.deck_plotter.extract_solids(solids: pandas.DataFrame, mapping: numpy.ndarray)[source]#

Extract solid elements from DataFrame (optimized vectorized version).

ansys.dyna.core.lib.deck_plotter.get_pyvista()[source]#

Method to import pyvista, raising an exception if not installed.

ansys.dyna.core.lib.deck_plotter.is_jupyter_environment()[source]#

Check if code is running in a Jupyter notebook environment.

Returns:
bool

True if running in Jupyter notebook/lab, False otherwise.

ansys.dyna.core.lib.deck_plotter.get_polydata(deck: ansys.dyna.core.Deck, cwd=None, extract_surface=True)[source]#

Create the PolyData Object for plotting from a given deck with nodes and elements.

Parameters:
deckDeck

The deck to plot

cwdstr, optional

Current working directory for expanding includes

extract_surfacebool, default=True

If True, extract only the exterior surface for solid elements. This dramatically improves performance for large solid meshes with no visual difference, since only the surface is visible anyway. Set to False to include all cells.

Returns:
pyvista.UnstructuredGrid

UnstructuredGrid containing the mesh for visualization

ansys.dyna.core.lib.deck_plotter.plot_deck(deck, **args)[source]#

Plot the deck with automatic Jupyter notebook support.

Parameters:
deckDeck

The deck to plot

cwdstr, optional

Current working directory for expanding includes

jupyter_backendstr, optional

Jupyter backend to use. Options are ‘static’, ‘server’, ‘trame’, or None. If not specified, automatically detects Jupyter environment and uses ‘static’. Set to None to disable Jupyter mode explicitly.

colorstr, optional

Color of the mesh

scalarsstr, optional

Scalars to color by (e.g., ‘part_ids’, ‘element_ids’)

**args

Additional keyword arguments passed to pyvista.plot()

Returns:
pyvista plot or camera position

Depends on the plotting backend used