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