mom_random module reference

Provides gridded random number capability.

More…

Data Types

prng

Container for pseudo-random number generators.

Functions/Subroutines

random_01()

Returns a random number between 0 and 1.

random_norm()

Returns an approximately normally distributed random number with mean 0 and variance 1.

random_2d_01()

Generates random numbers between 0 and 1 for each cell of the model grid.

random_2d_norm()

Returns an approximately normally distributed random number with mean 0 and variance 1 for each cell of the model grid.

random_0d_constructor()

Constructor for scalar PRNG.

random_2d_constructor()

Constructor for gridded PRNG.

seed_from_time()

Return a seed derived as hash of values in Time.

seed_from_index()

Create seed from position index.

random_destruct()

Destructor for PRNG.

random_unit_tests()

Runs some statistical tests on the PRNG.

test_fn()

Convenience function for reporting result of test.

Detailed Description

Provides MOM6 wrappers to the FMS implementation of the Mersenne twister.

Example usage:

type(PRNG)  ::  rng
real  ::  rn
call  random_0d_constructor(rng,  Time,  seed)  !  Call  this  each  time-step
rn  =  random_01(rng)
rn  =  random_norm(rng)

type(PRNG)  ::  rng
real,  dimension(:,:)  ::  rn2d
call  random_2d_constructor(rng,  HI,  Time,  seed)  !  Call  this  each  time-step
call  random_2d_01(rng,  HI,  rn2d)
call  random_2d_norm(rng,  HI,  rn2d)

Note:  reproducibility  across  restarts  is  implemented  by  using  time-derived
seeds  to  pass  to  the  Mersenne  twister.  It  is  therefore  important  that  any
PRNG  type  be  re-initialized  each  time-step.

Type Documentation

type mom_random/prng

Container for pseudo-random number generators.

Type fields
  • % stream0d [type(randomnumbersequence)] :: Scalar random number generator for whole model.

  • % stream2d [type(randomnumbersequence)(:,:),allocatable] :: Random number generator for each cell on horizontal grid.

Function/Subroutine Documentation

function mom_random/random_01(CS) [real]

Returns a random number between 0 and 1.

Parameters

cs :: [inout] Container for pseudo-random number generators

Called from

random_unit_tests

function mom_random/random_norm(CS) [real]

Returns an approximately normally distributed random number with mean 0 and variance 1.

Parameters

cs :: [inout] Container for pseudo-random number generators

Called from

random_unit_tests

subroutine mom_random/random_2d_01(CS, HI, rand)

Generates random numbers between 0 and 1 for each cell of the model grid.

Parameters
  • cs :: [inout] Container for pseudo-random number generators

  • hi :: [in] Horizontal index structure

  • rand :: [out] Random numbers between 0 and 1

Called from

random_unit_tests

subroutine mom_random/random_2d_norm(CS, HI, rand)

Returns an approximately normally distributed random number with mean 0 and variance 1 for each cell of the model grid.

Parameters
  • cs :: [inout] Container for pseudo-random number generators

  • hi :: [in] Horizontal index structure

  • rand :: [out] Random numbers between 0 and 1

Called from

random_unit_tests

subroutine mom_random/random_0d_constructor(CS, Time, seed)

Constructor for scalar PRNG. Can be used to reset the sequence.

Parameters
  • cs :: [inout] Container for pseudo-random number generators

  • time :: [in] Current model time

  • seed :: [in] Seed for PRNG

Call to

seed_from_time

Called from

random_unit_tests

subroutine mom_random/random_2d_constructor(CS, HI, Time, seed)

Constructor for gridded PRNG. Can be used to reset the sequence.

Parameters
  • cs :: [inout] Container for pseudo-random number generators

  • hi :: [in] Horizontal index structure

  • time :: [in] Current model time

  • seed :: [in] Seed for PRNG

Call to

seed_from_index seed_from_time

Called from

random_unit_tests

function mom_random/seed_from_time(Time) [integer]

Return a seed derived as hash of values in Time.

Parameters

time :: [in] Current model time

Called from

random_0d_constructor random_2d_constructor random_unit_tests

function mom_random/seed_from_index(HI, i, j) [integer]

Create seed from position index.

Parameters
  • hi :: [in] Horizontal index structure

  • i :: [in] i-index (of h-cell)

  • j :: [in] j-index (of h-cell)

Called from

random_2d_constructor random_unit_tests

subroutine mom_random/random_destruct(CS)

Destructor for PRNG.

Parameters

cs :: Container for pseudo-random number generators

function mom_random/random_unit_tests(verbose) [logical]

Runs some statistical tests on the PRNG.

Parameters

verbose :: True if results should be written to stdout

Call to

random_01 random_0d_constructor random_2d_01 random_2d_constructor random_2d_norm random_norm seed_from_index seed_from_time test_fn

Called from

mom_unit_tests::unit_tests

function mom_random/test_fn(verbose, good, label, rvalue, ivalue) [logical]

Convenience function for reporting result of test.

Parameters
  • verbose :: [in] Verbosity

  • good :: [in] True if pass, false otherwise

  • label :: [in] Label for messages

  • rvalue :: [in] Result of calculation

  • ivalue :: [in] Result of calculation

Called from

random_unit_tests