C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
Structure.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_STRUCTURE_STRUCTURE_H_INCLUDED
5 #define CPPQEDCORE_STRUCTURE_STRUCTURE_H_INCLUDED
6 
7 #include "StructureFwd.h"
8 
9 #include "QuantumSystem.h"
10 #include "DynamicsBase.h"
11 
12 #include "Exact.h"
13 #include "Hamiltonian.h"
14 #include "Liouvillean.h"
15 #include "Averaged.h"
16 
17 
19 
40 namespace structure {
41 
42 
43 typedef blitz::TinyVector<bool,3> SystemCharacteristics;
44 
45 
46 using boost::dynamic_pointer_cast;
47 
48 
50 template<int RANK>
51 inline
52 const typename Exact<RANK>::Ptr
53 qse(boost::shared_ptr<const QuantumSystem<RANK> > quantumSystem)
54 {return dynamic_pointer_cast<const Exact<RANK> >(quantumSystem);}
55 
57 template<int RANK>
58 inline
59 const typename Hamiltonian<RANK>::Ptr
60 qsh(boost::shared_ptr<const QuantumSystem<RANK> > quantumSystem)
61 {return dynamic_pointer_cast<const Hamiltonian<RANK> >(quantumSystem);}
62 
64 template<int RANK>
65 inline
66 const typename Liouvillean<RANK>::Ptr
67 qsl(boost::shared_ptr<const QuantumSystem<RANK> > quantumSystem)
68 {return dynamic_pointer_cast<const Liouvillean<RANK> >(quantumSystem);}
69 
71 template<int RANK>
72 inline
73 const typename Averaged<RANK>::Ptr
74 qsa(boost::shared_ptr<const QuantumSystem<RANK> > quantumSystem)
75 {return dynamic_pointer_cast<const Averaged<RANK> >(quantumSystem);}
76 
77 
79 template<int RANK>
80 inline
81 const typename Exact<RANK>::Ptr
82 qse(DynamicsBase::Ptr base)
83 {return dynamic_pointer_cast<const Exact<RANK> >(base);}
84 
86 template<int RANK>
87 inline
88 const typename Hamiltonian<RANK>::Ptr
89 qsh(DynamicsBase::Ptr base)
90 {return dynamic_pointer_cast<const Hamiltonian<RANK> >(base);}
91 
93 template<int RANK>
94 inline
95 const typename Liouvillean<RANK>::Ptr
96 qsl(DynamicsBase::Ptr base)
97 {return dynamic_pointer_cast<const Liouvillean<RANK> >(base);}
98 
100 template<int RANK>
101 inline
102 const typename Averaged<RANK>::Ptr
103 qsa(DynamicsBase::Ptr base)
104 {return dynamic_pointer_cast<const Averaged<RANK> >(base);}
105 
106 
107 
108 // Some functions that are used in contexts other than QuantumSystemWrapper are factored out:
109 
110 
112 template<int RANK>
113 std::ostream& display(boost::shared_ptr<const Averaged<RANK> >, double, const quantumdata::LazyDensityOperator<RANK>&, std::ostream&, int);
114 
115 
117 template<int RANK>
118 const LiouvilleanAveragedCommon::DArray1D average(typename LiouvilleanAveragedCommonRanked<RANK>::Ptr, double, const quantumdata::LazyDensityOperator<RANK>&);
119 
120 
122 
133 template<int RANK, bool IS_CONST>
135 {
136 public:
137  static const int N_RANK=RANK;
138 
140 
141  typedef QuantumSystem<RANK> QS;
142  typedef Exact <RANK> Ex;
143  typedef Hamiltonian <RANK> Ha;
144  typedef Liouvillean <RANK> Li;
145  typedef Averaged <RANK> Av;
147 
149 
150  typedef typename QS::Ptr QuantumSystemPtr;
151  typedef typename Ex::Ptr ExactPtr;
152  typedef typename Ha::Ptr HamiltonianPtr;
153  typedef typename Li::Ptr LiouvilleanPtr;
154  typedef typename Av::Ptr AveragedPtr;
156 
158 
159  typedef typename Ex::StateVectorLow StateVectorLow;
160 
161  typedef typename Li::Rates Rates ;
162  typedef typename Li::LazyDensityOperator LazyDensityOperator;
163 
164  typedef typename Av::Averages Averages;
166 
168 
169  explicit QuantumSystemWrapper(DynamicsBase::Ptr qs)
170  : qs_(dynamic_pointer_cast<const QuantumSystem<RANK> >(qs)),
171  ex_(qse<RANK>(qs)),
172  ha_(qsh<RANK>(qs)),
173  li_(qsl<RANK>(qs)),
174  av_(qsa<RANK>(qs))
175  {}
176 
177  explicit QuantumSystemWrapper(QuantumSystemPtr qs, bool isNoisy)
178  : qs_(qs),
179  ex_(qse<RANK>(qs)),
180  ha_(qsh<RANK>(qs)),
181  li_(isNoisy ? qsl<RANK>(qs) : LiouvilleanPtr()),
182  av_(qsa<RANK>(qs))
183  {}
184 
185 
187 
188  const QuantumSystemPtr getQS() const {return qs_;}
189  const ExactPtr getEx() const {return ex_;}
190  const HamiltonianPtr getHa() const {return ha_;}
191  const LiouvilleanPtr getLi() const {return li_;}
192  const AveragedPtr getAv() const {return av_;}
193 
194  QuantumSystemPtr getQS() {return qs_;}
195  ExactPtr getEx() {return ex_;}
196  HamiltonianPtr getHa() {return ha_;}
197  LiouvilleanPtr getLi() {return li_;}
198  AveragedPtr getAv() {return av_;}
200 
201 private:
202  typedef typename LiouvilleanAveragedCommonRanked<RANK>::Ptr L_or_A_Ptr;
203 
204 public:
210  const L_or_A_Ptr getLA(LA_Li_tagType) const {return li_;}
211  const L_or_A_Ptr getLA(LA_Av_tagType) const {return av_;}
213 
215  std::ostream& displayCharacteristics(std::ostream& os) const {return os<<"# System characteristics: "<<(ex_ ? "Interaction picture, " : "")<<(ha_ ? "Hamiltonian evolution, " : "")<<(li_ ? "Liouvillean evolution, " : "")<<(av_ ? "calculates Averages." : "");}
216 
217 
219 
220  bool applicableInMaster() const {return ex_ ? ex_->applicableInMaster() : true;}
221 
222  void actWithU(double t, StateVectorLow& psi, double t0) const {if (ex_) ex_->actWithU(t,psi,t0);}
224 
225 
227 
228  void addContribution(double t, const StateVectorLow& psi, StateVectorLow& dpsidt, double t0) const {if (ha_) ha_->addContribution(t,psi,dpsidt,t0);}
230 
231 
233 
234  void actWithJ(double t, StateVectorLow& psi, size_t lindbladNo) const {if (li_) li_->actWithJ(t,psi,lindbladNo);}
236 
237 
239 
240  void process(Averages& averages) const {if (av_) av_->process(averages);}
241 
242  std::ostream& display(double t, const LazyDensityOperator& matrix, std::ostream& os, int precision) const {return structure::display(av_,t,matrix,os,precision);}
244 
245 
247 
248  template<LiouvilleanAveragedTag LA>
249  size_t nAvr() const {const auto ptr=getLA(LiouvilleanAveragedTag_<LA>()); return ptr ? ptr->nAvr() : 0;}
250 
251  template<LiouvilleanAveragedTag LA>
252  std::ostream& displayKey(std::ostream& os, size_t& i) const {if (const auto ptr=getLA(LiouvilleanAveragedTag_<LA>())) ptr->displayKey(os,i); return os;}
253 
254  template<LiouvilleanAveragedTag LA>
255  const Averages average(double t, const LazyDensityOperator& matrix) const {return structure::average(getLA(LiouvilleanAveragedTag_<LA>()),t,matrix);}
257 
258 protected:
259  QuantumSystemWrapper() : qs_(), ex_(), ha_(), li_(), av_() {}
260 
261 private:
267 
268 };
269 
270 
271 
272 template<int RANK>
273 std::ostream& display(boost::shared_ptr<const Averaged<RANK> > av,
274  double t,
276  std::ostream& os,
277  int precision)
278 {
279  if (av) {
280  typename Averaged<RANK>::Averages averages(av->average(t,matrix));
281  av->process(averages);
282  av->display(averages,os,precision);
283  }
284  return os;
285 }
286 
287 
288 template<int RANK>
289 const LiouvilleanAveragedCommon::DArray1D average(typename LiouvilleanAveragedCommonRanked<RANK>::Ptr ptr, double t, const quantumdata::LazyDensityOperator<RANK>& matrix)
290 {
291  return ptr ? ptr->average(t,matrix) : LiouvilleanAveragedCommon::DArray1D();
292 }
293 
294 
295 } // structure
296 
297 
298 
299 #endif // CPPQEDCORE_STRUCTURE_STRUCTURE_H_INCLUDED
const Liouvillean< RANK >::Ptr qsl(boost::shared_ptr< const QuantumSystem< RANK > > quantumSystem)
Dynamic cast to a shared pointer to Liouvillean
Definition: Structure.h:67
std::ostream & displayCharacteristics(std::ostream &os) const
Displays the dynamical characteristics of the system.
Definition: Structure.h:215
The interface every system that needs transformation between two quantum mechanical pictures must pre...
Definition: Exact.h:57
Defines class of the same name.
const Exact< RANK >::Ptr qse(DynamicsBase::Ptr base)
Dynamic cast to a shared pointer to Exact
Definition: Structure.h:82
Applies add_const if ADD_CONST = true.
Definition: TMP_Tools.h:62
boost::shared_ptr< const Base > Ptr
Convenience typedef.
Definition: BinarySystem.h:17
A wrapper for Exact, Hamiltonian, Liouvillean, and Averaged.
Definition: Structure.h:134
DArray< 1 > DArray1D
A 1D real array storing the quantum averages – even if they are complex, their real & imaginary part...
const Hamiltonian< RANK >::Ptr qsh(DynamicsBase::Ptr base)
Dynamic cast to a shared pointer to Hamiltonian
Definition: Structure.h:89
boost::shared_ptr< const QuantumSystem > Ptr
Many of the basic template classes in the framework act as template metafunctions returning a shared ...
Definition: QuantumSystem.h:30
Defines class of the same name.
Comprises modules for describing quantum systems.
Definition: Averaged.h:17
The interface every system having (possibly non-Hermitian) Hamiltonian time-evolution must present to...
Definition: Hamiltonian.h:27
Defines class of the same name.
const Averaged< RANK >::Ptr qsa(boost::shared_ptr< const QuantumSystem< RANK > > quantumSystem)
Dynamic cast to a shared pointer to Averaged
Definition: Structure.h:74
Defines class of the same name.
The interface every system that calculates and displays quantum averages must present towards the tra...
Definition: Averaged.h:84
const Hamiltonian< RANK >::Ptr qsh(boost::shared_ptr< const QuantumSystem< RANK > > quantumSystem)
Dynamic cast to a shared pointer to Hamiltonian
Definition: Structure.h:60
const Liouvillean< RANK >::Ptr qsl(DynamicsBase::Ptr base)
Dynamic cast to a shared pointer to Liouvillean
Definition: Structure.h:96
Defines class of the same name.
Common interface for calculating quantum averages.
const Averaged< RANK >::Ptr qsa(DynamicsBase::Ptr base)
Dynamic cast to a shared pointer to Averaged
Definition: Structure.h:103
The abstract interface every system has to present towards the quantum trajectory drivers quantumtraj...
Definition: QuantumSystem.h:25
Defines class of the same name.
const Exact< RANK >::Ptr qse(boost::shared_ptr< const QuantumSystem< RANK > > quantumSystem)
Dynamic cast to a shared pointer to Exact
Definition: Structure.h:53
QuantumSystemWrapper(QuantumSystemPtr qs, bool isNoisy)
Constructor from QuantumSystem.
Definition: Structure.h:177
The interface every system having Liouvillean time-evolution must present towards the trajectory driv...
Definition: Liouvillean.h:37
QuantumSystemWrapper(DynamicsBase::Ptr qs)
Constructor from DynamicsBase.
Definition: Structure.h:169
const DArray1D average(double t, const LazyDensityOperator &matrix) const
Calculates quantum averages & checks post-conditions.
Base::DArray1D Rates
The 1D real array for storing the jump rates.
Definition: Liouvillean.h:55