hexagon logo

How to pass a design variable to a contact force with python?

I have a model with a large number of contacts. I am writing a python script that determines the number of contact pairs and then creates the corresponding contact force(s). I have design variables for the stiffness, damping, etc. in order for the contacts to use the same values and thus can be tuned by simply changing one of the variables. I am struggling to pass the design variable to the contact force. If I reference the variable like this '(my_variable)', the script sees it as a string and not a design variable and doesn't work. I'm sure I am overlooking something fundamental. Any ideas?
Parents
  • Hi Todd - I also struggled with this. I'll log a bug report because I think that this should work but it doesn't for me:
    cont.stiffness=Adams.expression("(dv_1)")
     
    So instead you can do some string formatting and issue cmd to get around this:
    cmd = "contact modify contact={} stiffness=( {} )".format('contact_1', 'dv_1')
    Adams.execute_cmd(cmd)
     
    HTH,
    Kent
     
Reply
  • Hi Todd - I also struggled with this. I'll log a bug report because I think that this should work but it doesn't for me:
    cont.stiffness=Adams.expression("(dv_1)")
     
    So instead you can do some string formatting and issue cmd to get around this:
    cmd = "contact modify contact={} stiffness=( {} )".format('contact_1', 'dv_1')
    Adams.execute_cmd(cmd)
     
    HTH,
    Kent
     
Children
No Data