source: palm/trunk/SOURCE/disturb_field.f90 @ 4327

Last change on this file since 4327 was 4237, checked in by knoop, 5 years ago

Added missing OpenMP directives within "disturb_field", "surface_layer_fluxes" and "timestep"

  • Property svn:keywords set to Id
File size: 9.3 KB
RevLine 
[1682]1!> @file disturb_field.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]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.
[1036]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!
[3655]17! Copyright 1997-2019 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1318]21! ------------------
[1354]22!
[2233]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: disturb_field.f90 4237 2019-09-25 11:33:42Z Giersch $
[4237]27! Added missing OpenMP directives
28!
29! 4182 2019-08-22 15:20:23Z scharf
[2716]30! Corrected "Former revisions" section
31!
[4182]32! 3849 2019-04-01 16:35:16Z knoop
33! Corrected "Former revisions" section
[2716]34!
[4182]35! Revision 1.1  1998/02/04 15:40:45  raasch
36! Initial revision
37!
38!
[1]39! Description:
40! ------------
[1682]41!> Imposing a random perturbation on a 3D-array.
42!> On parallel computers, the random number generator is as well called for all
43!> gridpoints of the total domain to ensure, regardless of the number of PEs
44!> used, that the elements of the array have the same values in the same
45!> order in every case. The perturbation range is steered by dist_range.
[1]46!------------------------------------------------------------------------------!
[2232]47 SUBROUTINE disturb_field( var_char, dist1, field )
[1682]48 
[1]49
[2232]50    USE control_parameters,                                                    &
[1320]51        ONLY:  dist_nxl, dist_nxr, dist_nyn, dist_nys, dist_range,             &
52               disturbance_amplitude, disturbance_created,                     &
53               disturbance_level_ind_b, disturbance_level_ind_t, iran,         &
54               random_generator, topography
55               
56    USE cpulog,                                                                &
57        ONLY:  cpu_log, log_point
58       
59    USE indices,                                                               &
[2232]60        ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzb_max, &
61               nzt, wall_flags_0
[1320]62       
63    USE kinds
64   
65    USE random_function_mod,                                                   &
66        ONLY: random_function
[1400]67       
68    USE random_generator_parallel,                                             &
69        ONLY:  random_number_parallel, random_seed_parallel, random_dummy,     &
[2172]70               seq_random_array
[1]71
72    IMPLICIT NONE
73
[2232]74    CHARACTER (LEN = *) ::  var_char !< flag to distinguish betwenn u- and v-component
[1]75
[2232]76    INTEGER(iwp) ::  flag_nr !< number of respective flag for u- or v-grid
77    INTEGER(iwp) ::  i       !< index variable
78    INTEGER(iwp) ::  j       !< index variable
79    INTEGER(iwp) ::  k       !< index variable
80
[1682]81    REAL(wp) ::  randomnumber  !<
[1320]82   
[1682]83    REAL(wp) ::  dist1(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !<
84    REAL(wp) ::  field(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !<
[1320]85   
[1682]86    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  dist2  !<
[1]87
88
89    CALL cpu_log( log_point(20), 'disturb_field', 'start' )
90!
[2232]91!-- Set flag number, 20 for u-grid, 21 for v-grid, required to mask topography
92    flag_nr = MERGE( 20, 21, TRIM(var_char) == 'u' )
93!
[1]94!-- Create an additional temporary array and initialize the arrays needed
95!-- to store the disturbance
[667]96    ALLOCATE( dist2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[3849]97!$ACC DATA CREATE(dist2(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
98
99!
100!-- dist1 is initialized on the host (see below) and then updated on the device.
[1353]101    dist1 = 0.0_wp
[3849]102    !$ACC KERNELS PRESENT(dist2)
[1353]103    dist2 = 0.0_wp
[3849]104    !$ACC END KERNELS
[1]105
106!
107!-- Create the random perturbation and store it on temporary array
108    IF ( random_generator == 'numerical-recipes' )  THEN
109       DO  i = dist_nxl(dist_range), dist_nxr(dist_range)
110          DO  j = dist_nys(dist_range), dist_nyn(dist_range)
111             DO  k = disturbance_level_ind_b, disturbance_level_ind_t
[1322]112                randomnumber = 3.0_wp * disturbance_amplitude *                &
113                               ( random_function( iran ) - 0.5_wp )
[1320]114                IF ( nxl <= i  .AND.  nxr >= i  .AND.  nys <= j  .AND.         &
115                     nyn >= j )                                                &
[1]116                THEN
117                   dist1(k,j,i) = randomnumber
118                ENDIF
119             ENDDO
120          ENDDO
121       ENDDO
[1400]122    ELSEIF ( random_generator == 'random-parallel' )  THEN
123       DO  i = dist_nxl(dist_range), dist_nxr(dist_range)
124          DO  j = dist_nys(dist_range), dist_nyn(dist_range)
125             CALL random_seed_parallel( put=seq_random_array(:, j, i) )
126             DO  k = disturbance_level_ind_b, disturbance_level_ind_t
127                CALL random_number_parallel( random_dummy )
128                randomnumber = 3.0_wp * disturbance_amplitude *                &
129                               ( random_dummy - 0.5_wp )
130                IF ( nxl <= i  .AND.  nxr >= i  .AND.  nys <= j  .AND.         &
131                     nyn >= j )                                                &
132                THEN
133                   dist1(k,j,i) = randomnumber
134                ENDIF
135             ENDDO
136             CALL random_seed_parallel( get=seq_random_array(:, j, i) )
137          ENDDO
138       ENDDO
[1]139    ELSEIF ( random_generator == 'system-specific' )  THEN
140       DO  i = dist_nxl(dist_range), dist_nxr(dist_range)
141          DO  j = dist_nys(dist_range), dist_nyn(dist_range)
142             DO  k = disturbance_level_ind_b, disturbance_level_ind_t
143                CALL RANDOM_NUMBER( randomnumber )
[1322]144                randomnumber = 3.0_wp * disturbance_amplitude *                &
145                                ( randomnumber - 0.5_wp )
[1320]146                IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. nyn >= j )   &
[1]147                THEN
148                   dist1(k,j,i) = randomnumber
149                ENDIF
150             ENDDO
151          ENDDO
152       ENDDO
153
154    ENDIF
155
156!
[3849]157!-- Update dist1 on the device, this is expected by exchange_horiz!
158    !$ACC UPDATE DEVICE(dist1(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
159
160!
[1]161!-- Exchange of ghost points for the random perturbation
[420]162
[667]163    CALL exchange_horiz( dist1, nbgp )
[1]164!
165!-- Applying the Shuman filter in order to smooth the perturbations.
166!-- Neighboured grid points in all three directions are used for the
167!-- filter operation.
[420]168!-- Loop has been splitted to make runs reproducible on HLRN systems using
169!-- compiler option -O3
[3849]170     !$ACC PARALLEL LOOP COLLAPSE(2) PRIVATE(i, j, k) PRESENT(dist1, dist2)
[4237]171     !$OMP PARALLEL DO PRIVATE(i, j, k)
[420]172     DO  i = nxl, nxr
173        DO  j = nys, nyn
[1]174          DO  k = disturbance_level_ind_b-1, disturbance_level_ind_t+1
[1320]175             dist2(k,j,i) = ( dist1(k,j,i-1) + dist1(k,j,i+1)                  &
176                            + dist1(k,j+1,i) + dist1(k+1,j,i)                  &
[1322]177                            ) / 12.0_wp
[420]178          ENDDO
179          DO  k = disturbance_level_ind_b-1, disturbance_level_ind_t+1
180              dist2(k,j,i) = dist2(k,j,i) + ( dist1(k,j-1,i) + dist1(k-1,j,i)  &
[1322]181                            + 6.0_wp * dist1(k,j,i)                            &
182                            ) / 12.0_wp
[1]183          ENDDO
[420]184        ENDDO
185     ENDDO
[1]186
187!
188!-- Exchange of ghost points for the filtered perturbation.
189!-- Afterwards, filter operation and exchange of ghost points are repeated.
[667]190    CALL exchange_horiz( dist2, nbgp )
[420]191
[3849]192    !$ACC PARALLEL LOOP COLLAPSE(2) PRIVATE(i, j, k) PRESENT(dist1, dist2)
[4237]193    !$OMP PARALLEL DO PRIVATE(i, j, k)
[1]194    DO  i = nxl, nxr
195       DO  j = nys, nyn
196          DO  k = disturbance_level_ind_b-2, disturbance_level_ind_t+2
197             dist1(k,j,i) = ( dist2(k,j,i-1) + dist2(k,j,i+1) + dist2(k,j-1,i) &
198                            + dist2(k,j+1,i) + dist2(k+1,j,i) + dist2(k-1,j,i) &
[1322]199                            + 6.0_wp * dist2(k,j,i)                            &
200                            ) / 12.0_wp
[1]201          ENDDO
202       ENDDO
203    ENDDO
[420]204
[667]205    CALL exchange_horiz( dist1, nbgp )
[1]206
207!
208!-- Remove perturbations below topography (including one gridpoint above it
209!-- in order to allow for larger timesteps at the beginning of the simulation
210!-- (diffusion criterion))
211    IF ( TRIM( topography ) /= 'flat' )  THEN
[667]212       DO  i = nxlg, nxrg
213          DO  j = nysg, nyng
[2232]214             DO  k = nzb, nzb_max
215                dist1(k,j,i) = MERGE( dist1(k,j,i), 0.0_wp,                    &
216                                      BTEST( wall_flags_0(k,j,i), flag_nr )    &
217                                    )
218             ENDDO
[1]219          ENDDO
220       ENDDO
221    ENDIF
222
223!
224!-- Random perturbation is added to the array to be disturbed.
[3849]225    !$ACC PARALLEL LOOP COLLAPSE(3) PRIVATE(i, j, k) PRESENT(field, dist1)
[4237]226    !$OMP PARALLEL DO PRIVATE(i, j, k)
[667]227    DO  i = nxlg, nxrg
228       DO  j = nysg, nyng
[1]229          DO  k = disturbance_level_ind_b-2, disturbance_level_ind_t+2
230             field(k,j,i) = field(k,j,i) + dist1(k,j,i)
231          ENDDO
232       ENDDO
233    ENDDO
234
[3849]235!$ACC END DATA
236
[1]237!
238!-- Deallocate the temporary array
239    DEALLOCATE( dist2 )
240
241!
242!-- Set a flag, which indicates that a random perturbation is imposed
243    disturbance_created = .TRUE.
244
245
246    CALL cpu_log( log_point(20), 'disturb_field', 'stop' )
247
248
249 END SUBROUTINE disturb_field
Note: See TracBrowser for help on using the repository browser.