diff --git a/topfarm/cost_models/fuga/Colonel b/topfarm/cost_models/fuga/Colonel index 6eb5b3fe9c4a7654d039b1e77a92e930749a57dc..0f0015c52e0a30dbef8d2674df8dd69b1ee521e3 160000 --- a/topfarm/cost_models/fuga/Colonel +++ b/topfarm/cost_models/fuga/Colonel @@ -1 +1 @@ -Subproject commit 6eb5b3fe9c4a7654d039b1e77a92e930749a57dc +Subproject commit 0f0015c52e0a30dbef8d2674df8dd69b1ee521e3 diff --git a/topfarm/cost_models/fuga/py_fuga.py b/topfarm/cost_models/fuga/py_fuga.py index bb3268460fe2a5e6d748d72f73cb4645ac52f1fe..83bb90e58d3f2cb9a874b285bcbe1f68469cf6cf 100644 --- a/topfarm/cost_models/fuga/py_fuga.py +++ b/topfarm/cost_models/fuga/py_fuga.py @@ -27,10 +27,11 @@ class PyFuga(object): 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'): + farms_dir='./LUT/', wind_atlas_path='Horns Rev 1\hornsrev.lib', climate_interpolation=True): atexit.register(self.cleanup) with NamedTemporaryFile() as f: - self.stdout_filename = f.name + ".txt" + self.stdout_filename = f.name + "pyfuga.txt" + self.lib = PascalDLL(os.path.dirname(__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']) self.lib.CheckInterfaceVersion(self.interface_version) self.lib.Setup(self.stdout_filename, float(mast_position[0]), float(mast_position[1]), float(mast_position[2]), @@ -44,7 +45,7 @@ class PyFuga(object): len(tb_x), tb_x_ctype.data_as(c_double_p), tb_y_ctype.data_as(c_double_p)) assert os.path.isfile(farms_dir + wind_atlas_path), farms_dir + wind_atlas_path - self.lib.SetupWindClimate(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() @@ -61,8 +62,13 @@ class PyFuga(object): except: pass del self.lib - if os.path.isfile(self.stdout_filename): - os.remove(self.stdout_filename) + tmp_folder = os.path.dirname(self.stdout_filename) + for f in os.listdir(tmp_folder): + if f.endswith('pyfuga.txt'): + try: + os.remove(os.path.join(tmp_folder, f)) + except Exception: + pass def __init__old(self): path = r'C:\mmpe\programming\pascal\Fuga\Colonel\FugaLib/' diff --git a/topfarm/cost_models/fuga/tests/test_pyfuga.py b/topfarm/cost_models/fuga/tests/test_pyfuga.py index c65c78c46b52d46318a3806e8f6862292b160c21..e26750d6a2d6ef6efbf8b43f3d98ae2fc6278c7a 100644 --- a/topfarm/cost_models/fuga/tests/test_pyfuga.py +++ b/topfarm/cost_models/fuga/tests/test_pyfuga.py @@ -33,15 +33,23 @@ def test_parallel(id): class Test(unittest.TestCase): - def get_fuga(self): + @classmethod + def setUpClass(cls): + super(Test, cls).setUpClass() + + @classmethod + def tearDownClass(cls): + super(Test, cls).tearDownClass() + + 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=[423974, 424033], tb_y=[6151447, 6150889], + 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') + farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib', climate_interpolation=False) def testCheckVersion(self): - 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) # 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') @@ -50,19 +58,31 @@ class Test(unittest.TestCase): pyFuga = self.get_fuga() self.assertEqual(pyFuga.get_no_tubines(), 2) self.assertIn("Loading", pyFuga.log) + + # check that new setup resets number of turbines + pyFuga = self.get_fuga() + self.assertEqual(pyFuga.get_no_tubines(), 2) pyFuga.cleanup() + 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.]) + def testAEP(self): pyFuga = self.get_fuga() - np.testing.assert_array_almost_equal(pyFuga.get_aep([0, 0], [0, 200]), [14.044704, 16.753474, 0.401041, 0.838316]) - np.testing.assert_array_almost_equal(pyFuga.get_aep([0, 200], [0, 0]), [16.714122, 16.753474, 0.477265, 0.997651]) - np.testing.assert_array_almost_equal(pyFuga.get_aep([0, 200], [0, 200]), [17.072517, 16.753474, 0.487499, 1.019043]) - np.testing.assert_array_almost_equal(pyFuga.get_aep_gradients([0, 200], [0, 200]), [[0.002905, -0.002905], - [-0.001673, 0.001673], - [0., 0.]]) + 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_gradients(np.array([[0, 200], [0, 0]]).T), 0) + np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0, 0], [0, 200]]).T), [12.110134, 14.882419, 0.3458, 0.813721]) + np.testing.assert_array_almost_equal(pyFuga.get_aep_gradients(np.array([[0, 0], [0, 200]]).T), [[-0.001792, 0.001792], + [-0.008116, 0.008116], + [0., 0.]]) + np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0, 200], [0, 200]]).T), [14.846827, 14.882419, 0.423946, 0.997608]) + np.testing.assert_array_almost_equal(pyFuga.get_aep_gradients(np.array([[0, 200], [0, 200]]).T), [[-5.165553e-06, 5.165553e-06], + [1.599768e-06, -1.599768e-06], + [0.000000e+00, 0.000000e+00]]) pyFuga.cleanup() - + # def test_parallel(self): # from multiprocessing import Pool #