diff --git a/tests/test_fuga/test_pyfuga.py b/tests/test_fuga/test_pyfuga.py index 033893c4a0e2e70f5946bb431760c42d1afb485a..d1e6d571e034ca38ec57164c3a3572178e3135a2 100644 --- a/tests/test_fuga/test_pyfuga.py +++ b/tests/test_fuga/test_pyfuga.py @@ -19,11 +19,12 @@ fuga_path = os.path.abspath(os.path.dirname(py_fuga.__file__)) + '/Colonel/' def _test_parallel(id): - pyFuga = PyFuga(farm_name='Horns Rev 1', - 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], - 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') + pyFuga = PyFuga() + pyFuga.setup(farm_name='Horns Rev 1', + 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], + 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) for i in range(1): print(threading.current_thread(), id) @@ -38,21 +39,25 @@ class Test(unittest.TestCase): return os.path.isfile(lib_path) is False def get_fuga(self, tb_x=[423974, 424033], tb_y=[6151447, 6150889]): - return PyFuga(farm_name='Horns Rev 1', - turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]', - tb_x=tb_x, tb_y=tb_y, - 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) + pyFuga = PyFuga() + pyFuga.setup(farm_name='Horns Rev 1', + turbine_model_path=fuga_path + 'LUT/', turbine_model_name='Vestas_V80_(2_MW_offshore)[h=67.00]', + tb_x=tb_x, tb_y=tb_y, + 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): - if self.lib_missing(): return + if self.lib_missing(): + return 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 = self.get_fuga() # check that current interface version match pyFuga.cleanup() def testSetup(self): - if self.lib_missing(): return + if self.lib_missing(): + return pyFuga = self.get_fuga() self.assertEqual(pyFuga.get_no_tubines(), 2) self.assertIn("Loading", pyFuga.log) @@ -63,13 +68,15 @@ class Test(unittest.TestCase): pyFuga.cleanup() def testAEP_one_tb(self): - if self.lib_missing(): return + if self.lib_missing(): + return 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.]) pyFuga.cleanup() def testAEP(self): - if self.lib_missing(): return + if self.lib_missing(): + return 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]) @@ -86,7 +93,7 @@ class Test(unittest.TestCase): # def test_parallel(self): # from multiprocessing import Pool -# +# # with Pool(5) as p: # print(p.map(_test_parallel, [1, 2])) diff --git a/topfarm/cost_models/fuga/Colonel b/topfarm/cost_models/fuga/Colonel index 41cdbf9403170ce0f132f226fa7dab0d4d12b894..100b7842bbeb29ba6f51556fbc24d01cf153efe1 160000 --- a/topfarm/cost_models/fuga/Colonel +++ b/topfarm/cost_models/fuga/Colonel @@ -1 +1 @@ -Subproject commit 41cdbf9403170ce0f132f226fa7dab0d4d12b894 +Subproject commit 100b7842bbeb29ba6f51556fbc24d01cf153efe1 diff --git a/topfarm/cost_models/fuga/py_fuga.py b/topfarm/cost_models/fuga/py_fuga.py index 54c7423d96b5d610ca553913ddd0dbc35f34899b..a7e8f8be5759652380bbacca6039da6b6882d9c6 100644 --- a/topfarm/cost_models/fuga/py_fuga.py +++ b/topfarm/cost_models/fuga/py_fuga.py @@ -18,16 +18,13 @@ from topfarm.cost_models.fuga.pascal_dll import PascalDLL c_double_p = POINTER(c_double) c_int_p = POINTER(ctypes.c_int32) +fuga_path = os.path.abspath(os.path.dirname(__file__)) + '/Colonel/' + class PyFuga(object): - interface_version = 2 - - 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): + interface_version = 3 + + def __init__(self): atexit.register(self.cleanup) with NamedTemporaryFile() as f: self.stdout_filename = f.name + "pyfuga.txt" @@ -38,7 +35,14 @@ class PyFuga(object): self.lib = PascalDLL(lib_path) 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)) tb_x_ctype = np.array(tb_x, dtype=np.float).ctypes @@ -51,13 +55,7 @@ class PyFuga(object): assert os.path.isfile(farms_dir + wind_atlas_path), farms_dir + wind_atlas_path 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() - - -# 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) + #assert len(tb_x) == self.get_no_tubines(), self.log + "\n%d!=%d" % (self.get_no_tubines(),len(tb_x)) def cleanup(self): if hasattr(self, 'lib'): @@ -74,15 +72,6 @@ class PyFuga(object): except Exception: 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): no_turbines_p = c_int_p(c_int(0)) self.lib.GetNoTurbines(no_turbines_p) diff --git a/topfarm/cost_models/fuga/tests/__init__.py b/topfarm/cost_models/fuga/tests/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000