Script for Ansys LS-Dyna / Mechanical

Louis
Louis Member Posts: 16
10 Comments Photogenic Name Dropper
**
edited June 2023 in Structures

Ansys LS-Dyna / Mechanical 2023R1

How could I use script and/or ACT to

  • Generate CFL time-step in Ansys LS-Dyna
  • Get its Minimum CFL value and Maximum CFL value

Best Answer

  • Aria
    Aria Member, Employee Posts: 67
    25 Answers 25 Likes 10 Comments First Anniversary
    ✭✭✭✭
    Answer ✓

    Some calls seem to be asynchronous. For instance, when scoping the bodies to the CFL object, it appears to still be under-defined. For this reason I create a dummy comment object and delete it which will update the comment object.

    the import() method initiates the cfl generation but this too seem to have issues, which is why i activate the model object and then the cfl object again. 

    for larger models i would maybe try putting in a time.sleep(x) after the x.Import() 


    msscl = ExtAPI.DataModel.CreateObject("TimeStepCalc",'LSDYNA')
    allbodies = Model.Geometry.GetChildren[Ansys.ACT.Automation.Mechanical.Body](True)
    
    bodies = [x.GetGeoBody().Id for x in allbodies if x.Suppressed == False]
    
    sel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    sel.Ids = bodies
    msscl.Properties['Geometry/DefineBy/Geo'].Value = sel
    temp = Model.AddComment()
    temp.Delete()
    
    
    
    msscl.Import()
    Model.Activate()
    msscl.Activate()
    
    
    print msscl.Properties['Minimum CFL value'].Value.ToString()
    print msscl.Properties['Maximum CFL value'].Value.ToString()
    

Answers

  • Louis
    Louis Member Posts: 16
    10 Comments Photogenic Name Dropper
    **

    Aria,

    It works. Thank you very much!

    This challenge has bothered me for a long time. Finally got this fixed.

  • Louis
    Louis Member Posts: 16
    10 Comments Photogenic Name Dropper
    **

    One further question -

    if this CFL Time Step object has been already created. How to get it and activate this existing CFL object?

    I tried to get this object by ExtAPI.DataModel......as below, but got error.


    ExtAPI.DataModel.Project.Children[0].Children[9].Import()

    'DataModelObject' object has no attribute 'Import'

  • Louis
    Louis Member Posts: 16
    10 Comments Photogenic Name Dropper
    **

    @Aria , could you help on the follow-up question....thank you.

  • Aria
    Aria Member, Employee Posts: 67
    25 Answers 25 Likes 10 Comments First Anniversary
    ✭✭✭✭

    @Louis The CFL timestep is a custom object, it has to be retrieved like this:

    userObjs = ExtAPI.DataModel.GetUserObjects("LSDYNA")
    myTimeStepObj = [obj for obj in userObjs if obj.Name == "TimeStepCalc"]
    if len(myTimeStepObj)>0:
        myTimeStepObj=myTimeStepObj[0]
    


  • Louis
    Louis Member Posts: 16
    10 Comments Photogenic Name Dropper
    **

    Aria,

    This could be closed.

    Thanks a lot for the answering.