ansys.dpf.core.MeshedRegion#
- class ansys.dpf.core.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])
- _server#
- _api#
- _full_grid = None#
- _elements = None#
- _nodes = None#
- as_linear = None#
- _get_scoping(loc=locations.nodal)#
Return ids of the elements or nodes of the mesh.
- Parameters:
loc (str or ansys.dpf.core.common.locations, optional) – location of the requested scoping (“Nodal”, “Elemental”…)
- Returns:
scoping – ids of the elements or nodes of the mesh
- Return type:
- property elements#
All elemental properties of the mesh, such as connectivity and element types.
- Returns:
elements – Elements belonging to the meshed region.
- Return type:
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 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:
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 nodes#
All nodal properties of the mesh, such as node coordinates and nodal connectivity.
- Returns:
nodes – Nodes belonging to the meshed region
- Return type:
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 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
- _get_unit()#
Retrieve the unit type.
- Returns:
unit
- Return type:
str
- _set_unit(unit)#
Set the unit of the meshed region.
- Parameters:
unit (str)
- __del__()#
Delete this instance of the meshed region.
- __str__()#
Return string representation of the meshed region.
- property available_property_fields#
Returns a list of available property fields.
- Returns:
available_property_fields
- Return type:
list str
- property_field(property_name)#
Property field getter. It can be coordinates (field), element types (property field)…
- Returns:
field_or_property_field
- Return type:
- 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)
- set_coordinates_field(coordinates_field)#
Coordinates field setter.
- Parameters:
coordinates_field (PropertyField or Field)
- property available_named_selections#
List of available named selections.
- Returns:
named_selections
- Return type:
list str
- _get_available_named_selections()#
List of available named selections.
- Returns:
named_selections
- Return type:
list str
- named_selection(named_selection: str, server: ansys.dpf.core.server_types.AnyServerType = None) ansys.dpf.core.scoping.Scoping #
Scoping containing the list of nodes or elements in the named selection.
- Parameters:
named_selection – Name of the named selection.
server – Server on which to create the scoping if different from the server of the model.
- Returns:
A scoping containing the IDs of the entities in the named selection. The location depends on the type of entities targeted by the named selection.
- Return type:
named_selection
- set_named_selection_scoping(named_selection_name, scoping)#
Named selection scoping setter.
- Parameters:
named_selection_name (str) – named selection name
scoping (Scoping)
- _set_stream_provider(stream_provider)#
- 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.
- _as_vtk(coordinates=None, as_linear=True, include_ids=False)#
Convert DPF mesh to a PyVista unstructured grid.
- property grid#
Unstructured grid in VTK format from PyVista.
- Returns:
UnstructuredGrid of the mesh.
- Return type:
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()
- 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)
- 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:
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)
- field_of_properties(property_name)#
Return the
Field
orPropertyField
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:
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)
- is_empty() bool #
Whether the mesh is empty.
A mesh is considered empty when it has zero element, zero face, and zero node.