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

add dAEP_dxy as cost_gradient_function in PyWakeAEPCostModelComponent

parent dcc9204b
No related branches found
No related tags found
1 merge request!175add dAEP_dxy as cost_gradient_function in PyWakeAEPCostModelComponent
Pipeline #29593 passed
......@@ -58,7 +58,8 @@ def main():
def get_tf(windFarmModel):
return TopFarmProblem(
design_vars=dict(zip('xy', init_pos.T)),
cost_comp=PyWakeAEPCostModelComponent(windFarmModel, n_wt=3, ws=10, wd=np.arange(0, 360, 12)),
cost_comp=PyWakeAEPCostModelComponent(windFarmModel, n_wt=3, ws=10, wd=np.arange(0, 360, 12),
grad_method=None),
constraints=[SpacingConstraint(min_spacing),
XYBoundaryConstraint(boundary)],
driver=EasyScipyOptimizeDriver(),
......
......@@ -13,6 +13,7 @@ from scipy.interpolate.interpolate import RegularGridInterpolator
import warnings
from py_wake.flow_map import HorizontalGrid
import xarray as xr
from py_wake.utils.gradients import autograd
class PyWakeAEP(AEPCalculator):
......@@ -55,17 +56,32 @@ class PyWakeAEP(AEPCalculator):
class PyWakeAEPCostModelComponent(AEPCostModelComponent):
def __init__(self, windFarmModel, n_wt, wd=None, ws=None, max_eval=None, **kwargs):
def __init__(self, windFarmModel, n_wt, wd=None, ws=None, max_eval=None, grad_method=autograd, **kwargs):
self.windFarmModel = windFarmModel
def aep(**kwargs):
return self.windFarmModel.aep(x=kwargs[topfarm.x_key],
y=kwargs[topfarm.y_key],
h=kwargs.get(topfarm.z_key, None),
type=kwargs.get(topfarm.type_key, 0),
wd=wd, ws=ws)
if grad_method:
dAEPdxy = self.windFarmModel.dAEPdxy(grad_method)
def daep(**kwargs):
return dAEPdxy(x=kwargs[topfarm.x_key],
y=kwargs[topfarm.y_key],
h=kwargs.get(topfarm.z_key, None),
type=kwargs.get(topfarm.type_key, 0),
wd=wd, ws=ws)
else:
daep = None
AEPCostModelComponent.__init__(self,
input_keys=[topfarm.x_key, topfarm.y_key],
n_wt=n_wt,
cost_function=lambda **kwargs: self.windFarmModel.aep(
x=kwargs[topfarm.x_key],
y=kwargs[topfarm.y_key],
h=kwargs.get(topfarm.z_key, None),
type=kwargs.get(topfarm.type_key, 0),
wd=wd, ws=ws),
cost_function=aep,
cost_gradient_function=daep,
output_unit='GWh',
max_eval=max_eval, **kwargs)
......
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