SUBROUTINE disturb_field( nzb_uv_inner, dist1, field ) !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! ! Former revisions: ! ----------------- ! $Id: disturb_field.f90 668 2010-12-23 13:22:58Z helmke $ ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng ! Calls of exchange_horiz are modified. ! ! 420 2010-01-13 15:10:53Z franke ! Loop was split to make runs reproducible when using ifort compiler ! ! 75 2007-03-22 09:54:05Z raasch ! xrp, ynp eliminated, 2nd+3rd argument removed from exchange horiz ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.11 2006/08/04 14:31:59 raasch ! izuf renamed iran ! ! Revision 1.1 1998/02/04 15:40:45 raasch ! Initial revision ! ! ! Description: ! ------------ ! Imposing a random perturbation on a 3D-array. ! On parallel computers, the random number generator is as well called for all ! gridpoints of the total domain to ensure, regardless of the number of PEs ! used, that the elements of the array have the same values in the same ! order in every case. The perturbation range is steered by dist_range. !------------------------------------------------------------------------------! USE control_parameters USE cpulog USE grid_variables USE indices USE interfaces USE random_function_mod IMPLICIT NONE INTEGER :: i, j, k INTEGER :: nzb_uv_inner(nysg:nyng,nxlg:nxrg) REAL :: randomnumber, & dist1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & field(nzb:nzt+1,nysg:nyng,nxlg:nxrg) REAL, DIMENSION(:,:,:), ALLOCATABLE :: dist2 CALL cpu_log( log_point(20), 'disturb_field', 'start' ) ! !-- Create an additional temporary array and initialize the arrays needed !-- to store the disturbance ALLOCATE( dist2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) dist1 = 0.0 dist2 = 0.0 ! !-- Create the random perturbation and store it on temporary array IF ( random_generator == 'numerical-recipes' ) THEN DO i = dist_nxl(dist_range), dist_nxr(dist_range) DO j = dist_nys(dist_range), dist_nyn(dist_range) DO k = disturbance_level_ind_b, disturbance_level_ind_t randomnumber = 3.0 * disturbance_amplitude * & ( random_function( iran ) - 0.5 ) IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. & nyn >= j ) & THEN dist1(k,j,i) = randomnumber ENDIF ENDDO ENDDO ENDDO ELSEIF ( random_generator == 'system-specific' ) THEN DO i = dist_nxl(dist_range), dist_nxr(dist_range) DO j = dist_nys(dist_range), dist_nyn(dist_range) DO k = disturbance_level_ind_b, disturbance_level_ind_t #if defined( __nec ) randomnumber = 3.0 * disturbance_amplitude * & ( RANDOM( 0 ) - 0.5 ) #else CALL RANDOM_NUMBER( randomnumber ) randomnumber = 3.0 * disturbance_amplitude * & ( randomnumber - 0.5 ) #endif IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. nyn >= j ) & THEN dist1(k,j,i) = randomnumber ENDIF ENDDO ENDDO ENDDO ENDIF ! !-- Exchange of ghost points for the random perturbation CALL exchange_horiz( dist1, nbgp ) ! !-- Applying the Shuman filter in order to smooth the perturbations. !-- Neighboured grid points in all three directions are used for the !-- filter operation. !-- Loop has been splitted to make runs reproducible on HLRN systems using !-- compiler option -O3 DO i = nxl, nxr DO j = nys, nyn DO k = disturbance_level_ind_b-1, disturbance_level_ind_t+1 dist2(k,j,i) = ( dist1(k,j,i-1) + dist1(k,j,i+1) & + dist1(k,j+1,i) + dist1(k+1,j,i) & ) / 12.0 ENDDO DO k = disturbance_level_ind_b-1, disturbance_level_ind_t+1 dist2(k,j,i) = dist2(k,j,i) + ( dist1(k,j-1,i) + dist1(k-1,j,i) & + 6.0 * dist1(k,j,i) & ) / 12.0 ENDDO ENDDO ENDDO ! !-- Exchange of ghost points for the filtered perturbation. !-- Afterwards, filter operation and exchange of ghost points are repeated. CALL exchange_horiz( dist2, nbgp ) DO i = nxl, nxr DO j = nys, nyn DO k = disturbance_level_ind_b-2, disturbance_level_ind_t+2 dist1(k,j,i) = ( dist2(k,j,i-1) + dist2(k,j,i+1) + dist2(k,j-1,i) & + dist2(k,j+1,i) + dist2(k+1,j,i) + dist2(k-1,j,i) & + 6.0 * dist2(k,j,i) & ) / 12.0 ENDDO ENDDO ENDDO CALL exchange_horiz( dist1, nbgp ) ! !-- Remove perturbations below topography (including one gridpoint above it !-- in order to allow for larger timesteps at the beginning of the simulation !-- (diffusion criterion)) IF ( TRIM( topography ) /= 'flat' ) THEN DO i = nxlg, nxrg DO j = nysg, nyng dist1(nzb:nzb_uv_inner(j,i)+1,j,i) = 0.0 ENDDO ENDDO ENDIF ! !-- Random perturbation is added to the array to be disturbed. DO i = nxlg, nxrg DO j = nysg, nyng DO k = disturbance_level_ind_b-2, disturbance_level_ind_t+2 field(k,j,i) = field(k,j,i) + dist1(k,j,i) ENDDO ENDDO ENDDO ! !-- Deallocate the temporary array DEALLOCATE( dist2 ) ! !-- Set a flag, which indicates that a random perturbation is imposed disturbance_created = .TRUE. CALL cpu_log( log_point(20), 'disturb_field', 'stop' ) END SUBROUTINE disturb_field