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

Merge branch 'test_pyfuga' into 'master'

Test pyfuga

See merge request !9
parents 0aa11200 9b49b281
No related branches found
No related tags found
1 merge request!94Handle disabled mpi
import os
tfp = testfilepath = os.path.dirname(__file__) + "/"
\ No newline at end of file
wrf_HRI 173 183 0 0.0004 <coordinates>7.83191,55.48940,0.0</coordinates>
1 1 12
0.000 0.030 0.100 0.400 1.500
70.0
3.597152 3.948682 5.167395 7.000154 8.364547 6.43485 8.643194 11.77051 15.15757 14.73792 10.01205 5.165975
9.176929 9.782334 9.531809 9.909545 10.04269 9.593921 9.584007 10.51499 11.39895 11.68746 11.63732 10.08803
2.392578 2.447266 2.412109 2.591797 2.755859 2.595703 2.583984 2.548828 2.470703 2.607422 2.626953 2.326172
\ No newline at end of file
'''
Created on 25. apr. 2018
@author: mmpe
'''
import os
import unittest
from topfarm.cost_models.fuga.lib_reader import read_lib
import numpy as np
from topfarm.cost_models.fuga import py_fuga
from tests.test_files import testfilepath
class Test(unittest.TestCase):
def test_lib_reader(self):
f, A, k = read_lib(testfilepath + "wind_resources/hornsrev2.lib")
np.testing.assert_array_almost_equal(f, [0.035972, 0.039487, 0.051674, 0.070002, 0.083645, 0.064349,
0.086432, 0.117705, 0.151576, 0.147379, 0.100121, 0.05166])
np.testing.assert_array_almost_equal(A, [9.176929, 9.782334, 9.531809, 9.909545, 10.04269, 9.593921,
9.584007, 10.51499, 11.39895, 11.68746, 11.63732, 10.08803])
np.testing.assert_array_almost_equal(k, [2.392578, 2.447266, 2.412109, 2.591797, 2.755859, 2.595703,
2.583984, 2.548828, 2.470703, 2.607422, 2.626953, 2.326172])
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.test_lib_reader']
unittest.main()
...@@ -18,7 +18,7 @@ from topfarm.cost_models.fuga import py_fuga ...@@ -18,7 +18,7 @@ from topfarm.cost_models.fuga import py_fuga
fuga_path = os.path.abspath(os.path.dirname(py_fuga.__file__)) + '/Colonel/' fuga_path = os.path.abspath(os.path.dirname(py_fuga.__file__)) + '/Colonel/'
def test_parallel(id): def _test_parallel(id):
pyFuga = PyFuga(farm_name='Horns Rev 1', pyFuga = PyFuga(farm_name='Horns Rev 1',
turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]', turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]',
tb_x=[423974, 424033], tb_y=[6151447, 6150889], tb_x=[423974, 424033], tb_y=[6151447, 6150889],
...@@ -33,13 +33,9 @@ def test_parallel(id): ...@@ -33,13 +33,9 @@ def test_parallel(id):
class Test(unittest.TestCase): class Test(unittest.TestCase):
@classmethod def lib_missing(self):
def setUpClass(cls): lib_path = os.path.dirname(py_fuga.__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']
super(Test, cls).setUpClass() return os.path.isfile(lib_path) is False
@classmethod
def tearDownClass(cls):
super(Test, cls).tearDownClass()
def get_fuga(self, tb_x=[423974, 424033], tb_y=[6151447, 6150889]): def get_fuga(self, tb_x=[423974, 424033], tb_y=[6151447, 6150889]):
return PyFuga(farm_name='Horns Rev 1', return PyFuga(farm_name='Horns Rev 1',
...@@ -49,12 +45,14 @@ class Test(unittest.TestCase): ...@@ -49,12 +45,14 @@ class Test(unittest.TestCase):
farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib', climate_interpolation=False) farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib', climate_interpolation=False)
def testCheckVersion(self): def testCheckVersion(self):
if self.lib_missing(): return
lib = PascalDLL(fuga_path + "FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']) lib = PascalDLL(fuga_path + "FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt'])
self.assertRaisesRegex(Exception, "This version of FugaLib supports interface version ", lib.CheckInterfaceVersion, 1) self.assertRaisesRegex(Exception, "This version of FugaLib supports interface version ", lib.CheckInterfaceVersion, 1)
# PyFuga(fuga_path + "FugaLib/FugaLib.dll", fuga_path + "LUT/Farms/", "Horns Rev 1", fuga_path + "LUT/", pyFuga = self.get_fuga() # check that current interface version match
# (0, 0, 70), 0.0001, 400, 0, 'Horns Rev 1\hornsrev0.lib') pyFuga.cleanup()
def testSetup(self): def testSetup(self):
if self.lib_missing(): return
pyFuga = self.get_fuga() pyFuga = self.get_fuga()
self.assertEqual(pyFuga.get_no_tubines(), 2) self.assertEqual(pyFuga.get_no_tubines(), 2)
self.assertIn("Loading", pyFuga.log) self.assertIn("Loading", pyFuga.log)
...@@ -65,10 +63,13 @@ class Test(unittest.TestCase): ...@@ -65,10 +63,13 @@ class Test(unittest.TestCase):
pyFuga.cleanup() pyFuga.cleanup()
def testAEP_one_tb(self): def testAEP_one_tb(self):
if self.lib_missing(): return
pyFuga = self.get_fuga([0], [0]) pyFuga = self.get_fuga([0], [0])
np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0], [0]]).T), [7.44121, 7.44121, 0.424962, 1.]) np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0], [0]]).T), [7.44121, 7.44121, 0.424962, 1.])
pyFuga.cleanup()
def testAEP(self): def testAEP(self):
if self.lib_missing(): return
pyFuga = self.get_fuga() pyFuga = self.get_fuga()
np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0, 200], [0, 0]]).T), [14.848055, 14.882419, 0.423981, 0.997691]) np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0, 200], [0, 0]]).T), [14.848055, 14.882419, 0.423981, 0.997691])
...@@ -85,11 +86,10 @@ class Test(unittest.TestCase): ...@@ -85,11 +86,10 @@ class Test(unittest.TestCase):
# def test_parallel(self): # def test_parallel(self):
# from multiprocessing import Pool # from multiprocessing import Pool
# #
# with Pool(5) as p: # with Pool(5) as p:
# print(p.map(test_parallel, [1, 2])) # print(p.map(_test_parallel, [1, 2]))
if __name__ == "__main__": if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testAEP']
unittest.main() unittest.main()
'''
Created on 25. apr. 2018
@author: mmpe
'''
import os
import numpy as np
def read_lib(filename):
with open(filename) as fid:
lines = fid.readlines()
descriptor = lines[0]
nRoughnessClasses, nHeights, nSectorslib = map(int, lines[2].split())
z0ref_lst = list(map(float, lines[4].split()))
# TODO: Implement for specified z0 and height
#
#
# for i:=0 to nRoughnessClasses-1 do read(fil,z0reflib[i]);
# readln(fil);
# for i:=0 to nHeights-1 do read(fil,zreflib[i]);
# readln(fil);
# for k:=0 to nRoughnessClasses-1 do
# begin
# for i:=0 to nSectorslib-1 do
# begin
# read(fil,freq[k,i]);
# freq[k,i]:=freq[k,i]/100;
# end;
# readln(fil);
# for i:=0 to nHeights-1 do
# begin
# for j:=0 to nSectorslib-1 do read(fil,WAlib[k,i,j]);
# readln(fil);
# for j:=0 to nSectorslib-1 do read(fil,Wklib[k,i,j]);
# readln(fil);
# end;
# end;
f,A,k = [np.array(lines[i].split()[:nSectorslib], dtype=np.float) for i in [8, 10, 12]]
return f/100,A,k
if __name__ == '__main__':
print(read_lib(os.path.dirname(__file__) + "/Colonel/LUT/Farms/Horns Rev 1/hornsrev2.lib"))
...@@ -31,8 +31,12 @@ class PyFuga(object): ...@@ -31,8 +31,12 @@ class PyFuga(object):
atexit.register(self.cleanup) atexit.register(self.cleanup)
with NamedTemporaryFile() as f: with NamedTemporaryFile() as f:
self.stdout_filename = f.name + "pyfuga.txt" self.stdout_filename = f.name + "pyfuga.txt"
self.lib = PascalDLL(os.path.dirname(__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']) lib_path = os.path.dirname(__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']
if os.path.isfile(lib_path) is False:
raise Exception("Fuga lib cannot be found: '%s'" % lib_path)
self.lib = PascalDLL(lib_path)
self.lib.CheckInterfaceVersion(self.interface_version) self.lib.CheckInterfaceVersion(self.interface_version)
self.lib.Setup(self.stdout_filename, float(mast_position[0]), float(mast_position[1]), float(mast_position[2]), self.lib.Setup(self.stdout_filename, float(mast_position[0]), float(mast_position[1]), float(mast_position[2]),
float(z0), float(zi), float(zeta0)) float(z0), float(zi), float(zeta0))
...@@ -93,8 +97,8 @@ class PyFuga(object): ...@@ -93,8 +97,8 @@ class PyFuga(object):
def get_aep(self, turbine_positions=None): def get_aep(self, turbine_positions=None):
if turbine_positions is not None: if turbine_positions is not None:
self.move_turbines(turbine_positions[:,0], turbine_positions[:,1]) self.move_turbines(turbine_positions[:, 0], turbine_positions[:, 1])
AEPNet_p = c_double_p(c_double(0)) AEPNet_p = c_double_p(c_double(0))
AEPGros_p = c_double_p(c_double(0)) AEPGros_p = c_double_p(c_double(0))
capacity_p = c_double_p(c_double(0)) capacity_p = c_double_p(c_double(0))
...@@ -105,8 +109,8 @@ class PyFuga(object): ...@@ -105,8 +109,8 @@ class PyFuga(object):
def get_aep_gradients(self, turbine_positions=None): def get_aep_gradients(self, turbine_positions=None):
if turbine_positions is not None: if turbine_positions is not None:
self.move_turbines(turbine_positions[:,0], turbine_positions[:,1]) self.move_turbines(turbine_positions[:, 0], turbine_positions[:, 1])
n_wt = self.get_no_tubines() n_wt = self.get_no_tubines()
dAEPdxyz = np.zeros(n_wt), np.zeros(n_wt), np.zeros(n_wt) dAEPdxyz = np.zeros(n_wt), np.zeros(n_wt), np.zeros(n_wt)
dAEPdxyz_ctype = [dAEP.ctypes for dAEP in dAEPdxyz] dAEPdxyz_ctype = [dAEP.ctypes for dAEP in dAEPdxyz]
......
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