Skip to content
Snippets Groups Projects
Commit 843fc9bd authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

fix #106, issue with autograd in combination with types

parent eb106f92
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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',)),
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment