def run(method_dict, n): """ method_dict = {} keys of method_dict: 'method' = 'dakota', 'rect' or 'chaospy' # 'chaospy needs updating 'wake_model = 'floris', 'jensen', 'gauss', 'larsen' # larsen is not working 'coeff_method' = 'quadrature', 'sparse_grid' or 'regression' 'uncertain_var' = 'speed', 'direction' or 'direction_and_speed' 'layout' = 'amalia', 'optimized', 'grid', 'random', 'test' 'distribution' = a distribution object 'dakota_filename' = 'dakotaInput.in', applicable for dakota method 'offset' = [0, 1, 2, Noffset-1] 'Noffset' = 'number of starting directions to consider' Returns: Writes a json file 'record.json' with the run information. """ ### For visualization purposes. Set up the file that specifies the points for the polynomial approximation ### if method_dict['method'] == 'dakota': approximate.generate_approx_file(method_dict['uncertain_var']) ### Set up the wind speeds and wind directions for the problem ### points = windfarm_setup.getPoints(method_dict, n) winddirections = points['winddirections'] windspeeds = points['windspeeds'] weights = points['weights'] # This might be None depending on the method. N = winddirections.size # actual number of samples print 'Locations at which power is evaluated' print '\twindspeed \t winddirection' for i in range(N): print i+1, '\t', '%.2f' % windspeeds[i], '\t', '%.2f' % winddirections[i] # Turbines layout turbineX, turbineY = windfarm_setup.getLayout(method_dict['layout']) # turbine size and operating conditions rotor_diameter = 126.4 # (m) air_density = 1.1716 # kg/m^3 # initialize arrays for each turbine properties nTurbs = turbineX.size rotorDiameter = np.zeros(nTurbs) axialInduction = np.zeros(nTurbs) Ct = np.zeros(nTurbs) Cp = np.zeros(nTurbs) generator_efficiency = np.zeros(nTurbs) yaw = np.zeros(nTurbs) # define initial values for turbI in range(nTurbs): rotorDiameter[turbI] = rotor_diameter axialInduction[turbI] = 1.0/3.0 Ct[turbI] = 4.0*axialInduction[turbI]*(1.0-axialInduction[turbI]) Cp[turbI] = 0.7737/0.944 * 4.0 * 1.0/3.0 * np.power((1 - 1.0/3.0), 2) generator_efficiency[turbI] = 0.944 yaw[turbI] = 0. # deg. # define wake model inputs if method_dict['wake_model'] is 'floris': wake_model = floris_wrapper IndepVarFunc = add_floris_params_IndepVarComps elif method_dict['wake_model'] is 'jensen': wake_model = jensen_wrapper IndepVarFunc = add_jensen_params_IndepVarComps elif method_dict['wake_model'] is 'gauss': wake_model = gauss_wrapper IndepVarFunc = add_gauss_params_IndepVarComps else: raise KeyError('Invalid wake model selection. Must be one of [floris, jensen, gauss]') # initialize problem prob = Problem(AEPGroup(nTurbines=nTurbs, nDirections=N, method_dict=method_dict, wake_model=wake_model, params_IdepVar_func=IndepVarFunc)) prob.setup(check=False) # assign initial values to variables prob['windSpeeds'] = windspeeds prob['windDirections'] = winddirections prob['windWeights'] = weights prob['rotorDiameter'] = rotorDiameter prob['axialInduction'] = axialInduction prob['generatorEfficiency'] = generator_efficiency prob['air_density'] = air_density prob['Ct_in'] = Ct prob['Cp_in'] = Cp prob['turbineX'] = turbineX prob['turbineY'] = turbineY for direction_id in range(0, N): prob['yaw%i' % direction_id] = yaw # Run the problem prob.pre_run_check() prob.run() # For visualization purposes. Get the PC approximation if method_dict['method'] == 'dakota': winddirections_approx, windspeeds_approx, power_approx = approximate.get_approximation(method_dict) else: winddirections_approx = np.array([None]) windspeeds_approx = np.array([None]) power_approx = np.array([None]) # print the results mean_data = prob['mean'] std_data = prob['std'] factor = 1e6 print 'mean = ', mean_data/factor, ' GWhrs' print 'std = ', std_data/factor, ' GWhrs' power = prob['dirPowers'] return mean_data/factor, std_data/factor, N, winddirections, windspeeds, power,\ winddirections_approx, windspeeds_approx, power_approx
def run(method_dict): """ method_dict = {} keys of method_dict: 'method' = 'dakota', 'rect' or 'chaospy' # 'chaospy needs updating 'uncertain_var' = 'speed' or 'direction' 'layout' = 'amalia', 'optimized', 'grid', 'random', 'test' 'distribution' = a distribution object 'dakota_filename' = 'dakotaInput.in', applicable for dakota method 'offset' = [0, 1, 2, Noffset-1] 'Noffset' = 'number of starting directions to consider' Returns: Writes a json file 'record.json' with the run information. """ mean = [] std = [] samples = [] for n in range(100, 101, 1): ### Set up the wind speeds and wind directions for the problem ### points, weights = windfarm_setup.getPoints(method_dict, n) if method_dict['uncertain_var'] == 'speed': # For wind speed windspeeds = points winddirections = np.ones(n) * 225 elif method_dict['uncertain_var'] == 'direction': # For wind direction windspeeds = np.ones(n) * 8 winddirections = points else: raise ValueError( 'unknown uncertain_var option "%s", valid options "speed" or "direction".' % method_dict['uncertain_var']) print 'Locations at which power is evaluated' print '\twindspeed \t winddirection' for i in range(n): print i + 1, '\t', '%.2f' % windspeeds[ i], '\t', '%.2f' % winddirections[i] # Turbines layout turbineX, turbineY = windfarm_setup.getLayout(method_dict['layout']) filename = "layout_1_5_XY.txt" optimized = open(filename) x_y = np.loadtxt(optimized) turbineX = x_y[:, 0] turbineY = x_y[:, 1] # turbine size and operating conditions rotor_diameter = 126.4 # (m) air_density = 1.1716 # kg/m^3 # initialize arrays for each turbine properties nTurbs = turbineX.size rotorDiameter = np.zeros(nTurbs) axialInduction = np.zeros(nTurbs) Ct = np.zeros(nTurbs) Cp = np.zeros(nTurbs) generator_efficiency = np.zeros(nTurbs) yaw = np.zeros(nTurbs) # define initial values for turbI in range(nTurbs): rotorDiameter[turbI] = rotor_diameter axialInduction[turbI] = 1.0 / 3.0 Ct[turbI] = 4.0 * axialInduction[turbI] * (1.0 - axialInduction[turbI]) Cp[turbI] = 0.7737 / 0.944 * 4.0 * 1.0 / 3.0 * np.power( (1 - 1.0 / 3.0), 2) generator_efficiency[turbI] = 0.944 yaw[turbI] = 0. # deg. # initialize problem prob = Problem( AEPGroup(nTurbines=nTurbs, nDirections=n, method_dict=method_dict)) prob.setup(check=False) # assign initial values to variables prob['windSpeeds'] = windspeeds prob['windDirections'] = winddirections prob['weights'] = weights prob['rotorDiameter'] = rotorDiameter prob['axialInduction'] = axialInduction prob['generatorEfficiency'] = generator_efficiency prob['air_density'] = air_density prob['Ct_in'] = Ct prob['Cp_in'] = Cp prob['turbineX'] = turbineX prob['turbineY'] = turbineY for direction_id in range(0, n): prob['yaw%i' % direction_id] = yaw # Run the problem prob.run() # print the results mean_data = prob['mean'] std_data = prob['std'] print 'mean = ', mean_data / 1e6, ' GWhrs' print 'std = ', std_data / 1e6, ' GWhrs' mean.append(mean_data / 1e6) std.append(std_data / 1e6) samples.append(n) # Save a record of the run power = prob['power'] obj = { 'mean': mean, 'std': std, 'samples': samples, 'winddirections': winddirections.tolist(), 'windspeeds': windspeeds.tolist(), 'power': power.tolist(), 'method': method_dict['method'], 'uncertain_variable': method_dict['uncertain_var'], 'layout': method_dict['layout'] }
windspeeds = points winddirections = np.ones(n)*225 elif method_dict['uncertain_var'] == 'direction': # For wind direction windspeeds = np.ones(n)*8 winddirections = points else: raise ValueError('unknown uncertain_var option "%s", valid options "speed" or "direction".' %method_dict['uncertain_var']) print('Locations at which power is evaluated') print('\twindspeed \t winddirection') for i in range(n): print(i+1, '\t', '%.2f' % windspeeds[i], '\t', '%.2f' % winddirections[i]) # Turbines layout turbineX, turbineY = windfarm_setup.getLayout(method_dict['layout']) locations = np.column_stack((turbineX, turbineY)) # generate boundary constraint # boundaryVertices, boundaryNormals = calculate_boundary(locations) #amalia boundaryVertices boundaryVertices = np.array([ [ 3710.176, 3569.028], [ 1683.694, 4889.77 ], [ 1124.143, 4869.606], [ 297.419, 4390.711], [ 20.164, 3911.816], [ 0. , 2948.985], [ 216.763, 1497.177], [ 972.913, 10.082], [ 1552.628, 0. ], [ 2157.548, 20.164],
### Set up the wind speeds and wind directions for the problem ### n = 20 # number of points, i.e., number of winddirections and windspeeds pairs points = windfarm_setup.getPoints(method_dict, n) winddirections = points['winddirections'] windspeeds = points['windspeeds'] weights = points['weights'] # This might be None depending on the method. N = winddirections.size # actual number of samples print('Locations at which power is evaluated') print('\twindspeed \t winddirection') for i in range(N): print(i+1, '\t', '%.2f' % windspeeds[i], '\t', '%.2f' % winddirections[i]) # Turbines layout turbineX, turbineY = windfarm_setup.getLayout(method_dict['layout']) locations = np.column_stack((turbineX, turbineY)) # generate boundary constraint boundaryVertices, boundaryNormals = calculate_boundary(locations) nVertices = boundaryVertices.shape[0] print('boundary vertices', boundaryVertices) # turbine size and operating conditions rotor_diameter = 126.4 # (m) air_density = 1.1716 # kg/m^3 # initialize arrays for each turbine properties nTurbs = turbineX.size rotorDiameter = np.zeros(nTurbs)