COPYRIGHT NOTICE
Photonic - A perl package for calculations on photonics and metamaterials.
Copyright (C) 2016 by W. Luis Mochán
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
mochan@fis.unam.mx
Instituto de Ciencias Físicas, UNAM
Apartado Postal 48-3
62251 Cuernavaca, Morelos
México
NAME
Photonic::Utils
VERSION
version 0.023
SYNOPSIS
use Photonic::Utils qw(cmatmult);
$c=cmatmult($a, $b);
DESCRIPTION
Utility functions that may be useful.
Exportable Functions
$slice=top_slice($pdl, $slice_arg)
Applies the given
$slice_arg
to the highest dimension of the given ndarray.$pdl=dummyN($pdl, $how_many, $where, $dim_size)
dummyN(sequence(2, 3), 3, 0, 4) # dims: 4, 4, 4, 2, 3 dummyN(sequence(2, 3), 3, 1, 4) # dims: 2, 4, 4, 4, 3 dummyN(sequence(2, 3), 3, -1, 4) # dims: 2, 3, 4, 4, 4 dummyN(sequence(2, 3), 3, -2, 4) # dims: 2, 4, 4, 4, 3
Adds
$how_many
(no-op if <= 0) dummy dimensions of size$dim_size
(default 1) in the$which_dim
(default 0) position.$r=linearCombineIt($c, $it, $thread_dims)
Complex linear combination of states. $c is a 'complex' ndarray and $it is an ndarray of states from a Photonic::Roles::Haydock. $thread_dims is the quantity of dimensions over which this is threaded.
$reordered=mvN($pdl, $start, $end, $to)
mvN(sequence(1,2,3,4,5,6), 1, 2, -1) # dims 1,4,5,6,2,3
Reorder given ndarray's dimensions, moving dimensions starting
$start
and ending$end
(no-op if less than$start
before negative-adjustment).They are moved to after the current
$to
if$start
is less than$to
(i.e. moving dims to right), and before if greater. This is like "mv" in PDL::Slices, and intuitive if superficially odd. If$to
is between$start
and$end
inclusive, it is a no-op.Negative-adjustment: like "mv" in PDL::Slices, all parameters may be negative, which is treated relative to the end of the dimension-list.
$pdl=corner_rotate($pdl, $start, $end)
Rotates each dimension from
$start
to$end
by 1, to opposite corner.$pdl=triangle_coords($n, $include_diag)
Returns ndarray of coordinates of the lower triangle of a square $n*$n matrix, either with or without the diagonal. Ordered by column, then row.
$p=HProd($a, $b, $dims, $skip)
Hermitean product <a|b> of two 'complex' multidimensional pdls $a and $b. Only sums over $dims dimensions, allowing threading. If $skip is present, preserve the first $skip dimensions before adding up.
$p=MHProd($a, $b, $m, $skip)
Hermitean product <a|m|b> of two 'complex' multidimensional pdls $a and $b representing vector fields using metric $m. If $skip is present, preserve the first $skip dimensions before adding up. (Might not be functional yet, or might be wrong)
$p=EProd($a, $b, $skip)
Euclidean product <a|b> of two 'complex' multidimensional pdls $a and $b in reciprocal space. If $skip is present, preserve the first $skip dimensions before adding up.
$p=SProd($a, $b, $skip)
Spinor product <a|b> of two 'complex' multidimensional pdls $a and $b in reciprocal space. If $skip is present, preserve the first 1+$skip dimensions (the first dimension is the spinor dimension) before adding up.
$p=VSProd($a, $b)
Vector-Spinor product <a|b> of two 'complex' multidimensional pdls $a and $b in reciprocal space. For the vector-spinor field dimensions are like xy:pm:nx:ny.
$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 $skip dimensions are skipped (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' scalar, vector or tensorial field from reciprocal to real space.
$c=lentzCF($as, $bs, $max, $small)
Compute a continued fraction a0+b1/a1+b2+... using the Lentz algorithm. $as and $bs are given in a PDL. $max is maximum number of iterations. $small is a small convergence criterium.
$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.
any_complex
True if any of the args are a complex PDL.
cartesian_product
Given two ndarrays a(Z,x1,m), b(Z,x2,n), return c(Z,x1+x2,m*n), with each row from
b
appended to all rows froma
.Z
can be empty but must be compatible; the shorter one will be "dummied up" from the zero end as necessary.tensor
Given a complex PDL, an LU decomposition array-ref as returned by "lu_decomp", and the size of the tensor, returns the tensor.
wave_operator
Given a Green tensor and number of dimension in the geometry, returns a wave operator.
make_haydock
make_greenp
Given an object and a classname, construct an array-ref of objects of that class, with relevant fields copied from the object.
incarnate_as
my $new_obj = incarnate_as('New::Class', $obj, [qw(f1 f2)], other => $value);
Given an object and a classname, an array-ref of attribute-names, and then key/value pairs, returns a new object of the given class, with the given object's given attributes plus the additional ones.
cgtsv
Solves a general complex tridiagonal system of equations.
$b = cgtsv($c, $d, $e, $b);
where
$c(0..$n-2)
is the subdiagonal,$d(0..$n-1)
the diagonal and$e(0..$n-2)
the supradiagonal of an $nX$n tridiagonal complex double precision matrix.$b(0..$n-1)
is the right hand side vector.$b
is replaced by the solution. Dies if gets an error.lu_decomp
Uses the appropriate LU decomposition function (real vs complex, detected) for "lu_solve". Returns list of LU, permutations. Dies if decomposition failed.
lu_solve
Uses the appropriate LU solver function (real vs complex, detected). Given an array-ref with the return values of "lu_decomp", and a transposed
B
matrix, returns transposedx
. Dies if solving failed.apply_longitudinal_projection
Given a
psi_G
state, aGNorm
, the number of dimensions, and a real-space coefficient, transforms thepsi_G
field from reciprocal to real space, multiplies by the coefficient, transforms back to reciprocal space.make_dyads
Given a number of dimensions, and an array-ref of "unit pair" ndarrays, returns a matrix of dyads of unit vector pairs d^{ij}_{kl}=u^{i}_{kl}u^{j}_{kl} as 2d matrix, adjusted for symmetry.