Example #1
0
def testAEP_topfarm_optimization_2tb_scale(get_fuga, scale):
    D = 80.0
    B = 2 * D + 10
    init_pos = np.array([(-10, 1 * D), (10, -D)])

    wind_atlas = 'MyFarm/north_pm30_only.lib'
    pyFuga = get_fuga(init_pos[:1, 0], init_pos[:1, 1], wind_atlas=wind_atlas)
    AEP_pr_tb = pyFuga.get_aep()[1]
    pyFuga = get_fuga(init_pos[:, 0], init_pos[:, 1], wind_atlas=wind_atlas)
    boundary = [(-B, B), (B, B), (B, -B), (-B, -B), (-B, B)]

    plot_comp = NoPlot()
    # plot_comp = PlotComp()

    cost_comp = AEPCostModelComponent(
        'xy',
        init_pos.shape[0],
        lambda x, y: scale * pyFuga.get_aep(np.array([x, y]).T)[0],  # only aep
        lambda x, y: scale * pyFuga.get_aep_gradients(np.array([x, y]).T)[:2]
    )  # only dAEPdx and dAEPdy

    tf = TopFarmProblem(
        dict(zip('xy', init_pos.T)),
        cost_comp,
        constraints=[SpacingConstraint(2 * D),
                     XYBoundaryConstraint(boundary)],
        plot_comp=plot_comp,
        driver=EasyScipyOptimizeDriver(tol=1e-8, disp=False),
        expected_cost=AEP_pr_tb * 2 * scale)
    cost, _, rec = tf.optimize()
    tf.plot_comp.show()
    uta.assertAlmostEqual(-cost / scale, AEP_pr_tb * 2, delta=.02)
Example #2
0
    def get_TopFarm_cost_component(self):
        n_wt = self.wake_model.windFarm.nWT

        return AEPCostModelComponent(
            input_keys=['x', 'y'],
            n_wt=n_wt,
            cost_function=lambda *args, **kwargs: self(*args, **kwargs),
            output_unit='GWh')
Example #3
0
 def get_TopFarm_cost_component(self):
     n_wt = self.get_no_turbines()
     return AEPCostModelComponent(
         ['x', 'y'],
         n_wt,
         lambda x, y, **kwargs: self.get_aep(np.array([x, y]).T)[
             0],  # only aep
         lambda x, y, **kwargs: self.get_aep_gradients(np.array([x, y]).T)
         [:2])  # only dAEPdx and dAEPdy
Example #4
0
def test_maxiter_CostModelComponent():
    tf = get_tf(
        AEPCostModelComponent(['x', 'y'],
                              4,
                              aep_cost,
                              aep_gradients,
                              max_eval=10))
    cost, state, recorder = tf.optimize()
    assert 10 <= tf.cost_comp.counter <= 11, tf.cost_comp.counter
    npt.assert_array_equal(recorder['AEP'][tf.cost_comp.n_func_eval],
                           recorder['AEP'][tf.cost_comp.n_func_eval:])
Example #5
0
    def get_TopFarm_cost_component(self):
        n_wt = self.wake_model.windFarm.nWT

        def aep_func(x, y, **kwargs):
            return AEPCalculator(self.wind_resource, self.wake_model)(x,
                                                                      y).sum()

        return AEPCostModelComponent(input_keys=['x', 'y'],
                                     n_wt=n_wt,
                                     cost_function=aep_func,
                                     output_unit='GWh')
Example #6
0
    def get_TopFarm_cost_component(self, n_wt):

        return AEPCostModelComponent(
            input_keys=['x', 'y'],
            n_wt=n_wt,
            cost_function=lambda **kwargs: self.calculate_AEP(
                x_i=kwargs[x_key],
                y_i=kwargs[y_key],
                h_i=kwargs.get(z_key, None),
                type_i=kwargs.get(type_key, None)).sum(),
            output_unit='GWh')
 def __init__(self,
              windFarmModel,
              n_wt,
              wd=None,
              ws=None,
              max_eval=None,
              **kwargs):
     self.windFarmModel = windFarmModel
     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),
         output_unit='GWh',
         max_eval=max_eval,
         **kwargs)
Example #8
0
def testCostModelComponentAdditionalOutput():
    def aep_cost(x, y):
        opt_x, opt_y = optimal.T
        return -np.sum((x - opt_x)**2 + (y - opt_y)**2), {'add_out': sum(x)}

    tf = get_tf(
        AEPCostModelComponent(['x', 'y'],
                              4,
                              aep_cost,
                              aep_gradients,
                              additional_output=[('add_out', 0)]))
    _, state, _ = tf.optimize()
    npt.assert_array_almost_equal(tf.turbine_positions[:, :2],
                                  optimal_with_constraints, 5)
    npt.assert_equal(sum(state['x']), state['add_out'])
    def get_TopFarm_cost_component(self, n_wt, wd=None, ws=None):
        """Create topfarm-style cost component

        Parameters
        ----------
        n_wt : int
            Number of wind turbines
        """
        return AEPCostModelComponent(
            input_keys=['x', 'y'],
            n_wt=n_wt,
            cost_function=lambda **kwargs: self.calculate_AEP(
                x_i=kwargs[topfarm.x_key],
                y_i=kwargs[topfarm.y_key],
                h_i=kwargs.get(topfarm.z_key, None),
                type_i=kwargs.get(topfarm.type_key, 0),
                wd=wd,
                ws=ws).sum(),
            output_unit='GWh')
Example #10
0
def testCostModelComponentDiffShapeInput():
    def aep_cost(x, y, h):
        opt_x, opt_y = optimal.T
        return -np.sum((x - opt_x)**2 + (y - opt_y)**2) + h, {
            'add_out': sum(x)
        }

    cost_comp = AEPCostModelComponent(['x', 'y', ('h', 0)],
                                      4,
                                      aep_cost,
                                      additional_output=[('add_out', 0)])
    tf = TopFarmProblem(dict(zip('xy', initial.T)),
                        cost_comp=cost_comp,
                        constraints=[
                            SpacingConstraint(min_spacing),
                            XYBoundaryConstraint(boundary)
                        ],
                        driver=EasyScipyOptimizeDriver(disp=False),
                        ext_vars={'h': 0})
    cost0, _, _ = tf.optimize(state={'h': 0})
    cost10, _, _ = tf.optimize(state={'h': 10})
    npt.assert_almost_equal(cost10, cost0 - 10)
Example #11
0
def testAEPCostModelComponent():
    tf = get_tf(AEPCostModelComponent(['x', 'y'], 4, aep_cost, aep_gradients))
    tf.optimize()
    np.testing.assert_array_almost_equal(tf.turbine_positions[:, :2],
                                         optimal_with_constraints, 5)