def N2_diagram(nRows, maxDirections): from openmdao.api import view_tree # Scaling grid case nTurbines = nRows**2 probg = Problem( root=OptAEP(nTurbines, nDirections=maxDirections, use_rotor_components=False, wake_model=gauss_wrapper, params_IdepVar_func=add_gauss_params_IndepVarComps, wake_model_options={'nSamples': 0}, params_IndepVar_args=None)) probf = Problem( root=OptAEP(nTurbines, nDirections=maxDirections, use_rotor_components=False, wake_model=floris_wrapper, differentiable=True, params_IdepVar_func=add_floris_params_IndepVarComps, wake_model_options=None, params_IndepVar_args=None)) # initialize problem probf.setup() probg.setup() view_tree(probf, show_browser=True, outfile='tree_floris.html') view_tree(probg, show_browser=True, outfile='tree_gauss.html')
axialInduction = np.zeros(nTurbines) + axial_induction rotorDiameter = np.zeros(nTurbines) + rotor_diameter generatorEfficiency = np.zeros(nTurbines) + generator_efficiency yaw = np.zeros(nTurbines) + yaw_init Ct = np.zeros(nTurbines) + CT Cp = np.zeros(nTurbines) + CP # Define site measurements nDirections = 1 wind_direction = 270.-0.523599*180./np.pi wind_speed = 8. # m/s air_density = 1.1716 # initialize problems gauss_prob = Problem(root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False, wake_model=gauss_wrapper, wake_model_options={'nSamples': 0}, datasize=0, params_IdepVar_func=add_gauss_params_IndepVarComps, force_fd=True, params_IndepVar_args={})) floris_prob = Problem(root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False, wake_model=floris_wrapper, wake_model_options=None, datasize=0, params_IdepVar_func=add_floris_params_IndepVarComps, params_IndepVar_args={})) jensen_prob = Problem(root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False, wake_model=jensen_wrapper, wake_model_options={'variant': 'CosineYaw_1R', 'radius multiplier': 1.0}, datasize=0, params_IdepVar_func=add_jensen_params_IndepVarComps, params_IndepVar_args={'use_angle': True})) probs = [gauss_prob, floris_prob, jensen_prob] names = ['gauss', 'floris', 'jensen']
def calc_data(nRows, maxDirections, savetxt=False): # set up wind farm rotor_diameter = 126.4 axialInduction = 1.0 / 3.0 # used only for initialization generatorEfficiency = 0.944 hub_height = 90.0 Ct = 4.0 * axialInduction * (1.0 - axialInduction) Cp = 0.7737 / 0.944 * 4.0 * 1.0 / 3.0 * np.power((1 - 1.0 / 3.0), 2) # Scaling grid case spacing = 4 # turbine grid spacing in diameters nTurbines = nRows**2 # Set up position arrays points = np.linspace(start=spacing * rotor_diameter, stop=nRows * spacing * rotor_diameter, num=nRows) xpoints, ypoints = np.meshgrid(points, points) turbineX = np.ndarray.flatten(xpoints) turbineY = np.ndarray.flatten(ypoints) print turbineX, turbineY # initialize input variable arrays rotorDiameter = np.ones(nTurbines) * rotor_diameter axialInduction = np.ones(nTurbines) * axialInduction Ct = np.ones(nTurbines) * Ct Cp = np.ones(nTurbines) * Cp generatorEfficiency = np.ones(nTurbines) * generatorEfficiency yaw = np.zeros(nTurbines) hubHeight = np.ones(nTurbines) * hub_height # Define flow properties wind_speed = 8.0 # m/s air_density = 1.1716 # kg/m^3 # initialize results arrays directions = np.arange(1, maxDirections + 2, 10) time_ex_f = np.zeros_like(directions) * 0.0 time_ex_g = np.zeros_like(directions) * 0.0 time_fd_f = np.zeros_like(directions) * 0.0 time_fd_g = np.zeros_like(directions) * 0.0 AEPf = np.zeros_like(directions) AEPg = np.zeros_like(directions) index = 0 for d in directions: # set up problem probg = Problem( root=OptAEP(nTurbines, nDirections=d, use_rotor_components=False, wake_model=gauss_wrapper, params_IdepVar_func=add_gauss_params_IndepVarComps, wake_model_options={'nSamples': 0}, params_IndepVar_args=None)) probf = Problem( root=OptAEP(nTurbines, nDirections=d, use_rotor_components=False, wake_model=floris_wrapper, differentiable=True, params_IdepVar_func=add_floris_params_IndepVarComps, wake_model_options=None, params_IndepVar_args=None)) # initialize problem # profile.setup(probf) probf.setup() probg.setup() # assign values to constant inputs (not design variables) probf['turbineX'] = probg['turbineX'] = turbineX probf['turbineY'] = probg['turbineY'] = turbineY probf['hubHeight'] = probg['hubHeight'] = hubHeight probf['yaw0'] = probg['yaw0'] = yaw probf['rotorDiameter'] = probg['rotorDiameter'] = rotorDiameter probf['axialInduction'] = probg['axialInduction'] = axialInduction probf['Ct_in'] = probg['Ct_in'] = Ct probf['Cp_in'] = probg['Cp_in'] = Cp probf['generatorEfficiency'] = probg[ 'generatorEfficiency'] = generatorEfficiency probf['windSpeeds'] = probg['windSpeeds'] = np.ones(d) * wind_speed probf['air_density'] = probg['air_density'] = air_density probf['windDirections'] = probg['windDirections'] = np.linspace( 0, 360, d) probf['windFrequencies'] = probg['windFrequencies'] = np.ones(d) / d # run problem probf.run() probg.run() AEPf[index] = probf['AEP'] AEPg[index] = probg['AEP'] # pass results to self for use with unit test tic = time() # profile.start() J = probf.calc_gradient(['turbineX', 'turbineY'], ['AEP'], return_format='dict', mode='auto') # profile.stop() toc = time() time_ex_f[index] = toc - tic tic = time() # profile.start() J = probf.calc_gradient(['turbineX', 'turbineY'], ['AEP'], return_format='dict', mode='fd') # profile.stop() toc = time() time_fd_f[index] = toc - tic tic = time() # profile.start() J = probg.calc_gradient(['turbineX', 'turbineY'], ['AEP'], return_format='dict', mode='auto') # profile.stop() toc = time() time_ex_g[index] = toc - tic tic = time() # profile.start() J = probg.calc_gradient(['turbineX', 'turbineY'], ['AEP'], return_format='dict', mode='fd') # profile.stop() toc = time() time_fd_g[index] = toc - tic index += 1 if savetxt: np.savetxt( 'scaling_by_directions_combined_%i_turbines_%i_directions.txt' % (nTurbines, maxDirections), np.array([ time_ex_f, time_ex_g, time_fd_f, time_fd_g, AEPf, AEPg, directions ])) return np.array( [time_ex_f, time_ex_g, time_fd_f, time_fd_g, AEPf, AEPg, directions])
rotorDiameter[turbI] = rotor_diameter # m 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) generatorEfficiency[turbI] = 0.944 yaw[turbI] = 0. # deg. # Define flow properties air_density = 1.1716 # kg/m^3 # initialize problem prob = Problem(impl=impl, root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, minSpacing=minSpacing, differentiable=True, use_rotor_components=False, nVertices=nVertices)) # set up optimizer prob.driver = pyOptSparseDriver() prob.driver.options['optimizer'] = 'SNOPT' prob.driver.add_objective('obj', scaler=1E-5) # set optimizer options # prob.driver.opt_settings['Verify level'] = 3 prob.driver.opt_settings[ 'Print file'] = 'SNOPT_print_exampleOptAEP_amalia.out' prob.driver.opt_settings[ 'Summary file'] = 'SNOPT_summary_exampleOptAEP_amalia.out' prob.driver.opt_settings['Major iterations limit'] = 1000
axialInduction = np.array([axialInduction, axialInduction]) rotorDiameter = np.array([rotorDiameter, rotorDiameter]) generatorEfficiency = np.array([generator_efficiency, generator_efficiency]) yaw = np.array([0., 0.]) # Define site measurements wind_direction = 270.-0.523599*180./np.pi wind_speed = 8. # m/s air_density = 1.1716 Ct = np.array([CT, CT]) Cp = np.array([CP, CP]) global prob prob = Problem(root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False, wake_model=gauss_wrapper, wake_model_options={'nSamples': 0}, datasize=0, params_IdepVar_func=add_gauss_params_IndepVarComps, params_IndepVar_args={})) prob.setup() prob['model_params:integrate'] = False prob['model_params:spread_mode'] = 'bastankhah' prob['model_params:yaw_mode'] = 'bastankhah' prob['model_params:n_std_dev'] = 4. # prob['model_params:m'] = 0.33 # prob['model_params:Dw0'] = 1.3 tuning_obj_function(plot=True) # initialize optimization problem optProb = Optimization('Tuning Gaussian Model to SOWFA', tuning_obj_function) optProb.addVarGroup('ke', 1, lower=0.0, upper=1.0, value=0.152, scalar=1)
yaw[turbI] = 0. # deg. # Define flow properties wind_speed = 8.0 # m/s air_density = 1.1716 # kg/m^3 windDirections = np.linspace(0, 270, size) windSpeeds = np.ones(size) * wind_speed windFrequencies = np.ones(size) / size # initialize problem prob = Problem(impl=impl, root=OptAEP( nTurbines=nTurbs, nDirections=windDirections.size, nVertices=nVertices, minSpacing=minSpacing, differentiable=True, use_rotor_components=False, wake_model=gauss_wrapper, params_IdepVar_func=add_gauss_params_IndepVarComps, params_IndepVar_args={})) # prob.root.deriv_options['type'] = 'fd' # prob.root.deriv_options['form'] = 'central' # prob.root.deriv_options['step_size'] = 1.0e-8 # set up optimizer prob.driver = pyOptSparseDriver() prob.driver.options['optimizer'] = 'SNOPT' prob.driver.add_objective('obj', scaler=1E0) # prob.driver.options['gradient method'] = 'snopt_fd'
samplesX = np.linspace(0, 3000, res) samplesY = np.linspace(0, 3000, res) samplesX, samplesY = np.meshgrid(samplesX, samplesY) samplesX = samplesX.flatten() samplesY = samplesY.flatten() samplesZ = np.ones(samplesX.shape) * hub_height # initialize problems gauss_prob = Problem( root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False, wake_model=gauss_wrapper, wake_model_options={'nSamples': res**2}, datasize=0, params_IdepVar_func=add_gauss_params_IndepVarComps, force_fd=True, params_IndepVar_args={})) wake_model_options = { 'differentiable': True, 'use_rotor_components': False, 'nSamples': res**2, 'verbose': False } floris_prob = Problem( root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False,
(1 - 1.0 / 3.0), 2) generatorEfficiency[turbI] = 0.944 yaw[turbI] = 0. # deg. # Define flow properties wind_speed = 8.0 # m/s air_density = 1.1716 # kg/m^3 windDirections = np.linspace(0, 270, size) windSpeeds = np.ones(size) * wind_speed windFrequencies = np.ones(size) / size # initialize problem prob = Problem(impl=impl, root=OptAEP(nTurbines=nTurbs, nDirections=windDirections.size, minSpacing=minSpacing, differentiable=True, use_rotor_components=False)) # set up optimizer prob.driver = pyOptSparseDriver() prob.driver.options['optimizer'] = 'SNOPT' prob.driver.add_objective('obj', scaler=1E-5) # set optimizer options prob.driver.opt_settings['Verify level'] = 3 prob.driver.opt_settings['Print file'] = 'SNOPT_print_exampleOptAEP.out' prob.driver.opt_settings[ 'Summary file'] = 'SNOPT_summary_exampleOptAEP.out' prob.driver.opt_settings['Major iterations limit'] = 1000
Cp[turbI] = 0.7737 / 0.944 * 4.0 * 1.0 / 3.0 * np.power( (1 - 1.0 / 3.0), 2) generatorEfficiency[turbI] = 0.944 yaw[turbI] = 0. # deg. # Define flow properties wind_speed = 8.0 # m/s air_density = 1.1716 # kg/m^3 windDirections = np.linspace(0, 270, nDirections) windFrequencies = np.ones_like(windDirections) * 1.0 / nDirections # initialize problem prob = Problem(impl=impl, root=OptAEP(nTurbines=nTurbs, nDirections=windDirections.size, minSpacing=minSpacing, use_rotor_components=use_rotor_components, datasize=datasize)) # set up optimizer prob.driver = pyOptSparseDriver() prob.driver.options['optimizer'] = 'SNOPT' prob.driver.add_objective('obj', scaler=1E-8) # set optimizer options prob.driver.opt_settings['Verify level'] = 0 prob.driver.opt_settings[ 'Print file'] = 'SNOPT_print_exampleOptAEP-Rotor.out' prob.driver.opt_settings[ 'Summary file'] = 'SNOPT_summary_exampleOptAEP-Rotor.out' prob.driver.opt_settings['Major iterations limit'] = 1000
# 1:TI by Niayifar and Porte Agel altered by Annoni and Thomas, # 2:TI by Niayifar and Porte Agel 2016, # 3:no yet implemented] calc_k_star = False z_ref = 90.0 z_0 = 0.0 TI = 0.06 # k_calc = 0.022 k_calc = 0.3837 * TI + 0.003678 nRotorPoints = 16 prob = Problem( root=OptAEP(nTurbines=nTurbines, nDirections=nDirections, use_rotor_components=False, wake_model=gauss_wrapper, wake_model_options={'nSamples': 0}, datasize=0, params_IdepVar_func=add_gauss_params_IndepVarComps, params_IndepVar_args={})) prob.setup() prob['model_params:wake_combination_method'] = wake_combination_method prob['model_params:ti_calculation_method'] = ti_calculation_method prob['model_params:calc_k_star'] = calc_k_star prob['model_params:sort'] = sort_turbs prob['model_params:z_ref'] = z_ref prob['model_params:z_0'] = z_0 prob['model_params:ky'] = k_calc prob['model_params:kz'] = k_calc prob['model_params:I'] = TI