.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\10-mesh_operations\13-nodes_in_local_coordinate_system.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_10-mesh_operations_13-nodes_in_local_coordinate_system.py: .. _ref_nodes_in_local_coordinate_system: Convert nodal coordinates field to local coordinate system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Currently, there is no native operator to get nodal coordinates in an Local Coordinate System (LCS). The operator :class:`rotate ` rotates the input field in Global Coordinate System (GCS) as per the input rotation matrix. So, if the LCS is at the same origin as the GCS, only one operation using the :class:`rotate ` operator give the desired output. However, if the aim is to obtain the LCS in a case where the LCS origin does not coincide with the GCS, a transformation is required after the rotation to get the correct coordinates in LCS. The script below demonstrates the methodology using PyDPF. .. GENERATED FROM PYTHON SOURCE LINES 41-47 .. code-block:: Python # Import necessary modules from ansys.dpf import core as dpf from ansys.dpf.core import examples .. GENERATED FROM PYTHON SOURCE LINES 48-49 Create a model object to establish a connection with an example result file: .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python model = dpf.Model(examples.download_hemisphere()) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Get the property ``coordinates_field`` from :class:`nodes `: .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: Python ncoord_f = model.metadata.meshed_region.nodes.coordinates_field .. GENERATED FROM PYTHON SOURCE LINES 56-58 Get the rotation matrix of the LCS ID 12. The first 9 values in the ``cs`` output is the rotation matrix. .. GENERATED FROM PYTHON SOURCE LINES 58-69 .. code-block:: Python try: # Starting with DPF 2025.1.pre1 cs = dpf.operators.result.coordinate_system() cs.inputs.data_sources.connect(model) except KeyError: # For previous DPF versions cs = model.operator(r"mapdl::rst::CS") cs.inputs.cs_id.connect(12) cs_rot_mat = cs.outputs.field.get_data().data.T[0:9] .. GENERATED FROM PYTHON SOURCE LINES 70-71 Create a 3x3 rotation matrix field ``rot_mat_f``: .. GENERATED FROM PYTHON SOURCE LINES 71-74 .. code-block:: Python rot_mat_f = dpf.fields_factory.create_scalar_field(1) rot_mat_f.data = cs_rot_mat .. GENERATED FROM PYTHON SOURCE LINES 75-78 Create a 3D vector field for the position vector of the LCS's origin and rotate the origin as per the rotation matrix of the LCS. The last 3 entries of ``cs`` output is the LCS's origin in GCS. .. GENERATED FROM PYTHON SOURCE LINES 78-82 .. code-block:: Python pos_vec = dpf.fields_factory.create_3d_vector_field(1) pos_vec.data = cs.outputs.field.get_data().data.T[-3:] pos_vec_rot = dpf.operators.geo.rotate(field=pos_vec, field_rotation_matrix=rot_mat_f) .. GENERATED FROM PYTHON SOURCE LINES 83-84 Get rotated nodal coordinates field: .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: Python ncoord_rot_f = dpf.operators.geo.rotate(field=ncoord_f, field_rotation_matrix=rot_mat_f) .. GENERATED FROM PYTHON SOURCE LINES 87-89 Transform rotated nodal coordinates field along rotated position vector ``pos_vec_rot``: .. GENERATED FROM PYTHON SOURCE LINES 89-92 .. code-block:: Python pos_vec_rot_neg_f = dpf.operators.math.scale(field=pos_vec_rot, ponderation=-1.0) pos_vec_rot_neg = pos_vec_rot_neg_f.outputs.field.get_data().data_as_list ncoord_translate = dpf.operators.math.add_constant(field=ncoord_rot_f, ponderation=pos_vec_rot_neg) .. GENERATED FROM PYTHON SOURCE LINES 93-94 Get the nodal coordinates field ``ncoord_lcs_f`` in LCS: .. GENERATED FROM PYTHON SOURCE LINES 94-96 .. code-block:: Python ncoord_lcs_f = ncoord_translate.outputs.field.get_data() .. GENERATED FROM PYTHON SOURCE LINES 97-98 Coordinates of NID 1 in GCS .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: Python print(ncoord_f.get_entity_data_by_id(1)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-2.74445261 13.2627943 4.68419313]] .. GENERATED FROM PYTHON SOURCE LINES 101-102 Coordinates of NID 1 in LCS .. GENERATED FROM PYTHON SOURCE LINES 102-103 .. code-block:: Python print(ncoord_lcs_f.get_entity_data_by_id(1)) .. rst-class:: sphx-glr-script-out .. code-block:: none [[11.71685114 -4.83846377 -2.35002614]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.974 seconds) .. _sphx_glr_download_examples_10-mesh_operations_13-nodes_in_local_coordinate_system.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 13-nodes_in_local_coordinate_system.ipynb <13-nodes_in_local_coordinate_system.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 13-nodes_in_local_coordinate_system.py <13-nodes_in_local_coordinate_system.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 13-nodes_in_local_coordinate_system.zip <13-nodes_in_local_coordinate_system.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_