utilities Module

Utilities for parallel random number generation and sparse arrays


Uses

  • module~~utilities~~UsesGraph module~utilities utilities iso_c_binding iso_c_binding module~utilities->iso_c_binding omp_lib omp_lib module~utilities->omp_lib

Used by

  • module~~utilities~~UsedByGraph module~utilities utilities module~libfida libfida module~libfida->module~utilities program~generate_tables generate_tables program~generate_tables->module~utilities program~fidasim fidasim program~fidasim->module~libfida

Contents


Variables

TypeVisibilityAttributesNameInitial
type(rng_type), public, dimension(:), allocatable:: rng

Interfaces

public interface randu

  • private subroutine randu_arr(randomu)

    Generate an array of uniformally-distributed random deviates

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(out), dimension(:):: randomu

    Array of uniform random deviates

  • private subroutine randu_r_arr(r, randomu)

    Generate an array of uniformally-distributed random deviates

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(out), dimension(:):: randomu

    Array of uniform random deviates

public interface randn

  • private subroutine randn_arr(randomn)

    Generate an array of normally-distributed random deviates

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(out), dimension(:):: randomn

    Array of normal random deviates

  • private subroutine randn_r_arr(r, randomn)

    Generate an array of normally-distributed random deviates

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(out), dimension(:):: randomn

    Array of normal random deviates

public interface randind_cdf

Procedure for generating a random array index/subscripts

  • private subroutine randind_r_cdf_1(r, cdf, randomi)

    Generate an array of random indices of an 1D array distributed according to cdf

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(in), dimension(:):: cdf

    1D array of index weights

    integer, intent(out), dimension(:):: randomi

    Random indices

  • private subroutine randind_cdf_1(cdf, randomi)

    Generate an array of random indices of an 1D array distributed according to cdf

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: cdf

    1D array of index weights

    integer, intent(out), dimension(:):: randomi

    Random indices

public interface randind

Procedure for generating a random array index/subscripts

  • private subroutine randind_n(n, randomi)

    Generate a array of uniformally-distributed random integers in the range [1, n]

    Arguments

    TypeIntentOptionalAttributesName
    integer, intent(in) :: n

    Largest possible value

    integer, intent(out), dimension(:):: randomi

    Array of uniform deviates

  • private subroutine randind_w_1(w, randomi)

    Generate an array of random indices of an 1D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: w

    1D array of index weights

    integer, intent(out), dimension(:):: randomi

    Random indices

  • private subroutine randind_w_2(w, randomi)

    Generate an array of random subscripts of an 2D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:):: w

    2D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_w_3(w, randomi)

    Generate an array of random subscripts of an 3D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:,:):: w

    3D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_w_4(w, randomi)

    Generate an array of random subscripts of an 4D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:,:,:):: w

    4D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_w_5(w, randomi)

    Generate an array of random subscripts of an 5D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:,:,:,:):: w

    5D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_r_n(r, n, randomi)

    Generate a array of uniformally-distributed random integers in the range [1, n]

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    integer, intent(in) :: n

    Largest possible value

    integer, intent(out), dimension(:):: randomi

    Array of uniform deviates

  • private subroutine randind_r_w_1(r, w, randomi)

    Generate an array of random indices of an 1D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(in), dimension(:):: w

    1D array of index weights

    integer, intent(out), dimension(:):: randomi

    Random indices

  • private subroutine randind_r_w_2(r, w, randomi)

    Generate an array of random subscripts of an 2D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(in), dimension(:,:), target:: w

    2D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_r_w_3(r, w, randomi)

    Generate an array of random subscripts of an 3D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(in), dimension(:,:,:), target:: w

    3D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_r_w_4(r, w, randomi)

    Generate an array of random subscripts of an 4D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(in), dimension(:,:,:,:), target:: w

    4D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

  • private subroutine randind_r_w_5(r, w, randomi)

    Generate an array of random subscripts of an 5D array distributed according to w

    Arguments

    TypeIntentOptionalAttributesName
    type(rng_type), intent(inout) :: r

    Random Number Generator

    real(kind=Float64), intent(in), dimension(:,:,:,:,:), target:: w

    5D array of subscript weights

    integer, intent(out), dimension(:,:):: randomi

    A 2D (ndim, :) array of random subscripts

public interface sparse

Creates a sparse array from a dense array

  • private subroutine sparse_1(A, SA)

    Routine to create a 1D sparse array from a 1D dense array

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: A

    Dense Array

    type(SparseArray), intent(out) :: SA

    Sparse Array

  • private subroutine sparse_2(A, SA)

    Routine to create a 2D sparse array from a 2D dense array

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:):: A

    Dense Array

    type(SparseArray), intent(out) :: SA

    Sparse Array

  • private subroutine sparse_3(A, SA)

    Routine to create a 3D sparse array from a 3D dense array

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:,:):: A

    Dense Array

    type(SparseArray), intent(out) :: SA

    Sparse Array

  • private subroutine sparse_4(A, SA)

    Routine to create a 4D sparse array from a 4D dense array

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:,:,:,:):: A

    Dense Array

    type(SparseArray), intent(out) :: SA

    Sparse Array

public interface deriv

Procedure for finding derivatives from an array

  • private subroutine deriv_1d(x, y, yp)

    Uses 3 point lagrangian method to calculate the derivative of an array

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    X Values

    real(kind=Float64), intent(in), dimension(:):: y

    Y Values

    real(kind=Float64), intent(out), dimension(:):: yp

    Derivative of Y w.r.t. X

  • private subroutine deriv_2d(x, y, z, zxp, zyp)

    Uses 3 point lagrangian method to calculate the partial derivative of an array Z w.r.t X and Y

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    X Values

    real(kind=Float64), intent(in), dimension(:):: y

    Y Values

    real(kind=Float64), intent(in), dimension(:,:):: z

    Z Values

    real(kind=Float64), intent(out), dimension(:,:):: zxp

    Derivative of Z w.r.t. X

    real(kind=Float64), intent(out), dimension(:,:):: zyp

    Derivative of Z w.r.t. Y

  • private subroutine deriv_3d(r, z, phi, f, frp, fzp, fphip)

    Uses 3 point lagrangian method to calculate the partial derivative of an array F w.r.t R, Z and Phi

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: r

    R Values

    real(kind=Float64), intent(in), dimension(:):: z

    Z Values

    real(kind=Float64), intent(in), dimension(:):: phi

    Phi Values

    real(kind=Float64), intent(in), dimension(:,:,:):: f

    F Values

    real(kind=Float64), intent(out), dimension(:,:,:):: frp

    Derivative of F w.r.t. R

    real(kind=Float64), intent(out), dimension(:,:,:):: fzp

    Derivative of F w.r.t. Z

    real(kind=Float64), intent(out), dimension(:,:,:):: fphip

    Derivative of F w.r.t. Phi

public interface interpol_coeff

Calculates interpolation coefficients

  • private subroutine interpol1D_coeff(xmin, dx, nx, xout, c, err)

    Linear interpolation coefficients and index for a 1D grid y(x)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in) :: xmin

    Minimum abscissa value

    real(kind=Float64), intent(in) :: dx

    Absissa spacing

    integer, intent(in) :: nx

    Number of abscissa

    real(kind=Float64), intent(in) :: xout

    Abscissa value to interpolate

    type(InterpolCoeffs1D), intent(out) :: c

    Interpolation Coefficients

    integer, intent(out), optional :: err

    Error code

  • private subroutine interpol1D_coeff_arr(x, xout, c, err)

    Linear interpolation coefficients and index for a 1D grid y(x)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    Abscissa values

    real(kind=Float64), intent(in) :: xout

    Abscissa value to interpolate

    type(InterpolCoeffs1D), intent(out) :: c

    Interpolation Coefficients

    integer, intent(out), optional :: err

    Error code

  • private subroutine interpol2D_coeff(xmin, dx, nx, ymin, dy, ny, xout, yout, c, err)

    Bilinear interpolation coefficients and indicies for a 2D grid z(x,y)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in) :: xmin

    Minimum abscissa

    real(kind=Float64), intent(in) :: dx

    Abscissa spacing

    integer, intent(in) :: nx

    Number of abscissa

    real(kind=Float64), intent(in) :: ymin

    Minimum ordinate

    real(kind=Float64), intent(in) :: dy

    Ordinate spacing

    integer, intent(in) :: ny

    Number of ordinates points

    real(kind=Float64), intent(in) :: xout

    Abscissa value to interpolate

    real(kind=Float64), intent(in) :: yout

    Ordinate value to interpolate

    type(InterpolCoeffs2D), intent(out) :: c

    Interpolation Coefficients

    integer, intent(out), optional :: err

    Error code

  • private subroutine interpol2D_coeff_arr(x, y, xout, yout, c, err)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    Abscissa values

    real(kind=Float64), intent(in), dimension(:):: y

    Ordinate values

    real(kind=Float64), intent(in) :: xout

    Abscissa value to interpolate

    real(kind=Float64), intent(in) :: yout

    Ordinate value to interpolate

    type(InterpolCoeffs2D), intent(out) :: c

    Interpolation Coefficients

    integer, intent(out), optional :: err

    Error code

  • private subroutine cyl_interpol3D_coeff(rmin, dr, nr, zmin, dz, nz, phimin, dphi, nphi, rout, zout, phiout, c, err)

    Cylindrical interpolation coefficients and indicies for a 3D grid

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in) :: rmin

    Minimum R

    real(kind=Float64), intent(in) :: dr

    R spacing

    integer, intent(in) :: nr

    Number of R points

    real(kind=Float64), intent(in) :: zmin

    Minimum Z

    real(kind=Float64), intent(in) :: dz

    Z spacing

    integer, intent(in) :: nz

    Number of Z points

    real(kind=Float64), intent(in) :: phimin

    Minimum phi

    real(kind=Float64), intent(in) :: dphi

    Phi spacing

    integer, intent(in) :: nphi

    Number of phi points

    real(kind=Float64), intent(in) :: rout

    R value to interpolate

    real(kind=Float64), intent(in) :: zout

    Z value to interpolate

    real(kind=Float64), intent(in) :: phiout

    Phi value to interpolate

    type(InterpolCoeffs3D), intent(out) :: c

    Interpolation Coefficients

    integer, intent(out), optional :: err

    Error code

  • private subroutine cyl_interpol3D_coeff_arr(r, z, phi, rout, zout, phiout, c, err)

    Cylindrical interpolation coefficients and indicies for a 3D grid

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: r

    R values

    real(kind=Float64), intent(in), dimension(:):: z

    Z values

    real(kind=Float64), intent(in), dimension(:):: phi

    Phi values

    real(kind=Float64), intent(in) :: rout

    R value to interpolate

    real(kind=Float64), intent(in) :: zout

    Z value to interpolate

    real(kind=Float64), intent(in) :: phiout

    Phi value to interpolate

    type(InterpolCoeffs3D), intent(out) :: c

    Interpolation Coefficients

    integer, intent(out), optional :: err

    Error code

public interface interpol

Performs linear/bilinear/cylindrical interpolation

  • private subroutine interpol1D_arr(x, y, xout, yout, err, coeffs)

    Performs linear interpolation on a uniform 1D grid y(x)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    The abscissa values of y

    real(kind=Float64), intent(in), dimension(:):: y

    Values at abscissa values x: y(x)

    real(kind=Float64), intent(in) :: xout

    Abscissa value to interpolate

    real(kind=Float64), intent(out) :: yout

    Interpolant: y(xout)

    integer, intent(out), optional :: err

    Error code

    type(InterpolCoeffs1D), intent(in), optional :: coeffs

    Precomputed Linear Interpolation Coefficients

  • private subroutine interpol2D_arr(x, y, z, xout, yout, zout, err, coeffs)

    Performs bilinear interpolation on a 2D grid z(x,y)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    The abscissa values of z

    real(kind=Float64), intent(in), dimension(:):: y

    The ordinate values of z

    real(kind=Float64), intent(in), dimension(:,:):: z

    Values at the abscissa/ordinates: z(x,y)

    real(kind=Float64), intent(in) :: xout

    The abscissa value to interpolate

    real(kind=Float64), intent(in) :: yout

    The ordinate value to interpolate

    real(kind=Float64), intent(out) :: zout

    Interpolant: z(xout,yout)

    integer, intent(out), optional :: err

    Error code

    type(InterpolCoeffs2D), intent(in), optional :: coeffs

    Precomputed Linear Interpolation Coefficients

  • private subroutine interpol2D_2D_arr(x, y, z, xout, yout, zout, err, coeffs)

    Performs bilinear interpolation on a 2D grid of 2D arrays z(:,:,x,y)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: x

    The abscissa values of z

    real(kind=Float64), intent(in), dimension(:):: y

    The ordinate values of z

    real(kind=Float64), intent(in), dimension(:,:,:,:):: z

    Values at the abscissa/ordinates: z(:,:,x,y)

    real(kind=Float64), intent(in) :: xout

    The abscissa value to interpolate

    real(kind=Float64), intent(in) :: yout

    The ordinate value to interpolate

    real(kind=Float64), intent(out), dimension(:,:):: zout

    Interpolant: z(:,:,xout,yout)

    integer, intent(out), optional :: err

    Error code

    type(InterpolCoeffs2D), intent(in), optional :: coeffs

    Precomputed Linear Interpolation Coefficients

  • private subroutine interpol3D_arr(r, z, phi, d, rout, zout, phiout, dout, err, coeffs)

    Performs cylindrical interpolation on a 3D grid f(r,z,phi)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: r

    R values

    real(kind=Float64), intent(in), dimension(:):: z

    Z values

    real(kind=Float64), intent(in), dimension(:):: phi

    Phi values

    real(kind=Float64), intent(in), dimension(:,:,:):: d

    Values at r,z,phi: d(r,z,phi)

    real(kind=Float64), intent(in) :: rout

    R value to interpolate

    real(kind=Float64), intent(in) :: zout

    Z value to interpolate

    real(kind=Float64), intent(in) :: phiout

    Phi value to interpolate

    real(kind=Float64), intent(out) :: dout

    Interpolant: d(rout,zout,phiout)

    integer, intent(out), optional :: err

    Error code

    type(InterpolCoeffs3D), intent(in), optional :: coeffs

    Precomputed Interpolation Coefficients

  • private subroutine interpol3D_2D_arr(r, z, phi, f, rout, zout, phiout, fout, err, coeffs)

    Performs cylindrical interpolation on a 3D grid of 2D arrays f(:,:,r,z,phi)

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=Float64), intent(in), dimension(:):: r

    R values

    real(kind=Float64), intent(in), dimension(:):: z

    Z values

    real(kind=Float64), intent(in), dimension(:):: phi

    Phi values

    real(kind=Float64), intent(in), dimension(:,:,:,:,:):: f

    Values at r,z,phi: f(:,:,r,z,phi)

    real(kind=Float64), intent(in) :: rout

    R value to interpolate

    real(kind=Float64), intent(in) :: zout

    Z value to interpolate

    real(kind=Float64), intent(in) :: phiout

    Phi value to interpolate

    real(kind=Float64), intent(out), dimension(:,:):: fout

    Interpolant: f(:,:,rout,zout,phiout)

    integer, intent(out), optional :: err

    Error code

    type(InterpolCoeffs3D), intent(in), optional :: coeffs

    Precomputed Interpolation Coefficients


Derived Types

type, public :: rng_type

Random Number Generator Derived Type

type, public :: SparseArray

type, public :: InterpolCoeffs1D

Linear Interpolation Coefficients and indices

type, public :: InterpolCoeffs2D

2D Linear Interpolation Coefficients and indices

type, public :: InterpolCoeffs3D

3D Cylindrical Interpolation Coefficients and indices


Functions

public function sub2ind(dims, subs) result(ind)

Calculates the linear index of an array with dimensions dims and subcripts subs

Arguments

TypeIntentOptionalAttributesName
integer, intent(in), dimension(:):: dims

Dimension of Array

integer, intent(in), dimension(:):: subs

Subscripts to convert

Return Value integer

Linear index

public function rng_seed() result(seed)

Generates random 32-bit integer seed from /dev/urandom

Arguments

None

Return Value integer(kind=Int32)

Seed value

public function get_rng() result(r)

Arguments

None

Return Value type(rng_type)

public function rng_uniform(self) result(u)

Generate a uniformally-distributed random number in the range [0,1)

Arguments

TypeIntentOptionalAttributesName
type(rng_type), intent(inout) :: self

Random Number Generator

Return Value real(kind=Float64)

Uniform random deviate

public function rng_normal(self) result(n)

Generate a normally-distributed random number with mean 0 and standard deviation 1

Arguments

TypeIntentOptionalAttributesName
type(rng_type), intent(inout) :: self

Random Number Generator

Return Value real(kind=Float64)

Normal random deviate

public function get_value(SA, subs) result(val)

Gets value of sparse array SA at the subscripts subs

Arguments

TypeIntentOptionalAttributesName
type(SparseArray), intent(in) :: SA

Sparse Array

integer, intent(in), dimension(:):: subs

Subscripts of Sparse Array

Return Value real(kind=Float64)

Value of SA at subs

public function time_string(time_start) result(time_str)

Returns time string

Arguments

TypeIntentOptionalAttributesName
integer, intent(in), optional dimension(8):: time_start

Optional start time

Return Value character(len=30)

Time string

public function norm2(in) result(res)

Arguments

TypeIntentOptionalAttributesName
real(kind=Float64), dimension(:):: in

Return Value real(kind=Float64)


Subroutines

public subroutine ind2sub(dims, ind, subs)

Calculate the subscripts subs into an array with dimensions dims given the corresponding linear index ind

Arguments

TypeIntentOptionalAttributesName
integer, intent(in), dimension(:):: dims

Dimensions of array

integer, intent(in) :: ind

Linear index

integer, intent(out), dimension(:):: subs

Subscripts corresponding to the linear index

public subroutine rng_init(self, seed)

Procedure to initialize a random number generator with a seed. If seed is negative then random seed is used

Arguments

TypeIntentOptionalAttributesName
type(rng_type), intent(inout) :: self

Random Number Generator

integer(kind=Int32), intent(in) :: seed

Initial Seed Value

public subroutine cumsum(x, cs)

Calculate cumulative sum

Arguments

TypeIntentOptionalAttributesName
real(kind=Float64), intent(in), dimension(:):: x

Array to sum

real(kind=Float64), intent(out), dimension(:):: cs

Cumulative sum of x