Open
Description
📝 Description of the example
The script below captures the contact for each element by getting the CONTAC174 element and calculates its contact surface. Afterwards it calculates the heat flux of each element.
A prerequisite for the generation of the contact surface named selection is to add the following APDL command under the desired contact:
my_cont=cid
And the following command object before solution:
/PREP7
ESEL, S, TYPE, , my_cont
CM, PCB_CONT, ELEM
ALLSEL
/SOLU
The PyDPF script is as follows:
from ansys.dpf import core as dpf
from ansys.dpf import core as dpf
from ansys.dpf.core.plotter import DpfPlotter
import numpy as np
"""
Load result file and create model database
"""
ds = dpf.DataSources("file.rth")
model = dpf.Model(ds)
# %%
get_NSs = model.metadata.available_named_selections
print(get_NSs)
# %%
mesh_scoping = model.metadata.named_selection("PCB_CONT_2")
print(mesh_scoping)
# %%
print(get_NSs)
mesh_scoping = model.metadata.named_selection("PCB_CONT_2")
print(mesh_scoping)
# %%
contact_status_op = dpf.operators.result.nmisc(
# time_scoping=-1,
mesh_scoping=mesh_scoping,
# fields_container=my_fields_container,
# streams_container=my_streams_container,
data_sources=ds,
# mesh=my_mesh,
item_index=41,
# num_components=my_num_components,
)
print(contact_status_op)
# %%
contact_status_res = contact_status_op.outputs.fields_container()
print(contact_status_res)
# %%
scoping_op = dpf.operators.mesh.from_scoping()
scoping_op.inputs.scoping.connect(mesh_scoping)
scoping_op.inputs.mesh.connect(contact_status_res[0].meshed_region)
my_mesh = scoping_op.outputs.mesh()
print(my_mesh)
# %%
plot = DpfPlotter()
plot.add_field(contact_status_res[0], my_mesh, notebook=False)
plot.show_figure(show_axes=True)
# %%
touch_cond = (contact_status_res[0].data >= 2.)
Nelems_touch = sum(touch_cond)
print("Number of Touching Elements: ", Nelems_touch)
print("Number of Total Elements: ", len(contact_status_res[0].data))
# %%
contact_area_op = dpf.operators.result.nmisc(
# time_scoping=-1,
mesh_scoping=mesh_scoping,
# fields_container=my_fields_container,
# streams_container=my_streams_container,
data_sources=ds,
# mesh=my_mesh,
item_index=58,
# num_components=my_num_components,
)
print(contact_area_op)
# %%
contact_area_res = contact_area_op.outputs.fields_container()
print(contact_area_res)
# %%
print(contact_area_res[0].data)
# %%
scoping_op = dpf.operators.mesh.from_scoping()
scoping_op.inputs.scoping.connect(mesh_scoping)
scoping_op.inputs.mesh.connect(contact_area_res[0].meshed_region)
my_mesh = scoping_op.outputs.mesh()
print(my_mesh)
# %%
plot = DpfPlotter()
plot.add_field(contact_area_res[0], my_mesh, show_max=True, show_min=True, notebook=False)
plot.show_figure(show_axes=True)
# %%
contact_heatFlux_op = dpf.operators.result.smisc(
# time_scoping=-1,
mesh_scoping=mesh_scoping,
# fields_container=my_fields_container,
# streams_container=my_streams_container,
data_sources=ds,
# mesh=my_mesh,
item_index=14,
# num_components=my_num_components,
)
print(contact_heatFlux_op)
# %%
contact_heatFlux_res = contact_heatFlux_op.outputs.fields_container()
print(contact_heatFlux_res)
# %%
scoping_op = dpf.operators.mesh.from_scoping()
scoping_op.inputs.scoping.connect(mesh_scoping)
scoping_op.inputs.mesh.connect(contact_heatFlux_res[0].meshed_region)
my_mesh = scoping_op.outputs.mesh()
print(my_mesh)
# %%
plot = DpfPlotter()
plot.add_field(contact_heatFlux_res[0], my_mesh, show_max=True, show_min=True, notebook=False)
plot.show_figure(show_axes=True)
📁 Files needed for running the example
💻 Which operating system are you using?
Windows
📀 Which ANSYS version are you using?
2023R1
🐍 Which Python version are you using?
3.11
📦 Installed packages
ansys-dpf-core==0.8.1
ansys-dpf-gate==0.3.1
ansys-dpf-gatebin==0.3.1
ansys-dpf-post==0.4.0
ansys-grpc-dpf==0.7.1
asttokens==2.2.1
attrs==23.1.0
backcall==0.2.0
cachetools==5.3.0
certifi==2023.5.7
charset-normalizer==3.1.0
colorama==0.4.6
comm==0.1.3
contourpy==1.0.7
cycler==0.11.0
debugpy==1.6.7
decorator==5.1.1
executing==1.2.0
fastjsonschema==2.17.1
fonttools==4.39.4
google-api-core==2.11.0
google-api-python-client==2.86.0
google-auth==2.18.1
google-auth-httplib2==0.1.0
googleapis-common-protos==1.59.0
grpcio==1.54.2
httplib2==0.22.0
idna==3.4
importlib-metadata==6.6.0
ipykernel==6.23.1
ipython==8.13.2
jedi==0.18.2
jsonschema==4.18.0
jsonschema-specifications==2023.6.1
jupyter_client==8.2.0
jupyter_core==5.3.0
jupytext==1.14.7
kiwisolver==1.4.4
markdown-it-py==3.0.0
matplotlib==3.7.1
matplotlib-inline==0.1.6
mdit-py-plugins==0.4.0
mdurl==0.1.2
nbformat==5.9.0
nest-asyncio==1.5.6
numpy==1.24.3
packaging==23.1
parso==0.8.3
pickleshare==0.7.5
Pillow==9.5.0
platformdirs==3.5.1
pooch==1.7.0
prompt-toolkit==3.0.38
protobuf==4.23.1
psutil==5.9.5
pure-eval==0.2.2
pyasn1==0.5.0
pyasn1-modules==0.3.0
Pygments==2.15.1
pyparsing==3.0.9
python-dateutil==2.8.2
pyvista==0.39.1
pywin32==306
PyYAML==6.0
pyzmq==25.0.2
referencing==0.29.1
requests==2.30.0
rpds-py==0.8.8
rsa==4.9
scooby==0.7.2
six==1.16.0
stack-data==0.6.2
toml==0.10.2
tornado==6.3.2
tqdm==4.65.0
traitlets==5.9.0
uritemplate==4.1.1
urllib3==1.26.15
vtk==9.2.6
wcwidth==0.2.6
zipp==3.15.0