Elements

class ansys.dpf.core.elements.Element(mesh, elementid, index, nodes)
An element of the mesh. Encapsulates all the properties of an element:

its id, index, element type, element shape, connectivity…

Created from a MeshedRegion.

Parameters
  • mesh (MeshedRegion) – MeshedRegion containing this element.

  • elementid (int) – Element ID. This is the element number corresponding to the element.

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

  • nodes (list[Node]) – 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 the nodes in this element

Returns

node_ids – IDs of all the nodes in this element

Return type

list[int]

Examples

>>> 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

Element number

property index: int

Index of the element in the result (int starting at 0)

property nodes

List of Nodes

Returns

nodes

Return type

list[Node]

Examples

>>> first_node = element.nodes[0]
property n_nodes: int

Number of nodes

property type: int

Element type of this element.

Returns

element_type

Return type

element_types

Examples

>>> element.type
<element_types.Hex20: 1>
property shape: str

Element shape.

Can be 'shell', 'solid', 'beam', or 'unknown_shape'.

Examples

>>> element.shape
'solid'
property connectivity

Return the ordered list of node indices of the element

Returns

connectivity

Return type

list[int]

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

Elements belonging to a 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

Return an element using its element number (id).

Parameters

id (int) – Element number.

Returns

DPF Element

Return type

Element

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

Return an element using its index.

Parameters

index (int) – Zero-based index.

Returns

element

Return type

Element.

Examples

elements.element_by_index(0)

Notes

This is equivalent to elements[0]

add_elements(num)

Add num new elements in the mesh. add_elements yields num element that the user can fill

Parameters

num (int) – number of elements to add

Returns

yield element – element to add

Return type

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)

Appends a new solid 3D element in the mesh

Parameters
  • id (int) – new element’s id

  • connectivity (list of int) – list of node indices connected to the the element

add_shell_element(id, connectivity)

Appends a new shell 2D element in the mesh

Parameters
  • id (int) – new element’s id

  • connectivity (list of int) – list of node indices connected to the the element

add_beam_element(id, connectivity)

Appends a new beam 1D element in the mesh

Parameters
  • id (int) – new element’s id

  • connectivity (list of int) – list of node indices connected to the the element

add_point_element(id, connectivity)

Appends a new point element (1 node connectivity) in the mesh

Parameters
  • id (int) – new element’s id

  • connectivity (list of int) – list of node indices connected to the the element

add_element(id, shape, connectivity)

Appends a new element in the mesh

Parameters
  • id (int) – new element’s id

  • shape (str) – shape of the element, expected are “solid”, “shell”, “beam” or “unknown_shape”

  • connectivity (list of int) – list of node indices connected to the the element

property scoping: ansys.dpf.core.scoping.Scoping

The Scoping of the elements.

Examples

>>> my_scoping = elements.scoping
property element_types_field

Element types field

Returns

element_types_field – Field of all the element types.

Return type

core.Field

Examples

>>> field = elements.element_types_field
>>> field.data
array([1, 1, 1, 1, 1, 1, 1, 1])
property materials_field

Materials field

Returns

materials_field – Field of all the materials ids.

Return type

core.Field

Examples

Extract the material ids from the materials_field

>>> elements.materials_field.data
array([1, 1, 1, 1, 1, 1, 1, 1])
property connectivities_field

field containing for each element id the nodes indices connected to the given element

Returns

connectivities_field – Field of the node indices associated to each element.

Return type

Field

Examples

>>> 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])
Type

Connectivity field

property n_elements: int

Number of elements

property mapping_id_to_index: dict

Mapping between the ids and indices of the entity.

Useful for mapping scalar results from a field to this meshed region.

Examples

>>> meshed_region.nodes.mapping_id_to_index
{1: 0, 2: 1, 3: 2, 4: 3}
map_scoping(external_scope)

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

Parameters

external_scope (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

Returns true if at list one element is a 2D element (shell)

property has_solid_elements: bool

Returns true if at list one element is a 3D element (solid)

property has_beam_elements: bool

Returns true if at list one element is a 1D beam element

property has_point_elements: bool

Returns true if at list one element is a point element

class ansys.dpf.core.elements.ElementAdder

A class used to add new elements into a meshed region

id
Type

int

connectivity

ordered list of node indices of the element

Type

list of int

shape

“solid”, “shell”, “beam” or “unknown_shape”

Type

str

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 shape: str

Gives the element shape

Returns

shape – “solid”, “shell”, “beam” or “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