With Mechanical APDL, I can get the Euler angles of principal stresses using *VFUN Euler. How can I do this with ACT or DPF?
@J Wong
There is not direct operator with DPF to do this but you can use a combination of eigen-vectors and functions to convert Eigenvectors to Euler Angles.
PyDPF:
import numpy as np from ansys.dpf import core as dpf from scipy.spatial.transform import Rotation as R def normalize(v): return v / np.linalg.norm(v) def build_right_handed_rotation_matrix(v1, v2, v3): # Normalize vectors v1 = normalize(v1) v2 = normalize(v2) v3 = normalize(v3) # Form matrix R_matrix = np.column_stack((v1, v2, v3)) # Check determinant det = np.linalg.det(R_matrix) if det < 0: v3 = -v3 R_matrix = np.column_stack((v1, v2, v3)) return R_matrix def get_euler_angles(v1, v2, v3, convention='xyz', degrees=True): R_matrix = build_right_handed_rotation_matrix(v1, v2, v3) rot = R.from_matrix(R_matrix) return rot.as_euler(convention, degrees=degrees) rst = r"D:\…\file.rst" ds = dpf.DataSources(rst) stress = dpf.operators.result.stress(data_sources=ds, requested_location="Nodal") ev = dpf.operators.invariant.eigen_vectors_fc(fields_container=stress) ev_f = ev.outputs.fields_container.get_data()[0] euler_angles = [] for nid in ev_f.scoping.ids: v1 = ev_f.get_entity_data_by_id(nid)[0][0: 3] v2 = ev_f.get_entity_data_by_id(nid)[0][3: 6] v3 = ev_f.get_entity_data_by_id(nid)[0][6: 9] roll, pitch, yaw = get_euler_angles(v1, v2, v3, convention='xyz') euler_angles.append((yaw, roll, pitch)) # Euler angles field ea_f = dpf.fields_factory.create_3d_vector_field(num_entities=len(ev_f.scoping.ids)) ea_f.unit = "deg" ea_f.data = np.array(euler_angles).flatten() ea_f.scoping.ids = ev_f.scoping.ids # PrintEuler angle of principal stresses for NID 2436 print(ea_f.get_entity_data_by_id(2436))
For Mechanical you can use the following code for conversion:
def euler_xyz_from_vectors(v1, v2, v3): # Build rotation matrix from column vectors R = [ [v1[0], v2[0], v3[0]], [v1[1], v2[1], v3[1]], [v1[2], v2[2], v3[2]] ] pitch = math.asin(-R[2][0]) roll = math.atan2(R[2][1], R[2][2]) yaw = math.atan2(R[1][0], R[0][0]) return [math.degrees(roll), math.degrees(pitch), math.degrees(yaw)]