diff --git a/py_wake/tests/test_input_modifier_models/test_input_modifier.py b/py_wake/tests/test_input_modifier_models/test_input_modifier.py index 9655ddfddf52ca6240fe8b244fe5d98913974ea5..d1b28b6a585d9bb6618058aaa03edd52a82e4590 100644 --- a/py_wake/tests/test_input_modifier_models/test_input_modifier.py +++ b/py_wake/tests/test_input_modifier_models/test_input_modifier.py @@ -117,6 +117,5 @@ def test_floating_pitch_modifier(wfm_cls, pitch, displacement, ref): i = np.searchsorted(fm_wt2.x, sim_res.x.sel(ws=10, wd=270)[2]) - 1 else: i = np.searchsorted(fm_wt2.x, sim_res.x[2]) - 1 - print(fm_wt2.x.isel(x=i).item()) npt.assert_array_almost_equal(sim_res.WS_eff.sel(ws=10, wd=270, wt=2), fm_wt2.WS_eff.isel(x=i), 3) diff --git a/py_wake/tests/test_wind_farm_models/test_wind_farm_model.py b/py_wake/tests/test_wind_farm_models/test_wind_farm_model.py index 99429942ec5fa86cd06d829b921b2245f459404a..b3413b3f71519598ae25708ddb77f59866e30d10 100644 --- a/py_wake/tests/test_wind_farm_models/test_wind_farm_model.py +++ b/py_wake/tests/test_wind_farm_models/test_wind_farm_model.py @@ -16,6 +16,7 @@ import os from py_wake import examples from py_wake.literature.iea37_case_study1 import IEA37CaseStudy1 from py_wake.wind_farm_models.engineering_models import PropagateDownwind +from py_wake.site._site import UniformSite def test_yaw_wrong_name(): @@ -190,6 +191,22 @@ def test_aep_gradients_chunks(): npt.assert_array_almost_equal(dAEP_ref, dAEP_autograd, 8) +def test_aep_gradients_with_types(): + # Generating the powerCtCurves (the problem does not occur when using V80()) + wts = WindTurbines.from_WindTurbine_lst([V80(), V80()]) + wfm = NOJ(UniformSite(), wts) + + x = [0, 500] + y = [0, 0] + t = [0, 0] + + daep_autograd = wfm.aep_gradients(autograd, x=x, y=y, type=t) + daep_fd = wfm.aep_gradients(fd, x=x, y=y, type=t) + daep_cs = wfm.aep_gradients(cs, x=x, y=y, type=t) + npt.assert_array_almost_equal(daep_autograd, daep_cs, 10) + npt.assert_array_almost_equal(daep_autograd, daep_fd) + + @pytest.mark.parametrize('n_wt, shape,dims', [(16, (16,), ('wt',)), (12, (12,), ('wt',)), (12, (16,), ('wd',)), diff --git a/py_wake/wind_turbines/wind_turbine_functions.py b/py_wake/wind_turbines/wind_turbine_functions.py index 43b61b62e24ca65c421f89b598489cce8afab054..b2657175969dbb0009fb2fa18f6bfc1f65a25c89 100644 --- a/py_wake/wind_turbines/wind_turbine_functions.py +++ b/py_wake/wind_turbines/wind_turbine_functions.py @@ -120,18 +120,28 @@ class WindTurbineFunctionList(WindTurbineFunction): else: if isinstance(run_only, int): o = 0 - res = np.empty((1,) + np.asarray(ws).shape) + res = np.empty(np.asarray(ws).shape) else: res = np.empty((len(self.output_keys),) + np.asarray(ws).shape) o = run_only unique_idx = np.unique(idx) idx = np.zeros(ws.shape, dtype=int) + idx.reshape(idx.shape + (1,) * (len(ws.shape) - len(idx.shape))) - for i in unique_idx: - m = (idx == i) - res[o, m] = self.windTurbineFunction_lst[i]( - ws[m], run_only=run_only, **{k: self._subset(v, m) for k, v in get_kwargs(i).items()}) - res = res[o] + + if isinstance(o, int): + for i in unique_idx: + m = (idx == i) + r = self.windTurbineFunction_lst[i](ws, run_only=run_only, + **{k: v for k, v in get_kwargs(i).items()}) + res = np.where(m, r, res) + return res + else: + for i in unique_idx: + m = (idx == i) + res[o, m] = self.windTurbineFunction_lst[i]( + ws[m], run_only=run_only, **{k: self._subset(v, m) for k, v in get_kwargs(i).items()}) + return res[o] + return res