The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Photonic::Utils

VERSION

version 0.004

SYNOPSIS

use Photonic::Utils qw(cgtsl cmatmult);
my ($r, $info)=cgtsl($c,$d,$e, $b);
$c=cmatmult($a, $b);

DESCRIPTION

Utility functions that may be useful.

Exportable Functions

  • $r=linearCombine($c, $s)

    Complex linear combination of states. $c is an arrayref of 'complex' pdl scalars and $s is an arrayref of 'complex' states ('complex' multidimensional pdl).

  • $p=HProd($a, $b)

    Hermitean product <a|b> of two 2xNx... 'complex' pdls.

  • $psiG = RtoG($psiR, $ndims, $skip)

    Transforms a $ndims-dimensional 'complex' scalar, vector or tensor field $psiR that is a function of position within the unit cell to a complex field $psiG that is a function of the reciprocal vectors. The first dimension must be 2, as the values are complex. The next $skip dimensions are skiped (0 for a scalar, 1 for a vector, 2 for a 2-tensor field). The Fourier transform is performed over the following $ndims dimensions.

  • $psiR = GtoR($psiG, $ndims, $skip)

    The opposite transformation to RtoG. Transform a 'complex' scalara, vector or tensorial field from reciprocal to real space.

  • $b=tile($a, $nx, $ny,...)

    returns $a repeated periodically $nx times along the x direction, $ny along the y direction, etc. Useful for making plots.

  • $l=vectors2Dlist($f, $s, $d)

    Returns a 2D vector field ready for gnuplotting from a vector field $f scaling the result by $s and decimating the field by $d. The vectors are centered on the decimated lattice points.

  • $c=cmatmult($a, $b)

    Returns the matrix product of the complex matrices $a times $b, with signatures a(2,j,i), b(2,k,j), c(2,k,i). The first index is 2, corresponding to the real and imaginary parts, j denotes columns of a, rows of b, i denotes rows of a and of the result c, k denotes columns of b and the result c. Recall that in pdl the first (row) index is faster. May thread over extra dimensions.

  • ($r,$i)=dgtsl($c, $d, $e, $b)

    Solves the tridiagonal matrix equation $m x $r=$b. $m is a tridiagonal double matrix with subdiagonal $c, diagonal $d and supradiagonal $e, $b is an ordinary vector (not necessarily column vector) with the right hand side. $r is the result vector and $i is and integer indicator of where the calculation failed, zero on success. The signature would be double c(n), d(n), e(n), b(n), r(n) and long i(n). May thread over extra dimensions.

  • ($r,$i)=cgtsl($c, $d, $e, $b)

    Solves the tridiagonal matrix equation $m x $r=$b. $m is a tridiagonal complex matrix with subdiagonal $c, diagonal $d and supradiagonal $e, $b is an ordinary vector (not necessarily column vector) with the right hand side. $r is the result vector and $i is and integer indicator of where the calculation failed, zero on success. The signature would be double c(2,n), d(2,n), e(2,n), b(2,n), r(2,n) and long i(n). May thread over extra dimensions.

NOTE

Uses Inline::Pdlpp, so the first time it is run it compiles itself, and would take a little longer than the following. To recompile, remove the directory _Inline/ before running.

You must make sure that the relative location of the libutils.so library is correct. See $Bin below.

The sources for the Fortran routines cgtsl and dgtsl are in Photonic/sources. They must be compiled as

gfortran -fPIC -c dgtsl.f
gfortran -fPIC -c cgtsl.f

and linked to the library as

gcc -shared -o libutils.so dgtsl.o cgtsl.o

The library is at Photonic/lib.