Is there any way to calculate deformed face area from apdl results file?

Rajesh Meena
Rajesh Meena Moderator, Employee Posts: 85
10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
✭✭✭✭

I would like to calculate deformed face area of a crack face for comparing deformation or crack opening.
Is there a python way to do this?

Tagged:

Answers

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 85
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    ✭✭✭✭

    There are two solutions:

    Mechanical DPF, using iron python:

    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    import math
    
    dataSource = dpf.DataSources(Model.Analyses[0].ResultFileName)
    model = dpf.Model(dataSource)
    
    
    whole_mesh = model.Mesh
    face_scoping = model.GetNamedSelection("NS_SECRACK_BOTTOMFACE")
    
    op = dpf.operators.mesh.skin(mesh=whole_mesh,
        mesh_scoping=face_scoping,
    )
    
    skin_mesh = op.outputs.mesh.GetData()
    u = dpf.operators.result.displacement()
    u.inputs.data_sources.Connect(dataSource)
    u.inputs.mesh.Connect(skin_mesh)
    
    op = dpf.operators.geo.elements_facets_surfaces_over_time() # operator instantiation
    op.inputs.mesh.Connect(skin_mesh)
    op.inputs.displacement.Connect(u)
    my_fields_container = op.outputs.fields_container.GetData()
    deformed_area = math.fsum(my_fields_container[0].Data)
    
    print(deformed_area)
    
    1. PyDPF using CPython
    from ansys.dpf import core as dpf 
    
    model =  dpf.Model(r"C:\Users\rmeena\AppData\Local\Temp\WB_rmeena_21364_2\wbnew_files\dp0\SYS\MECH\file.rst")
    
    whole_mesh = model.metadata.meshed_region
    
    face_scoping = model.metadata.named_selection("FACE_SET")
    
    op = dpf.operators.mesh.skin(
        mesh=whole_mesh,
        mesh_scoping=face_scoping,
    )
    
    skin_mesh = op.outputs.mesh()
    
    #undeformed_area
    face_area = skin_mesh._as_vtk().area
    
    # Deformed area
    deformed_mesh = skin_mesh.deform_by(model.results.displacement.on_mesh_scoping(skin_mesh.nodes.scoping))
    skin_mesh.nodes.coordinates_field.data = deformed_mesh.data
    deformed_face_area = skin_mesh._as_vtk().area
    print(face_area)
    

    You could also covert the ironpython code to Cpython using same operator.

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 85
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    ✭✭✭✭

    There are two solutions:

    Mechanical DPF, using iron python:

    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    import math
    
    dataSource = dpf.DataSources(Model.Analyses[0].ResultFileName)
    model = dpf.Model(dataSource)
    
    
    whole_mesh = model.Mesh
    face_scoping = model.GetNamedSelection("NS_SECRACK_BOTTOMFACE")
    
    op = dpf.operators.mesh.skin(mesh=whole_mesh,
        mesh_scoping=face_scoping,
    )
    
    skin_mesh = op.outputs.mesh.GetData()
    u = dpf.operators.result.displacement()
    u.inputs.data_sources.Connect(dataSource)
    u.inputs.mesh.Connect(skin_mesh)
    
    op = dpf.operators.geo.elements_facets_surfaces_over_time() # operator instantiation
    op.inputs.mesh.Connect(skin_mesh)
    op.inputs.displacement.Connect(u)
    my_fields_container = op.outputs.fields_container.GetData()
    deformed_area = math.fsum(my_fields_container[0].Data)
    
    print(deformed_area)
    
    1. PyDPF using CPython
    from ansys.dpf import core as dpf 
    
    model =  dpf.Model(r"C:\Users\rmeena\AppData\Local\Temp\WB_rmeena_21364_2\wbnew_files\dp0\SYS\MECH\file.rst")
    
    whole_mesh = model.metadata.meshed_region
    
    face_scoping = model.metadata.named_selection("FACE_SET")
    
    op = dpf.operators.mesh.skin(
        mesh=whole_mesh,
        mesh_scoping=face_scoping,
    )
    
    skin_mesh = op.outputs.mesh()
    
    #undeformed_area
    face_area = skin_mesh._as_vtk().area
    
    # Deformed area
    deformed_mesh = skin_mesh.deform_by(model.results.displacement.on_mesh_scoping(skin_mesh.nodes.scoping))
    skin_mesh.nodes.coordinates_field.data = deformed_mesh.data
    deformed_face_area = skin_mesh._as_vtk().area
    print(face_area)
    

    You could also covert the ironpython code to Cpython using same operator.