C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
LazyDensityOperator.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_LAZYDENSITYOPERATOR_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_LAZYDENSITYOPERATOR_H_INCLUDED
6 
7 #include "LazyDensityOperatorFwd.h"
8 
9 #include "DimensionsBookkeeper.h"
10 
11 #include "BlitzArray.h"
12 #include "ComplexExtensions.h"
13 
14 #include <boost/shared_ptr.hpp>
15 
16 #include <boost/mpl/if.hpp>
17 
18 
19 namespace mpl=boost::mpl;
20 
21 
23 
24 namespace quantumdata {
25 
26 
28 
36 template<typename V, typename T, int RANK, typename F>
37 const T
38 partialTrace(const LazyDensityOperator<RANK>&, F function);
39 
40 
42 
60 template<int RANK>
62  : public DimensionsBookkeeper<RANK,true>
63 {
64 public:
65  typedef boost::shared_ptr<const LazyDensityOperator> Ptr;
66 
68 
69  typedef typename Base::Dimensions Dimensions;
70 
71  typedef IdxTiny<RANK> Idx;
72 
73  virtual ~LazyDensityOperator() {}
74 
75 private:
76  class IndexerProxy
77  {
78  public:
79  IndexerProxy(const LazyDensityOperator* ldo, const Idx& firstIndex) : ldo_(ldo), firstIndex_(firstIndex) {}
80 
81  const dcomp operator()(const Idx& secondIndex) const {return ldo_->index(firstIndex_,secondIndex);}
82 
83  template<typename... SubscriptPack>
84  const dcomp operator()(int s0, SubscriptPack... subscriptPack) const
85  {
86  static_assert( mpl::size<mpl::vector<SubscriptPack...> >::value==RANK-1 , "Incorrect number of subscripts for LazyDensityOperator::IndexerProxy." );
87  return operator()(Idx(s0,subscriptPack...));
88  }
89 
90  operator double() const {return real(ldo_->index(firstIndex_,firstIndex_));}
91 
92  private:
93  const LazyDensityOperator*const ldo_;
94  const Idx firstIndex_;
95 
96  };
97 
98  friend class IndexerProxy;
99 
100 public:
102  const IndexerProxy operator()(const Idx& firstIndex) const {return IndexerProxy(this,firstIndex);}
103 
105 
119  template<typename... SubscriptPack>
120  const IndexerProxy operator()(int s0, SubscriptPack... subscriptPack) const
121  {
122  static_assert( mpl::size<mpl::vector<SubscriptPack...> >::value==RANK-1 , "Incorrect number of subscripts for LazyDensityOperator." );
123  return operator()(Idx(s0,subscriptPack...));
124  }
125 
126  double trace() const {return trace_v();}
127 
129 
130 
134  template<typename V>
135  const ldo::DiagonalIterator<RANK,V> begin() const;
136 
137  template<typename V>
138  const ldo::DiagonalIterator<RANK,V> end () const;
139 
140 
141 protected:
142  LazyDensityOperator(const Dimensions& dims) : Base(dims) {}
143 
144 private:
145  virtual const dcomp index(const Idx& i, const Idx& j) const = 0;
146 
147  virtual double trace_v() const = 0;
148 
149 };
150 
151 
153 
159 template<int RANK>
160 const DArray<1> deflate(const LazyDensityOperator<RANK>&, bool offDiagonals);
161 
162 
269 } // quantumdata
270 
271 #endif // CPPQEDCORE_QUANTUMDATA_LAZYDENSITYOPERATOR_H_INCLUDED
const ldo::DiagonalIterator< RANK, V > begin() const
Return the ldo::DiagonalIterator corresponding to the beginning of the sequence of slices defined by ...
quantumdata::LazyDensityOperator< 1 > LazyDensityOperator
unary LazyDensityOperator
Definition: Free.h:37
blitz::TinyVector< ptrdiff_t, RANK > IdxTiny
A tiny vector used for indexing of objects of arbitrary arity.
Definition: BlitzTiny.h:32
Comprises classes representing the state of composite quantum systems and providing various interface...
Definition: ArrayBase.h:16
Iterator for slices of a LazyDensityOperator that are diagonal in the dummy indices.
double trace() const
Returns the trace (redirected to a pure virtual)
const IndexerProxy operator()(int s0, SubscriptPack...subscriptPack) const
Multi-matrix style indexing via packs of integers.
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.
Stores and manipulates dimensions of constructs over composite Hilbert spaces of arbitrary arity...
Additional helpers for dcomp.
boost::shared_ptr< const LazyDensityOperator > Ptr
Many class templates in the framework define shared pointers to their own types, in a template-metafu...
Common interface for calculating quantum averages.
const DArray< 1 > deflate(const LazyDensityOperator< RANK > &, bool offDiagonals)
Turns the data of a LazyDensityOperator into a real 1D array.
Base::Dimensions Dimensions
Inherited from DimensionsBookkeeper.
const IndexerProxy operator()(const Idx &firstIndex) const
Multi-matrix style indexing via Idx type.
const ldo::DiagonalIterator< RANK, V > end() const
” for the end
std::complex< double > dcomp
Double-precision complex number.
ExtTiny< RANK > Dimensions
The dimensions as a static vector of size N_RANK.
const T partialTrace(const LazyDensityOperator< RANK > &, F function)
The primary tool for performing slice iterations.
Defines template aliases for real and complex arrays.