Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fi test #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def __init__(self):
"wake": self.wake,
"solver": {
"type": "turbine_grid",
"turbine_grid_points": 5,
"turbine_grid_points": 3,
},
"logging": {
"console": {"enable": True, "level": 1},
Expand Down
37 changes: 1 addition & 36 deletions tests/floris_interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def test_calculate_no_wake():
"""
In FLORIS v3.2, running calculate_no_wake twice incorrectly set the yaw angles when the first
time has non-zero yaw settings but the second run had all-zero yaw settings. The test below
asserts that the yaw angles are correctly set in subsequent calls to calculate_no_wake. After
that test are additional tests to check the final values of calculate_no_wake.
asserts that the yaw angles are correctly set in subsequent calls to calculate_no_wake.
"""
fi = FlorisInterface(configuration=YAML_INPUT)
yaw_angles = 20 * np.ones(
Expand All @@ -72,40 +71,6 @@ def test_calculate_no_wake():
fi.calculate_no_wake(yaw_angles=yaw_angles)
assert fi.floris.farm.yaw_angles == yaw_angles

# check finalized values of calculate_no_wake
fi_base = FlorisInterface(configuration=YAML_INPUT)
yaw_angles = np.zeros(
(
fi_base.floris.flow_field.n_wind_directions,
fi_base.floris.flow_field.n_wind_speeds,
fi_base.floris.farm.n_turbines
)
)
fi_base.floris.farm.yaw_angles = yaw_angles
fi_base.floris.flow_field.initialize_velocity_field(fi_base.floris.grid)
fi_base.floris.farm.initialize(fi_base.floris.grid.sorted_indices)
fi_base.floris.finalize()

fi = FlorisInterface(configuration=YAML_INPUT)
fi.calculate_no_wake()

# check flow_field finalized values
assert np.allclose(fi_base.floris.flow_field.u, fi.floris.flow_field.u)
assert np.allclose(fi_base.floris.flow_field.v, fi.floris.flow_field.v)
assert np.allclose(fi_base.floris.flow_field.w, fi.floris.flow_field.w)
assert np.allclose(
fi_base.floris.flow_field.turbulence_intensity_field,
fi.floris.flow_field.turbulence_intensity_field
)

# check farm finalized values
assert np.allclose(fi_base.floris.farm.yaw_angles, fi.floris.farm.yaw_angles)
assert np.allclose(fi_base.floris.farm.hub_heights, fi.floris.farm.hub_heights)
assert np.allclose(fi_base.floris.farm.rotor_diameters, fi.floris.farm.rotor_diameters)
assert np.allclose(fi_base.floris.farm.TSRs, fi.floris.farm.TSRs)
assert np.allclose(fi_base.floris.farm.pPs, fi.floris.farm.pPs)
assert fi_base.floris.farm.turbine_type_map == fi.floris.farm.turbine_type_map


def test_reinitialize():
pass
Expand Down
100 changes: 50 additions & 50 deletions tests/reg_tests/cumulative_curl_regression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,85 +26,85 @@
[
# 8 m/s
[
[7.9803783, 0.7634300, 1695368.7987130, 0.2568077],
[5.3585771, 0.8698045, 492577.1572448, 0.3195870],
[4.9669368, 0.8944963, 379718.4177412, 0.3375933],
[7.9736330, 0.7636044, 1691326.6483808, 0.2568973],
[5.4838164, 0.8620156, 529225.9172271, 0.3142687],
[5.0221433, 0.8907283, 394126.6156555, 0.3347186],
],
# 9 m/s
[
[8.9779256, 0.7625731, 2413658.0981405, 0.2563676],
[6.0299374, 0.8340431, 719536.2896199, 0.2963110],
[5.5776779, 0.8570341, 560907.3153174, 0.3109458],
[8.9703371, 0.7625570, 2407841.6718785, 0.2563594],
[6.1712539, 0.8275295, 776795.0248898, 0.2923521],
[5.6500663, 0.8533298, 586018.0719934, 0.3085123],
],
# 10 m/s
[
[9.9754729, 0.7527803, 3306006.2306084, 0.2513940],
[6.7205268, 0.8035032, 1012640.0064192, 0.2783602],
[6.2110904, 0.8256933, 792936.0055473, 0.2912497],
[9.9670412, 0.7529384, 3298067.1555604, 0.2514735],
[6.8779113, 0.7971705, 1085894.0434488, 0.2748170],
[6.2985764, 0.8216609, 828383.6208269, 0.2888489],
],
# 11 m/s
[
[10.9730201, 0.7304328, 4373596.1594956, 0.2404007],
[7.4516751, 0.7774337, 1381908.5141696, 0.2641154],
[6.8606000, 0.7978670, 1077836.5443900, 0.2752040],
]
[10.9637454, 0.7306256, 4363191.9880631, 0.2404936],
[7.6258784, 0.7725938, 1482932.7552807, 0.2615643],
[6.9611771, 0.7938200, 1124649.7898263, 0.2729648],
],
]
)

yawed_baseline = np.array(
[
# 8 m/s
[
[7.9803783, 0.7605249, 1683956.5765064, 0.2548147],
[5.4029703, 0.8670436, 505567.9316776, 0.3176841],
[4.9742156, 0.8939700, 381463.8369041, 0.3371887],
[7.9736330, 0.7606986, 1679924.0721706, 0.2549029],
[5.5274362, 0.8596051, 543479.0426304, 0.3126534],
[5.0310723, 0.8901730, 396739.4832795, 0.3342992],
],
# 9 m/s
[
[8.9779256, 0.7596713, 2397236.5542849, 0.2543815],
[6.0798421, 0.8317429, 739756.7356164, 0.2949042],
[5.5879702, 0.8565074, 564477.6027506, 0.3105979],
[8.9703371, 0.7596552, 2391434.0080674, 0.2543734],
[6.2202711, 0.8252701, 796655.8471824, 0.2909965],
[5.6617378, 0.8527326, 590066.7909898, 0.3081228],
],
# 10 m/s
[
[9.9754729, 0.7499157, 3283591.8023665, 0.2494847],
[6.7754450, 0.8012935, 1038201.4571916, 0.2771174],
[6.2236744, 0.8251133, 798034.8027193, 0.2909027],
[9.9670412, 0.7500732, 3275671.6727516, 0.2495630],
[6.9317633, 0.7950036, 1110959.2451850, 0.2736173],
[6.3125748, 0.8210156, 834055.5094286, 0.2884673],
],
# 11 m/s
[
[10.9730201, 0.7276532, 4344222.0129382, 0.2386508],
[7.5103951, 0.7755790, 1413728.7289467, 0.2631345],
[6.8746872, 0.7973002, 1084393.3749950, 0.2748890],
]
[10.9637454, 0.7278454, 4333842.6695283, 0.2387424],
[7.6832308, 0.7711112, 1517301.5142304, 0.2607884],
[6.9761726, 0.7932167, 1131629.3899797, 0.2726328],
],
]
)

yaw_added_recovery_baseline = np.array(
[
# 8 m/s
[
[7.9803783, 0.7605249, 1683956.5765064, 0.2548147],
[5.4219904, 0.8658607, 511133.7736997, 0.3168748],
[4.9901603, 0.8928170, 385287.3116696, 0.3363059],
[7.9736330, 0.7606986, 1679924.0721706, 0.2549029],
[5.5431146, 0.8588028, 548917.6953551, 0.3121189],
[5.0453462, 0.8892852, 400916.4566323, 0.3336309],
],
# 9 m/s
[
[8.9779256, 0.7596713, 2397236.5542849, 0.2543815],
[6.1011855, 0.8307591, 748404.6404163, 0.2943055],
[5.6071092, 0.8555280, 571116.7279097, 0.3099527],
[8.9703371, 0.7596552, 2391434.0080674, 0.2543734],
[6.2378520, 0.8244598, 803779.2831349, 0.2905124],
[5.6785118, 0.8518742, 595885.4921489, 0.3075644],
],
# 10 m/s
[
[9.9754729, 0.7499157, 3283591.8023665, 0.2494847],
[6.7984638, 0.8003672, 1048915.4794254, 0.2765986],
[6.2451030, 0.8241256, 806717.2493019, 0.2903131],
[9.9670412, 0.7500732, 3275671.6727516, 0.2495630],
[6.9507085, 0.7942413, 1119777.2268361, 0.2731968],
[6.3312183, 0.8201563, 841609.4907163, 0.2879601],
],
# 11 m/s
[
[10.9730201, 0.7276532, 4344222.0129382, 0.2386508],
[7.5339320, 0.7749706, 1427833.3888763, 0.2628137],
[6.8970594, 0.7964000, 1094806.4414958, 0.2743897],
[10.9637454, 0.7278454, 4333842.6695283, 0.2387424],
[7.7025449, 0.7706119, 1528875.6023356, 0.2605276],
[6.9954994, 0.7924390, 1140624.9700319, 0.2722057],
],
]
)
Expand All @@ -113,27 +113,27 @@
[
# 8 m/s
[
[7.9803783, 0.7605249, 1683956.5765064, 0.2548147],
[5.4029709, 0.8670436, 505568.1176628, 0.3176840],
[4.9790760, 0.8936185, 382629.3354701, 0.3369191],
[7.9736330, 0.7606986, 1679924.0721706, 0.2549029],
[5.5274367, 0.8596051, 543479.2092235, 0.3126534],
[5.0364358, 0.8898394, 398309.0269631, 0.3340477],
],
# 9 m/s
[
[8.9779256, 0.7596713, 2397236.5542849, 0.2543815],
[6.0798429, 0.8317428, 739757.0246720, 0.2949042],
[5.5937356, 0.8562124, 566477.5644593, 0.3104033],
[8.9703371, 0.7596552, 2391434.0080674, 0.2543734],
[6.2202717, 0.8252701, 796656.0654567, 0.2909965],
[5.6680298, 0.8524106, 592249.4291781, 0.3079132],
],
# 10 m/s
[
[9.9754729, 0.7499157, 3283591.8023665, 0.2494847],
[6.7754458, 0.8012934, 1038201.8164555, 0.2771174],
[6.2301672, 0.8248140, 800665.5335362, 0.2907239],
[9.9670412, 0.7500732, 3275671.6727516, 0.2495630],
[6.9317639, 0.7950036, 1110959.5162103, 0.2736173],
[6.3196140, 0.8206912, 836907.6633514, 0.2882756],
],
# 11 m/s
[
[10.9730201, 0.7276532, 4344222.0129382, 0.2386508],
[7.5103959, 0.7755790, 1413729.2052485, 0.2631345],
[6.8816977, 0.7970181, 1087656.4020125, 0.2747324],
[10.9637454, 0.7278454, 4333842.6695283, 0.2387424],
[7.6832314, 0.7711112, 1517301.8723625, 0.2607884],
[6.9837299, 0.7929126, 1135146.9152189, 0.2724657],
],
]
)
Expand Down
126 changes: 126 additions & 0 deletions tests/reg_tests/floris_interface_regression_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Copyright 2023 NREL

# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

# See https://floris.readthedocs.io for documentation

import numpy as np

from floris.tools import FlorisInterface
from tests.conftest import (
N_TURBINES,
N_WIND_SPEEDS,
N_WIND_DIRECTIONS,
print_test_values,
assert_results_arrays,
)
from floris.simulation import Ct, power, axial_induction, average_velocity


DEBUG = False
VELOCITY_MODEL = "gauss"
DEFLECTION_MODEL = "gauss"

baseline = np.array(
[
# 8 m/s
[
[7.9736330, 0.7636044, 1691326.6483808, 0.2568973],
[7.9736330, 0.7636044, 1691326.6483808, 0.2568973],
[7.9736330, 0.7636044, 1691326.6483808, 0.2568973],
],
# 9 m/s
[
[8.9703371, 0.7625570, 2407841.6718785, 0.2563594],
[8.9703371, 0.7625570, 2407841.6718785, 0.2563594],
[8.9703371, 0.7625570, 2407841.6718785, 0.2563594],
],
# 10 m/s
[
[9.9670412, 0.7529384, 3298067.1555604, 0.2514735],
[9.9670412, 0.7529384, 3298067.1555604, 0.2514735],
[9.9670412, 0.7529384, 3298067.1555604, 0.2514735],
],
# 11 m/s
[
[10.9637454, 0.7306256, 4363191.9880631, 0.2404936],
[10.9637454, 0.7306256, 4363191.9880631, 0.2404936],
[10.9637454, 0.7306256, 4363191.9880631, 0.2404936],
],
]
)


def test_calculate_no_wake(sample_inputs_fixture):
"""
The calculate_no_wake function calculates the power production of a wind farm
assuming no wake losses. It does this by initializing and finalizing the
floris simulation while skipping the wake calculation. The power for all wind
turbines should be the same for a uniform wind condition. The chosen wake model
is not important since it will not actually be used. However, it is left enabled
instead of using "None" so that additional tests can be constructed here such
as one with yaw activated.
"""
sample_inputs_fixture.floris["wake"]["model_strings"]["velocity_model"] = VELOCITY_MODEL
sample_inputs_fixture.floris["wake"]["model_strings"]["deflection_model"] = DEFLECTION_MODEL

fi = FlorisInterface(sample_inputs_fixture.floris)
fi.calculate_no_wake()

n_turbines = fi.floris.farm.n_turbines
n_wind_speeds = fi.floris.flow_field.n_wind_speeds
n_wind_directions = fi.floris.flow_field.n_wind_directions

velocities = fi.floris.flow_field.u
yaw_angles = fi.floris.farm.yaw_angles
test_results = np.zeros((n_wind_directions, n_wind_speeds, n_turbines, 4))

farm_avg_velocities = average_velocity(
velocities,
)
farm_cts = Ct(
velocities,
yaw_angles,
fi.floris.farm.turbine_fCts,
fi.floris.farm.turbine_type_map,
)
farm_powers = power(
fi.floris.flow_field.air_density,
fi.floris.farm.ref_density_cp_cts,
velocities,
yaw_angles,
fi.floris.farm.pPs,
fi.floris.farm.turbine_power_interps,
fi.floris.farm.turbine_type_map,
)
farm_axial_inductions = axial_induction(
velocities,
yaw_angles,
fi.floris.farm.turbine_fCts,
fi.floris.farm.turbine_type_map,
)
for i in range(n_wind_directions):
for j in range(n_wind_speeds):
for k in range(n_turbines):
test_results[i, j, k, 0] = farm_avg_velocities[i, j, k]
test_results[i, j, k, 1] = farm_cts[i, j, k]
test_results[i, j, k, 2] = farm_powers[i, j, k]
test_results[i, j, k, 3] = farm_axial_inductions[i, j, k]

if DEBUG:
print_test_values(
farm_avg_velocities,
farm_cts,
farm_powers,
farm_axial_inductions,
)

assert_results_arrays(test_results[0], baseline)
Loading