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  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  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 make_idx_set (n, out, length, in)
 Construct out(1:length) = (/1, ..., n/) if in is not present, out(1:length) = in otherwise. More...
 
logical function, public member (n, a)
 Considers a(1:ubound(a, 1)) as an integer set and checks if n is a member of it. More...
 
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, public dsymmetrize_matrix (nn, aa)
 
subroutine, public dzero_small_elements_matrix (nn, aa, tol)
 
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 220 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 233 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 249 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 264 of file math.F90.

◆ factorial()

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

Definition at line 284 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 300 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 371 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 521 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 597 of file math.F90.

◆ make_idx_set()

subroutine, public math_oct_m::make_idx_set ( integer, intent(in)  n,
integer, dimension(:), intent(out), allocatable  out,
integer, intent(out)  length,
integer, dimension(:), intent(in), optional  in 
)

Construct out(1:length) = (/1, ..., n/) if in is not present, out(1:length) = in otherwise.

Definition at line 615 of file math.F90.

◆ member()

logical function, public math_oct_m::member ( integer, intent(in)  n,
integer, dimension(:), intent(in)  a 
)

Considers a(1:ubound(a, 1)) as an integer set and checks if n is a member of it.

Definition at line 644 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 665 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 688 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 698 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 708 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 755 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 801 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 841 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 856 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 864 of file math.F90.

◆ pad4()

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

Definition at line 872 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 885 of file math.F90.

◆ dlog2()

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

Definition at line 914 of file math.F90.

◆ ilog2()

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

Definition at line 922 of file math.F90.

◆ llog2()

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

Definition at line 930 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 938 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 950 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 969 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 983 of file math.F90.

◆ is_prime()

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

Definition at line 991 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 1026 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 1170 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 1225 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 1238 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 1351 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 1389 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 1402 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 1416 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 1429 of file math.F90.

◆ dsymmetrize_matrix()

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

Definition at line 1444 of file math.F90.

◆ dzero_small_elements_matrix()

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

Definition at line 1458 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 1538 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 1553 of file math.F90.

◆ zinterpolate_1()

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

Definition at line 1588 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 1616 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 1641 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 1729 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 1744 of file math.F90.

◆ dinterpolate_1()

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

Definition at line 1779 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 1807 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 1832 of file math.F90.