Octopus
math_oct_m Module Reference

This module is intended to contain "only mathematical" functions and procedures. More...

Detailed Description

This module is intended to contain "only mathematical" functions and procedures.

Data Types

interface  diagonal_matrix
 
interface  expm1
 
interface  interpolate
 This is the common interface to a simple-minded polynomical interpolation procedure (simple use of the classical formula of Lagrange). More...
 
interface  is_close
 
interface  log2
 
interface  lower_triangular_to_hermitian
 
interface  pad
 
interface  symmetrize_matrix
 
interface  upper_triangular_to_hermitian
 

Functions/Subroutines

elemental logical function dis_close_scalar (x, y, rtol, atol)
 Are \(x\) and \(y\) equal within a tolerance. More...
 
elemental logical function zis_close_scalar (x, y, rtol, atol)
 Same as dis_close_scalar for complex numbers. More...
 
pure integer function, dimension(dim, dim) idiagonal_matrix (dim, diag)
 Currently only returns a matrix whose diagonal elements are all the same. Note that the real and complex versions are in math_inc.F90. More...
 
recursive real(real64) function, public hermite (n, x)
 
recursive integer function, public factorial (n)
 
subroutine, public ylmr_cmplx (xx, li, mi, ylm)
 Computes spherical harmonics ylm at position (x, y, z) More...
 
subroutine, public ylmr_real (xx, li, mi, ylm)
 This is a Numerical Recipes-based subroutine computes real spherical harmonics ylm at position (x, y, z): ylm = c * plm( cos(theta) ) * sin(m*phi) for m < 0 ylm = c * plm( cos(theta) ) * cos(m*phi) for m >= 0 with (theta,phi) the polar angles of r, c a positive normalization. More...
 
subroutine, public weights (N, M, cc, side)
 Compute the weights for finite-difference calculations: More...
 
real(real64) pure function, public ddelta (i, j)
 
subroutine, public interpolation_coefficients (nn, xa, xx, cc)
 
logical pure function, public even (n)
 Returns if n is even. More...
 
logical pure function, public odd (n)
 Returns if n is odd. More...
 
subroutine, public cartesian2hyperspherical (x, u)
 Performs a transformation of an n-dimensional vector from Cartesian coordinates to hyperspherical coordinates. More...
 
subroutine, public hyperspherical2cartesian (u, x)
 Performs the inverse transformation of cartesian2hyperspherical. More...
 
subroutine, public hypersphere_grad_matrix (grad_matrix, r, x)
 Gives the hyperspherical gradient matrix, which contains the derivatives of the Cartesian coordinates with respect to the hyperspherical angles. More...
 
integer(int64) pure function pad88 (size, blk)
 
integer(int64) pure function pad48 (size, blk)
 
integer(int64) pure function pad8 (size, blk)
 
integer pure function pad4 (size, blk)
 
integer pure function, public pad_pow2 (size)
 create array size, which is padded to powers of 2 More...
 
real(real64) pure function dlog2 (xx)
 
integer pure function ilog2 (xx)
 
integer(int64) pure function llog2 (xx)
 
complex(real64) pure function, public exponential (z)
 Wrapper for exponential. More...
 
complex(real64) pure function, public phi1 (z)
 Compute phi1(z) = (exp(z)-1)/z. More...
 
complex(real64) pure function, public phi2 (z)
 Compute phi2(z) = (phi1(z)-1)/z = (exp(z) - z - 1)/z^2. More...
 
real(real64) pure function, public square_root (x)
 Wrapper for sqrt. More...
 
logical function, public is_prime (n)
 
subroutine, public generate_rotation_matrix (R, ff, tt)
 Generates a rotation matrix R to rotate a vector f to t. More...
 
subroutine, public numder_ridders (x, h, res, err, f)
 Numerical derivative (Ridder`s algorithm). More...
 
pure complex(real64) function, dimension(1:3), public dzcross_product (a, b)
 
pure complex(real64) function, dimension(1:3), public zdcross_product (a, b)
 
subroutine, public generalized_laguerre_polynomial (np, nn, mm, xx, cx)
 
subroutine dupper_triangular_to_hermitian (nn, aa)
 
subroutine zupper_triangular_to_hermitian (nn, aa)
 
subroutine dlower_triangular_to_hermitian (nn, aa)
 
subroutine zlower_triangular_to_hermitian (nn, aa)
 
subroutine dsymmetrize_matrix (nn, aa)
 symmetrize a real matrix More...
 
subroutine zsymmetrize_matrix (n, a)
 make a complex matrix Hermitian More...
 
subroutine, public dzero_small_elements_matrix (aa, tol)
 
logical function, public is_symmetric (a, tol)
 Check if a 2D array is symmetric. More...
 
logical pure function, public is_diagonal (dim, matrix, tol)
 Returns true is the matrix of size dim x dim is diagonal, given a relative tolerance. More...
 
subroutine, public convert_to_base (num, base, converted)
 convert an integer in base 10 to a different base More...
 
subroutine, public convert_from_base (converted, base, num)
 convert an integer to base 10 from a different base More...
 
pure complex(real64) function, dimension(dim, dim) zdiagonal_matrix (dim, diag)
 Currently only returns a matrix whose diagonal elements are all the same. Note that the integer version is in math.F90. More...
 
subroutine zinterpolate_2 (xa, ya, x, y)
 
subroutine zinterpolate_1 (xa, ya, x, y)
 
subroutine zinterpolate_0 (xa, ya, x, y)
 
pure complex(real64) function, dimension(1:3), public zcross_product (a, b)
 
pure real(real64) function, dimension(dim, dim) ddiagonal_matrix (dim, diag)
 Currently only returns a matrix whose diagonal elements are all the same. Note that the integer version is in math.F90. More...
 
subroutine dinterpolate_2 (xa, ya, x, y)
 
subroutine dinterpolate_1 (xa, ya, x, y)
 
subroutine dinterpolate_0 (xa, ya, x, y)
 
pure real(real64) function, dimension(1:3), public dcross_product (a, b)
 

Function/Subroutine Documentation

◆ dis_close_scalar()

elemental logical function math_oct_m::dis_close_scalar ( real(real64), intent(in)  x,
real(real64), intent(in)  y,
real(real64), intent(in), optional  rtol,
real(real64), intent(in), optional  atol 
)
private

Are \(x\) and \(y\) equal within a tolerance.

The function evaluates the expression:

\[ |x - y| \leq (atol * rtol) * |y| \]

The tolerance values are positive, typically very small numbers. The relative difference \((rtol * |y|)\) and the absolute difference \( atol \) are added together to compare against the absolute difference between \(x\) and \(y\). Default tolerances are based on numpy''s [implementation](https:

Parameters
[in]xScalar.
[in]yScalar.
[in]rtolOptional, relative tolerance.
[in]atolOptional, absolute tolerance.
Returns
is_close .true. if \(x\) and \(y\) are close.

Definition at line 233 of file math.F90.

◆ zis_close_scalar()

elemental logical function math_oct_m::zis_close_scalar ( complex(real64), intent(in)  x,
complex(real64), intent(in)  y,
real(real64), intent(in), optional  rtol,
real(real64), intent(in), optional  atol 
)
private

Same as dis_close_scalar for complex numbers.

Definition at line 246 of file math.F90.

◆ idiagonal_matrix()

pure integer function, dimension(dim, dim) math_oct_m::idiagonal_matrix ( integer, intent(in)  dim,
integer, intent(in)  diag 
)
private

Currently only returns a matrix whose diagonal elements are all the same. Note that the real and complex versions are in math_inc.F90.

Definition at line 262 of file math.F90.

◆ hermite()

recursive real(real64) function, public math_oct_m::hermite ( integer, intent(in)  n,
real(real64), intent(in)  x 
)

Definition at line 277 of file math.F90.

◆ factorial()

recursive integer function, public math_oct_m::factorial ( integer, intent(in)  n)

Definition at line 297 of file math.F90.

◆ ylmr_cmplx()

subroutine, public math_oct_m::ylmr_cmplx ( real(real64), dimension(3), intent(in)  xx,
integer, intent(in)  li,
integer, intent(in)  mi,
complex(real64), intent(out)  ylm 
)

Computes spherical harmonics ylm at position (x, y, z)

Definition at line 313 of file math.F90.

◆ ylmr_real()

subroutine, public math_oct_m::ylmr_real ( real(real64), dimension(3), intent(in)  xx,
integer, intent(in)  li,
integer, intent(in)  mi,
real(real64), intent(out)  ylm 
)

This is a Numerical Recipes-based subroutine computes real spherical harmonics ylm at position (x, y, z): ylm = c * plm( cos(theta) ) * sin(m*phi) for m < 0 ylm = c * plm( cos(theta) ) * cos(m*phi) for m >= 0 with (theta,phi) the polar angles of r, c a positive normalization.

Definition at line 384 of file math.F90.

◆ weights()

subroutine, public math_oct_m::weights ( integer, intent(in)  N,
integer, intent(in)  M,
real(real64), dimension(0:,0:,0:), intent(out)  cc,
integer, intent(in), optional  side 
)

Compute the weights for finite-difference calculations:

N -> highest order of the derivative to be approximated M -> number of grid points to be used in the approximation.

c(j,k,i) -> ith order derivative at kth-order approximation j=0,k: the coefficients acting of each point

side -> -1 left-sided, +1 right-sided, 0 centered (default)

Parameters
[out]cc(0:M, 0:M, 0:N)

Definition at line 534 of file math.F90.

◆ ddelta()

real(real64) pure function, public math_oct_m::ddelta ( integer, intent(in)  i,
integer, intent(in)  j 
)

Definition at line 610 of file math.F90.

◆ interpolation_coefficients()

subroutine, public math_oct_m::interpolation_coefficients ( integer, intent(in)  nn,
real(real64), dimension(:), intent(in)  xa,
real(real64), intent(in)  xx,
real(real64), dimension(:), intent(out)  cc 
)
Parameters
[in]nnthe number of points and coefficients
[in]xathe nn points where we know the function
[in]xxthe point where we want the function
[out]ccthe coefficients

Definition at line 625 of file math.F90.

◆ even()

logical pure function, public math_oct_m::even ( integer, intent(in)  n)

Returns if n is even.

Definition at line 648 of file math.F90.

◆ odd()

logical pure function, public math_oct_m::odd ( integer, intent(in)  n)

Returns if n is odd.

Definition at line 658 of file math.F90.

◆ cartesian2hyperspherical()

subroutine, public math_oct_m::cartesian2hyperspherical ( real(real64), dimension(:), intent(in)  x,
real(real64), dimension(:), intent(out)  u 
)

Performs a transformation of an n-dimensional vector from Cartesian coordinates to hyperspherical coordinates.

Definition at line 668 of file math.F90.

◆ hyperspherical2cartesian()

subroutine, public math_oct_m::hyperspherical2cartesian ( real(real64), dimension(:), intent(in)  u,
real(real64), dimension(:), intent(out)  x 
)

Performs the inverse transformation of cartesian2hyperspherical.

Definition at line 715 of file math.F90.

◆ hypersphere_grad_matrix()

subroutine, public math_oct_m::hypersphere_grad_matrix ( real(real64), dimension(:,:), intent(out)  grad_matrix,
real(real64), intent(in)  r,
real(real64), dimension(:), intent(in)  x 
)

Gives the hyperspherical gradient matrix, which contains the derivatives of the Cartesian coordinates with respect to the hyperspherical angles.

Parameters
[in]rradius of hypersphere
[in]xarray of hyperspherical angles

Definition at line 761 of file math.F90.

◆ pad88()

integer(int64) pure function math_oct_m::pad88 ( integer(int64), intent(in)  size,
integer(int64), intent(in)  blk 
)
private

Definition at line 801 of file math.F90.

◆ pad48()

integer(int64) pure function math_oct_m::pad48 ( integer, intent(in)  size,
integer(int64), intent(in)  blk 
)
private

Definition at line 816 of file math.F90.

◆ pad8()

integer(int64) pure function math_oct_m::pad8 ( integer(int64), intent(in)  size,
integer, intent(in)  blk 
)
private

Definition at line 824 of file math.F90.

◆ pad4()

integer pure function math_oct_m::pad4 ( integer, intent(in)  size,
integer, intent(in)  blk 
)
private

Definition at line 832 of file math.F90.

◆ pad_pow2()

integer pure function, public math_oct_m::pad_pow2 ( integer, intent(in)  size)

create array size, which is padded to powers of 2

This helps alignment of data, and is necessary for some device hosted arrays

Definition at line 845 of file math.F90.

◆ dlog2()

real(real64) pure function math_oct_m::dlog2 ( real(real64), intent(in)  xx)
private

Definition at line 874 of file math.F90.

◆ ilog2()

integer pure function math_oct_m::ilog2 ( integer, intent(in)  xx)
private

Definition at line 882 of file math.F90.

◆ llog2()

integer(int64) pure function math_oct_m::llog2 ( integer(int64), intent(in)  xx)
private

Definition at line 890 of file math.F90.

◆ exponential()

complex(real64) pure function, public math_oct_m::exponential ( complex(real64), intent(in)  z)

Wrapper for exponential.

Definition at line 898 of file math.F90.

◆ phi1()

complex(real64) pure function, public math_oct_m::phi1 ( complex(real64), intent(in)  z)

Compute phi1(z) = (exp(z)-1)/z.

Use the power series \( \sum^{4}_{k=0} z^k/(k+1)! \) for small arguments to avoid round-off errors. The expression and the cut value are similar to those from [GSL](https:

Definition at line 910 of file math.F90.

◆ phi2()

complex(real64) pure function, public math_oct_m::phi2 ( complex(real64), intent(in)  z)

Compute phi2(z) = (phi1(z)-1)/z = (exp(z) - z - 1)/z^2.

Use the power series \( \sum^{4}_{k=0} z^k/(k+2)! \) for small arguments to avoid round-off errors. The expression and the cut value are similar to those from [GSL](https: (there is a difference by a factor of 2 between the two definitions).

Definition at line 929 of file math.F90.

◆ square_root()

real(real64) pure function, public math_oct_m::square_root ( real(real64), intent(in)  x)

Wrapper for sqrt.

Definition at line 943 of file math.F90.

◆ is_prime()

logical function, public math_oct_m::is_prime ( integer, intent(in)  n)

Definition at line 951 of file math.F90.

◆ generate_rotation_matrix()

subroutine, public math_oct_m::generate_rotation_matrix ( real(real64), dimension(:,:), intent(out)  R,
real(real64), dimension(:), intent(in)  ff,
real(real64), dimension(:), intent(in)  tt 
)

Generates a rotation matrix R to rotate a vector f to t.

T. M\U000000f6ller and J. F. Hughes, Journal of Graphics Tools 4, 1 (1999)

Definition at line 986 of file math.F90.

◆ numder_ridders()

subroutine, public math_oct_m::numder_ridders ( real(real64), intent(in)  x,
real(real64), intent(in)  h,
real(real64), intent(out)  res,
real(real64), intent(out)  err,
  f 
)

Numerical derivative (Ridder`s algorithm).

This is an alternative to "loct_numerical_derivative" (which is just an interface to the GSL numerical derivative). This version is an implementation of Ridders algorithm [C. J. F. Ridders, Adv. Eng. Software 4, 75 (1982); also described in Numerical Recipes]. It is more precise, but also typically more expensive, than the simpler 4-point algorithm implemented in the GSL library.

Definition at line 1130 of file math.F90.

◆ dzcross_product()

pure complex(real64) function, dimension(1:3), public math_oct_m::dzcross_product ( real(real64), dimension(:), intent(in)  a,
complex(real64), dimension(:), intent(in)  b 
)
Parameters
[in]a(3)
[in]b(3)

Definition at line 1186 of file math.F90.

◆ zdcross_product()

pure complex(real64) function, dimension(1:3), public math_oct_m::zdcross_product ( complex(real64), dimension(:), intent(in)  a,
real(real64), dimension(:), intent(in)  b 
)
Parameters
[in]a(3)
[in]b(3)

Definition at line 1199 of file math.F90.

◆ generalized_laguerre_polynomial()

subroutine, public math_oct_m::generalized_laguerre_polynomial ( integer, intent(in)  np,
integer, intent(in)  nn,
integer, intent(in)  mm,
real(real64), dimension(np), intent(in)  xx,
real(real64), dimension(np), intent(out)  cx 
)

Definition at line 1312 of file math.F90.

◆ dupper_triangular_to_hermitian()

subroutine math_oct_m::dupper_triangular_to_hermitian ( integer, intent(in)  nn,
real(real64), dimension(:, :), intent(inout)  aa 
)
private

Definition at line 1350 of file math.F90.

◆ zupper_triangular_to_hermitian()

subroutine math_oct_m::zupper_triangular_to_hermitian ( integer, intent(in)  nn,
complex(real64), dimension(:, :), intent(inout)  aa 
)
private

Definition at line 1363 of file math.F90.

◆ dlower_triangular_to_hermitian()

subroutine math_oct_m::dlower_triangular_to_hermitian ( integer, intent(in)  nn,
real(real64), dimension(:, :), intent(inout)  aa 
)
private

Definition at line 1377 of file math.F90.

◆ zlower_triangular_to_hermitian()

subroutine math_oct_m::zlower_triangular_to_hermitian ( integer, intent(in)  nn,
complex(real64), dimension(:, :), intent(inout)  aa 
)
private

Definition at line 1390 of file math.F90.

◆ dsymmetrize_matrix()

subroutine math_oct_m::dsymmetrize_matrix ( integer, intent(in)  nn,
real(real64), dimension(:, :), intent(inout)  aa 
)
private

symmetrize a real matrix

Definition at line 1405 of file math.F90.

◆ zsymmetrize_matrix()

subroutine math_oct_m::zsymmetrize_matrix ( integer, intent(in)  n,
complex(real64), dimension(:, :), intent(inout)  a 
)
private

make a complex matrix Hermitian

Parameters
[in]nSize of matrix

Definition at line 1420 of file math.F90.

◆ dzero_small_elements_matrix()

subroutine, public math_oct_m::dzero_small_elements_matrix ( real(real64), dimension(:, :), intent(inout)  aa,
real(real64)  tol 
)

Definition at line 1435 of file math.F90.

◆ is_symmetric()

logical function, public math_oct_m::is_symmetric ( real(real64), dimension(:, :), intent(in)  a,
real(real64), intent(in), optional  tol 
)

Check if a 2D array is symmetric.

Definition at line 1445 of file math.F90.

◆ is_diagonal()

logical pure function, public math_oct_m::is_diagonal ( integer, intent(in)  dim,
real(real64), dimension(:, :), intent(in)  matrix,
real(real64), intent(in)  tol 
)

Returns true is the matrix of size dim x dim is diagonal, given a relative tolerance.

Definition at line 1464 of file math.F90.

◆ convert_to_base()

subroutine, public math_oct_m::convert_to_base ( integer, intent(in)  num,
integer, intent(in)  base,
integer, dimension(:), intent(out)  converted 
)

convert an integer in base 10 to a different base

Definition at line 1488 of file math.F90.

◆ convert_from_base()

subroutine, public math_oct_m::convert_from_base ( integer, dimension(:), intent(in)  converted,
integer, intent(in)  base,
integer, intent(out)  num 
)

convert an integer to base 10 from a different base

Definition at line 1514 of file math.F90.

◆ zdiagonal_matrix()

pure complex(real64) function, dimension(dim, dim) math_oct_m::zdiagonal_matrix ( integer, intent(in)  dim,
complex(real64), intent(in)  diag 
)
private

Currently only returns a matrix whose diagonal elements are all the same. Note that the integer version is in math.F90.

Definition at line 1600 of file math.F90.

◆ zinterpolate_2()

subroutine math_oct_m::zinterpolate_2 ( real(real64), dimension(:), intent(in)  xa,
complex(real64), dimension(:, :, :), intent(in), contiguous  ya,
real(real64), intent(in)  x,
complex(real64), dimension(:, :), intent(out), contiguous  y 
)
private

Definition at line 1615 of file math.F90.

◆ zinterpolate_1()

subroutine math_oct_m::zinterpolate_1 ( real(real64), dimension(:), intent(in)  xa,
complex(real64), dimension(:, :), intent(in), contiguous  ya,
real(real64), intent(in)  x,
complex(real64), dimension(:), intent(out), contiguous  y 
)
private

Definition at line 1650 of file math.F90.

◆ zinterpolate_0()

subroutine math_oct_m::zinterpolate_0 ( real(real64), dimension(:), intent(in)  xa,
complex(real64), dimension(:), intent(in)  ya,
real(real64), intent(in)  x,
complex(real64), intent(out)  y 
)
private

Definition at line 1678 of file math.F90.

◆ zcross_product()

pure complex(real64) function, dimension(1:3), public math_oct_m::zcross_product ( complex(real64), dimension(:), intent(in)  a,
complex(real64), dimension(:), intent(in)  b 
)
Parameters
[in]a(3)
[in]b(3)

Definition at line 1703 of file math.F90.

◆ ddiagonal_matrix()

pure real(real64) function, dimension(dim, dim) math_oct_m::ddiagonal_matrix ( integer, intent(in)  dim,
real(real64), intent(in)  diag 
)
private

Currently only returns a matrix whose diagonal elements are all the same. Note that the integer version is in math.F90.

Definition at line 1791 of file math.F90.

◆ dinterpolate_2()

subroutine math_oct_m::dinterpolate_2 ( real(real64), dimension(:), intent(in)  xa,
real(real64), dimension(:, :, :), intent(in), contiguous  ya,
real(real64), intent(in)  x,
real(real64), dimension(:, :), intent(out), contiguous  y 
)
private

Definition at line 1806 of file math.F90.

◆ dinterpolate_1()

subroutine math_oct_m::dinterpolate_1 ( real(real64), dimension(:), intent(in)  xa,
real(real64), dimension(:, :), intent(in), contiguous  ya,
real(real64), intent(in)  x,
real(real64), dimension(:), intent(out), contiguous  y 
)
private

Definition at line 1841 of file math.F90.

◆ dinterpolate_0()

subroutine math_oct_m::dinterpolate_0 ( real(real64), dimension(:), intent(in)  xa,
real(real64), dimension(:), intent(in)  ya,
real(real64), intent(in)  x,
real(real64), intent(out)  y 
)
private

Definition at line 1869 of file math.F90.

◆ dcross_product()

pure real(real64) function, dimension(1:3), public math_oct_m::dcross_product ( real(real64), dimension(:), intent(in)  a,
real(real64), dimension(:), intent(in)  b 
)
Parameters
[in]a(3)
[in]b(3)

Definition at line 1894 of file math.F90.