OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FStaticFP.h
Go to the documentation of this file.
1 #ifndef MAD_FStaticFP_HH
2 #define MAD_FStaticFP_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: FStaticFP.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.2.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: FStaticFP
13 //
14 // ------------------------------------------------------------------------
15 // Class category: FixedAlgebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2003/11/07 18:03:01 $
19 // $Author: dbruhwil $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "FixedAlgebra/FVps.h"
24 #include <cmath>
25 
26 
27 // Class FStaticFP
28 // ------------------------------------------------------------------------
30 
31 template <int N>
32 class FStaticFP {
33 
34 public:
35 
37  // Find fixed point for [b]map[/b].
38  FStaticFP(const FVps<double, N> &map);
39 
40  FStaticFP();
41  FStaticFP(const FStaticFP &rhs);
42  ~FStaticFP();
43 
45  const FVps<double, N> &getDispersion() const;
46 
48  const FVps<double, N> &getFixedPoint() const;
49 
51  const FVps<double, N> &getFixedPointMap() const;
52 
53 private:
54 
55  // Not implemented.
56  void operator=(const FStaticFP &);
57 
58  // Fixed point position.
60 
61  // Map around the fixed point.
63 };
64 
65 
66 #include "FixedAlgebra/FMatrix.h"
67 #include "FixedAlgebra/FLUMatrix.h"
68 #include "FixedAlgebra/FMonomial.h"
69 #include "FixedAlgebra/FTps.h"
70 #include "FixedAlgebra/FVector.h"
71 
72 
73 // Class FStaticFP
74 // ------------------------------------------------------------------------
75 
76 template <int N>
78  fixedPoint(), fixedPointMap()
79 {}
80 
81 
82 template <int N>
84  fixedPoint(fp.fixedPoint), fixedPointMap(fp.fixedPointMap)
85 {}
86 
87 
88 template <int N>
90  fixedPoint(), fixedPointMap() {
91  //std::cerr << "==> In FStaticFP<N>::FStaticFP(const FVps<double,N> &map)..." << std::endl;
92  const int nFree = 4;
94  FVector<double, N> fixPoint;
95 
96  // Find fixed point;
97  // tempMap will become the map around the fixed point.
98  FVps<double, N> tempMap(map);
99 
100  // Determine fixPoint of map T by iterating the contraction map
101  // z_{n+1} = z_n - (M(z_n) - I)^{-1} . (T(z_n) - z_n)
102  // Here M(z_n) is the matrix part of T(z_n + z); and the iterating atarts at z_0 = 0.
103  if(tempMap.getMinOrder() == 0) {
104  while(true) {
105  // Get system of equations for fixed point.
106  FMatrix<double, N, N> A = tempMap.linearTerms();
107  FVector<double, N> Error = tempMap.constantTerm();
108  double error = 0.0;
109 
110  // Form (A - I).
111  for(int i = 0; i < nFree; i++) {
112  A(i, i) -= 1.0;
113  if(std::abs(Error(i)) > error) error = std::abs(Error(i));
114  }
115  for(int i = nFree; i < N; i++) {
116  for(int j = 0; j < N; j++) A(i, j) = A(j, i) = 0.0;
117  A(i, i) = 1.0;
118  Error(i) = 0.0;
119  }
120 
121  // Correct the fixed point.
122  lu = FLUMatrix<double, N>(A);
123  lu.backSubstitute(Error);
124  fixPoint -= Error;
125 
126  // Test for convergence.
127  static const double tol = 1.0e-10;
128  if(error < tol) break;
129 
130  // Build map around fixed point found so far.
131  // (Note that inside this while loop fixedPoint == Identity.)
132  tempMap = map.substitute(fixPoint + fixedPoint) - fixPoint;
133  }
134  } else {
135  // Force computation of lu.
136  FMatrix<double, N, N> A = tempMap.linearTerms();
137  for(int i = 0; i < nFree; i++) A(i, i) -= 1.0;
138  for(int i = nFree; i < N; i++) {
139  for(int j = 0; j < N; j++) A(i, j) = A(j, i) = 0.0;
140  A(i, i) = 1.0;
141  }
142  lu = FLUMatrix<double, N>(A);
143  }
144 
145  // Fixed point map for orders one and higher in delta (dispersion).
147  for(int limit = 1; limit <= map.getMaxOrder(); limit++) {
148  // Remove pure delta terms.
149  FVps<double, N> Q = tempMap.substitute(fixedPoint) -
151  FMonomial<N> delta;
152  delta[nFree+1] = limit;
153  FVector<double, N> Error;
154  for(int i = 0; i < nFree; i++) {
155  fixedPointMap[i] += Q[i].filter(limit, limit);
156  Error(i) = Q[i].getCoefficient(delta);
157  fixedPointMap[i].setCoefficient(delta, 0.0);
158  }
159 
160  lu.backSubstitute(Error);
161 
162  for(int i = 0; i < nFree; i += 2) {
163  // Effect on orbit.
164  fixedPoint[i].setCoefficient(delta, - Error(i));
165  fixedPoint[i+1].setCoefficient(delta, - Error(i + 1));
166 
167  // Orbit terms acting on path length difference.
168  FMonomial<N> powers;
169  powers[nFree+1] = limit - 1;
170  powers[i] = 1;
171  fixedPoint[nFree].setCoefficient(powers, double(limit) * Error(i + 1));
172  powers[i] = 0;
173  powers[i+1] = 1;
174  fixedPoint[nFree].setCoefficient(powers, - double(limit) * Error(i));
175  powers[i+1] = 0;
176  }
177 
178  // Path length term in delta^limit.
179  fixedPoint[nFree].setCoefficient(delta, Q[nFree].getCoefficient(delta));
180  }
181 
182  // Fill in path length terms and identity for delta(p)/p.
183  fixedPointMap[nFree+1] = FTps<double, N>::makeVariable(nFree + 1);
184  fixedPointMap[nFree] =
186 
187  // Combine fixed point and dispersion.
188  fixedPoint += fixPoint;
189  //std::cerr << "Leaving FStaticFP<N>::FStaticFP(...)" << std::endl;
190 }
191 
192 
193 template <int N>
195 {}
196 
197 
198 template <int N>
200  return fixedPoint;
201 }
202 
203 
204 template <int N>
206  return fixedPointMap;
207 }
208 
209 #endif // MAD_FStaticFP_HH
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
FVps< double, N > fixedPointMap
Definition: FStaticFP.h:62
Static fixed point of a Truncated power series map.
Definition: FStaticFP.h:32
Representation of the exponents for a monomial with fixed dimension.
Definition: FMonomial.h:32
~FStaticFP()
Definition: FStaticFP.h:194
const FVps< double, N > & getFixedPoint() const
Get the transformation to the fixed point.
Definition: FStaticFP.h:199
void setTruncOrder(int order)
Set truncation order for all components.
Definition: FVps.hpp:217
void operator=(const FStaticFP &)
A templated representation of a LU-decomposition.
Definition: FLUMatrix.h:42
FVector< T, N > constantTerm() const
Extract the constant part of the map.
Definition: FVps.hpp:540
const FVps< double, N > & getFixedPointMap() const
Get the map around the fixed point.
Definition: FStaticFP.h:205
FVps inverse(int trunc=(FTps< T, N >::EXACT)) const
Inverse.
Definition: FVps.hpp:360
void backSubstitute(FVector< T, N > &B) const
Back substitution.
Definition: FLUMatrix.h:222
FVps< double, N > fixedPoint
Definition: FStaticFP.h:59
FVps filter(int minOrder, int maxOrder, int trcOrder=(FTps< T, N >::EXACT)) const
Extract given range of orders, with truncation.
Definition: FVps.hpp:223
FMatrix< T, N, N > linearTerms() const
Extract the linear part of the map.
Definition: FVps.hpp:561
int getMaxOrder() const
Get highest order contained in any component.
Definition: FVps.hpp:181
FStaticFP()
Definition: FStaticFP.h:77
FVps substitute(const FMatrix< T, N, N > &M, int n) const
Substitute.
Definition: FVps.hpp:608
const FVps< double, N > & getDispersion() const
Get the dispersion map.
int getMinOrder() const
Get lowest order contained in any component.
Definition: FVps.hpp:165
static FTps makeVariable(int var)
Make variable.
Definition: FTps.hpp:481