13 typedef std::pair<std::pair<int, int>,
int> mytuple;
15 mytuple make_mytuple(
int a,
int b,
int c)
17 return std::make_pair(std::make_pair(a, b),
c);
23 for(
int i = 0; i < intMat.
size1(); ++i) {
24 for(
int j = 0; j < intMat.
size2(); ++j) {
25 intMat(i, j) =
static_cast<int>(doubleMat(i, j) + .5);
30 std::map<int, fullMatrix<double> *> storedMatrices[6];
35 if(type < 3 || type > 8)
return nullptr;
36 std::map<int, fullMatrix<double> *>::iterator it;
37 it = storedMatrices[type - 3].find(order);
38 if(it != storedMatrices[type - 3].end()) {
return it->second; }
61 storedMatrices[type - 3][order] = matrix;
70 const int szInc = 3 * order;
71 const int szComp = (order + 1) * (order + 2) / 2;
72 const int szInt = szComp - szInc;
76 double2int(monomials, coordinates);
78 std::map<std::pair<int, int>,
int> coord2idx;
79 for(
int i = 0; i < szInc; ++i) {
80 int u = coordinates(i, 0);
81 int v = coordinates(i, 1);
82 coord2idx[std::make_pair(u, v)] = i;
87 for(
int i = 0; i < szInt; ++i) {
88 int u = coordinates(szInc + i, 0);
89 int v = coordinates(szInc + i, 1);
91 double xi = (double)u / n;
92 double eta = (double)v / n;
93 double rho = (double)q / n;
95 M(i, coord2idx[std::make_pair(u + v, 0)]) += xi;
96 M(i, coord2idx[std::make_pair(u + q, v)]) += xi;
97 M(i, coord2idx[std::make_pair(0, v + u)]) += eta;
98 M(i, coord2idx[std::make_pair(u, v + q)]) += eta;
99 M(i, coord2idx[std::make_pair(0, v)]) += rho;
100 M(i, coord2idx[std::make_pair(u, 0)]) += rho;
101 M(i, coord2idx[std::make_pair(n, 0)]) -= xi;
102 M(i, coord2idx[std::make_pair(0, n)]) -= eta;
103 M(i, coord2idx[std::make_pair(0, 0)]) -= rho;
112 const int szInc = 4 * order;
113 const int szComp = (order + 1) * (order + 1);
114 const int szInt = szComp - szInc;
118 double2int(monomials, coordinates);
120 std::map<std::pair<int, int>,
int> coord2idx;
121 for(
int i = 0; i < szInc; ++i) {
122 int u = coordinates(i, 0);
123 int v = coordinates(i, 1);
124 coord2idx[std::make_pair(u, v)] = i;
129 for(
int i = 0; i < szInt; ++i) {
130 int u = coordinates(szInc + i, 0);
131 int v = coordinates(szInc + i, 1);
132 double xi = (double)u / n;
133 double eta = (double)v / n;
135 M(i, coord2idx[std::make_pair(0, v)]) += 1 - xi;
136 M(i, coord2idx[std::make_pair(n, v)]) += xi;
137 M(i, coord2idx[std::make_pair(u, 0)]) += 1 - eta;
138 M(i, coord2idx[std::make_pair(u, n)]) += eta;
139 M(i, coord2idx[std::make_pair(0, 0)]) -= (1 - xi) * (1 - eta);
140 M(i, coord2idx[std::make_pair(n, 0)]) -= xi * (1 - eta);
141 M(i, coord2idx[std::make_pair(n, n)]) -= xi * eta;
142 M(i, coord2idx[std::make_pair(0, n)]) -= (1 - xi) * eta;
151 const int szInt = (order - 3) * (order - 2) * (order - 1) / 6;
152 const int szComp = (order + 1) * (order + 2) * (order + 3) / 6;
153 const int szInc = szComp - szInt;
157 double2int(monomials, coordinates);
159 std::map<mytuple, int> coord2idx;
160 for(
int i = 0; i < szInc; ++i) {
161 int u = coordinates(i, 0);
162 int v = coordinates(i, 1);
163 int w = coordinates(i, 2);
164 coord2idx[make_mytuple(u, v, w)] = i;
169 for(
int i = 0; i < szInt; ++i) {
170 int u = coordinates(szInc + i, 0);
171 int v = coordinates(szInc + i, 1);
172 int w = coordinates(szInc + i, 2);
173 int q = n - u - v - w;
174 double xi = (double)u / n;
175 double eta = (double)v / n;
176 double zeta = (double)w / n;
177 double rho = (double)q / n;
179 M(i, coord2idx[make_mytuple(u + v, 0, w)]) += xi;
180 M(i, coord2idx[make_mytuple(u + w, v, 0)]) += xi;
181 M(i, coord2idx[make_mytuple(u + q, v, w)]) += xi;
182 M(i, coord2idx[make_mytuple(0, v + u, w)]) += eta;
183 M(i, coord2idx[make_mytuple(u, v + w, 0)]) += eta;
184 M(i, coord2idx[make_mytuple(u, v + q, w)]) += eta;
185 M(i, coord2idx[make_mytuple(0, v, w + u)]) += zeta;
186 M(i, coord2idx[make_mytuple(u, 0, w + v)]) += zeta;
187 M(i, coord2idx[make_mytuple(u, v, w + q)]) += zeta;
188 M(i, coord2idx[make_mytuple(0, v, w)]) += rho;
189 M(i, coord2idx[make_mytuple(u, 0, w)]) += rho;
190 M(i, coord2idx[make_mytuple(u, v, 0)]) += rho;
192 M(i, coord2idx[make_mytuple(n - q, 0, 0)]) -= xi;
193 M(i, coord2idx[make_mytuple(n - w, 0, w)]) -= xi;
194 M(i, coord2idx[make_mytuple(n - v, v, 0)]) -= xi;
195 M(i, coord2idx[make_mytuple(0, n - q, 0)]) -= eta;
196 M(i, coord2idx[make_mytuple(0, n - w, w)]) -= eta;
197 M(i, coord2idx[make_mytuple(u, n - u, 0)]) -= eta;
198 M(i, coord2idx[make_mytuple(0, 0, n - q)]) -= zeta;
199 M(i, coord2idx[make_mytuple(0, v, n - v)]) -= zeta;
200 M(i, coord2idx[make_mytuple(u, 0, n - u)]) -= zeta;
201 M(i, coord2idx[make_mytuple(0, 0, w)]) -= rho;
202 M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho;
203 M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho;
205 M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi;
206 M(i, coord2idx[make_mytuple(0, n, 0)]) += eta;
207 M(i, coord2idx[make_mytuple(0, 0, n)]) += zeta;
208 M(i, coord2idx[make_mytuple(0, 0, 0)]) += rho;
217 const int szInt = (order - 1) * (order - 1) * (order - 1);
218 const int szComp = (order + 1) * (order + 1) * (order + 1);
219 const int szInc = szComp - szInt;
223 double2int(monomials, coordinates);
225 std::map<mytuple, int> coord2idx;
226 for(
int i = 0; i < szInc; ++i) {
227 int u = coordinates(i, 0);
228 int v = coordinates(i, 1);
229 int w = coordinates(i, 2);
230 coord2idx[make_mytuple(u, v, w)] = i;
235 for(
int i = 0; i < szInt; ++i) {
236 int u = coordinates(szInc + i, 0);
237 int v = coordinates(szInc + i, 1);
238 int w = coordinates(szInc + i, 2);
239 double xi = (double)u / n;
240 double eta = (double)v / n;
241 double zeta = (double)w / n;
243 M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - xi;
244 M(i, coord2idx[make_mytuple(n, v, w)]) += xi;
245 M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - eta;
246 M(i, coord2idx[make_mytuple(u, n, w)]) += eta;
247 M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - zeta;
248 M(i, coord2idx[make_mytuple(u, v, n)]) += zeta;
250 M(i, coord2idx[make_mytuple(0, 0, w)]) -= (1 - xi) * (1 - eta);
251 M(i, coord2idx[make_mytuple(0, n, w)]) -= (1 - xi) * eta;
252 M(i, coord2idx[make_mytuple(n, 0, w)]) -= xi * (1 - eta);
253 M(i, coord2idx[make_mytuple(n, n, w)]) -= xi * eta;
254 M(i, coord2idx[make_mytuple(u, 0, 0)]) -= (1 - eta) * (1 - zeta);
255 M(i, coord2idx[make_mytuple(u, 0, n)]) -= (1 - eta) * zeta;
256 M(i, coord2idx[make_mytuple(u, n, 0)]) -= eta * (1 - zeta);
257 M(i, coord2idx[make_mytuple(u, n, n)]) -= eta * zeta;
258 M(i, coord2idx[make_mytuple(0, v, 0)]) -= (1 - zeta) * (1 - xi);
259 M(i, coord2idx[make_mytuple(n, v, 0)]) -= (1 - zeta) * xi;
260 M(i, coord2idx[make_mytuple(0, v, n)]) -= zeta * (1 - xi);
261 M(i, coord2idx[make_mytuple(n, v, n)]) -= zeta * xi;
263 M(i, coord2idx[make_mytuple(0, 0, 0)]) += (1 - xi) * (1 - eta) * (1 - zeta);
264 M(i, coord2idx[make_mytuple(0, 0, n)]) += (1 - xi) * (1 - eta) * zeta;
265 M(i, coord2idx[make_mytuple(0, n, 0)]) += (1 - xi) * eta * (1 - zeta);
266 M(i, coord2idx[make_mytuple(0, n, n)]) += (1 - xi) * eta * zeta;
267 M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * (1 - eta) * (1 - zeta);
268 M(i, coord2idx[make_mytuple(n, 0, n)]) += xi * (1 - eta) * zeta;
269 M(i, coord2idx[make_mytuple(n, n, 0)]) += xi * eta * (1 - zeta);
270 M(i, coord2idx[make_mytuple(n, n, n)]) += xi * eta * zeta;
279 const int szInt = (order - 1) * (order - 2) * (order - 1) / 2;
280 const int szComp = (order + 1) * (order + 1) * (order + 2) / 2;
281 const int szInc = szComp - szInt;
285 double2int(monomials, coordinates);
287 std::map<mytuple, int> coord2idx;
288 for(
int i = 0; i < szInc; ++i) {
289 int u = coordinates(i, 0);
290 int v = coordinates(i, 1);
291 int w = coordinates(i, 2);
292 coord2idx[make_mytuple(u, v, w)] = i;
297 for(
int i = 0; i < szInt; ++i) {
298 int u = coordinates(szInc + i, 0);
299 int v = coordinates(szInc + i, 1);
300 int w = coordinates(szInc + i, 2);
302 double xi = (double)u / n;
303 double eta = (double)v / n;
304 double zeta = (double)w / n;
305 double rho = (double)q / n;
307 M(i, coord2idx[make_mytuple(u + v, 0, w)]) += xi;
308 M(i, coord2idx[make_mytuple(u + q, v, w)]) += xi;
309 M(i, coord2idx[make_mytuple(0, v + u, w)]) += eta;
310 M(i, coord2idx[make_mytuple(u, v + q, w)]) += eta;
311 M(i, coord2idx[make_mytuple(0, v, w)]) += rho;
312 M(i, coord2idx[make_mytuple(u, 0, w)]) += rho;
313 M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - zeta;
314 M(i, coord2idx[make_mytuple(u, v, n)]) += zeta;
316 M(i, coord2idx[make_mytuple(n, 0, w)]) -= xi;
317 M(i, coord2idx[make_mytuple(0, n, w)]) -= eta;
318 M(i, coord2idx[make_mytuple(0, 0, w)]) -= rho;
319 M(i, coord2idx[make_mytuple(u + v, 0, 0)]) -= xi * (1 - zeta);
320 M(i, coord2idx[make_mytuple(u + q, v, 0)]) -= xi * (1 - zeta);
321 M(i, coord2idx[make_mytuple(0, v + u, 0)]) -= eta * (1 - zeta);
322 M(i, coord2idx[make_mytuple(u, v + q, 0)]) -= eta * (1 - zeta);
323 M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho * (1 - zeta);
324 M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho * (1 - zeta);
325 M(i, coord2idx[make_mytuple(u + v, 0, n)]) -= xi * zeta;
326 M(i, coord2idx[make_mytuple(u + q, v, n)]) -= xi * zeta;
327 M(i, coord2idx[make_mytuple(0, v + u, n)]) -= eta * zeta;
328 M(i, coord2idx[make_mytuple(u, v + q, n)]) -= eta * zeta;
329 M(i, coord2idx[make_mytuple(0, v, n)]) -= rho * zeta;
330 M(i, coord2idx[make_mytuple(u, 0, n)]) -= rho * zeta;
332 M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * (1 - zeta);
333 M(i, coord2idx[make_mytuple(0, n, 0)]) += eta * (1 - zeta);
334 M(i, coord2idx[make_mytuple(0, 0, 0)]) += rho * (1 - zeta);
335 M(i, coord2idx[make_mytuple(n, 0, n)]) += xi * zeta;
336 M(i, coord2idx[make_mytuple(0, n, n)]) += eta * zeta;
337 M(i, coord2idx[make_mytuple(0, 0, n)]) += rho * zeta;
346 const int szInt = (order - 2) * ((order - 2) + 1) * (2 * (order - 2) + 1) / 6;
348 (order + 1) * ((order + 1) + 1) * (2 * (order + 1) + 1) / 6;
349 const int szInc = szComp - szInt;
353 double2int(monomials, coordinates);
355 std::map<mytuple, int> coord2idx;
356 for(
int i = 0; i < szInc; ++i) {
357 int u = coordinates(i, 0);
358 int v = coordinates(i, 1);
359 int w = order - coordinates(i, 2);
360 coord2idx[make_mytuple(u, v, w)] = i;
365 for(
int i = 0; i < szInt; ++i) {
366 int u = coordinates(szInc + i, 0);
367 int v = coordinates(szInc + i, 1);
368 int w = order - coordinates(szInc + i, 2);
371 double xi = (double)u / n;
372 double eta = (double)v / n;
373 double rho = (double)q / n;
374 double tau = (double)r / n;
375 double xip = (double)u / (n - w);
376 double etap = (double)v / (n - w);
379 M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - xip;
380 M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - etap;
381 M(i, coord2idx[make_mytuple(n - w, v, w)]) += xip;
382 M(i, coord2idx[make_mytuple(u, n - w, w)]) += etap;
384 M(i, coord2idx[make_mytuple(u, v, 0)]) += rho * tau;
385 M(i, coord2idx[make_mytuple(u + w, v, 0)]) += xi * tau;
386 M(i, coord2idx[make_mytuple(u + w, v + w, 0)]) += xi * eta;
387 M(i, coord2idx[make_mytuple(u, v + w, 0)]) += rho * eta;
389 M(i, coord2idx[make_mytuple(0, 0, w)]) -= (1 - xip) * (1 - etap);
390 M(i, coord2idx[make_mytuple(n - w, 0, w)]) -= xip * (1 - etap);
391 M(i, coord2idx[make_mytuple(n - w, n - w, w)]) -= xip * etap;
392 M(i, coord2idx[make_mytuple(0, n - w, w)]) -= (1 - xip) * etap;
394 M(i, coord2idx[make_mytuple(0, v, 0)]) -= rho * tau;
395 M(i, coord2idx[make_mytuple(u, 0, 0)]) -= rho * tau;
396 M(i, coord2idx[make_mytuple(u + w, 0, 0)]) -= xi * tau;
397 M(i, coord2idx[make_mytuple(n, v, 0)]) -= xi * tau;
398 M(i, coord2idx[make_mytuple(n, v + w, 0)]) -= xi * eta;
399 M(i, coord2idx[make_mytuple(u + w, n, 0)]) -= xi * eta;
400 M(i, coord2idx[make_mytuple(u, n, 0)]) -= rho * eta;
401 M(i, coord2idx[make_mytuple(0, v + w, 0)]) -= rho * eta;
403 M(i, coord2idx[make_mytuple(0, 0, 0)]) += rho * tau;
404 M(i, coord2idx[make_mytuple(n, 0, 0)]) += xi * tau;
405 M(i, coord2idx[make_mytuple(n, n, 0)]) += xi * eta;
406 M(i, coord2idx[make_mytuple(0, n, 0)]) += rho * eta;
416 const int szInc = 3 * order;
417 const int szComp = (order + 1) * (order + 2) / 2;
418 const int szInt = szComp - szInc;
422 double2int(monomials, coordinates);
424 std::map<std::pair<int, int>,
int> coord2idx;
425 for(
int i = 0; i < szInc; ++i) {
426 int u = coordinates(i, 0);
427 int v = coordinates(i, 1);
428 coord2idx[std::make_pair(u, v)] = i;
433 for(
int i = 0; i < szInt; ++i) {
434 int u = coordinates(szInc + i, 0);
435 int v = coordinates(szInc + i, 1);
440 mu = (double)u / (n - v);
441 M(i, coord2idx[std::make_pair(0, v)]) += 1 - mu;
442 M(i, coord2idx[std::make_pair(n - v, v)]) += mu;
445 mu = (double)v / (u + v);
446 M(i, coord2idx[std::make_pair(u + v, 0)]) += 1 - mu;
447 M(i, coord2idx[std::make_pair(0, u + v)]) += mu;
451 mu = (double)v / (n - u);
452 M(i, coord2idx[std::make_pair(u, 0)]) += 1 - mu;
453 M(i, coord2idx[std::make_pair(u, n - u)]) += mu;
465 const int szInc = 4 * order;
466 const int szComp = (order + 1) * (order + 1);
467 const int szInt = szComp - szInc;
471 double2int(monomials, coordinates);
473 std::map<std::pair<int, int>,
int> coord2idx;
474 for(
int i = 0; i < szInc; ++i) {
475 int u = coordinates(i, 0);
476 int v = coordinates(i, 1);
477 coord2idx[std::make_pair(u, v)] = i;
482 for(
int i = 0; i < szInt; ++i) {
483 int u = coordinates(szInc + i, 0);
484 int v = coordinates(szInc + i, 1);
485 double eta = (double)v / n;
487 M(i, coord2idx[std::make_pair(u, 0)]) += 1 - eta;
488 M(i, coord2idx[std::make_pair(u, n)]) += eta;
499 const int szInt = (order - 3) * (order - 2) * (order - 1) / 6;
500 const int szComp = (order + 1) * (order + 2) * (order + 3) / 6;
501 const int szInc = szComp - szInt;
505 double2int(monomials, coordinates);
507 std::map<mytuple, int> coord2idx;
508 for(
int i = 0; i < szInc; ++i) {
509 int u = coordinates(i, 0);
510 int v = coordinates(i, 1);
511 int w = coordinates(i, 2);
512 coord2idx[make_mytuple(u, v, w)] = i;
517 for(
int i = 0; i < szInt; ++i) {
518 int u = coordinates(szInc + i, 0);
519 int v = coordinates(szInc + i, 1);
520 int w = coordinates(szInc + i, 2);
525 mu = (double)u / (n - v - w);
526 M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - mu;
527 M(i, coord2idx[make_mytuple(n - v - w, v, w)]) += mu;
530 mu = (double)v / (n - u - w);
531 M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - mu;
532 M(i, coord2idx[make_mytuple(u, n - u - w, w)]) += mu;
536 mu = (double)w / (n - u - v);
537 M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - mu;
538 M(i, coord2idx[make_mytuple(u, v, n - u - v)]) += mu;
541 mu = (double)v / (u + v);
542 M(i, coord2idx[make_mytuple(u + v, 0, w)]) += 1 - mu;
543 M(i, coord2idx[make_mytuple(0, u + v, w)]) += mu;
546 mu = (double)w / (v + w);
547 M(i, coord2idx[make_mytuple(u, v + w, 0)]) += 1 - mu;
548 M(i, coord2idx[make_mytuple(u, 0, v + w)]) += mu;
551 mu = (double)w / (u + w);
552 M(i, coord2idx[make_mytuple(u + w, v, 0)]) += 1 - mu;
553 M(i, coord2idx[make_mytuple(0, v, u + w)]) += mu;
565 const int szInt = (order - 1) * (order - 1) * (order - 1);
566 const int szComp = (order + 1) * (order + 1) * (order + 1);
567 const int szInc = szComp - szInt;
571 double2int(monomials, coordinates);
573 std::map<mytuple, int> coord2idx;
574 for(
int i = 0; i < szInc; ++i) {
575 int u = coordinates(i, 0);
576 int v = coordinates(i, 1);
577 int w = coordinates(i, 2);
578 coord2idx[make_mytuple(u, v, w)] = i;
583 for(
int i = 0; i < szInt; ++i) {
584 int u = coordinates(szInc + i, 0);
585 int v = coordinates(szInc + i, 1);
586 int w = coordinates(szInc + i, 2);
592 M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - eta;
593 M(i, coord2idx[make_mytuple(n, v, w)]) += eta;
597 M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - eta;
598 M(i, coord2idx[make_mytuple(u, n, w)]) += eta;
603 M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - eta;
604 M(i, coord2idx[make_mytuple(u, v, n)]) += eta;
616 const int szInt = (order - 1) * (order - 2) * (order - 1) / 2;
617 const int szComp = (order + 1) * (order + 1) * (order + 2) / 2;
618 const int szInc = szComp - szInt;
622 double2int(monomials, coordinates);
624 std::map<mytuple, int> coord2idx;
625 for(
int i = 0; i < szInc; ++i) {
626 int u = coordinates(i, 0);
627 int v = coordinates(i, 1);
628 int w = coordinates(i, 2);
629 coord2idx[make_mytuple(u, v, w)] = i;
634 for(
int i = 0; i < szInt; ++i) {
635 int u = coordinates(szInc + i, 0);
636 int v = coordinates(szInc + i, 1);
637 int w = coordinates(szInc + i, 2);
642 mu = (double)u / (n - v);
643 M(i, coord2idx[make_mytuple(0, v, w)]) += 1 - mu;
644 M(i, coord2idx[make_mytuple(n - v, v, w)]) += mu;
647 mu = (double)v / (u + v);
648 M(i, coord2idx[make_mytuple(u + v, 0, w)]) += 1 - mu;
649 M(i, coord2idx[make_mytuple(0, u + v, w)]) += mu;
652 mu = (double)v / (n - u);
653 M(i, coord2idx[make_mytuple(u, 0, w)]) += 1 - mu;
654 M(i, coord2idx[make_mytuple(u, n - u, w)]) += mu;
659 M(i, coord2idx[make_mytuple(u, v, 0)]) += 1 - eta;
660 M(i, coord2idx[make_mytuple(u, v, n)]) += eta;