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
StateVector.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_STATEVECTOR_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_STATEVECTOR_H_INCLUDED
6 
7 #include "StateVectorFwd.h"
8 
9 #include "DensityOperatorFwd.h"
10 
11 #include "ArrayBase.h"
12 #include "DimensionsBookkeeper.h"
13 #include "LazyDensityOperator.h"
14 #include "Types.h"
15 
16 #include "Operators.h"
17 
18 
19 namespace quantumdata {
20 
32 template<int RANK1, int RANK2>
34 inline
35 const StateVector<RANK1+RANK2>
36 operator*(const StateVector<RANK1>&, const StateVector<RANK2>&);
37 
38 
40 template<int RANK>
41 const dcomp
42 braket(const StateVector<RANK>&, const StateVector<RANK>&);
43 
44 
46 
57 template<int RANK>
59  : public LazyDensityOperator<RANK>,
60  private ArrayBase<RANK>,
61  private linalg::VectorSpace<StateVector<RANK> >
62 {
63 public:
64  static const int N_RANK=RANK;
65 
67  typedef ArrayBase <RANK> ABase;
68 
69  typedef typename LDO_Base::Dimensions Dimensions;
70 
71  typedef typename ABase::ArrayLow StateVectorLow;
72 
73  typedef typename Types<RANK>::DensityOperatorLow DensityOperatorLow;
74 
75  typedef typename LDO_Base::Idx Idx;
76 
77  using ABase::vectorView; using ABase::getArray;
78 
80 
81 
88  StateVector(const StateVectorLow& psi, ByReference) : LDO_Base(psi.shape()), ABase(psi) {}
89 
90  explicit StateVector(const Dimensions&, bool init=true);
91 
92  StateVector(const StateVector&);
93 
95 
99  template<int RANK2>
101 
103 
104  StateVector& operator=(const StateVector& sv) {ABase::operator=(sv.getArray()); return *this;}
105 
107 
113  template<typename OTHER>
114  StateVector& operator=(const OTHER& other) {getArray()=other; return *this;}
116 
118 
119  template<typename... SubscriptPack>
120  const dcomp& operator()(int s0, SubscriptPack... subscriptPack) const;
121 
122  template<typename... SubscriptPack>
123  dcomp& operator()(int s0, SubscriptPack... subscriptPack) {return const_cast<dcomp&>(static_cast<const StateVector*>(this)->operator()(s0,subscriptPack...));}
124 
125 
126 
128 
129 
131  double norm() const {return ABase::frobeniusNorm();}
132  double renorm() ;
133 
134 
136 
137 
139  const DensityOperatorLow dyad(const StateVector&) const;
140  const DensityOperatorLow dyad( ) const {return dyad(*this);}
141 
142 
144 
148  void addTo(DensityOperator<RANK>& densityOperator) const;
149 
151 
152  StateVector& operator+=(const StateVector& psi) {ABase::operator+=(psi); return *this;}
153  StateVector& operator-=(const StateVector& psi) {ABase::operator-=(psi); return *this;}
154 
155  const StateVector operator-() const {StateVector res(this->getDimensions(),false); res.getArray()=-this->getArray(); return res;}
156  const StateVector operator+() const {return *this;}
157 
158 
160 
161  template<typename OTHER>
162  StateVector& operator*=(const OTHER& dc) {ABase::operator*=(dc); return *this;}
163 
164  template<typename OTHER>
165  StateVector& operator/=(const OTHER& dc) {ABase::operator/=(dc); return *this;}
167 
168 #ifndef NDEBUG
169  void debug() const {std::cerr<<"Debug: "<<getArray()<<std::endl;}
170 #endif // NDEBUG
171 
172 private:
173  const dcomp index(const Idx& i, const Idx& j) const override {return getArray()(i)*conj(getArray()(j));}
174 
175  double trace_v() const override {return norm();}
176 
177 };
178 
179 
180 template<int RANK1, int RANK2>
181 inline
182 const StateVector<RANK1+RANK2>
183 operator*(const StateVector<RANK1>& t1, const StateVector<RANK2>& t2)
184 {
185  return StateVector<RANK1+RANK2>(t1,t2);
186 }
187 
188 
189 } // quantumdata
190 
191 #endif // CPPQEDCORE_QUANTUMDATA_STATEVECTOR_H_INCLUDED
const DensityOperatorLow dyad() const
dyad with the object itself
Definition: StateVector.h:140
StateVector & operator=(const StateVector &sv)
Assignment with by-value semantics.
Definition: StateVector.h:104
Comprises the common functionalities of StateVector and DensityOperator.
Definition: ArrayBase.h:21
Defines class of the same name.
Basically only a metafunction defining types for higher-level constructs of arity RANK ...
Definition: Types.h:23
ArrayBase & operator=(const ArrayLow &arrayLow)
Assignment with by-value semantics (like the assignment of a blitz::Array).
Definition: ArrayBase.h:35
Comprises classes representing the state of composite quantum systems and providing various interface...
Definition: ArrayBase.h:16
const CVector vectorView() const
1d view created on the fly via blitzplusplus::unaryArray.
Definition: ArrayBase.h:66
Density operator of arbitrary arity.
StateVector & operator=(const OTHER &other)
Mixed-mode assignment with by-value semantics.
Definition: StateVector.h:114
State vector of arbitrary arity.
Definition: StateVector.h:58
IdxTiny< RANK > Idx
The type used for indexing the “rows” and the “columns”: a tiny vector of integers (multi-index) ...
const StateVector operator-() const
involves a deep-copy
Definition: StateVector.h:155
Defines class of the same name.
Defines class of the same name.
const dcomp & operator()(int s0, SubscriptPack...subscriptPack) const
Multi-array style subscription.
double frobeniusNorm() const
The entrywise array norm.
Definition: ArrayBase.h:76
const dcomp braket(const StateVector< RANK > &, const StateVector< RANK > &)
Calculates the inner product, relying on StateVector::vectorView.
StateVector & operator*=(const OTHER &dc)
Definition: StateVector.h:162
Defines class of the same name.
Common interface for calculating quantum averages.
Base::Dimensions Dimensions
Inherited from DimensionsBookkeeper.
double norm() const
Returns the norm .
Definition: StateVector.h:131
const Dimensions & getDimensions() const
Get the Dimensions vector.
dcomp & operator()(int s0, SubscriptPack...subscriptPack)
Definition: StateVector.h:123
StateVector(const StateVectorLow &psi, ByReference)
Constructs the class in such a way that the underlying data reference the same data as psi...
Definition: StateVector.h:88
std::complex< double > dcomp
Double-precision complex number.
void addTo(DensityOperator< RANK > &densityOperator) const
Adds a dyad of the present object to densityOperator
Operator aggregate for a complex vector space built on top of Boost.Operator.
Definition: Operators.h:25
CArray< RANK > ArrayLow
The underlying storage.
Definition: ArrayBase.h:24
double renorm()
” and also renormalises
const StateVector operator+() const
simply deep copy
Definition: StateVector.h:156
Extensions built on top of Boost.Operator.