Skip to content

Commit

Permalink
speed up tests; clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
misi9170 committed Sep 10, 2024
1 parent 667101b commit e1d18ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial.distance import cdist
from shapely.geometry import (
LineString,
Point,
Polygon,
)

from .layout_optimization_base import LayoutOptimization
from .layout_optimization_random_search import test_point_in_bounds
Expand Down Expand Up @@ -161,7 +154,7 @@ def optimize(self):
[test_point_in_bounds(xy[0], xy[1], self._boundary_polygon) for
xy in candidate_layouts[i, :, :]]
)
idx_max = np.argmax(turbines_in_bounds) # FIRST maximizing index returned
idx_max = np.argmax(turbines_in_bounds) # First maximizing index returned

# Get the best layout
x_opt_all = candidate_layouts[idx_max, :, 0]
Expand Down
30 changes: 8 additions & 22 deletions tests/layout_optimization_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,6 @@ def test_LayoutOptimizationGridded_initialization(caplog):
min_dist_D=5
)

def test_LayoutOptimizationGridded_default_grid():
fmodel = FlorisModel(configuration=YAML_INPUT)

# Set up a sample boundary
boundaries = [(0.0, 0.0), (0.0, 1000.0), (1000.0, 1000.0), (1000.0, 0.0), (0.0, 0.0)]

LayoutOptimizationGridded(
fmodel=fmodel,
boundaries=boundaries,
min_dist=50,
)

# Test it worked...

def test_LayoutOptimizationGridded_basic():
fmodel = FlorisModel(configuration=YAML_INPUT)

Expand Down Expand Up @@ -191,9 +177,9 @@ def test_LayoutOptimizationGridded_diagonal():
fmodel=fmodel,
boundaries=boundaries_diag,
min_dist=turbine_spacing,
rotation_step=5,
rotation_step=45, # To speed up test
rotation_range=(0, 360),
translation_step=20,
translation_step=50,
hexagonal_packing=False,
enable_geometric_yaw=False,
use_value=False,
Expand All @@ -217,7 +203,7 @@ def test_LayoutOptimizationGridded_diagonal():
min_dist=turbine_spacing,
rotation_step=5,
rotation_range=(0, 10),
translation_step=20,
translation_step=50,
hexagonal_packing=False,
enable_geometric_yaw=False,
use_value=False,
Expand All @@ -230,9 +216,9 @@ def test_LayoutOptimizationGridded_diagonal():
fmodel=fmodel,
boundaries=boundaries_diag,
min_dist=turbine_spacing,
rotation_step=60,
rotation_step=60, # Not fine enough to find ideal 45 deg rotation
rotation_range=(0, 360),
translation_step=20,
translation_step=50,
hexagonal_packing=False,
enable_geometric_yaw=False,
use_value=False,
Expand All @@ -245,7 +231,7 @@ def test_LayoutOptimizationGridded_diagonal():
fmodel=fmodel,
boundaries=boundaries_diag,
min_dist=turbine_spacing,
rotation_step=5,
rotation_step=45,
rotation_range=(0, 10),
translation_step=300,
hexagonal_packing=False,
Expand All @@ -259,7 +245,7 @@ def test_LayoutOptimizationGridded_separate_boundaries():
fmodel = FlorisModel(configuration=YAML_INPUT)
separate_boundaries = [
[(0.0, 0.0), (0.0, 100.0), (100.0, 100.0), (100.0, 0.0), (0.0, 0.0)],
[(1000.0, 0.0), (1000.0, 100.0), (1100.0, 100.0), (1100.0, 0.0), (1000.0, 0.0)]
[(200.0, 0.0), (200.0, 100.0), (300.0, 100.0), (300.0, 0.0), (200.0, 0.0)]
]

layout_opt = LayoutOptimizationGridded(
Expand All @@ -279,7 +265,7 @@ def test_LayoutOptimizationGridded_separate_boundaries():

# Check they're inside as expected
assert ((0.0 <= y_opt) & (y_opt <= 100.0)).all()
assert (((0.0 <= x_opt) & (x_opt <= 100.0)) | ((1000.0 <= x_opt) & (x_opt <= 1100.0))).all()
assert (((0.0 <= x_opt) & (x_opt <= 100.0)) | ((200.0 <= x_opt) & (x_opt <= 300.0))).all()


def test_LayoutOptimizationGridded_hexagonal():
Expand Down

0 comments on commit e1d18ae

Please sign in to comment.