foxes.core.rotor_model¶
Classes¶
Abstract base class of rotor models. |
Module Contents¶
-
class foxes.core.rotor_model.RotorModel(calc_vars: list[str] | None =
None)[source]¶ Bases:
foxes.core.farm_data_model.FarmDataModelAbstract base class of rotor models.
Rotor models calculate ambient farm data from states, and provide rotor points and weights for the calculation of rotor effective quantities.
- Parameters:¶
- calc_vars
The variables calculated by the model. Their ambients are added automatically.
-
calculate(algo: foxes.core.algorithm.Algorithm, mdata: foxes.core.data.MData, fdata: foxes.core.data.FData, rpoints: numpy.ndarray | None =
None, rpoint_weights: numpy.ndarray | None =None, store: bool =False, downwind_index: int | None =None) dict[str, numpy.ndarray][source]¶ Calculate ambient rotor-effective results.
- Parameters:¶
- algo
The calculation algorithm.
- mdata
The model data.
- fdata
The farm data.
- rpoints
The rotor points, or
Nonefor automatic selection for this rotor. Shape is(n_states, n_turbines, n_rpoints, 3).- rpoint_weights
The rotor-point weights, or
Nonefor automatic selection for this rotor. Shape is(n_rpoints,).- store
Flag for storing ambient rotor-point results.
- downwind_index
Only compute for the selected index in the downwind order.
- Returns:¶
- results
A dictionary of results keyed by variable name. Values are NumPy arrays with shape
(n_states, n_turbines).
- abstract design_points() numpy.ndarray[source]¶
Return the rotor-model design points.
Design points are formulated in rotor-plane
(x, y, z)coordinates in the rotor frame, such that(0, 0, 0)is the center point,(1, 0, 0)is the point radius timesn_rotor_axis,(0, 1, 0)is the point radius timesn_rotor_side, and(0, 0, 1)is the point radius timesn_rotor_up.- Returns:¶
- dpoints
The design points with shape
(n_points, 3).
-
ensure_output_vars(algo: foxes.core.algorithm.Algorithm, fdata: foxes.core.data.FData, defaults: dict[str, Any] | None =
None) None¶ Ensure the output variables are present in the farm data.
- Parameters:¶
- algo
The calculation algorithm.
- fdata
The farm data.
- defaults
Default values for the output variables. Keys are variable names, values are scalars or array-like data with shape
(n_states, n_turbines).
-
eval_rpoint_results(algo: foxes.core.algorithm.Algorithm, mdata: foxes.core.data.MData, fdata: foxes.core.data.FData, tdata: foxes.core.data.TData, rpoint_weights: numpy.ndarray, downwind_index: int | None =
None, copy_to_ambient: bool =False, set_wd: bool =False) None[source]¶ Evaluate rotor-point results.
This function modifies
fdatafor either all turbines or one turbine per state, depending on thestates_turbinesetting. In the latter case, the turbine dimension of the rotor-point results is expected to have size one.- Parameters:¶
- algo
The calculation algorithm.
- mdata
The model data.
- fdata
The farm data.
- tdata
The target-point data.
- rpoint_weights
The rotor-point weights with shape
(n_rpoints,).- downwind_index
The index in the downwind order.
- copy_to_ambient
If
True, thefdataresults are copied to ambient variables after calculation.- set_wd
If
True, the wind direction is updated.
-
finalize(algo: foxes.core.algorithm.Algorithm, verbosity: int =
0) None¶ Finalize the model.
- Parameters:¶
- algo
The calculation algorithm.
- verbosity
The verbosity level;
0is silent.
-
get_data(variable: str, target: str, lookup: str =
'smfp', mdata: foxes.core.data.MData | None =None, fdata: foxes.core.data.FData | None =None, tdata: foxes.core.data.TData | None =None, downwind_index: int | None =None, accept_none: False =False, accept_nan: bool =True, algo: foxes.core.algorithm.Algorithm | None =None, upcast: bool =False, selection: numpy.ndarray[Any, Any] | tuple[Any, ...] | list[Any] | None =None) numpy.ndarray[Any, Any]¶ -
get_data(variable: str, target: str, lookup: str =
'smfp', mdata: foxes.core.data.MData | None =None, fdata: foxes.core.data.FData | None =None, tdata: foxes.core.data.TData | None =None, downwind_index: int | None =None, accept_none: True =True, accept_nan: bool =True, algo: foxes.core.algorithm.Algorithm | None =None, upcast: bool =False, selection: numpy.ndarray[Any, Any] | tuple[Any, ...] | list[Any] | None =None) numpy.ndarray[Any, Any] | None Getter for a data entry in the model object or provided data sources
- Parameters:¶
- variable
The variable name used as the data key.
- target
The dimensions identifier for the output:
FC.STATE_TURBINE,FC.STATE_TARGET, orFC.STATE_TARGET_TPOINT.- lookup
The order of data sources. Combination of:
's'for self,'m'for mdata,'f'for fdata,'t'for tdata, and'w'for wake-modeling data.- mdata
The model data.
- fdata
The farm data.
- tdata
The target point data.
- downwind_index
The index in the downwind order.
- accept_none
Do not raise an error if the data entry is
None.- accept_nan
Do not raise an error if the data entry is
np.nan.- algo
The algorithm, needed for data from previous iterations.
- upcast
Ensure the target dimensions are present. If expansion is needed, the result is a read-only broadcasted view.
- selection
Apply this selection to the result, for state-turbine, state-target, or state-target-tpoint outputs.
- get_rotor_points(algo: foxes.core.algorithm.Algorithm, mdata: foxes.core.data.MData, fdata: foxes.core.data.FData) numpy.ndarray[source]¶
Calculate rotor points from design points.
-
initialize(algo: foxes.core.algorithm.Algorithm, loaded_data: LoadedData | None =
None, force: bool =False, verbosity: int =0) LoadedData¶ Initialize the model.
- Parameters:¶
- algo
The calculation algorithm.
- loaded_data
Data that has already been loaded, to be extended by this function. Keys are “coords”, a dict with entries
dim_name_str -> dim_array; “data_vars”, a dict with entriesname_str -> (dim_tuple, data_ndarray); and “extra_data”, a dict with non-array additional data.- force
Overwrite existing data.
- verbosity
The verbosity level, where 0 is silent.
- Returns:¶
- loaded_data
The loaded data, containing the keys “coords”, “data_vars”, and “extra_data”.
- abstract input_variables() list[str][source]¶
Return the input variables required by the model.
- Returns:¶
- input_vars
The input variable names.
- load_chunk_data(algo: foxes.core.algorithm.Algorithm, *data: foxes.core.data.Data) None¶
Load chunk data according to the configured load mode.
This function adds data to the model data container.
- Parameters:¶
- algo
The calculation algorithm.
- data
Input data, typically either
(mdata, fdata)for farm calculations or(mdata, fdata, tdata)for point data calculations.
-
load_data(algo: foxes.core.algorithm.Algorithm, loaded_data: LoadedData, force: bool =
False, verbosity: int =0) None¶ Load and/or create all data required for model calculations.
The function adds to loaded_data.
- Parameters:¶
- algo
The calculation algorithm.
- loaded_data
Data that has already been loaded, to be extended by this function. Keys are “coords”, a dict with entries
dim_name_str -> dim_array; “data_vars”, a dict with entriesname_str -> (dim_tuple, data_ndarray); and “extra_data”, a dict with non-array additional data.- force
Overwrite existing data.
- verbosity
The verbosity level, where 0 is silent.
- abstract n_rotor_points() int[source]¶
Return the number of rotor points.
- Returns:¶
- n_rpoints
The number of rotor points.
- classmethod new(rmodel_type: str, *args: Any, **kwargs: Any) RotorModel[source]¶
Run-time rotor model factory.
- Parameters:¶
- rmodel_type
The selected derived class name
- args
Additional parameters for constructor
- kwargs
Additional parameters for constructor
- output_coords() tuple[str, ...]¶
Gets the coordinates of all output arrays
- Returns:¶
- dims
The coordinates of all output arrays
- output_farm_vars(algo: foxes.core.algorithm.Algorithm) list[str][source]¶
Return the variables modified by the model.
- abstract rotor_point_weights() numpy.ndarray[source]¶
Return the weights of the rotor points.
- Returns:¶
- weights
The rotor-point weights, which sum to one and have shape
(n_rpoints,).
- run_calculation(algo: foxes.core.algorithm.Algorithm, *data: tuple[Any, ...], out_vars: list[str], **calc_pars: Any) Any¶
Starts the model calculation in parallel, via xarray’s apply_ufunc.
Typically this function is called by algorithms.
-
set_running(algo: foxes.core.algorithm.Algorithm, data_stash: dict[str, dict[str, Any]] | None, sel: dict[str, Any] | None =
None, isel: dict[str, Any] | None =None, verbosity: int =0) None¶ Set this model to the running state and move large data to the stash.
The stashed data is restored by
unset_runningafter the calculation has finished.- Parameters:¶
- algo
The calculation algorithm.
- data_stash
The large-data stash. This function adds entries here when provided. Keys are model names and values are dictionaries of large model data.
- sel
The subset selection dictionary.
- isel
The index subset selection dictionary.
- verbosity
The verbosity level;
0is silent.
-
unset_running(algo: foxes.core.algorithm.Algorithm, data_stash: dict[str, dict[str, Any]] | None, sel: dict[str, Any] | None =
None, isel: dict[str, Any] | None =None, verbosity: int =0) None¶ Set this model status to not running and recover large data from stash.
- Parameters:¶
- algo
The calculation algorithm.
- data_stash
Reconstruct model data from this stash when provided. Keys are model names and values are dictionaries of large model data.
- sel
The subset selection dictionary.
- isel
The index subset selection dictionary.
- verbosity
The verbosity level;
0is silent.
-
calc_vars =
None¶
- property initialized : bool¶
Initialization flag.
- Returns:¶
- initialized
True if the model has been initialized.
-
load_mode =
'preload'¶
- property model_id : int¶
Unique id based on the model type.
- Returns:¶
- int
Unique id of the model object
-
name =
'Model'¶