How to control number of cores used when solving Mechanical system in WB in batch?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 174
100 Comments Photogenic Ansys Employee 5 Likes
✭✭✭✭

I have a Mechanical System in WB. I am running WB and updating it in batch. But, how to control number of cores used for Mechanical solve?

Best Answer

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 174
    100 Comments Photogenic Ansys Employee 5 Likes
    ✭✭✭✭
    edited September 5 Answer ✓

    Here are the steps to launch WB in batch along with option to change number of cores used for the Mechanical solve.

    Step 1: Create a .bat file with the below command to launch WB version 24R2 in batch and run a python script once WB opens (this is to change number of cores in Mechanical and solve)

    "%AWP_ROOT242%\Framework\bin\Win64\runwb2" -B -R wb_Batch_MechCoreChange.py

    Step 2: Create .py file referenced above and use the below commands in it. This assumes that the input WB project is an archive with name "FileName". The script also assumes that we are solving in Foreground mode (and not Background mode or RSM - If so, the corresponding string that one sees in Mechanical needs to be used instead of "My Computer" say, "My Computer, Background"). The solve is done with 3 cores. Once solved, save and create a new archive.

    Unarchive(ArchivePath="FileName.wbpz", ProjectPath="FileName.wbpj", Overwrite=True)
    
    #Example script to set number of cores in Mechanical
    mechScriptCmds="""
    config2 = ExtAPI.Application.SolveConfigurations["My Computer"]
    config2.SolveProcessSettings.MaxNumberOfCores = 3
    """
    mySys = GetAllSystems()[0]
    model = mySys.GetContainer(ComponentName="Model")
    model.Edit(Interactive=False)
    #Uncomment the below command if you want to insert some Mechanical Scripting commands to be executed once Mechanical is opened in Batch and before solving
    model.SendCommand(Language="Python", Command=mechScriptCmds)
    
    Update()
    Save(Overwrite=True)
    Archive(FilePath="FileName-result.wbpz")
    

Answers

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 174
    100 Comments Photogenic Ansys Employee 5 Likes
    ✭✭✭✭

    If opening a .wbpj project instead of an archive project, please use the below script.

    import os
    projectDir = r"D:/del"
    projectName = r"testwb.wbpj"
    projectPath = os.path.join(projectDir,projectName)
    
    Open(FilePath=projectPath)
    
    mechScriptCmds="""
    config2 = ExtAPI.Application.SolveConfigurations["My Computer"]
    config2.SolveProcessSettings.MaxNumberOfCores = 6
    """
    
    mySys = GetAllSystems()[0]
    model = mySys.GetContainer(ComponentName="Model")
    model.Edit(Interactive=False)
    model.SendCommand(Language="Python", Command=mechScriptCmds)
    
    Update()
    Save(Overwrite=True)