OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
24#include <iosfwd>
25#include <list>
26#include <string>
27
28struct TpsSubstitution;
29
30template <class T> class Array1D;
31template <class T, int M, int N> class FMatrix;
32template <int N> class FMonomial;
33template <class T, int N> class FTpsRep;
34template <class T, int N> class FVector;
35template <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
44template <class T, int N>
45class FTps {
46
47public:
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
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
385private:
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.)
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].
410
411 // The global truncation order.
413};
414
415
416// Global functions.
417// ------------------------------------------------------------------------
418
420template <class T, int N>
421FTps<T, N> operator+(const FTps<T, N> &, const FTps<T, N> &);
422
424template <class T, int N>
425FTps<T, N> operator-(const FTps<T, N> &, const FTps<T, N> &);
426
428template <class T, int N>
429FTps<T, N> operator+(const FTps<T, N> &, const T &);
430
432template <class T, int N>
433FTps<T, N> operator-(const FTps<T, N> &, const T &);
434
436template <class T, int N>
437FTps<T, N> operator+(const T &, const FTps<T, N> &);
438
440template <class T, int N>
441FTps<T, N> operator-(const T &, const FTps<T, N> &);
442
444template <class T, int N>
445FTps<T, N> operator*(const FTps<T, N> &, const FTps<T, N> &);
446
448template <class T, int N>
449FTps<T, N> operator/(const FTps<T, N> &, const FTps<T, N> &);
450
452template <class T, int N>
453FTps<T, N> operator*(const FTps<T, N> &, const T &);
454
456template <class T, int N>
457FTps<T, N> operator/(const FTps<T, N> &, const T &);
458
460template <class T, int N>
461FTps<T, N> operator*(const T &, const FTps<T, N> &);
462
464template <class T, int N>
465FTps<T, N> operator/(const T &, const FTps<T, N> &);
466
468template <class T, int N>
469bool operator==(const T &, const FTps<T, N> &);
470
472template <class T, int N>
473bool 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.
478template <class T, int N>
479FVps<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].
484template <class T, int N>
485FTps<T, N> ExpMap(const FTps<T, N> &H, const FTps<T, N> &f, int trunc = FTps<T, N>::EXACT);
486
488template <class T, int N>
489FTps<T, N> PoissonBracket(const FTps<T, N> &f, const FTps<T, N> &g, int trunc = FTps<T, N>::EXACT);
490
492template <class T, int N>
493std::istream &operator>>(std::istream &is, FTps<T, N> &);
494
496template <class T, int N>
497std::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
bool operator==(const T &, const FTps< T, N > &)
Equality.
Definition: FTps.hpp:1982
FVps< T, N > ExpMap(const FTps< T, N > &H, int trunc=FTps< T, N >::EXACT)
Build the exponential series.
Definition: FTps.hpp:1994
std::ostream & operator<<(std::ostream &os, const FTps< T, N > &)
Insert FTps into stream [b]os[/b].
Definition: FTps.hpp:2098
std::istream & operator>>(std::istream &is, FTps< T, N > &)
Extract FTps from stream [b]is[/b].
Definition: FTps.hpp:2092
FTps< T, N > operator-(const FTps< T, N > &, const FTps< T, N > &)
Subtract.
Definition: FTps.hpp:1858
FTps< T, N > operator/(const FTps< T, N > &, const FTps< T, N > &)
Divide.
Definition: FTps.hpp:1949
FTps< T, N > operator+(const FTps< T, N > &, const FTps< T, N > &)
Add.
Definition: FTps.hpp:1802
FTps< T, N > PoissonBracket(const FTps< T, N > &f, const FTps< T, N > &g, int trunc=FTps< T, N >::EXACT)
Poisson bracket.
Definition: FTps.hpp:2058
bool operator!=(const T &, const FTps< T, N > &)
Inequality.
Definition: FTps.hpp:1988
FTps< T, N > operator*(const FTps< T, N > &, const FTps< T, N > &)
Multiply.
Definition: FTps.hpp:1942
Vector truncated power series in n variables.
Definition: FVps.h:39
One-dimensional array.
Definition: Array1D.h:36
Substitution for Tps<T>.
A templated representation for matrices.
Definition: FMatrix.h:39
Truncated power series in N variables of type T.
Definition: FTps.h:45
T * begin(int order) const
Return beginning of coefficient storage for given order.
Definition: FTps.h:124
static void deallocate(FTpsRep< T, N > *)
Definition: FTps.hpp:1726
static const Array1D< int > & getProductArray(int index)
Index array for products of monomial "index".
Definition: FTps.hpp:433
FTps< T, N > makePower(int power) const
Multiply FTps with itself.
Definition: FTps.hpp:1555
Array1D< int > getRepOrders() const
Definition: FTps.hpp:1756
FTps substitute(const FMatrix< T, N, N > &M, int n) const
Substitute.
Definition: FTps.hpp:1075
const T getCoefficient(int index) const
Get coefficient.
Definition: FTps.hpp:223
std::list< int > getListOfNonzeroCoefficients() const
Get a list containing the indexes of non-zero coefficients of a FTps.
Definition: FTps.hpp:1515
FTps inverse(int trunc=EXACT) const
Reciprocal, 1/(*this).
Definition: FTps.hpp:707
FTps taylor(const Array1D< T > &series, int order) const
Taylor series.
Definition: FTps.hpp:1481
FTps & operator/=(const FTps &y)
Divide and assign.
Definition: FTps.hpp:551
void setTruncOrder(int order)
Set truncation order.
Definition: FTps.hpp:393
std::istream & get(std::istream &is)
Read FTps on the stream [b]is[/b].
Definition: FTps.hpp:1571
FTps & operator+=(const FTps &y)
Add and assign.
Definition: FTps.hpp:533
FTps()
Default constructor.
Definition: FTps.hpp:159
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
~FTps()
Destructor.
Definition: FTps.hpp:194
int getMinOrder() const
Get minimum order.
Definition: FTps.h:165
static FTpsRep< T, N > * allocate(int minOrder, int maxOrder, int trcOrder)
Definition: FTps.hpp:1692
FTps truncate(int trunc)
Truncate.
Definition: FTps.hpp:475
int getTruncOrder() const
Get truncation order.
Definition: FTps.h:183
static void checkOrders(const std::string &method, int minOrder, int maxOrder, int &trcOrder)
Definition: FTps.hpp:1767
FTps multiply(const FTps &y, int trunc=EXACT) const
Multiplication.
Definition: FTps.hpp:650
std::ostream & put(std::ostream &os) const
Write FTps on the stream [b]os[/b].
Definition: FTps.hpp:1648
static int orderLength(int orderL, int orderH)
Definition: FTps.h:155
const T operator[](int index) const
Get coefficient.
Definition: FTps.hpp:275
static const int EXACT
Representation of infinite precision.
Definition: FTps.h:383
FTps & operator-=(const FTps &y)
Subtract and assign.
Definition: FTps.hpp:539
FTps operator+() const
Unary plus.
Definition: FTps.hpp:517
static FTps makeMonomial(int index, const T &t)
Make monomial.
Definition: FTps.hpp:499
int getSize() const
Get total number of coefficients.
Definition: FTps.h:136
FTps & operator=(const FTps &y)
Assign.
Definition: FTps.hpp:201
static Array1D< T > evalMonoms(const FVector< T, N > &, int)
Evaluate monomials at point.
Definition: FTps.hpp:898
static int orderLength(int order)
Definition: FTps.h:151
FTps multiplyVariable(int var, int trunc=EXACT) const
Multiply by variable [b]var[/b].
Definition: FTps.hpp:610
FTps derivative(int var) const
Partial derivative.
Definition: FTps.hpp:1396
void unique()
Make representation unique.
Definition: FTps.hpp:1505
FVps< T, N > gradient() const
Gradient.
Definition: FTps.hpp:1433
bool operator!=(const FTps &y) const
Inequality operator.
Definition: FTps.hpp:886
FTps & operator*=(const FTps &y)
Multiply and assign.
Definition: FTps.hpp:545
T * begin() const
Return beginning of monomial array.
Definition: FTps.h:118
void setCoefficient(int index, const T &value)
Set coefficient.
Definition: FTps.hpp:236
static FTps makeVariable(int var)
Make variable.
Definition: FTps.hpp:481
static int getGlobalTruncOrder()
Return the global truncation order.
Definition: FTps.h:191
static int orderEnd(int order)
Get one plus index at which [b]order[/b] ends.
Definition: FTps.h:147
static int globalTruncOrder
Definition: FTps.h:412
FTps divide(const FTps &y, int trunc=EXACT) const
Division.
Definition: FTps.hpp:761
T * end(int order) const
Return end of coefficient storage for given order.
Definition: FTps.h:128
T evaluate(const FVector< T, N > &) const
Evaluate FTps at point.
Definition: FTps.hpp:934
static void setGlobalTruncOrder(int order)
Set the global truncation order.
Definition: FTps.hpp:419
static const Array1D< TpsSubstitution > & getSubTable()
Return the substitution table.
Definition: FTps.hpp:445
int getMaxOrder() const
Get maximum order.
Definition: FTps.h:174
FTpsRep< T, N > * itsRep
Definition: FTps.h:405
static int getVariables()
Get number of variables.
Definition: FTps.h:132
static int orderStart(int order)
Get index at which [b]order[/b] starts.
Definition: FTps.h:143
void setMaxOrder(int order)
Set maximum order.
Definition: FTps.hpp:357
T * end() const
Return end of monomial array.
Definition: FTps.h:121
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
static const FMonomial< N > & getExponents(int index)
Get exponents for given index.
Definition: FTps.hpp:309
static FTpsRep< T, N > * freeList[100]
Definition: FTps.h:409
bool operator==(const FTps &y) const
Equality operator.
Definition: FTps.hpp:831
static const Array1D< int > & getVariableList(int index)
List of variables contained in monomial "index".
Definition: FTps.hpp:439
FTps scaleMonomials(const FTps &y) const
Scale monomial coefficients by coefficients in [b]y[/b].
Definition: FTps.hpp:589
FTps filter(int minOrder, int maxOrder, int trcOrder=EXACT) const
Extract given range of orders, with truncation.
Definition: FTps.hpp:451
FArray1D< int, N > extractExponents(int index) const
Extract exponents of coefficient.
Definition: FTps.hpp:1535
FTps operator-() const
Unary minus.
Definition: FTps.hpp:523
static int getIndex(const FMonomial< N > &mono)
Get Giorgilli index for monomial.
Definition: FTps.hpp:315
void setMinOrder(int order)
Set minimum order.
Definition: FTps.hpp:321
void grow(int maxOrder, int trcOrder)
Definition: FTps.hpp:1734
Representation of the exponents for a monomial with fixed dimension.
Definition: FMonomial.h:32
Definition: FTps.hpp:56
A templated representation for vectors.
Definition: FVector.h:38
static int orderEnd(int order)
Definition: FTpsData.h:208
static int orderLength(int order)
Definition: FTpsData.h:222
static int orderStart(int order)
Definition: FTpsData.h:194