C++QEDElements  2.100.2 (v2 Milestone 10 Development branch)
a framework for simulating open quantum dynamics – generic elements
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
AveragingUtils.h
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
2 // -*- C++ -*-
3 #ifndef CPPQEDELEMENTS_UTILS_AVERAGINGUTILS_H_INCLUDED
4 #define CPPQEDELEMENTS_UTILS_AVERAGINGUTILS_H_INCLUDED
5 
6 #include "AveragingUtilsFwd.h"
7 
8 #include "ElementAveraged.h"
9 
10 #include "DimensionsBookkeeper.h"
11 
12 #include <boost/assign/list_of.hpp>
13 
14 #include <boost/ptr_container/ptr_list.hpp>
15 
16 
17 
18 template<int RANK>
20 {
21 private:
23 
24 public:
25  typedef typename Base::Averages Averages;
27 
28  typedef typename Base::KeyLabels KeyLabels;
29 
31 
33 
34  ReducedDensityOperator(const std::string&, const Dimensions&, bool offDiagonals=false, const KeyLabels& =KeyLabels());
35 
36 private:
37  static const KeyLabels helper(const Dimensions&, bool offDiagonals, const KeyLabels&);
38 
39  Base*const do_clone() const {return new ReducedDensityOperator(*this);}
40 
41 protected:
42  const Averages average_v(structure::NoTime, const LazyDensityOperator&) const;
43 
44 private:
45  const bool offDiagonals_;
46 
47 };
48 
49 
50 template<int RANK, typename V>
52 {
53 public:
55  typedef typename Base::Dimensions Dimensions;
56  typedef typename Base::Averages Averages;
57  typedef typename Base::LazyDensityOperator LazyDensityOperator;
58 
60 
61  ReducedDensityOperatorNegativity(const std::string& label, const Dimensions& dim)
62  : Base(label,dim,true,boost::assign::list_of("negativity")) {}
63 
64 private:
65  const Averages average_v(structure::NoTime, const LazyDensityOperator&) const;
66  void process_v( Averages& ) const;
67 
68 };
69 
70 
71 namespace averagingUtils {
72 
73 
74 template<int RANK, bool IS_TIME_DEPENDENT>
75 class Collecting : public structure::ClonableElementAveraged<RANK,IS_TIME_DEPENDENT>
76 {
77 private:
79 
80 public:
81  typedef Base Element;
82  typedef boost::ptr_list<Element> Collection;
83 
84  typedef typename Base::KeyLabels KeyLabels;
85 
87  typedef typename Base::LazyDensityOperator LazyDensityOperator;
88 
89  typedef typename Base::Time Time;
90 
91  Collecting(const Collection&);
92  Collecting(const Collecting&);
93 
94 private:
95  Base*const do_clone() const {return new Collecting(*this);}
96 
97  const Averages average_v(Time, const LazyDensityOperator&) const;
98 
99  void process_v(Averages&) const;
100 
101  const Collection collection_;
102 
103 };
104 
105 
106 
107 template<int RANKFROM, int RANKTO, bool IS_TIME_DEPENDENT>
108 class Transferring : public structure::AveragedTimeDependenceDispatched<RANKFROM,IS_TIME_DEPENDENT>
109 // Transfers the calculation of averages to another Averaged class, possibly with different RANK.
110 // The LazyDensityOperator for the other class should reference the same data.
111 // For a usage example cf. scripts/QbitMode_Matrix.cc
112 {
113 private:
115 
116 public:
117  typedef typename Base::Averages Averages ;
118  typedef typename Base::LazyDensityOperator LazyDensityOperator;
119 
120  typedef typename Base::Time Time;
121 
124 
125  Transferring(AveragedToPtr averaged, const LazyDensityOperatorTo& ldo)
126  : averaged_(averaged), ldo_(ldo) {}
127 
128 private:
129  std::ostream& displayKey_v(std::ostream& os, size_t& n) const {return averaged_->displayKey(os,n);}
130 
131  void process_v(Averages& averages) const {averaged_->process(averages);}
132 
133  std::ostream& display_v(const Averages& averages, std::ostream& os, int n) const {return averaged_->display(averages,os,n);}
134 
135  size_t nAvr_v() const {return averaged_->nAvr();}
136 
137  const Averages average_v(Time t, const LazyDensityOperator&) const;
138 
139  const AveragedToPtr averaged_;
140  const LazyDensityOperatorTo& ldo_;
141 
142 };
143 
144 
145 } // averagingUtils
146 
147 
148 #endif // CPPQEDELEMENTS_UTILS_AVERAGINGUTILS_H_INCLUDED
const Dimensions & getDimensions() const
size_t getTotalDimension() const
LiouvilleanAveragedCommon::DArray1D Averages