Exemplo n.º 1
0
def test_state_array(turbineTypeOptimizationProblem):
    tf = turbineTypeOptimizationProblem
    arr = tf.state_array(['type', 'type'])
    npt.assert_equal(arr.shape, [3, 2])
    npt.assert_array_equal(arr, [[0, 0],
                                 [0, 0],
                                 [0, 0]])
Exemplo n.º 2
0
def testTopFarmProblem_get_DOE_array(turbineTypeOptimizationProblem):
    tf = turbineTypeOptimizationProblem
    npt.assert_array_equal(tf.get_DOE_array().shape, (27, 1, 3))
    npt.assert_array_equal(tf.get_DOE_array()[:5], [[[0, 0, 0]],
                                                    [[1, 0, 0]],
                                                    [[2, 0, 0]],
                                                    [[0, 1, 0]],
                                                    [[1, 1, 0]]])
def test_turbineType_optimization():
    optimal = np.array([[1], [0]])
    tf = TopFarmProblem(design_vars={'type': (optimal[:, 0], 0, 1)},
                        cost_comp=DummyCost(optimal_state=optimal,
                                            inputs=['type']),
                        driver=DOEDriver(FullFactorialGenerator(2)))
    cost, state, _ = tf.optimize()
    assert cost == 0
    npt.assert_array_equal(state['type'], [1, 0])
Exemplo n.º 4
0
def test_TopFarmProblemSpacingConstraint():
    tf = xy3tb.get_tf(design_vars={'x': [3, 7, 4], 'y': [-3, -7, -3]},
                      constraints=[SpacingConstraint(2)])
    tf.evaluate({'x': xy3tb.desired[:, 0], 'y': xy3tb.desired[:, 1]})
    npt.assert_array_equal(tf['wtSeparationSquared'], [32, 1, 25])

    _, state, _ = tf.optimize()
    npt.assert_array_almost_equal(state['x'], [2.5, 7, 4.5])
    npt.assert_array_almost_equal(state['y'], xy3tb.optimal[:, 1])
Exemplo n.º 5
0
def testTopFarm():
    tf = TopFarm(xy3tb.initial,
                 DummyCost(xy3tb.desired, ['x', 'y']),
                 min_spacing=2,
                 boundary=xy3tb.boundary)
    cost, state = tf.evaluate()
    assert cost == 45
    npt.assert_array_equal(state['x'], xy3tb.initial[:, 0])
    npt.assert_array_equal(state['y'], xy3tb.initial[:, 1])
Exemplo n.º 6
0
def test_update_state(turbineTypeOptimizationProblem, types, cost):
    tf = turbineTypeOptimizationProblem
    c, state = tf.evaluate({'type': types})
    npt.assert_equal(c, cost)
    npt.assert_array_equal(state['type'], types)
    # wrong shape
    c, state = tf.evaluate({'type': [types]})
    npt.assert_equal(c, cost)
    npt.assert_array_equal(state['type'], types)
    # missing key
    c, state = tf.evaluate({'missing': types})
Exemplo n.º 7
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:])
def test_turbineType_optimization():
    cost_comp = DummyCost(optimal_state=optimal, inputs=['type'])
    tf = TurbineTypeOptimizationProblem(cost_comp=cost_comp,
                                        turbineTypes=[0, 0],
                                        lower=0,
                                        upper=1,
                                        driver=DOEDriver(
                                            FullFactorialGenerator(2)))
    cost, state, _ = tf.optimize()
    assert cost == 0
    npt.assert_array_equal(state['type'], [1, 0])
Exemplo n.º 9
0
def test_TopFarmProblemXYBoundaryPenaltyAndLimits():
    tf = xy3tb.get_tf(design_vars={'x': ([3, 7, 4], -1, 5), 'y': ([-3, -7, -3], -9, -1)},
                      driver=EasyRandomSearchDriver(RandomizeTurbinePosition(1), 10),
                      constraints=[XYBoundaryConstraint(xy3tb.boundary)])
    tf.evaluate({'x': xy3tb.desired[:, 0], 'y': xy3tb.desired[:, 1]})
    npt.assert_equal(tf['boundaryDistances'][1, 3], -1)

    desvars = tf.driver._designvars
    npt.assert_equal(desvars['indeps.x']['lower'], 0)
    npt.assert_equal(desvars['indeps.x']['upper'], 5)
    npt.assert_array_equal(desvars['indeps.y']['lower'], -9)
    npt.assert_array_equal(desvars['indeps.y']['upper'], -1)
Exemplo n.º 10
0
def test_TopFarmProblemLimits():

    tf = xy3tb.get_tf(design_vars={'x': (xy3tb.initial[:, 0], -3, 3),
                                   'y': (xy3tb.initial[:, 1], [-4, -3, -2], [2, 3, 4])},
                      driver=EasyRandomSearchDriver(RandomizeTurbinePosition(1), max_iter=100),
                      constraints=[])
    tf.evaluate()
    desvars = tf.driver._designvars
    npt.assert_equal(desvars['indeps.x']['lower'], -3)
    npt.assert_equal(desvars['indeps.x']['upper'], 3)
    npt.assert_array_equal(desvars['indeps.y']['lower'], [-4, -3, -2])
    npt.assert_array_equal(desvars['indeps.y']['upper'], [2, 3, 4])
def test_list_driver(get_tf):
    xyz = [[[1, 2], [3, 4], [5, 6]], [[4, 3], [6, 5], [2, 1]]]
    lst = [[('x', [1, 2]), ('y', [3, 4]), ('z', [5, 6])],
           [('x', [4, 3]), ('y', [6, 5]), ('z', [2, 1])]]

    tf = get_tf(driver=lst)  # pure list
    npt.assert_array_equal(tf.get_DOE_array(), xyz)

    tf = get_tf(driver=ListGenerator(lst))  # list generator
    npt.assert_array_equal(tf.get_DOE_array(), xyz)

    tf = get_tf(driver=DOEDriver(ListGenerator(lst)))  # DOEDriver
    npt.assert_array_equal(tf.get_DOE_array(), xyz)
Exemplo n.º 12
0
def testTopFarmProblem_get_DOE_list(turbineTypeOptimizationProblem):
    tf = turbineTypeOptimizationProblem
    npt.assert_array_equal(len(tf.get_DOE_list()), 27)
    (k, v), = tf.get_DOE_list()[1]
    assert k == "indeps.type"
    npt.assert_array_equal(v, [1, 0, 0])