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

use faster method as long as only one wt type is used (even if type!=0)

parent 806bfcd3
No related branches found
No related tags found
No related merge requests found
import pytest import pytest
import matplotlib.pyplot as plt
import numpy as np import numpy as np
from py_wake import NOJ from py_wake import NOJ
from py_wake.examples.data.iea37 import iea37_path
from py_wake.examples.data.iea37._iea37 import IEA37_WindTurbines, IEA37Site
from py_wake.site._site import UniformSite from py_wake.site._site import UniformSite
from py_wake.tests import npt from py_wake.tests import npt
from py_wake.flow_map import HorizontalGrid from py_wake.flow_map import HorizontalGrid
...@@ -72,7 +68,7 @@ def test_NOJ_6_turbines_in_row(): ...@@ -72,7 +68,7 @@ def test_NOJ_6_turbines_in_row():
site = UniformSite([1], 0.1) site = UniformSite([1], 0.1)
wake_model = NOJ(site, NibeA0) wake_model = NOJ(site, NibeA0)
WS_eff_ilk = wake_model.calc_wt_interaction(x, y, [50] * n_wt, [0.0] * n_wt, 0.0, 11.0)[0] WS_eff_ilk = wake_model.calc_wt_interaction(x, y, [50] * n_wt, [0] * n_wt, 0.0, 11.0)[0]
np.testing.assert_array_almost_equal( np.testing.assert_array_almost_equal(
WS_eff_ilk[1:, 0, 0], 11 - np.sqrt(np.cumsum(((11 * 2 / 3 * 20**2)**2) / (20 + 8 * np.arange(1, 6))**4))) WS_eff_ilk[1:, 0, 0], 11 - np.sqrt(np.cumsum(((11 * 2 / 3 * 20**2)**2) / (20 + 8 * np.arange(1, 6))**4)))
......
...@@ -118,20 +118,15 @@ class WindTurbines(): ...@@ -118,20 +118,15 @@ class WindTurbines():
def _ct_power(self, ws_i, type_i=0): def _ct_power(self, ws_i, type_i=0):
ws_i = np.asarray(ws_i) ws_i = np.asarray(ws_i)
if np.any(type_i != 0): t = np.unique(type_i) # .astype(int)
CT = np.zeros_like(ws_i, dtype=np.float) if len(t) > 1:
P = np.zeros_like(ws_i, dtype=np.float) if type_i.shape != ws_i.shape:
type_i = (np.zeros(ws_i.shape[0]) + type_i).astype(int) type_i = (np.zeros(ws_i.shape[0]) + type_i).astype(int)
# TODO: check if faster to calculate both in same line
CT = np.array([self.ct_funcs[t](ws) for t, ws in zip(type_i, ws_i)]) CT = np.array([self.ct_funcs[t](ws) for t, ws in zip(type_i, ws_i)])
P = np.array([self.power_funcs[t](ws) for t, ws in zip(type_i, ws_i)]) P = np.array([self.power_funcs[t](ws) for t, ws in zip(type_i, ws_i)])
# for t in np.unique(type_i).astype(int):
# m = type_i == t
# CT[m] = self.ct_funcs[t](ws_i[m])
# P[m] = self.power_funcs[t](ws_i[m])
return CT, P return CT, P
else: else:
return self.ct_funcs[0](ws_i), self.power_funcs[0](ws_i) return self.ct_funcs[t[0]](ws_i), self.power_funcs[t[0]](ws_i)
def set_gradient_funcs(self, power_grad_funcs, ct_grad_funcs): def set_gradient_funcs(self, power_grad_funcs, ct_grad_funcs):
def add_grad(f_lst, df_lst): def add_grad(f_lst, df_lst):
......
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