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

Last change on this file since 2172 was 2172, checked in by knoop, 4 years ago

Bugfix: parallel random number generator

  • Property svn:keywords set to Id
File size: 9.0 KB
Line 
1!> @file disturb_field.f90
2!------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
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.
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!
17! Copyright 1997-2017 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! Bugfix removed id_random_array from USE list
23!
24! Former revisions:
25! -----------------
26! $Id: disturb_field.f90 2172 2017-03-08 15:55:25Z knoop $
27!
28! 2000 2016-08-20 18:09:15Z knoop
29! Forced header and separation lines into 80 columns
30!
31! 1682 2015-10-07 23:56:08Z knoop
32! Code annotations made doxygen readable
33!
34! 1425 2014-07-05 10:57:53Z knoop
35! bugfix: Parallel random number generator loop: print-statement no needed
36!
37! 1400 2014-05-09 14:03:54Z knoop
38! Parallel random number generator added
39!
40! 1353 2014-04-08 15:21:23Z heinze
41! REAL constants provided with KIND-attribute
42!
43! 1322 2014-03-20 16:38:49Z raasch
44! REAL constants defined as wp-kind
45!
46! 1320 2014-03-20 08:40:49Z raasch
47! ONLY-attribute added to USE-statements,
48! kind-parameters added to all INTEGER and REAL declaration statements,
49! kinds are defined in new module kinds,
50! revision history before 2012 removed,
51! comment fields (!:) to be used for variable explanations added to
52! all variable declaration statements
53!
54! 1036 2012-10-22 13:43:42Z raasch
55! code put under GPL (PALM 3.9)
56!
57! Revision 1.1  1998/02/04 15:40:45  raasch
58! Initial revision
59!
60!
61! Description:
62! ------------
63!> Imposing a random perturbation on a 3D-array.
64!> On parallel computers, the random number generator is as well called for all
65!> gridpoints of the total domain to ensure, regardless of the number of PEs
66!> used, that the elements of the array have the same values in the same
67!> order in every case. The perturbation range is steered by dist_range.
68!------------------------------------------------------------------------------!
69 SUBROUTINE disturb_field( nzb_uv_inner, dist1, field )
70 
71
72    USE control_parameters,   &
73        ONLY:  dist_nxl, dist_nxr, dist_nyn, dist_nys, dist_range,             &
74               disturbance_amplitude, disturbance_created,                     &
75               disturbance_level_ind_b, disturbance_level_ind_t, iran,         &
76               random_generator, topography
77               
78    USE cpulog,                                                                &
79        ONLY:  cpu_log, log_point
80       
81    USE indices,                                                               &
82        ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt
83       
84    USE kinds
85   
86    USE random_function_mod,                                                   &
87        ONLY: random_function
88       
89    USE random_generator_parallel,                                             &
90        ONLY:  random_number_parallel, random_seed_parallel, random_dummy,     &
91               seq_random_array
92
93    IMPLICIT NONE
94
95    INTEGER(iwp) ::  i  !<
96    INTEGER(iwp) ::  j  !<
97    INTEGER(iwp) ::  k  !<
98   
99    INTEGER(iwp) ::  nzb_uv_inner(nysg:nyng,nxlg:nxrg) !<
100
101    REAL(wp) ::  randomnumber  !<
102   
103    REAL(wp) ::  dist1(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !<
104    REAL(wp) ::  field(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !<
105   
106    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  dist2  !<
107
108
109    CALL cpu_log( log_point(20), 'disturb_field', 'start' )
110
111!
112!-- Create an additional temporary array and initialize the arrays needed
113!-- to store the disturbance
114    ALLOCATE( dist2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
115    dist1 = 0.0_wp
116    dist2 = 0.0_wp
117
118!
119!-- Create the random perturbation and store it on temporary array
120    IF ( random_generator == 'numerical-recipes' )  THEN
121       DO  i = dist_nxl(dist_range), dist_nxr(dist_range)
122          DO  j = dist_nys(dist_range), dist_nyn(dist_range)
123             DO  k = disturbance_level_ind_b, disturbance_level_ind_t
124                randomnumber = 3.0_wp * disturbance_amplitude *                &
125                               ( random_function( iran ) - 0.5_wp )
126                IF ( nxl <= i  .AND.  nxr >= i  .AND.  nys <= j  .AND.         &
127                     nyn >= j )                                                &
128                THEN
129                   dist1(k,j,i) = randomnumber
130                ENDIF
131             ENDDO
132          ENDDO
133       ENDDO
134    ELSEIF ( random_generator == 'random-parallel' )  THEN
135       DO  i = dist_nxl(dist_range), dist_nxr(dist_range)
136          DO  j = dist_nys(dist_range), dist_nyn(dist_range)
137             CALL random_seed_parallel( put=seq_random_array(:, j, i) )
138             DO  k = disturbance_level_ind_b, disturbance_level_ind_t
139                CALL random_number_parallel( random_dummy )
140                randomnumber = 3.0_wp * disturbance_amplitude *                &
141                               ( random_dummy - 0.5_wp )
142                IF ( nxl <= i  .AND.  nxr >= i  .AND.  nys <= j  .AND.         &
143                     nyn >= j )                                                &
144                THEN
145                   dist1(k,j,i) = randomnumber
146                ENDIF
147             ENDDO
148             CALL random_seed_parallel( get=seq_random_array(:, j, i) )
149          ENDDO
150       ENDDO
151    ELSEIF ( random_generator == 'system-specific' )  THEN
152       DO  i = dist_nxl(dist_range), dist_nxr(dist_range)
153          DO  j = dist_nys(dist_range), dist_nyn(dist_range)
154             DO  k = disturbance_level_ind_b, disturbance_level_ind_t
155#if defined( __nec )
156                randomnumber = 3.0_wp * disturbance_amplitude *                &
157                               ( RANDOM( 0 ) - 0.5_wp )
158#else
159                CALL RANDOM_NUMBER( randomnumber )
160                randomnumber = 3.0_wp * disturbance_amplitude *                &
161                                ( randomnumber - 0.5_wp )
162#endif
163                IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. nyn >= j )   &
164                THEN
165                   dist1(k,j,i) = randomnumber
166                ENDIF
167             ENDDO
168          ENDDO
169       ENDDO
170
171    ENDIF
172
173!
174!-- Exchange of ghost points for the random perturbation
175
176    CALL exchange_horiz( dist1, nbgp )
177!
178!-- Applying the Shuman filter in order to smooth the perturbations.
179!-- Neighboured grid points in all three directions are used for the
180!-- filter operation.
181!-- Loop has been splitted to make runs reproducible on HLRN systems using
182!-- compiler option -O3
183     DO  i = nxl, nxr
184        DO  j = nys, nyn
185          DO  k = disturbance_level_ind_b-1, disturbance_level_ind_t+1
186             dist2(k,j,i) = ( dist1(k,j,i-1) + dist1(k,j,i+1)                  &
187                            + dist1(k,j+1,i) + dist1(k+1,j,i)                  &
188                            ) / 12.0_wp
189          ENDDO
190          DO  k = disturbance_level_ind_b-1, disturbance_level_ind_t+1
191              dist2(k,j,i) = dist2(k,j,i) + ( dist1(k,j-1,i) + dist1(k-1,j,i)  &
192                            + 6.0_wp * dist1(k,j,i)                            &
193                            ) / 12.0_wp
194          ENDDO
195        ENDDO
196     ENDDO
197
198!
199!-- Exchange of ghost points for the filtered perturbation.
200!-- Afterwards, filter operation and exchange of ghost points are repeated.
201    CALL exchange_horiz( dist2, nbgp )
202
203    DO  i = nxl, nxr
204       DO  j = nys, nyn
205          DO  k = disturbance_level_ind_b-2, disturbance_level_ind_t+2
206             dist1(k,j,i) = ( dist2(k,j,i-1) + dist2(k,j,i+1) + dist2(k,j-1,i) &
207                            + dist2(k,j+1,i) + dist2(k+1,j,i) + dist2(k-1,j,i) &
208                            + 6.0_wp * dist2(k,j,i)                            &
209                            ) / 12.0_wp
210          ENDDO
211       ENDDO
212    ENDDO
213
214    CALL exchange_horiz( dist1, nbgp )
215
216!
217!-- Remove perturbations below topography (including one gridpoint above it
218!-- in order to allow for larger timesteps at the beginning of the simulation
219!-- (diffusion criterion))
220    IF ( TRIM( topography ) /= 'flat' )  THEN
221       DO  i = nxlg, nxrg
222          DO  j = nysg, nyng
223             dist1(nzb:nzb_uv_inner(j,i)+1,j,i) = 0.0_wp
224          ENDDO
225       ENDDO
226    ENDIF
227
228!
229!-- Random perturbation is added to the array to be disturbed.
230    DO  i = nxlg, nxrg
231       DO  j = nysg, nyng
232          DO  k = disturbance_level_ind_b-2, disturbance_level_ind_t+2
233             field(k,j,i) = field(k,j,i) + dist1(k,j,i)
234          ENDDO
235       ENDDO
236    ENDDO
237
238!
239!-- Deallocate the temporary array
240    DEALLOCATE( dist2 )
241
242!
243!-- Set a flag, which indicates that a random perturbation is imposed
244    disturbance_created = .TRUE.
245
246
247    CALL cpu_log( log_point(20), 'disturb_field', 'stop' )
248
249
250 END SUBROUTINE disturb_field
Note: See TracBrowser for help on using the repository browser.