def obj_func(xdict): global windDirections global windSpeeds global windFrequencies global boundaryVertices global boundaryNormals global damage_free global damage_close global damage_far turbineX = xdict['turbineX'] turbineY = xdict['turbineY'] """turbine definition""" turbineZ = np.ones_like(turbineX) * 90. rotorDiameter = np.ones_like(turbineX) * 126.4 shearExp = 0. wakemodel = 2 relaxationFactor = 1. rated_ws = 11.4 rated_power = 5000. cut_in_speed = 3. cut_out_speed = 25. zref = 90. z0 = 0. funcs = {} AEP = fast_calc_aep.calcaep(turbineX, turbineY, turbineZ, rotorDiameter, windDirections, windSpeeds, windFrequencies, shearExp, wakemodel, relaxationFactor, rated_ws, rated_power, cut_in_speed, cut_out_speed, zref, z0) funcs['AEP'] = -AEP / 1.E6 separation_squared, boundary_distances = constraints.constraints_position( turbineX, turbineY, boundaryVertices, boundaryNormals) funcs['sep'] = (separation_squared - (126.4 * 2.)**2) / 1.E5 bounds = boundary_distances # funcs['sep'] = SpacingConstraint(turbineX, turbineY, rotorDiameter, minSpacing=2.0)/1.E5 # bounds = arbitraryBoundary(turbineX, turbineY, boundaryVertices, boundaryNormals)/1.E3 b = np.zeros(np.shape(bounds)[0]) for i in range(len(b)): b[i] = min(bounds[i]) funcs['bound'] = b funcs['damage'] = farm_damage(turbineX, turbineY, windDirections, windFrequencies, damage_free, damage_close, damage_far) # funcs['damage'] = np.max(farm_damage(turbineX,turbineY,windDirections,windFrequencies,damage_free,damage_close,damage_far)) fail = False return funcs, fail
import time import sys sys.path.insert(0, '/fslhome/pjstanle/compute/reduction') from position_constraints import * nTurbines = 5 turbineX = np.random.rand(nTurbines) * 1200. turbineY = np.random.rand(nTurbines) * 1200. #circular boundary boundaryVertices = np.zeros((1, 2)) boundaryVertices[0] = np.array([1000., 0.]) boundaryNormals = np.zeros((1, 2)) boundaryNormals[0] = np.array([0., 0.]) s_fortran, b_fortran = constraints.constraints_position( turbineX, turbineY, boundaryVertices, boundaryNormals) # FD s_fd_x = np.zeros((nTurbines, ((nTurbines - 1) * nTurbines / 2))) s_fd_y = np.zeros((nTurbines, ((nTurbines - 1) * nTurbines / 2))) b_fd_x = np.zeros((nTurbines, nTurbines, 1)) b_fd_y = np.zeros((nTurbines, nTurbines, 1)) d = 1E-5 for i in range(nTurbines): x = np.zeros(nTurbines) y = np.zeros(nTurbines) x[:] = turbineX y[:] = turbineY x[i] += d y[i] += d s_x, b_x = constraints.constraints_position(x, turbineY, boundaryVertices,
def obj_func_no_damage(xdict): global windDirections global windSpeeds global windFrequencies global boundaryVertices global boundaryNormals global Omega_free global free_speed global Omega_close global close_speed global Omega_far global far_speed global Rhub global r global chord global theta global af global Rtip global B global rho global mu global precone global hubHt global nSector global pitch global yaw_deg global TI global scale turbineX = xdict['turbineX']*scale turbineY = xdict['turbineY']*scale """turbine definition""" turbineZ = np.ones_like(turbineX)*90. rotorDiameter = np.ones_like(turbineX)*126.4 shearExp = 0. wakemodel = 2 relaxationFactor = 1. rated_ws = 11.4 rated_power = 5000. cut_in_speed = 3. cut_out_speed = 25. zref = 90. z0 = 0. funcs = {} AEP = calcAEP(turbineX,turbineY,windDirections,windSpeeds,windFrequencies,TI=TI) funcs['AEP'] = -AEP/1.E7 separation_squared,boundary_distances = constraints.constraints_position(turbineX,turbineY,boundaryVertices,boundaryNormals) funcs['sep'] = (separation_squared-(126.4*2.)**2)/1.E5 bounds = boundary_distances # funcs['sep'] = SpacingConstraint(turbineX, turbineY, rotorDiameter, minSpacing=2.0)/1.E5 # bounds = arbitraryBoundary(turbineX, turbineY, boundaryVertices, boundaryNormals)/1.E3 b = np.zeros(np.shape(bounds)[0]) for i in range(len(b)): b[i] = min(bounds[i]) funcs['bound'] = b fail = False return funcs, fail
nTurbines = 15 turbineX = np.random.rand(nTurbines)*1200. turbineY = np.random.rand(nTurbines)*1200. #spacing ss_fortran = constraints.turbine_spacing_squared(turbineX,turbineY) ss_python = turbineSpacingSquared(turbineX,turbineY) print ss_fortran - ss_python #boundary circle boundaryVertices = np.zeros((1,2)) boundaryVertices[0] = np.array([1000.,0.]) boundaryNormals = np.zeros((1,2)) boundaryNormals[0] = np.array([0.,0.]) bc_fortran = constraints.boundary_distances(turbineX, turbineY, boundaryVertices, boundaryNormals) bc_python = circularBoundary(turbineX, turbineY, 1000.) print np.ndarray.flatten(bc_fortran) - bc_python #boundary polygon locations = np.loadtxt('/home/flowlab/PJ/reduction/layout_amalia.txt') boundaryVertices, boundaryNormals = calculate_boundary(locations) bp_fortran = constraints.boundary_distances(turbineX, turbineY, boundaryVertices, boundaryNormals) bp_python = arbitraryBoundary(turbineX, turbineY, boundaryVertices, boundaryNormals) print bp_fortran - bp_python s_fortran, b_fortran = constraints.constraints_position(turbineX, turbineY, boundaryVertices, boundaryNormals) print ss_python-s_fortran print bp_python-b_fortran