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

pyFuga interface v3

removed tests/__init__.py

adapt test to new structure

set to correct colonel commit

set colonel to master

switched back to cmdinterpreter
parent 360ff489
No related branches found
No related tags found
1 merge request!94Handle disabled mpi
...@@ -19,11 +19,12 @@ fuga_path = os.path.abspath(os.path.dirname(py_fuga.__file__)) + '/Colonel/' ...@@ -19,11 +19,12 @@ 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()
turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]', pyFuga.setup(farm_name='Horns Rev 1',
tb_x=[423974, 424033], tb_y=[6151447, 6150889], turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]',
mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0, tb_x=[423974, 424033], tb_y=[6151447, 6150889],
farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1\hornsrev0.lib') mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0,
farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1\hornsrev0.lib')
print(pyFuga.stdout_filename, id) print(pyFuga.stdout_filename, id)
for i in range(1): for i in range(1):
print(threading.current_thread(), id) print(threading.current_thread(), id)
...@@ -38,21 +39,25 @@ class Test(unittest.TestCase): ...@@ -38,21 +39,25 @@ class Test(unittest.TestCase):
return os.path.isfile(lib_path) is False return os.path.isfile(lib_path) is False
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', pyFuga = PyFuga()
turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]', pyFuga.setup(farm_name='Horns Rev 1',
tb_x=tb_x, tb_y=tb_y, turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]',
mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0, tb_x=tb_x, tb_y=tb_y,
farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib', climate_interpolation=False) mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0,
farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib', climate_interpolation=False)
return pyFuga
def testCheckVersion(self): def testCheckVersion(self):
if self.lib_missing(): return 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 = self.get_fuga() # check that current interface version match pyFuga = self.get_fuga() # check that current interface version match
pyFuga.cleanup() pyFuga.cleanup()
def testSetup(self): def testSetup(self):
if self.lib_missing(): return 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)
...@@ -63,13 +68,15 @@ class Test(unittest.TestCase): ...@@ -63,13 +68,15 @@ class Test(unittest.TestCase):
pyFuga.cleanup() pyFuga.cleanup()
def testAEP_one_tb(self): def testAEP_one_tb(self):
if self.lib_missing(): return 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.450272, 7.450272, 0.424962, 1.]) np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0], [0]]).T), [7.450272, 7.450272, 0.424962, 1.])
pyFuga.cleanup() pyFuga.cleanup()
def testAEP(self): def testAEP(self):
if self.lib_missing(): return 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.866138, 14.900544, 0.423981, 0.997691]) np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0, 200], [0, 0]]).T), [14.866138, 14.900544, 0.423981, 0.997691])
...@@ -86,7 +93,7 @@ class Test(unittest.TestCase): ...@@ -86,7 +93,7 @@ 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]))
......
Subproject commit 41cdbf9403170ce0f132f226fa7dab0d4d12b894 Subproject commit 100b7842bbeb29ba6f51556fbc24d01cf153efe1
...@@ -18,16 +18,13 @@ from topfarm.cost_models.fuga.pascal_dll import PascalDLL ...@@ -18,16 +18,13 @@ from topfarm.cost_models.fuga.pascal_dll import PascalDLL
c_double_p = POINTER(c_double) c_double_p = POINTER(c_double)
c_int_p = POINTER(ctypes.c_int32) c_int_p = POINTER(ctypes.c_int32)
fuga_path = os.path.abspath(os.path.dirname(__file__)) + '/Colonel/'
class PyFuga(object): class PyFuga(object):
interface_version = 2 interface_version = 3
def __init__(self, def __init__(self):
farm_name='Horns Rev 1',
turbine_model_path='./LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]',
tb_x=[423974, 424033], tb_y=[6151447, 6150889],
mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0,
farms_dir='./LUT/', wind_atlas_path='Horns Rev 1\hornsrev.lib', climate_interpolation=True):
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"
...@@ -38,7 +35,14 @@ class PyFuga(object): ...@@ -38,7 +35,14 @@ class PyFuga(object):
self.lib = PascalDLL(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.Initialize(self.stdout_filename)
def setup(self, farm_name='Horns Rev 1',
turbine_model_path='./LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]',
tb_x=[423974, 424033], tb_y=[6151447, 6150889],
mast_position=(0, 0, 70), z0=0.0001, zi=400, zeta0=0,
farms_dir='./LUT/', wind_atlas_path='Horns Rev 1\hornsrev.lib', climate_interpolation=True):
self.lib.Setup(float(mast_position[0]), float(mast_position[1]), float(mast_position[2]),
float(z0), float(zi), float(zeta0)) float(z0), float(zi), float(zeta0))
tb_x_ctype = np.array(tb_x, dtype=np.float).ctypes tb_x_ctype = np.array(tb_x, dtype=np.float).ctypes
...@@ -51,13 +55,7 @@ class PyFuga(object): ...@@ -51,13 +55,7 @@ class PyFuga(object):
assert os.path.isfile(farms_dir + wind_atlas_path), farms_dir + wind_atlas_path assert os.path.isfile(farms_dir + wind_atlas_path), farms_dir + wind_atlas_path
self.lib.SetupWindClimate(farms_dir, wind_atlas_path, climate_interpolation) self.lib.SetupWindClimate(farms_dir, wind_atlas_path, climate_interpolation)
assert len(tb_x) == self.get_no_tubines(), self.log + "\n%d" % self.get_no_tubines() #assert len(tb_x) == self.get_no_tubines(), self.log + "\n%d!=%d" % (self.get_no_tubines(),len(tb_x))
# self.lib.setup_old(farms_dir, farm_name, turbine_model_path,
# float(mast_position[0]), float(mast_position[1]), float(mast_position[2]),
# float(z0),float(zi),float(zeta0),
# wind_atlas_path)
def cleanup(self): def cleanup(self):
if hasattr(self, 'lib'): if hasattr(self, 'lib'):
...@@ -74,15 +72,6 @@ class PyFuga(object): ...@@ -74,15 +72,6 @@ class PyFuga(object):
except Exception: except Exception:
pass pass
def __init__old(self):
path = r'C:\mmpe\programming\pascal\Fuga\Colonel\FugaLib/'
self.lib = PascalDLL(path + 'FugaLib.dll')
self.lib.setup(path + '../LUT/Farms/', 'Horns Rev 1', path + '../LUT/',
0., 0., 70.,
0.0001, 400., 0.,
'Horns Rev 1\hornsrev0.lib')
def get_no_tubines(self): def get_no_tubines(self):
no_turbines_p = c_int_p(c_int(0)) no_turbines_p = c_int_p(c_int(0))
self.lib.GetNoTurbines(no_turbines_p) self.lib.GetNoTurbines(no_turbines_p)
......
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