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.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.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.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: int#

Type of the element.

Returns

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

Return type

int

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.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.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.static_rst)
>>> elements = model.metadata.meshed_region.elements
>>> elements.n_elements
8
element_by_id(id) ansys.dpf.core.elements.Element#

Retrieve an element by element ID.

Parameters

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

Returns

Element object.

Return type

Element

element_by_index(index) ansys.dpf.core.elements.Element#

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: ansys.dpf.core.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.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.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.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.static_rst)
>>> elements = model.metadata.meshed_region.elements
>>> field = elements.connectivities_field
>>> field.get_entity_data(1)
array([ 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 proprty 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.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.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)
>>> ind
array([0, 1, 2, 3, 4, 5, 6, 7])
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

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

Types of elements available in a dpf’s mesh.

General#
All#
Tet10#
Hex20#
Wedge15#
Pyramid13#
Tri6#
TriShell6#
Quad8#
QuadShell8#
Line3#
Point1#
Tet4#
Hex8#
Wedge6#
Pyramid5#
Tri3#
TriShell3#
Quad4#
QuadShell4#
Line2#
NumElementTypes#
Unknown#
EMagLine#
EMagArc#
EMagCircle#
Surface3#
Surface4#
Surface6#
Surface8#
Edge2#
Edge3#
Beam3#
Beam4#
GeneralPlaceholder#
Polygon#
Polyhedron#
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.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'