MeshedRegion#

class ansys.dpf.core.meshed_region.MeshedRegion(num_nodes=None, num_elements=None, mesh=None, server=None)#

Represents a mesh from DPF.

Parameters:
  • num_nodes (int, optional) – Number of nodes to reserve for mesh creation. The default is None.

  • num_elements (int, optional) – Number of elements to reserve for mesh creation. The default is None.

  • mesh (ansys.grpc.dpf.meshed_region_pb2.MeshedRegion) – The default is None.

  • server (ansys.dpf.core.server, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Examples

Extract a meshed region from a model.

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region

Create a meshed region from scratch (line with 3 beam elements).

>>> 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
>>> meshed_region.elements.add_beam_element(id=4,connectivity=[3,0])

Overview#

property_field

Property field getter. It can be coordinates (field), element types (property field)…

set_property_field

Property field setter. It can be coordinates (field), element types (property field)…

set_coordinates_field

Coordinates field setter.

named_selection

Scoping containing the list of nodes or elements in the named selection.

set_named_selection_scoping

Named selection scoping setter.

deform_by

Deforms the mesh according to a 3D vector field and an additional scale factor.

plot

Plot the field or fields container on the mesh.

deep_copy

Create a deep copy of the meshed region’s data on a given server.

field_of_properties

Return the Field or PropertyField associated to a given property of the mesh.

elements

All elemental properties of the mesh, such as connectivity and element types.

faces

All face properties of the mesh, such as faces_nodes_connectivity and face types.

nodes

All nodal properties of the mesh, such as node coordinates and nodal connectivity.

unit

Unit of the meshed region.

available_property_fields

Returns a list of available property fields.

available_named_selections

List of available named selections.

grid

Unstructured grid in VTK format from PyVista.

__del__

Delete this instance of the meshed region.

__str__

Return string representation of the meshed region.

Import detail#

from ansys.dpf.core.meshed_region import MeshedRegion

Property detail#

property MeshedRegion.elements#

All elemental properties of the mesh, such as connectivity and element types.

Returns:

elements – Elements belonging to the meshed region.

Return type:

Elements

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region
>>> elements = meshed_region.elements
>>> print(elements)
DPF Elements object with 8 elements
property MeshedRegion.faces#

All face properties of the mesh, such as faces_nodes_connectivity and face types.

Returns:

faces – Faces belonging to the meshed region.

Return type:

Faces

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region
>>> faces = meshed_region.faces
>>> print(faces)
DPF Faces object with 0 faces
property MeshedRegion.nodes#

All nodal properties of the mesh, such as node coordinates and nodal connectivity.

Returns:

nodes – Nodes belonging to the meshed region

Return type:

Nodes

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region
>>> nodes = meshed_region.nodes
>>> nodes.n_nodes
81
property MeshedRegion.unit#

Unit of the meshed region.

This unit is the same as the unit of the coordinates of the meshed region.

Returns:

unit

Return type:

str

property MeshedRegion.available_property_fields#

Returns a list of available property fields.

Returns:

available_property_fields

Return type:

list str

property MeshedRegion.available_named_selections#

List of available named selections.

Returns:

named_selections

Return type:

list str

property MeshedRegion.grid#

Unstructured grid in VTK format from PyVista.

Returns:

UnstructuredGrid of the mesh.

Return type:

pyvista.UnstructuredGrid

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region
>>> grid = meshed_region.grid

Plot this grid directly.

>>> grid.plot()

Extract the surface mesh of this grid

>>> mesh = grid.extract_surface()

Attribute detail#

MeshedRegion.as_linear = None#

Method detail#

MeshedRegion.__del__()#

Delete this instance of the meshed region.

MeshedRegion.__str__()#

Return string representation of the meshed region.

MeshedRegion.property_field(property_name)#

Property field getter. It can be coordinates (field), element types (property field)…

Returns:

field_or_property_field

Return type:

core.Field or core.PropertyField

MeshedRegion.set_property_field(property_name, value)#

Property field setter. It can be coordinates (field), element types (property field)…

Parameters:
  • property_name (str) – property name of the field to set

  • value (PropertyField or Field)

MeshedRegion.set_coordinates_field(coordinates_field)#

Coordinates field setter.

Parameters:

coordinates_field (PropertyField or Field)

MeshedRegion.named_selection(named_selection)#

Scoping containing the list of nodes or elements in the named selection.

Parameters:

named_selection (str) – Name of the named selection.

Returns:

named_selection

Return type:

Scoping

MeshedRegion.set_named_selection_scoping(named_selection_name, scoping)#

Named selection scoping setter.

Parameters:
  • named_selection_name (str) – named selection name

  • scoping (Scoping)

MeshedRegion.deform_by(deform_by, scale_factor=1.0)#

Deforms the mesh according to a 3D vector field and an additional scale factor.

Parameters:
  • deform_by (Field, FieldsContainer, Result, Operator) – Used to deform the plotted mesh. Must output a unique 3D vector field. Defaults to None.

  • scale_factor (float, Field, FieldsContainer, optional) – Used to scale the mesh deformation. Defaults to 1.0. Can be a scalar Field (or a FieldsContainer with only one Field) to get a spatially non-homogeneous scaling.

MeshedRegion.plot(field_or_fields_container=None, shell_layers=None, deform_by=None, scale_factor=1.0, **kwargs)#

Plot the field or fields container on the mesh.

Parameters:
  • field_or_fields_container (dpf.core.Field or dpf.core.FieldsContainer) – Field or fields container to plot. The default is None.

  • shell_layers (core.shell_layers, optional) – Enum used to set the shell layers if the model to plot contains shell elements.

  • deform_by (Field, Result, Operator, optional) – Used to deform the plotted mesh. Must output a 3D vector field. Defaults to None.

  • scale_factor (float, optional) – Scaling factor to apply when warping the mesh. Defaults to 1.0.

  • **kwargs (optional) – Additional keyword arguments for the plotter. For additional keyword arguments, see help(pyvista.plot).

Examples

Plot the displacement field from an example file.

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> disp = model.results.displacement()
>>> field = disp.outputs.fields_container()[0]
>>> model.metadata.meshed_region.plot(field)
MeshedRegion.deep_copy(server=None)#

Create a deep copy of the meshed region’s data on a given server.

This method is useful for passing data from one server instance to another.

Parameters:

server (ansys.dpf.core.server, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Returns:

mesh_copy

Return type:

MeshedRegion

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region
>>> other_server = dpf.start_local_server(as_global=False)
>>> deep_copy = meshed_region.deep_copy(server=other_server)
MeshedRegion.field_of_properties(property_name)#

Return the Field or PropertyField associated to a given property of the mesh.

Parameters:

property_name (str, common.elemental_properties, common.nodal_properties) – Name of the property.

Returns:

properties

Return type:

Field, PropertyField

Examples

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_static_rst())
>>> meshed_region = model.metadata.meshed_region
>>> connectivity = meshed_region.field_of_properties(
...     dpf.common.elemental_properties.connectivity)
>>> coordinates = meshed_region.field_of_properties(dpf.common.nodal_properties.coordinates)