def cs3posObjFun(posDict):
    #- Target function (AEP calculation) -#

    # Take our turbine array [x1 ... y1...] and make a matrix
    x0m = Iea37sb.makeArrayMatrix(posDict['aTurbCoords'])
    #nTurbs = len(x0m)  # get the number of turbines
    #nPairs = int(binom(nTurbs, 2))  # Number of unique turbine pairs
    funcs = {}
    AEP = g(x0m)  # Our tricky global function
    totAEP = np.sum(AEP)
    funcs['obj'] = -(totAEP)  # / fScaleFactorAEP) # Negative to minimize

    #- Prep data for constraints -#
    #fScaleFactorTurbLoc = posDict['fTCscale']
    x0s = Iea37sb.makeArrayCoord(posDict['aTurbCoords'])
    [fNormVals, __] = Iea37sb.calcDistNorms(x0s, dictParams['cncvVerts'],
                                            dictParams['cncvNorms'])
    funcs['bndry'] = fNormVals.flatten()
    fTurbSpace, __ = Iea37sb.checkTurbSpacing(x0s, dictParams['minTurbSpace'])
    funcs['spacing'] = fTurbSpace

    #- Constraints (Pairwise distance [C(numTurbs, 2)], and all boundary checks [4* numTurbs]) -#
    #nBndryCnstr = nTurbs * 4 # each turbine (25) has one constraint for each boundary (4)
    #nSpaceCnstr = nPairs
    #conval = [0]*(nBndryCnstr + nSpaceCnstr)
    # List all the boundary and spacing constraints
    #conval = np.concatenate(cnstrSpacing, nBndryCnstr)
    #funcs['con'] = conval

    fail = False

    return funcs, fail
    bestResult = np.zeros(2)  # Index, AEP number
    timeArray = np.zeros(numRestarts)  # To hold timing information

    #- Loop for every restart -#
    for cntr in range(numRestarts):
        print("Restart #" + str(cntr + 1) + "/" + str(numRestarts) +
              " (index " + str(cntr) + ")")
        timeStart = time.time()  # Start the clock
        #-- Use our pregenerated turbine locations --#
        x0l = []  # Initialize our turbine <coord> list
        for i in range(nNumRegions):  # Loop through our regions
            PreStarts = np.loadtxt('./results/randostarts-' +
                                   Iea37sb.cs34Regions().getRegionName(i) +
                                   '-200.csv',
                                   delimiter=',')
            x0l.extend(Iea37sb.makeArrayCoord(PreStarts[cntr]))
        x0 = Iea37sb.makeCoordListArray(x0l)
        x0s = Iea37sb.makeArrayCoord(x0)

        #- Get our turbine list ready for processing -#
        #x0 = Iea37sb.makeCoordArray(x0s)#/ Args['fTCscale']         # Get a random turbine placement and scale it
        startAEP = Iea37sb.optimoFun(x0, Args)
        print("Start AEP = " +
              str(startAEP * scaledAEP))  #*Args['fAEPscale']))

        cons = ({
            'type':
            'ineq',
            'fun':
            lambda x: Iea37sb.checkBndryConsCs4(
                x, nRegionNumTurbs, splineMatDict, coordsCornersDict)
Esempio n. 3
0
    Boundry constraint: Boundary normal method, (partial boundary, convex)
    Optimizer: scipy.minimize()
"""
if __name__ == "__main__":
    numTurbs = 25
    scaledAEP = 1  #e5
    scaledTC = 1  #e3

    #- Load the boundary (with scaling) -#
    fn = "../startup-files/iea37-boundary-cs3.yaml"
    #bndryPts = Iea37sb.getTurbAtrbtCs3YAML(fn)  # Normal read
    #- Scaled read -#
    tempPtsCoord = Iea37sb.getTurbAtrbtCs3YAML(fn)  # Read in as <coord>
    tempPtsArray = Iea37sb.makeCoordArray(
        tempPtsCoord) / scaledTC  # Convert to an array to scale
    bndryPts = Iea37sb.makeArrayCoord(
        tempPtsArray)  # Convert back to <coord> type

    clsdBP = Iea37sb.closeBndryList(
        bndryPts)  # Duplicate the 1st coord for a closed boundary
    cncvBP = Iea37sb.makeSimpleCs3Bndry(clsdBP)  # Make the boundary concave
    BndryNormals = Iea37sb.bndryNormals(cncvBP)

    #- Load the turbine and windrose atributes -#
    fname_turb = "../startup-files/iea37-10mw.yaml"
    fname_wr = "../startup-files/iea37-windrose-cs3.yaml"
    wind_dir, wind_dir_freq, wind_speeds, wind_speed_probs, num_speed_bins, min_speed, max_speed = iea37aepC.getWindRoseYAML(
        fname_wr)
    turb_ci, turb_co, rated_ws, rated_pwr, turb_diam = iea37aepC.getTurbAtrbtYAML(
        fname_turb)
    turb_diam = turb_diam / scaledTC
    fname_wr)
turb_ci, turb_co, rated_ws, rated_pwr, turb_diam = iea37aepC.getTurbAtrbtYAML(
    fname_turb)
#- Make a dictionary for variable passing -#
dictParams = dict([('wind_dir_freq', wind_dir_freq),
                   ('wind_speeds', wind_speeds),
                   ('wind_speed_probs', wind_speed_probs),
                   ('wind_dir', wind_dir), ('turb_diam', turb_diam),
                   ('fMinTurbDist', fMinTurbDist), ('turb_ci', turb_ci),
                   ('turb_co', turb_co), ('rated_ws', rated_ws),
                   ('rated_pwr', rated_pwr), ('splineMatDict', splineMatDict),
                   ('coordsCornersDict', coordsCornersDict),
                   ('nRegionNumTurbs', nRegionNumTurbs)])

#- Necessary constants -#
nNumRegions = 5
x0l = []  # Initialize our turbine <coord> list
nRunToRead = 14

# Read in the correct file
for i in range(nNumRegions):  # Loop through our regions
    PreStarts = np.loadtxt('./results/baker-cs3-bpm-snopt.csv', delimiter=',')
    x0l.extend(Iea37sb.makeArrayCoord(PreStarts[nRunToRead]))

x0 = Iea37sb.makeCoordListArray(x0l)
x0s = Iea37sb.makeArrayCoord(x0)
startAEP = Iea37sb.optimoFun(x0, dictParams)
print("Start AEP = " + str(startAEP * scaledAEP))  # *Args['fAEPscale']))
# Convert to correct format
# Write to a .yaml file.