C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
NonOrthogonalStateVector.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_NONORTHOGONALSTATEVECTOR_H_INCLUDED
5 #define CPPQEDCORE_QUANTUMDATA_NONORTHOGONALSTATEVECTOR_H_INCLUDED
6 
7 #include "NonOrthogonalStateVectorFwd.h"
9 
10 #include "StateVector.h"
11 #include "Transformation.h"
12 
13 
14 
15 namespace quantumdata {
16 
17 template<int RANK, typename TRAFO>
19  public StateVector<RANK>,
20  private linalg::VectorSpace<NonOrthogonalStateVector<RANK, TRAFO> >
21 {
22 public:
23  typedef StateVector<RANK> Base;
24 
25  typedef typename Base::Dimensions Dimensions;
26  typedef typename Base::StateVectorLow StateVectorLow;
27  typedef typename Base::DensityOperatorLow DensityOperatorLow;
28 
29  typedef typename Base::Idx Idx;
30 
31  typedef TRAFO Trafo;
32  typedef transformation::Traits<Trafo> TrafoTraits;
33 
34  using Base::operator(); using Base::vectorView; using Base::getTotalDimension;
35 
36  explicit NonOrthogonalStateVector(const StateVectorLow& psi, const Trafo& tf, ByReference)
37  : Base(psi,byReference), dual_(psi.shape()), transformation_(tf){}
38 
39  explicit NonOrthogonalStateVector(const Dimensions& dimensions,
40  const Trafo& tf, bool init=true)
41  : Base(dimensions, init), dual_(dimensions), transformation_(tf){}
42 
44  : Base(sv), dual_(sv().shape()),
45  transformation_(sv.getTrafo()){}
46 
47  double norm() const;
48 
49  void update() const;
50 
51  const StateVectorLow& dual() const {return dual_;};
52  const Trafo& getTrafo() const {return transformation_;}
53 
54  template<typename OTHER>
55  NonOrthogonalStateVector& operator=(const OTHER& other) {operator()()=other; return *this;}
56 
57  // naive operations for vector space
58 
59  NonOrthogonalStateVector& operator+=(const NonOrthogonalStateVector& psi) {Base::operator+=(psi); return *this;}
60  NonOrthogonalStateVector& operator-=(const NonOrthogonalStateVector& psi) {Base::operator-=(psi); return *this;}
61 
62  const NonOrthogonalStateVector operator-() const {return NonOrthogonalStateVector(-operator()());}
63  const NonOrthogonalStateVector operator+() const {return *this;} // deep copy
64 
65  template<typename OTHER>
66  NonOrthogonalStateVector& operator*=(const OTHER& dc) {Base::operator*=(dc); return *this;}
67 
68  template<typename OTHER>
69  NonOrthogonalStateVector& operator/=(const OTHER& dc) {Base::operator/=(dc); return *this;}
70 
71  void addTo(NonOrthogonalDensityOperator<RANK>&) const;
72 
73 private:
74  mutable StateVectorLow dual_;
75 
76  const Trafo transformation_;
77 
78 };
79 
80 
81 
82 template<typename SV1, typename SV2>
83 struct TensorType : mpl::identity<NonOrthogonalStateVector<SV1::N_RANK+SV2::N_RANK,
84  typename transformation::Compose<typename SV1::Trafo,
85  typename SV2::Trafo>::type> >
86 {
87 };
88 
89 
91 template<typename SV1, int RANK2>
92 struct TensorType<SV1,StateVector<RANK2> >
93  : mpl::identity<NonOrthogonalStateVector<SV1::N_RANK+RANK2,
94  typename transformation::Compose<typename SV1::Trafo,
95  transformation::Identity<RANK2> >::type> >
96 {
97 };
98 
99 
100 template<int RANK1, typename SV2>
101 struct TensorType<StateVector<RANK1>,SV2>
102  : mpl::identity<NonOrthogonalStateVector<RANK1+SV2::N_RANK,
103  typename transformation::Compose<transformation::Identity<RANK1>,
104  typename SV2::Trafo>::type> >
105 {
106 };
111 #define RETURN_typeKERNEL transformation::Compose<TRAFO1,TRAFO2>
112 #define RETURN_type NonOrthogonalStateVector<RANK1+RANK2,typename RETURN_typeKERNEL::type>
113 
114 
115 template<int RANK1, typename TRAFO1, int RANK2, typename TRAFO2>
116 inline
117 const RETURN_type
118 operator*(const NonOrthogonalStateVector<RANK1,TRAFO1>& sv1, const NonOrthogonalStateVector<RANK2,TRAFO2>& sv2)
119 {
120  using namespace blitzplusplus;
121  return RETURN_type(doDirect<dodirect::multiplication>(sv1(),sv2()),RETURN_typeKERNEL::compose(sv1.getTrafo(),sv2.getTrafo()),byReference);
122 }
123 
124 #undef RETURN_typeKERNEL
125 
126 #define RETURN_typeKERNEL transformation::Compose<TRAFO1,transformation::Identity<RANK2> >
127 
128 template<int RANK1, typename TRAFO1, int RANK2>
129 inline
130 const RETURN_type
131 operator*(const NonOrthogonalStateVector<RANK1,TRAFO1>& sv1, const StateVector<RANK2>& sv2)
132 {
133  using namespace blitzplusplus;
134  return RETURN_type(doDirect<dodirect::multiplication>(sv1(),sv2()),RETURN_typeKERNEL::compose(sv1.getTrafo(),transformation::Identity<RANK2>()),byReference);
135 }
136 
137 #undef RETURN_typeKERNEL
138 
139 #define RETURN_typeKERNEL transformation::Compose<transformation::Identity<RANK1>,TRAFO2>
140 
141 template<int RANK1, int RANK2, typename TRAFO2>
142 inline
143 const RETURN_type
144 operator*(const StateVector<RANK1>& sv1, const NonOrthogonalStateVector<RANK2,TRAFO2>& sv2)
145 {
146  using namespace blitzplusplus;
147  return RETURN_type(doDirect<dodirect::multiplication>(sv1(),sv2()),RETURN_typeKERNEL::compose(transformation::Identity<RANK1>(),sv2.getTrafo()),byReference);
148 }
149 
150 #undef RETURN_type
151 #undef RETURN_typeKERNEL
152 
153 
154 } // quantumdata
155 
156 #endif // CPPQEDCORE_QUANTUMDATA_NONORTHOGONALSTATEVECTOR_H_INCLUDED
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
quantumdata::StateVector< 1 > StateVector
unary StateVector
Definition: Free.h:39
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 dcomp & operator()(int s0, SubscriptPack...subscriptPack) const
Multi-array style subscription.
StateVector & operator*=(const OTHER &dc)
Definition: StateVector.h:162
Defines class of the same name.
Base::Dimensions Dimensions
Inherited from DimensionsBookkeeper.
Defines class of the same name.
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++.
size_t getTotalDimension() const
Get the total dimension of a system of arbitrary arity.