JDFTx  1.7.0
Operators.h File Reference

Operators on ScalarField's and ScalarFieldTilde's. More...

#include <core/ScalarField.h>
#include <core/BlasExtra.h>
#include <core/GridInfo.h>
#include <core/LoopMacros.h>
#include <core/RadialFunction.h>
#include <string.h>

Macros

#define Tptr   std::shared_ptr<T>
 shorthand for writing the template operators (undef'd at end of header)
 

Functions

ScalarField Real (const complexScalarField &)
 real part of a complex scalar field (real-space)
 
ScalarFieldTilde Real (const complexScalarFieldTilde &)
 real part of a complex scalar field (reciprocal space)
 
ScalarField Imag (const complexScalarField &)
 imaginary part of a complex scalar field (real-space)
 
ScalarFieldTilde Imag (const complexScalarFieldTilde &)
 imaginary part of a complex scalar field (reciprocal space)
 
complexScalarField Complex (const ScalarField &)
 convert real to complex scalar field with zero imaginary part (real-space)
 
complexScalarField Complex (const ScalarField &re, const ScalarField &im)
 construct complex scalar field fromr eal and imaginary parts (real-space)
 
complexScalarFieldTilde Complex (const ScalarFieldTilde &)
 convert real to complex scalar field with zero imaginary part (reciprocal-space)
 
ScalarFieldTilde O (const ScalarFieldTilde &)
 Inner product operator (diagonal in PW basis)
 
ScalarFieldTilde O (ScalarFieldTilde &&)
 Inner product operator (diagonal in PW basis)
 
complexScalarFieldTilde O (const complexScalarFieldTilde &)
 Inner product operator (diagonal in PW basis)
 
complexScalarFieldTilde O (complexScalarFieldTilde &&)
 Inner product operator (diagonal in PW basis)
 
ScalarField I (const ScalarFieldTilde &, int nThreads=0)
 Forward transform: PW basis -> real space (preserve input)
 
ScalarField I (ScalarFieldTilde &&, int nThreads=0)
 Forward transform: PW basis -> real space (destructible input)
 
complexScalarField I (const complexScalarFieldTilde &, int nThreads=0)
 Forward transform: PW basis -> real space (preserve input)
 
complexScalarField I (complexScalarFieldTilde &&, int nThreads=0)
 Forward transform: PW basis -> real space (destructible input)
 
ScalarFieldTilde J (const ScalarField &, int nThreads=0)
 Inverse transform: Real space -> PW basis.
 
complexScalarFieldTilde J (const complexScalarField &, int nThreads=0)
 Inverse transform: Real space -> PW basis (preserve input)
 
complexScalarFieldTilde J (complexScalarField &&, int nThreads=0)
 Inverse transform: Real space -> PW basis (destructible input)
 
ScalarFieldTilde Idag (const ScalarField &, int nThreads=0)
 Forward transform transpose: Real space -> PW basis.
 
complexScalarFieldTilde Idag (const complexScalarField &, int nThreads=0)
 Forward transform transpose: Real space -> PW basis (preserve input)
 
complexScalarFieldTilde Idag (complexScalarField &&, int nThreads=0)
 Forward transform transpose: Real space -> PW basis (destructible input)
 
ScalarField Jdag (const ScalarFieldTilde &, int nThreads=0)
 Inverse transform transpose: PW basis -> real space (preserve input)
 
ScalarField Jdag (ScalarFieldTilde &&, int nThreads=0)
 Inverse transform transpose: PW basis -> real space (destructible input)
 
complexScalarField Jdag (const complexScalarFieldTilde &, int nThreads=0)
 Inverse transform transpose: PW basis -> real space (preserve input)
 
complexScalarField Jdag (complexScalarFieldTilde &&, int nThreads=0)
 Inverse transform transpose: PW basis -> real space (destructible input)
 
ScalarField JdagOJ (const ScalarField &)
 Evaluate Jdag(O(J())), which avoids 2 fourier transforms in PW basis (preserve input)
 
ScalarField JdagOJ (ScalarField &&)
 Evaluate Jdag(O(J())), which avoids 2 fourier transforms in PW basis (destructible input)
 
complexScalarField JdagOJ (const complexScalarField &)
 Evaluate Jdag(O(J())), which avoids 2 fourier transforms in PW basis (preserve input)
 
complexScalarField JdagOJ (complexScalarField &&)
 Evaluate Jdag(O(J())), which avoids 2 fourier transforms in PW basis (destructible input)
 
ScalarFieldTilde L (const ScalarFieldTilde &)
 Laplacian.
 
ScalarFieldTilde L (ScalarFieldTilde &&)
 Laplacian.
 
complexScalarFieldTilde L (const complexScalarFieldTilde &)
 Laplacian.
 
complexScalarFieldTilde L (complexScalarFieldTilde &&)
 Laplacian.
 
matrix3 Lstress (const ScalarFieldTilde &X, const ScalarFieldTilde &Y)
 Lattice vector derivative of dot(X,L(Y))
 
ScalarFieldTilde Linv (const ScalarFieldTilde &)
 Inverse Laplacian.
 
ScalarFieldTilde Linv (ScalarFieldTilde &&)
 Inverse Laplacian.
 
complexScalarFieldTilde Linv (const complexScalarFieldTilde &, vector3<> *k=0)
 Inverse Laplacian.
 
complexScalarFieldTilde Linv (complexScalarFieldTilde &&, vector3<> *k=0)
 Inverse Laplacian.
 
complexScalarFieldTilde Linv (const ScalarFieldTilde &in, vector3<> *k)
 
matrix3 LinvStress (const ScalarFieldTilde &X, const ScalarFieldTilde &Y)
 Lattice vector derivative of dot(X,Linv(Y))
 
ScalarFieldTilde D (const ScalarFieldTilde &, int iDir)
 compute the gradient in the iDir'th cartesian direction
 
ScalarFieldTilde D (const ScalarFieldTilde &in, const vector3<> &dir)
 directional derivative of scalar field along (cartesian direction) dir
 
ScalarFieldTilde DD (const ScalarFieldTilde &, int iDir, int jDir)
 second derivative along iDir'th and jDir'th cartesian directions
 
void zeroNyquist (RealKernel &Gdata)
 zeros out all the nyquist components of a real G-kernel
 
void zeroNyquist (ScalarFieldTilde &Gptr)
 zeros out all the nyquist components of a G-space data array
 
void zeroNyquist (ScalarField &Rptr)
 zeros out all the nyquist components of an R-space data array
 
void removePhase (size_t N, complex *data, double &meanPhase, double &sigmaPhase, double &rmsImagErr)
 
void translate (ScalarFieldTilde &, const vector3<> &r)
 Translate by vector r in Cartesian coordinates.
 
void translate (complexScalarFieldTilde &, const vector3<> &r)
 Translate by vector r in Cartesian coordinates.
 
void multiplyBlochPhase (complexScalarField &, const vector3<> &k)
 Multiply by Block phase for wave-vector k (in reciprocal lattice coordinates)
 
ScalarField radialFunction (const GridInfo &gInfo, const RadialFunctionG &f, vector3<> r0)
 Create spherically-symmetric scalar field from radial form f, centered at lattice coordinates r0.
 
void radialFunctionG (const RadialFunctionG &f, RealKernel &Kernel)
 Create a spherically-symmetric RealKernel from its radial form f.
 
ScalarFieldTilde radialFunctionG (const GridInfo &gInfo, const RadialFunctionG &f, vector3<> r0)
 Create spherically-symmetric scalar field from radial form f, centered at lattice coordinates r0.
 
ScalarFieldTilde operator* (const RadialFunctionG &, const ScalarFieldTilde &)
 Convolve a scalar field by a radial function (preserve input)
 
ScalarFieldTilde operator* (const RadialFunctionG &, ScalarFieldTilde &&)
 Convolve a scalar field by a radial function (destructible input)
 
matrix3 convolveStress (const RadialFunctionG &w, const ScalarFieldTilde &X, const ScalarFieldTilde &Y)
 stress due to dot(X,O(w*Y))
 
ScalarField exp (const ScalarField &)
 Elementwise exponential (preserve input)
 
ScalarField exp (ScalarField &&)
 Elementwise exponential (destructible input)
 
ScalarField log (const ScalarField &)
 Elementwise logarithm (preserve input)
 
ScalarField log (ScalarField &&)
 Elementwise logarithm (destructible input)
 
ScalarField sqrt (const ScalarField &)
 Elementwise square root (preserve input)
 
ScalarField sqrt (ScalarField &&)
 Elementwise square root (destructible input)
 
ScalarField inv (const ScalarField &)
 Elementwise reciprocal (preserve input)
 
ScalarField inv (ScalarField &&)
 Elementwise reciprocal (destructible input)
 
ScalarField pow (const ScalarField &, double alpha)
 Elementwise power (preserve input)
 
ScalarField pow (ScalarField &&, double alpha)
 Elementwise power (destructible input)
 
template<class T >
Tptr clone (const Tptr &X)
 Clone (NOTE: operator= is by reference for the ScalarField classes)
 
template<class T >
Tptroperator*= (Tptr &in, double scaleFac)
 Scale.
 
template<class T >
Tptr operator* (const Tptr &in, double scaleFac)
 Scalar multiply (preserve input)
 
template<class T >
Tptr operator* (double scaleFac, const Tptr &in)
 Scalar multiply (preserve input)
 
template<class T >
Tptr operator* (Tptr &&in, double scaleFac)
 Scalar multiply (destructible input)
 
template<class T >
Tptr operator* (double scaleFac, Tptr &&in)
 Scalar multiply (destructible input)
 
template<class T >
Tptr conj (Tptr &&in)
 Generic elementwise conjugate for complex data:
 
template<class T >
Tptr conj (const Tptr &in)
 
template<class T >
Tptroperator*= (Tptr &in, const Tptr &other)
 Generic elementwise multiply for complex data:
 
ScalarFieldoperator*= (ScalarField &in, const ScalarField &other)
 Elementwise multiply for real data.
 
template<class T >
Tptr operator* (const Tptr &in1, const Tptr &in2)
 Elementwise multiply (preserve inputs)
 
template<class T >
Tptr operator* (const Tptr &in1, Tptr &&in2)
 Elementwise multiply (destructible input)
 
template<class T >
Tptr operator* (Tptr &&in1, const Tptr &in2)
 Elementwise multiply (destructible input)
 
template<class T >
Tptr operator* (Tptr &&in1, Tptr &&in2)
 Elementwise multiply (destructible inputs)
 
complexScalarFieldoperator*= (complexScalarField &, const ScalarField &)
 elementwise multiply
 
complexScalarField operator* (const complexScalarField &, const ScalarField &)
 elementwise multiply (preserve inputs)
 
complexScalarField operator* (const ScalarField &, const complexScalarField &)
 elementwise multiply (preserve inputs)
 
complexScalarField operator* (complexScalarField &&, const ScalarField &)
 elementwise multiply (destructible inputs)
 
complexScalarField operator* (const ScalarField &, complexScalarField &&)
 elementwise multiply (destructible inputs)
 
ScalarFieldTildeoperator*= (ScalarFieldTilde &, const RealKernel &)
 Elementwise multiply.
 
ScalarFieldTilde operator* (const RealKernel &, const ScalarFieldTilde &)
 Elementwise multiply (preserve inputs)
 
ScalarFieldTilde operator* (const ScalarFieldTilde &, const RealKernel &)
 Elementwise multiply (preserve inputs)
 
ScalarFieldTilde operator* (const RealKernel &, ScalarFieldTilde &&)
 Elementwise multiply (destructible input)
 
ScalarFieldTilde operator* (ScalarFieldTilde &&, const RealKernel &)
 Elementwise multiply (destructible input)
 
template<typename T >
void axpy (double alpha, const Tptr &X, Tptr &Y)
 Generic axpy for complex data types (Note: null pointers are treated as zero)
 
void axpy (double alpha, const ScalarField &X, ScalarField &Y)
 Real data Linear combine: Y += alpha * X (Note: null pointers are treated as zero)
 
template<class T >
Tptroperator+= (Tptr &in, const Tptr &other)
 Increment.
 
template<class T >
Tptroperator-= (Tptr &in, const Tptr &other)
 Decrement.
 
template<class T >
Tptr operator+ (const Tptr &in1, const Tptr &in2)
 Add (preserve inputs)
 
template<class T >
Tptr operator+ (const Tptr &in1, Tptr &&in2)
 Add (destructible input)
 
template<class T >
Tptr operator+ (Tptr &&in1, const Tptr &in2)
 Add (destructible input)
 
template<class T >
Tptr operator+ (Tptr &&in1, Tptr &&in2)
 Add (destructible inputs)
 
template<class T >
Tptr operator- (const Tptr &in1, const Tptr &in2)
 Subtract (preserve inputs)
 
template<class T >
Tptr operator- (const Tptr &in1, Tptr &&in2)
 Subtract (destructible input)
 
template<class T >
Tptr operator- (Tptr &&in1, const Tptr &in2)
 Subtract (destructible input)
 
template<class T >
Tptr operator- (Tptr &&in1, Tptr &&in2)
 Subtract (destructible inputs)
 
template<class T >
Tptr operator- (const Tptr &in)
 Negate.
 
template<class T >
Tptr operator- (Tptr &&in)
 Negate.
 
ScalarFieldoperator+= (ScalarField &, double)
 Increment by scalar.
 
ScalarField operator+ (double, const ScalarField &)
 Add scalar (preserve inputs)
 
ScalarField operator+ (const ScalarField &, double)
 Add scalar (preserve inputs)
 
ScalarField operator+ (double, ScalarField &&)
 Add scalar (destructible input)
 
ScalarField operator+ (ScalarField &&, double)
 Add scalar (destructible input)
 
ScalarFieldoperator-= (ScalarField &, double)
 Decrement by scalar.
 
ScalarField operator- (double, const ScalarField &)
 Subtract from scalar (preserve inputs)
 
ScalarField operator- (const ScalarField &, double)
 Subtract scalar (preserve inputs)
 
ScalarField operator- (double, ScalarField &&)
 Subtract from scalar (destructible input)
 
ScalarField operator- (ScalarField &&, double)
 Subtract scalar (destructible input)
 
template<typename T >
complex dot (const Tptr &X, const Tptr &Y)
 
template<typename T >
double nrm2 (const Tptr &X)
 
template<typename T >
complex sum (const Tptr &X)
 
double dot (const ScalarField &, const ScalarField &)
 Inner product.
 
double dot (const ScalarFieldTilde &, const ScalarFieldTilde &)
 Inner product.
 
double nrm2 (const ScalarField &)
 2-norm
 
double nrm2 (const ScalarFieldTilde &)
 2-norm
 
double sum (const ScalarField &)
 Sum of elements.
 
double sum (const ScalarFieldTilde &)
 Equivalent to dot() with a ScalarFieldTilde of all 1s (NOTE: sum(X) != sum(I(X)))
 
double integral (const ScalarField &)
 Integral in the unit cell (dV times sum())
 
double integral (const ScalarFieldTilde &)
 Integral in the unit cell (just fetches the G=0 component with correct prefactor)
 
complex integral (const complexScalarField &)
 Integral in the unit cell (dV times sum())
 
complex integral (const complexScalarFieldTilde &)
 Integral in the unit cell (just fetches the G=0 component with correct prefactor)
 
ScalarFieldTilde changeGrid (const ScalarFieldTilde &, const GridInfo &gInfoNew)
 
ScalarField changeGrid (const ScalarField &, const GridInfo &gInfoNew)
 
complexScalarFieldTilde changeGrid (const complexScalarFieldTilde &, const GridInfo &gInfoNew)
 
complexScalarField changeGrid (const complexScalarField &, const GridInfo &gInfoNew)
 
template<typename T >
void initZero (Tptr &X)
 
template<typename T >
void initZero (Tptr &X, const GridInfo &gInfo)
 
template<typename T >
void nullToZero (Tptr &X, const GridInfo &gInfo)
 If X is null, allocate and initialize to 0.
 
void initRandom (ScalarField &, double cap=0.0)
 initialize element-wise with a unit-normal random number (with a cap if cap>0)
 
void initRandomFlat (ScalarField &)
 initialize element-wise with a unit-flat [0:1) random number
 
void randomize (ScalarFieldTilde &)
 alternate interface needed for Mnimize
 
void initGaussianKernel (RealKernel &, double x0)
 initialize to gaussian kernel exp(-(G x0/2)^2)
 
void initTranslation (ScalarFieldTilde &, const vector3<> &r)
 initialize to translation operator exp(-i G.r)
 
ScalarFieldTilde gaussConvolve (const ScalarFieldTilde &, double sigma)
 convolve with a gaussian
 
ScalarFieldTilde gaussConvolve (ScalarFieldTilde &&, double sigma)
 convolve with a gaussian (destructible input)
 
template<typename Func , typename... Args>
void applyFuncGsq (const GridInfo &gInfo, const Func &f, Args... args)
 Evaluate a function f(i, Gsq, args...) at each point in reciprocal space indexed by i.
 
template<typename Func , typename... Args>
void applyFunc_r (const GridInfo &gInfo, const Func &f, Args... args)
 Evaluate a function f(i, r, args...) at each point in real space index by i.
 
void printStats (const ScalarField &X, const char *name, FILE *fp=stdout)
 Print mean and standard deviation of array with specified name (debug utility)
 
template<typename Callable , typename Vec >
void checkSymmetry (Callable *func, const Vec &v1, const Vec &v2, const char *funcName)
 

Detailed Description

Operators on ScalarField's and ScalarFieldTilde's.