Index: /palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 2944)
+++ /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 2945)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! - Mimic for topography input slightly revised, in order to enable consistency 
+!   checks
+! - Add checks for dimensions in dynamic input file and move already existing
+!   checks 
+! 
+! 2938 2018-03-27 15:52:42Z suehring
 ! Initial read of geostrophic wind components from dynamic driver. 
 ! 
@@ -104,6 +110,8 @@
        INTEGER(iwp) :: nx                             !< dimension length in x
        INTEGER(iwp) :: ny                             !< dimension length in y
+       INTEGER(iwp) :: nz                             !< dimension length in z
        REAL(wp), DIMENSION(:), ALLOCATABLE :: x       !< dimension array in x
        REAL(wp), DIMENSION(:), ALLOCATABLE :: y       !< dimension array in y
+       REAL(wp), DIMENSION(:), ALLOCATABLE :: z       !< dimension array in z
     END TYPE dims_xy
 !
@@ -316,5 +324,5 @@
 !
 !-- Define variables
-    TYPE(dims_xy)    ::  dim_static !< data structure for x, y-dimension in static input file
+    TYPE(dims_xy)    ::  dim_static  !< data structure for x, y-dimension in static input file
 
     TYPE(force_type) ::  force     !< data structure for data input at lateral and top boundaries (provided by Inifor)  
@@ -1672,5 +1680,4 @@
        REAL(wp) ::  dum           !< dummy variable to skip columns while reading topography file   
 
-       IF ( TRIM( topography ) /= 'read_from_file' )  RETURN
 
        DO  ii = 0, io_blocks-1
@@ -1695,5 +1702,5 @@
                 CALL inquire_variable_names( id_topo, var_names )
 !
-!--             Read x, y - dimensions
+!--             Read x, y - dimensions. Only required for consistency checks.
                 CALL get_dimension_length( id_topo, dim_static%nx, 'x' )
                 CALL get_dimension_length( id_topo, dim_static%ny, 'y' )
@@ -1830,5 +1837,5 @@
 !
 !--          ASCII input
-             ELSE
+             ELSEIF ( TRIM( topography ) == 'read_from_file' )  THEN
 
                 OPEN( 90, FILE='TOPOGRAPHY_DATA'//TRIM( coupling_char ),       &
@@ -2013,13 +2020,4 @@
              CALL get_dimension_length( id_dynamic, init_3d%ny,  'y'  )
              CALL get_dimension_length( id_dynamic, init_3d%nyv, 'yv' )
-!
-!--          Check for correct horizontal dimension. Please note, u- and v-grid
-!--          hase 1 grid point less on Inifor grid. 
-             IF ( init_3d%nx-1 /= nx  .OR.  init_3d%nxu-1 /= nx - 1  .OR.      &
-                  init_3d%ny-1 /= ny  .OR.  init_3d%nyv-1 /= ny - 1 )  THEN
-                message_string = 'Number of inifor grid points does not '  //  &
-                                 'match the number of numeric grid points.'
-                CALL message( 'netcdf_data_input_mod', 'NDI003', 1, 2, 0, 6, 0 )
-             ENDIF
 !
 !--          Read vertical dimensions. Later, these are required for eventual
@@ -2376,5 +2374,5 @@
 
        USE indices,                                                            &
-           ONLY:  nx, nxl, nxlu, nxr, ny, nyn, nys, nysv, nzb, nzt
+           ONLY:  nxl, nxlu, nxr, nyn, nys, nysv, nzb, nzt
 
        IMPLICIT NONE
@@ -2780,4 +2778,7 @@
            ONLY:  initializing_actions, forcing, message_string
 
+       USE indices,                                                            &
+           ONLY:  nx, ny, nz
+
        IMPLICIT NONE
 
@@ -2798,4 +2799,19 @@
                            TRIM( coupling_char )
           CALL message( 'netcdf_data_input_mod', 'NDI010', 1, 2, 0, 6, 0 )
+       ENDIF
+!
+!--    Check for correct horizontal and vertical dimension. 
+!--    Please note, u- and v-grid has 1 grid point less on Inifor grid. 
+       IF ( init_3d%nx-1 /= nx  .OR.  init_3d%nxu-1 /= nx - 1  .OR.            &
+            init_3d%ny-1 /= ny  .OR.  init_3d%nyv-1 /= ny - 1 )  THEN
+          message_string = 'Number of inifor horizontal grid points does '  // &
+                           'not match the number of numeric grid points.'
+          CALL message( 'netcdf_data_input_mod', 'NDI003', 1, 2, 0, 6, 0 )
+       ENDIF
+
+       IF ( init_3d%nzu /= nz )  THEN
+          message_string = 'Number of inifor vertical grid points does '  // &
+                           'not match the number of numeric grid points.'
+          CALL message( 'netcdf_data_input_mod', 'NDI003', 1, 2, 0, 6, 0 )
        ENDIF
 
Index: /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90
===================================================================
--- /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 2944)
+++ /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 2945)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! - Bugfix in parallelization of synthetic turbulence generator in case the 
+!   z-dimension is not an integral divisor of the number of processors along  
+!   the x- and y-dimension
+! - Revision in control mimic in case of RAN-LES nesting 
+! 
+! 2938 2018-03-27 15:52:42Z suehring
 ! Apply turbulence generator at all non-cyclic lateral boundaries in case of 
 ! realistic Inifor large-scale forcing or RANS-LES nesting 
@@ -87,4 +93,5 @@
 !>       enable cyclic_fill
 !>       implement turbulence generation for e and pt
+!> @todo Input of height-constant length scales via namelist
 !> @note <Enter notes on the module>
 !> @bug  Height information from input file is not used. Profiles from input
@@ -388,5 +395,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  coupling_char, dz, e_init, forcing, nest_domain
+        ONLY:  coupling_char, dz, e_init, forcing, nest_domain, rans_mode
 
     USE grid_variables,                                                        &
@@ -395,4 +402,7 @@
     USE indices,                                                               &
         ONLY:  nz
+
+    USE pmc_interface,                                                         &
+        ONLY : rans_mode_parent
 
 
@@ -411,5 +421,4 @@
     INTEGER(iwp) :: newtype                  !< dummy MPI type
     INTEGER(iwp) :: realsize                 !< size of REAL variables
-    INTEGER(iwp) :: nnz                      !< increment used to determine processor decomposition of z-axis along x and y direction  
     INTEGER(iwp) :: nseed                    !< dimension of random number seed
     INTEGER(iwp) :: startseed = 1234567890   !< start seed for random number generator
@@ -431,4 +440,5 @@
     REAL(wp) :: lwy     !< length scale for w in y direction
     REAL(wp) :: lwz     !< length scale for w in z direction
+    REAL(wp) :: nnz     !< increment used to determine processor decomposition of z-axis along x and y direction  
     REAL(wp) :: zz      !< height
 
@@ -463,17 +473,20 @@
 !-- Determine processor decomposition of z-axis along x- and y-direction
     nnz = nz / pdims(1)
-    nzb_x_stg = 1 + myidx * nnz
-    nzt_x_stg = ( myidx + 1 ) * nnz
+    nzb_x_stg = 1 + myidx * INT( nnz )
+    nzt_x_stg = ( myidx + 1 ) * INT( nnz )
 
     IF ( MOD( nz , pdims(1) ) /= 0  .AND.  myidx == id_stg_right )             &  
-       nzt_x_stg = myidx * nnz + MOD( nz , pdims(1) )
-
-    IF ( forcing  .OR.  nest_domain )  THEN
+       nzt_x_stg = nzt_x_stg + myidx * ( nnz - INT( nnz ) )
+!        nzt_x_stg = myidx * nnz + MOD( nz , pdims(1) )
+
+    IF ( forcing  .OR.  ( nest_domain .AND.  rans_mode_parent  .AND.           &
+                   .NOT.  rans_mode ) )  THEN
        nnz = nz / pdims(2)
-       nzb_y_stg = 1 + myidy * nnz
-       nzt_y_stg = ( myidy + 1 ) * nnz
-
-       IF ( MOD( nz , pdims(2) ) /= 0  .AND.  myidy == id_stg_north )          &  
-          nzt_y_stg = myidy * nnz + MOD( nz , pdims(2) )
+       nzb_y_stg = 1 + myidy * INT( nnz )
+       nzt_y_stg = ( myidy + 1 ) * INT( nnz )
+
+       IF ( MOD( nz , pdims(2) ) /= 0  .AND.  myidy == id_stg_north )          &
+          nzt_y_stg = nzt_y_stg + myidy * ( nnz - INT( nnz ) )  
+!           nzt_y_stg = myidy * nnz + MOD( nz , pdims(2) )
     ENDIF
 
@@ -494,5 +507,5 @@
 
     ! stg_type_yz_small: yz-slice with vertical bounds nzb_x_stg:nzt_x_stg+1
-    CALL MPI_TYPE_CREATE_SUBARRAY( 2, [nzt_x_stg-nzb_x_stg+2,nyng-nysg+1],             &
+    CALL MPI_TYPE_CREATE_SUBARRAY( 2, [nzt_x_stg-nzb_x_stg+2,nyng-nysg+1],     &
             [1,nyng-nysg+1], [0,0], MPI_ORDER_FORTRAN, MPI_REAL, newtype, ierr )
     CALL MPI_TYPE_CREATE_RESIZED( newtype, tob, extent, stg_type_yz_small, ierr )
@@ -513,6 +526,7 @@
 !-- layer 
 !-- stg_type_xz: xz-slice with vertical bounds nzb:nzt+1
-    IF ( forcing  .OR.  nest_domain)  THEN
-       CALL MPI_TYPE_CREATE_SUBARRAY( 2, [nzt-nzb+2,nxrg-nxlg+1],                 &
+    IF ( forcing  .OR.  ( nest_domain .AND.  rans_mode_parent  .AND.           &
+                   .NOT.  rans_mode ) )  THEN
+       CALL MPI_TYPE_CREATE_SUBARRAY( 2, [nzt-nzb+2,nxrg-nxlg+1],              &
                [1,nxrg-nxlg+1], [0,0], MPI_ORDER_FORTRAN, MPI_REAL, newtype, ierr )
        CALL MPI_TYPE_CREATE_RESIZED( newtype, tob, extent, stg_type_xz, ierr )
@@ -521,5 +535,5 @@
 
        ! stg_type_yz_small: xz-slice with vertical bounds nzb_x_stg:nzt_x_stg+1
-       CALL MPI_TYPE_CREATE_SUBARRAY( 2, [nzt_y_stg-nzb_y_stg+2,nxrg-nxlg+1],             &
+       CALL MPI_TYPE_CREATE_SUBARRAY( 2, [nzt_y_stg-nzb_y_stg+2,nxrg-nxlg+1],  &
                [1,nxrg-nxlg+1], [0,0], MPI_ORDER_FORTRAN, MPI_REAL, newtype, ierr )
        CALL MPI_TYPE_CREATE_RESIZED( newtype, tob, extent, stg_type_xz_small, ierr )
@@ -600,5 +614,5 @@
 !--    Set-up defaul length scales. Assume exponentially decreasing length 
 !--    scales and isotropic turbulence. 
-!--    Typical length (time) scales of 100 m (s) should be a goog compromise 
+!--    Typical length (time) scales of 100 m (s) should be a good compromise 
 !--    between all stratrifications. Near-surface variances are fixed to 
 !--    0.1 m2/s2, vertical fluxes are one order of magnitude smaller.
@@ -998,5 +1012,5 @@
     USE control_parameters,                                                    &
         ONLY:  dt_3d, forcing, intermediate_timestep_count,  nest_domain,      &
-               simulated_time, volume_flow_initial
+               rans_mode, simulated_time, volume_flow_initial
 
     USE grid_variables,                                                        &
@@ -1008,4 +1022,7 @@
     USE statistics,                                                            &
         ONLY:  weight_substep
+
+    USE pmc_interface,                                                         &
+        ONLY : rans_mode_parent
 
 
@@ -1038,5 +1055,6 @@
        CALL stg_generate_seed_yz( nwy, nwz, bwy, bwz, fw_yz, id_stg_left )
 
-       IF ( forcing  .OR.  nest_domain )  THEN
+       IF ( forcing  .OR.  ( nest_domain .AND.  rans_mode_parent  .AND.        &
+                      .NOT.  rans_mode ) )  THEN
 !
 !--       Generate turbulence at right boundary
@@ -1063,5 +1081,6 @@
     CALL stg_generate_seed_yz( nwy, nwz, bwy, bwz, fwo_yz, id_stg_left )
 
-    IF ( forcing  .OR.  nest_domain )  THEN
+    IF ( forcing  .OR.  ( nest_domain .AND.  rans_mode_parent  .AND.           &
+                   .NOT.  rans_mode ) )  THEN
 !
 !--       Generate turbulence at right boundary
@@ -1120,12 +1139,12 @@
                 dist_yz(k,j,1) = a11(k) * fu_yz(k,j)
                 !experimental test of 1.2
-                dist_yz(k,j,2) = ( SQRT( a22(k) / MAXVAL(a22) )                   &
+                dist_yz(k,j,2) = ( SQRT( a22(k) / MAXVAL(a22) )                &
                                          * 1.2_wp )                            &
-                                       * (   a21(k) * fu_yz(k,j)                  &
+                                       * (   a21(k) * fu_yz(k,j)               &
                                            + a22(k) * fv_yz(k,j) )
-                dist_yz(k,j,3) = ( SQRT(a33(k) / MAXVAL(a33) )                    &
+                dist_yz(k,j,3) = ( SQRT(a33(k) / MAXVAL(a33) )                 &
                                          * 1.3_wp )                            &
-                                       * (   a31(k) * fu_yz(k,j)                  &
-                                           + a32(k) * fv_yz(k,j)                  &
+                                       * (   a31(k) * fu_yz(k,j)               &
+                                           + a32(k) * fv_yz(k,j)               &
                                            + a33(k) * fw_yz(k,j) )
                 ! Calculation for pt and e not yet implemented
@@ -1303,18 +1322,18 @@
        DO  i = nxl, nxr
           DO  k = nzb+1, nzt
-             volume_flow_l = volume_flow_l + v(k,j,i) * dzw(k) * dx         &
-                                  * MERGE( 1.0_wp, 0.0_wp,                  &   
+             volume_flow_l = volume_flow_l + v(k,j,i) * dzw(k) * dx            &
+                                  * MERGE( 1.0_wp, 0.0_wp,                     &   
                                            BTEST( wall_flags_0(k,j,i), 2 ) )
 
-             mc_factor_l = mc_factor_l     + ( v(k,j,i) + dist_xz(k,i,2) )  &
-                                                      * dzw(k) * dx         &
-                                  * MERGE( 1.0_wp, 0.0_wp,                  &   
+             mc_factor_l = mc_factor_l     + ( v(k,j,i) + dist_xz(k,i,2) )     &
+                                                      * dzw(k) * dx            &
+                                  * MERGE( 1.0_wp, 0.0_wp,                     &   
                                            BTEST( wall_flags_0(k,j,i), 2 ) )
           ENDDO
        ENDDO
 #if defined( __parallel )
-       CALL MPI_ALLREDUCE( volume_flow_l, volume_flow,                      &
+       CALL MPI_ALLREDUCE( volume_flow_l, volume_flow,                         &
                            1, MPI_REAL, MPI_SUM, comm1dx, ierr )
-       CALL MPI_ALLREDUCE( mc_factor_l, mc_factor,                          &
+       CALL MPI_ALLREDUCE( mc_factor_l, mc_factor,                             &
                            1, MPI_REAL, MPI_SUM, comm1dx, ierr )
 #else
@@ -1374,4 +1393,5 @@
         ONLY: ny
 
+    USE pegrid
 
     IMPLICIT NONE
@@ -1467,5 +1487,4 @@
 
     DEALLOCATE( rand_it )
-
 !
 !-- Gather velocity seeds of full subdomain
@@ -1474,6 +1493,6 @@
 
 #if defined( __parallel )
-    CALL MPI_GATHERV( f_n_l(nzb_x_stg,nysg), send_count, stg_type_yz_small,        &
-                      f_n(nzb+1,nysg), recv_count_yz, displs_yz, stg_type_yz,        &
+    CALL MPI_GATHERV( f_n_l(nzb_x_stg,nysg), send_count, stg_type_yz_small,    &
+                      f_n(nzb+1,nysg), recv_count_yz, displs_yz, stg_type_yz,  &
                       id, comm1dx, ierr )
 #else
@@ -1603,5 +1622,5 @@
 
 #if defined( __parallel )
-    CALL MPI_GATHERV( f_n_l(nzb_y_stg,nxlg), send_count, stg_type_xz_small,        &
+    CALL MPI_GATHERV( f_n_l(nzb_y_stg,nxlg), send_count, stg_type_xz_small,    &
                       f_n(nzb+1,nxlg), recv_count_xz, displs_xz, stg_type_xz,  &
                       id, comm1dy, ierr )
