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

add type argument to aep map

parent 6320a202
No related branches found
No related tags found
No related merge requests found
......@@ -8,10 +8,12 @@ from py_wake.examples.data.iea37 import IEA37Site, IEA37_WindTurbines
from py_wake import IEA37SimpleBastankhahGaussian
import pytest
from py_wake.deflection_models.jimenez import JimenezWakeDeflection
from py_wake.wind_turbines._wind_turbines import WindTurbines
from py_wake.examples.data import wtg_path
from py_wake.wind_turbines._wind_turbines import WindTurbines, WindTurbine
from py_wake.examples.data import wtg_path, hornsrev1
from py_wake.utils.profiling import timeit
from py_wake.utils.parallelization import get_pool
from py_wake.wind_turbines.power_ct_functions import PowerCtTabular
from py_wake.examples.data.hornsrev1 import V80
@pytest.fixture(autouse=True)
......@@ -338,6 +340,23 @@ def test_aep_map():
npt.assert_array_almost_equal(aep_map[0], aep_line)
def test_aep_map_type():
site = IEA37Site(16)
x, y = [0, 600, 1200], [0, 0, 0] # site.initial_position[:2].T
v80 = V80()
v120 = WindTurbine('V80_low_induc', 80, 70, powerCtFunction=PowerCtTabular(
hornsrev1.power_curve[:, 0], hornsrev1.power_curve[:, 1] * 1.5, 'w', hornsrev1.ct_curve[:, 1]))
wts = WindTurbines.from_WindTurbines([v80, v120])
wfm = IEA37SimpleBastankhahGaussian(site, wts)
sim_res = wfm(x, y)
grid = XYGrid(x=np.linspace(-100, 2000, 50), y=np.linspace(-500, 500, 25))
aep_map0 = sim_res.aep_map(grid, normalize_probabilities=True)
aep_map1 = sim_res.aep_map(grid, type=1, normalize_probabilities=True)
npt.assert_array_almost_equal(aep_map0 * 1.5, aep_map1)
def test_aep_map_parallel():
site = IEA37Site(16)
x, y = [0, 600, 1200], [0, 0, 0] # site.initial_position[:2].T
......
......@@ -375,7 +375,7 @@ class EngineeringWindFarmModel(WindFarmModel):
TI_eff_jlk = None
return WS_eff_jlk, TI_eff_jlk
def _aep_map(self, x_j, y_j, h_j, sim_res_data):
def _aep_map(self, x_j, y_j, h_j, type_j, sim_res_data):
arg_funcs, lw_j, wd, WD_il = self.get_map_args(x_j, y_j, h_j, sim_res_data)
P = lw_j.P_ilk
I, J, L, K = arg_funcs['IJLK']()
......@@ -384,6 +384,11 @@ class EngineeringWindFarmModel(WindFarmModel):
wd_i = np.round(np.linspace(0, L, wd_chunks + 1)).astype(int)
wd_slices = [slice(i0, i1) for i0, i1 in zip(wd_i[:-1], wd_i[1:])]
aep_j = np.zeros(len(x_j))
power_kwargs = {}
if 'type' in (self.windTurbines.powerCtFunction.required_inputs +
self.windTurbines.powerCtFunction.optional_inputs):
power_kwargs['type'] = type_j
for l_slice in tqdm(wd_slices, disable=len(wd_slices) <= 1 or not self.verbose,
desc='Calculate flow map', unit='wd'):
ws_eff_jlk = self._get_flow_l(arg_funcs, l_slice, lw_j, wd, WD_il, I, J, L, K)[0]
......@@ -391,7 +396,7 @@ class EngineeringWindFarmModel(WindFarmModel):
# p_bin = self.windTurbines.power(np.arange(0, 50, .01))
# power_jlk = p_bin[(ws_eff_jlk * 100).astype(int)]
power_jlk = self.windTurbines.power(ws_eff_jlk)
power_jlk = self.windTurbines.power(ws_eff_jlk, **power_kwargs)
aep_j += (power_jlk * P[:, l_slice]).sum((1, 2))
return aep_j * 365 * 24 * 1e-9
......
......@@ -636,7 +636,7 @@ class SimulationResult(xr.Dataset):
plane = (None,)
return grid + (plane, )
def aep_map(self, grid=None, wd=None, ws=None, normalize_probabilities=False, n_cpu=1, wd_chunks=None):
def aep_map(self, grid=None, wd=None, ws=None, type=0, normalize_probabilities=False, n_cpu=1, wd_chunks=None):
X, Y, x_j, y_j, h_j, plane = self._get_grid(grid)
wd, ws = self._wd_ws(wd, ws)
sim_res = self.sel(wd=wd, ws=ws)
......@@ -648,17 +648,17 @@ class SimulationResult(xr.Dataset):
if len(wd) >= n_cpu:
# chunkification more efficient on wd than j
wd_i = np.linspace(0, len(wd), n_cpu + 1).astype(int)
args_lst = [[x_j, y_j, h_j, sim_res.sel(wd=wd[i0:i1])] for i0, i1 in zip(wd_i[:-1], wd_i[1:])]
args_lst = [[x_j, y_j, h_j, type, sim_res.sel(wd=wd[i0:i1])] for i0, i1 in zip(wd_i[:-1], wd_i[1:])]
aep_lst = map(self.windFarmModel._aep_map, args_lst)
aep_j = np.sum(aep_lst, 0)
else:
j_i = np.linspace(0, len(x_j), n_cpu + 1).astype(int)
args_lst = [[xyh_j[i0:i1] for xyh_j in [x_j, y_j, h_j]] + [sim_res]
args_lst = [[xyh_j[i0:i1] for xyh_j in [x_j, y_j, h_j]] + [type, sim_res]
for i0, i1 in zip(j_i[:-1], j_i[1:])]
aep_lst = map(self.windFarmModel._aep_map, args_lst)
aep_j = np.concatenate(aep_lst)
else:
aep_j = self.windFarmModel._aep_map(x_j, y_j, h_j, sim_res)
aep_j = self.windFarmModel._aep_map(x_j, y_j, h_j, type, sim_res)
if normalize_probabilities:
lw_j = self.windFarmModel.site.local_wind(x_i=x_j, y_i=y_j, h_i=h_j, wd=wd, ws=ws)
aep_j /= lw_j.P_ilk.sum((1, 2))
......
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