OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
LieMap.h
Go to the documentation of this file.
1 #ifndef CLASSIC_LieMap_HH
2 #define CLASSIC_LieMap_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: LieMap.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.2.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: LieMap
13 //
14 // ------------------------------------------------------------------------
15 // Class category: Algebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2004/11/18 22:18:05 $
19 // $Author: jsberg $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "Algebra/Matrix.h"
24 #include "Algebra/Vector.h"
25 #include "Algebra/Tps.h"
26 #include "Algebra/TpsData.h"
27 #include "Algebra/VpsInvMap.h"
29 #include "Utilities/LogicalError.h"
30 #include <iosfwd>
31 
32 
33 // Template class LieMap<T>
34 // ------------------------------------------------------------------------
36 // LieMap<T> is a truncated Taylor series map with coefficients of type
37 // [b]T[/b]. It implements operations available only for symplectic maps.
38 
39 template <class T>
40 class LieMap: public VpsInvMap<T> {
41 
42 public:
43 
45  // Construct identity with [b]nDim[/b] variables.
46  LieMap(int nDim);
47 
49  // Construct a map from the matrix [b]M[/b], which should be symplectic.
50  LieMap(const Matrix<T> &M);
51 
53  // Construct an identity map with a displacement vector [b]V[/b].
54  LieMap(const Vector<T> &V);
55 
57  // Convert possibly non-symplectic map.
58  LieMap(const Vps<T> &rhs);
59 
60  LieMap();
61  LieMap(const LieMap<T> &rhs);
62  ~LieMap();
63  LieMap<T> &operator=(const LieMap<T> &);
64 
66  void check() const;
67 
69  // Build the exponential series exp(:H:)Z from the Tps<T> H,
70  // acting on the identity map [b]Z[/b].
71  static LieMap<T> ExpMap(const Tps<T> &H);
72 
74  // Build the exponential series exp(:H:)M from the Tps<T> H,
75  // acting on the map M.
76  static LieMap<T> ExpMap(const Tps<T> &H, const LieMap<T> &M);
77 
78 private:
79 
80  // The iteration limit for Lie series convergence.
81  static const int MAXITER = 100;
82 };
83 
84 
85 // Operations on Vps<T>.
86 // ------------------------------------------------------------------------
87 
89 template <class T>
90 Tps<T> PoissonBracket(const Tps<T> &x, const Tps<T> &y);
91 
93 template <class T>
94 Vps<T> PoissonBracket(const Tps<T> &x, const Vps<T> &y);
95 
97 template <class T>
98 std::istream &operator>>(std::istream &, LieMap<T> &x);
99 
101 template <class T>
102 std::ostream &operator<<(std::ostream &, const LieMap<T> &x);
103 
104 
105 // Implementation of global functions for class LieMap<T>.
106 // ------------------------------------------------------------------------
107 
108 template <class T>
110 {}
111 
112 
113 template <class T>
114 LieMap<T>::LieMap(int nDim): VpsInvMap<T>(nDim) {
115  check();
116 }
117 
118 
119 template <class T>
121 {}
122 
123 
124 template <class T>
126 {}
127 
128 
129 template <class T>
131 {}
132 
133 
134 template <class T>
136  VpsInvMap<T>(rhs) {
137  check();
138 }
139 
140 
141 template <class T> inline
143 {}
144 
145 
146 template <class T> inline
149  return *this;
150 }
151 
152 
153 template <class T>
154 Tps<T> PoissonBracket(const Tps<T> &x, const Tps<T> &y) {
155  Tps<T> z;
156  int nDim = x.getDimension();
157 
158  for(int q = 0; q < nDim; q += 2) {
159  int p = q + 1;
160  z += x.derivative(q) * y.derivative(p) - x.derivative(p) * y.derivative(q);
161  }
162 
163  return z;
164 }
165 
166 
167 template <class T>
168 Vps<T> PoissonBracket(const Tps<T> &x, const Vps<T> &y) {
169  Vps<T> z;
170  int nDim = x.getDimension();
171 
172  for(int q = 0; q < nDim; q += 2) {
173  int p = q + 1;
174  z += x.derivative(q) * y.derivative(p) - x.derivative(p) * y.derivative(q);
175  }
176 
177  return z;
178 }
179 
180 
181 template <class T>
184 }
185 
186 
187 template <class T>
189  int nDim = H.getVariables();
190  if(nDim % 2 != 0) {
191  throw LogicalError("LieMap::ExpMap()", "Tps dimension is zero or odd.");
192  }
193  if(nDim == 0) return M;
194  if(nDim != M.getVariables()) {
195  throw LogicalError
196  ("LieMap::ExpMap()",
197  "Lie map and Hamiltonian have inconsistent dimensions.");
198  }
199 
200  LieMap<T> temp(nDim);
201  Vps<T> dH(nDim, nDim);
202 
203  for(int i = 0; i < nDim; i += 2) {
204  dH[i] = - H.derivative(i + 1);
205  dH[i+1] = H.derivative(i);
206  }
207 
208  for(int var = 0; var < nDim; var++) {
209  Tps<T> old = 0.0;
210  Tps<T> u = temp[var] = M[var];
211 
212  for(int count = 1; temp[var] != old; count++) {
213  if(count >= MAXITER) {
214  throw ConvergenceError("LieMap::ExpMap()",
215  "No convergence in ExpMap()");
216  }
217 
218  Tps<T> w = 0.0;
219  for(int v = 0; v < nDim; v++) w += dH[v] * u.derivative(v);
220  u = w / T(count);
221  old = temp[var];
222  temp[var] += u;
223  }
224  }
225 
226  return temp;
227 }
228 
229 
230 template <class T>
231 std::istream &operator>>(std::istream &is, LieMap<T> &x)
232 { return x.get(is); }
233 
234 
235 template <class T>
236 std::ostream &operator<<(std::ostream &os, const LieMap<T> &x)
237 { return x.put(os); }
238 
239 
240 template <class T>
241 void LieMap<T>::check() const {
243 
244  if(this->getDimension() % 2 != 0) {
245  throw LogicalError("LieMap::check()", "LieMap representation corrupted.");
246  }
247 }
248 
249 #endif // CLASSIC_LieMap_HH
LieMap()
Definition: LieMap.h:109
Definition: rbendmap.h:8
static LieMap< T > ExpMap(const Tps< T > &H)
Lie series.
Definition: LieMap.h:182
std::istream & get(std::istream &is)
Get a Vps&lt;T&gt; from stream is.
Definition: Vps.hpp:213
int getVariables() const
Get number of variables (the same in all components).
Definition: Vps.hpp:279
Invertible power series map.
Definition: VpsInvMap.h:40
Tps< T > PoissonBracket(const Tps< T > &x, const Tps< T > &y)
Poisson bracket.
Definition: LieMap.h:154
Lie algebraic map.
Definition: LieMap.h:40
Truncated power series.
Definition: Tps.h:27
Convergence error exception.
FVps< T, N > ExpMap(const FTps< T, N > &H, int trunc=FTps< T, N >::EXACT)
Build the exponential series.
Definition: FTps.hpp:1994
static const int MAXITER
Definition: LieMap.h:81
int getVariables() const
Get number of variables.
Definition: Tps.hpp:1043
void check() const
Check consistency.
Definition: LieMap.h:241
Vector truncated power series.
Definition: Vps.h:24
VpsInvMap< T > & operator=(const VpsInvMap< T > &y)
Definition: VpsInvMap.h:280
Matrix.
Definition: Matrix.h:38
Vector.
void check() const
Check consistency.
Definition: VpsInvMap.h:287
LieMap< T > & operator=(const LieMap< T > &)
Definition: LieMap.h:147
~LieMap()
Definition: LieMap.h:142
Tps< T > derivative(int var) const
Partial derivative.
Definition: Tps.hpp:920
Logical error exception.
Definition: LogicalError.h:33
std::istream & operator>>(std::istream &, LieMap< T > &x)
Extract LieMap&lt;T&gt; from stream.
Definition: LieMap.h:231