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

lib_reader.py and fuga tests

parent e461f746
No related branches found
No related tags found
1 merge request!94Handle disabled mpi
'''
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
class Test(unittest.TestCase):
def test_lib_reader(self):
f, A, k = read_lib(os.path.dirname(py_fuga.__file__) + "/Colonel/LUT/Farms/Horns Rev 1/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()
......@@ -33,13 +33,9 @@ def test_parallel(id):
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(Test, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(Test, cls).tearDownClass()
def lib_missing(self):
lib_path = os.path.dirname(py_fuga.__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']
return os.path.isfile(lib_path)
def get_fuga(self, tb_x=[423974, 424033], tb_y=[6151447, 6150889]):
return PyFuga(farm_name='Horns Rev 1',
......@@ -51,8 +47,8 @@ class Test(unittest.TestCase):
def testCheckVersion(self):
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)
# PyFuga(fuga_path + "FugaLib/FugaLib.dll", fuga_path + "LUT/Farms/", "Horns Rev 1", fuga_path + "LUT/",
# (0, 0, 70), 0.0001, 400, 0, 'Horns Rev 1\hornsrev0.lib')
pyFuga = self.get_fuga() # check that current interface version match
pyFuga.cleanup()
def testSetup(self):
pyFuga = self.get_fuga()
......@@ -67,6 +63,7 @@ class Test(unittest.TestCase):
def testAEP_one_tb(self):
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.])
pyFuga.cleanup()
def testAEP(self):
pyFuga = self.get_fuga()
......@@ -91,5 +88,4 @@ class Test(unittest.TestCase):
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testAEP']
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"))
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