How to calculate contact surface and heat flow with the use of PyDpf

Member, Employee Posts: 6
Ansys Employee First Comment
✭✭✭
edited August 2023 in Structures

How to calculate contact surface and heat flow with the use of PyDpf

Comments

  • Member, Employee Posts: 6
    Ansys Employee First Comment
    ✭✭✭

    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:

    1. my_cont=cid

    And the following command object before solution:

    1. /PREP7
    2.  
    3. ESEL, S, TYPE, , my_cont
    4. CM, PCB_CONT, ELEM
    5. ALLSEL
    6.  
    7. /SOLU

    The PyDPF script is as follows:

    1. from ansys.dpf import core as dpf
    2. from ansys.dpf import core as dpf
    3. from ansys.dpf.core.plotter import DpfPlotter
    4.  
    5. import numpy as np
    6.  
    7. """
    8. Load result file and create model database
    9. """
    10. ds = dpf.DataSources("file.rth")
    11. model = dpf.Model(ds)
    12.  
    13. # %%
    14. get_NSs = model.metadata.available_named_selections
    15. print(get_NSs)
    16.  
    17. # %%
    18. mesh_scoping = model.metadata.named_selection("PCB_CONT_2")
    19. print(mesh_scoping)
    20.  
    21. # %%
    22. print(get_NSs)
    23.  
    24. mesh_scoping = model.metadata.named_selection("PCB_CONT_2")
    25. print(mesh_scoping)
    26.  
    27. # %%
    28. contact_status_op = dpf.operators.result.nmisc(
    29. # time_scoping=-1,
    30. mesh_scoping=mesh_scoping,
    31. # fields_container=my_fields_container,
    32. # streams_container=my_streams_container,
    33. data_sources=ds,
    34. # mesh=my_mesh,
    35. item_index=41,
    36. # num_components=my_num_components,
    37. )
    38.  
    39. print(contact_status_op)
    40.  
    41. # %%
    42. contact_status_res = contact_status_op.outputs.fields_container()
    43. print(contact_status_res)
    44.  
    45. # %%
    46. scoping_op = dpf.operators.mesh.from_scoping()
    47. scoping_op.inputs.scoping.connect(mesh_scoping)
    48. scoping_op.inputs.mesh.connect(contact_status_res[0].meshed_region)
    49.  
    50. my_mesh = scoping_op.outputs.mesh()
    51. print(my_mesh)
    52.  
    53. # %%
    54. plot = DpfPlotter()
    55. plot.add_field(contact_status_res[0], my_mesh, notebook=False)
    56. plot.show_figure(show_axes=True)
    57.  
    58. # %%
    59. touch_cond = (contact_status_res[0].data >= 2.)
    60. Nelems_touch = sum(touch_cond)
    61.  
    62. print("Number of Touching Elements: ", Nelems_touch)
    63. print("Number of Total Elements: ", len(contact_status_res[0].data))
    64.  
    65. # %%
    66. contact_area_op = dpf.operators.result.nmisc(
    67. # time_scoping=-1,
    68. mesh_scoping=mesh_scoping,
    69. # fields_container=my_fields_container,
    70. # streams_container=my_streams_container,
    71. data_sources=ds,
    72. # mesh=my_mesh,
    73. item_index=58,
    74. # num_components=my_num_components,
    75. )
    76.  
    77. print(contact_area_op)
    78.  
    79. # %%
    80. contact_area_res = contact_area_op.outputs.fields_container()
    81. print(contact_area_res)
    82.  
    83. # %%
    84. print(contact_area_res[0].data)
    85.  
    86. # %%
    87. scoping_op = dpf.operators.mesh.from_scoping()
    88. scoping_op.inputs.scoping.connect(mesh_scoping)
    89. scoping_op.inputs.mesh.connect(contact_area_res[0].meshed_region)
    90.  
    91. my_mesh = scoping_op.outputs.mesh()
    92. print(my_mesh)
    93.  
    94. # %%
    95. plot = DpfPlotter()
    96. plot.add_field(contact_area_res[0], my_mesh, show_max=True, show_min=True, notebook=False)
    97. plot.show_figure(show_axes=True)
    98.  
    99. # %%
    100. contact_heatFlux_op = dpf.operators.result.smisc(
    101. # time_scoping=-1,
    102. mesh_scoping=mesh_scoping,
    103. # fields_container=my_fields_container,
    104. # streams_container=my_streams_container,
    105. data_sources=ds,
    106. # mesh=my_mesh,
    107. item_index=14,
    108. # num_components=my_num_components,
    109. )
    110.  
    111. print(contact_heatFlux_op)
    112.  
    113. # %%
    114. contact_heatFlux_res = contact_heatFlux_op.outputs.fields_container()
    115. print(contact_heatFlux_res)
    116.  
    117. # %%
    118. scoping_op = dpf.operators.mesh.from_scoping()
    119. scoping_op.inputs.scoping.connect(mesh_scoping)
    120. scoping_op.inputs.mesh.connect(contact_heatFlux_res[0].meshed_region)
    121.  
    122. my_mesh = scoping_op.outputs.mesh()
    123. print(my_mesh)
    124.  
    125. # %%
    126. plot = DpfPlotter()
    127. plot.add_field(contact_heatFlux_res[0], my_mesh, show_max=True, show_min=True, notebook=False)
    128. plot.show_figure(show_axes=True)

Welcome!

It looks like you're new here. Sign in or register to get started.