How to extract contact reaction forces using DPF from inside mechanical

Vishnu
Vishnu Member, Employee Posts: 219
Solution Developer Community of Practice Member First Anniversary Name Dropper 100 Comments
✭✭✭✭
edited March 21 in Structures
Tagged:

Comments

  • Vishnu
    Vishnu Member, Employee Posts: 219
    Solution Developer Community of Practice Member First Anniversary Name Dropper 100 Comments
    ✭✭✭✭
    edited May 2023

    below is a function which does this extraction.

    You need to pass the object name as the argument to this function.


    def get_cont_reaction(contact_obj_name):
        """    
        Use like below:    get_cont_reaction("Contact Region")    
        """    
        first_solution = ExtAPI.DataModel.Project.Model.Analyses[0].Solution    
        solver_data = first_solution.SolverData    
        contact_object = ExtAPI.DataModel.GetObjectsByName(contact_obj_name)[0]
        contact_object_data = solver_data.GetObjectData(contact_object)
        cont_elem_type_id = contact_object_data.SourceId    
        cont_elems = solver_data.ElementIdsByMaterialId(str(cont_elem_type_id))
        import mech_dpf    
        import Ans.DataProcessing as dpf    
        #Result Data    
        analysis1 = ExtAPI.DataModel.Project.Model.Analyses[0]
        dataSource = dpf.DataSources(analysis1.Solution.ResultFilePath)
        #model    
        my_model = dpf.Model(analysis1.Solution.ResultFilePath)
        #my mesh    
        my_mesh = my_model.Mesh    
        #time scoping    
        my_time_scoping = [1]
        #scoping    
        my_scoping = dpf.Scoping()
        my_scoping.Location = "Elemental"    
        my_scoping.Ids = cont_elems    
        CX = dpf.operators.result.mapdl.nmisc(time_scoping=my_time_scoping,mesh=my_mesh,data_sources=dataSource,item_index = 43,mesh_scoping=my_scoping).outputs.fields_container.GetData()[0]
        CY = dpf.operators.result.mapdl.nmisc(time_scoping=my_time_scoping,mesh=my_mesh,data_sources=dataSource,item_index = 44,mesh_scoping=my_scoping).outputs.fields_container.GetData()[0]
        CZ = dpf.operators.result.mapdl.nmisc(time_scoping=my_time_scoping,mesh=my_mesh,data_sources=dataSource,item_index = 45,mesh_scoping=my_scoping).outputs.fields_container.GetData()[0]
        #Release Locked RST    
        my_model.ReleaseStreams()
        return [-sum(CX.Data),-sum(CY.Data),-sum(CZ.Data)]
    
    
    
    
  • Vishnu
    Vishnu Member, Employee Posts: 219
    Solution Developer Community of Practice Member First Anniversary Name Dropper 100 Comments
    ✭✭✭✭

    The nmisc result operator is updated in recent releases like below:

    dpf.operators.result.nmisc