OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
VpsInvMap.h
Go to the documentation of this file.
1 #ifndef CLASSIC_VpsInvMap_HH
2 #define CLASSIC_VpsInvMap_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: VpsInvMap.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1.2.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: VpsInvMap
13 //
14 // ------------------------------------------------------------------------
15 // Class category: Algebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2004/11/18 22:18:06 $
19 // $Author: jsberg $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "Algebra/LUMatrix.h"
24 #include "Algebra/Matrix.h"
25 #include "Algebra/Vector.h"
26 #include "Algebra/VpsInvMap.h"
27 #include "Algebra/Tps.h"
28 #include "Algebra/VpsMap.h"
29 #include "Utilities/LogicalError.h"
30 #include <iosfwd>
31 
32 
33 // Class VpsInvMap
34 // ------------------------------------------------------------------------
36 // An invertible truncated power series map.
37 // The number of variables and the dimension are equal.
38 
39 template <class T>
40 class VpsInvMap: public VpsMap<T> {
41 
42 public:
43 
45  // Construct identity in [b]nDim[/b] variables.
46  VpsInvMap(int nDim);
47 
49  // Throw SizeError if [b]rhs[/b] is not R**n --> R**n.
50  VpsInvMap(const VpsMap<T> &rhs);
51 
53  // Throw SizeError if [b]rhs[/b] is not R**n --> R**n.
54  VpsInvMap(const Vps<T> &rhs);
55 
57  // Construct map of dimension [b]nDim[/b] and fill from [b]rhs[/b].
58  VpsInvMap(int nDim, const Tps<T> rhs[]);
59 
61  // The constant terms are zero.
62  // The linear terms are taken from [b]M[/b].
63  // Throw SizeError if [b]M[/b] is not square.
64  VpsInvMap(const Matrix<T> &M);
65 
67  // The constant terms are taken from [b]V[/b].
68  // The linear terms are the identity map.
69  VpsInvMap(const Vector<T> &);
70 
71  VpsInvMap();
72  VpsInvMap(const VpsInvMap<T> &rhs);
73  ~VpsInvMap();
75 
77  void check() const;
78 
80  VpsInvMap<T> inverse() const;
81 
83  static VpsInvMap<T> identity(int nVar);
84 };
85 
86 
87 // ------------------------------------------------------------------------
89 
91 template <class T>
92 VpsInvMap<T> operator*(const VpsInvMap<T> &x, const Tps<T> &y);
93 
95 template <class T>
96 VpsInvMap<T> operator*(const Tps<T> &x, const VpsInvMap<T> &y);
97 
99 template <class T>
100 VpsInvMap<T> operator*(const VpsInvMap<T> &x, const T &y);
101 
103 template <class T>
104 VpsInvMap<T> operator*(const T &x, const VpsInvMap<T> &y);
105 
107 // Throw DivideError, if constant part of [b]y[/b] is zero.
108 template <class T>
109 VpsInvMap<T> operator/(const VpsInvMap<T> &x, const Tps<T> &y);
110 
112 // Throw DivideError, if [b]y[/b] is zero.
113 template <class T>
114 VpsInvMap<T> operator/(const VpsInvMap<T> &x, const T &y);
115 
117 template <class T>
118 VpsInvMap<T> operator+(const VpsInvMap<T> &x, const VpsInvMap<T> &y);
119 
121 template <class T>
122 VpsInvMap<T> operator-(const VpsInvMap<T> &x, const VpsInvMap<T> &y);
123 
125 template <class T>
126 VpsInvMap<T> operator+(const VpsInvMap<T> &x, const Vector<T> &y);
127 
129 template <class T>
130 VpsInvMap<T> operator-(const VpsInvMap<T> &x, const Vector<T> &y);
131 
133 template <class T>
134 VpsInvMap<T> operator+(const Vector<T> &x, const VpsInvMap<T> &y);
135 
137 template <class T>
138 VpsInvMap<T> operator-(const Vector<T> &x, const VpsInvMap<T> &y);
139 
141 template <class T>
142 std::istream &operator>>(std::istream &, VpsInvMap<T> &x);
143 
145 template <class T>
146 std::ostream &operator<<(std::ostream &, const VpsInvMap<T> &x);
147 
149 template <class T> VpsInvMap<T>
150 operator*(const Matrix<T> &x, const VpsInvMap<T> &y);
151 
152 
153 // Implementation of global functions for class Vps<T>.
154 // ------------------------------------------------------------------------
155 
156 template <class T> inline
158 { VpsInvMap<T> z(x); return z *= y; }
159 
160 template <class T> inline
162 { VpsInvMap<T> z(x); return z *= y; }
163 
164 template <class T> inline
166 { VpsInvMap<T> z(x); return z *= y; }
167 
168 template <class T> inline
170 { VpsInvMap<T> z(x); return z *= y; }
171 
172 template <class T> inline
174 { VpsInvMap<T> z(x); return z /= y; }
175 
176 template <class T> inline
178 { VpsInvMap<T> z(x); return z /= y; }
179 
180 
181 template <class T> inline
183 { VpsInvMap<T> z(x); return z += y; }
184 
185 template <class T> inline
187 { VpsInvMap<T> z(x); return z -= y; }
188 
189 template <class T> inline
191 { VpsInvMap<T> z(x); return z += y; }
192 
193 template <class T> inline
195 { VpsInvMap<T> z(x); return z -= y; }
196 
197 template <class T> inline
199 { VpsInvMap<T> z(y); return z += x; }
200 
201 template <class T> inline
203 { VpsInvMap<T> z(- y); return z += x; }
204 
205 template <class T> inline
207 { return y.substituteInto(x); }
208 
209 template <class T> inline
210 std::istream &operator>>(std::istream &is, VpsInvMap<T> &x)
211 { return x.get(is); }
212 
213 template <class T> inline
214 std::ostream &operator<<(std::ostream &os, const VpsInvMap<T> &x)
215 { return x.put(os); }
216 
217 
218 // Class VpsInvMap, implementation.
219 // ------------------------------------------------------------------------
220 
221 template <class T>
223  VpsMap<T>()
224 {}
225 
226 
227 template <class T>
229  VpsMap<T>(nDim, nDim) {
230  for(int i = 0; i < nDim; i++) this->data[i] = Tps<T>::makeVariable(nDim, i);
231 }
232 
233 
234 template <class T>
236  VpsMap<T>(rhs)
237 {}
238 
239 
240 template <class T>
242  VpsMap<T>(rhs)
243 {}
244 
245 
246 template <class T>
248  VpsMap<T>(rhs)
249 {}
250 
251 
252 template <class T>
253 VpsInvMap<T>::VpsInvMap(int nDim, const Tps<T> rhs[]):
254  VpsMap<T>(nDim, rhs) {
255  check();
256 }
257 
258 
259 template <class T>
261  VpsMap<T>(x) {
262  if(x.nrows() != x.ncols()) {
263  throw LogicalError("VpsInvMap::VpsInvMap()", "Matrix is not n by n.");
264  }
265 }
266 
267 
268 template <class T>
270  VpsMap<T>(x) {
271 }
272 
273 
274 template <class T>
276 }
277 
278 
279 template <class T>
282  return *this;
283 }
284 
285 
286 template <class T>
287 void VpsInvMap<T>::check() const {
288  Vps<T>::check();
289  if(this->getDimension() != this->variables) {
290  throw LogicalError("VpsInvMap::VpsInvMap()", "Map is not n->n.");
291  }
292 }
293 
294 template <class T>
296  // Separate out linear terms and change sign of all other terms:
297  // M := A(1), the linear part of map A,
298  // map1 := - (A - A(1)).
299  check();
300  Vector<T> vec = this->constantTerm();
301  LUMatrix<T> lu(this->linearTerms());
302  Matrix<T> mat(lu.inverse());
303  VpsInvMap<T> map1 = - this->filter(2, Tps<T>::EXACT);
304 
305  // Initialize map B = M**(-1) (with truncation at maxOrder).
306  VpsInvMap<T> B(mat);
307  B -= mat * vec;
308 
309  // Compute inverse order by order.
310  for(int maxOrder = 2; maxOrder <= this->getTruncOrder(); maxOrder++) {
311  VpsInvMap<T> map2 = map1.substitute(B, maxOrder);
312  B = mat * (map2 + identity(this->variables) - vec);
313  }
314 
315  return VpsInvMap<T>(B);
316 }
317 
318 
319 template <class T>
321  return VpsInvMap<T>(nDim);
322 }
323 
324 #endif // CLASSIC_VpsInvMap_HH
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
Definition: Matrix.h:275
Matrix< T > operator/(const Matrix< T > &, const T &)
Matrix divided by scalar.
Definition: Matrix.h:329
Triangle decomposition of a matrix.
Definition: LUMatrix.h:44
Definition: rbendmap.h:8
Truncate power series map.
Definition: Tps.h:31
int ncols() const
Get number of columns.
Definition: Array2D.h:307
Matrix< T > operator*(const Matrix< T > &, const Matrix< T > &)
Matrix multiply.
Definition: Matrix.h:297
VpsMap< T > & operator=(const VpsMap< T > &y)
Definition: VpsMap.h:214
std::istream & get(std::istream &is)
Get a Vps&lt;T&gt; from stream is.
Definition: Vps.hpp:213
Invertible power series map.
Definition: VpsInvMap.h:40
VpsInvMap< T > inverse() const
Inverse.
Definition: VpsInvMap.h:295
Truncated power series.
Definition: Tps.h:27
~VpsInvMap()
Definition: VpsInvMap.h:275
Matrix< T > inverse() const
Get inverse.
Definition: LUMatrix.h:251
Definition: Vec.h:21
VpsMap< T > substituteInto(const Matrix< T > &x) const
Substitute.
Definition: VpsMap.h:371
Vector truncated power series.
Definition: Vps.h:24
VpsInvMap< T > & operator=(const VpsInvMap< T > &y)
Definition: VpsInvMap.h:280
static VpsInvMap< T > identity(int nVar)
Set to identity.
Definition: VpsInvMap.h:320
Matrix.
Definition: Matrix.h:38
void check() const
Check consistency.
Definition: Vps.hpp:108
Matrix< T > operator-(const Matrix< T > &, const Matrix< T > &)
Matrix subtraction.
Definition: Matrix.h:282
Vector.
void check() const
Check consistency.
Definition: VpsInvMap.h:287
int nrows() const
Get number of rows.
Definition: Array2D.h:301
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
Array1D< Tps< T > > data
Definition: Vps.h:143