How can we set the contact type through scripting?

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
100 Answers 500 Comments 250 Likes First Anniversary
✭✭✭✭
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: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭
    Answer ✓

    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()")