C++QEDCore  2.100.2 (v2 Milestone 10 Development branch)
a framework for simulating open quantum dynamics – core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DistributionFunctions.h
Go to the documentation of this file.
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
2 // -*- C++ -*-
4 #ifndef CPPQEDCORE_QUANTUMDATA_DISTRIBUTIONFUNCTIONS_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_DISTRIBUTIONFUNCTIONS_H_INCLUDED
6 
7 #include "BlitzArray.h"
8 #include "ComplexExtensions.h"
9 #include "MathExtensions.h"
10 
11 #include "ParsFwd.h"
12 
13 #include <boost/math/special_functions/factorials.hpp>
14 
15 
16 namespace quantumdata {
17 
18 
21 
22  double
23  &fLimitXUL, &fLimitYUL, &fLimitXL, &fLimitXU, &fLimitYL, &fLimitYU, &fStep;
24 
25  int &fCutoff;
26 
27  ParsFunctionScan(parameters::ParameterTable& p, const std::string& mod="");
28 
29 };
30 
31 
32 namespace details {
33 
34 double w(size_t n, double r, size_t k);
35 
36 }
37 
39 
58 template<typename DensityOperatorFunctor>
59 double wignerFunction(const DensityOperatorFunctor& rho, double x, double y, size_t truncatedDimension=0)
60 {
61  using namespace mathutils; using boost::math::factorial;
62 
63  struct Helper
64  {
65  static dcomp _(const DensityOperatorFunctor& rho, size_t dim, double r, size_t k)
66  {
67  dcomp res(0.);
68  for (size_t n=0; n<dim-k; ++n) res+=details::w(n,r,k)*rho(n+k)(n);
69  return res;
70  }
71  };
72 
73  const double r=sqrt(sqr(x)+sqr(y)), phi=(x || y) ? atan2(y,x) : 0.;
74 
75  const size_t dim=truncatedDimension && truncatedDimension<rho.getDimension(0) ? truncatedDimension : rho.getDimension(0);
76 
77  double res=real(Helper::_(rho,dim,r,0));
78 
79  for (size_t k=1; k<dim; ++k) res+=2*real(Helper::_(rho,dim,r,k)*exp(-DCOMP_I*(k*phi)));
80 
81  return res;
82 }
83 
84 template<typename DensityOperator>
85 double qFunction(const DensityOperator& rho, double x, double y, size_t)
86 {
87  using namespace mathutils;
88 
89  const dcomp alpha(x,y);
90 
91  dcomp qComplex;
92 
93  for (size_t m=0; m<rho.getDimension(); ++m) for (size_t n=0; n<rho.getDimension(); ++n)
94  qComplex+=coherentElement(n,alpha)*coherentElement(m,conj(alpha))*rho(m)(n);
95 
96  return exp(-sqrAbs(alpha))*real(qComplex);
97 }
98 
99 
101 {
102 public:
103  typedef DArray<1> Hermites;
104 
105  WignerFunctionKernelOld(double x, double y, size_t dim);
106 
107  dcomp operator()(size_t m, size_t n) const;
108 
109 private:
110  const Hermites hermite_m2x_, hermite_2y_;
111 
112 };
113 
114 
115 
116 template<typename DensityOperatorFunctor>
117 double wignerFunctionOld(const DensityOperatorFunctor& rho, double x, double y, size_t truncatedDimension=0)
118 // NEEDS_WORK should refer rho only via some traits class to make the code really generic.
119 {
120  using namespace mathutils; using boost::math::factorial;
121 
122  const size_t dim=truncatedDimension ? truncatedDimension : rho.getDimension(0);
123 
124  const WignerFunctionKernelOld wignerFunctionKernel(x,y,dim);
125 
126  double res=0;
127 
128  for (size_t m=0; m<dim; ++m) {
129  res+=real(minusOneToThePowerOf(m)/factorial<double>(m)*rho(m,m)*pow(2.*DCOMP_I,-2*m)*wignerFunctionKernel(m,m));
130 
131  for (size_t n=m+1; n<dim; ++n)
132  res+=2.*real(minusOneToThePowerOf(m)/sqrt(factorial<double>(n)*factorial<double>(m))*rho(n,m)*pow(2.*DCOMP_I,-m-n)*wignerFunctionKernel(n,m));
133 
134  }
135 
136  return 2./PI*exp(-2*(sqr(x)+sqr(y)))*res;
137 
138 }
139 
140 
142 template<typename DistributionFunctor,typename DensityOperator>
143 std::ostream& scanFunction(DistributionFunctor distributionFunctor, const DensityOperator& rho, std::ostream& os, const ParsFunctionScan& pfs)
144 {
145  if (pfs.fLimitXUL) pfs.fLimitXL=-(pfs.fLimitXU=pfs.fLimitXUL);
146  if (pfs.fLimitYUL) pfs.fLimitYL=-(pfs.fLimitYU=pfs.fLimitYUL);
147  for (double x=pfs.fLimitXL; x<pfs.fLimitXU; x+=pfs.fStep) {
148  for (double y=pfs.fLimitYL; y<pfs.fLimitYU; y+=pfs.fStep) os<<x<<"\t"<<y<<"\t"<<distributionFunctor(rho,x,y,pfs.fCutoff)<<std::endl;
149  os<<std::endl;
150  }
151  return os;
152 }
153 
154 
155 
156 }
157 
158 #endif // CPPQEDCORE_QUANTUMDATA_DISTRIBUTIONFUNCTIONS_H_INCLUDED
Comprises classes representing the state of composite quantum systems and providing various interface...
Definition: ArrayBase.h:16
Density operator of arbitrary arity.
const dcomp DCOMP_I(0, 1)
Imaginary unit.
Defines wrapper functions for mathematical functions taken from libraries, and several other mathemat...
blitz::Array< double, RANK > DArray
An array of doubles of arbitrary arity.
Definition: BlitzArray.h:13
dcomp coherentElement(unsigned long n, const dcomp &alpha)
Calculates relying on the Stirling formula if is too large for explicit calculation of factorial...
The parameter table according to which the command line will be parsed by update() ...
Definition: Pars.h:134
std::ostream & scanFunction(DistributionFunctor distributionFunctor, const DensityOperator &rho, std::ostream &os, const ParsFunctionScan &pfs)
Creates a map of the Wigner function over the region specified by pfs and streams it in a format suit...
double wignerFunction(const DensityOperatorFunctor &rho, double x, double y, size_t truncatedDimension=0)
Calculates the Wigner function corresponding to a harmonic-oscillator mode density matrix expressed i...
Additional helpers for dcomp.
Comprises wrapper functions for mathematical functions taken from libraries (Boost.Math, GSL), and several other mathematical functions.
quantumdata::DensityOperator< 1 > DensityOperator
unary DensityOperator
Definition: Free.h:40
Parameter set for scanFunction.
std::complex< double > dcomp
Double-precision complex number.
Defines template aliases for real and complex arrays.