Skip to content

Calculate Angular Velocity and Angular Acceleration with PyDPF #1068

Open
@ayush-kumar-423

Description

@ayush-kumar-423

file.zip

📝 Description of the example

Calculate Angular Velocity and Angular Acceleration with PyDPF

📁 Files needed for running the example

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]"))

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

2023R2

🐍 Which Python version are you using?

3.10

📦 Installed packages

aiofiles==22.1.0
aiohttp==3.8.4
aiosignal==1.3.1
aiosqlite==0.18.0
ansys-api-mapdl==0.5.1
ansys-api-mechanical==0.1.0
ansys-api-platform-instancemanagement==1.0.0b3
-e git+https://github.com/pyansys/pydpf-core.git@220ad166738c39ead6f49d7d68a0984bbab6e894#egg=ansys_dpf_core
ansys-dpf-gate==0.3.1
ansys-dpf-gatebin==0.3.1
ansys-dpf-post==0.4.0
-e git+https://github.com/pyansys/pyDyna.git@5abcb6beb0d8e40b23eff647e276afac9c364f1f#egg=ansys_dyna_core
ansys-grpc-dpf==0.7.1
ansys-mapdl-core==0.65.0
ansys-mapdl-reader==0.52.16
ansys-mechanical-core==0.8.0
ansys-platform-instancemanagement==1.1.1
ansys-pythonnet==3.1.0rc1
ansys-tools-path==0.2.6
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens==2.2.1
async-timeout==4.0.2
attrs==18.2.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.11.2
bleach==6.0.0
cachetools==5.3.1
certifi==2022.12.7
cffi==1.15.1
cfgv==3.3.1
chardet==5.1.0
charset-normalizer==2.1.1
circle-fit==0.2.0
click==8.1.3
clr-loader==0.2.5
colorama==0.4.6
comm==0.1.2
contourpy==1.0.6
cycler==0.11.0
debugpy==1.6.6
decorator==5.1.1
defusedxml==0.7.1
distlib==0.3.6
docutils==0.20.1
executing==1.2.0
fastjsonschema==2.16.3
filelock==3.12.1
flit==3.9.0
flit_core==3.9.0
fonttools==4.38.0
fqdn==1.5.1
frozenlist==1.3.3
google-api-core==2.11.0
google-api-python-client==2.70.0
google-auth==2.15.0
google-auth-httplib2==0.1.0
googleapis-common-protos==1.57.0
grpcio==1.53.0
grpcio-tools==1.48.2
httplib2==0.21.0
identify==2.5.24
idna==3.4
imageio==2.23.0
importlib-metadata==6.0.0
ipykernel==6.21.3
ipython==8.8.0
ipython-genutils==0.2.0
isoduration==20.11.0
jaraco.classes==3.2.3
jedi==0.18.2
Jinja2==3.1.2
json5==0.9.11
jsonpointer==2.3
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter-ydoc==0.2.2
jupyter_client==8.0.3
jupyter_core==5.2.0
jupyter_server==2.4.0
jupyter_server_fileid==0.8.0
jupyter_server_terminals==0.4.4
jupyter_server_ydoc==0.6.1
jupyterlab==3.6.1
jupyterlab-pygments==0.2.2
jupyterlab_server==2.20.0
keyring==23.13.1
kiwisolver==1.4.4
markdown-it-py==3.0.0
MarkupSafe==2.1.2
matplotlib==3.6.2
matplotlib-inline==0.1.6
mdurl==0.1.2
mistune==2.0.5
more-itertools==9.1.0
multidict==6.0.4
nbclassic==0.5.3
nbclient==0.7.2
nbconvert==7.2.9
nbformat==5.7.3
nest-asyncio==1.5.6
nodeenv==1.8.0
notebook==6.5.3
notebook_shim==0.2.2
numpy==1.23.5
packaging==23.1
pandocfilters==1.5.0
parso==0.8.3
pdflatex==0.1.3
pickleshare==0.7.5
Pillow==9.3.0
pkginfo==1.9.6
platformdirs==3.5.3
pluggy==1.0.0
pooch==1.6.0
pre-commit==3.3.2
prometheus-client==0.16.0
prompt-toolkit==3.0.36
protobuf==3.20.3
protoc-gen-swagger==0.1.0
psutil==5.9.4
pure-eval==0.2.2
pyansys-tools-versioning==0.3.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
Pygments==2.13.0
pyiges==0.3.0
pyparsing==3.0.9
pyproject_api==1.5.1
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.12.1
pyrsistent==0.19.3
python-dateutil==2.8.2
python-json-logger==2.0.7
pyvista==0.38.5
pyvista-gui==0.1.1
pyvistaqt==0.10.0
pywin32==305
pywin32-ctypes==0.2.0
pywinpty==2.0.10
PyYAML==6.0
pyzmq==25.0.0
QDarkStyle==3.1
qtconsole==5.4.3
QtPy==2.3.1
readme-renderer==37.3
requests==2.28.1
requests-toolbelt==1.0.0
rfc3339-validator==0.1.4
rfc3986==2.0.0
rfc3986-validator==0.1.1
rich==13.4.2
rsa==4.9
scikit-guess==0.0.1a0
scipy==1.9.3
scooby==0.7.0
Send2Trash==1.8.0
six==1.16.0
sniffio==1.3.0
soupsieve==2.4
stack-data==0.6.2
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tomli_w==1.0.0
tornado==6.2
tox==4.6.0
tqdm==4.64.1
traitlets==5.7.1
trame==2.5.0
trame-client==2.9.0
trame-components==2.1.1
trame-deckgl==2.0.2
trame-markdown==2.0.2
trame-matplotlib==2.0.2
trame-plotly==2.1.1
trame-rca==0.3.1
trame-router==2.0.2
trame-server==2.11.4
trame-simput==2.3.2
trame-vega==2.0.3
trame-vtk==2.4.4
trame-vuetify==2.2.4
twine==4.0.2
uri-template==1.2.0
uritemplate==4.1.1
urllib3==1.26.13
virtualenv==20.23.0
vtk==9.2.4
wcwidth==0.2.5
webcolors==1.12
webencodings==0.5.1
websocket-client==1.5.1
wslink==1.11.0
y-py==0.5.9
yarl==1.9.2
ypy-websocket==0.8.2
zipp==3.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    examplesRelated to PyDPF-Core examples

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions