def obj_func(xdict):
    global dia
    global tsr
    global solidity
    global Cp
    global dens
    global velf
    global funcs
    
    Vars = xdict['xvars']
    x = xdict['xvars']
    y = xdict['yvars']
    funcs = {}
    
    veleff = np.zeros_like(x)
    power_turb = np.zeros_like(x)
    
    for i in range(np.size(x)):
        xp = np.delete(x,i)
        yp = np.delete(y,i)
        diap = np.delete(dia,i)
        tsrp = np.delete(tsr,i)
        solidityp = np.delete(solidity,i)
        veleff[i] = overlap(xp,yp,diap,tsrp,solidityp,x[i],y[i],dia[i],velf,True,False)
        power_turb[i] = powerval(Cp,dens,veleff[i],dia[i])
        # print i+1
    
    power = np.sum(power_turb)
    print power 
    funcs['obj'] = (-1.0*power)
    
    sep = sep_func(np.append(x,y))
    funcs['sep'] = sep
    funcs['veleff'] = veleff
    funcs['power_turb'] = power_turb
    
    fail = False

    return funcs, fail
 spacing = 5     # turbine grid spacing in diameters
 
 # Set up position arrays
 points = np.linspace(spacing*turb_dia,nRows*spacing*turb_dia,nRows)
 xpoints, ypoints = np.meshgrid(points, points)
 xt = np.ndarray.flatten(xpoints)
 yt = np.ndarray.flatten(ypoints)
 dia = np.ones_like(xt)*turb_dia
 tsr = np.ones_like(xt)*4.0
 solidity = np.ones_like(xt)*0.25
 
 Cp = 0.4
 dens = 1.225
 velf = 15.
 
 power_iso = powerval(Cp,dens,velf,turb_dia)
 
 x0 = xt
 y0 = yt
 area = 2
 xlow = points[0]-spacing*area
 xupp = points[-1]+spacing*area
 ylow = points[0]-spacing*area
 yupp = points[-1]+spacing*area
 
 optProb = Optimization('VAWT_Power', obj_func)
 optProb.addObj('obj')
 
 n = np.size(x0)
 optProb.addVarGroup('xvars', n, 'c', lower=xlow, upper=xupp, value=x0)
 optProb.addVarGroup('yvars', n, 'c', lower=ylow, upper=yupp, value=y0)