Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 2045)
+++ palm/trunk/SOURCE/Makefile	(revision 2050)
@@ -20,5 +20,5 @@
 # Current revisions:
 # ------------------
-# 
+# Implement turbulent outflow method
 # 
 # Former revisions:
@@ -334,6 +334,6 @@
 	ls_forcing_mod.f90 message.f90 microphysics_mod.f90 modules.f90 mod_kinds.f90 \
 	mod_particle_attributes.f90 netcdf_interface_mod.f90 nudging_mod.f90 \
-	package_parin.f90 palm.f90 parin.f90 plant_canopy_model_mod.f90 pmc_interface_mod.f90 \
-	pmc_child_mod.f90 pmc_general_mod.f90 pmc_handle_communicator_mod.f90 \
+	outflow_turbulence.f90 package_parin.f90 palm.f90 parin.f90 plant_canopy_model_mod.f90 \
+	pmc_interface_mod.f90 pmc_child_mod.f90 pmc_general_mod.f90 pmc_handle_communicator_mod.f90 \
 	pmc_mpi_wrapper_mod.f90 pmc_parent_mod.f90 poisfft_mod.f90 poismg_mod.f90 \
 	poismg_noopt.f90 posix_calls_from_fortran.f90 pres.f90 print_1d.f90 production_e.f90 \
@@ -518,4 +518,5 @@
    land_surface_model_mod.o radiation_model_mod.o spectra_mod.o urban_surface_mod.o
 nudging_mod.o: modules.o cpulog_mod.o mod_kinds.o
+outflow_turbulence.o: modules.o cpulog_mod.o mod_kinds.o
 package_parin.o: modules.o mod_kinds.o mod_particle_attributes.o
 palm.o: modules.o cpulog_mod.o land_surface_model_mod.o ls_forcing_mod.o mod_kinds.o nudging_mod.o\
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 2045)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 2050)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Implement turbulent outflow condition
 ! 
 ! Former revisions:
@@ -3703,4 +3703,24 @@
     ENDIF
 
+
+    IF ( turbulent_outflow )  THEN
+!
+!--    Turbulent outflow requires Dirichlet conditions at the respective inflow
+!--    boundary (so far, a turbulent outflow is realized at the right side only)
+       IF ( bc_lr /= 'dirichlet/radiation' )  THEN
+          message_string = 'turbulent_outflow = .T. requires ' //              &
+                           'bc_lr = "dirichlet/radiation"'
+          CALL message( 'check_parameters', 'PA0038', 1, 2, 0, 6, 0 )
+       ENDIF
+!
+!--    The ouflow-source plane must lay inside the model domain
+       IF ( outflow_source_plane < dx  .OR.  &
+            outflow_source_plane > nx * dx )  THEN
+          WRITE( message_string, * )  'illegal value for outflow_source'//     &
+                                      '_plane: ', outflow_source_plane
+          CALL message( 'check_parameters', 'PA0145', 1, 2, 0, 6, 0 )
+       ENDIF
+    ENDIF
+
 !
 !-- Determine damping level index for 1D model
Index: palm/trunk/SOURCE/header.f90
===================================================================
--- palm/trunk/SOURCE/header.f90	(revision 2045)
+++ palm/trunk/SOURCE/header.f90	(revision 2050)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Implement turbulent outflow condition
 ! 
 ! Former revisions:
@@ -1121,4 +1121,7 @@
                                 inflow_damping_height, inflow_damping_width
           END IF
+       ENDIF
+       IF ( turbulent_outflow )  THEN
+          WRITE ( io, 323 )  outflow_source_plane, INT(outflow_source_plane/dx)
        ENDIF
     ENDIF
@@ -2068,4 +2071,7 @@
             '       width of recycling domain: ',F7.1,' m   grid index: ',I4/ &
             '       inflow damping height: ',F6.1,' m   width: ',F6.1,' m'/)
+323 FORMAT ('       turbulent outflow conditon switched on'/ &
+            '       position of outflow source plane: ',F7.1,' m   ', &
+                    'grid index: ', I4)
 325 FORMAT (//' List output:'/ &
              ' -----------'//  &
Index: palm/trunk/SOURCE/init_pegrid.f90
===================================================================
--- palm/trunk/SOURCE/init_pegrid.f90	(revision 2045)
+++ palm/trunk/SOURCE/init_pegrid.f90	(revision 2050)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! Implement turbulent outflow condition
 ! 
 ! Former revisions:
@@ -169,5 +169,6 @@
                nest_bound_n, nest_bound_r, nest_bound_s, nest_domain, neutral, &
                psolver, outflow_l, outflow_n, outflow_r, outflow_s,            &
-               recycling_width, scalar_advec, subdomain_size 
+               outflow_source_plane, recycling_width, scalar_advec,            &
+               subdomain_size, turbulent_outflow
 
     USE grid_variables,                                                        &
@@ -199,4 +200,6 @@
     INTEGER(iwp) ::  i                        !<
     INTEGER(iwp) ::  id_inflow_l              !<
+    INTEGER(iwp) ::  id_outflow_l             !< local value of id_outflow
+    INTEGER(iwp) ::  id_outflow_source_l      !< local value of id_outflow_source
     INTEGER(iwp) ::  id_recycling_l           !<
     INTEGER(iwp) ::  ind(5)                   !<
@@ -1170,5 +1173,4 @@
     ENDIF
 
-       
 !
 !-- Broadcast the id of the inflow PE
@@ -1194,4 +1196,29 @@
     CALL MPI_ALLREDUCE( id_recycling_l, id_recycling, 1, MPI_INTEGER, MPI_SUM, &
                         comm1dx, ierr )
+
+!
+!-- Broadcast the id of the outflow PE and outflow-source plane
+    IF ( turbulent_outflow )  THEN
+
+       IF ( outflow_r )  THEN
+          id_outflow_l = myidx
+       ELSE
+          id_outflow_l = 0
+       ENDIF
+       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
+       CALL MPI_ALLREDUCE( id_outflow_l, id_outflow, 1, MPI_INTEGER, MPI_SUM, &
+                           comm1dx, ierr )
+
+       IF ( NINT( outflow_source_plane / dx ) >= nxl  .AND. &
+            NINT( outflow_source_plane / dx ) <= nxr )  THEN
+          id_outflow_source_l = myidx
+       ELSE
+          id_outflow_source_l = 0
+       ENDIF
+       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
+       CALL MPI_ALLREDUCE( id_outflow_source_l, id_outflow_source, 1, &
+                           MPI_INTEGER, MPI_SUM, comm1dx, ierr )
+
+    ENDIF
 
     CALL location_message( 'finished', .TRUE. )
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 2045)
+++ palm/trunk/SOURCE/modules.f90	(revision 2050)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! Implement turbulent outflow condition
 ! 
 ! Former revisions:
@@ -783,4 +783,5 @@
                 terminate_run = .FALSE., transpose_compute_overlap = .FALSE., &
                 turbulent_inflow = .FALSE.
+    LOGICAL ::  turbulent_outflow = .FALSE. !< flag for turbulent outflow condition
     LOGICAL ::  urban_surface = .FALSE.  !< flag for urban surface model
     LOGICAL ::  use_cmax = .TRUE., use_initial_profile_as_reference = .FALSE., &
@@ -832,4 +833,5 @@
                  molecular_viscosity = 1.461E-5_wp, &
                  old_dt = 1.0E-10_wp, omega = 7.29212E-5_wp, omega_sor = 1.8_wp, &
+                 outflow_source_plane = -9999999.9_wp, & !< x-position of outflow-source plane (turbulent outflow method)
                  particle_maximum_age = 9999999.9_wp, &
                  phi = 55.0_wp, prandtl_number = 1.0_wp, &
@@ -1195,15 +1197,18 @@
     CHARACTER(LEN=2) ::  send_receive = 'al'
     CHARACTER(LEN=7) ::  myid_char = ''
-    INTEGER(iwp)          ::  acc_rank, comm1dx, comm1dy, comm2d, comm_inter,       &
-                              comm_palm, id_inflow = 0, id_recycling = 0, ierr,     &
-                              myid = 0, myidx = 0, myidy = 0, ndim = 2, ngp_a,      &
-                              ngp_o, ngp_xy, ngp_y, npex = -1, npey = -1,           &
-                              numprocs = 1, numprocs_previous_run = -1,             &
-                              num_acc_per_node = 0, pleft, pnorth, pright, psouth,  &
-                              req_count = 0, sendrecvcount_xy, sendrecvcount_yz,    &
-                              sendrecvcount_zx, sendrecvcount_zyd,                  &
-                              sendrecvcount_yxd, target_id, tasks_per_node = -9999, &
-                              threads_per_task = 1, type_x, type_xy,    &
-                              type_y
+    INTEGER(iwp)     ::  acc_rank, comm1dx, comm1dy, comm2d, comm_inter,       &
+                         comm_palm, id_inflow = 0,                             &
+                         id_outflow = 0,        & !< myidx of procs at outflow (turbulent outflow method)
+                         id_outflow_source = 0, & !< myidx of procs including ouflow source plane (turbulent outflow method)
+                         id_recycling = 0, ierr,                               &
+                         myid = 0, myidx = 0, myidy = 0, ndim = 2, ngp_a,      &
+                         ngp_o, ngp_xy, ngp_y, npex = -1, npey = -1,           &
+                         numprocs = 1, numprocs_previous_run = -1,             &
+                         num_acc_per_node = 0, pleft, pnorth, pright, psouth,  &
+                         req_count = 0, sendrecvcount_xy, sendrecvcount_yz,    &
+                         sendrecvcount_zx, sendrecvcount_zyd,                  &
+                         sendrecvcount_yxd, target_id, tasks_per_node = -9999, &
+                         threads_per_task = 1, type_x, type_xy,    &
+                         type_y
 
     INTEGER(iwp)          ::  pdims(2) = 1, req(100)
Index: palm/trunk/SOURCE/outflow_turbulence.f90
===================================================================
--- palm/trunk/SOURCE/outflow_turbulence.f90	(revision 2050)
+++ palm/trunk/SOURCE/outflow_turbulence.f90	(revision 2050)
@@ -0,0 +1,165 @@
+!> @file outflow_turbulence.f90
+!------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! PALM is free software: you can redistribute it and/or modify it under the
+! terms of the GNU General Public License as published by the Free Software
+! Foundation, either version 3 of the License, or (at your option) any later
+! version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2016 Leibniz Universitaet Hannover
+!------------------------------------------------------------------------------!
+!
+! Current revisions:
+! -----------------
+! Initial version
+! 
+! Former revisions:
+! -----------------
+! $Id$
+!
+!
+! Description:
+! ------------
+!> Routine based on inflow_turbulence.f90. Copies values of 3d data from a 2d
+!> vertical source plane (defined by outflow_source_plane) to the outflow
+!> boundary.
+!------------------------------------------------------------------------------!
+ SUBROUTINE outflow_turbulence
+
+    USE arrays_3d,                                                             &
+        ONLY:  e, pt, q, s, u, v, w
+
+    USE control_parameters,                                                    &
+        ONLY:  humidity, passive_scalar, outflow_source_plane
+
+    USE cpulog,                                                                &
+        ONLY:  cpu_log, log_point
+
+    USE grid_variables,                                                        &
+        ONLY:  ddx
+
+    USE indices,                                                               &
+        ONLY:  nbgp, nx, nxr, ny, nyn, nys, nyng, nysg, nzb, nzt
+
+    USE kinds
+
+    USE pegrid!,                                                                &
+        !ONLY:  comm1dx, id_outflow, id_outflow_source, ierr, myidx, status
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i        !< loop index
+    INTEGER(iwp) ::  j        !< loop index
+    INTEGER(iwp) ::  k        !< loop index
+    INTEGER(iwp) ::  l        !< loop index
+    INTEGER(iwp) ::  ngp_ofv  !< number of grid points stored in outflow_val
+
+    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
+       outflow_val            !< values to be copied to the outflow boundary
+
+
+    CALL cpu_log( log_point(56), 'outflow_turbulence', 'start' )
+!
+!-- Get number of grid points stored in outflow_val
+    ngp_ofv = ( nzt - nzb + 2 ) * ( nyn - nys + 1 + 2 * nbgp ) * 7 * nbgp
+!
+!-- Get position of the source plane inside the palm grid
+    i = outflow_source_plane * ddx
+!
+!-- Use instantaneous values instead of averaged profiles
+#if defined( __parallel )
+    IF ( myidx == id_outflow_source )  THEN
+       DO  l = 1, nbgp
+          DO  j = nysg, nyng
+             DO  k = nzb, nzt + 1
+
+                outflow_val(k,j,1,l) = u(k,j,i)
+                outflow_val(k,j,2,l) = v(k,j,i)
+                outflow_val(k,j,3,l) = w(k,j,i)
+                outflow_val(k,j,4,l) = pt(k,j,i)
+                outflow_val(k,j,5,l) = e(k,j,i)
+                IF ( humidity  )                                               &
+                   outflow_val(k,j,6,l) = q(k,j,i)
+                IF ( passive_scalar )                                          &
+                   outflow_val(k,j,7,l) = s(k,j,i)
+
+            ENDDO
+          ENDDO
+          i = i + 1
+       ENDDO
+
+    ENDIF
+#else
+    DO  l = 1, nbgp
+       DO  j = nysg, nyng
+          DO  k = nzb, nzt+1
+
+             outflow_val(k,j,1,l) = u(k,j,i)
+             outflow_val(k,j,2,l) = v(k,j,i)
+             outflow_val(k,j,3,l) = w(k,j,i)
+             outflow_val(k,j,4,l) = pt(k,j,i)
+             outflow_val(k,j,5,l) = e(k,j,i)
+             IF ( humidity  )                                                  &
+                outflow_val(k,j,6,l) = q(k,j,i)
+             IF ( passive_scalar )                                             &
+                outflow_val(k,j,7,l) = s(k,j,i)
+
+          ENDDO
+       ENDDO
+       i = i + 1
+    ENDDO
+#endif
+
+!
+!-- For parallel runs, send the values to the respective outflow PE
+#if defined( __parallel )
+    IF ( myidx == id_outflow_source  .AND.  myidx /= id_outflow )  THEN
+
+       CALL MPI_SEND( outflow_val(nzb,nysg,1,1), ngp_ofv, MPI_REAL,            &
+                      id_outflow, 1, comm1dx, ierr )
+
+    ELSEIF ( myidx /= id_outflow_source  .AND.  myidx == id_outflow )  THEN
+
+       outflow_val = 0.0_wp
+       CALL MPI_RECV( outflow_val(nzb,nysg,1,1), ngp_ofv, MPI_REAL,            &
+                      id_outflow_source, 1, comm1dx, status, ierr )
+
+    ENDIF
+#endif
+
+!
+!-- Copy values to the outflow
+    IF ( nxr == nx )  THEN
+
+       DO  j = nysg, nyng
+          DO  k = nzb, nzt + 1
+
+             u(k,j,nx+1:nx+nbgp)  = outflow_val(k,j,1,1:nbgp)
+             v(k,j,nx+1:nx+nbgp)  = outflow_val(k,j,2,1:nbgp)
+             w(k,j,nx+1:nx+nbgp)  = outflow_val(k,j,3,1:nbgp)
+             pt(k,j,nx+1:nx+nbgp) = outflow_val(k,j,4,1:nbgp)
+             e(k,j,nx+1:nx+nbgp)  = outflow_val(k,j,5,1:nbgp)
+             e(k,j,nx+1:nx+nbgp)  = MAX( e(k,j,nx+1:nx+nbgp), 0.0_wp )
+
+             IF ( humidity )                                                   &
+                q(k,j,nx+1:nx+nbgp)  = outflow_val(k,j,6,1:nbgp)
+             IF ( passive_scalar )                                             &
+                s(k,j,nx+1:nx+nbgp)  = outflow_val(k,j,7,1:nbgp)
+
+          ENDDO
+       ENDDO
+
+
+    ENDIF
+
+    CALL cpu_log( log_point(56), 'outflow_turbulence', 'stop' )
+
+ END SUBROUTINE outflow_turbulence
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 2045)
+++ palm/trunk/SOURCE/parin.f90	(revision 2050)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Implement turbulent outflow condition
 ! 
 ! Former revisions:
@@ -348,5 +348,5 @@
              most_method, nc_const, netcdf_precision, neutral, ngsrb,          &
              nsor, nsor_ini, nudging, nx, ny, nz, ocean, omega, omega_sor,     &
-             passive_scalar, phi,                                              &
+             outflow_source_plane, passive_scalar, phi,                        &
              prandtl_number, precipitation, psolver, pt_damping_factor,        &
              pt_damping_width, pt_reference, pt_surface,                       &
@@ -369,4 +369,5 @@
              top_momentumflux_u, top_momentumflux_v, top_salinityflux,         &
              top_scalarflux, transpose_compute_overlap, turbulent_inflow,      &
+             turbulent_outflow,                                                &
              use_subsidence_tendencies, ug_surface, ug_vertical_gradient,      &
              ug_vertical_gradient_level, use_surface_fluxes, use_cmax,         &
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 2045)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 2050)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! Implement turbulent outflow condition
 ! 
 ! Former revisions:
@@ -282,5 +282,5 @@
                time_dots, time_do_av, time_do_sla, time_disturb, time_dvrp,    &
                time_run_control, time_since_reference_point,                   &
-               turbulent_inflow, urban_surface,                                &
+               turbulent_inflow, turbulent_outflow, urban_surface,             &
                use_initial_profile_as_reference,                               &
                use_single_reference_value, u_gtrans, v_gtrans, virtual_flight, &
@@ -803,4 +803,8 @@
 !--       Impose a turbulent inflow using the recycling method
           IF ( turbulent_inflow )  CALL  inflow_turbulence
+
+!
+!--       Set values at outflow boundary using the special outflow condition
+          IF ( turbulent_outflow )  CALL  outflow_turbulence
 
 !
