:class:`Nodes` ============== .. py:class:: ansys.dpf.core.nodes.Nodes(mesh) Provides a collection of DPF nodes. :param mesh: Mesh region that the collection is created from. :type mesh: :class:`ansys.dpf.core.meshed_region` class .. rubric:: 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 = model.metadata.meshed_region.nodes >>> nodes.n_nodes 81 .. py:currentmodule:: Nodes Overview -------- .. tab-set:: .. tab-item:: Methods .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~node_by_id` - Array of node coordinates ordered by ID. * - :py:attr:`~node_by_index` - Array of node coordinates ordered by index. * - :py:attr:`~map_scoping` - Retrieve the indices to map the scoping of these elements to the scoping of a field. * - :py:attr:`~add_node` - Add a node in the mesh. * - :py:attr:`~add_nodes` - Add a number of nodes in the mesh. .. tab-item:: Properties .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~scoping` - Scoping of the nodes. * - :py:attr:`~n_nodes` - Number of nodes. * - :py:attr:`~coordinates_field` - Coordinates field. * - :py:attr:`~nodal_connectivity_field` - Nodal connectivity field. * - :py:attr:`~mapping_id_to_index` - Property storing mapping between IDs and indices of the entity. .. tab-item:: Special methods .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~__str__` - Return custom str representation with information about number of nodes. * - :py:attr:`~__getitem__` - Return node based on index. * - :py:attr:`~__len__` - Return the number of nodes. * - :py:attr:`~__iter__` - Provide for iterating through the nodes. Import detail ------------- .. code-block:: python from ansys.dpf.core.nodes import Nodes Property detail --------------- .. py:property:: scoping Scoping of the nodes. :returns: **scoping** -- Scoping of the nodes. :rtype: Scoping .. rubric:: Examples Get the IDs of all nodes in this collection. >>> 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 = model.metadata.meshed_region.nodes >>> nodes.scoping.ids[2] np.int32(3) .. py:property:: n_nodes Number of nodes. .. py:property:: coordinates_field Coordinates field. :returns: **coordinates_field** -- Field with all the coordinates for the nodes. :rtype: Field .. rubric:: 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 = model.metadata.meshed_region.nodes >>> coordinates = nodes.coordinates_field >>> # Extract the array of coordinates the coordinates field >>> nodes.coordinates_field.data[2] DPFArray([0.015, 0.045, 0.03 ]... .. py:property:: nodal_connectivity_field Nodal connectivity field. Field containing each node ID for the elements indices connected to the given node. :returns: **nodal_connectivity_field** -- Field of the element indices associated with each node. :rtype: PropertyField .. rubric:: 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 = model.metadata.meshed_region.nodes >>> field = nodes.nodal_connectivity_field >>> field.get_entity_data(1) DPFArray([0, 2, 4, 6]... .. py:property:: mapping_id_to_index Property storing mapping between IDs and indices of the entity. Method detail ------------- .. py:method:: __str__() Return custom str representation with information about number of nodes. .. py:method:: __getitem__(index) Return node based on index. .. py:method:: __len__() Return the number of nodes. .. py:method:: __iter__() Provide for iterating through the nodes. .. py:method:: node_by_id(id) Array of node coordinates ordered by ID. .. py:method:: node_by_index(index) Array of node coordinates ordered by index. .. py:method:: map_scoping(external_scope) Retrieve the indices to map the scoping of these elements to the scoping of a field. :param external_scope: Scoping to map to. :type external_scope: scoping.Scoping :returns: * **indices** (*numpy.ndarray*) -- List of indices to map from the external scope to the scoping of these nodes. * **mask** (*numpy.ndarray*) -- Members of the external scope that are in the node scoping. .. rubric:: Examples Retrieve the indices that map a field to a nodes collection. >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples >>> model = dpf.Model(examples.find_static_rst()) >>> nodes = model.metadata.meshed_region.nodes >>> disp = model.results.displacement() >>> field = disp.outputs.fields_container()[0] >>> ind, mask = nodes.map_scoping(field.scoping) These indices can then be used to remap the coordinates of the nodes to match the order of the field data. This way, the field data matches the order of the nodes in the :class:`ansys.dpf.core.meshed_region` class. >>> mapped_nodes = nodes.coordinates_field.data[ind] .. py:method:: add_node(id, coordinates) Add a node in the mesh. :param id: ID for the new node. :type id: int :param coordinates: List of ``[x, y, z]`` coordinates for the node. :type coordinates: list[float] .. py:method:: add_nodes(num) Add a number of nodes in the mesh. This method yields a number of nodes that you can define. :param num: Number of nodes to add. :type num: int :Yields: **yield node** (*NodeAdder*) -- Node to add .. rubric:: Examples >>> import ansys.dpf.core as dpf >>> meshed_region = dpf.MeshedRegion(num_nodes=4,num_elements=3) >>> for i, node in enumerate(meshed_region.nodes.add_nodes(4)): ... node.id = i+1 ... node.coordinates = [float(i), float(i), 0.0]