OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
TpsData.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: TpsData.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: TpsData
10 // Bookkeeper class for Tps class.
11 //
12 // ------------------------------------------------------------------------
13 // Class category: Algebra
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2000/03/27 09:32:32 $
17 // $Author: fci $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "Algebra/TpsData.h"
22 #include "Algebra/TpsMonomial.h"
23 
24 
25 // Class TpsData
26 // ------------------------------------------------------------------------
27 
28 namespace {
29  const int TpsData_SIZE = 100;
30  TpsData theirTpsData[TpsData_SIZE];
31 };
32 
33 
35  clear();
36 }
37 
38 
40 {}
41 
42 
43 TpsData *TpsData::getTpsData(int nOrd, int nVar) {
44  if(nVar == 0) {
45  return 0;
46  } else {
47  theirTpsData[nVar].build(nOrd, nVar);
48  return &theirTpsData[nVar];
49  }
50 }
51 
52 
53 int TpsData::indexMonomial(const TpsMonomial &pows) const {
54  int index = 0;
55  int order = 0;
56 
57  for(int var = variables; var-- > 0;) {
58  order += pows[var];
59  index += binom[var][order];
60  }
61 
62  return index;
63 }
64 
65 
66 void TpsData::build(int nOrd, int nVar) {
67  // Number of variables.
68  variables = nVar;
69 
70  // Maximum order so far.
71  if(topOrder < nOrd) {
72  topOrder = nOrd;
73 
74  // Define binomial coefficients.
75  int var, ord;
76  binom = BinomialTable(nVar, topOrder + 2);
77 
78  for(var = 0; var < nVar; var++) {
79  binom[var][0] = 0;
80  }
81 
82  for(ord = 1; ord <= topOrder + 1; ord++) {
83  binom[nVar-1][ord] = ord;
84 
85  for(var = nVar - 1; var-- > 0;) {
86  binom[var][ord] = binom[var][ord-1] + binom[var+1][ord];
87  }
88  }
89 
90  // Set up table of exponents up to topOrder
91  // (algorithm due to Liam Healey (Marylie 3.0)).
93  {
94  TpsMonomial power(nVar);
95  expon = ExponentTable(maxSize, power);
96 
97  for(int index = 1; index < maxSize; index++) {
98  int carry = power[nVar-1];
99  power[nVar-1] = 0;
100  int lastnz = int(-1);
101 
102  for(int j = 0; j < nVar - 1; j++) {
103  if(power[j] > 0) lastnz = j;
104  }
105 
106  if(lastnz == int(-1)) {
107  power[lastnz+1] = power[lastnz+1] + 1 + carry;
108  } else {
109  power[lastnz]--;
110  power[lastnz+1] = power[lastnz+1] + 1 + carry;
111  }
112 
113  expon[index] = power;
114  }
115  }
116 
117  // Set up table of products for total order up to topOrder.
118  {
120  TpsMonomial power(nVar);
121 
122  for(int xord = 0; xord <= topOrder; xord++) {
123  int yord = topOrder - xord;
124  int ysize = getSize(yord);
125  for(int i = getSize(xord - 1); i < getSize(xord); i++) {
126  prod[i] = ProductRow(ysize);
127 
128  for(int j = 0; j < ysize; j++) {
129  power = expon[i] * expon[j];
130  prod[i][j] = indexMonomial(power);
131  }
132  }
133  }
134  }
135 
136  {
137  // Fill the substitution table.
139  TpsMonomial power(nVar);
140  int next = 1;
141  fillSubst(0, 1, power, next);
142  }
143  }
144 }
145 
146 
148  variables = 0;
149  topOrder = 0;
150 }
151 
152 
154 (int var, int order, TpsMonomial &pow, int &next) {
155  for(int v = var; v < variables; v++) {
156  TpsSubstitution &s = subTable[next++];
157  pow[v]++;
158  s.index = indexMonomial(pow);
159  s.order = order;
160  s.variable = v;
161  if(order < topOrder) fillSubst(v, order + 1, pow, next);
162  s.skip = next;
163  pow[v]--;
164  }
165 }
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
Bookkeeping class for Tps<T>.
Definition: TpsData.h:35
static TpsData * getTpsData(int nOrd, int nVar)
Definition: TpsData.cpp:43
Array1D< int > ProductRow
Definition: TpsData.h:95
void build(int max, int nVar)
Definition: TpsData.cpp:66
ProductTable prod
Definition: TpsData.h:97
Array2D< int > BinomialTable
Definition: TpsData.h:101
BinomialTable binom
Definition: TpsData.h:102
int variables
Definition: TpsData.h:82
void clear()
Definition: TpsData.cpp:147
int getSize(int order) const
Definition: TpsData.h:124
~TpsData()
Definition: TpsData.cpp:39
ExponentTable expon
Definition: TpsData.h:92
void fillSubst(int var, int order, TpsMonomial &pow, int &next)
Definition: TpsData.cpp:154
Array1D< TpsMonomial > ExponentTable
Definition: TpsData.h:91
Array1D< TpsSubstitution > subTable
Definition: TpsData.h:105
int maxSize
Definition: TpsData.h:88
Array1D< ProductRow > ProductTable
Definition: TpsData.h:96
TpsData()
Definition: TpsData.cpp:34
int topOrder
Definition: TpsData.h:85
int indexMonomial(const TpsMonomial &) const
Definition: TpsData.cpp:53
Exponent array for Tps<T>.
Definition: TpsMonomial.h:31
Substitution for Tps<T>.