Example #1
0
    print('Running Local Optimization')
    LocalOpt = TheSystem.Tools.OpenLocalOptimization()
    LocalOpt.Algorithm = constants.OptimizationAlgorithm_DampedLeastSquares
    LocalOpt.Cycles = constants.OptimizationCycles_Automatic
    LocalOpt.NumberOfCores = 8
    LocalOptCast = CastTo(LocalOpt, 'ISystemTool')
    LocalOptCast.RunAndWaitForCompletion()
    LocalOptCast.Close()
    #! [e03s05_py]

    #! [e03s06_py]
    # Hammer for 10 seconds
    # need to 'import time' at the top of the file to use the pause function
    print('Running Hammer Optimization')
    HammerOpt = TheSystem.Tools.OpenHammerOptimization()
    HammerOptCast = CastTo(HammerOpt, 'ISystemTool')
    HammerOptCast.Run()
    time.sleep(10)
    HammerOptCast.Cancel()
    HammerOptCast.Close()
    #! [e03s06_py]

    #Save and close
    TheSystem.Save()

    # This will clean up the connection to OpticStudio.
    # Note that it closes down the server instance of OpticStudio, so you for maximum performance do not do
    # this until you need to.
    del zosapi
    zosapi = None
Example #2
0
            print(str(int(j)) + ': ' + str(GlobalOpt.CurrentMeritFunction(j)))
        baseTool.Cancel()
        time.sleep(1)
        baseTool.Close()
    # ! [e15s14_py]
    '''
    # ! [e15s15_py]
    # run hammer optimization
    HammerOptimTimeInSeconds = 1
    HammerOpt = TheSystem.Tools.OpenHammerOptimization()
    if (HammerOpt != None):
        print(HammerOpt.Algorithm)
        print(HammerOpt.NumberOfCores)
        print('Hammer Optimization for ' + str(HammerOptimTimeInSeconds) +
              ' seconds...')
        print('Initial Merit Function ', HammerOpt.InitialMeritFunction)
        baseTool = CastTo(HammerOpt, 'ISystemTool')
        baseTool.RunAndWaitWithTimeout(1 * HammerOptimTimeInSeconds)
        print('Final Merit Function ', HammerOpt.CurrentMeritFunction)

        baseTool.Cancel()
        baseTool.Close()
    # ! [e15s15_py]

    TheSystem.Save()

    # This will clean up the connection to OpticStudio.
    # Note that it closes down the server instance of OpticStudio, so you for maximum performance do not do
    # this until you need to.
    del zosapi
    zosapi = None