Elements#

class ansys.dpf.core.elements.Element(mesh, elementid, index, nodes)#

Contains all properties of an element of a mesh.

The element is created from the MeshedRegion class. Properties include the element ID, index, type, shape, and connectivity.

Parameters:
  • mesh (ansys.dpf.core.meshed_region.MeshedRegion) – Mesh containing the element.

  • elementid (int) – Number (ID) of the element.

  • index (int) – Fortran-based (1-based) index of the element in the result.

  • nodes (list) – List of DPF nodes belonging to the element.

Examples

Extract a single element from a meshed region.

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> element = elements[0]

List the coordinates belonging to the first node of the element.

>>> element.nodes[0].coordinates
[0.015, 0.045, 0.015]
property node_ids#

IDs of all nodes in the element.

Returns:

List of IDs for all nodes in the element.

Return type:

list

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> element = elements[0]
>>> element.node_ids
[1, 26, 14, 12, 2, 27, 15, 13, 33, 64, 59, 30, 37, 65, 61, 34, 28, 81, 63, 58]
property id: int#

ID of the element.

Returns:

ID of the element.

Return type:

int

property index: int#

Index of the element in the result.

Returns:

Index of the element in the result. This uses zero-based indexing starting at 0.

Return type:

int

property nodes#

All nodes in the element. :returns: List of all nodes in the element. :rtype: list

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> element = elements[0]
>>> first_node = element.nodes[0]
property n_nodes: int#

Number of nodes in the element.

Returns:

Number of nodes.

Return type:

int

property type: element_types#

Type of the element.

Returns:

Type of the element. For more information, see ansys.dpf.core.elements.element_types.

Return type:

element_types

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> element = elements[0]
>>> element.type
<element_types.Hex20: 1>
property shape: str#

Shape of the element.

Returns:

Shape of the element, which can be "shell", "solid", "beam", or "unknown_shape".

Return type:

str

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> element = elements[0]
>>> element.shape
'solid'
property connectivity#

Ordered list of node indices of the element.

Returns:

Ordered list of node indices.

Return type:

list

class ansys.dpf.core.elements.Elements(mesh)#

Contains elements belonging to a meshed region.

Parameters:

mesh (str) – Name of the meshed region.

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> elements.n_elements
8
element_by_id(id)#

Retrieve an element by element ID.

Parameters:

id (int) – Number (ID) of the element.

Returns:

Element object.

Return type:

Element

element_by_index(index)#

Retrieve an element using its index.

Parameters:

index (int) – Zero-based index.

Returns:

Yield element.

Return type:

ansys.dpf.core.elements.ElementAdder

Examples

elements.element_by_index(0)

Notes

This is equivalent to elements[0]

add_elements(num)#

Add one or more elements in the mesh.

Parameters:

num (int) – Number of elements to add in the mesh.

Returns:

Elements added to the mesh.

Return type:

ansys.dpf.core.elements.ElementAdder

Examples

>>> import ansys.dpf.core as dpf
>>> meshed_region = dpf.MeshedRegion(num_nodes=4,num_elements=3)
>>> i=0
>>> for node in meshed_region.nodes.add_nodes(4):
...     node.id = i+1
...     node.coordinates = [float(i), float(i), 0.0]
...     i=i+1
>>> i=0
>>> for element in meshed_region.elements.add_elements(3):
...     element.id=i+1
...     element.connectivity = [i, i+1]
...     element.is_beam=True #or is_solid, is_beam, is_point
...     i=i+1
add_solid_element(id, connectivity)#

Add a solid 3D element in the mesh.

Parameters:
  • id (int) – ID to assign the new element.

  • connectivity (list) – List of the node indices to connect to the new element.

add_shell_element(id, connectivity)#

Add a shell 2D element in the mesh.

Parameters:
  • id (int) – ID to assign the new element.

  • connectivity (list) – List of the node indices to connect to the new element.

add_beam_element(id, connectivity)#

Add a beam 1D element in the mesh.

Parameters:
  • id (int) – ID to assign the new element.

  • connectivity (list) – List of the node indices to connect to the new element.

add_point_element(id, connectivity)#

Add a point element (one node connectivity) in the mesh.

Parameters:
  • id (int) – ID to assign the new element.

  • connectivity (list) – List of the node indices to connect to the new element.

add_element(id, shape, connectivity)#

Add an element in the mesh.

Parameters:
  • id (int) – ID to assign the new element.

  • shape (str) – Shape of the element. Options are "solid", "shell", "beam" and "unknown_shape".

  • connectivity (list) – List of the node indices to connect to the new element.

property scoping: scoping.Scoping#

Scoping of the elements.

Return type:

ansys.dpf.core.scoping.Scoping

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> my_scoping = elements.scoping
property element_types_field#

Field of all element types.

Returns:

Field of all element types.

Return type:

ansys.dpf.core.field.Field

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> field = elements.element_types_field
>>> print(field.data)
[1 1 1 1 1 1 1 1]
property materials_field#

Field of all material IDs.

Returns:

Field of all materials IDs.

Return type:

ansys.dpf.core.field.Field

Examples

Extract the material IDs from the materials_field

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> print(elements.materials_field.data)
[1 1 1 1 1 1 1 1]
property connectivities_field#

Field containing for each element ID the node indices connected to the element.

Returns:

Field containing for each element ID the node indices connected to the element.

Return type:

ansys.dpf.core.field.Field

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> field = elements.connectivities_field
>>> field.get_entity_data(1)
DPFArray([ 0, 11, 13, 25,  2,  9,  8,  3, 29, 58, 63, 32, 40, 52, 42, 37, 28,
       55, 53, 43]...
property n_elements: int#

Number of elements

property mapping_id_to_index: dict#

Mapping between the IDs and indices of the entity.

This property is useful for mapping scalar results from a field to the meshed region.

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_simple_bar())
>>> meshed_region = model.metadata.meshed_region
>>> map = meshed_region.nodes.mapping_id_to_index
map_scoping(external_scope)#

Retrieve the indices to map the scoping of these elements to the scoping of a field.

Parameters:

external_scope (ansys.dpf.core.scoping.Scoping) – Scoping to map to.

Returns:

  • indices (numpy.ndarray) – List of indices to map from the external scope to the scoping of these elements.

  • mask (numpy.ndarray) – Members of the external scope that are in the element scoping.

Examples

Return the indices that map a field to an elements collection.

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> vol = model.results.elemental_volume()
>>> field = vol.outputs.fields_container()[0]
>>> ind, mask = elements.map_scoping(field.scoping)
property has_shell_elements: bool#

Whether at least one element is a 2D element (shell).

Return type:

bool

property has_solid_elements: bool#

Whether at list one element is a 3D element (solid).

Return type:

bool

property has_beam_elements: bool#

Whether at least one element is a 1D beam element.

Return type:

bool

property has_point_elements: bool#

Whether at least one element is a point element.

Return type:

bool

class ansys.dpf.core.elements.ElementAdder#

Provides for adding new elements in a meshed region.

Parameters:
  • id (int) – ID to assign to the new element.

  • shape (str) – Shape of the element. Options are "solid", "shell", "beam" and "unknown_shape".

  • connectivity (list) – List of the node indices to connect to the new element.

Examples

Create a meshed region from scratch.

>>> import ansys.dpf.core as dpf
>>> meshed_region = dpf.MeshedRegion(num_nodes=4, num_elements=1)
>>> i=0
>>> for node in meshed_region.nodes.add_nodes(4):
...     node.id = i+1
...     node.coordinates = [float(i), float(i), 0.0]
...     i=i+1
>>> for element in meshed_region.elements.add_elements(1):
...     element.id=1
...     element.connectivity = range(0,4)
...     element.is_shell=True #or is_solid, is_beam, is_point
property is_solid: bool#

Whether the element is a solid.

Return type:

bool

property is_shell: bool#

Whether the element is a shell.

Return type:

bool

property is_beam: bool#

Whether the element is a beam.

Return type:

bool

property is_point: bool#

Whether the element is a point.

Return type:

bool

property shape: str#

Shape of the element.

Returns:

Shape of the element. Options are "solid", "shell", "beam" and "unknown_shape".

Return type:

str

enum ansys.dpf.core.elements.element_types(value)#

Types of elements available in a dpf’s mesh.

Valid values are as follows:

General = <element_types.General: -2>#
All = <element_types.All: -1>#
Tet10 = <element_types.Tet10: 0>#
Hex20 = <element_types.Hex20: 1>#
Wedge15 = <element_types.Wedge15: 2>#
Pyramid13 = <element_types.Pyramid13: 3>#
Tri6 = <element_types.Tri6: 4>#
TriShell6 = <element_types.TriShell6: 5>#
Quad8 = <element_types.Quad8: 6>#
QuadShell8 = <element_types.QuadShell8: 7>#
Line3 = <element_types.Line3: 8>#
Point1 = <element_types.Point1: 9>#
Tet4 = <element_types.Tet4: 10>#
Hex8 = <element_types.Hex8: 11>#
Wedge6 = <element_types.Wedge6: 12>#
Pyramid5 = <element_types.Pyramid5: 13>#
Tri3 = <element_types.Tri3: 14>#
TriShell3 = <element_types.TriShell3: 15>#
Quad4 = <element_types.Quad4: 16>#
QuadShell4 = <element_types.QuadShell4: 17>#
Line2 = <element_types.Line2: 18>#
NumElementTypes = <element_types.NumElementTypes: 19>#
Unknown = <element_types.Unknown: 20>#
EMagLine = <element_types.EMagLine: 21>#
EMagArc = <element_types.EMagArc: 22>#
EMagCircle = <element_types.EMagCircle: 23>#
Surface3 = <element_types.Surface3: 24>#
Surface4 = <element_types.Surface4: 25>#
Surface6 = <element_types.Surface6: 26>#
Surface8 = <element_types.Surface8: 27>#
Edge2 = <element_types.Edge2: 28>#
Edge3 = <element_types.Edge3: 29>#
Beam3 = <element_types.Beam3: 30>#
Beam4 = <element_types.Beam4: 31>#
GeneralPlaceholder = <element_types.GeneralPlaceholder: 32>#
Polygon = <element_types.Polygon: 33>#
Polyhedron = <element_types.Polyhedron: 34>#

The Enum and its members also have the following methods:

static shape(element_type)#

Retrieve the shape of the element.

Return type:

type

static descriptor(element_type)#

Retrieve element information.

This method provides access to an instance of the ElementDescriptor of the requested element to retrieve such information as the number of nodes and shape.

Parameters:

element_type (int) – Type of the elemment.

Returns:

Element descriptor instance that provides element information.

Return type:

ElementDescriptor

Examples

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> elements = model.metadata.meshed_region.elements
>>> element = elements[0]
>>> type_of_element = element.type
>>> type_of_element
<element_types.Hex20: 1>
>>> element_descriptor = dpf.element_types.descriptor(type_of_element)
>>> element_descriptor.name
'hex20'
>>> element_descriptor.description
'Quadratic 20-nodes Hexa'