C++QEDCore  v2 Milestone 10
a framework for simulating open quantum dynamics – core
EnsembleMCWF.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_QUANTUMTRAJECTORY_ENSEMBLEMCWF_H_INCLUDED
4 #define CPPQEDCORE_QUANTUMTRAJECTORY_ENSEMBLEMCWF_H_INCLUDED
5 
6 #include "EnsembleMCWFFwd.h"
7 
8 #include "DO_Display.h"
9 #include "MCWF_Trajectory.h"
10 #include "DensityOperator.h"
11 
12 #include "Conversions.h"
13 #include "SmartPtr.h"
14 
15 
16 namespace quantumtrajectory {
17 
18 
19 namespace ensemble {
20 
21 using namespace mcwf;
22 
23 #define STATE_VECTORS(r) boost::ptr_vector<quantumdata::StateVector<r> >
24 
25 #define BASE_class trajectory::Ensemble< quantumdata::DensityOperator<RANK>&, const quantumdata::StateVector<RANK>& >
26 
28 template<int RANK>
29 class Base
30  : private boost::base_from_member<STATE_VECTORS(RANK) >,
31  public BASE_class
32 {
33 private:
34  typedef STATE_VECTORS(RANK) StateVectors;
35 
36 #undef STATE_VECTORS
37 
38 protected:
39  typedef BASE_class Ensemble;
40 
41 #undef BASE_class
42 
43 private:
44  typedef typename Ensemble::Impl Trajectories;
45 
46  typedef boost::base_from_member<StateVectors> StateVectorsBase;
47 
49 
50 public:
51  typedef typename Single::StateVector StateVector ;
52  typedef typename Single::StateVectorLow StateVectorLow;
53 
54  typedef typename structure::QuantumSystem<RANK>::Ptr QuantumSystemPtr;
55 
56 protected:
58  Base(
59  const StateVector& psi,
60  QuantumSystemPtr sys,
61  const Pars& p,
62  const StateVectorLow& =StateVectorLow()
63  );
64 
65  const QuantumSystemPtr getQS() const {return qs_;}
66 
67 private:
68  virtual std::ostream& logOnEnd_v(std::ostream& os) const final;
69 
70  // static helpers to constructor
71  static std::auto_ptr<StateVectors> stateVectors(const StateVector& psi, size_t nTraj);
72  static std::auto_ptr<Trajectories> trajectories(StateVectors& psis, QuantumSystemPtr qs, const Pars& p, const StateVectorLow& scaleAbs);
73 
74 
75  virtual quantumdata::DensityOperator<RANK>& getInitializedDensityOperator_v() const final {rho_=0; return rho_;}
76 
78 
79  const QuantumSystemPtr qs_;
80 
81  const size_t nBins_, nJumpsPerBin_;
82 
83 };
84 
85 } // ensemble
86 
87 
89 
108 template<int RANK, typename V>
109 class EnsembleMCWF : public ensemble::Base<RANK>
110 {
111 private:
112  typedef ensemble::Base<RANK> Base;
113 
115 
116 public:
117  typedef typename Base::StateVectorLow StateVectorLow;
118 
119  typedef typename Base::Ensemble Ensemble;
120 
121  typedef typename Base :: StateVector StateVector;
123 
125 
126  template<typename SYS>
128  const StateVector& psi,
129  const SYS& sys,
130  const mcwf::Pars& p,
131  bool negativity,
132  const StateVectorLow& scaleAbs=StateVectorLow()
133  )
134  : Base(psi,cpputils::sharedPointerize(sys),p,scaleAbs), doDisplay_(structure::qsa<RANK>(this->getQS()),negativity) {}
135 
136 private:
137  virtual std::ostream& display_v (std::ostream& os, int precision) const final {return doDisplay_.display (this->getTime(),this->toBeAveraged(),os,precision);}
138  virtual std::ostream& displayKey_v(std::ostream& os, size_t& i ) const final {return doDisplay_.displayKey(os,i);}
139 
140  const DO_Display doDisplay_;
141 
142 };
143 
144 
145 } // quantumtrajectory
146 
149 namespace trajectory { namespace ensemble {
150 
151 
152 template<int RANK>
153 class Base<quantumdata::DensityOperator<RANK>&>
154 {
155 public:
156  quantumdata::DensityOperator<RANK>& getInitializedDensityOperator() const {return getInitializedDensityOperator_v();}
157 
158 private:
159  virtual quantumdata::DensityOperator<RANK>& getInitializedDensityOperator_v() const = 0;
160 
161 };
162 
163 
164 template<int RANK>
165 class Traits<quantumdata::DensityOperator<RANK>&, const quantumdata::StateVector<RANK>&>
166 {
167 public:
168  typedef Ensemble<quantumdata::DensityOperator<RANK>&, const quantumdata::StateVector<RANK>&> EnsembleType;
169 
170  typedef typename EnsembleType::Elem Elem ;
171  typedef typename EnsembleType::Impl Impl ;
172  typedef typename EnsembleType::ToBeAveragedType ToBeAveragedType;
173 
175  static const ToBeAveragedType averageInRange(typename Impl::const_iterator begin, typename Impl::const_iterator end, const EnsembleType& et)
176  {
177  ToBeAveragedType res(et.getInitializedDensityOperator());
178 
179  for (auto i=begin; i!=end; i++) i->toBeAveraged().addTo(res);
180 
181  return res/=size2Double(end-begin);
182 
183  }
184 
185 
186 };
187 
188 
189 } } // trajectory::ensemble
190 
193 #endif // CPPQEDCORE_QUANTUMTRAJECTORY_ENSEMBLEMCWF_H_INCLUDED
Defines display_densityoperator::_.
EnsembleMCWF(const StateVector &psi, const SYS &sys, const mcwf::Pars &p, bool negativity, const StateVectorLow &scaleAbs=StateVectorLow())
Templated constructor with the same idea as Master::Master.
Definition: EnsembleMCWF.h:127
Comprises classes representing the state of composite quantum systems and providing various interface...
Definition: ArrayBase.h:16
The trajectory-bundle.
Namespace comprising otherwise hard-to-classify generic utilities.
Definition: Algorithm.h:10
Density operator of arbitrary arity.
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
quantumdata::Types< 1 >::StateVectorLow StateVectorLow
unary StateVectorLow
Definition: Free.h:34
const boost::shared_ptr< T > sharedPointerize(boost::shared_ptr< T > t)
Part of a bundle of functions providing a unified interface to wrap objects into the shared-pointer i...
Definition: SmartPtr.h:52
quantumdata::StateVector< 1 > StateVector
unary StateVector
Definition: Free.h:39
State vector of arbitrary arity.
Definition: StateVector.h:58
Comprises modules representing trajectory drivers for simulating quantum systems. ...
Definition: DO_Display.h:12
Defines class of the same name.
Comprises modules for describing quantum systems.
Definition: Averaged.h:17
Some converters along the lines of Boost.NumericConversion
Less templatized base for EnsembleMCWF.
Definition: EnsembleMCWF.h:29
Implements a single Monte Carlo wave-function trajectory.
Wraps common functionality of Master & EnsembleMCWF concerning display of quantum averages on the bas...
Definition: DO_Display.h:30
Tools for creating non-owning shared pointers.
quantumdata::DensityOperator< 1 > DensityOperator
unary DensityOperator
Definition: Free.h:40
Derived from trajectory::Ensemble < quantumdata::DensityOperator <RANK>& , const quantumdata::StateVe...
Definition: EnsembleMCWF.h:109
Defines class of the same name.
void addTo(DensityOperator< RANK > &densityOperator) const
Adds a dyad of the present object to densityOperator
Aggregate of parameters pertaining to MCWF simulations.
boost::ptr_vector< Elem > Impl
The storage of the element trajectories is through a pointer-vector