Index: palm/trunk/SOURCE/wind_turbine_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 2553)
+++ palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 2563)
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Restart runs with wind turbine model are possible now. For this purpose, two 
+! new subroutines wtm_write_restart_data and wtm_read_restart_data had to be 
+! defined
+! 
+! 2553 2017-10-18 08:03:45Z Giersch
 ! Bugfix of vertical loop in wtm_tendencies to account for different turbine 
 ! heights, bugfix of the interpolation of the u-component concerning the 
@@ -104,5 +109,6 @@
 
     USE control_parameters,                                                    &
-        ONLY:  dt_3d, dz, message_string, simulated_time
+        ONLY:  dt_3d, dz, message_string, simulated_time, wind_turbine,        & 
+               initializing_actions
 
     USE cpulog,                                                                &
@@ -124,6 +130,4 @@
 
     PRIVATE
-
-    LOGICAL ::  wind_turbine=.FALSE.   !< switch for use of wind turbine model
 
 !
@@ -265,7 +269,5 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  alpha_attack !< 
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  chord        !< 
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  omega_gen    !< curr. generator speed
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  phi_rel      !< 
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  pitch_add_old!<
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  torque_total !<
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  thrust_rotor !<
@@ -337,12 +339,7 @@
     REAL(wp) ::  vs_sysp             !< 
     REAL(wp) ::  lp_coeff            !< coeff for the controller low pass filter 
-    
-    REAL(wp), DIMENSION(:), ALLOCATABLE :: omega_gen_old   !< last gen. speed
-    REAL(wp), DIMENSION(:), ALLOCATABLE :: omega_gen_f     !< filtered gen. sp
-    REAL(wp), DIMENSION(:), ALLOCATABLE :: omega_gen_f_old !< last filt. gen. sp
-    REAL(wp), DIMENSION(:), ALLOCATABLE :: torque_gen      !< generator torque
-    REAL(wp), DIMENSION(:), ALLOCATABLE :: torque_gen_old  !< last gen. torque
 
     REAL(wp), DIMENSION(100) :: omega_rot_l = 0.0_wp !< local rot speed [rad/s]
+
 !
 !-- Fixed variables for the yaw controller
@@ -362,4 +359,14 @@
     INTEGER(iwp)                          ::  WDSHO            !<
 
+!
+!-- Variables that have to be saved in the binary file for restarts
+    REAL(wp), DIMENSION(1:100) ::  pitch_add_old           = 0.0_wp  !< old constant pitch angle
+    REAL(wp), DIMENSION(1:100) ::  omega_gen               = 0.0_wp  !< curr. generator speed
+    REAL(wp), DIMENSION(1:100) ::  omega_gen_f             = 0.0_wp  !< filtered generator speed
+    REAL(wp), DIMENSION(1:100) ::  omega_gen_old           = 0.0_wp  !< last generator speed
+    REAL(wp), DIMENSION(1:100) ::  omega_gen_f_old         = 0.0_wp  !< last filtered generator speed
+    REAL(wp), DIMENSION(1:100) ::  torque_gen              = 0.0_wp  !< generator torque
+    REAL(wp), DIMENSION(1:100) ::  torque_gen_old          = 0.0_wp  !< last generator torque
+
 
     SAVE
@@ -369,4 +376,12 @@
        MODULE PROCEDURE wtm_parin
     END INTERFACE wtm_parin
+
+    INTERFACE wtm_write_restart_data 
+       MODULE PROCEDURE wtm_write_restart_data 
+    END INTERFACE wtm_write_restart_data
+
+    INTERFACE wtm_read_restart_data 
+       MODULE PROCEDURE wtm_read_restart_data
+    END INTERFACE wtm_read_restart_data 
     
     INTERFACE wtm_check_parameters
@@ -410,5 +425,6 @@
     
     PUBLIC wtm_check_parameters, wtm_forces, wtm_init, wtm_init_arrays,        &
-           wtm_parin, wtm_tendencies, wind_turbine 
+           wtm_parin, wtm_write_restart_data, wtm_tendencies
+
 
  CONTAINS
@@ -467,4 +483,8 @@
        wind_turbine = .TRUE.
 
+       IF ( TRIM( initializing_actions ) == 'read_restart_data' ) THEN
+          CALL wtm_read_restart_data
+       ENDIF
+
  10    CONTINUE   ! TBD Change from continue, mit ierrn machen
 
@@ -472,4 +492,93 @@
     END SUBROUTINE wtm_parin
 
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine writes the respective restart data.
+!------------------------------------------------------------------------------!
+    SUBROUTINE wtm_write_restart_data  
+
+       IMPLICIT NONE
+       
+       WRITE ( 14 )  'omega_gen                     '
+       WRITE ( 14 )  omega_gen
+       WRITE ( 14 )  'omega_gen_f                   '
+       WRITE ( 14 )  omega_gen_f
+       WRITE ( 14 )  'omega_gen_f_old               '
+       WRITE ( 14 )  omega_gen_f_old
+       WRITE ( 14 )  'omega_gen_old                 '
+       WRITE ( 14 )  omega_gen_old
+       WRITE ( 14 )  'omega_rot                     '
+       WRITE ( 14 )  omega_rot
+       WRITE ( 14 )  'phi_yaw                       '
+       WRITE ( 14 )  phi_yaw(:)
+       WRITE ( 14 )  'pitch_add                     '
+       WRITE ( 14 )  pitch_add
+       WRITE ( 14 )  'pitch_add_old                 '
+       WRITE ( 14 )  pitch_add_old
+       WRITE ( 14 )  'torque_gen                    '
+       WRITE ( 14 )  torque_gen
+       WRITE ( 14 )  'torque_gen_old                '
+       WRITE ( 14 )  torque_gen_old
+     
+       WRITE ( 14 )  '*** end wtm ***               '
+       
+    END SUBROUTINE wtm_write_restart_data    
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine reads the respective restart data.
+!------------------------------------------------------------------------------!
+ SUBROUTINE wtm_read_restart_data
+
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=30) ::  variable_chr  !< dummy variable to read string
+
+
+    READ ( 13 )  variable_chr
+    DO  WHILE ( TRIM( variable_chr ) /= '*** end wtm ***' )
+
+       SELECT CASE ( TRIM( variable_chr ) )
+
+          CASE ( 'omega_gen' )
+             READ ( 13 )  omega_gen
+          CASE ( 'omega_gen_f' )
+             READ ( 13 )  omega_gen_f
+          CASE ( 'omega_gen_old' )
+             READ ( 13 )  omega_gen_old
+          CASE ( 'omega_gen_f_old' )
+             READ ( 13 )  omega_gen_f_old
+          CASE ( 'omega_rot' )
+             READ ( 13 )  omega_rot
+          CASE ( 'phi_yaw' )
+             READ ( 13 )  phi_yaw
+          CASE ( 'pitch_add' )
+             READ ( 13 )  pitch_add
+          CASE ( 'pitch_add_old' )
+             READ ( 13 )  pitch_add_old
+          CASE ( 'torque_gen' )
+             READ ( 13 )  torque_gen
+          CASE ( 'torque_gen_old' )
+             READ ( 13 )  torque_gen_old
+
+       END SELECT
+
+       READ ( 13 )  variable_chr
+
+    ENDDO
+
+ END SUBROUTINE wtm_read_restart_data
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check namelist parameter
+!------------------------------------------------------------------------------!
     SUBROUTINE wtm_check_parameters
 
@@ -594,14 +703,4 @@
 
 !
-!--    Allocation of the 1D arrays for speed pitch_control
-       ALLOCATE( omega_gen(1:nturbines) )
-       ALLOCATE( omega_gen_old(1:nturbines) )
-       ALLOCATE( omega_gen_f(1:nturbines) )
-       ALLOCATE( omega_gen_f_old(1:nturbines) )
-       ALLOCATE( pitch_add_old(1:nturbines) )
-       ALLOCATE( torque_gen(1:nturbines) )
-       ALLOCATE( torque_gen_old(1:nturbines) )
-
-!
 !--    Allocation of the 1D arrays for yaw control
        ALLOCATE( yawdir(1:nturbines) )
@@ -672,12 +771,14 @@
        thrust_rotor(:)          = 0.0_wp
 
-       omega_gen(:)             = 0.0_wp
-       omega_gen_old(:)         = 0.0_wp
-       omega_gen_f(:)           = 0.0_wp
-       omega_gen_f_old(:)       = 0.0_wp
-       pitch_add_old(:)         = 0.0_wp
-       torque_gen(:)            = 0.0_wp
-       torque_gen_old(:)        = 0.0_wp
-       
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN
+          omega_gen(:)             = 0.0_wp
+          omega_gen_old(:)         = 0.0_wp
+          omega_gen_f(:)           = 0.0_wp
+          omega_gen_f_old(:)       = 0.0_wp
+          pitch_add_old(:)         = 0.0_wp
+          torque_gen(:)            = 0.0_wp
+          torque_gen_old(:)        = 0.0_wp
+       ENDIF
+
        yawdir(:)                = 0.0_wp
        wdir(:)                  = 0.0_wp
@@ -776,4 +877,44 @@
           CALL wtm_speed_control
 
+          IF ( TRIM( initializing_actions ) == 'read_restart_data' ) THEN
+
+             DO inot = 1, nturbines
+
+                IF ( nxl > i_hub(inot) ) THEN
+                   torque_gen(inot) = 0.0_wp
+                   omega_gen_f(inot) = 0.0_wp
+                   omega_rot_l(inot) = 0.0_wp
+                ENDIF
+
+                IF ( nxr < i_hub(inot) ) THEN
+                   torque_gen(inot) = 0.0_wp
+                   omega_gen_f(inot) = 0.0_wp
+                   omega_rot_l(inot) = 0.0_wp
+                ENDIF
+
+                IF ( nys > j_hub(inot) ) THEN
+                   torque_gen(inot) = 0.0_wp
+                   omega_gen_f(inot) = 0.0_wp
+                   omega_rot_l(inot) = 0.0_wp
+                ENDIF
+
+                IF ( nyn < j_hub(inot) ) THEN
+                   torque_gen(inot) = 0.0_wp
+                   omega_gen_f(inot) = 0.0_wp
+                   omega_rot_l(inot) = 0.0_wp
+                ENDIF
+
+                IF ( ( nxl <= i_hub(inot) ) .AND. ( nxr >= i_hub(inot) ) ) THEN
+                   IF ( ( nys <= j_hub(inot) ) .AND. ( nyn >= j_hub(inot) ) ) THEN
+
+                      omega_rot_l(inot) = omega_gen(inot) / gear_ratio
+
+                   ENDIF
+                ENDIF
+
+             END DO
+
+          ENDIF
+
        ENDIF
 
@@ -814,5 +955,7 @@
 !
 !--    Change yaw angle to rad:
-       phi_yaw(:) = phi_yaw(:) * pi / 180.0_wp
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN
+          phi_yaw(:) = phi_yaw(:) * pi / 180.0_wp
+       ENDIF
 
 
@@ -2366,5 +2509,7 @@
 !--    At the first timestep the torque is set to its maximum to prevent
 !--    an overspeeding of the rotor
-       torque_gen_old(:) = max_torque_gen  
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN
+          torque_gen_old(:) = max_torque_gen
+       ENDIF  
      
     END SUBROUTINE wtm_init_speed_control
