MeshedRegion

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

A class used to represent a Mesh from DPF.

Parameters
  • num_nodes (int) – number of nodes to reserve for mesh creation

  • num_elements (int) – number of elements to reserve for mesh creation

  • mesh (ansys.grpc.dpf.meshed_region_pb2.MeshedRegion) –

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the the global server.

nodes

Entity containing all the nodal properties

Type

Nodes

elements

Entity containing all the 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
Gives access to all the elemental properties of the mesh:

connectivity, element types…

Returns

elements – Elements belonging to this 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
Gives access to all the nodal properties of the mesh:

nodes coordinates, nodal connectivity…

Returns

nodes – Nodes belonging to this 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 (same as the unit of the coordinates of the meshed region)

Returns

unit

Return type

str

property available_named_selections

Returns a list of available named selections

Returns

named_selections

Return type

list str

named_selection(named_selection)

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

property grid

VTK pyvista UnstructuredGrid

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()
[(0.0729555495773441, 0.1029555495773441, 0.0729555495773441),
 (0.015, 0.045, 0.015),
 (0.0, 0.0, 1.0)]

Extract the surface mesh of this grid

>>> mesh = grid.extract_surface()
plot(field_or_fields_container=None, notebook=None, shell_layers=None, off_screen=None, show_axes=True, **kwargs)

Plot the field/fields container on mesh.

Parameters
  • field_or_fields_container – dpf.core.Field or dpf.core.FieldsContainer

  • notebook (bool, optional) – That specifies if the plotting is in the notebook (2D) or not (3D).

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

  • off_screen (bool, optional) – Renders off screen when True. Useful for automated screenshots.

  • show_axes (bool, optional) – Shows a vtk axes widget. Enabled by default.

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

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)
[(0.0729555495773441, 0.1029555495773441, 0.0729555495773441),
 (0.015, 0.045, 0.015),
 (0.0, 0.0, 1.0)]
deep_copy(server=None)

Creates a deep copy of the meshed region’s data on a given server. This can be useful to pass 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 (DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the 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)