def main(): if __name__ == '__main__': from py_wake.examples.data.iea37._iea37 import IEA37Site from py_wake.examples.data.iea37._iea37 import IEA37_WindTurbines from py_wake.superposition_models import LinearSum from py_wake.wind_farm_models import All2AllIterative from py_wake.deficit_models.no_wake import NoWakeDeficit import matplotlib.pyplot as plt # setup site, turbines and wind farm model site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() vd = VortexDipole() plt.figure() noj_vd = All2AllIterative(site, windTurbines, wake_deficitModel=NoWakeDeficit(), superpositionModel=LinearSum(), blockage_deficitModel=vd) flow_map = noj_vd(x=[0], y=[0], wd=[270], ws=[10]).flow_map() clevels = np.array([ .6, .7, .8, .9, .95, .98, .99, .995, .998, .999, 1., 1.01, 1.02 ]) * 10. flow_map.plot_wake_map(levels=clevels) plt.title('Vortex Dipole') plt.ylabel("Crosswind distance [y/R]") plt.xlabel("Downwind distance [x/R]") plt.show() # run wind farm simulation sim_res = noj_vd(x, y, wd=[0, 30, 45, 60, 90], ws=[5, 10, 15]) # calculate AEP aep = sim_res.aep().sum() # plot wake map plt.figure() print(noj_vd) flow_map = sim_res.flow_map(wd=0, ws=10) flow_map.plot_wake_map(levels=clevels, plot_colorbar=False) plt.title('Vortex Dipole model, AEP: %.3f GWh' % aep) plt.show()
def test_wake_map(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wake_model = NOJ(windTurbines) aep = AEPCalculator(site, windTurbines, wake_model) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) X, Y, Z = aep.wake_map(x_j, y_j, 110, x, y, wd=[0], ws=[9]) if 0: import matplotlib.pyplot as plt c = plt.contourf(X, Y, Z) # , np.arange(2, 10, .01)) plt.colorbar(c) windTurbines.plot(x, y) plt.show() ref = [3.27, 3.27, 9.0, 7.46, 7.46, 7.46, 7.46, 7.31, 7.31, 7.31, 7.31, 8.3, 8.3, 8.3, 8.3, 8.3, 8.3] npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)
def test_IEA37SimpleBastankhahGaussian_all_ex(): """check SBG matches IEA37 value in file""" for n_wt in [9, 16, 36, 64]: x, y, aep_ref = read_iea37_windfarm(iea37_path + 'iea37-ex%d.yaml' % n_wt) if 0: plt.plot(x, y, '2k') for i, (x_, y_) in enumerate(zip(x, y)): plt.annotate(i, (x_, y_)) plt.axis('equal') plt.show() site = IEA37Site(n_wt) windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = IEA37SimpleBastankhahGaussian(site, windTurbines) aep_ilk = wake_model(x, y, wd=np.arange(0, 360, 22.5), ws=[9.8]).aep_ilk(normalize_probabilities=True) aep_MW_l = aep_ilk.sum((0, 2)) * 1000 # test that the result is equal to results provided for IEA task 37 npt.assert_almost_equal(aep_ref[0], aep_MW_l.sum(), 5) npt.assert_array_almost_equal(aep_ref[1], aep_MW_l, 5)
def test_models_with_BastankhahGaussian(turbulence_model, ref_ti): # setup site, turbines and wind farm model site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() for wake_model in [ BastankhahGaussian(site, windTurbines, turbulenceModel=turbulence_model) ]: res = wake_model(x, y) # print(turbulence_model.__class__.__name__, np.round(res.TI_eff_ilk[:, 0, 0], 3).tolist()) if 0: res.flow_map(wd=0).plot_ti_map() plt.show() npt.assert_array_almost_equal(res.TI_eff_ilk[:, 0, 0], ref_ti, 3)
def test_aep(): site = UniformSite([1], ti=0) windTurbines = IEA37_WindTurbines() wfm = NOJ(site, windTurbines) sim_res = wfm([0], [0], wd=270) npt.assert_almost_equal(sim_res.aep().sum(), 3.35 * 24 * 365 / 1000) npt.assert_almost_equal( sim_res.aep(normalize_probabilities=True).sum(), 3.35 * 24 * 365 / 1000) npt.assert_equal(sim_res.aep().data.sum(), wfm.aep([0], [0], wd=270)) npt.assert_almost_equal( sim_res.aep(normalize_probabilities=True).sum(), wfm.aep([0], [0], wd=270, normalize_probabilities=True)) npt.assert_almost_equal( sim_res.aep(with_wake_loss=False).sum(), wfm.aep([0], [0], wd=270, with_wake_loss=False))
def test_RotorGridAvg_deficit(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wfm = IEA37SimpleBastankhahGaussian(site, windTurbines) flow_map = wfm([0, 500], [0, 0], wd=270, ws=10).flow_map(HorizontalGrid(x=[500], y=np.arange(-100, 100))) plt.plot(flow_map.Y[:, 0], flow_map.WS_eff_xylk[:, 0, 0, 0]) R = windTurbines.diameter() / 2 for name, rotorAvgModel, ref1 in [ ('RotorCenter', RotorCenter(), 7.172723970425709), ('RotorGrid2', EqGridRotorAvg(2), 7.495889360682771), ('RotorGrid3', EqGridRotorAvg(3), 7.633415167369133), ('RotorGrid4', EqGridRotorAvg(4), 7.710215921858325), ('RotorGrid100', EqGridRotorAvg(100), 7.820762402628349), ('RotorGQGrid_4,3', GQGridRotorAvg(4, 3), 7.826105012683896), ('RotorCGI4', CGIRotorAvg(4), 7.848406907726826), ('RotorCGI4', CGIRotorAvg(7), 7.819900693605533), ('RotorCGI4', CGIRotorAvg(9), 7.82149363932618), ('RotorCGI4', CGIRotorAvg(21), 7.821558905416136)]: # test with PropagateDownwind wfm = IEA37SimpleBastankhahGaussian(site, windTurbines, rotorAvgModel=rotorAvgModel) sim_res = wfm([0, 500], [0, 0], wd=270, ws=10) npt.assert_almost_equal(sim_res.WS_eff_ilk[1, 0, 0], ref1) # test with All2AllIterative wfm = All2AllIterative(site, windTurbines, IEA37SimpleBastankhahGaussianDeficit(), rotorAvgModel=rotorAvgModel, superpositionModel=SquaredSum()) sim_res = wfm([0, 500], [0, 0], wd=270, ws=10) npt.assert_almost_equal(sim_res.WS_eff_ilk[1, 0, 0], ref1) plt.plot([-R, R], [sim_res.WS_eff_ilk[1, 0, 0]] * 2, label=name) if 0: plt.legend() plt.show() plt.close('all')
def main(): if __name__ == '__main__': from py_wake import Fuga from py_wake.examples.data.iea37._iea37 import IEA37Site, IEA37_WindTurbines site = IEA37Site(16) x, y = [0, 600, 1200], [0, 0, 0] # site.initial_position[:2].T windTurbines = IEA37_WindTurbines() from py_wake.tests.test_files import tfp path = tfp + 'fuga/2MW/Z0=0.03000000Zi=00401Zeta0=0.00E+0/' noj = Fuga(path, site, windTurbines, deflectionModel=JimenezWakeDeflection()) yaw_ilk = np.zeros((len(x), 1, 1)) yaw_ilk[:, 0, 0] = [-30, 30, 0] noj(x, y, yaw_ilk=yaw_ilk, wd=270, ws=10).flow_map().plot_wake_map() import matplotlib.pyplot as plt plt.show() pass
def test_save_load(): site = UniformSite([1], ti=0) windTurbines = IEA37_WindTurbines() wfm = NOJ(site, windTurbines) sim_res1 = wfm([0], [0], wd=270) sim_res1.save(tfp + "tmp.nc") sim_res2 = SimulationResult.load(tfp + 'tmp.nc', wfm) for sim_res in [sim_res1, sim_res2]: npt.assert_almost_equal(sim_res.aep().sum(), 3.35 * 24 * 365 / 1000) npt.assert_almost_equal(sim_res.aep(normalize_probabilities=True).sum(), 3.35 * 24 * 365 / 1000) npt.assert_equal(sim_res.aep().data.sum(), wfm.aep([0], [0], wd=270)) npt.assert_almost_equal(sim_res.aep(normalize_probabilities=True).sum(), wfm.aep([0], [0], wd=270, normalize_probabilities=True)) npt.assert_almost_equal(sim_res.aep(with_wake_loss=False).sum(), wfm.aep([0], [0], wd=270, with_wake_loss=False))
def test_models_with_noj(turbulence_model, ref_ti): # setup site, turbines and wind farm model site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() for wake_model in [NOJ(site, windTurbines, turbulenceModel=turbulence_model), All2AllIterative(site, windTurbines, wake_deficitModel=NOJDeficit(), superpositionModel=SquaredSum(), turbulenceModel=turbulence_model), ]: res = wake_model(x, y) # print(turbulence_model.__class__.__name__, np.round(res.TI_eff_ilk[:, 0, 0], 3).tolist()) if 0: res.flow_map(wd=0).plot_ti_map() plt.show() npt.assert_array_almost_equal(res.TI_eff_ilk[:, 0, 0], ref_ti, 3)
def main(): if __name__ == '__main__': from py_wake.examples.data.iea37._iea37 import IEA37Site from py_wake.examples.data.iea37._iea37 import IEA37_WindTurbines from py_wake.turbulence_models.gcl import GCLTurbulence import matplotlib.pyplot as plt # setup site, turbines and wind farm model site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wf_model = GCL(site, windTurbines) wf_model_local = GCLLocal(site, windTurbines, turbulenceModel=GCLTurbulence()) # run wind farm simulation sim_res = wf_model(x, y) sim_res_local = wf_model_local(x, y) # calculate AEP aep = sim_res.aep().sum() aep_local = sim_res_local.aep().sum() # plot wake map fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5), tight_layout=True) levels = np.arange(0, 10.5, 0.5) print(wf_model) flow_map = sim_res.flow_map(wd=30, ws=9.8) flow_map.plot_wake_map(levels=levels, ax=ax1, plot_colorbar=False) flow_map.plot_windturbines(ax=ax1) ax1.set_title('Original Larsen, AEP: %.2f GWh' % aep) # plot wake map print(wf_model_local) flow_map = sim_res_local.flow_map(wd=30, ws=9.8) flow_map.plot_wake_map(levels=levels, ax=ax2, plot_colorbar=False) flow_map.plot_windturbines(ax=ax2) ax2.set_title('Local Larsen, AEP: %.2f GWh' % aep_local) plt.figure() flow_map.plot_ti_map(levels=np.arange(0, 1, .01)) plt.title('TI map for GCLLocal with GCL turbulence model') plt.show()
def test_RotorGridAvg_ti(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wfm = IEA37SimpleBastankhahGaussian(site, windTurbines, turbulenceModel=STF2017TurbulenceModel()) flow_map = wfm([0, 500], [0, 0], wd=270, ws=10).flow_map(HorizontalGrid(x=[500], y=np.arange(-100, 100))) plt.plot(flow_map.Y[:, 0], flow_map.TI_eff_xylk[:, 0, 0, 0]) R = windTurbines.diameter() / 2 for name, rotorAvgModel, ref1 in [ ('RotorCenter', RotorCenter(), 0.22292190804089568), ('RotorGrid2', EqGridRotorAvg(2), 0.2111162769995657), ('RotorGrid3', EqGridRotorAvg(3), 0.2058616982653193), ('RotorGrid4', EqGridRotorAvg(4), 0.2028701990648858), ('RotorGrid100', EqGridRotorAvg(100), 0.1985255601976247), ('RotorGQGrid_4,3', GQGridRotorAvg(4, 3), 0.1982984399750206)]: # test with PropagateDownwind wfm = IEA37SimpleBastankhahGaussian(site, windTurbines, rotorAvgModel=rotorAvgModel, turbulenceModel=STF2017TurbulenceModel()) sim_res = wfm([0, 500], [0, 0], wd=270, ws=10) npt.assert_almost_equal(sim_res.TI_eff_ilk[1, 0, 0], ref1) # test with All2AllIterative wfm = All2AllIterative(site, windTurbines, IEA37SimpleBastankhahGaussianDeficit(), rotorAvgModel=rotorAvgModel, superpositionModel=SquaredSum(), turbulenceModel=STF2017TurbulenceModel()) sim_res = wfm([0, 500], [0, 0], wd=270, ws=10) npt.assert_almost_equal(sim_res.TI_eff_ilk[1, 0, 0], ref1) plt.plot([-R, R], [sim_res.TI_eff_ilk[1, 0, 0]] * 2, label=name) if 0: plt.legend() plt.show() plt.close('all')
def test_IEA37SimpleBastankhahGaussian_wake_map(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = IEA37SimpleBastankhahGaussian(site, windTurbines) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) flow_map = wake_model(x, y, wd=0, ws=9).flow_map(HorizontalGrid(x_j, y_j)) X, Y, Z = flow_map.X, flow_map.Y, flow_map.WS_eff_xylk[:, :, 0, 0] # test that the result is equal to last run (no evidens that these number are correct) ref = [ 3.32, 4.86, 7.0, 8.1, 7.8, 7.23, 6.86, 6.9, 7.3, 7.82, 8.11, 8.04, 7.87, 7.79, 7.85, 8.04, 8.28 ] if 0: flow_map.plot_wake_map() plt.plot(X[49, 100:133:2], Y[49, 100:133:2], '.-') plt.show() npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)
def test_wake_radius_not_implemented(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() class MyDeficitModel(WakeDeficitModel): args4deficit = ['WS_ilk', 'dw_ijlk', 'cw_ijlk'] def calc_deficit(self, WS_ilk, dw_ijlk, cw_ijlk, **_): # 10% deficit in downstream triangle ws_10pct_ijlk = 0.1 * WS_ilk[:, na] triangle_ijlk = ((.2 * dw_ijlk) > cw_ijlk) return ws_10pct_ijlk * triangle_ijlk wfm = PropagateDownwind(site, windTurbines, wake_deficitModel=MyDeficitModel(), turbulenceModel=GCLTurbulence()) with pytest.raises(NotImplementedError, match="wake_radius not implemented for MyDeficitModel"): wfm(x, y)
def main(): if __name__ == '__main__': for n_wt in [9, 16, 36, 64]: x, y, aep_ref = read_iea37_windfarm(iea37_path + 'iea37-ex%d.yaml' % n_wt) if 0: import matplotlib.pyplot as plt plt.plot(x, y, '2k') for i, (x_, y_) in enumerate(zip(x, y)): plt.annotate(i, (x_, y_)) plt.axis('equal') plt.show() site = IEA37Site(n_wt) windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = IEA37SimpleBastankhahGaussian(site, windTurbines) aep = wake_model(x, y, wd=np.arange(0, 360, 22.5), ws=[9.8]).aep() # Compare to reference results provided for IEA task 37 print(n_wt, aep_ref[0] * 1e-3, aep)
def test_IEA37SimpleBastankhahGaussian_ex16(): _, _, freq = read_iea37_windrose(iea37_path + "iea37-windrose.yaml") n_wt = 16 x, y, aep_ref = read_iea37_windfarm(iea37_path + 'iea37-ex%d.yaml' % n_wt) if 0: import matplotlib.pyplot as plt plt.plot(x, y, '2k') for i, (x_, y_) in enumerate(zip(x, y)): plt.annotate(i, (x_, y_)) plt.axis('equal') plt.show() site = UniformSite(freq, ti=0.75) windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = IEA37SimpleBastankhahGaussian(windTurbines) aep = AEPCalculator(site, windTurbines, wake_model) aep_ilk = aep.calculate_AEP(x, y, wd=np.arange(0, 360, 22.5), ws=[9.8]) aep_MW_l = aep_ilk.sum((0, 2)) * 1000 # test that the result is equal to results provided for IEA task 37 npt.assert_almost_equal(aep_ref[0], aep_MW_l.sum(), 5) npt.assert_array_almost_equal(aep_ref[1], aep_MW_l, 5)
def test_aep_map(): site = IEA37Site(16) x = [0, 0] y = [0, 200] windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = IEA37SimpleBastankhahGaussian(windTurbines) aep = AEPCalculator(site, windTurbines, wake_model) # print(aep.calculate_AEP([0], [0]).sum()) x_j = np.arange(-150, 150, 20) y_j = np.arange(-250, 250, 20) X, Y, Z = aep.aep_map(x_j, y_j, 0, x, y, wd=[0], ws=np.arange(3, 25)) # print(y_j) if 0: import matplotlib.pyplot as plt c = plt.contourf(X, Y, Z, 100) # , np.arange(2, 10, .01)) plt.colorbar(c) windTurbines.plot(x, y) plt.show() # print(np.round(Z[17], 2).tolist()) ref = [21.5, 21.4, 21.02, 20.34, 18.95, 16.54, 13.17, 10.17, 10.17, 13.17, 16.54, 18.95, 20.34, 21.02, 21.4] npt.assert_array_almost_equal(Z[17], ref, 2)
def test_wake_map(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = NOJ(site, windTurbines) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) flow_map = wake_model(x, y, wd=[0], ws=[9]).flow_map(HorizontalGrid(x_j, y_j, 110)) Z = flow_map.WS_eff_xylk.mean((2, 3)) if 0: flow_map.plot_wake_map() plt.show() ref = [ 3.27, 3.27, 9.0, 7.46, 7.46, 7.46, 7.46, 7.31, 7.31, 7.31, 7.31, 8.3, 8.3, 8.3, 8.3, 8.3, 8.3 ] npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)
def main(): if __name__ == '__main__': from py_wake.examples.data.iea37._iea37 import IEA37Site from py_wake.examples.data.iea37._iea37 import IEA37_WindTurbines from py_wake import NOJ # setup site, turbines and flow model site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() import matplotlib.pyplot as plt _, (ax1, ax2) = plt.subplots(1, 2) for ax, wf_model, lbl in [(ax1, NOJ(site, windTurbines, turbulenceModel=STF2005TurbulenceModel()), 'STF2005'), (ax2, NOJ(site, windTurbines, turbulenceModel=STF2017TurbulenceModel()), 'STF2017')]: sim_res = wf_model(x, y) print(sim_res.TI_eff_ilk[:, 0]) # plot wake map flow_map = sim_res.flow_map(wd=0, ws=9.8) c = flow_map.plot_ti_map(ax=ax) ax.set_title('Turbulence intensity calculated by %s' % lbl) plt.show()
def test_set_gradients(): wt = IEA37_WindTurbines() wt.set_gradient_funcs(lambda ws: np.where((ws > 4) & (ws <= 9.8), 100000 * ws, # not the right gradient, but similar to the reference 0), lambda ws: 0) with use_autograd_in([WindTurbines, iea37_reader]): ws_lst = np.arange(3, 25, .1) plt.plot(ws_lst, wt.power(ws_lst)) ws_pts = np.array([3., 6., 9., 12.]) dpdu_lst = np.diag(autograd(wt.power)(ws_pts)) if 0: for dpdu, ws in zip(dpdu_lst, ws_pts): plot_gradients(wt.power(ws), dpdu, ws, "", 1) plt.show() dpdu_ref = np.where((ws_pts > 4) & (ws_pts <= 9.8), 100000 * ws_pts, 0) npt.assert_array_almost_equal(dpdu_lst, dpdu_ref)
def test_dAEP_2wt(): site = Hornsrev1Site() iea37_site = IEA37Site(16) wt = IEA37_WindTurbines() wfm = IEA37SimpleBastankhahGaussian(site, wt) x, y = iea37_site.initial_position[np.array([0, 2, 5, 8, 14])].T # plot 2 wt case x, y = np.array([[0, 130 * 4], [0, 0]], dtype=np.float) x_lst = np.array([0., 1.]) * np.arange(1, 600, 10)[:, na] kwargs = {'ws': [10], 'wd': [270]} _, (ax1, ax2) = plt.subplots(1, 2, sharey=False) ax1.plot(x_lst[:, 1], [wfm.aep(x_, y, **kwargs) for x_ in x_lst]) ax1.set_xlabel('Downwind distance [m]') ax1.set_ylabel('AEP [GWh]') x_ = x_lst[20] ax1.set_title("Center line") for grad in [fd, cs, autograd]: dAEPdx = wfm.dAEPdn(0, grad)(x_, y, **kwargs)[1] npt.assert_almost_equal(dAEPdx / 360, 3.976975605364392e-06, (10, 5)[grad == fd]) plot_gradients(wfm.aep(x_, y, **kwargs), dAEPdx, x_[1], grad.__name__, step=100, ax=ax1) y_lst = np.array([0, 1.]) * np.arange(-100, 100, 5)[:, na] ax2.plot(y_lst[:, 1], [wfm.aep(x, y_, **kwargs) for y_ in y_lst]) ax2.set_xlabel('Crosswind distance [m]') ax2.set_ylabel('AEP [GWh]') y_ = y_lst[25] ax2.set_title("%d m downstream" % x[1]) for grad in [fd, cs, autograd]: dAEPdy = wfm.dAEPdn(1, grad)(x, y_, **kwargs)[1] plot_gradients(wfm.aep(x, y_, **kwargs), dAEPdy, y_[1], grad.__name__, step=50, ax=ax2) npt.assert_almost_equal(dAEPdy / 360, 3.794435973860448e-05, (10, 5)[grad == fd]) if 0: plt.legend() plt.show() plt.close()
def test_BastankhahGaussian_ex16(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = BastankhahGaussian(site, windTurbines) if 0: windTurbines.plot(x, y) plt.show() aep_ilk = wake_model(x, y, wd=np.arange(0, 360, 22.5), ws=[9.8]).aep_ilk(normalize_probabilities=True) aep_MW_l = aep_ilk.sum((0, 2)) * 1000 # test that the result is equal to last run (no evidens that these number are correct) aep_ref = (355971.9717035484, [ 9143.74048, 8156.71681, 11311.92915, 13955.06316, 19807.65346, 25196.64182, 39006.65223, 41463.31044, 23042.22602, 12978.30551, 14899.26913, 32320.21637, 67039.04091, 17912.40907, 12225.04134, 7513.75582 ]) npt.assert_almost_equal(aep_MW_l.sum(), aep_ref[0], 5) npt.assert_array_almost_equal(aep_MW_l, aep_ref[1], 5)
def test_deficitModel_wake_map_convection_all2all(deficitModel, ref): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wf_model = All2AllIterative(site, windTurbines, wake_deficitModel=deficitModel, superpositionModel=WeightedSum(), blockage_deficitModel=VortexDipole(), turbulenceModel=STF2017TurbulenceModel()) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) flow_map = wf_model(x, y, wd=0, ws=9).flow_map(HorizontalGrid(x_j, y_j)) X, Y = flow_map.X, flow_map.Y Z = flow_map.WS_eff_xylk[:, :, 0, 0] mean_ref = [ 3.2, 4.9, 8., 8.2, 7.9, 7.4, 7., 7., 7.4, 7.9, 8.1, 8.1, 8., 7.8, 7.9, 8.1, 8.4 ] if 0: flow_map.plot_wake_map() plt.plot(X[49, 100:133:2], Y[49, 100:133:2], '.-') windTurbines.plot(x, y) plt.figure() plt.plot(Z[49, 100:133:2], label='Actual') plt.plot(ref, label='Reference') plt.plot(mean_ref, label='Mean ref') plt.legend() plt.show() # check that ref is reasonable npt.assert_allclose(ref[2:], mean_ref[2:], atol=2.6) npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)
def test_deficitModel_wake_map(deficitModel, ref): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wf_model = PropagateDownwind(site, windTurbines, wake_deficitModel=deficitModel, superpositionModel=SquaredSum(), turbulenceModel=GCLTurbulence()) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) flow_map = wf_model(x, y, wd=0, ws=9).flow_map(HorizontalGrid(x_j, y_j)) X, Y = flow_map.X, flow_map.Y Z = flow_map.WS_eff_xylk[:, :, 0, 0] mean_ref = [ 3.2, 4.9, 8., 8.2, 7.9, 7.4, 7., 7., 7.4, 7.9, 8.1, 8.1, 8., 7.8, 7.9, 8.1, 8.4 ] if 0: flow_map.plot_wake_map() plt.plot(X[49, 100:133:2], Y[49, 100:133:2], '.-') windTurbines.plot(x, y) plt.figure() plt.plot(Z[49, 100:133:2]) plt.plot(ref, label='ref') plt.plot(mean_ref, label='Mean ref') plt.legend() plt.show() npt.assert_array_almost_equal(ref, Z[49, 100:133:2], 2) # check that ref is reasonable npt.assert_allclose(ref[2:], mean_ref[2:], atol=2.6)
def test_RotorAvg_deficit(): site = IEA37Site(16) windTurbines = IEA37_WindTurbines() wfm = IEA37SimpleBastankhahGaussian(site, windTurbines, turbulenceModel=STF2017TurbulenceModel()) flow_map = wfm([0, 500], [0, 0], wd=270, ws=10).flow_map(HorizontalGrid(x=[500], y=np.arange(-100, 100))) plt.plot(flow_map.Y[:, 0], flow_map.TI_eff_xylk[:, 0, 0, 0]) R = windTurbines.diameter() / 2 for name, rotorAvgModel, ref1 in [ ('None', None, 0.22292190804089568), ('RotorCenter', RotorCenter(), 0.22292190804089568), ('RotorGrid100', EqGridRotorAvg(100), 0.1989725533174574), ('RotorGQGrid_4,3', GQGridRotorAvg(4, 3), 0.19874837617113356), ('RotorCGI4', CGIRotorAvg(4), 0.19822024411411204), ('RotorCGI4', CGIRotorAvg(21), 0.1989414764606653)]: # test with PropagateDownwind wfm = IEA37SimpleBastankhahGaussian(site, windTurbines, turbulenceModel=STF2017TurbulenceModel(rotorAvgModel=rotorAvgModel)) sim_res = wfm([0, 500], [0, 0], wd=270, ws=10) npt.assert_almost_equal(sim_res.TI_eff_ilk[1, 0, 0], ref1, err_msg=name) # test with All2AllIterative wfm = All2AllIterative(site, windTurbines, IEA37SimpleBastankhahGaussianDeficit(), turbulenceModel=STF2017TurbulenceModel(rotorAvgModel=rotorAvgModel), superpositionModel=SquaredSum()) sim_res = wfm([0, 500], [0, 0], wd=270, ws=10) npt.assert_almost_equal(sim_res.TI_eff_ilk[1, 0, 0], ref1) plt.plot([-R, R], [sim_res.WS_eff_ilk[1, 0, 0]] * 2, label=name) if 0: plt.legend() plt.show() plt.close()
def test_gradients(): wt = IEA37_WindTurbines() wt.enable_autograd() ws_lst = np.arange(3, 25, .1) ws_pts = np.array([3., 6., 9., 12.]) dpdu_lst = autograd(wt.power)(ws_pts) if 0: plt.plot(ws_lst, wt.power(ws_lst)) for dpdu, ws in zip(dpdu_lst, ws_pts): plot_gradients(wt.power(ws), dpdu, ws, "", 1) plt.show() dpdu_ref = np.where((ws_pts > 4) & (ws_pts <= 9.8), 3 * 3350000 * (ws_pts - 4)**2 / (9.8 - 4)**3, 0) npt.assert_array_almost_equal(dpdu_lst, dpdu_ref) fd_dpdu_lst = fd(wt.power)(ws_pts) npt.assert_array_almost_equal(fd_dpdu_lst, dpdu_ref, 0) cs_dpdu_lst = cs(wt.power)(ws_pts) npt.assert_array_almost_equal(cs_dpdu_lst, dpdu_ref)
def test_BastankhahGaussian_wake_map(): site = IEA37_Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = BastankhahGaussian(windTurbines) aep = AEPCalculator(site, windTurbines, wake_model) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) X, Y, Z = aep.wake_map(x_j, y_j, 110, x, y, wd=[0], ws=[9]) # test that the result is equal to last run (no evidens that these number are correct) ref = [ 0.18, 3.6, 7.27, 8.32, 7.61, 6.64, 5.96, 6.04, 6.8, 7.69, 8.08, 7.87, 7.59, 7.46, 7.55, 7.84, 8.19 ] if 0: import matplotlib.pyplot as plt c = plt.contourf(X, Y, Z, np.arange(-.25, 9.1, .01)) plt.colorbar(c) windTurbines.plot(x, y) plt.show() npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)
def test_IEA37SimpleBastankhahGaussian_wake_map(): site = IEA37_Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = IEA37SimpleBastankhahGaussian(windTurbines) aep = AEPCalculator(site, windTurbines, wake_model) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) X, Y, Z = aep.wake_map(x_j, y_j, 110, x, y, wd=[0], ws=[9]) # test that the result is equal to last run (no evidens that these number are correct) ref = [ 3.32, 4.86, 7.0, 8.1, 7.8, 7.23, 6.86, 6.9, 7.3, 7.82, 8.11, 8.04, 7.87, 7.79, 7.85, 8.04, 8.28 ] npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2) if 0: import matplotlib.pyplot as plt c = plt.contourf(X, Y, Z, np.arange(2, 9.1, .01)) plt.colorbar(c) site.plot_windturbines(x, y) plt.plot(X[49, 100:133:2], Y[49, 100:133:2], '-.') plt.show()
def test_wake_map(): _, _, freq = read_iea37_windrose(iea37_path + "iea37-windrose.yaml") n_wt = 16 x, y, _ = read_iea37_windfarm(iea37_path + 'iea37-ex%d.yaml' % n_wt) site = UniformSite(freq, ti=0.75) windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = NOJ(windTurbines) aep = AEPCalculator(site, windTurbines, wake_model) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) X, Y, Z = aep.wake_map(x_j, y_j, 110, x, y, wd=[0], ws=[9]) if 0: import matplotlib.pyplot as plt c = plt.contourf(X, Y, Z) # , np.arange(2, 10, .01)) plt.colorbar(c) site.plot_windturbines(x, y) plt.show() ref = [3.27, 3.27, 9.0, 7.46, 7.46, 7.46, 7.46, 7.31, 7.31, 7.31, 7.31, 8.3, 8.3, 8.3, 8.3, 8.3, 8.3] npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)
def main(): if __name__ == '__main__': from py_wake.examples.data.iea37._iea37 import IEA37Site from py_wake.examples.data.iea37._iea37 import IEA37_WindTurbines from py_wake import NOJ import matplotlib.pyplot as plt # setup site, turbines and wakemodel site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines() wf_model = NOJ(site, windTurbines, turbulenceModel=GCLTurbulence()) # calculate AEP sim_res = wf_model(x, y) print(sim_res.TI_eff_ilk.flatten()) # plot wake mape aep = sim_res.aep().sum() flow_map = sim_res.flow_map(wd=0, ws=9.8) flow_map.plot_ti_map() plt.title('AEP: %.2f GWh' % aep) plt.show()
def test_BastankhahGaussian_wake_map(): site = IEA37Site(16) x, y = site.initial_position.T windTurbines = IEA37_WindTurbines(iea37_path + 'iea37-335mw.yaml') wake_model = BastankhahGaussian(site, windTurbines) x_j = np.linspace(-1500, 1500, 200) y_j = np.linspace(-1500, 1500, 100) flow_map = wake_model(x, y, wd=0, ws=9).flow_map(HorizontalGrid(x_j, y_j)) X, Y = flow_map.X, flow_map.Y Z = flow_map.WS_eff_xylk[:, :, 0, 0] # test that the result is equal to last run (no evidens that these number are correct) ref = [ 0.18, 3.6, 7.27, 8.32, 7.61, 6.64, 5.96, 6.04, 6.8, 7.69, 8.08, 7.87, 7.59, 7.46, 7.55, 7.84, 8.19 ] if 0: flow_map.plot_wake_map() plt.plot(X[49, 100:133:2], Y[49, 100:133:2], '.-') windTurbines.plot(x, y) plt.show() npt.assert_array_almost_equal(Z[49, 100:133:2], ref, 2)