Skip to content

Commit d1df5c2

Browse files
author
Daniel Ruprecht
committed
advection test now uses generic random number functions
1 parent e3e48a7 commit d1df5c2

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

test/src/advection_test.f90

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,43 @@ PROGRAM Upwind_Test
2525
DOUBLE PRECISION, DIMENSION(Nthreads) :: runtimes
2626
INTEGER :: i, j, k, r, nt, ierr, mpi_thread_provided, i_add, j_add, k_add
2727

28-
INTEGER :: Nx, Ny, Nz, i_start, i_end, j_start, j_end, k_start, k_end, seed, time1(8), order
28+
INTEGER, ALLOCATABLE, DIMENSION(:) :: seed
29+
30+
INTEGER :: Nx, Ny, Nz, i_start, i_end, j_start, j_end, k_start, k_end, seed_size, clock, order
31+
REAL :: random_real
2932

3033
LOGICAL, PARAMETER, DIMENSION(3) :: do_test = (/ .true. , .true., .true. /)
3134

3235
CALL MPI_INIT_THREAD(MPI_THREAD_FUNNELED, mpi_thread_provided, ierr)
3336

3437
! Create two random value for the offsets
35-
CALL DATE_AND_TIME(values=time1)
36-
seed = 1000*time1(7)+time1(8)
37-
CALL SRAND(seed)
38+
CALL RANDOM_SEED(size = seed_size)
39+
ALLOCATE(seed(seed_size))
40+
CALL SYSTEM_CLOCK(count = clock)
41+
seed = clock + 37 * (/ (i - 1, i = 1, seed_size) /)
42+
CALL RANDOM_SEED(put = seed)
43+
DEALLOCATE(seed)
3844

3945
IF (do_test(1)) THEN
4046

4147
! Test for order 1 and 5
4248
DO order=1,5,4
4349

44-
Nx = 128 + INT( RAND()*128 )
45-
Ny = 128 + INT( RAND()*128 )
46-
Nz = 128 + INT( RAND()*128 )
50+
Nx = random_integer(128, 256)
51+
Ny = random_integer(128, 256)
52+
Nz = random_integer(128, 256)
4753

4854
! Generate three random integers between -256 and +256
49-
i_start = INT( RAND()*(256+1+256) )-256
50-
j_start = INT( RAND()*(256+1+256) )-256
51-
k_start = INT( RAND()*(256+1+256) )-256
55+
i_start = random_integer(-256, 256)
56+
j_start = random_integer(-256, 256)
57+
k_start = random_integer(-256, 256)
5258

5359
! Then generate three more positive random integers between 3 and 32.
5460
! In initialization, the used buffer is enlarged by these numbers to verify the routine
5561
! can correctly work on a subset of the allocated buffer
56-
i_add = 3 + INT( RAND()*32 )
57-
j_add = 3 + INT( RAND()*32 )
58-
k_add = 3 + INT( RAND()*32 )
62+
i_add = random_integer(3, 32)
63+
j_add = random_integer(3, 32)
64+
k_add = random_integer(3, 32)
5965

6066
! The first test makes sure that a constant Q leads to a zero flux divergence. This is
6167
! for running 1 to 8 concurrent calls to GetRHS. Also, the time is measured in some
@@ -134,21 +140,21 @@ PROGRAM Upwind_Test
134140
! TEST 2: Make sure that if Q is constant in one dimension, so is the resulting RQ
135141
IF (do_test(2)) THEN
136142

137-
Nx = 32 + INT( RAND()*32 )
138-
Ny = 32 + INT( RAND()*32 )
139-
Nz = 32 + INT( RAND()*32 )
143+
Nx = random_integer(32, 64)
144+
Ny = random_integer(32, 64)
145+
Nz = random_integer(32, 64)
140146

141147
! Generate three random integers between -256 and +256
142-
i_start = INT( RAND()*(256+1+256) )-256
143-
j_start = INT( RAND()*(256+1+256) )-256
144-
k_start = INT( RAND()*(256+1+256) )-256
148+
i_start = random_integer(-256, 256)
149+
j_start = random_integer(-256, 256)
150+
k_start = random_integer(-256, 256)
145151

146152
! Then generate three more positive random integers between 3 and 32.
147153
! In initialization, the used buffer is enlarged by these numbers to verify the routine
148154
! can correctly work on a subset of the allocated buffer
149-
i_add = 3 + INT( RAND()*32 )
150-
j_add = 3 + INT( RAND()*32 )
151-
k_add = 3 + INT( RAND()*32 )
155+
i_add = random_integer(3, 32)
156+
j_add = random_integer(3, 32)
157+
k_add = random_integer(3, 32)
152158

153159
! The first test makes sure that a constant Q leads to a zero flux divergence. This is
154160
! for running 1 to 8 concurrent calls to GetRHS. Also, the time is measured in some
@@ -295,16 +301,16 @@ PROGRAM Upwind_Test
295301
dz = 1.0/DBLE(Nz)
296302

297303
! Generate three random integers between -256 and +256
298-
i_start = INT( RAND()*(256+1+256) )-256
299-
j_start = INT( RAND()*(256+1+256) )-256
300-
k_start = INT( RAND()*(256+1+256) )-256
304+
i_start = random_integer(-256, 256)
305+
j_start = random_integer(-256, 256)
306+
k_start = random_integer(-256, 256)
301307

302-
! Then generate three more positive random integers between 3 and 32.
308+
! Then generate three more positive random integers between 3 and 8.
303309
! In initialization, the used buffer is enlarged by these numbers to verify the routine
304310
! can correctly work on a subset of the allocated buffer
305-
i_add = 3 + INT( RAND()*8 )
306-
j_add = 3 + INT( RAND()*8 )
307-
k_add = 3 + INT( RAND()*8 )
311+
i_add = random_integer(3, 8)
312+
j_add = random_integer(3, 8)
313+
k_add = random_integer(3, 8)
308314

309315
i_end = i_start + Nx - 1
310316
j_end = j_start + Ny - 1
@@ -412,4 +418,14 @@ PROGRAM Upwind_Test
412418
PRINT*, '\x1B[32m[0] -- Successful: Advection module returns zero for constant input and produces expected rates of convergence. \x1B[0m'
413419
END IF
414420

415-
END PROGRAM Upwind_Test
421+
CONTAINS
422+
FUNCTION random_integer(vmin, vmax) RESULT(val)
423+
INTEGER, INTENT(IN) :: vmin, vmax
424+
INTEGER :: val
425+
426+
CALL RANDOM_NUMBER(random_real)
427+
val = vmin + FLOOR( (vmax+1-vmin)*random_real )
428+
429+
END FUNCTION random_integer
430+
431+
END PROGRAM Upwind_Test

0 commit comments

Comments
 (0)