Multipoint Optimization


Optimization does not have to be limited to a single flight condition. This section goes through the same optimization as the single point case, except with one more flight condition. Instead of rewriting the code from scratch, the differences in code will be pointed out.


Different parallelizations are possible with multipoint optimizations. In this tutorial, all of the processors will be used to solve the first AeroProblem, then they will all switch and solve the second AeroProblem. Alternatively, it’s possible to solve both simultaneously by using twice the number of processors, but load balancing becomes an issue.

The optimization problem is defined as:

average drag: \(\frac{1}{2} \left(C_{D,0} + C_{D,1}\right)\)
with respect to
10 shape variables
subject to
\(C_{L,0} = 0.5\)
\(C_{L,1} = 0.7\)
\(V \ge V_0\)
\(t \ge 0.1t_0\)
\(\Delta z_\text{LETE, upper} = -\Delta z_{LETE, lower}\)


Navigate to the directory airfoilopt/multipoint in your tutorial folder. Copy the FFD file,, and the CGNS mesh file, n0012.cgns, generated previously, into the directory:

cp ../mesh/n0012.cgns .
cp ../ffd/ .

Copy the singlepoint script from the previous section to a new file in this directory:

cp ../singlepoint/

Highlighting the changes required in the multipoint optimization script

Open the file in your favorite text editor. Change the following sections for multipoint optimization.

Specifying parameters for the optimization

For multipoint optimization, the parameters have to be specified in lists of the same size.

# specify flight conditions and constraints
mach = [0.75, 0.5]
alt = [10000, 5000]
alpha = [1.5, 5]
mycl = [0.5, 0.7]
# number of points in multipoint optimization
nFlowCases = len(mach)

Creating processor sets

This is largely unchanged from the single-point case, since we use a very similar parallelization scheme. The only difference is in defining the variable nGroup which is used later on to distinguish between the two AeroProblems.

# assign number of processors
nGroup = 1
nProcPerGroup = MPI.COMM_WORLD.size
MP = multiPointSparse(MPI.COMM_WORLD)
MP.addProcessorSet("cruise", nMembers=nGroup, memberSizes=nProcPerGroup)
comm, setComm, setFlags, groupFlags, ptID = MP.createCommunicators()
if not os.path.exists(args.output):
    if comm.rank == 0:

Set the AeroProblem

For more than one AeroProblem, a list needs to be created. Each AeroProblem is created with the respective optimization point and appended to the list.

aeroProblems = []
for i in range(nFlowCases):
    ap = AeroProblem(
        name="fc%d" % i,
        evalFuncs=["cl", "cd"],
    # Add angle of attack variable
    ap.addDV("alpha", value=alpha[i], lower=0, upper=10.0, scale=1.0)

Optimization callback functions

The same for-loop needs to be added to the callback functions. The lines that require a call to the an AeroProblem is now put into a for-loop to iterate through all of them.

def cruiseFuncs(x):
    if MPI.COMM_WORLD.rank == 0:
    # Set design vars
    # Evaluate functions
    funcs = {}

    for i in range(nFlowCases):
        if i % nGroup == ptID:
            CFDSolver.evalFunctions(aeroProblems[i], funcs)
            CFDSolver.checkSolutionFailure(aeroProblems[i], funcs)
    if MPI.COMM_WORLD.rank == 0:
    return funcs

def cruiseFuncsSens(x, funcs):
    funcsSens = {}
    for i in range(nFlowCases):
        if i % nGroup == ptID:
            CFDSolver.evalFunctionsSens(aeroProblems[i], funcsSens)
            CFDSolver.checkAdjointFailure(aeroProblems[i], funcsSens)
    if MPI.COMM_WORLD.rank == 0:
    return funcsSens

def objCon(funcs, printOK):
    # Assemble the objective and any additional constraints:
    funcs["obj"] = 0.0
    for i in range(nFlowCases):
        ap = aeroProblems[i]
        funcs["obj"] += funcs[ap["cd"]] / nFlowCases
        funcs["cl_con_" +] = funcs[ap["cl"]] - mycl[i]
    if printOK:
        print("funcs in obj:", funcs)
    return funcs

In the objCon function, the \(c_l\) constraint is also placed into the for-loop.

Optimization problem

The only difference here is that we now have two different \(c_l\) constraints, one for each point. These are added in a loop. In addition, we use the wrt keyword to specify the variables that affect each lift constraint. In this case, the alpha from the other flight conditions do not impact the lift constraint, so they are set to zero.

# Create optimization problem
optProb = Optimization("opt", MP.obj, comm=MPI.COMM_WORLD)

# Add objective
optProb.addObj("obj", scale=1e4)

# Add variables from the AeroProblem
for ap in aeroProblems:

# Add DVGeo variables

# Add constraints
for ap in aeroProblems:
    optProb.addCon(f"cl_con_{}", lower=0.0, upper=0.0, scale=1.0, wrt=[f"alpha_{}", "shape"])

# The MP object needs the 'obj' and 'sens' function for each proc set,
# the optimization problem and what the objcon function is:
MP.setProcSetObjFunc("cruise", cruiseFuncs)
MP.setProcSetSensFunc("cruise", cruiseFuncsSens)

Run it yourself!

The script can be run in the same way

mpirun -np 4 python | tee output.txt