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

Last change on this file since 2341 was 2341, checked in by Giersch, 7 years ago

Unit correction in Doxygen comments

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