OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FTps.h
Go to the documentation of this file.
1 #ifndef CLASSIC_FTps_HH
2 #define CLASSIC_FTps_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: FTps.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.4.2.9 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Template class: FTps<T,V>
13 //
14 // ------------------------------------------------------------------------
15 // Class category: FixedAlgebra
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2003/11/07 18:06:20 $
19 // $Author: dbruhwil $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "FixedAlgebra/FTpsData.h"
24 #include <iosfwd>
25 #include <list>
26 #include <string>
27 
28 struct TpsSubstitution;
29 
30 template <class T> class Array1D;
31 template <class T, int M, int N> class FMatrix;
32 template <int N> class FMonomial;
33 template <class T, int N> class FTpsRep;
34 template <class T, int N> class FVector;
35 template <class T, int N> class FVps;
36 
37 
38 // Template class FTps<T,N>.
39 // ------------------------------------------------------------------------
41 // All divide operations throw DivideError
42 // if the constant part of the divisor is zero.
43 
44 template <class T, int N>
45 class FTps {
46 
47 public:
48 
50  // Constructs zero value.
51  FTps();
52 
54  FTps(const FTps &x);
55 
57  // Define the internal orders.
58  FTps(int minOrder, int maxOrder, int trcOrder);
59 
61  FTps(const T &);
62 
64  FTps(int);
65 
67  ~FTps();
68 
70  FTps &operator=(const FTps &y);
71 
73  FTps &operator=(const T &y);
74 
76  // Return value of the coefficient denoted by the Giorgilli index.
77  // Return zero if index is out of range.
78  const T getCoefficient(int index) const;
79 
81  // Assign value of the coefficient denoted by the Giorgilli index.
82  // Ignore if index is out of range.
83  void setCoefficient(int index, const T &value);
84 
86  // Return value of the coefficient denoted by monomial exponents.
87  // Return zero if monomial order lies outside range [minOrd,maxOrd].
88  const T getCoefficient(const FMonomial<N> &monomial) const;
89 
91  // Assign value of the coeffient denoted by monomial exponents.
92  // Ignore if monomial order exceeds truncation order.
93  void setCoefficient(const FMonomial<N> &monomial, const T &value);
94 
96  // Return value of the coefficient denoted by the Giorgilli index.
97  // Result undefined for index not in range [orderStart(minOrd),orderEnd(maxOrd)).
98  inline const T operator[](int index) const;
99 
101  // Return a reference to the coefficient denoted by the Giorgilli index.
102  // Result undefined for index not in range [orderStart(minOrd),orderEnd(maxOrd)).
103  // Makes FTps unique(), so use as an lvalue is allowed.
104  inline T &operator[](int index);
105 
107  // Return value of the coefficient denoted by monomial exponents.
108  // Result undefined if monomial order lies outside range [minOrd,maxOrd].
109  const T operator[](const FMonomial<N> &monomial) const;
110 
112  // Return a reference to the coefficient denoted by monomial exponents.
113  // Result undefined for monomial order not in range [minOrd,maxOrd].
114  // Makes FTps unique(), so use as an lvalue is allowed.
115  T &operator[](const FMonomial<N> &monomial);
116 
118  T *begin() const { return itsRep->begin(); }
119 
121  T *end() const { return itsRep->end(); }
122 
124  T *begin(int order) const
125  { return itsRep->data + FTpsData<N>::orderStart(order); }
126 
128  T *end(int order) const
129  { return itsRep->data + FTpsData<N>::orderEnd(order); }
130 
132  static int getVariables()
133  { return N; }
134 
136  int getSize() const
137  { return itsRep->len; }
138 
140  static int getSize(int order);
141 
143  static int orderStart(int order)
144  { return FTpsData<N>::orderStart(order); }
145 
147  static int orderEnd(int order)
148  { return FTpsData<N>::orderEnd(order); }
149 
150  // Number of coefficients of degree "order".
151  static int orderLength(int order)
152  { return FTpsData<N>::orderLength(order); }
153 
154  // Number of coefficients such that "orderL" <= degree <= "orderH".
155  static int orderLength(int orderL, int orderH)
156  { return FTpsData<N>::orderLength(orderL, orderH); }
157 
159  static const FMonomial<N> &getExponents(int index);
160 
162  static int getIndex(const FMonomial<N> &mono);
163 
165  int getMinOrder() const
166  { return itsRep->minOrd; }
167 
169  // If necessary, this function will insert zeroes or modify the
170  // maximum order. It will not modify the truncation order.
171  void setMinOrder(int order);
172 
174  int getMaxOrder() const
175  { return itsRep->maxOrd; }
176 
178  // If necessary, this function will insert zeroes or modify the minimum
179  // or maximum orders. It will not modify the truncation order.
180  void setMaxOrder(int order);
181 
183  int getTruncOrder() const
184  { return itsRep->trcOrd; }
185 
187  // This is the only function that may increase the truncation order of an FTps.
188  void setTruncOrder(int order);
189 
191  static int getGlobalTruncOrder()
192  { return globalTruncOrder; }
193 
195  static void setGlobalTruncOrder(int order);
196 
198  static inline const Array1D<int> &getProductArray(int index);
199 
201  static inline const Array1D<int> &getVariableList(int index);
202 
204  static inline const Array1D<TpsSubstitution> &getSubTable();
205 
207  // If the argument range [minOrder,maxOrder] does not overlap the range of
208  // min and max orders of the calling FTps, then filter() returns a zero FTps
209  // with the requested min and max orders.
210  FTps filter(int minOrder, int maxOrder, int trcOrder = EXACT) const;
211 
213  // Limit the truncation order to [b]trunc[/b].
214  FTps truncate(int trunc);
215 
217  // Construct the variable identified by the index [b]var[/b].
218  static FTps makeVariable(int var);
219 
221  // Construct [b]power[/b] of variable [b]var[/b].
222  static FTps makeVarPower(int var, int power);
223 
225  // Construct the monomial with Giorgilli index [b]index[/b] and coefficient [b]t[/b].
226  static FTps makeMonomial(int index, const T &t);
227 
229  // Construct the monomial with exponents [b]m[/b] and coefficient [b]t[/b].
230  static FTps makeMonomial(const FMonomial<N> &m, const T &t);
231 
233  FTps operator+() const;
234 
236  FTps operator-() const;
237 
239  FTps &operator+=(const FTps &y);
240 
242  FTps &operator-=(const FTps &y);
243 
245  FTps &operator*=(const FTps &y);
246 
248  FTps &operator/=(const FTps &y);
249 
251  FTps &operator+=(const T &y);
252 
254  FTps &operator-=(const T &y);
255 
257  FTps &operator*=(const T &y);
258 
260  FTps &operator/=(const T &y);
261 
263  FTps scaleMonomials(const FTps &y) const;
264 
266  FTps multiplyVariable(int var, int trunc = EXACT) const;
267 
269  FTps multiply(const FTps &y, int trunc = EXACT) const;
270 
272  FTps inverse(int trunc = EXACT) const;
273 
275  // Throws exception if handed a pair of EXACT Tps's with trunc > globalTruncOrder.
276  FTps divide(const FTps &y, int trunc = EXACT) const;
277 
279  // Returns "true" if polynomials agree
280  // (up to the smaller truncation order).
281  bool operator==(const FTps &y) const;
282 
284  bool operator==(const T &y) const;
285 
287  bool operator!=(const FTps &y) const;
288 
290  bool operator!=(const T &y) const;
291 
293  // NB: this method uses static local memory.
294  static Array1D<T> evalMonoms(const FVector<T, N> &, int);
295 
297  // NB: this method uses static local memory.
298  T evaluate(const FVector<T, N> &) const;
299 
301  // NB: This routine is NOT guaranteed to return min <= max <= trc.
302  // If min exceeds max, then f(rhs(z)) = 0 + O(z^{trunc+1}).
303  // This possibility must be checked for. Also, if both TPSs are
304  // EXACT and of sufficiently low order, then the result can be EXACT
305  // even if trunc is finite.
306  Array1D<int> getSubstOrders(const FVps<T, N> &rhs, int trunc = EXACT) const;
307 
309  // with ordersL = orders(f), and ordersR = orders(rhs).
310  // NB: This routine is NOT guaranteed to return min <= max <= trc.
311  // If min exceeds max, then f(rhs(z)) = 0 + O(z^{trunc+1}).
312  // This possibility must be checked for. Also, if both TPSs are
313  // EXACT and of sufficiently low order, then the result can be EXACT
314  // even if trunc is finite.
315  static Array1D<int> getSubstOrders(Array1D<int> &ordersL, Array1D<int> &ordersR,
316  int trunc = EXACT);
317 
319  // Use the linear map with matrix representation [b]M[/b] to transform the
320  // order n part of an FTps; leave remaining parts unchanged. Return a new FTps.
321  // NB: This method uses static local memory. Note that instead of static local
322  // memory, one could use the data storage of an FTps---it's the correct size,
323  // it's reference counted, and it's retained on a stack.
324  FTps substitute(const FMatrix<T, N, N> &M, int n) const;
325 
327  // Use the linear map with matrix representation [b]M[/b] to transform the
328  // order nl through nh parts of an FTps; leave remaining parts unchanged.
329  // Return a new FTps.
330  // NB: This method uses static local memory.
331  FTps substitute(const FMatrix<T, N, N> &M, int nl, int nh) const;
332 
334  // Use the linear map with matrix representation [b]M[/b]
335  // to transform an FTps. Return a new FTps.
336  // NB: This method (indirectly) uses static local memory.
337  FTps substitute(const FMatrix<T, N, N> &M) const;
338 
340  // Use the (nonlinear) map [b]m[/b] to transform an FTps. Return a new FTps.
341  // NB: this method uses static local memory.
342  FTps substitute(const FVps<T, N> &m, int trunc = EXACT) const;
343 
345  // Return partial derivative with respect to variable [b]var[/b].
346  // Return zero for a constant.
347  FTps derivative(int var) const;
348 
350  FVps<T, N> gradient() const;
351 
353  // Return partial integral with respect to variable [b]var[/b].
354  FTps integral(int var, int trunc = EXACT) const;
355 
357  // Return a Taylor series with given order and coefficients.
358  // f.taylor(c,n) ==> c[0] + c[1] * (f-f[0]) + ... + c[n] * (f-f[0])^n
359  FTps taylor(const Array1D<T> &series, int order) const;
360 
362  inline void unique();
363 
365  // Returns a STL list containing the indexes
366  std::list<int> getListOfNonzeroCoefficients() const;
367 
369  // Retuns a 1D Array containing the exponents to index [b]index[/b].
370  FArray1D<int, N> extractExponents(int index) const;
371 
373  // Return the power of the truncated power series
374  FTps<T, N> makePower(int power) const;
375 
377  std::istream &get(std::istream &is);
378 
380  std::ostream &put(std::ostream &os) const;
381 
383  static const int EXACT;// = INT_MAX;
384 
385 private:
386 
387  // Memory allocator. Return an unfilled representation.
388  static FTpsRep<T, N> *allocate(int minOrder, int maxOrder, int trcOrder);
389 
390  // Memory deallocator. Return the representation to the memory pool.
391  static void deallocate(FTpsRep<T, N> *);
392 
393  // Grow the representation, if necessary, so as to accomodate a higher order.
394  void grow(int maxOrder, int trcOrder);
395 
396  // Report orders of underlying FTpsRep. (Useful for debugging.)
397  Array1D<int> getRepOrders() const;
398 
399  // Check that min-, max-, and trcOrder's have the correct relationships.
400  // If not, complain with a message that names the given "method".
401  static void checkOrders(const std::string &method, int minOrder, int maxOrder, int &trcOrder);
402 
403  // Pointer to representation.
404  // This is the only non-static data member of class FTps<T,N>.
406 
407  // The free storage list: freeList[ord] points to the first entry
408  // in a linked list of FTpsRep's allocated for order [b]ord[/b].
409  static FTpsRep<T, N> *freeList[100];
410 
411  // The global truncation order.
412  static int globalTruncOrder;
413 };
414 
415 
416 // Global functions.
417 // ------------------------------------------------------------------------
418 
420 template <class T, int N>
421 FTps<T, N> operator+(const FTps<T, N> &, const FTps<T, N> &);
422 
424 template <class T, int N>
425 FTps<T, N> operator-(const FTps<T, N> &, const FTps<T, N> &);
426 
428 template <class T, int N>
429 FTps<T, N> operator+(const FTps<T, N> &, const T &);
430 
432 template <class T, int N>
433 FTps<T, N> operator-(const FTps<T, N> &, const T &);
434 
436 template <class T, int N>
437 FTps<T, N> operator+(const T &, const FTps<T, N> &);
438 
440 template <class T, int N>
441 FTps<T, N> operator-(const T &, const FTps<T, N> &);
442 
444 template <class T, int N>
445 FTps<T, N> operator*(const FTps<T, N> &, const FTps<T, N> &);
446 
448 template <class T, int N>
449 FTps<T, N> operator/(const FTps<T, N> &, const FTps<T, N> &);
450 
452 template <class T, int N>
453 FTps<T, N> operator*(const FTps<T, N> &, const T &);
454 
456 template <class T, int N>
457 FTps<T, N> operator/(const FTps<T, N> &, const T &);
458 
460 template <class T, int N>
461 FTps<T, N> operator*(const T &, const FTps<T, N> &);
462 
464 template <class T, int N>
465 FTps<T, N> operator/(const T &, const FTps<T, N> &);
466 
468 template <class T, int N>
469 bool operator==(const T &, const FTps<T, N> &);
470 
472 template <class T, int N>
473 bool operator!=(const T &, const FTps<T, N> &);
474 
476 // Return the series exp(:H:) z,
477 // the Lie transform exp(:H:) acting on the identity map.
478 template <class T, int N>
479 FVps<T, N> ExpMap(const FTps<T, N> &H, int trunc = FTps<T, N>::EXACT);
480 
482 // Return the series exp(:H:) f,
483 // the Lie transform exp(:H:) acting on the function [b]f[/b].
484 template <class T, int N>
485 FTps<T, N> ExpMap(const FTps<T, N> &H, const FTps<T, N> &f, int trunc = FTps<T, N>::EXACT);
486 
488 template <class T, int N>
489 FTps<T, N> PoissonBracket(const FTps<T, N> &f, const FTps<T, N> &g, int trunc = FTps<T, N>::EXACT);
490 
492 template <class T, int N>
493 std::istream &operator>>(std::istream &is, FTps<T, N> &);
494 
496 template <class T, int N>
497 std::ostream &operator<<(std::ostream &os, const FTps<T, N> &);
498 
499 
500 // Implementation.
501 #include "FixedAlgebra/FVps.h"
502 #include "FixedAlgebra/FTps.hpp"
503 
504 #endif // CLASSIC_FTps_HH
Matrix< T > operator+(const Matrix< T > &, const Matrix< T > &)
Matrix addition.
Definition: Matrix.h:275
FTps operator+() const
Unary plus.
Definition: FTps.hpp:517
static int globalTruncOrder
Definition: FTps.h:412
static void checkOrders(const std::string &method, int minOrder, int maxOrder, int &trcOrder)
Definition: FTps.hpp:1767
Array1D< int > getRepOrders() const
Definition: FTps.hpp:1756
Matrix< T > operator/(const Matrix< T > &, const T &)
Matrix divided by scalar.
Definition: Matrix.h:329
FTps truncate(int trunc)
Truncate.
Definition: FTps.hpp:475
void setMinOrder(int order)
Set minimum order.
Definition: FTps.hpp:321
int getMaxOrder() const
Get maximum order.
Definition: FTps.h:174
static int orderLength(int order)
Definition: FTpsData.h:224
Definition: rbendmap.h:8
bool operator!=(const FTps &y) const
Inequality operator.
Definition: FTps.hpp:886
Array1D< int > getSubstOrders(const FVps< T, N > &rhs, int trunc=EXACT) const
Return orders {min, max, trc} of f(rhs(z)).
Definition: FTps.hpp:1008
A templated representation for matrices.
Definition: IdealMapper.h:26
A templated representation for vectors.
Definition: PartBunchBase.h:26
int getMinOrder() const
Get minimum order.
Definition: FTps.h:165
FTps & operator+=(const FTps &y)
Add and assign.
Definition: FTps.hpp:533
Representation of the exponents for a monomial with fixed dimension.
Definition: FMonomial.h:32
static int orderStart(int order)
Definition: FTpsData.h:196
static int orderLength(int order)
Definition: FTps.h:151
Matrix< T > operator*(const Matrix< T > &, const Matrix< T > &)
Matrix multiply.
Definition: Matrix.h:297
Definition: FTps.h:33
FTps< T, N > makePower(int power) const
Multiply FTps with itself.
Definition: FTps.hpp:1555
std::list< int > getListOfNonzeroCoefficients() const
Get a list containing the indexes of non-zero coefficients of a FTps.
Definition: FTps.hpp:1515
~FTps()
Destructor.
Definition: FTps.hpp:194
static FTps makeMonomial(int index, const T &t)
Make monomial.
Definition: FTps.hpp:499
static int orderEnd(int order)
Definition: FTpsData.h:210
FTpsRep< T, N > * itsRep
Definition: FTps.h:405
FTps multiplyVariable(int var, int trunc=EXACT) const
Multiply by variable [b]var[/b].
Definition: FTps.hpp:610
FTps multiply(const FTps &y, int trunc=EXACT) const
Multiplication.
Definition: FTps.hpp:650
static int orderStart(int order)
Get index at which [b]order[/b] starts.
Definition: FTps.h:143
FTps divide(const FTps &y, int trunc=EXACT) const
Division.
Definition: FTps.hpp:761
Tps< T > PoissonBracket(const Tps< T > &x, const Tps< T > &y)
Poisson bracket.
Definition: LieMap.h:154
FTps()
Default constructor.
Definition: FTps.hpp:159
static const Array1D< int > & getVariableList(int index)
List of variables contained in monomial &quot;index&quot;.
Definition: FTps.hpp:439
static const Array1D< int > & getProductArray(int index)
Index array for products of monomial &quot;index&quot;.
Definition: FTps.hpp:433
FVps< T, N > gradient() const
Gradient.
Definition: FTps.hpp:1433
int getSize() const
Get total number of coefficients.
Definition: FTps.h:136
const T operator[](int index) const
Get coefficient.
Definition: FTps.hpp:275
static int getVariables()
Get number of variables.
Definition: FTps.h:132
void setMaxOrder(int order)
Set maximum order.
Definition: FTps.hpp:357
bool operator==(const FTps &y) const
Equality operator.
Definition: FTps.hpp:831
void unique()
Make representation unique.
Definition: FTps.hpp:1505
T * begin(int order) const
Return beginning of coefficient storage for given order.
Definition: FTps.h:124
FVps< T, N > ExpMap(const FTps< T, N > &H, int trunc=FTps< T, N >::EXACT)
Build the exponential series.
Definition: FTps.hpp:1994
FTps & operator-=(const FTps &y)
Subtract and assign.
Definition: FTps.hpp:539
const T getCoefficient(int index) const
Get coefficient.
Definition: FTps.hpp:223
T * end(int order) const
Return end of coefficient storage for given order.
Definition: FTps.h:128
int getTruncOrder() const
Get truncation order.
Definition: FTps.h:183
FTps & operator=(const FTps &y)
Assign.
Definition: FTps.hpp:201
FTps substitute(const FMatrix< T, N, N > &M, int n) const
Substitute.
Definition: FTps.hpp:1075
static Array1D< T > evalMonoms(const FVector< T, N > &, int)
Evaluate monomials at point.
Definition: FTps.hpp:898
T evaluate(const FVector< T, N > &) const
Evaluate FTps at point.
Definition: FTps.hpp:934
FTps scaleMonomials(const FTps &y) const
Scale monomial coefficients by coefficients in [b]y[/b].
Definition: FTps.hpp:589
std::ostream & put(std::ostream &os) const
Write FTps on the stream [b]os[/b].
Definition: FTps.hpp:1648
FArray1D< int, N > extractExponents(int index) const
Extract exponents of coefficient.
Definition: FTps.hpp:1535
T * end() const
Return end of monomial array.
Definition: FTps.h:121
static void deallocate(FTpsRep< T, N > *)
Definition: FTps.hpp:1726
FTps derivative(int var) const
Partial derivative.
Definition: FTps.hpp:1396
FTps taylor(const Array1D< T > &series, int order) const
Taylor series.
Definition: FTps.hpp:1481
static int getGlobalTruncOrder()
Return the global truncation order.
Definition: FTps.h:191
bool operator!=(const Offset &off1, const Offset &off2)
Definition: Offset.cpp:225
Substitution for Tps&lt;T&gt;.
FTps filter(int minOrder, int maxOrder, int trcOrder=EXACT) const
Extract given range of orders, with truncation.
Definition: FTps.hpp:451
void grow(int maxOrder, int trcOrder)
Definition: FTps.hpp:1734
FTps inverse(int trunc=EXACT) const
Reciprocal, 1/(*this).
Definition: FTps.hpp:707
FTps operator-() const
Unary minus.
Definition: FTps.hpp:523
static const FMonomial< N > & getExponents(int index)
Get exponents for given index.
Definition: FTps.hpp:309
FTps & operator/=(const FTps &y)
Divide and assign.
Definition: FTps.hpp:551
static void setGlobalTruncOrder(int order)
Set the global truncation order.
Definition: FTps.hpp:419
static FTps makeVarPower(int var, int power)
Make power.
Definition: FTps.hpp:489
FTps integral(int var, int trunc=EXACT) const
Partial integral.
Definition: FTps.hpp:1441
static const int EXACT
Representation of infinite precision.
Definition: FTps.h:383
One-dimensional array.
Definition: Array1D.h:36
static int orderEnd(int order)
Get one plus index at which [b]order[/b] ends.
Definition: FTps.h:147
void setTruncOrder(int order)
Set truncation order.
Definition: FTps.hpp:393
Truncated power series in N variables of type T.
Matrix< T > operator-(const Matrix< T > &, const Matrix< T > &)
Matrix subtraction.
Definition: Matrix.h:282
static FTpsRep< T, N > * freeList[100]
Definition: FTps.h:409
static int getIndex(const FMonomial< N > &mono)
Get Giorgilli index for monomial.
Definition: FTps.hpp:315
static int orderLength(int orderL, int orderH)
Definition: FTps.h:155
static const Array1D< TpsSubstitution > & getSubTable()
Return the substitution table.
Definition: FTps.hpp:445
Vector truncated power series in n variables.
static FTps makeVariable(int var)
Make variable.
Definition: FTps.hpp:481
static FTpsRep< T, N > * allocate(int minOrder, int maxOrder, int trcOrder)
Definition: FTps.hpp:1692
std::istream & operator>>(std::istream &, LieMap< T > &x)
Extract LieMap&lt;T&gt; from stream.
Definition: LieMap.h:231
void setCoefficient(int index, const T &value)
Set coefficient.
Definition: FTps.hpp:236
T * begin() const
Return beginning of monomial array.
Definition: FTps.h:118
bool operator==(const TwoPolynomial &left, const TwoPolynomial &right)
FTps & operator*=(const FTps &y)
Multiply and assign.
Definition: FTps.hpp:545