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.

nodes#

Entity containing all nodal properties.

Type

Nodes

elements#

Entity containing all elemental properties.

Type

Elements

Examples

Extract a meshed region from a model.

>>> import ansys.dpf.core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.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])
property 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.static_rst)
>>> meshed_region = model.metadata.meshed_region
>>> elements = meshed_region.elements
>>> print(elements)
DPF Elements object with 8 elements
property 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.static_rst)
>>> meshed_region = model.metadata.meshed_region
>>> nodes = meshed_region.nodes
>>> nodes.n_nodes
81
property 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 available_named_selections#

List of available named selections.

Returns

named_selections

Return type

list str

named_selection(*args, **kwargs)#

Call the original function

property 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.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()
plot(field_or_fields_container=None, shell_layers=None, **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.

  • **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.static_rst)
>>> disp = model.results.displacement()
>>> field = disp.outputs.fields_container()[0]
>>> model.metadata.meshed_region.plot(field)
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.

Warning

Only nodes scoping and coordinates and elements scoping, connectivity, and types are copied. The eventual property field for elemental properties and named selection will not be copied.

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.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)
field_of_properties(property_name)#

Returns 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.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)