Skip to content
Snippets Groups Projects
Commit 18c1401c authored by Mikkel Friis-Møller's avatar Mikkel Friis-Møller
Browse files

Merge branch 'adapt_to_new_fusedwake_pos_format' into 'master'

Adapt to new fusedwake pos format

Closes #17

See merge request !29
parents 6419d34f b36dc5b1
No related branches found
No related tags found
1 merge request!94Handle disabled mpi
...@@ -8,6 +8,7 @@ test_topfarm: # name the job what we like ...@@ -8,6 +8,7 @@ test_topfarm: # name the job what we like
stage: # build, test, deploy defined by default [2] stage: # build, test, deploy defined by default [2]
test test
script: script:
- pip install --upgrade git+git://github.com/FUSED-Wind/FUSED-Wake@master
- cd tests; py.test - cd tests; py.test
tags: # only runners with this tag can do the job [3] tags: # only runners with this tag can do the job [3]
- python - python
......
...@@ -10,6 +10,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource ...@@ -10,6 +10,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource
from tests.test_files import testfilepath from tests.test_files import testfilepath
from topfarm.cost_models.fused_wake_wrappers import FusedWakeGCLWakeModel from topfarm.cost_models.fused_wake_wrappers import FusedWakeGCLWakeModel
from topfarm.cost_models.utils.aep_calculator import AEPCalculator from topfarm.cost_models.utils.aep_calculator import AEPCalculator
import warnings
class TestAEPCalculator(unittest.TestCase): class TestAEPCalculator(unittest.TestCase):
...@@ -20,10 +21,11 @@ class TestAEPCalculator(unittest.TestCase): ...@@ -20,10 +21,11 @@ class TestAEPCalculator(unittest.TestCase):
k = [2.392578,2,2,2] k = [2.392578,2,2,2]
wr = WindResource(np.array(f), A, k, ti=np.zeros_like(f) + .1) wr = WindResource(np.array(f), A, k, ti=np.zeros_like(f) + .1)
wf_3tb = testfilepath + "wind_farms/3tb.yml" wf_3tb = testfilepath + "wind_farms/3tb.yml"
wm = FusedWakeGCLWakeModel(wf_3tb) with warnings.catch_warnings():
aep_calc = AEPCalculator(wr, wm) warnings.simplefilter("ignore")
wm = FusedWakeGCLWakeModel(wf_3tb)
self.assertAlmostEqual(aep_calc(np.array([[-1600, 0, 1600], [0, 0, 0]]).T), 22.3178800761) aep_calc = AEPCalculator(wr, wm)
self.assertAlmostEqual(aep_calc(np.array([[-1600, 0, 1600], [0, 0, 0]]).T), 22.3178800761)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -5,6 +5,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource ...@@ -5,6 +5,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource
from tests.test_files import tfp from tests.test_files import tfp
from topfarm._topfarm import TopFarm from topfarm._topfarm import TopFarm
import pytest import pytest
import warnings
@pytest.fixture() @pytest.fixture()
...@@ -14,24 +15,32 @@ def aep_calc(): ...@@ -14,24 +15,32 @@ def aep_calc():
A = [9.176929, 9.782334, 9.531809, 9.909545] A = [9.176929, 9.782334, 9.531809, 9.909545]
k = [2.392578, 2.447266, 2.412109, 2.591797] k = [2.392578, 2.447266, 2.412109, 2.591797]
wr = WindResource(f, A, k, ti=np.zeros_like(f) + .1) wr = WindResource(f, A, k, ti=np.zeros_like(f) + .1)
wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml") with warnings.catch_warnings():
warnings.simplefilter("ignore")
wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml")
return AEPCalculator(wr, wm) return AEPCalculator(wr, wm)
def test_input_shape_must_be_equal(): def test_input_shape_must_be_equal():
wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml") with warnings.catch_warnings():
with pytest.raises(AssertionError, message="Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal"): warnings.simplefilter("ignore")
wm(wm.windFarm.pos.T, no_wake_wdir=[[270]], no_wake_wsp=[[8, 9]], no_wake_ti=0.1) wm = FusedWakeGCLWakeModel(tfp + "wind_farms/3tb.yml")
with pytest.raises(AssertionError, message="Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal"):
wm(wm.windFarm.pos.T, no_wake_wdir=[[270]], no_wake_wsp=[[8, 9]], no_wake_ti=0.1)
def test_GCL(aep_calc): def test_GCL(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos.T init_pos = aep_calc.wake_model.windFarm.pos.T
assert aep_calc(init_pos) == 19.85973533524627 # tb aligned north-south -> wake with warnings.catch_warnings():
assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 # tb aligned West-East -> no wake warnings.simplefilter("ignore")
assert aep_calc(init_pos) == 19.85973533524627 # tb aligned north-south -> wake
assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 # tb aligned West-East -> no wake
def test_GCL_Topfarm(aep_calc): def test_GCL_Topfarm(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos.T init_pos = aep_calc.wake_model.windFarm.pos
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square') with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])"
tf.evaluate() warnings.simplefilter("ignore")
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square')
tf.evaluate()
assert tf.get_cost() == -19.85973533524627 assert tf.get_cost() == -19.85973533524627
...@@ -6,6 +6,7 @@ from topfarm._topfarm import TopFarm ...@@ -6,6 +6,7 @@ from topfarm._topfarm import TopFarm
from topfarm.cost_models.fused_wake_wrappers import FusedWakeNOJWakeModel from topfarm.cost_models.fused_wake_wrappers import FusedWakeNOJWakeModel
from topfarm.cost_models.utils.aep_calculator import AEPCalculator from topfarm.cost_models.utils.aep_calculator import AEPCalculator
from topfarm.cost_models.utils.wind_resource import WindResource from topfarm.cost_models.utils.wind_resource import WindResource
import warnings
@pytest.fixture() @pytest.fixture()
...@@ -15,18 +16,24 @@ def aep_calc(): ...@@ -15,18 +16,24 @@ def aep_calc():
A = [9.176929, 9.782334, 9.531809, 9.909545] A = [9.176929, 9.782334, 9.531809, 9.909545]
k = [2.392578, 2.447266, 2.412109, 2.591797] k = [2.392578, 2.447266, 2.412109, 2.591797]
wr = WindResource(f, A, k, ti=np.zeros_like(f) + .1) wr = WindResource(f, A, k, ti=np.zeros_like(f) + .1)
wm = FusedWakeNOJWakeModel(tfp + "wind_farms/3tb.yml") with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])"
warnings.simplefilter("ignore")
wm = FusedWakeNOJWakeModel(tfp + "wind_farms/3tb.yml")
return AEPCalculator(wr, wm) return AEPCalculator(wr, wm)
def test_GCL(aep_calc): def test_NOJ(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos.T init_pos = aep_calc.wake_model.windFarm.pos
assert aep_calc(init_pos) == 18.90684500124578 with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])"
assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505 warnings.simplefilter("ignore")
assert aep_calc(init_pos) == 18.90684500124578
assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505
def test_GCL_Topfarm(aep_calc): def test_NOJ_Topfarm(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos.T init_pos = aep_calc.wake_model.windFarm.pos
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square') with warnings.catch_warnings(): # suppress "warning, make sure that this position array is oriented in ndarray([n_wt, 2]) or ndarray([n_wt, 3])"
tf.evaluate() warnings.simplefilter("ignore")
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square')
tf.evaluate()
assert tf.get_cost() == -18.90684500124578 assert tf.get_cost() == -18.90684500124578
...@@ -23,13 +23,12 @@ class FusedWakeModel(object): ...@@ -23,13 +23,12 @@ class FusedWakeModel(object):
self.windFarm = WindFarm(yml=yml) self.windFarm = WindFarm(yml=yml)
if version: if version:
self.version = version self.version = version
try: self.wake_model = self.wake_model_cls(WF=self.windFarm, version=self.version, **kwargs)
self.wake_model = self.wake_model_cls(WF=self.windFarm, version=self.version, **kwargs)
except ValueError as e:
pytest.xfail(str(e))
def __call__(self, turbine_positions, no_wake_wdir, no_wake_wsp, no_wake_ti): def __call__(self, turbine_positions, no_wake_wdir, no_wake_wsp, no_wake_ti):
self.wake_model.update_position(turbine_positions.T) if not hasattr(self.wake_model, 'update_position'):
pytest.xfail("Method update_position missing in wakemodel")
self.wake_model.update_position(turbine_positions)
WD, WS, TI = (np.atleast_2d(v) for v in [no_wake_wdir, no_wake_wsp, no_wake_ti]) WD, WS, TI = (np.atleast_2d(v) for v in [no_wake_wdir, no_wake_wsp, no_wake_ti])
assert WD.shape == WS.shape == TI.shape, "Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal: %s != %s != %s" % (WD.shape, WS.shape, TI.shape) assert WD.shape == WS.shape == TI.shape, "Shape of no_wake_wdir, no_wake_wsp and no_wake_ti must equal: %s != %s != %s" % (WD.shape, WS.shape, TI.shape)
if len(WD.shape) == 3: if len(WD.shape) == 3:
......
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