This PyDPF script demonstrates how to identify contact elements in an Ansys Mechanical result file, specifically excluding those with bonded contact behavior. The script utilizes the Ansys DPF (Data Processing Framework) to process the result file, extract relevant element information, and perform scoping operations.
The script begins by setting up a DPF server and loading the result file. It then retrieves the mesh and identifies all contact elements (CONTA17X series).
For each contact element type, it checks for bonded contact behavior by examining specific key options (keyopt_12 or keyopt_10). The script excludes bonded contact elements from the final scoping of contact elements.
The script concludes by printing the scopings of contact elements excluding bonded contacts. This approach allows users to focus on non-bonded contact elements for further analysis or results postprocessing.
The script is particularly useful for engineers and analysts working with contact simulations in Ansys Mechanical, enabling them to efficiently filter and analyze contact elements based on their behavior.
The script can be adapted for various contact element types and key options as needed for specific analysis requirements.
Import Necessary Modules
import ansys.dpf.core as dpf
Start a local server with the path to your ANSYS installation
server = dpf.start_local_server(ansys_path=r'C:\Program Files\ANSYS Inc\v251')
Define the path to the result file
rst_file = r'./file.rst'
Create a data source from the result file
ds = dpf.DataSources()
ds.set_result_file_path(rst_file)
Operator instantiation to get result information
op = dpf.operators.metadata.result_info_provider()
op.inputs.data_sources.connect(ds)
Get result information
my_result_info = op.outputs.result_info()
print(my_result_info)
Create a model from the data source
model = dpf.Model(ds)
print(model)
Get the mesh from the model
mesh = model.metadata.meshed_region
print(mesh)
Get available element types in the mesh
apdl_types = mesh.property_field('apdl_element_type').data
apdl_types_list = list(dict.fromkeys(list(apdl_types)))
print('available elements:' + str(apdl_types_list))
Define a dictionary mapping element types to their corresponding keyopt and value for bonded contact
contact_dict = {
'171': {'keyopt':'keyopt_12','value':5},
'172': {'keyopt':'keyopt_12','value':5},
'173': {'keyopt':'keyopt_12','value':5},
'174': {'keyopt':'keyopt_12','value':5},
'175': {'keyopt':'keyopt_12','value':5},
'176': {'keyopt':'keyopt_12','value':5},
'177': {'keyopt':'keyopt_12','value':5},
'178': {'keyopt':'keyopt_10','value':5},
}
Loop through available element types and check for matches in the contact_dict
for item in apdl_types_list:
for key, val in contact_dict.items():
if item == int(key):
print(f"Match found for item {item}: {val}")
print(val['keyopt'], val['value'])
### Get scoping of all CONTA17X elements in the mesh
ct17x_scoping_op = dpf.operators.scoping.on_mesh_property() ### operator instantiation
ct17x_scoping_op.inputs.requested_location.connect('Elemental')
ct17x_scoping_op.inputs.property_name.connect("apdl_element_type")
ct17x_scoping_op.inputs.property_id.connect(int(item))
ct17x_scoping_op.inputs.mesh.connect(mesh)
ct17x_scoping = ct17x_scoping_op.outputs.mesh_scoping()
print(ct17x_scoping)
### Get scoping of all elements with keyopt 12/10 = 5 (bonded contact)
keyo_scoping_op = dpf.operators.scoping.on_property() ### operator instantiation
keyo_scoping_op.inputs.requested_location.connect('Elemental')
keyo_scoping_op.inputs.property_name.connect(val['keyopt'])
keyo_scoping_op.inputs.property_id.connect(val['value'])
keyo_scoping_op.inputs.data_sources.connect(ds)
keyo_scoping = keyo_scoping_op.outputs.mesh_scoping()
print(keyo_scoping)
### Get intersection of both scopings
ct_bonded_scoping = dpf.Scoping()
ct_bonded_scoping.ids = list(set(ct17x_scoping.ids) & set(keyo_scoping.ids))
print(ct_bonded_scoping)
### Get contact elements other than bonded contacts
ct_scoping_no_bonded = list(set(ct17x_scoping.ids) ^ set(ct_bonded_scoping.ids))
Check if elements from ct_scoping_no_bonded are in ct_bonded_scoping
for ids in ct_scoping_no_bonded:
if ids in ct_bonded_scoping.ids:
print(ids)
else:
print('Not found')