C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
Composite.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)
3 #ifndef CPPQEDCORE_COMPOSITES_COMPOSITE_H_INCLUDED
4 #define CPPQEDCORE_COMPOSITES_COMPOSITE_H_INCLUDED
5 
6 #include "CompositeFwd.h"
7 
8 #include "Act.h"
9 
11 // This is included at this point mainly to pull in necessary TMP tools
12 
13 #include "SubSystem.h"
14 
15 #include "details_TMP_helpers.h"
16 
17 #include <boost/fusion/container/generation/make_list.hpp>
18 
19 
20 namespace composite {
21 
22 using boost::fusion::make_list;
23 
24 using ::size_t;
25 
26 namespace result_of {
27 
28 using boost::fusion::result_of::make_list;
29 
30 } // result_of
31 
32 
33 template<typename VA>
34 struct MaxRank : MaxMF<typename MaxMF<VA,SeqLess<mpl::_1,mpl::_2> >::type>::type::type {};
35 
36 
37 
38 template<int N_RANK>
39 // Factoring out code that depends only on RANK:
40 class RankedBase : public structure::QuantumSystem<N_RANK>
41 {
42 public:
43  static const int RANK=N_RANK;
44 
45  typedef boost::shared_ptr<const RankedBase<RANK> > Ptr;
46 
47  typedef blitz::TinyVector<SubSystemFree,RANK> Frees;
48 
50 
51  typedef typename QS_Base::Dimensions Dimensions;
52 
54 
55 private:
56  // Constructor helper
57  static const Dimensions fillDimensions(const Frees&);
58 
59 protected:
60  explicit RankedBase(const Frees& frees)
61  : QS_Base(fillDimensions(frees)), frees_(frees) {}
62 
63  const Frees& getFrees() const {return frees_;}
64 
65 private:
66  const Frees frees_;
67 
68 };
69 
70 
71 template<typename VA>
72 // VA should model a fusion sequence of Acts
73 class Base
74  : public RankedBase<MaxRank<VA>::value+1>,
75  public structure::Averaged<MaxRank<VA>::value+1>
76 {
77 public:
78  typedef boost::shared_ptr<const Base<VA> > Ptr;
79 
80  // The calculated RANK
81  static const int RANK=MaxRank<VA>::value+1;
82 
83 private:
84  // Compile-time sanity check
85  static_assert( composite::CheckMeta<RANK,VA>::type::value == true , "Composite not consistent" );
86 
87 public:
88  // Public types
89  typedef VA Acts;
90 
91  typedef RankedBase<RANK> RBase ;
93 
95 
96  typedef typename Av_Base::Averages Averages ;
97 
98  typedef typename RBase:: Frees Frees;
99  typedef typename RBase::Ordinals Ordinals;
100 
101  template<structure::LiouvilleanAveragedTag>
102  static std::ostream& displayKeyLA(std::ostream& , size_t&, const Frees&, const VA& acts);
103 
104  template<structure::LiouvilleanAveragedTag>
105  class DisplayKey;
106 
107  template<structure::LiouvilleanAveragedTag>
108  static size_t nAvrLA(const Frees& frees, const VA& acts);
109 
110  template<structure::LiouvilleanAveragedTag>
111  class NAvr;
112 
113  template<structure::LiouvilleanAveragedTag>
114  static const Averages averageLA(double t, const LazyDensityOperator& ldo, const Frees& frees, const VA& acts, size_t numberAvr);
115 
116  template<structure::LiouvilleanAveragedTag>
117  class Average;
118 
119 protected:
120  // Constructor
121  explicit Base(const Frees& frees, const VA& acts)
122  : RBase(frees), frees_(RBase::getFrees()), acts_(acts) {}
123 
124  const VA& getActs() const {return acts_;}
125 
126 private:
127  // Implementing QuantumSystem interface
128 
129  double highestFrequency_v( ) const;
130  std::ostream& displayParameters_v(std::ostream&) const; class DisplayParameters;
131 
132  // Implementing Av_Base
133 
134  std::ostream& displayKey_v(std::ostream& os, size_t& i) const {return displayKeyLA<structure::LA_Av>(os,i, frees_,acts_ );}
135  size_t nAvr_v() const {return nAvrLA<structure::LA_Av>( frees_,acts_ );}
136  const Averages average_v(double t, const LazyDensityOperator& ldo) const {return averageLA<structure::LA_Av>(t,ldo,frees_,acts_,nAvr_v());}
137 
138  void process_v(Averages&) const; class Process;
139  std::ostream& display_v(const Averages&, std::ostream&, int) const; class Display;
140 
141  const Frees& frees_;
142  const VA acts_;
143 
144 };
145 
146 
147 // Constructor helper
148 template<typename VA>
149 const typename Base<VA>::Frees fillFrees(const VA& acts);
150 
151 
152 
153 template<typename VA>
154 const typename Base<VA>::Ptr doMake(const VA&);
155 
156 
157 
158 template<typename VA>
159 class Exact
160  : public structure::Exact<MaxRank<VA>::value+1>
161 {
162 private:
163  static const int RANK=MaxRank<VA>::value+1;
164 
165  typedef blitz::TinyVector<SubSystemFree,RANK> Frees;
166 
167  typedef typename quantumdata::Types<RANK>::StateVectorLow StateVectorLow;
168 
170 
171 protected:
172  Exact(const Frees& frees, const VA& acts) : frees_(frees), acts_(acts) {}
173 
174 private:
175  bool applicableInMaster_v( ) const; class IsUnitary;
176  void actWithU_v(double, StateVectorLow&, double) const; class ActWithU ;
177 
178  const Frees& frees_;
179  const VA & acts_;
180 
181 };
182 
183 
184 template<typename VA>
186  : public structure::Hamiltonian<MaxRank<VA>::value+1>
187 {
188 private:
189  static const int RANK=MaxRank<VA>::value+1;
190 
191  typedef blitz::TinyVector<SubSystemFree,RANK> Frees;
192 
193  typedef typename quantumdata::Types<RANK>::StateVectorLow StateVectorLow;
194 
196 
197 protected:
198  Hamiltonian(const Frees& frees, const VA& acts) : frees_(frees), acts_(acts) {}
199 
200 private:
201  void addContribution_v(double, const StateVectorLow&, StateVectorLow&, double) const; class AddContribution;
202 
203  const Frees& frees_;
204  const VA & acts_;
205 
206 };
207 
208 
209 template<typename VA>
211  : public structure::Liouvillean<MaxRank<VA>::value+1>
212 {
213 private:
214  static const int RANK=MaxRank<VA>::value+1;
215 
216  typedef blitz::TinyVector<SubSystemFree,RANK> Frees;
217 
218  typedef typename quantumdata::Types<RANK>::StateVectorLow StateVectorLow;
219 
221 
223 
224  typedef typename structure::Liouvillean<RANK>::Rates Rates;
225 
226 protected:
227  Liouvillean(const Frees& frees, const VA& acts) : frees_(frees), acts_(acts) {}
228 
229 private:
230  std::ostream& displayKey_v(std::ostream& os, size_t& i) const {return Base<VA>::template displayKeyLA<structure::LA_Li>(os,i, frees_,acts_ );}
231  size_t nAvr_v() const {return Base<VA>::template nAvrLA<structure::LA_Li>( frees_,acts_ );}
232  const Rates average_v(double t, const LazyDensityOperator& ldo) const {return Base<VA>::template averageLA<structure::LA_Li>(t,ldo,frees_,acts_,nAvr_v());}
233 
234  void actWithJ_v(double, StateVectorLow&, size_t) const; class ActWithJ;
235 
236  const Frees& frees_;
237  const VA & acts_;
238 
239 };
240 
241 
242 template<typename>
244 {
245 public:
246  template<typename VA>
247  EmptyBase(const blitz::TinyVector<SubSystemFree,MaxRank<VA>::value+1>&, const VA&) {}
248 
249 };
250 
251 
252 } // composite
253 
254 
255 
256 #define BASE_class(Aux,Class) mpl::if_c<IS_##Aux,composite::Class<VA>,composite::EmptyBase<composite::Class<VA> > >::type
257 
259 
313 template<typename VA, bool IS_EX=true, bool IS_HA=true, bool IS_LI=true>
314 // VA should model a fusion sequence of Acts
316  : public composite::Base<VA>,
317  public BASE_class(EX,Exact),
318  public BASE_class(HA,Hamiltonian),
319  public BASE_class(LI,Liouvillean)
320 {
321 public:
322  typedef composite::Base<VA> Base;
323 
324  typedef typename BASE_class(EX,Exact) ExactBase;
325  typedef typename BASE_class(HA,Hamiltonian) HamiltonianBase;
326  typedef typename BASE_class(LI,Liouvillean) LiouvilleanBase;
327 
328  typedef typename composite::Base<VA>::Frees Frees;
329 
330  // The calculated RANK
331  static const int RANK=Base::RANK;
332 
333 private:
334  using Base::getFrees; using Base::getActs ;
335 
336 public:
337  // Constructor
338  explicit Composite(const VA& acts)
339  : Base(composite::fillFrees(acts),acts),
340  ExactBase (getFrees(),getActs()),
341  HamiltonianBase(getFrees(),getActs()),
342  LiouvilleanBase(getFrees(),getActs()) {}
343 
344 // private:
345  Composite(const Frees& frees, const VA& acts)
346  : Base(frees ,acts),
347  ExactBase (getFrees(),getActs()),
348  HamiltonianBase(getFrees(),getActs()),
349  LiouvilleanBase(getFrees(),getActs()) {}
350 
351  friend const typename composite::Base<VA>::Ptr composite::doMake<VA>(const VA&);
352 
353  // Note that Frees and Acts are stored by value in Base
354 
355 };
356 
357 #undef BASE_class
358 
359 
360 // The following provides a much more convenient interface:
361 
362 namespace composite {
363 
364 namespace result_of {
365 
366 
367 template<bool IS_EX, bool IS_HA, bool IS_LI, typename... Acts>
368 struct MakeConcrete : boost::mpl::identity<Composite<typename make_list<Acts...>::type, IS_EX, IS_HA, IS_LI> > {};
369 
370 
371 template<typename... Acts>
372 struct Make : boost::mpl::identity<typename Base<typename make_list<Acts...>::type>::Ptr> {};
373 
374 
375 
376 } // result_of
377 
378 
379 template<typename... Acts>
380 const typename result_of::Make<Acts...>::type
381 make(const Acts&... acts)
382 {
383  return doMake(make_list(acts...));
384 }
385 
386 
387 } // composite
388 
389 
390 #endif // CPPQEDCORE_COMPOSITES_COMPOSITE_H_INCLUDED
The interface every system that needs transformation between two quantum mechanical pictures must pre...
Definition: Exact.h:57
Definition of blitzplusplus::basi::Iterator together with its helpers.
boost::shared_ptr< const Base > Ptr
Convenience typedef.
Definition: BinarySystem.h:17
Auxiliary tools to Composite.
Definition: Act.h:15
const Ptr doMake(Interaction::Ptr)
Maker function for BinarySystem.
The interface every system having (possibly non-Hermitian) Hamiltonian time-evolution must present to...
Definition: Hamiltonian.h:27
The interface every system that calculates and displays quantum averages must present towards the tra...
Definition: Averaged.h:84
Class representing a full-fledged composite quantum system defined by a network of interactions...
Definition: Composite.h:315
Common interface for calculating quantum averages.
Defines the helper class composite::_.
The abstract interface every system has to present towards the quantum trajectory drivers quantumtraj...
Definition: QuantumSystem.h:25
The interface every system having Liouvillean time-evolution must present towards the trajectory driv...
Definition: Liouvillean.h:37
static const int N_RANK
Arity of the Hilbert space.
Defines composite::SubSystemFree and composite::SubSystemsInteraction.
LiouvilleanAveragedCommon::DArray1D Averages
The 1D real array storing the calculated quantum averages (perhaps in real-imaginary pairs if a given...
Definition: Averaged.h:33
Sequence of ordinals 0 ... N-1 based on Range.
Definition: TMP_Tools.h:71
Base::DArray1D Rates
The 1D real array for storing the jump rates.
Definition: Liouvillean.h:55