Example #1
0
            opt.optimize()

            # Get the optimized point
            x, z, zw, zl, zu = opt.getOptimizedPoint()
            # Write the solution out to a file
            if i % args.output_freq == 0:
                # Compute the iteration counter
                itr = ite * args.max_opt_iters + i

                # Get the vector and convert it
                vec = problem.convertPVecToVec(x)

                for k in range(vars_per_node):
                    f = 'levelset05_var%d_binary%04d.bstl' % (k, itr)
                    filename = os.path.join(args.prefix, f)
                    TMR.writeSTLToBin(filename, filtr, vec, offset=k)

            # Update the trust region method
            infeas, l1, linfty = tr.update(x, z, zw)
            # Check for convergence using relatively strict tolerances
            if infeas < 1e-4 and l1 < 0.01:
                break
        # Set the old values of the variables
        old_x, z, zw, zl, zu = opt.getOptimizedPoint()
    elif use_paropt:
        # Create the ParOpt problem
        opt = ParOpt.pyParOpt(problem, args.max_lbfgs, ParOpt.BFGS)

        # Set parameters
        opt.setMaxMajorIterations(args.max_opt_iters)
        opt.setHessianResetFreq(args.hessian_reset)
Example #2
0
        # Enter the optimization loop
        for i in range(max_mma_iters):
            filename = os.path.join(args.prefix, 'paropt%04d.out' % (i))
            opt.setOutputFile(filename)
            opt.setInitBarrierParameter(0.1)
            opt.optimize()

            # Write the solution out to a file
            if i % args.output_freq == 0:
                itr = max_mma_iters * ite + i
                filename = os.path.join(args.prefix,
                                        'levelset05_binary%04d.bstl' % (itr))

                # Get the vector and convert it
                vec = problem.convertPVecToVec(mma.getOptimizedPoint())
                TMR.writeSTLToBin(filename, filtr, vec)

            # Get the optimized point
            x, z, zw, zl, zu = opt.getOptimizedPoint()
            mma.setMultipliers(z, zw)
            mma.initializeSubProblem(x)
            opt.resetDesignAndBounds()

            # Compute the KKT error
            l1_norm, linfty_norm, infeas = mma.computeKKTError()
            if comm.rank == 0:
                print 'z = ', z
                print 'l1_norm = ', l1_norm
                print 'infeas = ', infeas

            if l1_norm < 1e-3 and infeas < 1e-6: