#include #include #include #include #ifdef USE_IMAGINARY #include "include/Imaginary.hpp" #endif #include "boost/array.hpp" #include "boost/timer.hpp" /** * \file ImaginaryExample.cpp * \brief Example code to present the strength of the Imaginary class * * The timed section of code is ~2.3 times faster with g++ 4.6.1 on * an Intel core i7-2820QM when compiled in -O2 or -O3 mode and with -DUSE_IMAGINARY * than without without this last compiling option * \version 0.99 * \author Matthieu Schaller * \date 13.11.2011 */ //Potential barrier height const double V0 = 1.; //Dirack's constant const double hbar = 1.; //Particle mass const double m = 0.5; //Domain const double xl = -500.; const double xr = 1000.; //Number of points on the interval const size_t nbPoints = 2000; //Time step size const double deltaT = 0.005; //Imaginary unit #ifdef USE_IMAGINARY const Imaginary ii(1.); #else const std::complex ii(0.,1.); using std::exp; #endif //Potential double V(double x) { return fabs(x-600.) < 100. ? 1. : 0.; } int main() { //Usefull constants const double deltaX = (xr-xl)/static_cast(nbPoints); const double x0 = xl + (xr-xl)*0.35; const double sigma0 = (xr-xl)*0.0375; const int n = 32; const double zk = 2.*M_PI*n/(xr-xl); //Spatial Domain boost::array x; for(size_t i(0); i(i)-2.)*deltaX; //Wavefunction at t-\Delta t, t and t+\Delta t boost::array, nbPoints+4> Psi_old, Psi_cur, Psi_new; //Build an initial wavepacket for(size_t i(0); i(1.) as sqrt(-1)" << std::endl; #else std::cout << "Using std::complex(0.,1.) as sqrt(-1)" << std::endl; #endif std::cout << "Time spent evolving the wavefunctions: " << computingTime << std::endl; return 0; }