source: palm/trunk/SOURCE/wind_turbine_model_mod.f90 @ 1914

Last change on this file since 1914 was 1914, checked in by witha, 8 years ago

Merged branch/forwind into trunk

  • Property svn:keywords set to Id
File size: 106.0 KB
RevLine 
[1820]1!> @file wind_turbine_model_mod.f90
[1912]2!------------------------------------------------------------------------------!
[1819]3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
[1912]17!------------------------------------------------------------------------------!
[1819]18!
19! Current revisions:
20! -----------------
[1913]21!
22!
23! Former revisions:
24! -----------------
25! $Id: wind_turbine_model_mod.f90 1914 2016-05-26 14:44:07Z witha $
26!
27! 1912 2016-05-26 13:03:07Z witha
[1912]28! Added subroutine wtm_check_parameters
29! Renamed wtm_read_tables to wtm_read_blade_tables
30! Review of Pitch and Speed Control
31!
[1865]32! 1864 2016-04-14 17:23:11Z witha
[1864]33! Definition of PRIVATE and PUBLIC variables and functions
34! Relocation of some variables from module to the subroutines
35! Added subroutines wtm_speed_control and wtm_init_speed_control
36! Airfoil tables are now read from the input folder
37!
[1844]38! 1843 2016-04-08 08:20:19Z witha
39! Bugfix and revision in reading mechanism
40!
[1840]41! 1839 2016-04-07 18:48:14Z witha
42! Added subroutine for parin, renamed subroutines, witha
43! Added subroutine wtm_read_tables, changes on parin, lvo
44!
[1821]45! 1820 2016-04-06 21:08:26Z witha
46! Initial revision
47!
[1819]48!
49! Description:
50! ------------
51!> This module calculates the effect of wind turbines on the flow fields. The
52!> initial version contains only the advanced actuator disk with rotation method
53!> (ADM-R).
54!> The wind turbines include the tower effect, can be yawed and tilted.
55!> The wind turbine model includes controllers for rotational speed, pitch and
56!> yaw.
57!> Currently some specifications of the NREL 5 MW reference turbine
58!> are hardcoded whereas most input data comes from separate files (currently
59!> external, planned to be included as namelist which will be read in
60!> automatically).
61!>
62!> @todo Revise code according to PALM Coding Standard
63!> @todo Implement ADM and ALM turbine models
64!> @todo Generate header information
65!> @todo Implement parameter checks and error messages
66!> @todo Revise and add code documentation
67!> @todo Output turbine parameters as timeseries
68!> @todo Include additional output variables
[1864]69!> @todo Revise smearing the forces for turbines in yaw
70!> @todo Revise nacelle and tower parameterization
71!> @todo Allow different turbine types in one simulation
[1819]72!
73!------------------------------------------------------------------------------!
74 MODULE wind_turbine_model_mod
75
76    USE arrays_3d,                                                             &
77        ONLY:  dd2zu, tend, u, v, w, zu, zw
78
79    USE constants
80
81    USE control_parameters,                                                    &
82        ONLY:  dt_3d, dz, message_string, simulated_time
83
84    USE cpulog,                                                                &
85        ONLY:  cpu_log, log_point_s
86
87    USE grid_variables,                                                        &
88        ONLY:  ddx, dx, ddy, dy
89
90    USE indices,                                                               &
91        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz,   &
92               nzb, nzb_u_inner, nzb_v_inner, nzb_w_inner, nzt
93
94    USE kinds
95
96    USE pegrid
97
98
99    IMPLICIT NONE
100
[1864]101    PRIVATE
[1819]102
[1839]103    LOGICAL ::  wind_turbine=.FALSE.   !< switch for use of wind turbine model
[1819]104
105!
106!-- Variables specified in the namelist wind_turbine_par
107
[1864]108    INTEGER(iwp) ::  nairfoils = 8   !< number of airfoils of the used turbine model (for ADM-R and ALM)
[1839]109    INTEGER(iwp) ::  nturbines = 1   !< number of turbines
[1819]110
[1839]111    LOGICAL ::  pitch_control = .FALSE.   !< switch for use of pitch controller
112    LOGICAL ::  speed_control = .FALSE.   !< switch for use of speed controller
113    LOGICAL ::  yaw_control   = .FALSE.   !< switch for use of yaw controller
[1819]114
[1839]115    REAL(wp) ::  segment_length  = 1.0_wp          !< length of the segments, the rotor area is divided into
116                                                   !< (in tangential direction, as factor of MIN(dx,dy,dz))
117    REAL(wp) ::  segment_width   = 0.5_wp          !< width of the segments, the rotor area is divided into
118                                                   !< (in radial direction, as factor of MIN(dx,dy,dz))
119    REAL(wp) ::  time_turbine_on = 0.0_wp          !< time at which turbines are started
120    REAL(wp) ::  tilt            = 0.0_wp          !< vertical tilt of the rotor [degree] ( positive = backwards )
[1819]121
[1912]122    REAL(wp), DIMENSION(1:100) ::  dtow             = 0.0_wp  !< tower diameter [m]
123    REAL(wp), DIMENSION(1:100) ::  omega_rot        = 0.0_wp  !< inital or constant rotor speed [rad/s]
124    REAL(wp), DIMENSION(1:100) ::  phi_yaw          = 0.0_wp  !< yaw angle [degree] ( clockwise, 0 = facing west )
125    REAL(wp), DIMENSION(1:100) ::  pitch_add        = 0.0_wp  !< constant pitch angle
126    REAL(wp), DIMENSION(1:100) ::  rcx        = 9999999.9_wp  !< position of hub in x-direction
127    REAL(wp), DIMENSION(1:100) ::  rcy        = 9999999.9_wp  !< position of hub in y-direction
128    REAL(wp), DIMENSION(1:100) ::  rcz        = 9999999.9_wp  !< position of hub in z-direction
129    REAL(wp), DIMENSION(1:100) ::  rnac             = 0.0_wp  !< nacelle diameter [m]
130    REAL(wp), DIMENSION(1:100) ::  rr              = 63.0_wp  !< rotor radius [m]
131    REAL(wp), DIMENSION(1:100) ::  turb_cd_nacelle = 0.85_wp  !< drag coefficient for nacelle
132    REAL(wp), DIMENSION(1:100) ::  turb_cd_tower    = 1.2_wp  !< drag coefficient for tower
[1839]133
[1819]134!
135!-- Variables specified in the namelist for speed controller
136!-- Default values are from the NREL 5MW research turbine (Jonkman, 2008)
137
[1912]138    REAL(wp) ::  rated_power    = 5296610.0_wp    !< rated turbine power [W]
[1839]139    REAL(wp) ::  gear_ratio     = 97.0_wp         !< Gear ratio from rotor to generator
140    REAL(wp) ::  inertia_rot    = 34784179.0_wp   !< Inertia of the rotor [kg/m2]
141    REAL(wp) ::  inertia_gen    = 534.116_wp      !< Inertia of the generator [kg/m2]
142    REAL(wp) ::  gen_eff        = 0.944_wp        !< Electric efficiency of the generator
143    REAL(wp) ::  gear_eff       = 1.0_wp          !< Loss between rotor and generator
144    REAL(wp) ::  air_dens       = 1.225_wp        !< Air density to convert to W [kg/m3]
145    REAL(wp) ::  rated_genspeed = 121.6805_wp     !< Rated generator speed [rad/s]
[1912]146    REAL(wp) ::  max_torque_gen = 47402.91_wp     !< Maximum of the generator torque [Nm]
[1839]147    REAL(wp) ::  slope2         = 2.332287_wp     !< Slope constant for region 2
148    REAL(wp) ::  min_reg2       = 91.21091_wp     !< Lower generator speed boundary of region 2 [rad/s]
149    REAL(wp) ::  min_reg15      = 70.16224_wp     !< Lower generator speed boundary of region 1.5 [rad/s]
[1912]150    REAL(wp) ::  max_trq_rate   = 15000.0_wp      !< Max generator torque increase [Nm/s]
151    REAL(wp) ::  pitch_rate     = 8.0_wp          !< Max pitch rate [degree/s]
[1839]152
[1912]153
[1819]154!
155!-- Variables specified in the namelist for yaw control
156
[1839]157    REAL(wp) ::  yaw_speed = 0.005236_wp   !< speed of the yaw actuator [rad/s]
158    REAL(wp) ::  max_miss = 0.08726_wp     !< maximum tolerated yaw missalignment [rad]
159    REAL(wp) ::  min_miss = 0.008726_wp    !< minimum yaw missalignment for which the actuator stops [rad]
160
[1819]161!
162!-- Set flag for output files TURBINE_PARAMETERS
163    TYPE file_status
164       LOGICAL ::  opened, opened_before
165    END TYPE file_status
166   
[1912]167    TYPE(file_status), DIMENSION(500) :: openfile_turb_mod =                   &
168                                         file_status(.FALSE.,.FALSE.)
[1819]169
170!
171!-- Variables for initialization of the turbine model
172
[1839]173    INTEGER(iwp) ::  inot         !< turbine loop index (turbine id)
174    INTEGER(iwp) ::  nsegs_max    !< maximum number of segments (all turbines, required for allocation of arrays)
175    INTEGER(iwp) ::  nrings_max   !< maximum number of rings (all turbines, required for allocation of arrays)
176    INTEGER(iwp) ::  ring         !< ring loop index (ring number)
177    INTEGER(iwp) ::  rr_int       !<
178    INTEGER(iwp) ::  upper_end    !<
[1819]179
[1839]180    INTEGER(iwp), DIMENSION(1) ::  lct   !<
[1819]181
[1912]182    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  i_hub     !< index belonging to x-position of the turbine
183    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  i_smear   !< index defining the area for the smearing of the forces (x-direction)
184    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  j_hub     !< index belonging to y-position of the turbine
185    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  j_smear   !< index defining the area for the smearing of the forces (y-direction)
186    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_hub     !< index belonging to hub height
187    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_smear   !< index defining the area for the smearing of the forces (z-direction)
188    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  nrings    !< number of rings per turbine
189    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  nsegs_total !< total number of segments per turbine
[1819]190
[1912]191    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nsegs   !< number of segments per ring and turbine
[1819]192
[1912]193!
194!-  parameters for the smearing from the rotor to the cartesian grid   
[1864]195    REAL(wp) ::  pol_a            !< parameter for the polynomial smearing fct
196    REAL(wp) ::  pol_b            !< parameter for the polynomial smearing fct
[1912]197    REAL(wp) ::  delta_t_factor   !<
[1864]198    REAL(wp) ::  eps_factor       !< 
[1839]199    REAL(wp) ::  eps_min          !<
200    REAL(wp) ::  eps_min2         !<
201    REAL(wp) ::  sqrt_arg         !<
[1819]202
[1839]203!
204!-- Variables for the calculation of lift and drag coefficients
[1912]205    REAL(wp), DIMENSION(:), ALLOCATABLE  ::  ard     !<
206    REAL(wp), DIMENSION(:), ALLOCATABLE  ::  crd     !<
207    REAL(wp), DIMENSION(:), ALLOCATABLE  ::  delta_r !< radial segment length
208    REAL(wp), DIMENSION(:), ALLOCATABLE  ::  lrd     !<
[1864]209   
[1912]210    REAL(wp) ::  accu_cl_cd_tab = 0.1_wp  !< Accuracy of the interpolation of
211                                          !< the lift and drag coeff [deg]
[1819]212
[1912]213    REAL(wp), DIMENSION(:,:), ALLOCATABLE :: turb_cd_tab   !< table of the blade drag coefficient
214    REAL(wp), DIMENSION(:,:), ALLOCATABLE :: turb_cl_tab   !< table of the blade lift coefficient
[1819]215
[1912]216    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  nac_cd_surf  !< 3d field of the tower drag coefficient
217    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  tow_cd_surf  !< 3d field of the nacelle drag coefficient
[1819]218
219!
220!-- Variables for the calculation of the forces
[1912]221     
[1839]222    REAL(wp) ::  cur_r                       !<
[1912]223    REAL(wp) ::  delta_t                     !<  tangential segment length
[1839]224    REAL(wp) ::  phi_rotor                   !<
225    REAL(wp) ::  pre_factor                  !< 
226    REAL(wp) ::  torque_seg                  !<
227    REAL(wp) ::  u_int_l                     !<
228    REAL(wp) ::  u_int_u                     !<
229    REAL(wp) ::  u_rot                       !<
230    REAL(wp) ::  v_int_l                     !<
231    REAL(wp) ::  v_int_u                     !<
232    REAL(wp) ::  w_int_l                     !<
233    REAL(wp) ::  w_int_u                     !<
[1912]234!
235!-  Tendencies from the nacelle and tower thrust
236    REAL(wp) ::  tend_nac_x = 0.0_wp  !<
237    REAL(wp) ::  tend_tow_x = 0.0_wp  !<
238    REAL(wp) ::  tend_nac_y = 0.0_wp  !<
239    REAL(wp) ::  tend_tow_y = 0.0_wp  !<
[1819]240
[1912]241    REAL(wp), DIMENSION(:), ALLOCATABLE ::  alpha_attack !<
242    REAL(wp), DIMENSION(:), ALLOCATABLE ::  chord        !<
243    REAL(wp), DIMENSION(:), ALLOCATABLE ::  omega_gen    !< curr. generator speed
244    REAL(wp), DIMENSION(:), ALLOCATABLE ::  phi_rel      !<
245    REAL(wp), DIMENSION(:), ALLOCATABLE ::  pitch_add_old!<
246    REAL(wp), DIMENSION(:), ALLOCATABLE ::  torque_total !<
247    REAL(wp), DIMENSION(:), ALLOCATABLE ::  thrust_rotor !<
248    REAL(wp), DIMENSION(:), ALLOCATABLE ::  turb_cl      !<
249    REAL(wp), DIMENSION(:), ALLOCATABLE ::  turb_cd      !<
250    REAL(wp), DIMENSION(:), ALLOCATABLE ::  vrel         !<
251    REAL(wp), DIMENSION(:), ALLOCATABLE ::  vtheta       !<
252
253    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  rbx, rby, rbz     !< coordinates of the blade elements
254    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  rotx, roty, rotz  !< normal vectors to the rotor coordinates
255
256!
257!-  Fields for the interpolation of velocities on the rotor grid
258    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_int       !<
259    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_int_1_l   !<
260    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_int       !<
261    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_int_1_l   !<
262    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_int       !<
263    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_int_1_l   !<
264   
265!
266!-  rotor tendencies on the segments
267    REAL(wp), DIMENSION(:), ALLOCATABLE :: thrust_seg   !<
268    REAL(wp), DIMENSION(:), ALLOCATABLE :: torque_seg_y !<
269    REAL(wp), DIMENSION(:), ALLOCATABLE :: torque_seg_z !<   
270
271!
272!-  rotor tendencies on the rings
273    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  thrust_ring       !<
274    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  torque_ring_y     !<
275    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  torque_ring_z     !<
276   
277!
278!-  rotor tendencies on rotor grids for all turbines
279    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  thrust      !<
280    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  torque_y    !<
281    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  torque_z    !<
282
283!
284!-  rotor tendencies on coordinate grid
285    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  rot_tend_x  !<
286    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  rot_tend_y  !<
287    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  rot_tend_z  !<
288!   
289!-  variables for the rotation of the rotor coordinates       
290    REAL(wp), DIMENSION(1:100,1:3,1:3) ::  rot_coord_trans  !< matrix for rotation of rotor coordinates
291   
[1839]292    REAL(wp), DIMENSION(1:3) ::  rot_eigen_rad   !<
293    REAL(wp), DIMENSION(1:3) ::  rot_eigen_azi   !<
294    REAL(wp), DIMENSION(1:3) ::  rot_eigen_nor   !<
295    REAL(wp), DIMENSION(1:3) ::  re              !<
296    REAL(wp), DIMENSION(1:3) ::  rea             !<
297    REAL(wp), DIMENSION(1:3) ::  ren             !<
298    REAL(wp), DIMENSION(1:3) ::  rote            !<
299    REAL(wp), DIMENSION(1:3) ::  rota            !<
300    REAL(wp), DIMENSION(1:3) ::  rotn            !<
[1819]301
[1839]302!
303!-- Fixed variables for the speed controller
[1819]304
[1912]305    LOGICAL  ::  start_up = .TRUE.   !<
[1864]306   
[1912]307    REAL(wp) ::  Fcorner             !< corner freq for the controller low pass filter
308    REAL(wp) ::  min_reg25           !< min region 2.5
309    REAL(wp) ::  om_rate             !< rotor speed change
310    REAL(wp) ::  slope15             !< slope in region 1.5
311    REAL(wp) ::  slope25             !< slope in region 2.5
312    REAL(wp) ::  trq_rate            !< torque change
313    REAL(wp) ::  vs_sysp             !<
314    REAL(wp) ::  lp_coeff            !< coeff for the controller low pass filter
[1864]315   
316    REAL(wp), DIMENSION(:), ALLOCATABLE :: omega_gen_old   !< last gen. speed
317    REAL(wp), DIMENSION(:), ALLOCATABLE :: omega_gen_f     !< filtered gen. sp
318    REAL(wp), DIMENSION(:), ALLOCATABLE :: omega_gen_f_old !< last filt. gen. sp
319    REAL(wp), DIMENSION(:), ALLOCATABLE :: torque_gen      !< generator torque
320    REAL(wp), DIMENSION(:), ALLOCATABLE :: torque_gen_old  !< last gen. torque
[1819]321
[1864]322    REAL(wp), DIMENSION(100) :: omega_rot_l = 0.0_wp !< local rot speed [rad/s]
[1839]323!
324!-- Fixed variables for the yaw controller
[1819]325
[1912]326    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  yawdir           !< direction to yaw
327    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  phi_yaw_l        !< local (cpu) yaw angle
328    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  wd30_l           !< local (cpu) long running avg of the wd
329    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  wd2_l            !< local (cpu) short running avg of the wd
330    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  wdir             !< wind direction at hub
331    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  u_inflow         !< wind speed at hub
332    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  wdir_l           !<
333    REAL(wp), DIMENSION(:)  , ALLOCATABLE ::  u_inflow_l       !<
334    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  wd30             !<
335    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  wd2              !<
336    LOGICAL,  DIMENSION(1:100)            ::  doyaw = .FALSE.  !<
337    INTEGER(iwp)                          ::  WDLON            !<
338    INTEGER(iwp)                          ::  WDSHO            !<
[1819]339
340
[1839]341    SAVE
[1819]342
[1839]343
344    INTERFACE wtm_parin
345       MODULE PROCEDURE wtm_parin
346    END INTERFACE wtm_parin
[1912]347   
348    INTERFACE wtm_check_parameters
349       MODULE PROCEDURE wtm_check_parameters
350    END INTERFACE wtm_check_parameters
[1839]351       
352    INTERFACE wtm_init_arrays
353       MODULE PROCEDURE wtm_init_arrays
354    END INTERFACE wtm_init_arrays
355
356    INTERFACE wtm_init
357       MODULE PROCEDURE wtm_init
358    END INTERFACE wtm_init
359   
[1912]360    INTERFACE wtm_read_blade_tables
361       MODULE PROCEDURE wtm_read_blade_tables
362    END INTERFACE wtm_read_blade_tables
[1839]363           
[1819]364    INTERFACE wtm_forces
365       MODULE PROCEDURE wtm_forces
[1839]366       MODULE PROCEDURE wtm_yawcontrol
[1819]367    END INTERFACE wtm_forces
[1864]368   
369    INTERFACE wtm_rotate_rotor
370       MODULE PROCEDURE wtm_rotate_rotor
371    END INTERFACE wtm_rotate_rotor
372   
373    INTERFACE wtm_speed_control
374       MODULE PROCEDURE wtm_init_speed_control
375       MODULE PROCEDURE wtm_speed_control
376    END INTERFACE wtm_speed_control
[1819]377
378    INTERFACE wtm_tendencies
379       MODULE PROCEDURE wtm_tendencies
380       MODULE PROCEDURE wtm_tendencies_ij
381    END INTERFACE wtm_tendencies
[1864]382   
383   
[1912]384    PUBLIC wtm_check_parameters, wtm_forces, wtm_init, wtm_init_arrays,        &
385           wtm_parin, wtm_tendencies, wtm_tendencies_ij, wind_turbine 
[1819]386
387 CONTAINS
388
389
390!------------------------------------------------------------------------------!
391! Description:
392! ------------
[1839]393!> Parin for &wind_turbine_par for wind turbine model
[1819]394!------------------------------------------------------------------------------!
[1839]395    SUBROUTINE wtm_parin
[1819]396
397
398       IMPLICIT NONE
[1912]399       
400       INTEGER(iwp) ::  ierrn       !<
[1819]401
[1839]402       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
403
404       NAMELIST /wind_turbine_par/   air_dens, dtow, gear_eff, gear_ratio,     &
[1864]405                                  gen_eff, inertia_gen, inertia_rot, max_miss, &
[1839]406                                  max_torque_gen, max_trq_rate, min_miss,      &
[1864]407                                  min_reg15, min_reg2, nairfoils, nturbines,   &
[1912]408                                  omega_rot, phi_yaw, pitch_add, pitch_control,&
[1839]409                                  rated_genspeed, rated_power, rcx, rcy, rcz,  &
410                                  rnac, rr, segment_length, segment_width,     &
[1864]411                                  slope2, speed_control, tilt, time_turbine_on,&
[1912]412                                  turb_cd_nacelle, turb_cd_tower,              &
[1839]413                                  yaw_control, yaw_speed
414
[1819]415!
[1839]416!--    Try to find wind turbine model package
417       REWIND ( 11 )
418       line = ' '
419       DO  WHILE ( INDEX( line, '&wind_turbine_par' ) == 0 )
420          READ ( 11, '(A)', END=10 )  line
421       ENDDO
422       BACKSPACE ( 11 )
423
424!
425!--    Read user-defined namelist
[1912]426       READ ( 11, wind_turbine_par, IOSTAT=ierrn )
427       
428       IF ( ierrn < 0 )  THEN
429          message_string = 'errors in \$wind_turbine_par'
430          CALL message( 'wtm_parin', 'PA0???', 1, 2, 0, 6, 0 )
431       ENDIF
432       
[1839]433!
434!--    Set flag that indicates that the wind turbine model is switched on
435       wind_turbine = .TRUE.
436
[1912]437 10    CONTINUE   ! TBD Change from continue, mit ierrn machen
[1839]438
439
440    END SUBROUTINE wtm_parin
441
[1912]442    SUBROUTINE wtm_check_parameters
443
444   
445       IMPLICIT NONE
446   
447       IF ( ( .NOT.speed_control ) .AND. pitch_control )  THEN
448          message_string = 'pitch_control = .TRUE. requires '//                &
449                           'speed_control = .TRUE.'
450          CALL message( 'wtm_check_parameters', 'PA0???', 1, 2, 0, 6, 0 )
451       ENDIF
452       
453       IF ( ANY( omega_rot(1:nturbines) <= 0.0 ) )  THEN
454          message_string = 'omega_rot <= 0.0, Please set omega_rot to '     // &
455                           'a value larger than zero'
456          CALL message( 'wtm_check_parameters', 'PA0???', 1, 2, 0, 6, 0 )
457       ENDIF
458       
459       
460       IF ( ANY( rcx(1:nturbines) == 9999999.9_wp ) .OR.                       &
461            ANY( rcy(1:nturbines) == 9999999.9_wp ) .OR.                       &
462            ANY( rcz(1:nturbines) == 9999999.9_wp ) )  THEN
463         
464          message_string = 'rcx, rcy, rcz '                                 // &
465                           'have to be given for each turbine.'         
466          CALL message( 'wtm_check_parameters', 'PA0???', 1, 2, 0, 6, 0 )         
467         
468       ENDIF
469
470 
471    END SUBROUTINE wtm_check_parameters 
472   
473                                       
[1839]474!------------------------------------------------------------------------------!
475! Description:
476! ------------
477!> Allocate wind turbine model arrays
478!------------------------------------------------------------------------------!
479    SUBROUTINE wtm_init_arrays
480
481
482       IMPLICIT NONE
483
[1864]484       REAL(wp) ::  delta_r_factor   !<
485       REAL(wp) ::  delta_r_init     !<
486
[1839]487!
488!--    To be able to allocate arrays with dimension of rotor rings and segments,
[1819]489!--    the maximum possible numbers of rings and segments have to be calculated:
490
491       ALLOCATE( nrings(1:nturbines) )
492       ALLOCATE( delta_r(1:nturbines) )
493
494       nrings(:)  = 0
495       delta_r(:) = 0.0_wp
496
497!
498!--    Thickness (radial) of each ring and length (tangential) of each segment:
499       delta_r_factor = segment_width
500       delta_t_factor = segment_length
501       delta_r_init   = delta_r_factor * MIN( dx, dy, dz)
502       delta_t        = delta_t_factor * MIN( dx, dy, dz)
503
504       DO inot = 1, nturbines
505!
506!--       Determine number of rings:
507          nrings(inot) = NINT( rr(inot) / delta_r_init )
508
509          delta_r(inot) = rr(inot) / nrings(inot)
510
511       ENDDO
512
513       nrings_max = MAXVAL(nrings)
514
515       ALLOCATE( nsegs(1:nrings_max,1:nturbines) )
516       ALLOCATE( nsegs_total(1:nturbines) )
517
518       nsegs(:,:)     = 0
519       nsegs_total(:) = 0
520
521
522       DO inot = 1, nturbines
523          DO ring = 1, nrings(inot)
524!
525!--          Determine number of segments for each ring:
[1839]526             nsegs(ring,inot) = MAX( 8, CEILING( delta_r_factor * pi *         &
527                                                 ( 2.0_wp * ring - 1.0_wp ) /  &
528                                                 delta_t_factor ) )
[1819]529          ENDDO
530!
531!--       Total sum of all rotor segments:
[1839]532          nsegs_total(inot) = SUM( nsegs(:,inot) )
[1819]533
534       ENDDO
535
536!
537!--    Maximum number of segments per ring:
538       nsegs_max = MAXVAL(nsegs)
539
[1864]540!!
541!!--    TODO: Folgendes im Header ausgeben!
542!       IF ( myid == 0 )  THEN
543!          PRINT*, 'nrings(1) = ', nrings(1)
544!          PRINT*, '--------------------------------------------------'
545!          PRINT*, 'nsegs(:,1) = ', nsegs(:,1)
546!          PRINT*, '--------------------------------------------------'
547!          PRINT*, 'nrings_max = ', nrings_max
548!          PRINT*, 'nsegs_max = ', nsegs_max
549!          PRINT*, 'nsegs_total(1) = ', nsegs_total(1)
550!       ENDIF
[1819]551
552
553!
554!--    Allocate 1D arrays (dimension = number of turbines)
555       ALLOCATE( i_hub(1:nturbines) )
556       ALLOCATE( i_smear(1:nturbines) )
557       ALLOCATE( j_hub(1:nturbines) )
558       ALLOCATE( j_smear(1:nturbines) )
559       ALLOCATE( k_hub(1:nturbines) )
560       ALLOCATE( k_smear(1:nturbines) )
561       ALLOCATE( torque_total(1:nturbines) )
[1912]562       ALLOCATE( thrust_rotor(1:nturbines) )
[1819]563
564!
565!--    Allocation of the 1D arrays for speed pitch_control
566       ALLOCATE( omega_gen(1:nturbines) )
[1864]567       ALLOCATE( omega_gen_old(1:nturbines) )
[1819]568       ALLOCATE( omega_gen_f(1:nturbines) )
569       ALLOCATE( omega_gen_f_old(1:nturbines) )
[1912]570       ALLOCATE( pitch_add_old(1:nturbines) )
[1819]571       ALLOCATE( torque_gen(1:nturbines) )
572       ALLOCATE( torque_gen_old(1:nturbines) )
573
574!
575!--    Allocation of the 1D arrays for yaw control
576       ALLOCATE( yawdir(1:nturbines) )
577       ALLOCATE( u_inflow(1:nturbines) )
578       ALLOCATE( wdir(1:nturbines) )
579       ALLOCATE( u_inflow_l(1:nturbines) )
580       ALLOCATE( wdir_l(1:nturbines) )
581       ALLOCATE( phi_yaw_l(1:nturbines) )
582       
583!
584!--    Allocate 1D arrays (dimension = number of rotor segments)
585       ALLOCATE( alpha_attack(1:nsegs_max) )
586       ALLOCATE( chord(1:nsegs_max) )
587       ALLOCATE( phi_rel(1:nsegs_max) )
588       ALLOCATE( thrust_seg(1:nsegs_max) )
589       ALLOCATE( torque_seg_y(1:nsegs_max) )
590       ALLOCATE( torque_seg_z(1:nsegs_max) )
[1839]591       ALLOCATE( turb_cd(1:nsegs_max) )
592       ALLOCATE( turb_cl(1:nsegs_max) )
[1819]593       ALLOCATE( vrel(1:nsegs_max) )
594       ALLOCATE( vtheta(1:nsegs_max) )
595
596!
597!--    Allocate 2D arrays (dimension = number of rotor rings and segments)
598       ALLOCATE( rbx(1:nrings_max,1:nsegs_max) )
599       ALLOCATE( rby(1:nrings_max,1:nsegs_max) )
600       ALLOCATE( rbz(1:nrings_max,1:nsegs_max) )
601       ALLOCATE( thrust_ring(1:nrings_max,1:nsegs_max) )
602       ALLOCATE( torque_ring_y(1:nrings_max,1:nsegs_max) )
603       ALLOCATE( torque_ring_z(1:nrings_max,1:nsegs_max) )
604
605!
606!--    Allocate additional 2D arrays
607       ALLOCATE( rotx(1:nturbines,1:3) )
608       ALLOCATE( roty(1:nturbines,1:3) )
609       ALLOCATE( rotz(1:nturbines,1:3) )
610
611!
612!--    Allocate 3D arrays (dimension = number of grid points)
[1912]613       ALLOCATE( nac_cd_surf(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
614       ALLOCATE( rot_tend_x(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
615       ALLOCATE( rot_tend_y(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
616       ALLOCATE( rot_tend_z(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1819]617       ALLOCATE( thrust(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
618       ALLOCATE( torque_y(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
619       ALLOCATE( torque_z(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1912]620       ALLOCATE( tow_cd_surf(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1819]621
622!
623!--    Allocate additional 3D arrays
624       ALLOCATE( u_int(1:nturbines,1:nrings_max,1:nsegs_max) )
625       ALLOCATE( u_int_1_l(1:nturbines,1:nrings_max,1:nsegs_max) )
626       ALLOCATE( v_int(1:nturbines,1:nrings_max,1:nsegs_max) )
627       ALLOCATE( v_int_1_l(1:nturbines,1:nrings_max,1:nsegs_max) )
628       ALLOCATE( w_int(1:nturbines,1:nrings_max,1:nsegs_max) )
629       ALLOCATE( w_int_1_l(1:nturbines,1:nrings_max,1:nsegs_max) )
630
631!
632!--    All of the arrays are initialized with a value of zero:
633       i_hub(:)                 = 0
634       i_smear(:)               = 0
635       j_hub(:)                 = 0
636       j_smear(:)               = 0
637       k_hub(:)                 = 0
638       k_smear(:)               = 0
[1912]639       
[1819]640       torque_total(:)          = 0.0_wp
[1912]641       thrust_rotor(:)          = 0.0_wp
[1819]642
643       omega_gen(:)             = 0.0_wp
[1864]644       omega_gen_old(:)         = 0.0_wp
[1819]645       omega_gen_f(:)           = 0.0_wp
646       omega_gen_f_old(:)       = 0.0_wp
[1912]647       pitch_add_old(:)         = 0.0_wp
[1819]648       torque_gen(:)            = 0.0_wp
649       torque_gen_old(:)        = 0.0_wp
650       
651       yawdir(:)                = 0.0_wp
652       wdir(:)                  = 0.0_wp
653       u_inflow(:)              = 0.0_wp
654
655!
656!--    Allocate 1D arrays (dimension = number of rotor segments)
657       alpha_attack(:)          = 0.0_wp
658       chord(:)                 = 0.0_wp
659       phi_rel(:)               = 0.0_wp
660       thrust_seg(:)            = 0.0_wp
661       torque_seg_y(:)          = 0.0_wp
662       torque_seg_z(:)          = 0.0_wp
[1864]663       turb_cd(:)               = 0.0_wp
664       turb_cl(:)               = 0.0_wp
[1819]665       vrel(:)                  = 0.0_wp
666       vtheta(:)                = 0.0_wp
667
668       rbx(:,:)                 = 0.0_wp
669       rby(:,:)                 = 0.0_wp
670       rbz(:,:)                 = 0.0_wp
671       thrust_ring(:,:)         = 0.0_wp
672       torque_ring_y(:,:)       = 0.0_wp
673       torque_ring_z(:,:)       = 0.0_wp
674
675       rotx(:,:)                = 0.0_wp
676       roty(:,:)                = 0.0_wp
677       rotz(:,:)                = 0.0_wp
[1864]678       turb_cl_tab(:,:)         = 0.0_wp
679       turb_cd_tab(:,:)         = 0.0_wp
[1819]680
[1912]681       nac_cd_surf(:,:,:)       = 0.0_wp
682       rot_tend_x(:,:,:)        = 0.0_wp
683       rot_tend_y(:,:,:)        = 0.0_wp
684       rot_tend_z(:,:,:)        = 0.0_wp
[1819]685       thrust(:,:,:)            = 0.0_wp
686       torque_y(:,:,:)          = 0.0_wp
687       torque_z(:,:,:)          = 0.0_wp
[1912]688       tow_cd_surf(:,:,:)       = 0.0_wp
[1819]689
690       u_int(:,:,:)             = 0.0_wp
691       u_int_1_l(:,:,:)         = 0.0_wp
692       v_int(:,:,:)             = 0.0_wp
693       v_int_1_l(:,:,:)         = 0.0_wp
694       w_int(:,:,:)             = 0.0_wp
695       w_int_1_l(:,:,:)         = 0.0_wp
696
697
[1839]698    END SUBROUTINE wtm_init_arrays
[1819]699
700
701!------------------------------------------------------------------------------!
702! Description:
703! ------------
[1839]704!> Initialization of the wind turbine model
[1819]705!------------------------------------------------------------------------------!
[1839]706    SUBROUTINE wtm_init
[1819]707
[1839]708   
[1819]709       IMPLICIT NONE
710
711       INTEGER(iwp) ::  i  !< running index
712       INTEGER(iwp) ::  j  !< running index
713       INTEGER(iwp) ::  k  !< running index
[1864]714       
[1819]715!
[1864]716!--    Help variables for the smearing function       
717       REAL(wp) ::  eps_kernel       !<       
718       
[1839]719!
[1864]720!--    Help variables for calculation of the tower drag       
721       INTEGER(iwp) ::  tower_n      !<
722       INTEGER(iwp) ::  tower_s      !<
[1839]723!
[1864]724!--    Help variables for the calulaction of the nacelle drag
725       INTEGER(iwp) ::  i_ip         !<
726       INTEGER(iwp) ::  i_ipg        !<
727       
728       REAL(wp) ::  yvalue               
729       REAL(wp) ::  dy_int           !<
730       REAL(wp) ::  dz_int           !<
731       
732       REAL(wp), DIMENSION(:,:), ALLOCATABLE :: circle_points  !<
733             
734       INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: index_nacb       !<
735       INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: index_nacl       !<
736       INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: index_nacr       !<
737       INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: index_nact       !<
738       
739       ALLOCATE( index_nacb(1:nturbines) )
740       ALLOCATE( index_nacl(1:nturbines) )
741       ALLOCATE( index_nacr(1:nturbines) )
742       ALLOCATE( index_nact(1:nturbines) )
[1819]743
744
[1864]745       IF ( speed_control)  THEN
746       
747          CALL wtm_speed_control
748
749       ENDIF
750
[1839]751!
[1819]752!------------------------------------------------------------------------------!
[1839]753!--    Calculation of parameters for the regularization kernel
754!--    (smearing of the forces)
[1819]755!------------------------------------------------------------------------------!
756!
[1839]757!--    In the following, some of the required parameters for the smearing will
758!--    be calculated:
[1819]759
[1839]760!--    The kernel is set equal to twice the grid spacing which has turned out to
761!--    be a reasonable value (see e.g. Troldborg et al. (2013), Wind Energy,
[1819]762!--    DOI: 10.1002/we.1608):
763       eps_kernel = 2.0_wp * dx
764!
[1839]765!--    The zero point (eps_min) of the polynomial function must be the following
766!--    if the integral of the polynomial function (for values < eps_min) shall
767!--    be equal to the integral of the Gaussian function used before:
768       eps_min = ( 105.0_wp / 32.0_wp )**( 1.0_wp / 3.0_wp ) *                 &
769                 pi**( 1.0_wp / 6.0_wp ) * eps_kernel
[1819]770!
771!--    Square of eps_min:
772       eps_min2 = eps_min**2
773!
774!--    Parameters in the polynomial function:
[1864]775       pol_a = 1.0_wp / eps_min**4
776       pol_b = 2.0_wp / eps_min**2
[1819]777!
[1839]778!--    Normalization factor which is the inverse of the integral of the smearing
779!--    function:
780       eps_factor = 105.0_wp / ( 32.0_wp * pi * eps_min**3 )
781       
[1864]782!--    Change tilt angle to rad:
783       tilt = tilt * pi / 180.0_wp
784     
[1819]785!
[1864]786!--    Change yaw angle to rad:
787       phi_yaw(:) = phi_yaw(:) * pi / 180.0_wp
[1819]788
[1864]789
[1819]790       DO inot = 1, nturbines
791!
[1864]792!--       Rotate the rotor coordinates in case yaw and tilt are defined
793          CALL wtm_rotate_rotor( inot )
[1819]794         
795!
796!--       Determine the indices of the hub height
797          i_hub(inot) = INT(   rcx(inot)                 / dx )
798          j_hub(inot) = INT( ( rcy(inot) + 0.5_wp * dy ) / dy )
799          k_hub(inot) = INT( ( rcz(inot) + 0.5_wp * dz ) / dz )
800
801!
802!--       Determining the area to which the smearing of the forces is applied.
[1839]803!--       As smearing now is effectively applied only for distances smaller than
804!--       eps_min, the smearing area can be further limited and regarded as a
805!--       function of eps_min:
[1819]806          i_smear(inot) = CEILING( ( rr(inot) + eps_min ) / dx )
807          j_smear(inot) = CEILING( ( rr(inot) + eps_min ) / dy )
808          k_smear(inot) = CEILING( ( rr(inot) + eps_min ) / dz )
[1864]809       
[1819]810       ENDDO
811
812!
813!------------------------------------------------------------------------------!
[1839]814!--    Determine the area within each grid cell that overlaps with the area
815!--    of the nacelle and the tower (needed for calculation of the forces)
[1819]816!------------------------------------------------------------------------------!
817!
818!--    Note: so far this is only a 2D version, in that the mean flow is
819!--    perpendicular to the rotor area.
820
821!
822!--    Allocation of the array containing information on the intersection points
823!--    between rotor disk and the numerical grid:
824       upper_end = ( ny + 1 ) * 10000 
825
826       ALLOCATE( circle_points(1:2,1:upper_end) )
[1839]827       
828       circle_points(:,:) = 0.0_wp
[1819]829
[1839]830       
831       DO inot = 1, nturbines                     ! loop over number of turbines
[1819]832!
[1839]833!--       Determine the grid index (u-grid) that corresponds to the location of
834!--       the rotor center (reduces the amount of calculations in the case that
835!--       the mean flow is perpendicular to the rotor area):
[1819]836          i = i_hub(inot)
837
838!
[1839]839!--       Determine the left and the right edge of the nacelle (corresponding
840!--       grid point indices):
[1819]841          index_nacl(inot) = INT( ( rcy(inot) - rnac(inot) + 0.5_wp * dy ) / dy )
842          index_nacr(inot) = INT( ( rcy(inot) + rnac(inot) + 0.5_wp * dy ) / dy )
843!
[1839]844!--       Determine the bottom and the top edge of the nacelle (corresponding
845!--       grid point indices).The grid point index has to be increased by 1, as
846!--       the first level for the u-component (index 0) is situated below the
847!--       surface. All points between z=0 and z=dz/s would already be contained
848!--       in grid box 1.
[1819]849          index_nacb(inot) = INT( ( rcz(inot) - rnac(inot) ) / dz ) + 1
850          index_nact(inot) = INT( ( rcz(inot) + rnac(inot) ) / dz ) + 1
851
852!
853!--       Determine the indices of the grid boxes containing the left and
[1864]854!--       the right boundaries of the tower:
[1819]855          tower_n = ( rcy(inot) + 0.5_wp * dtow(inot) - 0.5_wp * dy ) / dy
856          tower_s = ( rcy(inot) - 0.5_wp * dtow(inot) - 0.5_wp * dy ) / dy
857
858!
859!--       Determine the fraction of the grid box area overlapping with the tower
[1864]860!--       area and multiply it with the drag of the tower:
[1839]861          IF ( ( nxlg <= i )  .AND.  ( nxrg >= i ) )  THEN
[1819]862
863             DO  j = nys, nyn
864!
[1839]865!--             Loop from south to north boundary of tower
866                IF ( ( j >= tower_s )  .AND.  ( j <= tower_n ) )  THEN
867
[1819]868                   DO  k = nzb, nzt
869
870                      IF ( k == k_hub(inot) )  THEN
871                         IF ( tower_n - tower_s >= 1 )  THEN
[1839]872!
[1819]873!--                      leftmost and rightmost grid box:
874                            IF ( j == tower_s )  THEN
[1912]875                               tow_cd_surf(k,j,i) = ( rcz(inot) -              &
876                                    ( k_hub(inot) * dz - 0.5_wp * dz ) )  *    & ! extension in z-direction
877                                  ( ( tower_s + 1.0_wp + 0.5_wp ) * dy    -    &
878                                    ( rcy(inot) - 0.5_wp * dtow(inot) ) ) *    & ! extension in y-direction
879                                  turb_cd_tower(inot)
[1819]880                            ELSEIF ( j == tower_n )  THEN
[1912]881                               tow_cd_surf(k,j,i) = ( rcz(inot)            -   &
882                                    ( k_hub(inot) * dz - 0.5_wp * dz ) )  *    & ! extension in z-direction
883                                  ( ( rcy(inot) + 0.5_wp * dtow(inot) )   -    &
884                                    ( tower_n + 0.5_wp ) * dy )           *    & ! extension in y-direction
885                                  turb_cd_tower(inot)
[1819]886!
887!--                         grid boxes inbetween
[1912]888!--                         (where tow_cd_surf = grid box area):
[1819]889                            ELSE
[1912]890                               tow_cd_surf(k,j,i) = ( rcz(inot) -              &
891                                    ( k_hub(inot) * dz - 0.5_wp * dz ) )  *    &
892                                    dy * turb_cd_tower(inot)
[1819]893                            ENDIF
894!
895!--                      tower lies completely within one grid box:
896                         ELSE
[1912]897                            tow_cd_surf(k,j,i) = ( rcz(inot)                 - &
[1839]898                                       ( k_hub(inot) * dz - 0.5_wp * dz ) ) *  &
[1912]899                                       dtow(inot) * turb_cd_tower(inot)
[1819]900                         ENDIF
[1839]901!
902!--                  In case that k is smaller than k_hub the following actions
903!--                  are carried out:
[1819]904                      ELSEIF ( k < k_hub(inot) )  THEN
905                     
[1839]906                         IF ( ( tower_n - tower_s ) >= 1 )  THEN
907!
[1819]908!--                         leftmost and rightmost grid box:
909                            IF ( j == tower_s )  THEN                         
[1912]910                               tow_cd_surf(k,j,i) = dz * (                     &
[1839]911                                      ( tower_s + 1 + 0.5_wp ) * dy         -  &
912                                      ( rcy(inot) - 0.5_wp * dtow(inot) )      &
[1912]913                                                        ) * turb_cd_tower(inot)
[1819]914                            ELSEIF ( j == tower_n )  THEN
[1912]915                               tow_cd_surf(k,j,i) = dz * (                     &
[1839]916                                      ( rcy(inot) + 0.5_wp * dtow(inot) )   -  &
917                                      ( tower_n + 0.5_wp ) * dy                &
[1912]918                                                         ) * turb_cd_tower(inot)
[1839]919!
920!--                         grid boxes inbetween
[1912]921!--                         (where tow_cd_surf = grid box area):
[1819]922                            ELSE
[1912]923                               tow_cd_surf(k,j,i) = dz * dy * turb_cd_tower(inot)
[1819]924                            ENDIF
[1839]925!
[1819]926!--                         tower lies completely within one grid box:
927                         ELSE
[1912]928                            tow_cd_surf(k,j,i) = dz * dtow(inot) *             &
929                                                turb_cd_tower(inot)
[1839]930                         ENDIF ! end if larger than grid box
931
932                      ENDIF    ! end if k == k_hub
933
934                   ENDDO       ! end loop over k
935
936                ENDIF          ! end if inside north and south boundary of tower
937
938             ENDDO             ! end loop over j
939
940          ENDIF                ! end if hub inside domain + ghostpoints
[1819]941       
[1839]942         
[1912]943          CALL exchange_horiz( tow_cd_surf, nbgp )
[1819]944
[1839]945!
[1864]946!--       Calculation of the nacelle area
947!--       CAUTION: Currently disabled due to segmentation faults on the FLOW HPC
948!--                cluster (Oldenburg)
949!!
950!!--       Tabulate the points on the circle that are required in the following for
951!!--       the calculation of the Riemann integral (node points; they are called
952!!--       circle_points in the following):
953!
954!          dy_int = dy / 10000.0_wp
955!
956!          DO  i_ip = 1, upper_end
957!             yvalue   = dy_int * ( i_ip - 0.5_wp ) + 0.5_wp * dy           !<--- segmentation fault
958!             sqrt_arg = rnac(inot)**2 - ( yvalue - rcy(inot) )**2          !<--- segmentation fault
959!             IF ( sqrt_arg >= 0.0_wp )  THEN
960!!
961!!--             bottom intersection point
962!                circle_points(1,i_ip) = rcz(inot) - SQRT( sqrt_arg )
963!!
964!!--             top intersection point
965!                circle_points(2,i_ip) = rcz(inot) + SQRT( sqrt_arg )       !<--- segmentation fault
966!             ELSE
967!                circle_points(:,i_ip) = -111111                            !<--- segmentation fault
968!             ENDIF
969!          ENDDO
970!
971!
972!          DO  j = nys, nyn
973!!
974!!--          In case that the grid box is located completely outside the nacelle
975!!--          (y) it can automatically be stated that there is no overlap between
976!!--          the grid box and the nacelle and consequently we can set
[1912]977!!--          nac_cd_surf(:,j,i) = 0.0:
[1864]978!             IF ( ( j >= index_nacl(inot) )  .AND.  ( j <= index_nacr(inot) ) )  THEN
979!                DO  k = nzb+1, nzt
980!!
981!!--                In case that the grid box is located completely outside the
982!!--                nacelle (z) it can automatically be stated that there is no
983!!--                overlap between the grid box and the nacelle and consequently
[1912]984!!--                we can set nac_cd_surf(k,j,i) = 0.0:
[1864]985!                   IF ( ( k >= index_nacb(inot) )  .OR.                           &
986!                        ( k <= index_nact(inot) ) )  THEN
987!!
988!!--                   For all other cases Riemann integrals are calculated.
989!!--                   Here, the points on the circle that have been determined
990!!--                   above are used in order to calculate the overlap between the
991!!--                   gridbox and the nacelle area (area approached by 10000
992!!--                   rectangulars dz_int * dy_int):
993!                      DO  i_ipg = 1, 10000
994!                         dz_int = dz
995!                         i_ip = j * 10000 + i_ipg
996!!
997!!--                      Determine the vertical extension dz_int of the circle
998!!--                      within the current grid box:
999!                         IF ( ( circle_points(2,i_ip) < zw(k) ) .AND.          &  !<--- segmentation fault
1000!                              ( circle_points(2,i_ip) >= zw(k-1) ) ) THEN
1001!                            dz_int = dz_int -                                  &  !<--- segmentation fault
1002!                                     ( zw(k) - circle_points(2,i_ip) )
1003!                         ENDIF
1004!                         IF ( ( circle_points(1,i_ip) <= zw(k) ) .AND.         &  !<--- segmentation fault
1005!                              ( circle_points(1,i_ip) > zw(k-1) ) ) THEN
1006!                            dz_int = dz_int -                                  &
1007!                                     ( circle_points(1,i_ip) - zw(k-1) )
1008!                         ENDIF
1009!                         IF ( zw(k-1) > circle_points(2,i_ip) ) THEN
1010!                            dz_int = 0.0_wp
1011!                         ENDIF
1012!                         IF ( zw(k) < circle_points(1,i_ip) ) THEN
1013!                            dz_int = 0.0_wp                     
1014!                         ENDIF
1015!                         IF ( ( nxlg <= i ) .AND. ( nxrg >= i ) ) THEN
[1912]1016!                            nac_cd_surf(k,j,i) = nac_cd_surf(k,j,i) +        &  !<--- segmentation fault
1017!                                                  dy_int * dz_int * turb_cd_nacelle(inot)
[1864]1018!                         ENDIF   
1019!                      ENDDO
1020!                   ENDIF
1021!                ENDDO
1022!             ENDIF
[1819]1023!
[1864]1024!          ENDDO
[1819]1025!       
[1912]1026!          CALL exchange_horiz( nac_cd_surf, nbgp )                                !<---  segmentation fault
[1819]1027
[1864]1028       ENDDO   ! end of loop over turbines
[1819]1029
[1912]1030       tow_cd_surf   = tow_cd_surf   / ( dx * dy * dz )      ! Normalize tower drag
1031       nac_cd_surf = nac_cd_surf / ( dx * dy * dz )      ! Normalize nacelle drag
[1819]1032
[1912]1033       CALL wtm_read_blade_tables
[1839]1034 
[1864]1035    END SUBROUTINE wtm_init
1036
1037
[1819]1038!------------------------------------------------------------------------------!
[1864]1039! Description:
1040! ------------
1041!> Read in layout of the rotor blade , the lift and drag tables
1042!> and the distribution of lift and drag tables along the blade
[1819]1043!------------------------------------------------------------------------------!
[1912]1044!
1045    SUBROUTINE wtm_read_blade_tables
[1819]1046
[1839]1047
[1864]1048       IMPLICIT NONE
1049
1050       INTEGER(iwp) ::  ii   !< running index
1051       INTEGER(iwp) ::  jj   !< running index
[1843]1052   
[1864]1053       INTEGER(iwp) ::  ierrn       !<
1054   
1055       CHARACTER(200) :: chmess     !< Read in string
[1839]1056
[1864]1057       INTEGER(iwp) ::  dlen        !< no. rows of local table
1058       INTEGER(iwp) ::  dlenbl      !< no. rows of cd, cl table
1059       INTEGER(iwp) ::  ialpha      !< table position of current alpha value
1060       INTEGER(iwp) ::  iialpha     !<
1061       INTEGER(iwp) ::  iir         !<
1062       INTEGER(iwp) ::  radres      !< radial resolution
1063       INTEGER(iwp) ::  t1          !< no. of airfoil
1064       INTEGER(iwp) ::  t2          !< no. of airfoil
1065       INTEGER(iwp) ::  trow        !<
1066       INTEGER(iwp) ::  dlenbl_int  !< no. rows of interpolated cd, cl tables
[1839]1067   
[1864]1068       REAL(wp) :: alpha_attack_i   !<
1069       REAL(wp) :: weight_a         !<
1070       REAL(wp) :: weight_b         !<
[1839]1071
[1864]1072       INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: ttoint1    !<
1073       INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: ttoint2    !<
[1839]1074   
[1864]1075       REAL(wp), DIMENSION(:), ALLOCATABLE :: turb_cd_sel1   !<
1076       REAL(wp), DIMENSION(:), ALLOCATABLE :: turb_cd_sel2   !<
1077       REAL(wp), DIMENSION(:), ALLOCATABLE :: turb_cl_sel1   !<
1078       REAL(wp), DIMENSION(:), ALLOCATABLE :: turb_cl_sel2   !<
1079       REAL(wp), DIMENSION(:), ALLOCATABLE :: read_cl_cd     !< read in var array
[1839]1080             
[1864]1081       REAL(wp), DIMENSION(:), ALLOCATABLE    :: alpha_attack_tab   !<
1082       REAL(wp), DIMENSION(:), ALLOCATABLE    :: trad1              !<
1083       REAL(wp), DIMENSION(:), ALLOCATABLE    :: trad2              !<         
1084       REAL(wp), DIMENSION(:,:), ALLOCATABLE  :: turb_cd_table      !<
1085       REAL(wp), DIMENSION(:,:), ALLOCATABLE  :: turb_cl_table      !<
[1839]1086                                         
[1864]1087       ALLOCATE ( read_cl_cd(1:2*nairfoils+1) )
[1839]1088
[1864]1089!
1090!--    Read in the distribution of lift and drag tables along the blade, the
1091!--    layout of the rotor blade and the lift and drag tables:
1092
1093       OPEN ( 201, FILE='WTM_DATA', STATUS='OLD', FORM='FORMATTED', IOSTAT=ierrn )
1094
1095       IF ( ierrn /= 0 )  THEN
1096          message_string = 'file WTM_DATA does not exist'
1097          CALL message( 'wtm_init', 'PA0???', 1, 2, 0, 6, 0 )
1098       ENDIF
1099!
1100!--    Read distribution table:
1101
1102       dlen = 0
1103
1104       READ ( 201, '(3/)' )
1105
1106       rloop3: DO
1107          READ ( 201, *, IOSTAT=ierrn ) chmess
1108          IF ( ierrn < 0  .OR.  chmess == '#'  .OR.  chmess == '')  EXIT rloop3
1109          dlen = dlen + 1
1110       ENDDO rloop3
1111
1112       ALLOCATE( trad1(1:dlen), trad2(1:dlen), ttoint1(1:dlen), ttoint2(1:dlen))
1113
1114       DO jj = 1,dlen+1
1115          BACKSPACE ( 201, IOSTAT=ierrn )
1116       ENDDO
1117
1118       DO jj = 1,dlen
1119          READ ( 201, * ) trad1(jj), trad2(jj), ttoint1(jj), ttoint2(jj)
1120       ENDDO
1121
1122!
1123!--    Read layout table:
1124
[1839]1125       dlen = 0 
[1864]1126
[1839]1127       READ ( 201, '(3/)')
[1864]1128
[1843]1129       rloop1: DO
[1864]1130          READ ( 201, *, IOSTAT=ierrn ) chmess
1131          IF ( ierrn < 0  .OR.  chmess == '#'  .OR.  chmess == '')  EXIT rloop1
1132          dlen = dlen + 1
[1843]1133       ENDDO rloop1
[1864]1134
[1839]1135       ALLOCATE( lrd(1:dlen), ard(1:dlen), crd(1:dlen) )
[1864]1136       DO jj = 1, dlen+1
1137          BACKSPACE ( 201, IOSTAT=ierrn )
1138       ENDDO             
1139       DO jj = 1, dlen
1140          READ ( 201, * ) lrd(jj), ard(jj), crd(jj) 
[1839]1141       ENDDO
[1819]1142
[1864]1143!
1144!--    Read tables (turb_cl(alpha),turb_cd(alpha) for the different profiles:
[1819]1145
[1864]1146       dlen = 0
1147
[1839]1148       READ ( 201, '(3/)' )
[1864]1149
[1843]1150       rloop2: DO
[1864]1151          READ ( 201, *, IOSTAT=ierrn ) chmess
1152          IF ( ierrn < 0  .OR.  chmess == '#'  .OR.  chmess == '')  EXIT rloop2
1153          dlen = dlen + 1
1154       ENDDO rloop2 
1155
[1912]1156       ALLOCATE( alpha_attack_tab(1:dlen), turb_cl_table(1:dlen,1:nairfoils),  &
[1864]1157                 turb_cd_table(1:dlen,1:nairfoils) )
1158
1159       DO jj = 1,dlen+1
1160          BACKSPACE ( 201, IOSTAT=ierrn )
1161       ENDDO 
1162
[1839]1163       DO jj = 1,dlen
[1864]1164          READ ( 201, * ) read_cl_cd
1165          alpha_attack_tab(jj) = read_cl_cd(1)
1166          DO ii= 1, nairfoils
1167             turb_cl_table(jj,ii) = read_cl_cd(ii*2)
1168             turb_cd_table(jj,ii) = read_cl_cd(ii*2+1)
[1819]1169          ENDDO
[1864]1170
[1839]1171       ENDDO
[1864]1172
1173       dlenbl = dlen 
1174
[1839]1175       CLOSE ( 201 )
[1819]1176
[1864]1177!
1178!--    For each possible radial position (resolution: 0.1 m --> 630 values) and
1179!--    each possible angle of attack (resolution: 0.01 degrees --> 36000 values!)
1180!--    determine the lift and drag coefficient by interpolating between the
1181!--    tabulated values of each table (interpolate to current angle of attack)
1182!--    and between the tables (interpolate to current radial position):
[1839]1183
[1864]1184       ALLOCATE( turb_cl_sel1(0:dlenbl) ) 
1185       ALLOCATE( turb_cl_sel2(0:dlenbl) ) 
1186       ALLOCATE( turb_cd_sel1(0:dlenbl) )
1187       ALLOCATE( turb_cd_sel2(0:dlenbl) )
[1819]1188
[1864]1189       radres     = INT( rr(1) * 10.0_wp ) + 1_iwp
1190       dlenbl_int = INT( 360.0_wp / accu_cl_cd_tab ) + 1_iwp
[1839]1191
[1864]1192
1193       ALLOCATE( turb_cl_tab(0:dlenbl_int,1:radres) )
1194       ALLOCATE( turb_cd_tab(0:dlenbl_int,1:radres) )
1195
1196
1197       DO iir = 1, radres ! loop over radius
1198
1199          DO iialpha = 1, dlenbl_int  ! loop over angles
1200
1201             cur_r = ( iir - 1_iwp ) * 0.1_wp             
1202             alpha_attack_i = -180.0_wp + REAL( iialpha-1 ) * accu_cl_cd_tab
1203             ialpha = 1
1204
1205             DO WHILE ( alpha_attack_i > alpha_attack_tab(ialpha) )
1206                ialpha = ialpha + 1
1207             ENDDO
[1819]1208!
[1864]1209!--          Find position in table
1210             lct = MINLOC( ABS( trad1 - cur_r ) )
1211!                lct(1) = lct(1)
[1819]1212
[1864]1213             IF ( ( trad1(lct(1)) - cur_r ) .GT. 0.0 )  THEN
1214                lct(1) = lct(1) - 1
1215             ENDIF
[1819]1216
[1864]1217             trow = lct(1)
1218!
1219!--          Calculate weights for interpolation
1220             weight_a = ( trad2(trow) - cur_r ) / ( trad2(trow) - trad1(trow) )
1221             weight_b = ( cur_r - trad1(trow) ) / ( trad2(trow) - trad1(trow) )
1222             t1 = ttoint1(trow)
1223             t2 = ttoint2(trow)
[1819]1224
[1912]1225             IF ( t1 .EQ. t2 ) THEN  ! if both are the same, the weights are NaN
1226                weight_a = 0.5_wp    ! then do interpolate in between same twice
1227                weight_b = 0.5_wp    ! using 0.5 as weight
[1864]1228             ENDIF
[1819]1229
[1864]1230             IF ( t1 == 0 .AND. t2 == 0 ) THEN
1231                turb_cd_sel1 = 0.0_wp
1232                turb_cd_sel2 = 0.0_wp
1233                turb_cl_sel1 = 0.0_wp
1234                turb_cl_sel2 = 0.0_wp
1235             ELSE
1236                turb_cd_sel1 = turb_cd_table(:,t1)
1237                turb_cd_sel2 = turb_cd_table(:,t2)
1238                turb_cl_sel1 = turb_cl_table(:,t1)
1239                turb_cl_sel2 = turb_cl_table(:,t2)
1240             ENDIF
1241
[1912]1242!
1243!--          Interpolation of lift and drag coefficiencts on fine grid of radius
1244!--          segments and angles of attack
1245
1246             turb_cl_tab(iialpha,iir) = ( alpha_attack_tab(ialpha) -           &
1247                                          alpha_attack_i ) /                   &
[1864]1248                                        ( alpha_attack_tab(ialpha) -           &
1249                                          alpha_attack_tab(ialpha-1) ) *       &
1250                                        ( weight_a * turb_cl_sel1(ialpha-1) +  &
1251                                          weight_b * turb_cl_sel2(ialpha-1) ) +&
1252                                        ( alpha_attack_i             -         &
1253                                          alpha_attack_tab(ialpha-1) ) /       &
1254                                        ( alpha_attack_tab(ialpha) -           &
1255                                          alpha_attack_tab(ialpha-1) ) *       &
1256                                        ( weight_a * turb_cl_sel1(ialpha) +    &
1257                                          weight_b * turb_cl_sel2(ialpha) )
[1912]1258             turb_cd_tab(iialpha,iir) = ( alpha_attack_tab(ialpha) -           &
1259                                          alpha_attack_i ) /                   &
[1864]1260                                        ( alpha_attack_tab(ialpha) -           &
1261                                          alpha_attack_tab(ialpha-1) ) *       &
1262                                        ( weight_a * turb_cd_sel1(ialpha-1) +  &
1263                                          weight_b * turb_cd_sel2(ialpha-1) ) +&
1264                                        ( alpha_attack_i             -         &
1265                                          alpha_attack_tab(ialpha-1) ) /       &
1266                                        ( alpha_attack_tab(ialpha) -           &
1267                                          alpha_attack_tab(ialpha-1) ) *       &
1268                                        ( weight_a * turb_cd_sel1(ialpha) +    &
1269                                          weight_b * turb_cd_sel2(ialpha) )
[1819]1270   
[1912]1271          ENDDO   ! end loop over angles of attack
[1819]1272
[1864]1273       ENDDO   ! end loop over radius
1274   
[1912]1275    END SUBROUTINE wtm_read_blade_tables
[1819]1276
1277
[1864]1278!------------------------------------------------------------------------------!
1279! Description:
1280! ------------
1281!> The projection matrix for the coordinate system of therotor disc in respect
1282!> to the yaw and tilt angle of the rotor is calculated
1283!------------------------------------------------------------------------------!
1284    SUBROUTINE wtm_rotate_rotor( inot )
[1819]1285
[1864]1286
1287       IMPLICIT NONE
1288
1289       INTEGER(iwp) :: inot
1290!
1291!--    Calculation of the rotation matrix for the application of the tilt to
1292!--    the rotors
1293       rot_eigen_rad(1) = SIN( phi_yaw(inot) )    ! x-component of the radial eigenvector
1294       rot_eigen_rad(2) = COS( phi_yaw(inot) )    ! y-component of the radial eigenvector
1295       rot_eigen_rad(3) = 0.0_wp                  ! z-component of the radial eigenvector
1296
1297       rot_eigen_azi(1) = 0.0_wp                  ! x-component of the azimuth eigenvector
1298       rot_eigen_azi(2) = 0.0_wp                  ! y-component of the azimuth eigenvector
1299       rot_eigen_azi(3) = 1.0_wp                  ! z-component of the azimuth eigenvector
1300
1301       rot_eigen_nor(1) =  COS( phi_yaw(inot) )   ! x-component of the normal eigenvector
1302       rot_eigen_nor(2) = -SIN( phi_yaw(inot) )   ! y-component of the normal eigenvector
1303       rot_eigen_nor(3) = 0.0_wp                  ! z-component of the normal eigenvector
[1839]1304   
[1864]1305!
1306!--    Calculation of the coordinate transformation matrix to apply a tilt to
1307!--    the rotor. If tilt = 0, rot_coord_trans is a unit matrix.
[1819]1308
[1912]1309       rot_coord_trans(inot,1,1) = rot_eigen_rad(1)**2                   *     &
[1864]1310                                   ( 1.0_wp - COS( tilt ) ) + COS( tilt ) 
[1912]1311       rot_coord_trans(inot,1,2) = rot_eigen_rad(1) * rot_eigen_rad(2)   *     &
1312                                   ( 1.0_wp - COS( tilt ) )              -     &
[1864]1313                                   rot_eigen_rad(3) * SIN( tilt )
[1912]1314       rot_coord_trans(inot,1,3) = rot_eigen_rad(1) * rot_eigen_rad(3)   *     &
1315                                   ( 1.0_wp - COS( tilt ) )              +     &
[1864]1316                                   rot_eigen_rad(2) * SIN( tilt )
[1912]1317       rot_coord_trans(inot,2,1) = rot_eigen_rad(2) * rot_eigen_rad(1)   *     &
1318                                   ( 1.0_wp - COS( tilt ) )              +     &
[1864]1319                                   rot_eigen_rad(3) * SIN( tilt )
[1912]1320       rot_coord_trans(inot,2,2) = rot_eigen_rad(2)**2                   *     &
[1864]1321                                   ( 1.0_wp - COS( tilt ) ) + COS( tilt ) 
[1912]1322       rot_coord_trans(inot,2,3) = rot_eigen_rad(2) * rot_eigen_rad(3)   *     &
1323                                   ( 1.0_wp - COS( tilt ) )              -     &
[1864]1324                                   rot_eigen_rad(1) * SIN( tilt )
[1912]1325       rot_coord_trans(inot,3,1) = rot_eigen_rad(3) * rot_eigen_rad(1)   *     &
1326                                   ( 1.0_wp - COS( tilt ) )              -     &
[1864]1327                                   rot_eigen_rad(2) * SIN( tilt )
[1912]1328       rot_coord_trans(inot,3,2) = rot_eigen_rad(3) * rot_eigen_rad(2)   *     &
1329                                   ( 1.0_wp - COS( tilt ) )              +     &
[1864]1330                                   rot_eigen_rad(1) * SIN( tilt )
[1912]1331       rot_coord_trans(inot,3,3) = rot_eigen_rad(3)**2                   *     &
[1864]1332                                   ( 1.0_wp - COS( tilt ) ) + COS( tilt )
[1839]1333
[1864]1334!
1335!--    Vectors for the Transformation of forces from the rotor's spheric
1336!--    coordinate system to the cartesian coordinate system
1337       rotx(inot,:) = MATMUL( rot_coord_trans(inot,:,:), rot_eigen_nor )
1338       roty(inot,:) = MATMUL( rot_coord_trans(inot,:,:), rot_eigen_rad )
1339       rotz(inot,:) = MATMUL( rot_coord_trans(inot,:,:), rot_eigen_azi )
1340   
1341    END SUBROUTINE wtm_rotate_rotor
[1839]1342
1343
[1819]1344!------------------------------------------------------------------------------!
1345! Description:
1346! ------------
[1839]1347!> Calculation of the forces generated by the wind turbine
[1819]1348!------------------------------------------------------------------------------!
1349    SUBROUTINE wtm_forces
1350
[1864]1351
[1819]1352       IMPLICIT NONE
1353
1354       CHARACTER (LEN=2) ::  turbine_id
1355
[1839]1356       INTEGER(iwp) ::  i, j, k          !< loop indices
1357       INTEGER(iwp) ::  inot             !< turbine loop index (turbine id)
1358       INTEGER(iwp) ::  iialpha, iir     !<
1359       INTEGER(iwp) ::  rseg, rseg_int   !<
1360       INTEGER(iwp) ::  ring, ring_int   !<
1361       INTEGER(iwp) ::  ii, jj, kk       !<
[1912]1362   
[1839]1363       REAL(wp)     ::  sin_rot, cos_rot   !<
1364       REAL(wp)     ::  sin_yaw, cos_yaw   !<
[1912]1365       
1366       REAL(wp) ::  aa, bb, cc, dd  !< interpolation distances
1367       REAL(wp) ::  gg              !< interpolation volume var 
1368       
1369       REAL(wp) ::  dist_u_3d, dist_v_3d, dist_w_3d  !< smearing distances
1370
1371       
[1839]1372!
[1819]1373!      Variables for pitch control
1374       REAL(wp)     ::  torque_max=0.0_wp
[1839]1375       LOGICAL      ::  pitch_sw=.FALSE.
1376
[1819]1377       INTEGER(iwp), DIMENSION(1) :: lct=0
[1839]1378       REAL(wp), DIMENSION(1)     :: rad_d=0.0_wp
[1819]1379
1380
[1864]1381       CALL cpu_log( log_point_s(61), 'wtm_forces', 'start' )
[1819]1382
1383
1384       IF ( simulated_time >= time_turbine_on ) THEN
1385
[1864]1386!
[1819]1387!--       Set forces to zero for each new time step:
1388          thrust(:,:,:)         = 0.0_wp
1389          torque_y(:,:,:)       = 0.0_wp
1390          torque_z(:,:,:)       = 0.0_wp
1391          torque_total(:)       = 0.0_wp
[1912]1392          rot_tend_x(:,:,:)     = 0.0_wp
1393          rot_tend_y(:,:,:)     = 0.0_wp
1394          rot_tend_z(:,:,:)     = 0.0_wp
1395          thrust_rotor(:)       = 0.0_wp
[1819]1396!
1397!--       Loop over number of turbines:
1398          DO inot = 1, nturbines
1399
1400             cos_yaw = COS(phi_yaw(inot))
1401             sin_yaw = SIN(phi_yaw(inot))
1402!
[1839]1403!--          Loop over rings of each turbine:
[1819]1404             DO ring = 1, nrings(inot)
1405
1406                thrust_seg(:)   = 0.0_wp
1407                torque_seg_y(:) = 0.0_wp
1408                torque_seg_z(:) = 0.0_wp
1409!
1410!--             Determine distance between each ring (center) and the hub:
1411                cur_r = (ring - 0.5_wp) * delta_r(inot)
1412
1413!
[1839]1414!--             Loop over segments of each ring of each turbine:
[1819]1415                DO rseg = 1, nsegs(ring,inot)
1416!
[1864]1417!--                !-----------------------------------------------------------!
1418!--                !-- Determine coordinates of the ring segments            --!
1419!--                !-----------------------------------------------------------!
[1819]1420!
[1864]1421!--                Determine angle of ring segment towards zero degree angle of
1422!--                rotor system (at zero degree rotor direction vectors aligned
1423!--                with y-axis):
[1819]1424                   phi_rotor = rseg * 2.0_wp * pi / nsegs(ring,inot)
1425                   cos_rot   = COS( phi_rotor )
1426                   sin_rot   = SIN( phi_rotor )
1427
[1864]1428!--                Now the direction vectors can be determined with respect to
1429!--                the yaw and tilt angle:
[1819]1430                   re(1) = cos_rot * sin_yaw
[1839]1431                   re(2) = cos_rot * cos_yaw   
[1819]1432                   re(3) = sin_rot
1433
1434                   rote = MATMUL( rot_coord_trans(inot,:,:), re )
1435!
1436!--                Coordinates of the single segments (center points):
1437                   rbx(ring,rseg) = rcx(inot) + cur_r * rote(1)
1438                   rby(ring,rseg) = rcy(inot) + cur_r * rote(2)
1439                   rbz(ring,rseg) = rcz(inot) + cur_r * rote(3)
1440
[1864]1441!--                !-----------------------------------------------------------!
1442!--                !-- Interpolation of the velocity components from the     --!
1443!--                !-- cartesian grid point to the coordinates of each ring  --!
1444!--                !-- segment (follows a method used in the particle model) --!
1445!--                !-----------------------------------------------------------!
[1819]1446
1447                   u_int(inot,ring,rseg)     = 0.0_wp
1448                   u_int_1_l(inot,ring,rseg) = 0.0_wp
1449
1450                   v_int(inot,ring,rseg)     = 0.0_wp
1451                   v_int_1_l(inot,ring,rseg) = 0.0_wp
1452
1453                   w_int(inot,ring,rseg)     = 0.0_wp
1454                   w_int_1_l(inot,ring,rseg) = 0.0_wp
1455
1456!
1457!--                Interpolation of the u-component:
1458
1459                   ii =   rbx(ring,rseg) * ddx
1460                   jj = ( rby(ring,rseg) - 0.5_wp * dy ) * ddy
1461                   kk = ( rbz(ring,rseg) - 0.5_wp * dz ) / dz
1462!
[1864]1463!--                Interpolate only if all required information is available on
1464!--                the current PE:
[1839]1465                   IF ( ( ii >= nxl )  .AND.  ( ii <= nxr ) )  THEN
1466                      IF ( ( jj >= nys )  .AND.  ( jj <= nyn ) )  THEN
[1819]1467
[1839]1468                         aa = ( ( ii + 1          ) * dx - rbx(ring,rseg) ) *  &
1469                              ( ( jj + 1 + 0.5_wp ) * dy - rby(ring,rseg) )
1470                         bb = ( rbx(ring,rseg) - ii * dx )                  *  &
1471                              ( ( jj + 1 + 0.5_wp ) * dy - rby(ring,rseg) )
1472                         cc = ( ( ii+1            ) * dx - rbx(ring,rseg) ) *  &
1473                              ( rby(ring,rseg) - ( jj + 0.5_wp ) * dy )
1474                         dd = ( rbx(ring,rseg) -              ii * dx )     *  &
1475                              ( rby(ring,rseg) - ( jj + 0.5_wp ) * dy ) 
[1819]1476                         gg = dx * dy
1477
[1864]1478                         u_int_l = ( aa * u(kk,jj,ii)     +                    &
1479                                     bb * u(kk,jj,ii+1)   +                    &
1480                                     cc * u(kk,jj+1,ii)   +                    &
1481                                     dd * u(kk,jj+1,ii+1)                      &
[1819]1482                                   ) / gg
1483
[1864]1484                         u_int_u = ( aa * u(kk+1,jj,ii)     +                  &
1485                                     bb * u(kk+1,jj,ii+1)   +                  &
1486                                     cc * u(kk+1,jj+1,ii)   +                  &
1487                                     dd * u(kk+1,jj+1,ii+1)                    &
[1819]1488                                   ) / gg
1489
[1864]1490                         u_int_1_l(inot,ring,rseg) = u_int_l          +        &
1491                                     ( rbz(ring,rseg) - zu(kk) ) / dz *        &
[1819]1492                                     ( u_int_u - u_int_l )
1493
1494                      ELSE
1495                         u_int_1_l(inot,ring,rseg) = 0.0_wp
1496                      ENDIF
1497                   ELSE
1498                      u_int_1_l(inot,ring,rseg) = 0.0_wp
1499                   ENDIF
1500
1501
1502!
1503!--                Interpolation of the v-component:
1504                   ii = ( rbx(ring,rseg) - 0.5_wp * dx ) * ddx
[1839]1505                   jj =   rby(ring,rseg)                 * ddy
[1819]1506                   kk = ( rbz(ring,rseg) + 0.5_wp * dz ) / dz 
1507!
[1864]1508!--                Interpolate only if all required information is available on
1509!--                the current PE:
[1839]1510                   IF ( ( ii >= nxl )  .AND.  ( ii <= nxr ) )  THEN
1511                      IF ( ( jj >= nys )  .AND.  ( jj <= nyn ) )  THEN
[1819]1512
[1839]1513                         aa = ( ( ii + 1 + 0.5_wp ) * dx - rbx(ring,rseg) ) *  &
1514                              ( ( jj + 1 )          * dy - rby(ring,rseg) )
1515                         bb = ( rbx(ring,rseg)     - ( ii + 0.5_wp ) * dx ) *  &
1516                              ( ( jj + 1 ) * dy          - rby(ring,rseg) )
1517                         cc = ( ( ii + 1 + 0.5_wp ) * dx - rbx(ring,rseg) ) *  &
1518                              ( rby(ring,rseg)           -        jj * dy )
1519                         dd = ( rbx(ring,rseg)     - ( ii + 0.5_wp ) * dx ) *  &
1520                              ( rby(ring,rseg)           -        jj * dy )
[1819]1521                         gg = dx * dy
1522
[1864]1523                         v_int_l = ( aa * v(kk,jj,ii)     +                    &
1524                                     bb * v(kk,jj,ii+1)   +                    &
1525                                     cc * v(kk,jj+1,ii)   +                    &
1526                                     dd * v(kk,jj+1,ii+1)                      &
[1819]1527                                   ) / gg
1528
[1864]1529                         v_int_u = ( aa * v(kk+1,jj,ii)     +                  &
1530                                     bb * v(kk+1,jj,ii+1)   +                  &
1531                                     cc * v(kk+1,jj+1,ii)   +                  &
1532                                     dd * v(kk+1,jj+1,ii+1)                    &
[1819]1533                                  ) / gg
1534
[1864]1535                         v_int_1_l(inot,ring,rseg) = v_int_l +                 &
1536                                     ( rbz(ring,rseg) - zu(kk) ) / dz *        &
[1819]1537                                     ( v_int_u - v_int_l )
1538
1539                      ELSE
1540                         v_int_1_l(inot,ring,rseg) = 0.0_wp
1541                      ENDIF
1542                   ELSE
1543                      v_int_1_l(inot,ring,rseg) = 0.0_wp
1544                   ENDIF
1545
1546
1547!
1548!--                Interpolation of the w-component:
1549                   ii = ( rbx(ring,rseg) - 0.5_wp * dx ) * ddx
1550                   jj = ( rby(ring,rseg) - 0.5_wp * dy ) * ddy
[1839]1551                   kk =   rbz(ring,rseg)                 / dz
[1819]1552!
[1864]1553!--                Interpolate only if all required information is available on
1554!--                the current PE:
[1839]1555                   IF ( ( ii >= nxl )  .AND.  ( ii <= nxr ) )  THEN
1556                      IF ( ( jj >= nys )  .AND.  ( jj <= nyn ) )  THEN
[1819]1557
[1839]1558                         aa = ( ( ii + 1 + 0.5_wp ) * dx - rbx(ring,rseg) ) *  &
1559                              ( ( jj + 1 + 0.5_wp ) * dy - rby(ring,rseg) )
1560                         bb = ( rbx(ring,rseg)     - ( ii + 0.5_wp ) * dx ) *  &
1561                              ( ( jj + 1 + 0.5_wp ) * dy - rby(ring,rseg) )
1562                         cc = ( ( ii + 1 + 0.5_wp ) * dx - rbx(ring,rseg) ) *  &
1563                              ( rby(ring,rseg)     - ( jj + 0.5_wp ) * dy )
1564                         dd = ( rbx(ring,rseg)     - ( ii + 0.5_wp ) * dx ) *  &
1565                              ( rby(ring,rseg)     - ( jj + 0.5_wp ) * dy )
[1819]1566                         gg = dx * dy
1567
[1864]1568                         w_int_l = ( aa * w(kk,jj,ii)     +                    &
1569                                     bb * w(kk,jj,ii+1)   +                    &
1570                                     cc * w(kk,jj+1,ii)   +                    &
1571                                     dd * w(kk,jj+1,ii+1)                      &
[1819]1572                                   ) / gg
1573
[1864]1574                         w_int_u = ( aa * w(kk+1,jj,ii)     +                  &
1575                                     bb * w(kk+1,jj,ii+1)   +                  &
1576                                     cc * w(kk+1,jj+1,ii)   +                  &
1577                                     dd * w(kk+1,jj+1,ii+1)                    &
[1819]1578                                    ) / gg
1579
[1864]1580                         w_int_1_l(inot,ring,rseg) = w_int_l +                 &
1581                                     ( rbz(ring,rseg) - zw(kk) ) / dz *        &
[1819]1582                                     ( w_int_u - w_int_l )
1583                      ELSE
1584                         w_int_1_l(inot,ring,rseg) = 0.0_wp
1585                      ENDIF
1586                   ELSE
1587                      w_int_1_l(inot,ring,rseg) = 0.0_wp
1588                   ENDIF
1589
1590                ENDDO
1591             ENDDO
1592
1593          ENDDO
1594
1595!
1596!--       Exchange between PEs (information required on each PE):
1597#if defined( __parallel )
[1839]1598          CALL MPI_ALLREDUCE( u_int_1_l, u_int, nturbines * MAXVAL(nrings) *   &
1599                              MAXVAL(nsegs), MPI_REAL, MPI_SUM, comm2d, ierr )
1600          CALL MPI_ALLREDUCE( v_int_1_l, v_int, nturbines * MAXVAL(nrings) *   &
1601                              MAXVAL(nsegs), MPI_REAL, MPI_SUM, comm2d, ierr )
1602          CALL MPI_ALLREDUCE( w_int_1_l, w_int, nturbines * MAXVAL(nrings) *   &
1603                              MAXVAL(nsegs), MPI_REAL, MPI_SUM, comm2d, ierr )
[1819]1604#else
1605          u_int = u_int_1_l
1606          v_int = v_int_1_l
1607          w_int = w_int_1_l
1608#endif
1609
1610
1611!
1612!--       Loop over number of turbines:
[1912]1613
[1819]1614          DO inot = 1, nturbines
[1912]1615pit_loop: DO
[1819]1616
[1912]1617             IF ( pitch_sw )  THEN
[1839]1618                torque_total(inot) = 0.0_wp
[1912]1619                thrust_rotor(inot) = 0.0_wp
1620                pitch_add(inot)    = pitch_add(inot) + 0.25_wp
1621!                 IF ( myid == 0 ) PRINT*, 'Pitch', inot, pitch_add(inot)
1622             ELSE
1623                cos_yaw = COS(phi_yaw(inot))
1624                sin_yaw = SIN(phi_yaw(inot))
1625                IF ( pitch_control )  THEN
1626                   pitch_add(inot) = MAX(pitch_add_old(inot) - pitch_rate *    &
1627                                         dt_3d , 0.0_wp )
1628                ENDIF
[1819]1629             ENDIF
1630
[1839]1631!
1632!--          Loop over rings of each turbine:
[1819]1633             DO ring = 1, nrings(inot)
1634!
1635!--             Determine distance between each ring (center) and the hub:
1636                cur_r = (ring - 0.5_wp) * delta_r(inot)
[1839]1637!
1638!--             Loop over segments of each ring of each turbine:
[1819]1639                DO rseg = 1, nsegs(ring,inot)
1640!
[1839]1641!--                Determine angle of ring segment towards zero degree angle of
1642!--                rotor system (at zero degree rotor direction vectors aligned
1643!--                with y-axis):
[1819]1644                   phi_rotor = rseg * 2.0_wp * pi / nsegs(ring,inot)
1645                   cos_rot   = COS(phi_rotor)
1646                   sin_rot   = SIN(phi_rotor)
1647!
[1839]1648!--                Now the direction vectors can be determined with respect to
1649!--                the yaw and tilt angle:
[1819]1650                   re(1) = cos_rot * sin_yaw
1651                   re(2) = cos_rot * cos_yaw
1652                   re(3) = sin_rot
1653
[1864]1654!                  The current unit vector in azimuthal direction:                         
[1819]1655                   rea(1) = - sin_rot * sin_yaw
1656                   rea(2) = - sin_rot * cos_yaw
1657                   rea(3) =   cos_rot
1658
1659!
[1864]1660!--                To respect the yawing angle for the calculations of
1661!--                velocities and forces the unit vectors perpendicular to the
1662!--                rotor area in direction of the positive yaw angle are defined:
[1819]1663                   ren(1) =   cos_yaw
1664                   ren(2) = - sin_yaw
1665                   ren(3) = 0.0_wp
1666!
1667!--                Multiplication with the coordinate transformation matrix
[1864]1668!--                gives the final unit vector with consideration of the rotor
1669!--                tilt:
[1819]1670                   rote = MATMUL( rot_coord_trans(inot,:,:), re )
1671                   rota = MATMUL( rot_coord_trans(inot,:,:), rea )
1672                   rotn = MATMUL( rot_coord_trans(inot,:,:), ren )
1673!
1674!--                Coordinates of the single segments (center points):
1675                   rbx(ring,rseg) = rcx(inot) + cur_r * rote(1)
1676
1677                   rby(ring,rseg) = rcy(inot) + cur_r * rote(2)
1678
1679                   rbz(ring,rseg) = rcz(inot) + cur_r * rote(3)
1680
1681!
[1864]1682!--                !-----------------------------------------------------------!
1683!--                !-- Calculation of various angles and relative velocities --!
1684!--                !-----------------------------------------------------------!
[1819]1685!
[1864]1686!--                In the following the 3D-velocity field is projected its
[1819]1687!--                components perpedicular and parallel to the rotor area
1688!--                The calculation of forces will be done in the rotor-
1689!--                coordinates y' and z.
1690!--                The yaw angle will be reintroduced when the force is applied
1691!--                on the hydrodynamic equations
[1864]1692!
1693!--                Projection of the xy-velocities relative to the rotor area
1694!
[1819]1695!--                Velocity perpendicular to the rotor area:
[1864]1696                   u_rot = u_int(inot,ring,rseg)*rotn(1) +                     &
1697                   v_int(inot,ring,rseg)*rotn(2) +                             &
[1819]1698                   w_int(inot,ring,rseg)*rotn(3)
1699!
[1864]1700!--                Projection of the 3D-velocity vector in the azimuthal
1701!--                direction:
1702                   vtheta(rseg) = rota(1) * u_int(inot,ring,rseg) +            & 
1703                                  rota(2) * v_int(inot,ring,rseg) +            &
[1819]1704                                  rota(3) * w_int(inot,ring,rseg)
1705!
[1864]1706!--                Determination of the angle phi_rel between the rotor plane
1707!--                and the direction of the flow relative to the rotor:
[1819]1708
[1864]1709                   phi_rel(rseg) = ATAN( u_rot /                               &
1710                                         ( omega_rot(inot) * cur_r -           &
[1819]1711                                           vtheta(rseg) ) )
1712
1713!
[1864]1714!--                Interpolation of the local pitch angle from tabulated values
1715!--                to the current radial position:
[1819]1716
1717                   lct=minloc(ABS(cur_r-lrd))
1718                   rad_d=cur_r-lrd(lct)
1719                   
1720                   IF (cur_r == 0.0_wp) THEN
1721                      alpha_attack(rseg) = 0.0_wp
1722                   ELSE IF (cur_r >= lrd(size(ard))) THEN
[1864]1723                      alpha_attack(rseg) = ( ard(size(ard)) +                  &
1724                                             ard(size(ard)-1) ) / 2.0_wp
[1819]1725                   ELSE
[1864]1726                      alpha_attack(rseg) = ( ard(lct(1)) *  &
1727                                             ( ( lrd(lct(1)+1) - cur_r ) /     &
1728                                               ( lrd(lct(1)+1) - lrd(lct(1)) ) &
1729                                             ) ) + ( ard(lct(1)+1) *           &
1730                                             ( ( cur_r - lrd(lct(1)) ) /       &
1731                                               ( lrd(lct(1)+1) - lrd(lct(1)) ) ) )
[1819]1732                   ENDIF
1733
1734!
[1864]1735!--                In Fortran radian instead of degree is used as unit for all
1736!--                angles. Therefore, a transformation from angles given in
1737!--                degree to angles given in radian is necessary here:
1738                   alpha_attack(rseg) = alpha_attack(rseg) *                   &
[1819]1739                                        ( (2.0_wp*pi) / 360.0_wp )
1740!
[1864]1741!--                Substraction of the local pitch angle to obtain the local
1742!--                angle of attack:
[1819]1743                   alpha_attack(rseg) = phi_rel(rseg) - alpha_attack(rseg)
1744!
[1864]1745!--                Preliminary transformation back from angles given in radian
1746!--                to angles given in degree:
1747                   alpha_attack(rseg) = alpha_attack(rseg) *                   &
[1819]1748                                        ( 360.0_wp / (2.0_wp*pi) )
1749!
[1864]1750!--                Correct with collective pitch angle:
[1819]1751                   alpha_attack = alpha_attack + pitch_add(inot)
1752
1753!
[1864]1754!--                Determination of the magnitude of the flow velocity relative
1755!--                to the rotor:
[1912]1756                   vrel(rseg) = SQRT( u_rot**2 +                               &
1757                                      ( omega_rot(inot) * cur_r -              &
[1819]1758                                        vtheta(rseg) )**2 )
1759
1760!
[1864]1761!--                !-----------------------------------------------------------!
1762!--                !-- Interpolation of chord as well as lift and drag       --!
1763!--                !-- coefficients from tabulated values                    --!
1764!--                !-----------------------------------------------------------!
[1819]1765
1766!
[1864]1767!--                Interpolation of the chord_length from tabulated values to
1768!--                the current radial position:
[1819]1769
1770                   IF (cur_r == 0.0_wp) THEN
1771                      chord(rseg) = 0.0_wp
1772                   ELSE IF (cur_r >= lrd(size(crd))) THEN
[1864]1773                      chord(rseg) = (crd(size(crd)) + ard(size(crd)-1)) / 2.0_wp
[1819]1774                   ELSE
[1864]1775                      chord(rseg) = ( crd(lct(1)) *                            &
1776                            ( ( lrd(lct(1)+1) - cur_r ) /                      &
1777                              ( lrd(lct(1)+1) - lrd(lct(1)) ) ) ) +            &
1778                            ( crd(lct(1)+1) *                                  &
1779                            ( ( cur_r-lrd(lct(1)) ) /                          &
1780                              ( lrd(lct(1)+1) - lrd(lct(1)) ) ) )
[1819]1781                   ENDIF
1782
1783!
1784!--                Determine index of current angle of attack, needed for
[1864]1785!--                finding the appropriate interpolated values of the lift and
1786!--                drag coefficients (-180.0 degrees = 0, +180.0 degrees = 36000,
1787!--                so one index every 0.01 degrees):
1788                   iialpha = CEILING( ( alpha_attack(rseg) + 180.0_wp )        &
[1839]1789                                      * ( 1.0_wp / accu_cl_cd_tab ) )
[1819]1790!
1791!--                Determine index of current radial position, needed for
[1864]1792!--                finding the appropriate interpolated values of the lift and
1793!--                drag coefficients (one index every 0.1 m):
[1819]1794                   iir = CEILING( cur_r * 10.0_wp )
1795!
[1864]1796!--                Read in interpolated values of the lift and drag coefficients
1797!--                for the current radial position and angle of attack:
[1839]1798                   turb_cl(rseg) = turb_cl_tab(iialpha,iir)
1799                   turb_cd(rseg) = turb_cd_tab(iialpha,iir)
[1819]1800
1801!
[1864]1802!--                Final transformation back from angles given in degree to
1803!--                angles given in radian:
1804                   alpha_attack(rseg) = alpha_attack(rseg) *                   &
[1819]1805                                        ( (2.0_wp*pi) / 360.0_wp )
1806
1807!
1808!--                !-----------------------------------------------------!
1809!--                !-- Calculation of the forces                       --!
1810!--                !-----------------------------------------------------!
1811
1812!
[1864]1813!--                Calculate the pre_factor for the thrust and torque forces:
[1819]1814
1815                   pre_factor = 0.5_wp * (vrel(rseg)**2) * 3.0_wp *  &
1816                                chord(rseg) * delta_r(inot) / nsegs(ring,inot)
1817
1818!
[1864]1819!--                Calculate the thrust force (x-component of the total force)
1820!--                for each ring segment:
1821                   thrust_seg(rseg) = pre_factor *                             &
1822                                      ( turb_cl(rseg) * COS(phi_rel(rseg)) +   &
1823                                        turb_cd(rseg) * SIN(phi_rel(rseg)) )
[1819]1824
1825!
[1864]1826!--                Determination of the second of the additional forces acting
1827!--                on the flow in the azimuthal direction: force vector as basis
1828!--                for torque (torque itself would be the vector product of the
1829!--                radius vector and the force vector):
1830                   torque_seg = pre_factor *                                   &
1831                                ( turb_cl(rseg) * SIN(phi_rel(rseg)) -         &
[1839]1832                                  turb_cd(rseg) * COS(phi_rel(rseg)) )
[1819]1833!
1834!--                Decomposition of the force vector into two parts:
[1864]1835!--                One acting along the y-direction and one acting along the
1836!--                z-direction of the rotor coordinate system:
[1819]1837
1838                   torque_seg_y(rseg) = -torque_seg * sin_rot
1839                   torque_seg_z(rseg) =  torque_seg * cos_rot
1840
[1912]1841!
1842!--                Add the segment thrust to the thrust of the whole rotor
1843                   thrust_rotor(inot) = thrust_rotor(inot) +                   &
1844                                        thrust_seg(rseg)                   
1845                   
1846
[1819]1847                   torque_total(inot) = torque_total(inot) + (torque_seg * cur_r)
1848
[1864]1849                ENDDO   !-- end of loop over ring segments
[1819]1850
1851!
[1864]1852!--             Restore the forces into arrays containing all the segments of
1853!--             each ring:
[1819]1854                thrust_ring(ring,:)   = thrust_seg(:)
1855                torque_ring_y(ring,:) = torque_seg_y(:)
1856                torque_ring_z(ring,:) = torque_seg_z(:)
1857
1858
[1864]1859             ENDDO   !-- end of loop over rings
[1819]1860
1861
[1864]1862             CALL cpu_log( log_point_s(62), 'wtm_controller', 'start' )
[1819]1863
[1912]1864             
1865             IF ( speed_control )  THEN
1866!
1867!--             Calculation of the current generator speed for rotor speed control
1868             
1869!                                     
1870!--             The acceleration of the rotor speed is calculated from
1871!--             the force balance of the accelerating torque
1872!--             and the torque of the rotating rotor and generator
1873                om_rate = ( torque_total(inot) * air_dens * gear_eff -         &
1874                            gear_ratio * torque_gen_old(inot) ) /              &
1875                          ( inertia_rot +                                      & 
1876                            gear_ratio * gear_ratio * inertia_gen ) * dt_3d
[1819]1877
[1912]1878!
1879!--             The generator speed is given by the product of gear gear_ratio
1880!--             and rotor speed
1881                omega_gen(inot) = gear_ratio * ( omega_rot(inot) + om_rate )     
1882             
1883             ENDIF
1884             
[1864]1885             IF ( pitch_control )  THEN
[1819]1886
[1912]1887!
1888!--             If the current generator speed is above rated, the pitch is not
1889!--             saturated and the change from the last time step is within the
1890!--             maximum pitch rate, then the pitch loop is repeated with a pitch
1891!--             gain
1892                IF ( (  omega_gen(inot)  > rated_genspeed   )  .AND.           &
1893                     ( pitch_add(inot) < 25.0_wp ) .AND.                       &
1894                     ( pitch_add(inot) < pitch_add_old(inot) +                 & 
1895                       pitch_rate * dt_3d  ) ) THEN
[1864]1896                   pitch_sw = .TRUE.
[1912]1897!
1898!--                Go back to beginning of pit_loop                   
1899                   CYCLE pit_loop
[1819]1900                ENDIF
[1912]1901               
1902!
1903!--             The current pitch is saved for the next time step
1904                pitch_add_old(inot) = pitch_add(inot)
[1864]1905                pitch_sw = .FALSE.
[1819]1906             ENDIF
[1912]1907             EXIT pit_loop             
1908          ENDDO pit_loop ! Recursive pitch control loop
[1819]1909
[1864]1910
[1819]1911!
[1864]1912!--          Call the rotor speed controller
1913             
[1819]1914             IF ( speed_control )  THEN
1915!
[1864]1916!--             Find processor at i_hub, j_hub             
[1912]1917                IF ( ( nxl <= i_hub(inot) )  .AND.  ( nxr >= i_hub(inot) ) )   &
1918                   THEN
1919                   IF ( ( nys <= j_hub(inot) )  .AND.  ( nyn >= j_hub(inot) ) )&
1920                      THEN
[1864]1921                      CALL wtm_speed_control( inot )
1922                   ENDIF
[1912]1923                ENDIF
[1864]1924                               
[1819]1925             ENDIF
1926
1927
[1864]1928             CALL cpu_log( log_point_s(62), 'wtm_controller', 'stop' )
[1819]1929
[1864]1930             CALL cpu_log( log_point_s(63), 'wtm_smearing', 'start' )
[1819]1931
1932
[1864]1933!--          !-----------------------------------------------------------------!
1934!--          !--                  Regularization kernel                      --!
1935!--          !-- Smearing of the forces and interpolation to cartesian grid  --!
1936!--          !-----------------------------------------------------------------!
[1819]1937!
[1864]1938!--          The aerodynamic blade forces need to be distributed smoothly on
1939!--          several mesh points in order to avoid singular behaviour
[1819]1940!
1941!--          Summation over sum of weighted forces. The weighting factor
[1864]1942!--          (calculated in user_init) includes information on the distance
1943!--          between the center of the grid cell and the rotor segment under
1944!--          consideration
[1819]1945!
[1864]1946!--          To save computing time, apply smearing only for the relevant part
1947!--          of the model domain:
[1819]1948!
1949!--
1950!--          Calculation of the boundaries:
[1864]1951             i_smear(inot) = CEILING( ( rr(inot) * ABS( roty(inot,1) ) +       &
1952                                        eps_min ) / dx )
1953             j_smear(inot) = CEILING( ( rr(inot) * ABS( roty(inot,2) ) +       &
1954                                        eps_min ) / dy )
[1819]1955
[1864]1956             DO i = MAX( nxl, i_hub(inot) - i_smear(inot) ),                   &
[1819]1957                    MIN( nxr, i_hub(inot) + i_smear(inot) )
[1864]1958                DO j = MAX( nys, j_hub(inot) - j_smear(inot) ),                &
[1819]1959                        MIN( nyn, j_hub(inot) + j_smear(inot) )
1960                   DO k = MAX( nzb_u_inner(j,i)+1, k_hub(inot) - k_smear(inot) ), &
1961                                k_hub(inot) + k_smear(inot)
1962                      DO ring = 1, nrings(inot)
1963                         DO rseg = 1, nsegs(ring,inot)
1964!
1965!--                         Determine the square of the distance between the
1966!--                         current grid point and each rotor area segment:
[1864]1967                            dist_u_3d = ( i * dx               - rbx(ring,rseg) )**2 + &
1968                                        ( j * dy + 0.5_wp * dy - rby(ring,rseg) )**2 + &
1969                                        ( k * dz - 0.5_wp * dz - rbz(ring,rseg) )**2
1970                            dist_v_3d = ( i * dx + 0.5_wp * dx - rbx(ring,rseg) )**2 + &
1971                                        ( j * dy               - rby(ring,rseg) )**2 + &
1972                                        ( k * dz - 0.5_wp * dz - rbz(ring,rseg) )**2
1973                            dist_w_3d = ( i * dx + 0.5_wp * dx - rbx(ring,rseg) )**2 + &
1974                                        ( j * dy + 0.5_wp * dy - rby(ring,rseg) )**2 + &
1975                                        ( k * dz               - rbz(ring,rseg) )**2
[1819]1976
1977!
1978!--                         3D-smearing of the forces with a polynomial function
1979!--                         (much faster than the old Gaussian function), using
1980!--                         some parameters that have been calculated in user_init.
1981!--                         The function is only similar to Gaussian function for
1982!--                         squared distances <= eps_min2:
1983                            IF ( dist_u_3d <= eps_min2 ) THEN
[1864]1984                            thrust(k,j,i) = thrust(k,j,i) +                    &
1985                                            thrust_ring(ring,rseg) *           &
1986                                            ( ( pol_a * dist_u_3d - pol_b ) *  & 
1987                                             dist_u_3d + 1.0_wp ) * eps_factor
[1819]1988                            ENDIF
1989                            IF ( dist_v_3d <= eps_min2 ) THEN
[1864]1990                            torque_y(k,j,i) = torque_y(k,j,i) +                &
1991                                              torque_ring_y(ring,rseg) *       &
1992                                              ( ( pol_a * dist_v_3d - pol_b ) *&
1993                                               dist_v_3d + 1.0_wp ) * eps_factor
[1819]1994                            ENDIF
1995                            IF ( dist_w_3d <= eps_min2 ) THEN
[1864]1996                            torque_z(k,j,i) = torque_z(k,j,i) +                &
1997                                              torque_ring_z(ring,rseg) *       &
1998                                              ( ( pol_a * dist_w_3d - pol_b ) *&
1999                                               dist_w_3d + 1.0_wp ) * eps_factor
[1819]2000                            ENDIF
2001
2002                         ENDDO  ! End of loop over rseg
2003                      ENDDO     ! End of loop over ring
2004             
2005!
2006!--                   Rotation of force components:
[1912]2007                      rot_tend_x(k,j,i) = rot_tend_x(k,j,i) +                  &
[1864]2008                                      thrust(k,j,i)*rotx(inot,1) +             &
2009                                      torque_y(k,j,i)*roty(inot,1) +           &
[1819]2010                                      torque_z(k,j,i)*rotz(inot,1)
2011                               
[1912]2012                      rot_tend_y(k,j,i) = rot_tend_y(k,j,i) +                  &
[1864]2013                                      thrust(k,j,i)*rotx(inot,2) +             &
2014                                      torque_y(k,j,i)*roty(inot,2) +           &
[1819]2015                                      torque_z(k,j,i)*rotz(inot,2)
2016                               
[1912]2017                      rot_tend_z(k,j,i) = rot_tend_z(k,j,i) +                  &
[1864]2018                                      thrust(k,j,i)*rotx(inot,3) +             &
2019                                      torque_y(k,j,i)*roty(inot,3) +           &
[1819]2020                                      torque_z(k,j,i)*rotz(inot,3)                               
2021
2022                   ENDDO        ! End of loop over k
2023                ENDDO           ! End of loop over j
2024             ENDDO              ! End of loop over i
2025
[1864]2026             CALL cpu_log( log_point_s(63), 'wtm_smearing', 'stop' )         
[1819]2027                   
[1912]2028          ENDDO                  !-- end of loop over turbines
[1819]2029
2030               
2031          IF ( yaw_control )  THEN
2032!
2033!--          Allocate arrays for yaw control at first call
2034!--          Can't be allocated before dt_3d is set
2035             IF ( start_up )  THEN
[1864]2036                WDLON = NINT( 30.0_wp / dt_3d )  ! 30s running mean array
[1819]2037                ALLOCATE( wd30(1:nturbines,1:WDLON) )
[1912]2038                wd30 = 999.0_wp                  ! Set to dummy value
[1819]2039                ALLOCATE( wd30_l(1:WDLON) )
2040               
[1864]2041                WDSHO = NINT( 2.0_wp / dt_3d )   ! 2s running mean array
[1819]2042                ALLOCATE( wd2(1:nturbines,1:WDSHO) )
[1912]2043                wd2 = 999.0_wp                   ! Set to dummy value
[1819]2044                ALLOCATE( wd2_l(1:WDSHO) )
2045                start_up = .FALSE.
2046             ENDIF         
2047
2048!
2049!--          Calculate the inflow wind speed
2050!--
2051!--          Loop over number of turbines:
2052             DO inot = 1, nturbines
2053!
2054!--             Find processor at i_hub, j_hub             
[1912]2055                IF ( ( nxl <= i_hub(inot) )  .AND.  ( nxr >= i_hub(inot) ) )   &
2056                   THEN
2057                   IF ( ( nys <= j_hub(inot) )  .AND.  ( nyn >= j_hub(inot) ) )&
2058                      THEN
[1864]2059
[1819]2060                      u_inflow_l(inot) = u(k_hub(inot),j_hub(inot),i_hub(inot))
[1864]2061
[1912]2062                      wdir_l(inot) = -1.0_wp * ATAN2(                          &
2063                         0.5_wp * ( v(k_hub(inot),j_hub(inot),i_hub(inot)+1) + &
2064                                    v(k_hub(inot),j_hub(inot),i_hub(inot)) ) , &
2065                         0.5_wp * ( u(k_hub(inot),j_hub(inot)+1,i_hub(inot)) + &
2066                                    u(k_hub(inot),j_hub(inot),i_hub(inot)) ) )
[1864]2067
2068                      CALL wtm_yawcontrol( inot )
2069
[1819]2070                      phi_yaw_l(inot) = phi_yaw(inot)
2071
2072                   ENDIF
2073                ENDIF
2074                   
[1864]2075             ENDDO                                 !-- end of loop over turbines
2076
2077!
2078!--          Transfer of information to the other cpus           
2079             CALL MPI_ALLREDUCE( u_inflow_l, u_inflow, nturbines, MPI_REAL,    &
2080                                 MPI_SUM, comm2d, ierr )
2081             CALL MPI_ALLREDUCE( wdir_l, wdir, nturbines, MPI_REAL, MPI_SUM,   &
2082                                 comm2d, ierr )
2083             CALL MPI_ALLREDUCE( phi_yaw_l, phi_yaw, nturbines, MPI_REAL,      &
2084                                 MPI_SUM, comm2d, ierr )
[1819]2085             
2086             DO inot = 1, nturbines
[1864]2087!             
2088!--             Update rotor orientation               
2089                CALL wtm_rotate_rotor( inot )
[1819]2090
2091             ENDDO ! End of loop over turbines
2092                           
2093          END IF
[1864]2094         
2095          IF ( speed_control )  THEN
2096!
2097!--          Transfer of information to the other cpus
[1912]2098!              CALL MPI_ALLREDUCE( omega_gen, omega_gen_old, nturbines,        &
2099!                                  MPI_REAL,MPI_SUM, comm2d, ierr )
[1864]2100             CALL MPI_ALLREDUCE( torque_gen, torque_gen_old, nturbines,        &
2101                                 MPI_REAL, MPI_SUM, comm2d, ierr )
2102             CALL MPI_ALLREDUCE( omega_rot_l, omega_rot, nturbines,            &
2103                                 MPI_REAL, MPI_SUM, comm2d, ierr )
[1912]2104             CALL MPI_ALLREDUCE( omega_gen_f, omega_gen_f_old, nturbines,      &
2105                                 MPI_REAL, MPI_SUM, comm2d, ierr )
[1864]2106           
2107          ENDIF
[1819]2108
2109          DO inot = 1, nturbines
2110
2111             IF ( myid == 0 ) THEN
2112                IF ( openfile_turb_mod(400+inot)%opened )  THEN
2113                   WRITE ( 400+inot, 106 ) simulated_time, omega_rot(inot),    &
[1912]2114                             omega_gen(inot), torque_gen_old(inot),            &
[1864]2115                             torque_total(inot), pitch_add(inot),              &
[1912]2116                             torque_gen_old(inot)*omega_gen(inot)*gen_eff,     &
[1864]2117                             torque_total(inot)*omega_rot(inot)*air_dens,      &
[1912]2118                             thrust_rotor(inot),                               & 
[1864]2119                             wdir(inot)*180.0_wp/pi,                           &
2120                             (phi_yaw(inot))*180.0_wp/pi                   
[1912]2121                             
[1819]2122                ELSE
2123
2124                   WRITE ( turbine_id,'(I2.2)')  inot
[1864]2125                   OPEN ( 400+inot, FILE=( 'TURBINE_PARAMETERS'//turbine_id ), &
2126                                            FORM='FORMATTED' )
[1819]2127                   WRITE ( 400+inot, 105 ) inot
2128                   WRITE ( 400+inot, 106 ) simulated_time, omega_rot(inot),    &
[1912]2129                             omega_gen(inot), torque_gen_old(inot),            &
[1864]2130                             torque_total(inot), pitch_add(inot),              &
[1912]2131                             torque_gen_old(inot)*omega_gen(inot)*gen_eff,     &
[1864]2132                             torque_total(inot)*omega_rot(inot)*air_dens,      &
[1912]2133                             thrust_rotor(inot),                               & 
[1864]2134                             wdir(inot)*180.0_wp/pi,                           &                   
2135                             (phi_yaw(inot))*180.0_wp/pi
[1819]2136                ENDIF
2137             ENDIF
2138
[1912]2139!--          Set open flag
[1819]2140             openfile_turb_mod(400+inot)%opened = .TRUE.
[1864]2141          ENDDO                                    !-- end of loop over turbines
[1819]2142
2143       ENDIF
2144
[1864]2145       CALL cpu_log( log_point_s(61), 'wtm_forces', 'stop' )
[1819]2146       
[1912]2147!
2148!--    Formats
[1819]2149       105 FORMAT ('Turbine control data for turbine ',I2,1X,':'/ &
2150              &'----------------------------------------'/ &
2151              &'   Time   RSpeed  GSpeed  ', &
[1912]2152               'GenTorque  AeroTorque  Pitch  Power(Gen)  Power(Rot)  ',       &
2153               'RotThrust  WDirection  YawOrient')
[1819]2154
[1864]2155       106 FORMAT (F9.3,2X,F7.3,2X,F7.2,2X,F9.1,3X,F9.1,1X,F6.2,2X,F10.1,2X,   &
2156                   F10.1,1X,F9.1,2X,F7.2,1X,F7.2)
[1819]2157
2158
2159    END SUBROUTINE wtm_forces
2160
2161   
[1839]2162!------------------------------------------------------------------------------!
2163! Description:
2164! ------------
2165!> Yaw controller for the wind turbine model
2166!------------------------------------------------------------------------------!
2167    SUBROUTINE wtm_yawcontrol( inot )
2168   
[1819]2169       USE constants
2170       USE kinds
[1839]2171               
2172       IMPLICIT NONE
[1819]2173     
2174       INTEGER(iwp)             :: inot
2175       INTEGER(iwp)             :: i_wd_30
2176       REAL(wp)                 :: missal
2177
2178       i_wd_30 = 0_iwp
2179
2180
[1864]2181!--    The yaw controller computes a 30s running mean of the wind direction.
2182!--    If the difference between turbine alignment and wind direction exceeds
2183!--    5°, the turbine is yawed. The mechanism stops as soon as the 2s-running
2184!--    mean of the missalignment is smaller than 0.5°.
2185!--    Attention: If the timestep during the simulation changes significantly
2186!--    the lengths of the running means change and it does not correspond to
2187!--    30s/2s anymore.
2188!--    ! Needs to be modified for these situations !
2189!--    For wind from the east, the averaging of the wind direction could cause
2190!--    problems and the yaw controller is probably flawed. -> Routine for
2191!--    averaging needs to be improved!
2192!
2193!--    Check if turbine is not yawing
[1819]2194       IF ( .NOT. doyaw(inot) )  THEN
[1843]2195!
[1864]2196!--       Write current wind direction into array
[1843]2197          wd30_l    = wd30(inot,:)
2198          wd30_l    = CSHIFT( wd30_l, SHIFT=-1 )
[1819]2199          wd30_l(1) = wdir(inot)
[1843]2200!
[1864]2201!--       Check if array is full ( no more dummies )
[1819]2202          IF ( .NOT. ANY( wd30_l == 999.) ) THEN
2203
2204             missal = SUM( wd30_l ) / SIZE( wd30_l ) - phi_yaw(inot)
2205!
[1864]2206!--          Check if turbine is missaligned by more than max_miss
[1843]2207             IF ( ABS( missal ) > max_miss )  THEN
2208!
[1864]2209!--             Check in which direction to yaw         
[1843]2210                yawdir(inot) = SIGN( 1.0_wp, missal )
[1819]2211!
[1864]2212!--             Start yawing of turbine
[1843]2213                phi_yaw(inot) = phi_yaw(inot) + yawdir(inot) * yaw_speed * dt_3d
[1819]2214                doyaw(inot) = .TRUE.
[1864]2215                wd30_l = 999.  ! fill with dummies again
[1819]2216             ENDIF
2217          ENDIF
2218         
2219          wd30(inot,:) = wd30_l
2220
2221!     
[1864]2222!--    If turbine is already yawing:
2223!--    Initialize 2 s running mean and yaw until the missalignment is smaller
2224!--    than min_miss
[1819]2225
2226       ELSE
2227!
2228!--       Initialize 2 s running mean
2229          wd2_l = wd2(inot,:)
[1864]2230          wd2_l = CSHIFT( wd2_l, SHIFT = -1 )
[1819]2231          wd2_l(1) = wdir(inot)
[1843]2232!     
[1864]2233!--       Check if array is full ( no more dummies )
2234          IF ( .NOT. ANY( wd2_l == 999.0_wp ) ) THEN
2235!
2236!--          Calculate missalignment of turbine       
[1819]2237             missal = SUM( wd2_l - phi_yaw(inot) ) / SIZE( wd2_l )
[1864]2238!
2239!--          Check if missalignment is still larger than 0.5 degree and if the
2240!--          yaw direction is still right
2241             IF ( ( ABS( missal ) > min_miss )  .AND.                          &
2242                  ( yawdir(inot) == SIGN( 1.0_wp, missal ) ) )  THEN
2243!
2244!--             Continue yawing       
2245                phi_yaw(inot) = phi_yaw(inot) + yawdir(inot) * yaw_speed * dt_3d
[1819]2246             ELSE
[1864]2247!
2248!--             Stop yawing       
[1819]2249                doyaw(inot) = .FALSE.
[1864]2250                wd2_l = 999.0_wp ! fill with dummies again
[1819]2251             ENDIF
2252          ELSE
[1864]2253!
2254!--          Continue yawing
[1843]2255             phi_yaw(inot) = phi_yaw(inot) + yawdir(inot) * yaw_speed * dt_3d
[1819]2256          ENDIF
2257     
2258          wd2(inot,:) = wd2_l
2259           
2260       ENDIF
2261     
[1839]2262    END SUBROUTINE wtm_yawcontrol 
[1819]2263
[1864]2264
[1819]2265!------------------------------------------------------------------------------!
2266! Description:
2267! ------------
[1864]2268!> Initialization of the speed control
2269!------------------------------------------------------------------------------!
2270    SUBROUTINE wtm_init_speed_control
2271
2272
2273       IMPLICIT NONE
2274
2275!
2276!--    If speed control is set, remaining variables and control_parameters for
2277!--    the control algorithm are calculated
2278!
2279!--    Calculate slope constant for region 15
2280       slope15   = ( slope2 * min_reg2 * min_reg2 ) / ( min_reg2 - min_reg15 )
2281!
2282!--    Calculate upper limit of slipage region
2283       vs_sysp   = rated_genspeed / 1.1_wp
2284!
2285!--    Calculate slope of slipage region
2286       slope25   = ( rated_power / rated_genspeed ) /                          &
2287                   ( rated_genspeed - vs_sysp )
2288!
2289!--    Calculate lower limit of slipage region
2290       min_reg25 = ( slope25 - SQRT( slope25 * ( slope25 - 4.0_wp *            &
2291                                                 slope2 * vs_sysp ) ) ) /      &
2292                   ( 2.0_wp * slope2 )
2293!
2294!--    Frequency for the simple low pass filter
2295       Fcorner   = 0.25_wp
2296!
2297!--    At the first timestep the torque is set to its maximum to prevent
2298!--    an overspeeding of the rotor
2299       torque_gen_old(:) = max_torque_gen 
2300     
2301    END SUBROUTINE wtm_init_speed_control
2302
2303
2304!------------------------------------------------------------------------------!
2305! Description:
2306! ------------
2307!> Simple controller for the regulation of the rotor speed
2308!------------------------------------------------------------------------------!
2309    SUBROUTINE wtm_speed_control( inot )
2310
2311
2312       IMPLICIT NONE
2313
[1912]2314       INTEGER(iwp)             :: inot
2315       
2316         
[1864]2317
2318!
2319!--    The controller is based on the fortran script from Jonkman
2320!--    et al. 2009 "Definition of a 5 MW Reference Wind Turbine for
2321!--    offshore system developement"
2322
2323!
2324!--    The generator speed is filtered by a low pass filter
2325!--    for the control of the generator torque       
2326       lp_coeff = EXP( -2.0_wp * 3.14_wp * dt_3d * Fcorner )
[1912]2327       omega_gen_f(inot) = ( 1.0_wp - lp_coeff ) * omega_gen(inot) + lp_coeff *&
[1864]2328                           omega_gen_f_old(inot)
2329
2330       IF ( omega_gen_f(inot) <= min_reg15 )  THEN
2331!                       
2332!--       Region 1: Generator torque is set to zero to accelerate the rotor:
2333          torque_gen(inot) = 0
2334       
2335       ELSEIF ( omega_gen_f(inot) <= min_reg2 )  THEN
2336!                       
2337!--       Region 1.5: Generator torque is increasing linearly with rotor speed:
2338          torque_gen(inot) = slope15 * ( omega_gen_f(inot) - min_reg15 )
2339                         
2340       ELSEIF ( omega_gen_f(inot) <= min_reg25 )  THEN
2341!
2342!--       Region 2: Generator torque is increased by the square of the generator
2343!--                 speed to keep the TSR optimal:
2344          torque_gen(inot) = slope2 * omega_gen_f(inot) * omega_gen_f(inot)
2345       
2346       ELSEIF ( omega_gen_f(inot) < rated_genspeed )  THEN
2347!                       
2348!--       Region 2.5: Slipage region between 2 and 3:
2349          torque_gen(inot) = slope25 * ( omega_gen_f(inot) - vs_sysp )
2350       
2351       ELSE
2352!                       
2353!--       Region 3: Generator torque is antiproportional to the rotor speed to
2354!--                 keep the power constant:
2355          torque_gen(inot) = rated_power / omega_gen_f(inot)
2356       
2357       ENDIF
2358!                       
2359!--    Calculate torque rate and confine with a max
2360       trq_rate = ( torque_gen(inot) - torque_gen_old(inot) ) / dt_3d
2361       trq_rate = MIN( MAX( trq_rate, -1.0_wp * max_trq_rate ), max_trq_rate )
2362!                       
2363!--    Calculate new gen torque and confine with max torque                         
2364       torque_gen(inot) = torque_gen_old(inot) + trq_rate * dt_3d
2365       torque_gen(inot) = MIN( torque_gen(inot), max_torque_gen )                                             
2366!
2367!--    Overwrite values for next timestep                       
[1912]2368       omega_rot_l(inot) = omega_gen(inot) / gear_ratio
[1864]2369
2370   
2371    END SUBROUTINE wtm_speed_control   
2372
2373
2374!------------------------------------------------------------------------------!
2375! Description:
2376! ------------
[1839]2377!> Application of the additional forces generated by the wind turbine on the
2378!> flow components (tendency terms)
2379!> Call for all grid points
[1819]2380!------------------------------------------------------------------------------!
2381    SUBROUTINE wtm_tendencies( component )
2382
[1839]2383   
[1819]2384       IMPLICIT NONE
2385
[1839]2386       INTEGER(iwp) ::  component   !< prognostic variable (u,v,w)
2387       INTEGER(iwp) ::  i           !< running index
2388       INTEGER(iwp) ::  j           !< running index
2389       INTEGER(iwp) ::  k           !< running index
[1819]2390
2391
2392       SELECT CASE ( component )
2393
2394       CASE ( 1 )
2395!
2396!--       Apply the x-component of the force to the u-component of the flow:
[1864]2397          IF ( simulated_time >= time_turbine_on )  THEN
[1819]2398             DO  i = nxlg, nxrg
2399                DO  j = nysg, nyng
2400                   DO  k = nzb_u_inner(j,i)+1, k_hub(1) + k_smear(1)
2401!
[1864]2402!--                   Calculate the thrust generated by the nacelle and the tower
[1912]2403                      tend_nac_x = 0.5_wp * nac_cd_surf(k,j,i) *               &
[1819]2404                                         SIGN( u(k,j,i)**2 , u(k,j,i) )     
[1912]2405                      tend_tow_x   = 0.5_wp * tow_cd_surf(k,j,i) *             &
[1819]2406                                         SIGN( u(k,j,i)**2 , u(k,j,i) ) 
2407                                                   
[1912]2408                      tend(k,j,i) = tend(k,j,i) - rot_tend_x(k,j,i)            &
2409                                  - tend_nac_x - tend_tow_x
[1819]2410                   ENDDO
2411                ENDDO
2412             ENDDO
2413          ENDIF
2414
2415       CASE ( 2 )
2416!
2417!--       Apply the y-component of the force to the v-component of the flow:
[1864]2418          IF ( simulated_time >= time_turbine_on )  THEN
[1819]2419             DO  i = nxlg, nxrg
2420                DO  j = nysg, nyng
2421                   DO  k = nzb_v_inner(j,i)+1, k_hub(1) + k_smear(1)
[1912]2422                      tend_nac_y = 0.5_wp * nac_cd_surf(k,j,i) *               &
[1819]2423                                         SIGN( v(k,j,i)**2 , v(k,j,i) )     
[1912]2424                      tend_tow_y   = 0.5_wp * tow_cd_surf(k,j,i) *             &
[1819]2425                                         SIGN( v(k,j,i)**2 , v(k,j,i) )                     
[1912]2426                      tend(k,j,i) = tend(k,j,i) - rot_tend_y(k,j,i)            &
2427                                  - tend_nac_y - tend_tow_y
[1819]2428                   ENDDO
2429                ENDDO
2430             ENDDO
2431          ENDIF
2432
2433       CASE ( 3 )
2434!
2435!--       Apply the z-component of the force to the w-component of the flow:
[1864]2436          IF ( simulated_time >= time_turbine_on )  THEN
[1819]2437             DO  i = nxlg, nxrg
2438                DO  j = nysg, nyng
2439                   DO  k = nzb_w_inner(j,i)+1,  k_hub(1) + k_smear(1)
[1912]2440                      tend(k,j,i) = tend(k,j,i) - rot_tend_z(k,j,i)
[1819]2441                   ENDDO
2442                ENDDO
2443             ENDDO
2444          ENDIF
2445
2446
2447       CASE DEFAULT
2448
2449          WRITE( message_string, * ) 'unknown prognostic variable: ', component
2450          CALL message( 'wtm_tendencies', 'PA04??', 1, 2, 0, 6, 0 ) 
2451
2452       END SELECT
2453
2454
2455    END SUBROUTINE wtm_tendencies
2456
2457
2458!------------------------------------------------------------------------------!
2459! Description:
2460! ------------
[1839]2461!> Application of the additional forces generated by the wind turbine on the
2462!> flow components (tendency terms)
2463!> Call for grid point i,j
[1819]2464!------------------------------------------------------------------------------!
2465    SUBROUTINE wtm_tendencies_ij( i, j, component )
2466
2467
2468       IMPLICIT NONE
2469
[1839]2470       INTEGER(iwp) ::  component   !< prognostic variable (u,v,w)
2471       INTEGER(iwp) ::  i           !< running index
2472       INTEGER(iwp) ::  j           !< running index
2473       INTEGER(iwp) ::  k           !< running index
[1819]2474
2475       SELECT CASE ( component )
2476
2477       CASE ( 1 )
2478!
2479!--       Apply the x-component of the force to the u-component of the flow:
[1839]2480          IF ( simulated_time >= time_turbine_on )  THEN
[1819]2481
2482             DO  k = nzb_u_inner(j,i)+1,  k_hub(1) + k_smear(1)
2483!
[1839]2484!--             Calculate the thrust generated by the nacelle and the tower
[1912]2485                tend_nac_x = 0.5_wp * nac_cd_surf(k,j,i) *                     &
[1819]2486                                   SIGN( u(k,j,i)**2 , u(k,j,i) )     
[1912]2487                tend_tow_x   = 0.5_wp * tow_cd_surf(k,j,i) *                   &
[1819]2488                                   SIGN( u(k,j,i)**2 , u(k,j,i) ) 
[1912]2489                tend(k,j,i) = tend(k,j,i) - rot_tend_x(k,j,i)                  &
2490                            - tend_nac_x - tend_tow_x
[1819]2491             ENDDO
2492          ENDIF
2493
2494       CASE ( 2 )
2495!
2496!--       Apply the y-component of the force to the v-component of the flow:
[1839]2497          IF ( simulated_time >= time_turbine_on )  THEN
[1819]2498             DO  k = nzb_v_inner(j,i)+1,  k_hub(1) + k_smear(1)
[1912]2499                tend_nac_y = 0.5_wp * nac_cd_surf(k,j,i) *                     &
[1819]2500                                   SIGN( v(k,j,i)**2 , v(k,j,i) )     
[1912]2501                tend_tow_y   = 0.5_wp * tow_cd_surf(k,j,i) *                   &
[1819]2502                                   SIGN( v(k,j,i)**2 , v(k,j,i) )                     
[1912]2503                tend(k,j,i) = tend(k,j,i) - rot_tend_y(k,j,i)                  &
2504                            - tend_nac_y - tend_tow_y
[1819]2505             ENDDO
2506          ENDIF
2507
2508       CASE ( 3 )
2509!
2510!--       Apply the z-component of the force to the w-component of the flow:
[1839]2511          IF ( simulated_time >= time_turbine_on )  THEN
[1819]2512             DO  k = nzb_w_inner(j,i)+1,  k_hub(1) + k_smear(1)
[1912]2513                tend(k,j,i) = tend(k,j,i) - rot_tend_z(k,j,i)
[1819]2514             ENDDO
2515          ENDIF
2516
2517
2518       CASE DEFAULT
2519
2520          WRITE( message_string, * ) 'unknown prognostic variable: ', component
2521          CALL message( 'wtm_tendencies', 'PA04??', 1, 2, 0, 6, 0 ) 
2522
2523       END SELECT
2524
2525
2526    END SUBROUTINE wtm_tendencies_ij
2527
2528 END MODULE wind_turbine_model_mod
Note: See TracBrowser for help on using the repository browser.