Skip to content

Commit 71a2251

Browse files
committed
Load cp_ct data on turbine construction rather than in operation model calls. Revert type_dec changes.
1 parent 437afe8 commit 71a2251

File tree

4 files changed

+45
-38
lines changed

4 files changed

+45
-38
lines changed

floris/core/turbine/tum_operation_model.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import annotations
22

33
import copy
4-
import os
5-
from pathlib import Path
64

75
import numpy as np
86
from attrs import define
@@ -191,13 +189,10 @@ def power(
191189
# ratio of yawed to unyawed thrust coefficients
192190
ratio = p / p0
193191

194-
# Load Cp surface data and construct interpolator
195-
pkgroot = Path(os.path.dirname(os.path.abspath(__file__))).resolve().parents[1]
196-
lut_file = pkgroot / "turbine_library" / power_thrust_table["cp_ct_data_file"]
197-
LUT = np.load(lut_file)
198-
cp_i = LUT["cp_lut"]
199-
pitch_i = LUT["pitch_lut"]
200-
tsr_i = LUT["tsr_lut"]
192+
# Extract data from lookup table and construct interpolator
193+
cp_i = power_thrust_table["cp_ct_data"]["cp_lut"]
194+
pitch_i = power_thrust_table["cp_ct_data"]["pitch_lut"]
195+
tsr_i = power_thrust_table["cp_ct_data"]["tsr_lut"]
201196
interp_lut = RegularGridInterpolator(
202197
(tsr_i, pitch_i), cp_i, bounds_error=False, fill_value=None
203198
)
@@ -343,13 +338,10 @@ def thrust_coefficient(
343338
# Compute ratio of yawed to unyawed thrust coefficients
344339
ratio = thrust_coefficient1 / thrust_coefficient0 # See above eq. (29)
345340

346-
# Load Ct surface data and construct interpolator
347-
pkgroot = Path(os.path.dirname(os.path.abspath(__file__))).resolve().parents[1]
348-
lut_file = pkgroot / "turbine_library" / power_thrust_table["cp_ct_data_file"]
349-
LUT = np.load(lut_file)
350-
ct_i = LUT["ct_lut"]
351-
pitch_i = LUT["pitch_lut"]
352-
tsr_i = LUT["tsr_lut"]
341+
# Extract data from lookup table and construct interpolator
342+
ct_i = power_thrust_table["cp_ct_data"]["ct_lut"]
343+
pitch_i = power_thrust_table["cp_ct_data"]["pitch_lut"]
344+
tsr_i = power_thrust_table["cp_ct_data"]["tsr_lut"]
353345
interp_lut = RegularGridInterpolator(
354346
(tsr_i, pitch_i), ct_i, bounds_error=False, fill_value=None
355347
) # *0.9722085500886761)
@@ -702,13 +694,10 @@ def get_pitch(x, *data):
702694
y = aero_pow - electric_pow
703695
return y
704696

705-
# Load Cp/Ct data
706-
pkgroot = Path(os.path.dirname(os.path.abspath(__file__))).resolve().parents[1]
707-
lut_file = pkgroot / "turbine_library" / power_thrust_table["cp_ct_data_file"]
708-
LUT = np.load(lut_file)
709-
cp_i = LUT["cp_lut"]
710-
pitch_i = LUT["pitch_lut"]
711-
tsr_i = LUT["tsr_lut"]
697+
# Extract data from lookup table
698+
cp_i = power_thrust_table["cp_ct_data"]["cp_lut"]
699+
pitch_i = power_thrust_table["cp_ct_data"]["pitch_lut"]
700+
tsr_i = power_thrust_table["cp_ct_data"]["tsr_lut"]
712701
idx = np.squeeze(np.where(cp_i == np.max(cp_i)))
713702

714703
tsr_opt = tsr_i[idx[0]]

floris/core/turbine/turbine.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import copy
5+
import os
56
from collections.abc import Callable, Iterable
67
from pathlib import Path
78

@@ -476,10 +477,6 @@ class Turbine(BaseClass):
476477
correct_cp_ct_for_tilt: bool = field(default=False)
477478
floating_tilt_table: dict[str, NDArrayFloat] | None = field(default=None)
478479

479-
# Even though this Turbine class does not support the multidimensional features as they
480-
# are implemented in TurbineMultiDim, providing the following two attributes here allows
481-
# the turbine data inputs to keep the multidimensional Cp and Ct curve but switch them off
482-
# with multi_dimensional_cp_ct = False
483480
multi_dimensional_cp_ct: bool = field(default=False)
484481

485482
# Initialized in the post_init function
@@ -507,13 +504,21 @@ def __attrs_post_init__(self) -> None:
507504

508505
def __post_init__(self) -> None:
509506
self._initialize_tilt_interpolation()
507+
508+
bypass_numeric_converter = False
510509
if self.multi_dimensional_cp_ct:
511510
self._initialize_multidim_power_thrust_table()
512-
else:
513-
self.power_thrust_table = floris_numeric_dict_converter(
514-
self.power_thrust_table,
515-
allow_strings=True
516-
)
511+
bypass_numeric_converter = True
512+
513+
# Check for whether a cp_ct_data_file is specified, and load it if so.
514+
if "cp_ct_data_file" in self.power_thrust_table:
515+
floris_root = Path(__file__).resolve().parents[2]
516+
file_path = floris_root / "turbine_library" / self.power_thrust_table["cp_ct_data_file"]
517+
self.power_thrust_table["cp_ct_data"] = np.load(file_path)
518+
bypass_numeric_converter = True
519+
520+
if not bypass_numeric_converter:
521+
self.power_thrust_table = floris_numeric_dict_converter(self.power_thrust_table)
517522

518523
def _initialize_power_thrust_functions(self) -> None:
519524
turbine_function_model = TURBINE_MODEL_MAP["operation_model"][self.operation_model]

floris/type_dec.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def floris_array_converter(data: Iterable) -> np.ndarray:
5959
raise TypeError(e.args[0] + f". Data given: {data}")
6060
return a
6161

62-
def floris_numeric_dict_converter(data: dict, allow_strings=False) -> dict:
62+
def floris_numeric_dict_converter(data: dict) -> dict:
6363
"""
6464
For the given dictionary, convert all the values to a numeric type. If a value is a scalar, it
6565
will be converted to a float. If a value is an iterable, it will be converted to a Numpy
@@ -79,11 +79,9 @@ def floris_numeric_dict_converter(data: dict, allow_strings=False) -> dict:
7979
except TypeError:
8080
# Not iterable so try to cast to float
8181
converted_dict[k] = float(v)
82-
else: # Iterable so convert to Numpy array
83-
if allow_strings and isinstance(v, str):
84-
converted_dict[k] = v
85-
else:
86-
converted_dict[k] = floris_array_converter(v)
82+
else:
83+
# Iterable so convert to Numpy array
84+
converted_dict[k] = floris_array_converter(v)
8785
return converted_dict
8886

8987
# def array_field(**kwargs) -> Callable:

tests/tum_operation_model_unit_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
from pathlib import Path
3+
14
import numpy as np
25
import pytest
36

@@ -22,6 +25,10 @@ def test_TUMLossTurbine():
2225
wind_speed = 10.0
2326
turbine_data = SampleInputs().turbine
2427
turbine_data["power_thrust_table"] = SampleInputs().tum_loss_turbine_power_thrust_table
28+
data_file_path = Path(__file__).resolve().parents[1] / "floris" / "turbine_library"
29+
turbine_data["power_thrust_table"]["cp_ct_data"] = np.load(
30+
data_file_path / turbine_data["power_thrust_table"]["cp_ct_data_file"]
31+
)
2532

2633
yaw_angles_nom = 0 * np.ones((1, n_turbines))
2734
tilt_angles_nom = turbine_data["power_thrust_table"]["ref_tilt"] * np.ones((1, n_turbines))
@@ -138,6 +145,10 @@ def test_TUMLossTurbine_regression():
138145
wind_speed = 10.0
139146
turbine_data = SampleInputs().turbine
140147
turbine_data["power_thrust_table"] = SampleInputs().tum_loss_turbine_power_thrust_table
148+
data_file_path = Path(__file__).resolve().parents[1] / "floris" / "turbine_library"
149+
turbine_data["power_thrust_table"]["cp_ct_data"] = np.load(
150+
data_file_path / turbine_data["power_thrust_table"]["cp_ct_data_file"]
151+
)
141152

142153
N_test = 20
143154
tilt_angles_nom = turbine_data["power_thrust_table"]["ref_tilt"] * np.ones((N_test, n_turbines))
@@ -262,6 +273,10 @@ def test_TUMLossTurbine_integration():
262273
n_turbines = 1
263274
turbine_data = SampleInputs().turbine
264275
turbine_data["power_thrust_table"] = SampleInputs().tum_loss_turbine_power_thrust_table
276+
data_file_path = Path(__file__).resolve().parents[1] / "floris" / "turbine_library"
277+
turbine_data["power_thrust_table"]["cp_ct_data"] = np.load(
278+
data_file_path / turbine_data["power_thrust_table"]["cp_ct_data_file"]
279+
)
265280

266281
N_test = 20
267282
tilt_angles_nom = turbine_data["power_thrust_table"]["ref_tilt"] * np.ones((N_test, n_turbines))

0 commit comments

Comments
 (0)