How can we set the contact type through scripting?

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

How can we set the contact type through scripting in Mechanical?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    The following function can be used:

    def SetContactRegion(contactRegion,contactType,nu):
        '''
        set the contact region 
        :param contactType: string of type of contact
        :param nu: friction coefficient    
        ''' 
        try:
            if contactType=="BONDED":
                if contactRegion.ContactType != ContactType.Bonded:
                    contactRegion.ContactType = ContactType.Bonded
                    ExtAPI.Log.WriteMessage((str(contactRegion.Name) + " was set bonded.")
                    
            elif contactType=="FRICTIONAL":
                if contactRegion.ContactType != ContactType.Frictional:
                    contactRegion.ContactType = ContactType.Frictional
                contactRegion.FrictionCoefficient = float(nu)
                # adjust to touch by default for better convergence
                contactRegion.InterfaceTreatment= ContactInitialEffect.AdjustToTouch
                # adding Fkn = 0.1 to ease solving
                contactRegion.AutomaticNormalStiffness= False
                contactRegion.NormalStiffnessFactor = 0.1            
                ExtAPI.Log.WriteMessage((str(contactRegion.Name) + " was set frictional.")            
            
            elif contactType=="SUPPRESSED":
                if contactRegion.Suppressed != True:
                    contactRegion.Suppressed = True                
                    ExtAPI.Log.WriteMessage((str(contactRegion.Name) + " was set suppressed.")
                    
        except:
            ExtAPI.Log.WriteMessage(("Error : Exception in SetContactRegion()")