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

Last change on this file since 2040 was 2001, checked in by knoop, 8 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 9.0 KB
RevLine 
[1682]1!> @file disturb_field.f90
[2000]2!------------------------------------------------------------------------------!
[1036]3! This file is part of PALM.
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!
[1818]17! Copyright 1997-2016 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1318]21! ------------------
[1354]22!
[2001]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: disturb_field.f90 2001 2016-08-20 18:41:22Z gronemeier $
27!
[2001]28! 2000 2016-08-20 18:09:15Z knoop
29! Forced header and separation lines into 80 columns
30!
[1683]31! 1682 2015-10-07 23:56:08Z knoop
32! Code annotations made doxygen readable
33!
[1426]34! 1425 2014-07-05 10:57:53Z knoop
35! bugfix: Parallel random number generator loop: print-statement no needed
36!
[1401]37! 1400 2014-05-09 14:03:54Z knoop
38! Parallel random number generator added
39!
[1354]40! 1353 2014-04-08 15:21:23Z heinze
41! REAL constants provided with KIND-attribute
42!
[1323]43! 1322 2014-03-20 16:38:49Z raasch
44! REAL constants defined as wp-kind
45!
[1321]46! 1320 2014-03-20 08:40:49Z raasch
[1320]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
[1]53!
[1037]54! 1036 2012-10-22 13:43:42Z raasch
55! code put under GPL (PALM 3.9)
56!
[1]57! Revision 1.1  1998/02/04 15:40:45  raasch
58! Initial revision
59!
60!
61! Description:
62! ------------
[1682]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.
[1]68!------------------------------------------------------------------------------!
[1682]69 SUBROUTINE disturb_field( nzb_uv_inner, dist1, field )
70 
[1]71
[1320]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
[1400]88       
89    USE random_generator_parallel,                                             &
90        ONLY:  random_number_parallel, random_seed_parallel, random_dummy,     &
91               id_random_array, seq_random_array
[1]92
93    IMPLICIT NONE
94
[1682]95    INTEGER(iwp) ::  i  !<
96    INTEGER(iwp) ::  j  !<
97    INTEGER(iwp) ::  k  !<
[1320]98   
[1682]99    INTEGER(iwp) ::  nzb_uv_inner(nysg:nyng,nxlg:nxrg) !<
[1]100
[1682]101    REAL(wp) ::  randomnumber  !<
[1320]102   
[1682]103    REAL(wp) ::  dist1(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !<
104    REAL(wp) ::  field(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !<
[1320]105   
[1682]106    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  dist2  !<
[1]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
[667]114    ALLOCATE( dist2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1353]115    dist1 = 0.0_wp
116    dist2 = 0.0_wp
[1]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
[1322]124                randomnumber = 3.0_wp * disturbance_amplitude *                &
125                               ( random_function( iran ) - 0.5_wp )
[1320]126                IF ( nxl <= i  .AND.  nxr >= i  .AND.  nys <= j  .AND.         &
127                     nyn >= j )                                                &
[1]128                THEN
129                   dist1(k,j,i) = randomnumber
130                ENDIF
131             ENDDO
132          ENDDO
133       ENDDO
[1400]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
[1]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 )
[1322]156                randomnumber = 3.0_wp * disturbance_amplitude *                &
157                               ( RANDOM( 0 ) - 0.5_wp )
[1]158#else
159                CALL RANDOM_NUMBER( randomnumber )
[1322]160                randomnumber = 3.0_wp * disturbance_amplitude *                &
161                                ( randomnumber - 0.5_wp )
[1]162#endif
[1320]163                IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. nyn >= j )   &
[1]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
[420]175
[667]176    CALL exchange_horiz( dist1, nbgp )
[1]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.
[420]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
[1]185          DO  k = disturbance_level_ind_b-1, disturbance_level_ind_t+1
[1320]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)                  &
[1322]188                            ) / 12.0_wp
[420]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)  &
[1322]192                            + 6.0_wp * dist1(k,j,i)                            &
193                            ) / 12.0_wp
[1]194          ENDDO
[420]195        ENDDO
196     ENDDO
[1]197
198!
199!-- Exchange of ghost points for the filtered perturbation.
200!-- Afterwards, filter operation and exchange of ghost points are repeated.
[667]201    CALL exchange_horiz( dist2, nbgp )
[420]202
[1]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) &
[1322]208                            + 6.0_wp * dist2(k,j,i)                            &
209                            ) / 12.0_wp
[1]210          ENDDO
211       ENDDO
212    ENDDO
[420]213
[667]214    CALL exchange_horiz( dist1, nbgp )
[1]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
[667]221       DO  i = nxlg, nxrg
222          DO  j = nysg, nyng
[1353]223             dist1(nzb:nzb_uv_inner(j,i)+1,j,i) = 0.0_wp
[1]224          ENDDO
225       ENDDO
226    ENDIF
227
228!
229!-- Random perturbation is added to the array to be disturbed.
[667]230    DO  i = nxlg, nxrg
231       DO  j = nysg, nyng
[1]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.