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 getter. It can be coordinates (field), element types (property field)… |
|
Property field setter. It can be coordinates (field), element types (property field)… |
|
Coordinates field setter. |
|
Scoping containing the list of nodes or elements in the named selection. |
|
Named selection scoping setter. |
|
Deforms the mesh according to a 3D vector field and an additional scale factor. |
|
Plot the field or fields container on the mesh. |
|
Create a deep copy of the meshed region’s data on a given server. |
|
Return the |
|
Whether the mesh is empty. |
|
Return the data length for a given mesh location. |
|
Return the array of number of nodes per element in the mesh. |
All elemental properties of the mesh, such as connectivity and element types. |
|
All face properties of the mesh, such as faces_nodes_connectivity and face types. |
|
All nodal properties of the mesh, such as node coordinates and nodal connectivity. |
|
Unit of the meshed region. |
|
Returns a list of available property fields. |
|
List of available named selections. |
|
Unstructured grid in VTK format from PyVista. |
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:
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:
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:
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:
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: 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
- 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:
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
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)
- MeshedRegion.is_empty() bool #
Whether the mesh is empty.
A mesh is considered empty when it has zero element, zero face, and zero node.
- MeshedRegion.location_data_len(location: ansys.dpf.core.common.locations) int #
Return the data length for a given mesh location.
Accepted mesh locations are nodal, elemental, faces, and elemental_nodal.
- Parameters:
location – The mesh location to compute data length for. Can be nodal, elemental, faces, or elemental_nodal.
- Returns:
If location is nodal, return the number of nodes. If location is elemental, return the number of elements. If location is faces, return the number of faces. If location is elemental nodal, return the sum of the number of nodes per element.
- Return type:
data_size
- MeshedRegion.get_elemental_nodal_size_list() numpy.ndarray #
Return the array of number of nodes per element in the mesh.