Skip to content
Snippets Groups Projects
Commit 747b38a8 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 2cacd617 74b56f5c
No related branches found
No related tags found
1 merge request!29Adapt to new fusedwake pos format
Pipeline #
......@@ -8,6 +8,7 @@ test_topfarm: # name the job what we like
stage: # build, test, deploy defined by default [2]
test
script:
- pip install --upgrade git+git://github.com/FUSED-Wind/FUSED-Wake@master
- cd tests; py.test
tags: # only runners with this tag can do the job [3]
- python
......
......@@ -10,6 +10,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource
from tests.test_files import testfilepath
from topfarm.cost_models.fused_wake_wrappers import FusedWakeGCLWakeModel
from topfarm.cost_models.utils.aep_calculator import AEPCalculator
import warnings
class TestAEPCalculator(unittest.TestCase):
......@@ -20,10 +21,11 @@ class TestAEPCalculator(unittest.TestCase):
k = [2.392578,2,2,2]
wr = WindResource(np.array(f), A, k, ti=np.zeros_like(f) + .1)
wf_3tb = testfilepath + "wind_farms/3tb.yml"
wm = FusedWakeGCLWakeModel(wf_3tb)
aep_calc = AEPCalculator(wr, wm)
self.assertAlmostEqual(aep_calc(np.array([[-1600, 0, 1600], [0, 0, 0]]).T), 22.3178800761)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
wm = FusedWakeGCLWakeModel(wf_3tb)
aep_calc = AEPCalculator(wr, wm)
self.assertAlmostEqual(aep_calc(np.array([[-1600, 0, 1600], [0, 0, 0]]).T), 22.3178800761)
if __name__ == "__main__":
......
......@@ -5,6 +5,7 @@ from topfarm.cost_models.utils.wind_resource import WindResource
from tests.test_files import tfp
from topfarm._topfarm import TopFarm
import pytest
import warnings
@pytest.fixture()
......@@ -14,24 +15,32 @@ def aep_calc():
A = [9.176929, 9.782334, 9.531809, 9.909545]
k = [2.392578, 2.447266, 2.412109, 2.591797]
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)
def test_input_shape_must_be_equal():
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)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
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):
init_pos = aep_calc.wake_model.windFarm.pos.T
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
with warnings.catch_warnings():
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):
init_pos = aep_calc.wake_model.windFarm.pos.T
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square')
tf.evaluate()
init_pos = aep_calc.wake_model.windFarm.pos
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")
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square')
tf.evaluate()
assert tf.get_cost() == -19.85973533524627
......@@ -6,6 +6,7 @@ from topfarm._topfarm import TopFarm
from topfarm.cost_models.fused_wake_wrappers import FusedWakeNOJWakeModel
from topfarm.cost_models.utils.aep_calculator import AEPCalculator
from topfarm.cost_models.utils.wind_resource import WindResource
import warnings
@pytest.fixture()
......@@ -15,18 +16,24 @@ def aep_calc():
A = [9.176929, 9.782334, 9.531809, 9.909545]
k = [2.392578, 2.447266, 2.412109, 2.591797]
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)
def test_GCL(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos.T
assert aep_calc(init_pos) == 18.90684500124578
assert aep_calc(np.array([[-500, 0, 500], [0, 0, 0]]).T) == 22.31788007605505
def test_NOJ(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos
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")
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):
init_pos = aep_calc.wake_model.windFarm.pos.T
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square')
tf.evaluate()
def test_NOJ_Topfarm(aep_calc):
init_pos = aep_calc.wake_model.windFarm.pos
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")
tf = TopFarm(init_pos, aep_calc.get_TopFarm_cost_component(), 160, init_pos, boundary_type='square')
tf.evaluate()
assert tf.get_cost() == -18.90684500124578
......@@ -23,13 +23,12 @@ class FusedWakeModel(object):
self.windFarm = WindFarm(yml=yml)
if version:
self.version = version
try:
self.wake_model = self.wake_model_cls(WF=self.windFarm, version=self.version, **kwargs)
except ValueError as e:
pytest.xfail(str(e))
self.wake_model = self.wake_model_cls(WF=self.windFarm, version=self.version, **kwargs)
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])
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:
......
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