# How do I fetch Angular Velocity and Angular Acceleration using PyDPF from a Transient Analysis?

Options
Member, Moderator, Employee Posts: 420
✭✭✭✭
edited July 2023

How do I fetch Angular Velocity and Angular Acceleration using PyDPF from a Transient Analysis??

Tagged:

• Member, Moderator, Employee Posts: 420
✭✭✭✭
edited July 2023
Options

Works only for a Transient Analysis

PyDPF Solution

The RST should have a named selection of nodes you want to plot the results on. If you want the whole model, please select all nodes. The reason behind this is to exclude elements and nodes created by the solver.

The script has two parts:

1. First the radial velocities and accelerations are calculated by rotating the results to cylindrical coordinate system.
2. The radial results are then divided by the distance of each node to the coordinate system origin to retrieve the Angular velocity (OMGY in Mechanical) and accelerations (DOMGY in Mechanical).
from ansys.dpf import core as dpf

rst_path = r"\Path\to\file.rst"
model = dpf.Model(rst_path)

time_ids = list(range(1, model.metadata.time_freq_support.n_sets + 1))

vel = model.results.velocity(time_scoping=time_ids, mesh_scoping=ms)
acc = model.results.acceleration(time_scoping=time_ids, mesh_scoping=ms)

cs = model.operator(r"mapdl::rst::CS")
cs.inputs.cs_id.connect(12)
cs_origin = list(cs.outputs.field.get_data().data[0][9:12])

"""
Angular velocity in Y
"""
ang_vel = dpf.operators.geo.rotate_in_cylindrical_cs_fc(coordinate_system=cs, field=vel,
ang_vel_y = dpf.operators.logic.component_selector_fc(fields_container=ang_vel, component_number=1)

"""
Angular acceleration in Y
"""
ang_acc = dpf.operators.geo.rotate_in_cylindrical_cs_fc(coordinate_system=cs, field=acc,
ang_acc_y = dpf.operators.logic.component_selector_fc(fields_container=ang_acc, component_number=1)

"""
Plot for last time state, change the time index accordingly.
"""

mesh.plot(ang_vel_y.outputs.fields_container.get_data()[-1], scalar_bar_args=dict(title="[mm/s]"))
mesh.plot(ang_acc_y.outputs.fields_container.get_data()[-1], scalar_bar_args=dict(title="[mm/s*s]"))

"""
Distance of each node to the CS origin
"""
node_coords = mesh.nodes.coordinates_field
dist_diff = dpf.operators.math.minus(fieldA=node_coords, fieldB=cs_origin)

for time_id in time_ids:

"""
Plot for last time state, change the time index accordingly.
"""



• Member, Employee Posts: 321
✭✭✭✭
Options

To clarify this solution seems like it does not have any rotational degrees of freedom, but this is working on XYZ displacement and calculation of angular velocity based on cyl. CS.

Also, is it possible to show an example where the CS is not defined in the rst? Perhaps from a mechanical CS inserted after the solution or simply based on python user data? Does DPF have any concept for a frame or CS itself that can be created from raw data?

• Member, Moderator, Employee Posts: 420
✭✭✭✭
edited July 2023
Options

The rotate operator expects a 4x3 matrix, first 3 rows being the directional vectors and last being the origin.

So if you create a matrix using DPF and pass that to the argument coordinate_system, it works equally fine.

Example:

…
mat = dpf.fields_factory.create_matrix_field(12, 4, 3)
mat.data = cs.outputs.field.get_data().data
…
ang_vel = dpf.operators.geo.rotate_in_cylindrical_cs_fc(coordinate_system=mat, field=vel,