.. 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 19-24 .. code-block:: Python # Import necessary modules from ansys.dpf import core as dpf from ansys.dpf.core import examples .. GENERATED FROM PYTHON SOURCE LINES 25-26 Create a model object to establish a connection with an example result file: .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python model = dpf.Model(examples.download_hemisphere()) .. GENERATED FROM PYTHON SOURCE LINES 29-30 Get the property ``coordinates_field`` from :class:`nodes `: .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python ncoord_f = model.metadata.meshed_region.nodes.coordinates_field .. GENERATED FROM PYTHON SOURCE LINES 33-35 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 35-39 .. code-block:: Python 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 40-41 Create a 3x3 rotation matrix field ``rot_mat_f``: .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. 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 45-48 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 48-52 .. 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 53-54 Get rotated nodal coordinates field: .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python ncoord_rot_f = dpf.operators.geo.rotate(field=ncoord_f, field_rotation_matrix=rot_mat_f) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Transform rotated nodal coordinates field along rotated position vector ``pos_vec_rot``: .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. 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 63-64 Get the nodal coordinates field ``ncoord_lcs_f`` in LCS: .. GENERATED FROM PYTHON SOURCE LINES 64-66 .. code-block:: Python ncoord_lcs_f = ncoord_translate.outputs.field.get_data() .. GENERATED FROM PYTHON SOURCE LINES 67-68 Coordinates of NID 1 in GCS .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. 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 71-72 Coordinates of NID 1 in LCS .. GENERATED FROM PYTHON SOURCE LINES 72-73 .. 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 7.253 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>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_