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
DensityOperator.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_DENSITYOPERATOR_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_DENSITYOPERATOR_H_INCLUDED
6 
7 #include "DensityOperatorFwd.h"
8 
9 #include "StateVectorFwd.h"
10 
11 #include "ArrayBase.h"
12 #include "DimensionsBookkeeper.h"
13 #include "LazyDensityOperator.h"
14 #include "Types.h"
15 
16 #include "Operators.h"
17 
18 
19 namespace quantumdata {
20 
21 
22 template<int RANK>
23 inline
24 const DensityOperator<RANK>
25 dyad(const StateVector<RANK>&, const StateVector<RANK>&);
26 
27 
28 template<int RANK1, int RANK2>
29 inline
30 const DensityOperator<RANK1+RANK2>
31 operator*(const DensityOperator<RANK1>&, const DensityOperator<RANK2>&);
32 
33 
34 template<int RANK>
35 inline
36 double frobeniusNorm(const DensityOperator<RANK>& rho) {return rho.frobeniusNorm();}
37 
38 
40 
53 template<int RANK>
55  : public LazyDensityOperator<RANK>,
56  private ArrayBase<2*RANK>,
57  private linalg::VectorSpace<DensityOperator<RANK> >
58 {
59 public:
60  static const int N_RANK=RANK;
61 
63  typedef ArrayBase <2*RANK> ABase;
64 
65  typedef typename LDO_Base::Dimensions Dimensions;
66 
67  typedef typename LDO_Base::Idx Idx;
68 
69  typedef typename ABase::ArrayLow DensityOperatorLow;
70 
71  typedef linalg::CMatrix CMatrix;
72 
73  using ABase::frobeniusNorm; using ABase::getArray;
74 
75  /*
76  DensityOperator() : Base() {}
77  DensityOperatorBase() : LDO_Base(Dimensions()), ABase(DensityOperatorLow()), matrixView_() {}
78  */
79 
80  DensityOperator(const DensityOperatorLow&, ByReference);
81 
82  explicit DensityOperator(const Dimensions&, bool init=true);
83 
84  explicit DensityOperator(const StateVector<RANK>& psi);
85 
87 
89  DensityOperator& operator=(const DensityOperator& rho) {ABase::operator=(rho.getArray()); return *this;}
90 
91  template<typename OTHER>
92  DensityOperator& operator=(const OTHER& other) {getArray()=other; return *this;}
93 
94 private:
95  class IndexerProxy
96  {
97  public:
98  IndexerProxy(const DensityOperator* rho, const Idx& firstIndex) : rho_(rho), firstIndex_(firstIndex) {}
99 
100  template<typename... SubscriptPack>
101  IndexerProxy(const DensityOperator* rho, int s0, SubscriptPack... subscriptPack) : IndexerProxy(rho,Idx(s0,subscriptPack...))
102  {static_assert( mpl::size<mpl::vector<SubscriptPack...> >::value==RANK-1 , "Incorrect number of subscripts for DensityOperator." );}
103 
104  const dcomp& operator()(const Idx& secondIndex) const {return rho_->indexWithTiny(firstIndex_,secondIndex);}
105  dcomp& operator()(const Idx& secondIndex) {return const_cast<dcomp&>(static_cast<const IndexerProxy&>(*this)(secondIndex));}
106 
107  template<typename... SubscriptPack>
108  const dcomp& operator()(int s0, SubscriptPack... subscriptPack) const
109  {
110  static_assert( mpl::size<mpl::vector<SubscriptPack...> >::value==RANK-1 , "Incorrect number of subscripts for DensityOperator::IndexerProxy." );
111  return operator()(Idx(s0,subscriptPack...));
112  }
113 
114  template<typename... SubscriptPack>
115  dcomp& operator()(int s0, SubscriptPack... subscriptPack) {return const_cast<dcomp&>(static_cast<const IndexerProxy&>(*this)(s0,subscriptPack...));}
116 
117  private:
118  const DensityOperator*const rho_;
119  const Idx firstIndex_;
120 
121  };
122 
123  friend class IndexerProxy;
124 
125 public:
127 
128  const IndexerProxy operator()(const Idx& firstIndex) const {return IndexerProxy(this,firstIndex);}
129  IndexerProxy operator()(const Idx& firstIndex) {return IndexerProxy(this,firstIndex);}
130 
131  template<typename... SubscriptPack>
132  const IndexerProxy operator()(int s0, SubscriptPack... subscriptPack) const {return IndexerProxy(this,s0,subscriptPack...);}
133 
134  template<typename... SubscriptPack>
135  IndexerProxy operator()(int s0, SubscriptPack... subscriptPack) {return IndexerProxy(this,s0,subscriptPack...);}
137 
139 
140  double norm() const;
141  double renorm() ;
142 
143 
145 
146  const CMatrix matrixView() const {return blitzplusplus::binaryArray(getArray());}
147  CMatrix matrixView() {return blitzplusplus::binaryArray(getArray());}
148 
149 
151 
152  DensityOperator& operator+=(const DensityOperator& rho) {ABase::operator+=(rho); return *this;}
153  DensityOperator& operator-=(const DensityOperator& rho) {ABase::operator-=(rho); return *this;}
154 
155  const DensityOperator operator-() const {DensityOperator res(this->getDimensions(),false); res.getArray()=-this->getArray(); return res;}
156  const DensityOperator operator+() const {return *this;}
157 
158  template<typename OTHER>
159  DensityOperator& operator*=(const OTHER& dc) {ABase::operator*=(dc); return *this;}
160 
161  template<typename OTHER>
162  DensityOperator& operator/=(const OTHER& dc) {ABase::operator/=(dc); return *this;}
164 
165 private:
166  const dcomp& indexWithTiny(const Idx&, const Idx&) const;
167 
168  const dcomp index(const Idx& i, const Idx& j) const override {return indexWithTiny(i,j);}
169 
170  double trace_v() const override {return norm();}
171 
172 };
173 
174 
176 template<int RANK>
177 void inflate(const DArray<1>&, DensityOperator<RANK>&, bool offDiagonals);
178 
179 
181 template<int RANK>
182 const DensityOperator<RANK>
183 densityOperatorize(const LazyDensityOperator<RANK>&);
184 
185 
186 template<int... SUBSYSTEM, int RANK>
187 const DensityOperator<mpl::size<tmptools::Vector<SUBSYSTEM...> >::value>
188 reduce(const LazyDensityOperator<RANK>&);
189 
190 
191 } // quantumdata
192 
193 
194 #endif // CPPQEDCORE_QUANTUMDATA_DENSITYOPERATOR_H_INCLUDED
const DensityOperator< RANK > densityOperatorize(const LazyDensityOperator< RANK > &)
Creates a DensityOperator as the (deep) copy of the data of a LazyDensityOperator of the same arity...
Comprises the common functionalities of StateVector and DensityOperator.
Definition: ArrayBase.h:21
Defines class of the same name.
ArrayBase & operator=(const ArrayLow &arrayLow)
Assignment with by-value semantics (like the assignment of a blitz::Array).
Definition: ArrayBase.h:35
Comprises classes representing the state of composite quantum systems and providing various interface...
Definition: ArrayBase.h:16
Density operator of arbitrary arity.
State vector of arbitrary arity.
Definition: StateVector.h:58
const blitz::Array< T, 2 > binaryArray(const blitz::Array< T, TWO_TIMES_RANK > &array)
Returns a binary view of array. TWO_TIMES_RANK must be an even number.
IdxTiny< RANK > Idx
The type used for indexing the “rows” and the “columns”: a tiny vector of integers (multi-index) ...
blitz::Array< double, RANK > DArray
An array of doubles of arbitrary arity.
Definition: BlitzArray.h:13
Defines class of the same name.
Defines class of the same name.
DensityOperator(const DensityOperatorLow &, ByReference)
Referencing constructor implemented in terms of blitzplusplus::halfCutTiny.
void inflate(const DArray< 1 > &, DensityOperator< RANK > &, bool offDiagonals)
Performs the opposite of quantumdata::deflate.
const CMatrix matrixView() const
returns a two-dimensional view of the underlying data, created on the fly via blitzplusplus::binaryAr...
DensityOperator & operator=(const DensityOperator &rho)
Default assignment doesn't work, because LazyDensityOperator is always purely constant (const Dimensi...
double frobeniusNorm() const
The entrywise array norm.
Definition: ArrayBase.h:76
CArray< 2 > CMatrix
Complex matrix.
Definition: CMatrix.h:14
Defines class of the same name.
Common interface for calculating quantum averages.
Base::Dimensions Dimensions
Inherited from DimensionsBookkeeper.
const Dimensions & getDimensions() const
Get the Dimensions vector.
quantumdata::DensityOperator< 1 > DensityOperator
unary DensityOperator
Definition: Free.h:40
double renorm()
” and also renormalises
std::complex< double > dcomp
Double-precision complex number.
A non-negative compile-time vector.
Definition: TMP_Tools.h:200
Operator aggregate for a complex vector space built on top of Boost.Operator.
Definition: Operators.h:25
CArray< RANK > ArrayLow
The underlying storage.
Definition: ArrayBase.h:24
double norm() const
returns the trace “norm”
Extensions built on top of Boost.Operator.