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

optional disabling of climateinterpolation in pyfuga

parent 82878ed4
No related branches found
No related tags found
No related merge requests found
Subproject commit 6eb5b3fe9c4a7654d039b1e77a92e930749a57dc
Subproject commit 0f0015c52e0a30dbef8d2674df8dd69b1ee521e3
......@@ -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/'
......
......@@ -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
#
......
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