How do I fetch Angular Velocity and Angular Acceleration using PyDPF from a Transient Analysis?
How do I fetch Angular Velocity and Angular Acceleration using PyDPF from a Transient Analysis??
Comments
-
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:
- First the radial velocities and accelerations are calculated by rotating the results to cylindrical coordinate system.
- 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)) ms = model.metadata.meshed_region.named_selection("ALL_NODES") 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, mesh=model.metadata.meshed_region) 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, mesh=model.metadata.meshed_region) ang_acc_y = dpf.operators.logic.component_selector_fc(fields_container=ang_acc, component_number=1) mesh = dpf.operators.mesh.from_scoping(scoping=ms, mesh=model.metadata.meshed_region).outputs.mesh.get_data() """ 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) radius_field = dpf.operators.math.norm(dist_diff).outputs.field.get_data() radius_field.unit = "mm" radius_fc = dpf.FieldsContainer() radius_fc.labels = ["time"] for time_id in time_ids: radius_fc.add_field({"time": time_id}, radius_field) omega_y = dpf.operators.math.component_wise_divide_fc(fields_containerA=ang_vel_y, fields_containerB=radius_fc) domega_y = dpf.operators.math.component_wise_divide_fc(fields_containerA=ang_acc_y, fields_containerB=radius_fc) """ Plot for last time state, change the time index accordingly. """ mesh.plot(omega_y.outputs.fields_container.get_data()[-1], scalar_bar_args=dict(title="OMGY [rad/s]")) mesh.plot(domega_y.outputs.fields_container.get_data()[-1], scalar_bar_args=dict(title="DOMGY [rad/s*s]"))1 -
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?
0 -
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, mesh=model.metadata.meshed_region)
…0