From baaff94c941c5ebb41b9f74332fea5f1624b3a4e Mon Sep 17 00:00:00 2001 From: "Mads M. Pedersen" <mmpe@dtu.dk> Date: Thu, 19 Apr 2018 12:59:35 +0200 Subject: [PATCH] pyfuga stuff --- docker/Dockerfile | 2 +- topfarm/cost_models/fuga/Colonel | 2 +- topfarm/cost_models/fuga/py_fuga.py | 6 ++--- topfarm/cost_models/fuga/tests/test_pyfuga.py | 4 ++-- topfarm/cost_models/utils/aep_calculator.py | 13 +++++----- topfarm/cost_models/utils/wind_resource.py | 24 +++++++++---------- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 86c6cca8..70c74e9c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM continuumio/anaconda:latest +FROM continuumio/anaconda3:latest MAINTAINER Pierre-Elouan Rethore <pe@retho.re> RUN apt-get update \ diff --git a/topfarm/cost_models/fuga/Colonel b/topfarm/cost_models/fuga/Colonel index 5e567f7f..5f695353 160000 --- a/topfarm/cost_models/fuga/Colonel +++ b/topfarm/cost_models/fuga/Colonel @@ -1 +1 @@ -Subproject commit 5e567f7f2f4a28ed43da99052b43474eadaefd81 +Subproject commit 5f695353b799e0e49ad78c9ba40e09e84b3c762d diff --git a/topfarm/cost_models/fuga/py_fuga.py b/topfarm/cost_models/fuga/py_fuga.py index 2c81a77e..a107204e 100644 --- a/topfarm/cost_models/fuga/py_fuga.py +++ b/topfarm/cost_models/fuga/py_fuga.py @@ -75,7 +75,7 @@ class PyFuga(object): def get_no_tubines(self): no_turbines_p = c_int_p(c_int(0)) - self.lib.getNoTurbines(no_turbines_p) + self.lib.GetNoTurbines(no_turbines_p) return no_turbines_p.contents.value def move_turbines(self, tb_x, tb_y): @@ -91,7 +91,7 @@ class PyFuga(object): AEPNet_p = c_double_p(c_double(0)) AEPGros_p = c_double_p(c_double(0)) capacity_p = c_double_p(c_double(0)) - self.lib.getAEP(AEPNet_p, AEPGros_p, capacity_p) + self.lib.GetAEP(AEPNet_p, AEPGros_p, capacity_p) #print(tb_x, tb_y, AEPNet_p.contents.value, (15.850434458235156 - AEPNet_p.contents.value) / .000001) net, gros, cap = [p.contents.value for p in [AEPNet_p, AEPGros_p, capacity_p]] return (net, gros, cap, net / gros) @@ -101,7 +101,7 @@ class PyFuga(object): dAEPdxyz = np.zeros(len(tb_x)), np.zeros(len(tb_x)), np.zeros(len(tb_x)) dAEPdxyz_ctype = [dAEP.ctypes for dAEP in dAEPdxyz] - self.lib.getAEPGradients(*[dAEP_ctype.data_as(c_double_p) for dAEP_ctype in dAEPdxyz_ctype]) + self.lib.GetAEPGradients(*[dAEP_ctype.data_as(c_double_p) for dAEP_ctype in dAEPdxyz_ctype]) #print(tb_x, tb_y, dAEPdxyz) return np.array(dAEPdxyz) diff --git a/topfarm/cost_models/fuga/tests/test_pyfuga.py b/topfarm/cost_models/fuga/tests/test_pyfuga.py index 8c20b363..c65c78c4 100644 --- a/topfarm/cost_models/fuga/tests/test_pyfuga.py +++ b/topfarm/cost_models/fuga/tests/test_pyfuga.py @@ -38,10 +38,10 @@ class Test(unittest.TestCase): 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\hornsrev_north_only.lib') + farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib') def testCheckVersion(self): - lib = PascalDLL(fuga_path + "FugaLib/FugaLib.dll") + 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') diff --git a/topfarm/cost_models/utils/aep_calculator.py b/topfarm/cost_models/utils/aep_calculator.py index 94d86f52..cd5a3e40 100644 --- a/topfarm/cost_models/utils/aep_calculator.py +++ b/topfarm/cost_models/utils/aep_calculator.py @@ -4,18 +4,17 @@ Created on 19/04/2018 @author: Mads ''' import numpy as np + + class AEPCalculator(object): - - def __init__(self, wdir=np.arange(360),wsp=np.arange(3,25), wind_resource, wake_model): + + def __init__(self, wdir=np.arange(360), wsp=np.arange(3, 25), wind_resource, wake_model): self.wdir = wdir self.wsp = wsp self.wind_resource = wind_resource self.wake_model = wake_model - + def calculate_aep(self, turbine_positions): no_wake_wsp, no_wake_ti, weight = self.wind_resource(turbine_positions, self.wdir, self.wsp) wake_wsp, power, ct = self.wake_model(turbine_positions, no_wake_wsp, no_wake_ti) - return np.sum(power * weight) - - - \ No newline at end of file + return np.sum(power * weight) * 24 * 365 diff --git a/topfarm/cost_models/utils/wind_resource.py b/topfarm/cost_models/utils/wind_resource.py index d41a14e7..1b5a81bd 100644 --- a/topfarm/cost_models/utils/wind_resource.py +++ b/topfarm/cost_models/utils/wind_resource.py @@ -4,22 +4,22 @@ Created on 19/04/2018 @author: Mads ''' import numpy as np + + class WindResource(object): - def __init__(self,f,a,k,ti): + def __init__(self, f, a, k, ti): self.f = f self.a = a self.k = k self.ti = ti - + def weibull_weight(self, ws): - cdf = lambda ws, A=self.A,k=self.k : 1 - np.exp(-(ws / A) ** k) - dws = np.diff(ws,0) - return cdf(ws+dws) - cdf(ws-dws) - + cdf = lambda ws, A=self.A, k=self.k: 1 - np.exp(-(ws / A) ** k) + dws = np.diff(ws, 0) / 2 + return cdf(ws + dws) - cdf(ws - dws) + def __call__(self, turbine_positions, wdir, wsp): - - WS = np.broadcast_to(wsp, (len(turbine_positions), len(wdir),len(wsp))) - weight = self.weibull_weight(self.a, self.k, WS) - #TODO: add weight from wdir dist - return WS, np.zeros_like(WS)+self.ti, weight - + + WS = np.broadcast_to(wsp, (len(turbine_positions), len(wdir), len(wsp))) + weight = self.weibull_weight(self.a, self.k, WS) * self.f + return WS, np.zeros_like(WS) + self.ti, weight -- GitLab