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
Tridiagonal.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_QUANTUMOPERATOR_TRIDIAGONAL_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMOPERATOR_TRIDIAGONAL_H_INCLUDED
6 
7 
8 #ifndef QUANTUMOPERATOR_TRIDIAGONAL_MAX_RANK
9 #define QUANTUMOPERATOR_TRIDIAGONAL_MAX_RANK BLITZ_ARRAY_LARGEST_RANK
10 #endif // QUANTUMOPERATOR_TRIDIAGONAL_MAX_RANK
11 
12 #include "TridiagonalFwd.h"
13 
14 #include "DimensionsBookkeeper.h"
15 #include "LazyDensityOperator.h"
16 #include "Types.h"
17 
18 #include "BlitzTinyOfArrays.tcc"
19 #include "Operators.h"
20 
21 #include "Exception.h"
22 
23 
24 
25 // Stencils???
26 
30 
31 
33 namespace quantumoperator {
34 
35 
37 template<int RANK>
38 inline
39 void
40 apply(const typename quantumdata::Types<RANK>::StateVectorLow& psi, typename quantumdata::Types<RANK>::StateVectorLow& dpsidt,
41  const Tridiagonal<RANK>&);
42 
43 
45 template<int RANK>
46 const Tridiagonal<RANK>
47 furnishWithFreqs(const Tridiagonal<RANK>& tridiag,
48  const typename Tridiagonal<RANK>::Diagonal& mainDiagonal
49  );
50 
51 
53 const Tridiagonal<1> zero (size_t);
55 const Tridiagonal<1> identity(size_t);
56 
57 
59 //
60 // Tridiagonal
61 //
63 
64 
66 
102 template<int RANK>
104  : public DimensionsBookkeeper<RANK>,
105  private linalg::VectorSpace<Tridiagonal<RANK> >
106 {
107 public:
109  static const int N_RANK=RANK;
110 
111  typedef blitzplusplus::TinyOfArrays<dcomp,RANK,LENGTH> Diagonals;
112 
113  typedef typename Diagonals::T_numtype Diagonal;
114 
115 private:
117 
118 public:
119  typedef typename Base::Dimensions Dimensions;
120 
121  typedef typename quantumdata::Types<RANK>::StateVectorLow StateVectorLow;
122 
123 private:
124  typedef blitz::TinyVector<blitz::TinyVector<blitz::Range,3>,RANK> Ranges;
125 
127 
128  typedef mpl::int_<RANK> IntRANK;
129 
130  static const mpl::int_<1> _1_ ;//=mpl::int_<1>();
131  static const Diagonal empty;//=Diagonal ();
133 
134 public:
136 
137 
156  explicit Tridiagonal(const Diagonal& zero=empty,
157  size_t k=0,
158  const Diagonal& minus=empty,
159  const Diagonal& plus=empty,
160  bool toFreqs=false,
161  IntRANK=_1_);
162 
164  Tridiagonal(const Tridiagonal& tridiag) : Tridiagonal(tridiag,tridiag.diagonals_,tridiag.differences_,tridiag.tCurrent_,tridiag.freqs_) {}
165 
167 
177  template<int RANK2>
180 
182 
183 
194  Tridiagonal& furnishWithFreqs(const Diagonal& mainDiagonal, IntRANK=_1_);
195 
197 
211  void apply(const StateVectorLow& psi, StateVectorLow& dpsidt) const;
212 
214 
217  Tridiagonal& propagate(double t);
218 
220 
226  const typename quantumdata::LazyDensityOperator<RANK>::Idx&, IntRANK=_1_);
228 
230 
231  const Diagonals & get () const {return diagonals_;}
232  const Dimensions& getDifferences() const {return differences_;}
233 
234  double getTime () const {return tCurrent_;}
235 
236  const Diagonals & getFreqs () const {return freqs_;}
238 
239 
241 
242  Tridiagonal& operator*=(const dcomp& dc);
243  Tridiagonal& operator/=(const dcomp& dc) {(*this)*=1./dc; return *this;}
244  Tridiagonal& operator*=(double d) {(*this)*=dcomp(d,0); return *this;}
245  Tridiagonal& operator/=(double d) {(*this)*=1./dcomp(d,0); return *this;}
246 
247  // void hermitianConjugateSelf();
249 
258  const Tridiagonal hermitianConjugate () const;
259  const Tridiagonal dagger () const {return hermitianConjugate();}
260 
262 
271 
272  const Tridiagonal operator-() const {return Tridiagonal(*this,blitzplusplus::negate(diagonals_),differences_,tCurrent_,freqs_);}
273 
274  const Tridiagonal operator+() const {return *this;}
275 
276  Tridiagonal& operator-=(const Tridiagonal& tridiag) {(*this)+=-tridiag; return *this;}
277 
278 
279 private:
280  Tridiagonal(const Base& base, const Diagonals& diagonals, const Dimensions& differences, double tCurrent, const Diagonals& freqs)
281  : Base(base), diagonals_(blitzplusplus::DeepCopy(),diagonals), differences_(differences), tCurrent_(tCurrent), freqs_(blitzplusplus::DeepCopy(),freqs) {}
282 
284 
285  template<int START, typename V_DPSIDT, typename V_A, typename V_PSI, int REMAINING>
286  void doApply(mpl::int_<REMAINING>,const Ranges&, const StateVectorLow&, StateVectorLow&) const;
287 
288  template<int START, typename V_DPSIDT, typename V_A, typename V_PSI>
289  void doApply(mpl::int_<0>,const Ranges&, const StateVectorLow&, StateVectorLow&) const;
290 
291  struct FillRangesHelper
292  {
293  typedef const typename StateVectorLow::T_index Bound;
294 
295  FillRangesHelper(Ranges& ranges, const Bound& ubound, const Dimensions& k) : ranges_(ranges), ubound_(ubound), k_(k) {}
296 
297  template<typename ICW> void operator()(ICW);
298 
299  private:
300  Ranges& ranges_;
301  const Bound& ubound_;
302  const Dimensions& k_;
303 
304  };
305 
306  const Ranges fillRanges(const typename StateVectorLow::T_index&) const;
307 
308 
310 
311  Diagonals diagonals_;
312 
313  Dimensions differences_;
314 
315  double tCurrent_;
316 
317  Diagonals freqs_;
319 
320 };
321 
322 
323 
324 template<int RANK>
325 inline
326 void
327 apply(const typename quantumdata::Types<RANK>::StateVectorLow& psi, typename quantumdata::Types<RANK>::StateVectorLow& dpsidt,
328  const Tridiagonal<RANK>& tridiag)
329 {
330  tridiag.apply(psi,dpsidt);
331 }
332 
333 
335 template<int RANK1, int RANK2>
336 inline
337 const Tridiagonal<RANK1+RANK2>
339 {
340  return Tridiagonal<RANK1+RANK2>(t1,t2);
341 }
342 
343 
345 template<int RANK>
346 inline
347 const Tridiagonal<RANK>
348 tridiagMinusHC (const Tridiagonal<RANK>& tridiag) {return tridiag-tridiag.hermitianConjugate();}
349 
350 
352 template<int RANK>
353 inline
354 const Tridiagonal<RANK>
355 tridiagPlusHC (const Tridiagonal<RANK>& tridiag) {return tridiag+tridiag.hermitianConjugate();}
356 
357 
359 template<int RANK>
360 inline
361 const Tridiagonal<RANK>
362 tridiagPlusHC_overI(const Tridiagonal<RANK>& tridiag) {return tridiagPlusHC(tridiag)/DCOMP_I;}
363 
364 
366 template<int RANK>
367 std::ostream& operator<<(std::ostream&, const Tridiagonal<RANK>&);
368 
369 
370 } // quantumoperator
371 
372 
373 #endif // CPPQEDCORE_QUANTUMOPERATOR_TRIDIAGONAL_H_INCLUDED
The class that is (meant to be, at least) the base of all exceptions in the framework.
Definition: Exception.h:18
const Tridiagonal< RANK > tridiagMinusHC(const Tridiagonal< RANK > &tridiag)
Returns the anti-Hermitian operator .
Definition: Tridiagonal.h:348
Defines class of the same name.
Tridiagonal & propagate(double t)
Updates the elements of the matrix to time instant t using the stored frequencies.
Tridiagonal & operator*=(const dcomp &dc)
Naively implemented, could be templated if need arises – Frequencies untouched.
const Tridiagonal operator-() const
Returns a (deep) copy with negated diagonals. Frequencies remain untouched.
Definition: Tridiagonal.h:272
void apply(const StateVectorLow &psi, StateVectorLow &dpsidt) const
“Applies” the tridiagonal matrix on the state vector psiprime, in the vein of structure::Hamiltonia...
const Tridiagonal< 1 > zero(size_t)
Unary zero operator as a Tridiagonal.
Tridiagonal & operator+=(const Tridiagonal &)
Naive addition.
blitzplusplus::TinyOfArrays< dcomp, RANK, LENGTH > Diagonals
The class is implemented in terms of a blitzplusplus::TinyOfArrays, this is the class used to store t...
Definition: Tridiagonal.h:111
const dcomp DCOMP_I(0, 1)
Imaginary unit.
Tridiagonal & operator/=(const dcomp &dc)
Definition: Tridiagonal.h:243
IdxTiny< RANK > Idx
The type used for indexing the “rows” and the “columns”: a tiny vector of integers (multi-index) ...
Tridiagonal(const Diagonal &zero=empty, size_t k=0, const Diagonal &minus=empty, const Diagonal &plus=empty, bool toFreqs=false, IntRANK=_1_)
Constructor for unary Tridiagonal.
static const int N_RANK
Reports the class’s rank for example towards DirectProduct.
Definition: Tridiagonal.h:109
Calculates the power @ compile time.
Definition: TMP_Tools.h:75
const Tridiagonal operator+() const
Returns a (deep) copy.
Definition: Tridiagonal.h:274
Defines class of the same name.
const Tridiagonal< RANK1+RANK2 > operator*(const Tridiagonal< RANK1 > &t1, const Tridiagonal< RANK2 > &t2)
Direct product.
Definition: Tridiagonal.h:338
Tridiagonal & operator*=(double d)
Definition: Tridiagonal.h:244
const Tridiagonal< RANK > tridiagPlusHC_overI(const Tridiagonal< RANK > &tridiag)
Returns the anti-Hermitian operator .
Definition: Tridiagonal.h:362
Stores and manipulates dimensions of constructs over composite Hilbert spaces of arbitrary arity...
const Tridiagonal< RANK > tridiagPlusHC(const Tridiagonal< RANK > &tridiag)
Returns the Hermitian operator .
Definition: Tridiagonal.h:355
const dcomp average(const quantumdata::LazyDensityOperator< RANK > &, const typename quantumdata::LazyDensityOperator< RANK >::Idx &, IntRANK=_1_)
Calculates the quantum average of a Tridiagonal in a quantum state described by a (unary) quantumdata...
const Tridiagonal dagger() const
Same as hermitianConjugate.
Definition: Tridiagonal.h:259
Tridiagonal & furnishWithFreqs(const Diagonal &mainDiagonal, IntRANK=_1_)
Furnishes a unary tridiagonal with frequencies calculated from mainDiagonal.
Defines class of the same name.
Common interface for calculating quantum averages.
Tridiagonal & operator-=(const Tridiagonal &tridiag)
Implemented in terms of operator+=.
Definition: Tridiagonal.h:276
Diagonals::T_numtype Diagonal
A unary complex blitz array.
Definition: Tridiagonal.h:113
static const int LENGTH
The number of Diagonals the class has to store.
Definition: Tridiagonal.h:108
Base::Dimensions Dimensions
Inherited from DimensionsBookkeeper.
Definition: Tridiagonal.h:119
Tridiagonal & operator/=(double d)
Definition: Tridiagonal.h:245
Comprises modules representing operators of special structure (tridiagonal, sparse) over Hilbert spac...
Definition: Sigma.h:12
CVector & apply(const CVector &a, CVector &b, const CMatrix &m)
Applies matrix m on a and adds the result to b
std::complex< double > dcomp
Double-precision complex number.
Tridiagonal(const Tridiagonal &tridiag)
Copy constructor with deep-copy semantics.
Definition: Tridiagonal.h:164
ExtTiny< RANK > Dimensions
The dimensions as a static vector of size N_RANK.
Operator aggregate for a complex vector space built on top of Boost.Operator.
Definition: Operators.h:25
Comprises our own extensions to Blitz++.
Defines tentative base classes for the exception classes of the framework.
Class representing a (unary) tridiagonal matrix or direct product of such matrices.
Definition: Tridiagonal.h:103
const Tridiagonal hermitianConjugate() const
Returns a newly constructed object, which is the Hermitian conjugate of this.
Extensions built on top of Boost.Operator.