@@ -10,8 +10,7 @@ author: Benjamin Varela
1010build_wind_farm_struct(x,turbine_x,turbine_y,turbine_z,hub_height,turbine_yaw,rotor_diameter,
1111 ct_models,generator_efficiency,cut_in_speed,cut_out_speed,rated_speed,rated_power,wind_resource,
1212 power_models,model_set,update_function;rotor_sample_points_y=[0.0],rotor_sample_points_z=[0.0],
13- AEP_scale=0.0,input_type=nothing,opt_x=false,opt_y=false,opt_hub=false,opt_yaw=false,opt_diam=false,
14- force_single_thread=false)
13+ AEP_scale=0.0,input_type=nothing,opt_x=false,opt_y=false,opt_hub=false,opt_yaw=false,opt_diam=false)
1514
1615function to build a wind_farm_struct
1716
@@ -42,17 +41,13 @@ function to build a wind_farm_struct
4241- `opt_hub`: Boolean to optimize hub heights of turbines
4342- `opt_yaw`: Boolean to optimize yaw angles of turbines
4443- `opt_diam`: Boolean to optimize rotor diameters of turbines
45- - `force_single_thread`: Boolean to force single thread calculation
4644"""
4745function build_wind_farm_struct (x,turbine_x,turbine_y,turbine_z,hub_height,turbine_yaw,rotor_diameter,
4846 ct_models,generator_efficiency,cut_in_speed,cut_out_speed,rated_speed,rated_power,wind_resource,
4947 power_models,model_set,update_function;rotor_sample_points_y= [0.0 ],rotor_sample_points_z= [0.0 ],
50- AEP_scale= 0.0 ,input_type= nothing ,opt_x= false ,opt_y= false ,opt_hub= false ,opt_yaw= false ,opt_diam= false ,
51- force_single_thread= false )
48+ AEP_scale= 0.0 ,input_type= nothing ,opt_x= false ,opt_y= false ,opt_hub= false ,opt_yaw= false ,opt_diam= false )
5249
5350 n_turbines = length (turbine_x)
54- n_threads = Threads. nthreads ()
55- force_single_thread && (n_threads = 1 )
5651 results = DiffResults. GradientResult (x)
5752 AEP_gradient = zeros (eltype (x),length (x))
5853 AEP = Array {eltype(x),0} (undef)
@@ -65,6 +60,7 @@ function build_wind_farm_struct(x,turbine_x,turbine_y,turbine_z,hub_height,turbi
6560 cut_out_speed, rated_speed, rated_power, wind_resource, power_models, model_set;
6661 rotor_sample_points_y= rotor_sample_points_y, rotor_sample_points_z= rotor_sample_points_z)
6762
63+ ideal_AEP == 0.0 && (ideal_AEP = 1.0 )
6864 (AEP_scale == 0.0 ) && (AEP_scale = 1.0 / ideal_AEP)
6965
7066 cfg = nothing
@@ -86,13 +82,40 @@ function build_wind_farm_struct(x,turbine_x,turbine_y,turbine_z,hub_height,turbi
8682 opt_yaw && (turbine_yaw = Vector {input_type} (turbine_yaw))
8783 opt_diam && (rotor_diameter = Vector {input_type} (rotor_diameter))
8884
89- preallocations = preallocations_struct (zeros (input_type,n_turbines,n_threads),zeros (input_type,n_turbines,n_threads),
90- zeros (input_type,n_turbines,n_threads),zeros (input_type,n_turbines,n_threads),zeros (input_type,n_turbines,
91- n_turbines,n_threads),zeros (input_type,n_turbines,n_turbines,n_threads),
92- zeros (input_type,n_turbines,n_turbines,n_threads),zeros (input_type,n_turbines,n_turbines,n_threads))
85+ preallocations = create_preallocations (turbine_x, turbine_y, turbine_yaw, rotor_diameter, hub_height, wind_farm_constants. wind_resource, wind_farm_constants. model_set)
9386
9487 return wind_farm_struct (turbine_x, turbine_y, hub_height, turbine_yaw, rotor_diameter, results,
95- wind_farm_constants, AEP_scale, ideal_AEP, preallocations, update_function, AEP_gradient, AEP, cfg, force_single_thread)
88+ wind_farm_constants, AEP_scale, ideal_AEP, preallocations, update_function, AEP_gradient, AEP, cfg)
89+ end
90+
91+ function create_preallocations (turbine_x, turbine_y, turbine_yaw, rotor_diameter, hub_height, wind_resource, model_set)
92+ n_turbines = length (turbine_x)
93+ n_threads = Threads. nthreads ()
94+ n_states = determine_number_of_states (wind_resource, model_set)
95+ T = promote_type (eltype (turbine_x),eltype (turbine_y),eltype (turbine_yaw),eltype (rotor_diameter),eltype (hub_height))
96+ return preallocations_struct (zeros (T,n_turbines,n_threads),zeros (T,n_turbines,n_threads),
97+ zeros (T,n_turbines,n_threads),zeros (T,n_turbines,n_threads),zeros (T,n_turbines,
98+ n_turbines,n_threads),zeros (T,n_turbines,n_turbines,n_threads),
99+ zeros (T,n_turbines,n_turbines,n_threads),zeros (T,n_turbines,n_turbines,n_threads),
100+ zeros (T,n_turbines,n_threads),zeros (T,n_turbines,n_threads),
101+ zeros (T,n_turbines,n_threads),
102+ zeros (Int,n_turbines,n_threads),
103+ zeros (T,n_turbines,n_threads),
104+ zeros (T,n_turbines,n_threads),
105+ zeros (T,n_turbines,n_threads),
106+ zeros (T,n_states))
107+ end
108+
109+ function determine_number_of_states (wind_resource, model_set)
110+ if typeof (model_set. wake_combination_model) == SumOfSquaresFreestreamSuperposition
111+ # find unique directions
112+ unique_directions = unique (wind_resource. wind_directions)
113+
114+ # find how many unique directions there are
115+ return length (unique_directions)
116+ else
117+ return length (wind_resource. wind_directions)
118+ end
96119end
97120
98121"""
@@ -171,6 +194,21 @@ function calculate_aep!(farm,x)
171194- `farm`: The wind_farm_struct
172195- `x`: Vector containing the design variables
173196"""
197+ function calculate_aep! (farm,x:: Array{ForwardDiff.Dual{T,V,N}} ) where {T,V,N}
198+ farm. update_function (farm,x)
199+
200+ AEP = calculate_aep (farm. turbine_x, farm. turbine_y, farm. constants. turbine_z, farm. rotor_diameter,
201+ farm. hub_height, farm. turbine_yaw, farm. constants. ct_models, farm. constants. generator_efficiency,
202+ farm. constants. cut_in_speed, farm. constants. cut_out_speed, farm. constants. rated_speed,
203+ farm. constants. rated_power, farm. constants. wind_resource, farm. constants. power_models,
204+ farm. constants. model_set,rotor_sample_points_y= farm. constants. rotor_sample_points_y,
205+ rotor_sample_points_z= farm. constants. rotor_sample_points_z,
206+ preallocations = farm. preallocations
207+ ) .* farm. AEP_scale
208+
209+ return AEP
210+ end
211+
174212function calculate_aep! (farm,x)
175213 farm. update_function (farm,x)
176214
@@ -180,17 +218,11 @@ function calculate_aep!(farm,x)
180218 farm. constants. rated_power, farm. constants. wind_resource, farm. constants. power_models,
181219 farm. constants. model_set,rotor_sample_points_y= farm. constants. rotor_sample_points_y,
182220 rotor_sample_points_z= farm. constants. rotor_sample_points_z,
183- prealloc_turbine_velocities= farm. preallocations. prealloc_turbine_velocities,
184- prealloc_turbine_ct= farm. preallocations. prealloc_turbine_ct,
185- prealloc_turbine_ai= farm. preallocations. prealloc_turbine_ai,
186- prealloc_turbine_local_ti= farm. preallocations. prealloc_turbine_local_ti,
187- prealloc_wake_deficits= farm. preallocations. prealloc_wake_deficits,
188- prealloc_contribution_matrix= farm. preallocations. prealloc_contribution_matrix,
189- prealloc_deflections= farm. preallocations. prealloc_deflections,
190- prealloc_sigma_squared= farm. preallocations. prealloc_sigma_squared,
191- force_single_thread= farm. force_single_thread
221+ preallocations = farm. preallocations
192222 ) .* farm. AEP_scale
193223
224+ farm. AEP[1 ] = AEP
225+
194226 return AEP
195227end
196228
@@ -211,20 +243,6 @@ function calculate_aep_gradient!(farm,x)
211243 return farm. AEP[1 ], farm. AEP_gradient
212244end
213245
214- """
215- calculate_aep_gradient!(farm,x,sparse_struct::T)
216-
217- function to calculate the AEP and its gradient for the wind farm using sparse methods
218-
219- # Arguments
220- - `farm`: The wind_farm_struct
221- - `x`: Vector containing the design variables
222- """
223- function calculate_aep_gradient! (farm,x,sparse_struct:: T ) where T <: AbstractSparseMethod
224- calculate_aep_gradient! (farm,x,sparse_struct)
225- return farm. AEP[1 ], farm. AEP_gradient
226- end
227-
228246"""
229247calculate_spacing!(spacing_vec,x,spacing_struct)
230248
0 commit comments