WaveBlocksND
hawp_paramset.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 
5 #include <Eigen/Core>
6 #include <Eigen/Dense>
7 #include <unsupported/Eigen/MatrixFunctions>
8 
9 #include "../types.hpp"
10 #include "../math/continuous_sqrt.hpp"
11 
12 
13 namespace waveblocks {
14  namespace wavepackets {
23  template<dim_t D>
24  struct HaWpParamSet
25  {
26  private:
31 
32  public:
36  : q_(RMatrix<D,1>::Zero())
37  , p_(RMatrix<D,1>::Zero())
38  , Q_(CMatrix<D,D>::Identity())
39  , P_(CMatrix<D,D>::Identity()*complex_t(0,1))
40  , S_(complex_t(0,0))
41  , sqrt_detQ_(1)
42  { }
43 
47  : q_(that.q_)
48  , p_(that.p_)
49  , Q_(that.Q_)
50  , P_(that.P_)
51  , S_(that.S_)
52  , sqrt_detQ_(that.sqrt_detQ_)
53  { }
54 
58  const RMatrix<D,1> &p,
59  const CMatrix<D,D> &Q,
60  const CMatrix<D,D> &P,
61  const complex_t &S)
62  : q_(q)
63  , p_(p)
64  , Q_(Q)
65  , P_(P)
66  , S_(S)
67  , sqrt_detQ_(std::sqrt(Q_.determinant()))
68  { }
69 
70  // Undocumented
72  const RMatrix<D,1> &p,
73  const CMatrix<D,D> &Q,
74  const CMatrix<D,D> &P,
75  const complex_t &S,
77  : q_(q)
78  , p_(p)
79  , Q_(Q)
80  , P_(P)
81  , S_(S)
82  , sqrt_detQ_(sqrt_detQ)
83  { }
84 
88  {
89  q_ = that.q_;
90  p_ = that.p_;
91  Q_ = that.Q_;
92  P_ = that.P_;
93  S_ = that.S_;
94  sqrt_detQ_ = that.sqrt_detQ_;
95  return *this;
96  }
97 
99  inline RMatrix<D,1> const& q() const {return q_;}
100 
102  inline RMatrix<D,1> const& p() const {return p_;}
103 
105  inline CMatrix<D,D> const& Q() const {return Q_;}
106 
108  inline CMatrix<D,D> const& P() const {return P_;}
109 
111  inline complex_t const& S() const {return S_;}
112 
113  // Undocumented
114  inline complex_t const sdQ() const {return sqrt_detQ_();}
115 
116  // Undocumented
117  inline real_t const state() const {return sqrt_detQ_.get_state();}
118 
120  inline void q(const RMatrix<D,1>& qnew) {q_ = qnew;}
121 
123  inline void p(const RMatrix<D,1>& pnew) {p_ = pnew;}
124 
126  inline void Q(const CMatrix<D,D>& Qnew) {Q_ = Qnew; resync();}
127 
129  inline void P(const CMatrix<D,D>& Pnew) {P_ = Pnew;}
130 
132  inline void S(const complex_t& Snew) {S_ = Snew;}
133 
135  inline void updateq(const RMatrix<D,1>& qnew) {q_ += qnew;}
136 
138  inline void updatep(const RMatrix<D,1>& pnew) {p_ += pnew;}
139 
141  inline void updateQ(const CMatrix<D,D>& Qnew) {Q_ += Qnew; resync();}
142 
144  inline void updateP(const CMatrix<D,D>& Pnew) {P_ += Pnew;}
145 
147  inline void updateS(const complex_t& Snew) {S_ += Snew;}
148 
149  /* Undocumented
150  * Compute the continuous square root of \f$ \det Q \f$ after an update
151  * of the \f$ Q \f$ parameter.
152  */
153  inline void resync() {sqrt_detQ_(Q_.determinant());}
154 
162  bool compatible() const
163  {
164  const double tol = 1e-10;
165 
166  CMatrix<D,D> C1 = Q_.adjoint()*P_ - P_.adjoint()*Q_ - CMatrix<D,D>::Identity()*complex_t(0,2);
167  CMatrix<D,D> C2 = Q_.transpose()*P_ - P_.transpose()*Q_;
168 
169  return C1.template lpNorm<1>() < tol && C2.template lpNorm<1>() < tol;
170  }
171 
180  std::pair< RMatrix<D,1>, RMatrix<D,D> >
181  mix(const HaWpParamSet<D>& ket) const
182  {
183  // Mix the parameters
184  CMatrix<D,D> Gbra = P_ * Q_.inverse();
185  CMatrix<D,D> Gket = ket.P_ * ket.Q_.inverse();
186  RMatrix<D,D> G = (Gket - Gbra.adjoint()).imag();
187  RMatrix<D,1> g = (Gket*ket.q_ - Gbra.adjoint()*q_).imag();
188  RMatrix<D,1> q0 = G.inverse() * g;
189  RMatrix<D,D> Q0 = 0.5 * G;
190  // We can not avoid the matrix root
191  RMatrix<D,D> Qs = Q0.sqrt().inverse();
192  return {q0,Qs};
193  }
194  };
195 
196  template<dim_t D>
197  std::ostream &operator<<(std::ostream &out, const HaWpParamSet<D> &parameters)
198  {
199  Eigen::IOFormat CleanFmt(4, 0, ", ", "\n ", "[", "]");
200 
201  out << "HaWpParamSet {\n";
202  out << " q: " << parameters.q().format(CleanFmt) << '\n';
203  out << " p: " << parameters.p().format(CleanFmt) << '\n';
204  out << " Q: " << parameters.Q().format(CleanFmt) << '\n';
205  out << " P: " << parameters.P().format(CleanFmt) << '\n';
206  out << " S: " << parameters.S() << '\n';
207  out << " sqrt(detQ): " << parameters.sdQ() << '\n';
208  out << " compatible(): " << (parameters.compatible() ? "yes" : "no") << '\n';
209  out << "}" << std::endl;
210  return out;
211  }
212  }
213 }
RMatrix< D, 1 > const & p() const
Get the parameter .
Definition: hawp_paramset.hpp:102
complex_t S_
Definition: hawp_paramset.hpp:29
void S(const complex_t &Snew)
Set the parameter .
Definition: hawp_paramset.hpp:132
Definition: coefficients_file_parser.cpp:10
complex_t const & S() const
Get the parameter .
Definition: hawp_paramset.hpp:111
CMatrix< D, D > P_
Definition: hawp_paramset.hpp:28
Eigen::Matrix< real_t, R, C > RMatrix
Definition: types.hpp:22
CMatrix< D, D > Q_
Definition: hawp_paramset.hpp:28
RMatrix< D, 1 > p_
Definition: hawp_paramset.hpp:27
CMatrix< D, D > const & Q() const
Get the parameter .
Definition: hawp_paramset.hpp:105
std::complex< real_t > complex_t
Definition: types.hpp:15
Definition: stdarray2stream.hpp:7
HaWpParamSet()
Definition: hawp_paramset.hpp:35
double real_t
Definition: types.hpp:14
void P(const CMatrix< D, D > &Pnew)
Set the parameter .
Definition: hawp_paramset.hpp:129
std::pair< RMatrix< D, 1 >, RMatrix< D, D > > mix(const HaWpParamSet< D > &ket) const
Definition: hawp_paramset.hpp:181
void updateQ(const CMatrix< D, D > &Qnew)
Update the parameter .
Definition: hawp_paramset.hpp:141
real_t const state() const
Definition: hawp_paramset.hpp:117
This class represents the Hagedorn parameter set .
Definition: hawp_paramset.hpp:24
T get_state(void) const
getter for state state
Definition: continuous_sqrt.hpp:140
RMatrix< D, 1 > q_
Definition: hawp_paramset.hpp:27
CMatrix< D, D > const & P() const
Get the parameter .
Definition: hawp_paramset.hpp:108
RMatrix< D, 1 > const & q() const
Get the parameter .
Definition: hawp_paramset.hpp:99
void updateq(const RMatrix< D, 1 > &qnew)
Update the parameter .
Definition: hawp_paramset.hpp:135
math::ContinuousSqrt< real_t > sqrt_detQ_
Definition: hawp_paramset.hpp:30
void updateP(const CMatrix< D, D > &Pnew)
Update the parameter .
Definition: hawp_paramset.hpp:144
void resync()
Definition: hawp_paramset.hpp:153
HaWpParamSet(const RMatrix< D, 1 > &q, const RMatrix< D, 1 > &p, const CMatrix< D, D > &Q, const CMatrix< D, D > &P, const complex_t &S)
Definition: hawp_paramset.hpp:57
HaWpParamSet & operator=(const HaWpParamSet &that)
Definition: hawp_paramset.hpp:87
Eigen::Matrix< complex_t, R, C > CMatrix
Definition: types.hpp:19
void updatep(const RMatrix< D, 1 > &pnew)
Update the parameter .
Definition: hawp_paramset.hpp:138
void updateS(const complex_t &Snew)
Update the parameter .
Definition: hawp_paramset.hpp:147
complex_t const sdQ() const
Definition: hawp_paramset.hpp:114
HaWpParamSet(const HaWpParamSet &that)
Definition: hawp_paramset.hpp:46
void Q(const CMatrix< D, D > &Qnew)
Set the parameter .
Definition: hawp_paramset.hpp:126
void q(const RMatrix< D, 1 > &qnew)
Set the parameter .
Definition: hawp_paramset.hpp:120
void p(const RMatrix< D, 1 > &pnew)
Set the parameter .
Definition: hawp_paramset.hpp:123
bool compatible() const
Definition: hawp_paramset.hpp:162
HaWpParamSet(const RMatrix< D, 1 > &q, const RMatrix< D, 1 > &p, const CMatrix< D, D > &Q, const CMatrix< D, D > &P, const complex_t &S, math::ContinuousSqrt< real_t > sqrt_detQ)
Definition: hawp_paramset.hpp:71