Quadrature.cc 51.2 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20
21


22
23
24
25
26
#include "Quadrature.h"
#include "FixVec.h"
#include "AbstractFunction.h"
#include <algorithm>

27
28
using namespace std;

29
30
31
32
namespace AMDiS {

  const int Quadrature::maxNQuadPoints[4] = {0, 10, 61, 64};

33
  list<FastQuadrature*> FastQuadrature::fastQuadList;
34
35
36
  int FastQuadrature::max_points = 0;

  Quadrature::Quadrature(const Quadrature& q)
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
40
41
42
43
    : name(q.name)
    , degree(q.degree)
    , dim(q.dim)
    , n_points(q.n_points)
    , lambda(new VectorOfFixVecs<DimVec<double> >(*(q.lambda)))
    , w(q.w)
  {}
44
45
46
47
48
49
50

  /****************************************************************************/
  /*  initialize gradient values of a function f in local coordinates at the  */
  /*  quadrature points                                                       */
  /****************************************************************************/

  const WorldVector<double>
51
52
  *Quadrature::grdFAtQp(const AbstractFunction<WorldVector<double>,
			DimVec<double> >& f,
53
54
			WorldVector<double>* vec) const
  {
55
    static WorldVector<double> *quad_vec_d = NULL;
56
    static size_t size = 0;
57
58
59
    WorldVector<double> *val;
    WorldVector<double> grd;

60
61
62
    if (vec) {
      val = vec;
    } else {
63
      if (static_cast<int>(size) < n_points) {
64
	size_t  new_size = std::max(maxNQuadPoints[dim], n_points);
Thomas Witkowski's avatar
Thomas Witkowski committed
65
66
	delete [] quad_vec_d;
	quad_vec_d = new WorldVector<double>[new_size];
67
	size = new_size;
68
      }
69
70
      val = quad_vec_d;
    }
71
72
73

    int dow = Global::getGeo(WORLD);

74
75
76
77
78
    for (int i = 0; i < n_points; i++) {
      grd = f((*lambda)[i]);
      for (int j = 0; j < dow; j++)
	val[i][j] = grd[j];
    }
79

80
81
82
    return val;
  }

83
84
  const double *Quadrature::fAtQp(const AbstractFunction<double, DimVec<double> >& f,
				  double *vec) const
85
  {
86
    static double *quad_vec = NULL;
87
    static size_t size = 0;
88
    double *val;
89

90
91
92
    if (vec) {
      val = vec;
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
93
      if (static_cast<int>(size) < n_points) {
94
	size_t new_size = std::max(maxNQuadPoints[dim], n_points);
Thomas Witkowski's avatar
Thomas Witkowski committed
95
96
	if (quad_vec)
	  delete [] quad_vec;
97
	quad_vec = new double[new_size];
98
	size = new_size;
99
      }
100
101
      val = quad_vec;
    }
102

103
    for (int i = 0; i < n_points; i++)
104
      val[i] = f((*lambda)[i]);
105

106
107
108
109
    return(const_cast<const double *>(val));
  }


Praetorius, Simon's avatar
Praetorius, Simon committed
110
  QuadratureFactory::QuadratureFactory()
111
112
  {

113
    TEST_EXIT(x0_1d == NULL)("static quadratures already initialized\n");
114
115
116
117
118
119
120
121
122

#define  zero  0.0
#define  one   1.0
#define  half  0.5
#define  third 1.0/3.0
#define  quart 1.0/4.0

#define  StdVol 1.0

123
    x_0d = createAndInit(0, 1, 1.0);
124

125
    w_0d = createAndInitArray(1, StdVol * 1.0);
126

Praetorius, Simon's avatar
Praetorius, Simon committed
127
    quad_0d[0].reset(new Quadrature("0d", 0, 0, 1, x_0d, w_0d));
128
129
130
131
132
133
134
135
136
137
138

    /****************************************************************************/
    /*  1d quadrature formulas using 2 barycentric coordinates                  */
    /****************************************************************************/

#define MAX_QUAD_DEG_1d   19

    /****************************************************************************/
    /*  quadrature exact on P_1                                                 */
    /****************************************************************************/

139
140
    x0_1d = createAndInit(1, 1, 0.5, 0.5);
    w0_1d = createAndInitArray(1, StdVol * 1.0);
141
142
143
144
145

    /****************************************************************************/
    /*  quadrature exact on P_3                                                 */
    /****************************************************************************/

146
    x1_1d = createAndInit(1, 2,
147
148
149
			  0.788675134594813, 0.211324865405187,
			  0.211324865405187, 0.788675134594813);
    w1_1d = createAndInitArray(2, StdVol * 0.5, StdVol * 0.5);
150
151
152
153
154
155

    /****************************************************************************/
    /*  quadrature exact on P_5                                                 */
    /****************************************************************************/


156
157
158
159
    x2_1d = createAndInit(1, 3,
			  0.887298334620741, 0.112701665379259,
			  0.500000000000000, 0.500000000000000,
			  0.112701665379259, 0.887298334620741);
160
    w2_1d = createAndInitArray(3,
161
162
163
			       StdVol * 0.277777777777778,
			       StdVol * 0.444444444444444,
			       StdVol * 0.277777777777778);
164
165
166
167
168

    /****************************************************************************/
    /*  quadrature exact on P_7                                                 */
    /****************************************************************************/

169
170
171
172
173
    x3_1d = createAndInit(1, 4,
			  0.930568155797026, 0.069431844202973,
			  0.669990521792428, 0.330009478207572,
			  0.330009478207572, 0.669990521792428,
			  0.069431844202973, 0.930568155797026);
174
    w3_1d = createAndInitArray(4,
175
176
177
178
			       StdVol * 0.173927422568727,
			       StdVol * 0.326072577431273,
			       StdVol * 0.326072577431273,
			       StdVol * 0.173927422568727);
179
180
181
182
183

    /****************************************************************************/
    /*  quadrature exact on P_9                                                 */
    /****************************************************************************/

184
185
186
187
188
189
    x4_1d = createAndInit(1, 5,
			  0.953089922969332, 0.046910077030668,
			  0.769234655052841, 0.230765344947159,
			  0.500000000000000, 0.500000000000000,
			  0.230765344947159, 0.769234655052841,
			  0.046910077030668, 0.953089922969332);
190
    w4_1d = createAndInitArray(5,
191
192
193
194
195
			       StdVol * 0.118463442528095,
			       StdVol * 0.239314335249683,
			       StdVol * 0.284444444444444,
			       StdVol * 0.239314335249683,
			       StdVol * 0.118463442528095);
196
197
198
199
200

    /****************************************************************************/
    /*  quadrature exact on P_11                                                */
    /****************************************************************************/

201
202
203
204
205
206
207
    x5_1d = createAndInit(1, 6,
			  0.966234757101576, 0.033765242898424,
			  0.830604693233133, 0.169395306766867,
			  0.619309593041598, 0.380690406958402,
			  0.380690406958402, 0.619309593041598,
			  0.169395306766867, 0.830604693233133,
			  0.033765242898424, 0.966234757101576);
208
    w5_1d = createAndInitArray(6,
209
210
211
212
213
214
			       StdVol * 0.085662246189585,
			       StdVol * 0.180380786524069,
			       StdVol * 0.233956967286345,
			       StdVol * 0.233956967286345,
			       StdVol * 0.180380786524069,
			       StdVol * 0.085662246189585);
215
216
217
218
219

    /****************************************************************************/
    /*  quadrature exact on P_13                                                */
    /****************************************************************************/

220
221
222
223
224
225
226
227
    x6_1d = createAndInit(1, 7,
			  0.974553956171380, 0.025446043828620,
			  0.870765592799697, 0.129234407200303,
			  0.702922575688699, 0.297077424311301,
			  0.500000000000000, 0.500000000000000,
			  0.297077424311301, 0.702922575688699,
			  0.129234407200303, 0.870765592799697,
			  0.025446043828620, 0.974553956171380);
228
    w6_1d = createAndInitArray(7,
229
230
231
232
233
234
235
			       StdVol * 0.064742483084435,
			       StdVol * 0.139852695744614,
			       StdVol * 0.190915025252559,
			       StdVol * 0.208979591836735,
			       StdVol * 0.190915025252559,
			       StdVol * 0.139852695744614,
			       StdVol * 0.064742483084435);
236
237
238
239
240

    /****************************************************************************/
    /*  quadrature exact on P_15                                                */
    /****************************************************************************/

241
    x7_1d = createAndInit(1, 8,
242
243
244
245
246
247
248
249
			  0.980144928248768, 0.019855071751232,
			  0.898333238706813, 0.101666761293187,
			  0.762766204958164, 0.237233795041836,
			  0.591717321247825, 0.408282678752175,
			  0.408282678752175, 0.591717321247825,
			  0.237233795041836, 0.762766204958164,
			  0.101666761293187, 0.898333238706813,
			  0.019855071751232, 0.980144928248768);
250
    w7_1d = createAndInitArray(8,
251
252
253
254
255
256
257
258
			       StdVol * 0.050614268145188,
			       StdVol * 0.111190517226687,
			       StdVol * 0.156853322938943,
			       StdVol * 0.181341891689181,
			       StdVol * 0.181341891689181,
			       StdVol * 0.156853322938943,
			       StdVol * 0.111190517226687,
			       StdVol * 0.050614268145188);
259
260
261
262
263

    /****************************************************************************/
    /*  quadrature exact on P_17                                                */
    /****************************************************************************/

264
265
266
267
268
269
270
271
272
273
    x8_1d = createAndInit(1, 9,
			  0.984080119753813, 0.015919880246187,
			  0.918015553663318, 0.081984446336682,
			  0.806685716350295, 0.193314283649705,
			  0.662126711701905, 0.337873288298095,
			  0.500000000000000, 0.500000000000000,
			  0.337873288298095, 0.662126711701905,
			  0.193314283649705, 0.806685716350295,
			  0.081984446336682, 0.918015553663318,
			  0.015919880246187, 0.984080119753813);
274
    w8_1d = createAndInitArray(9,
275
276
277
278
279
280
281
282
283
			       StdVol * 0.040637194180787,
			       StdVol * 0.090324080347429,
			       StdVol * 0.130305348201467,
			       StdVol * 0.156173538520001,
			       StdVol * 0.165119677500630,
			       StdVol * 0.156173538520001,
			       StdVol * 0.130305348201467,
			       StdVol * 0.090324080347429,
			       StdVol * 0.040637194180787);
284
285
286
287
288

    /****************************************************************************/
    /*  quadrature exact on P_19                                                */
    /****************************************************************************/

289
290
291
292
293
294
295
296
297
298
299
    x9_1d = createAndInit(1, 10,
			  0.986953264258586, 0.013046735741414,
			  0.932531683344493, 0.067468316655508,
			  0.839704784149512, 0.160295215850488,
			  0.716697697064623, 0.283302302935377,
			  0.574437169490815, 0.425562830509185,
			  0.425562830509185, 0.574437169490815,
			  0.283302302935377, 0.716697697064623,
			  0.160295215850488, 0.839704784149512,
			  0.067468316655508, 0.932531683344493,
			  0.013046735741414, 0.986953264258586);
300
    w9_1d = createAndInitArray(10,
301
302
303
304
305
306
307
308
309
310
			       StdVol * 0.033335672154344,
			       StdVol * 0.074725674575291,
			       StdVol * 0.109543181257991,
			       StdVol * 0.134633359654998,
			       StdVol * 0.147762112357376,
			       StdVol * 0.147762112357376,
			       StdVol * 0.134633359654998,
			       StdVol * 0.109543181257991,
			       StdVol * 0.074725674575291,
			       StdVol * 0.033335672154344);
311

Praetorius, Simon's avatar
Praetorius, Simon committed
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    quad_1d[0].reset(new Quadrature("1d-Gauss: P_1", 1, 1, 1, x0_1d, w0_1d)); /* P_0   */
    quad_1d[1].reset(new Quadrature("1d-Gauss: P_1", 1, 1, 1, x0_1d, w0_1d)); /* P_1   */
    quad_1d[2].reset(new Quadrature("1d-Gauss: P_3", 3, 1, 2, x1_1d, w1_1d)); /* P_2   */
    quad_1d[3].reset(new Quadrature("1d-Gauss: P_3", 3, 1, 2, x1_1d, w1_1d)); /* P_3   */
    quad_1d[4].reset(new Quadrature("1d-Gauss: P_5", 5, 1, 3, x2_1d, w2_1d)); /* P_4   */
    quad_1d[5].reset(new Quadrature("1d-Gauss: P_5", 5, 1, 3, x2_1d, w2_1d)); /* P_5   */
    quad_1d[6].reset(new Quadrature("1d-Gauss: P_7", 7, 1, 4, x3_1d, w3_1d)); /* P_6   */
    quad_1d[7].reset(new Quadrature("1d-Gauss: P_7", 7, 1, 4, x3_1d, w3_1d)); /* P_7   */
    quad_1d[8].reset(new Quadrature("1d-Gauss: P_9", 9, 1, 5, x4_1d, w4_1d)); /* P_8   */
    quad_1d[9].reset(new Quadrature("1d-Gauss: P_9", 9, 1, 5, x4_1d, w4_1d)); /* P_9   */
    quad_1d[10].reset(new Quadrature("1d-Gauss: P_11", 11, 1, 6, x5_1d, w5_1d)); /* P_10  */
    quad_1d[11].reset(new Quadrature("1d-Gauss: P_11", 11, 1, 6, x5_1d, w5_1d)); /* P_11  */
    quad_1d[12].reset(new Quadrature("1d-Gauss: P_13", 13, 1, 7, x6_1d, w6_1d)); /* P_12  */
    quad_1d[13].reset(new Quadrature("1d-Gauss: P_13", 13, 1, 7, x6_1d, w6_1d)); /* P_13  */
    quad_1d[14].reset(new Quadrature("1d-Gauss: P_15", 15, 1, 8, x7_1d, w7_1d)); /* P_14  */
    quad_1d[15].reset(new Quadrature("1d-Gauss: P_15", 15, 1, 8, x7_1d, w7_1d)); /* P_15  */
    quad_1d[16].reset(new Quadrature("1d-Gauss: P_17", 17, 1, 9, x8_1d, w8_1d)); /* P_16  */
    quad_1d[17].reset(new Quadrature("1d-Gauss: P_17", 17, 1, 9, x8_1d, w8_1d)); /* P_17  */
    quad_1d[18].reset(new Quadrature("1d-Gauss: P_19", 19, 1, 10, x9_1d, w9_1d)); /* P_18 */
    quad_1d[19].reset(new Quadrature("1d-Gauss: P_19", 19, 1, 10, x9_1d, w9_1d));/* P_19 */
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

#undef StdVol
    /****************************************************************************/
    /****************************************************************************/
    /****************************************************************************/
    /*  2d quadrature formulas using 3 barycentric coordinates                  */
    /****************************************************************************/
    /****************************************************************************/
    /****************************************************************************/

#define CYCLE(c1,c2,c3) c1, c2, c3, c2, c3, c1, c3, c1, c2

#define ALL_COMB(c1,c2,c3)  CYCLE(c1,c2,c3), CYCLE(c1,c3,c2)
#define W_CYCLE(w1)         w1, w1, w1
#define W_ALL_COMB(w1)      W_CYCLE(w1), W_CYCLE(w1)

#define MAX_QUAD_DEG_2d   17

#define StdVol 0.5

    /****************************************************************************/
    /*  quadrature exact on P 1                                                 */
    /****************************************************************************/

#define N1  1

#define c1  1.0/3.0
#define w1  StdVol*1.0

361
    x1_2d = createAndInit(2, 1, c1, c1, c1);
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    w1_2d = createAndInitArray(N1, w1);

#undef c1
#undef w1

    /****************************************************************************/
    /*  quadrature exact on P 2                                                 */
    /* Stroud, A.H.: Approximate calculation of multiple integrals              */
    /* Prentice-Hall Series in Automatic Computation. (1971)                    */
    /* optimal number of points: 3, number of points: 3                         */
    /* interior points, completly symmetric in barycentric coordinates          */
    /****************************************************************************/

#define N2  3

#define c1  2.0/3.0
#define c2  1.0/6.0
#define w1  StdVol/3.0

381
    x2_2d = createAndInit(2, 3, CYCLE(c1, c2, c2));
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
    w2_2d = createAndInitArray(3, W_CYCLE(w1));

#undef c1
#undef c2
#undef w1

    /****************************************************************************/
    /*  quadrature exact on P_3                                                 */
    /****************************************************************************/

#define N3  6

#define c1  0.0
#define c2  1.0/2.0
#define c3  4.0/6.0
#define c4  1.0/6.0
#define w1  StdVol*1.0/30.0
#define w2  StdVol*9.0/30.0

401
    x3_2d = createAndInit(2, N3, CYCLE(c1, c2, c2), CYCLE(c3, c4, c4));
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
    w3_2d = createAndInitArray(N3, W_CYCLE(w1), W_CYCLE(w2));

#undef c1
#undef c2
#undef c3
#undef c4
#undef w1
#undef w2

    /****************************************************************************/
    /*  quadrature exact on P 4                                                 */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nearly optimal number of (interior) points, positive wheights  (PI)      */
    /* number of points: 6, optimal number of points: 6                         */
    /****************************************************************************/

#define N4  6

#define c1  0.816847572980459
#define c2  0.091576213509771
#define c3  0.108103018168070
#define c4  0.445948490915965
#define w1  StdVol*0.109951743655322
#define w2  StdVol*0.223381589678011

428
    x4_2d = createAndInit(2, 6, CYCLE(c1, c2, c2), CYCLE(c3, c4, c4));
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
    w4_2d = createAndInitArray(6, W_CYCLE(w1), W_CYCLE(w2));

#undef c1
#undef c2
#undef c3
#undef c4
#undef w1
#undef w2


    /****************************************************************************/
    /*  quadrature exact on P 5                                                 */
    /****************************************************************************/

    /****************************************************************************/
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* number of points: 7, optimal number of points: 7                         */
    /****************************************************************************/

#define N5   7

#define c1   1.0/3.0
#define c2   0.797426985353087
#define c3   0.101286507323456
#define c4   0.059715871789770
#define c5   0.470142064105115
#define w1   StdVol*0.225000000000000
#define w2   StdVol*0.125939180544827
#define w3   StdVol*0.132394152788506

461
    x5_2d = createAndInit(2, 7, c1, c1, c1, CYCLE(c2, c3, c3), CYCLE(c4, c5, c5));
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
    w5_2d = createAndInitArray(N5, w1, W_CYCLE(w2), W_CYCLE(w3));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef w1
#undef w2
#undef w3

    /****************************************************************************/
    /*  quadrature exact on P 6: only 12 point rule available in the literature */
    /*  ->  use quadrature exact on P 7 with 12 points                          */
    /****************************************************************************/

    /****************************************************************************/
    /*  quadrature exact on P 7                                                 */
    /****************************************************************************/

    /****************************************************************************/
    /* Gatermann, Karin: The construction of symmetric cubature formulas for    */
    /* the square and the triangle. Computing 40, No.3, 229-240 (1988)          */
    /* optimal number of points: 12, number of points: 12                       */
    /* only interior points, not completly symmetric in barycentric coordinates */
    /****************************************************************************/

#define N7   12

#define c1   0.06238226509439084
#define c2   0.06751786707392436
#define c3   0.87009986783168480
#define c4   0.05522545665692000
#define c5   0.32150249385201560
#define c6   0.62327204949106440
#define c7   0.03432430294509488
#define c8   0.66094919618679800
#define c9   0.30472650086810720
#define c10  0.5158423343536001
#define c11  0.2777161669764050
#define c12  0.2064414986699949
#define w1   0.02651702815743450
#define w2   0.04388140871444811
#define w3   0.02877504278497528
#define w4   0.06749318700980879

508
509
510
    x7_2d = createAndInit(2, 12,
			  CYCLE(c1, c2, c3), CYCLE(c4, c5, c6),
			  CYCLE(c7, c8, c9), CYCLE(c10, c11, c12));
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
    w7_2d = createAndInitArray(N7, W_CYCLE(w1), W_CYCLE(w2),
			       W_CYCLE(w3), W_CYCLE(w4));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef c11
#undef c12
#undef w1
#undef w2
#undef w3
#undef w4


    /****************************************************************************/
    /*  quadrature exact on P 8                                                 */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* number of points: 16, optimal number of points: 15                       */
    /* only interior points, completly symmetric in barycentric coordinates     */
    /****************************************************************************/

#define N8  16

#define c1   1.0/3.0
#define c2   0.081414823414554
#define c3   0.459292588292723
#define c4   0.658861384496480
#define c5   0.170569307751760
#define c6   0.898905543365938
#define c7   0.050547228317031
#define c8   0.008394777409958
#define c9   0.263112829634638
#define c10  0.728492392955404
#define w1   StdVol*0.144315607677787
#define w2   StdVol*0.095091634267285
#define w3   StdVol*0.103217370534718
#define w4   StdVol*0.032458497623198
#define w5   StdVol*0.027230314174435

559
    x8_2d = createAndInit(2, 16,
560
			  c1, c1, c1,
561
562
563
564
			  CYCLE(c2, c3, c3),
			  CYCLE(c4, c5, c5),
			  CYCLE(c6, c7, c7),
			  ALL_COMB(c8, c9, c10));
565
566
    w8_2d = createAndInitArray(N8, w1, W_CYCLE(w2), W_CYCLE(w3),
			       W_CYCLE(w4), W_ALL_COMB(w5));
567

568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef w1
#undef w2
#undef w3
#undef w4
#undef w5

    /****************************************************************************/
    /*  quadrature exact on P 9                                                 */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* optimal number of points: ?, number of points: 19                        */
    /* only interior points, completly symmetric in barycentric coordinates     */
    /****************************************************************************/

#define N9  19

#define c1   1.0/3.0
#define c2   0.020634961602525
#define c3   0.489682519198738
#define c4   0.125820817014127
#define c5   0.437089591492937
#define c6   0.623592928761935
#define c7   0.188203535619033
#define c8   0.910540973211095
#define c9   0.044729513394453
#define c10  0.036838412054736
#define c11  0.221962989160766
#define c12  0.741198598784498
#define w1   StdVol*0.097135796282799
#define w2   StdVol*0.031334700227139
#define w3   StdVol*0.077827541004774
#define w4   StdVol*0.079647738927210
#define w5   StdVol*0.025577675658698
#define w6   StdVol*0.043283539377289

615
616
617
618
619
620
621
    x9_2d = createAndInit(2, 19,
			  c1, c1, c1,
			  CYCLE(c2, c3, c3),
			  CYCLE(c4, c5, c5),
			  CYCLE(c6, c7, c7),
			  CYCLE(c8, c9, c9),
			  ALL_COMB(c10, c11, c12));
622
    w9_2d = createAndInitArray(N9, w1,
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
			       W_CYCLE(w2),
			       W_CYCLE(w3),
			       W_CYCLE(w4),
			       W_CYCLE(w5),
			       W_ALL_COMB(w6));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef c11
#undef c12
#undef w1
#undef w2
#undef w3
#undef w4
#undef w5
#undef w6

    /****************************************************************************/
    /*  quadrature exact on P 10                                                */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* optimal number of points: ?, number of points: 25                        */
    /* only interior points, completly symmetric in barycentric coordinates     */
    /****************************************************************************/

#define N10 25

#define c1   1.0/3.0

#define c2   0.028844733232685
#define c3   0.485577633383657

#define c4   0.781036849029926
#define c5   0.109481575485037

#define c6   0.141707219414880
#define c7   0.307939838764121
#define c8   0.550352941820999

#define c9   0.025003534762686
#define c10  0.246672560639903
#define c11  0.728323904597411

#define c12  0.009540815400299
#define c13  0.066803251012200
#define c14  0.923655933587500

#define w1   StdVol*0.090817990382754
#define w2   StdVol*0.036725957756467
#define w3   StdVol*0.045321059435528
#define w4   StdVol*0.072757916845420
#define w5   StdVol*0.028327242531057
#define w6   StdVol*0.009421666963733

686
687
688
689
690
691
692
    x10_2d = createAndInit(2, 25,
			   c1, c1, c1,
			   CYCLE(c2, c3, c3),
			   CYCLE(c4, c5, c5),
			   ALL_COMB(c6, c7, c8),
			   ALL_COMB(c9, c10, c11),
			   ALL_COMB(c12, c13, c14));
693
    w10_2d = createAndInitArray(N10, w1,
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
				W_CYCLE(w2),
				W_CYCLE(w3),
				W_ALL_COMB(w4),
				W_ALL_COMB(w5),
				W_ALL_COMB(w6));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef c11
#undef c12
#undef c13
#undef c14
#undef w1
#undef w2
#undef w3
#undef w4
#undef w5
#undef w6

    /****************************************************************************/
    /*  quadrature exact on P 11                                                */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* optimal number of points: ?, number of points: 27                        */
    /* only interior points, completly symmetric in barycentric coordinates     */
    /****************************************************************************/

#define N11 27

#define c1  -0.069222096541517
#define c2   0.534611048270758

#define c3   0.202061394068290
#define c4   0.398969302965855

#define c5   0.593380199137435
#define c6   0.203309900431282

#define c7   0.761298175434837
#define c8   0.119350912282581

#define c9   0.935270103777448
#define c10  0.032364948111276

#define c11  0.050178138310495
#define c12  0.356620648261293
#define c13  0.593201213428213

#define c14  0.021022016536166
#define c15  0.171488980304042
#define c16  0.807489003159792

#define w1   StdVol*0.000927006328961
#define w2   StdVol*0.077149534914813
#define w3   StdVol*0.059322977380774
#define w4   StdVol*0.036184540503418
#define w5   StdVol*0.013659731002678
#define w6   StdVol*0.052337111962204
#define w7   StdVol*0.020707659639141

    x11_2d = createAndInit(2, 27,
			   CYCLE(c1,c2,c2),
			   CYCLE(c3,c4,c4),
			   CYCLE(c5,c6,c6),
			   CYCLE(c7,c8,c8),
			   CYCLE(c9,c10,c10),
			   ALL_COMB(c11,c12,c13),
			   ALL_COMB(c14,c15,c16));
    w11_2d = createAndInitArray(N11, W_CYCLE(w1),
				W_CYCLE(w2),
				W_CYCLE(w3),
				W_CYCLE(w4),
				W_CYCLE(w5),
				W_ALL_COMB(w6),
				W_ALL_COMB(w7));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef c11
#undef c12
#undef c13
#undef c14
#undef c15
#undef c16
#undef w1
#undef w2
#undef w3
#undef w4
#undef w5
#undef w6
#undef w7

    /****************************************************************************/
    /*  quadrature exact on P 12                                                */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* optimal number of points: 2, number of points: 25                        */
    /* only interior points, completly symmetric in barycentric coordinates     */
    /****************************************************************************/

#define N12 33

#define c1   0.023565220452390
#define c2   0.488217389773805

#define c3   0.120551215411079
#define c4   0.439724392294460

#define c5   0.457579229975768
#define c6   0.271210385012116

#define c7   0.744847708916828
#define c8   0.127576145541586
825

826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
#define c9   0.957365299093579
#define c10  0.021317350453210

#define c11  0.115343494534698
#define c12  0.275713269685514
#define c13  0.608943235779788

#define c14  0.022838332222257
#define c15  0.281325580989940
#define c16  0.695836086787803

#define c17  0.025734050548330
#define c18  0.116251915907597
#define c19  0.858014033544073

#define w1   StdVol*0.025731066440455
#define w2   StdVol*0.043692544538038
#define w3   StdVol*0.062858224217885
#define w4   StdVol*0.034796112930709
#define w5   StdVol*0.006166261051559
#define w6   StdVol*0.040371557766381
#define w7   StdVol*0.022356773202303
#define w8   StdVol*0.017316231108659

    x12_2d = createAndInit(2, 33,
			   CYCLE(c1,c2,c2),
			   CYCLE(c3,c4,c4),
			   CYCLE(c5,c6,c6),
			   CYCLE(c7,c8,c8),
			   CYCLE(c9,c10,c10),
			   ALL_COMB(c11,c12,c13),
			   ALL_COMB(c14,c15,c16),
			   ALL_COMB(c17,c18,c19));
    w12_2d = createAndInitArray(N12, W_CYCLE(w1),
				W_CYCLE(w2),
				W_CYCLE(w3),
				W_CYCLE(w4),
				W_CYCLE(w5),
				W_ALL_COMB(w6),
				W_ALL_COMB(w7),
				W_ALL_COMB(w8));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef c11
#undef c12
#undef c13
#undef c14
#undef c15
#undef c16
#undef c17
#undef c18
#undef c19
#undef w1
#undef w2
#undef w3
#undef w4
#undef w5
#undef w6
#undef w7
#undef w8

    /****************************************************************************/
    /*  quadrature exact on P 17                                                */
    /* Dunavant, D.A.: High degree efficient symmetrical Gaussian quadrature    */
    /* rules for the triangle. Int. J. Numer. Methods Eng. 21, 1129-1148 (1985) */
    /* nealy optimal number of (interior) points, positive wheights  (PI)       */
    /* optimal number of points: ?, number of points: 61                        */
    /* only interior points, completly symmetric in barycentric coordinates     */
    /****************************************************************************/

#define N17 61

#define c1   1.0/3.0
908

909
910
#define c2   0.005658918886452
#define c3   0.497170540556774
911

912
913
#define c4   0.035647354750751
#define c5   0.482176322624625
914

915
916
917
918
919
920
921
922
#define c6   0.099520061958437
#define c7   0.450239969020782

#define c8   0.199467521245206
#define c9   0.400266239377397

#define c10  0.495717464058095
#define c11  0.252141267970953
923

924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
#define c12  0.675905990683077
#define c13  0.162047004658461

#define c14  0.848248235478508
#define c15  0.075875882260746

#define c16  0.968690546064356
#define c17  0.015654726967822

#define c18  0.010186928826919
#define c19  0.334319867363658
#define c20  0.655493203809423

#define c21  0.135440871671036
#define c22  0.292221537796944
#define c23  0.572337590532020

#define c24  0.054423924290583
#define c25  0.319574885423190
#define c26  0.626001190286228

#define c27  0.012868560833637
#define c28  0.190704224192292
#define c29  0.796427214974071

#define c30  0.067165782413524
#define c31  0.180483211648746
#define c32  0.752351005937729

#define c33  0.014663182224828
#define c34  0.080711313679564
#define c35  0.904625504095608

#define w1   StdVol*0.033437199290803
#define w2   StdVol*0.005093415440507
#define w3   StdVol*0.014670864527638
#define w4   StdVol*0.024350878353672
#define w5   StdVol*0.031107550868969
#define w6   StdVol*0.031257111218620
#define w7   StdVol*0.024815654339665
#define w8   StdVol*0.014056073070557
#define w9   StdVol*0.003194676173779
#define w10  StdVol*0.008119655318993
#define w11  StdVol*0.026805742283163
#define w12  StdVol*0.018459993210822
#define w13  StdVol*0.008476868534328
#define w14  StdVol*0.018292796770025
#define w15  StdVol*0.006665632004165

    x17_2d = createAndInit(2, 61,
			   c1, c1, c1,
			   CYCLE(c2,c3,c3),
			   CYCLE(c4,c5,c5),
			   CYCLE(c6,c7,c7),
			   CYCLE(c8,c9,c9),
			   CYCLE(c10,c11,c11),
			   CYCLE(c12,c13,c13),
			   CYCLE(c14,c15,c15),
			   CYCLE(c16,c17,c17),
			   ALL_COMB(c18,c19,c20),
			   ALL_COMB(c21,c22,c23),
			   ALL_COMB(c24,c25,c26),
			   ALL_COMB(c27,c28,c29),
			   ALL_COMB(c30,c31,c32),
			   ALL_COMB(c33,c34,c35));
989
    w17_2d = createAndInitArray(N17, w1,
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
				W_CYCLE(w2),
				W_CYCLE(w3),
				W_CYCLE(w4),
				W_CYCLE(w5),
				W_CYCLE(w6),
				W_CYCLE(w7),
				W_CYCLE(w8),
				W_CYCLE(w9),
				W_ALL_COMB(w10),
				W_ALL_COMB(w11),
				W_ALL_COMB(w12),
				W_ALL_COMB(w13),
				W_ALL_COMB(w14),
				W_ALL_COMB(w15));

#undef c1
#undef c2
#undef c3
#undef c4
#undef c5
#undef c6
#undef c7
#undef c8
#undef c9
#undef c10
#undef c11
#undef c12
#undef c13
#undef c14
#undef c15
#undef c16
#undef c17
#undef c18
#undef c19
#undef c20
#undef c21
#undef c22
#undef c23
#undef c24
#undef c25
#undef c26
#undef c27
#undef c28
#undef c29
#undef c30
#undef c31
#undef c32
#undef c33
#undef c34
#undef c35

#undef w1
#undef w2
#undef w3
#undef w4
#undef w5
#undef w6
#undef w7
#undef w8
#undef w9
#undef w10
#undef w11
#undef w12
#undef w13
#undef w14
#undef w15

Praetorius, Simon's avatar
Praetorius, Simon committed
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
    quad_2d[0].reset(new Quadrature("2d-P_1", 1, 2, N1, x1_2d, w1_2d));   /* P 0  */
    quad_2d[1].reset(new Quadrature("2d-P_1", 1, 2, N1, x1_2d, w1_2d));   /* P 1  */
    quad_2d[2].reset(new Quadrature("2d  Stroud: P_2", 2, 2, N2, x2_2d, w2_2d));   /* P 2  */
    quad_2d[3].reset(new Quadrature("2d  Stroud: P_3", 3, 2, N3, x3_2d, w3_2d));   /* P 3  */
    quad_2d[4].reset(new Quadrature("2d  Dunavant: P_4", 4, 2, N4, x4_2d, w4_2d));   /* P 4  */
    quad_2d[5].reset(new Quadrature("2d  Dunavant: P_5", 5, 2, N5, x5_2d, w5_2d));   /* P 5  */
    quad_2d[6].reset(new Quadrature("2d  Gattermann: P_7", 7, 2, N7, x7_2d, w7_2d));   /* P 6  */
    quad_2d[7].reset(new Quadrature("2d  Gattermann: P_7", 7, 2, N7, x7_2d, w7_2d));   /* P 7  */
    quad_2d[8].reset(new Quadrature("2d  Dunavant: P_8", 8, 2, N8, x8_2d, w8_2d));   /* P 8  */
    quad_2d[9].reset(new Quadrature("2d  Dunavant: P_9", 9, 2, N9, x9_2d, w9_2d));   /* P 9  */
    quad_2d[10].reset(new Quadrature("2d  Dunavant: P_10", 10, 2, N10, x10_2d, w10_2d));/* P 10 */
    quad_2d[11].reset(new Quadrature("2d  Dunavant: P_11", 11, 2, N11, x11_2d, w11_2d));/* P 11 */
    quad_2d[12].reset(new Quadrature("2d  Dunavant: P_12", 12, 2, N12, x12_2d, w12_2d));/* P 12 */
    quad_2d[13].reset(new Quadrature("2d  Dunavant: P_17", 17, 2, N17, x17_2d, w17_2d));/* P 13 */
    quad_2d[14].reset(new Quadrature("2d  Dunavant: P_17", 17, 2, N17, x17_2d, w17_2d));/* P 14 */
    quad_2d[15].reset(new Quadrature("2d  Dunavant: P_17", 17, 2, N17, x17_2d, w17_2d));/* P 15 */
    quad_2d[16].reset(new Quadrature("2d  Dunavant: P_17", 17, 2, N17, x17_2d, w17_2d));/* P 16 */
    quad_2d[17].reset(new Quadrature("2d  Dunavant: P_17", 17, 2, N17, x17_2d, w17_2d)); /* P 17 */
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175


#undef StdVol
#undef N1
#undef N2
#undef N3
#undef N4
#undef N5
#undef N6
#undef N7
#undef N8
#undef N9
#undef N10
#undef N11
#undef N12
#undef N17

    /****************************************************************************/
    /*  3d quadrature formulas using 4 barycentric coordinates                  */
    /****************************************************************************/

#define MAX_QUAD_DEG_3d   7

#define StdVol (1.0/6.0)

    /****************************************************************************/
    /*  quadrature exact on P_1                                                 */
    /****************************************************************************/

    x1_3d = createAndInit(3, 1,
			  quart, quart, quart, quart);
    w1_3d = createAndInitArray(1, StdVol*one);



    /****************************************************************************/
    /*  Quad quadrature exact on P_2                                           */
    /****************************************************************************/

#define c14   0.585410196624969
#define c15   0.138196601125011

    x2_3d = createAndInit(3, 4,
			  c14, c15, c15, c15,
			  c15, c14, c15, c15,
			  c15, c15, c14, c15,
			  c15, c15, c15, c14);
    w2_3d = createAndInitArray(4, StdVol*quart, StdVol*quart,
			       StdVol*quart, StdVol*quart);

    /****************************************************************************/
    /*  quadrature exact on P_3                                                 */
    /****************************************************************************/

#define w8  1.0/40.0
#define w9  9.0/40.0

    x3_3d = createAndInit(3, 8,
			  one,  zero,  zero,  zero,
			  zero,   one,  zero,  zero,
			  zero,  zero,   one,  zero,
			  zero,  zero,  zero,   one,
			  zero, third, third, third,
			  third, zero, third, third,
			  third, third, zero, third,
			  third, third, third, zero);
    w3_3d = createAndInitArray(8,  StdVol*w8, StdVol*w8, StdVol*w8, StdVol*w8,
			       StdVol*w9, StdVol*w9, StdVol*w9, StdVol*w9);

    /****************************************************************************/
    /*  quadrature exact on P_4                                                 */
    /****************************************************************************/

#define c18  0.091971078
#define c19  0.724086765
#define c20  0.319793627
#define c21  0.040619116
#define c22  0.056350832
#define c23  0.443649167

#define w10  0.118518515999999990
#define w11  0.071937078000000002
#define w12  0.069068201999999995
#define w13  0.052910052911999995

    x4_3d = createAndInit(3, 15,
			  quart, quart, quart, quart,
			  c18, c18, c18, c19,
			  c18, c18, c19, c18,
			  c18, c19, c18, c18,
			  c19, c18, c18, c18,
			  c20, c20, c20, c21,
			  c20, c20, c21, c20,
			  c20, c21, c20, c20,
			  c21, c20, c20, c20,
			  c22, c22, c23, c23,
			  c22, c23, c22, c23,
			  c23, c22, c22, c23,
			  c22, c23, c23, c22,
			  c23, c22, c23, c22,
			  c23, c23, c22, c22);
1176
1177
    w4_3d = createAndInitArray(15, StdVol*w10,
			       StdVol*w11, StdVol*w11,
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
			       StdVol*w11, StdVol*w11,
			       StdVol*w12, StdVol*w12,
			       StdVol*w12, StdVol*w12,
			       StdVol*w13, StdVol*w13, StdVol*w13,
			       StdVol*w13, StdVol*w13, StdVol*w13);

    /****************************************************************************/
    /*  quadrature exact on P_5                                                 */
    /****************************************************************************/

    x5_3d = createAndInit(3, 15,
			  0.250000000000000, 0.250000000000000, 0.250000000000000, 0.250000000000000,
			  0.091971078052723, 0.091971078052723, 0.091971078052723, 0.724086765841831,
			  0.724086765841831, 0.091971078052723, 0.091971078052723, 0.091971078052723,
			  0.091971078052723, 0.724086765841831, 0.091971078052723, 0.091971078052723,
			  0.091971078052723, 0.091971078052723, 0.724086765841831, 0.091971078052723,
			  0.319793627829630, 0.319793627829630, 0.319793627829630, 0.040619116511110,
			  0.040619116511110, 0.319793627829630, 0.319793627829630, 0.319793627829630,
			  0.319793627829630, 0.040619116511110, 0.319793627829630, 0.319793627829630,
			  0.319793627829630, 0.319793627829630, 0.040619116511110, 0.319793627829630,
			  0.443649167310371, 0.056350832689629, 0.056350832689629, 0.443649167310371,
			  0.056350832689629, 0.443649167310371, 0.056350832689629, 0.443649167310371,
			  0.056350832689629, 0.056350832689629, 0.443649167310371, 0.443649167310371,
			  0.443649167310371, 0.056350832689629, 0.443649167310371, 0.056350832689629,
			  0.443649167310371, 0.443649167310371, 0.056350832689629, 0.056350832689629,
			  0.056350832689629, 0.443649167310371, 0.443649167310371, 0.056350832689629);
    w5_3d = createAndInitArray(15, StdVol*0.118518518518519,
			       StdVol*0.071937083779019,
			       StdVol*0.071937083779019,
			       StdVol*0.071937083779019,
			       StdVol*0.071937083779019,
			       StdVol*0.069068207226272,
			       StdVol*0.069068207226272,
			       StdVol*0.069068207226272,
			       StdVol*0.069068207226272,
			       StdVol*0.052910052910053,
			       StdVol*0.052910052910053,
			       StdVol*0.052910052910053,
			       StdVol*0.052910052910053,
			       StdVol*0.052910052910053,
			       StdVol*0.052910052910053);

    /****************************************************************************/
    /*  quadrature exact on P_7                                                 */
    /****************************************************************************/

    x7_3d = createAndInit(3, 64,
			  0.0485005494, 0.0543346112, 0.0622918076, 0.8348730318,
			  0.0485005494, 0.0543346112, 0.2960729005, 0.6010919389,
			  0.0485005494, 0.0543346112, 0.6010919389, 0.2960729005,
			  0.0485005494, 0.0543346112, 0.8348730300, 0.0622918093,
			  0.0485005494, 0.2634159753, 0.0477749033, 0.6403085720,
			  0.0485005494, 0.2634159753, 0.2270740686, 0.4610094066,
			  0.0485005494, 0.2634159753, 0.4610094066, 0.2270740686,
			  0.0485005494, 0.2634159753, 0.6403085706, 0.0477749047,
			  0.0485005494, 0.5552859758, 0.0275098315, 0.3687036433,
			  0.0485005494, 0.5552859758, 0.1307542021, 0.2654592727,
			  0.0485005494, 0.5552859758, 0.2654592727, 0.1307542021,
			  0.0485005494, 0.5552859758, 0.3687036425, 0.0275098323,
			  0.0485005494, 0.8185180165, 0.0092331459, 0.1237482881,
			  0.0485005494, 0.8185180165, 0.0438851337, 0.0890963004,
			  0.0485005494, 0.8185180165, 0.0890963004, 0.0438851337,
			  0.0485005494, 0.8185180165, 0.1237482879, 0.0092331462,
			  0.2386007376, 0.0434790928, 0.0498465199, 0.6680736497,
			  0.2386007376, 0.0434790928, 0.2369204606, 0.4809997090,
			  0.2386007376, 0.0434790928, 0.4809997090, 0.2369204606,
			  0.2386007376, 0.0434790928, 0.6680736482, 0.0498465214,
			  0.2386007376, 0.2107880664, 0.0382299497, 0.5123812464,
			  0.2386007376, 0.2107880664, 0.1817069135, 0.3689042825,
			  0.2386007376, 0.2107880664, 0.3689042825, 0.1817069135,
			  0.2386007376, 0.2107880664, 0.5123812453, 0.0382299508,
			  0.2386007376, 0.4443453248, 0.0220136390, 0.2950402987,
			  0.2386007376, 0.4443453248, 0.1046308045, 0.2124231331,
			  0.2386007376, 0.4443453248, 0.2124231331, 0.1046308045,
			  0.2386007376, 0.4443453248, 0.2950402980, 0.0220136396,
			  0.2386007376, 0.6549862048, 0.0073884546, 0.0990246030,
			  0.2386007376, 0.6549862048, 0.0351173176, 0.0712957400,
			  0.2386007376, 0.6549862048, 0.0712957400, 0.0351173176,
			  0.2386007376, 0.6549862048, 0.0990246028, 0.0073884548,
			  0.5170472951, 0.0275786260, 0.0316174612, 0.4237566177,
			  0.5170472951, 0.0275786260, 0.1502777622, 0.3050963168,
			  0.5170472951, 0.0275786260, 0.3050963168, 0.1502777622,
			  0.5170472951, 0.0275786260, 0.4237566168, 0.0316174621,
			  0.5170472951, 0.1337020823, 0.0242491141, 0.3250015085,
			  0.5170472951, 0.1337020823, 0.1152560157, 0.2339946069,
			  0.5170472951, 0.1337020823, 0.2339946069, 0.1152560157,
			  0.5170472951, 0.1337020823, 0.3250015078, 0.0242491148,
			  0.5170472951, 0.2818465779, 0.0139631689, 0.1871429581,
			  0.5170472951, 0.2818465779, 0.0663669280, 0.1347391990,
			  0.5170472951, 0.2818465779, 0.1347391990, 0.0663669280,
			  0.5170472951, 0.2818465779, 0.1871429577, 0.0139631693,
			  0.5170472951, 0.4154553004, 0.0046864691, 0.0628109354,
			  0.5170472951, 0.4154553004, 0.0222747832, 0.0452226213,
			  0.5170472951, 0.4154553004, 0.0452226213, 0.0222747832,
			  0.5170472951, 0.4154553004, 0.0628109352, 0.0046864693,
			  0.7958514179, 0.0116577407, 0.0133649937, 0.1791258477,
			  0.7958514179, 0.0116577407, 0.0635238021, 0.1289670393,
			  0.7958514179, 0.0116577407, 0.1289670393, 0.0635238021,
			  0.7958514179, 0.0116577407, 0.1791258473, 0.0133649941,
			  0.7958514179, 0.0565171087, 0.0102503252, 0.1373811482,
			  0.7958514179, 0.0565171087, 0.0487197855, 0.0989116879,
			  0.7958514179, 0.0565171087, 0.0989116879, 0.0487197855,
			  0.7958514179, 0.0565171087, 0.1373811479, 0.0102503255,
			  0.7958514179, 0.1191391593, 0.0059023608, 0.0791070620,
			  0.7958514179, 0.1191391593, 0.0280539153, 0.0569555075,
			  0.7958514179, 0.1191391593, 0.0569555075, 0.0280539153,
			  0.7958514179, 0.1191391593, 0.0791070618, 0.0059023610,
			  0.7958514179, 0.1756168040, 0.0019810139, 0.0265507642,
			  0.7958514179, 0.1756168040, 0.0094157572, 0.0191160209,
			  0.7958514179, 0.1756168040, 0.0191160209, 0.0094157572,
			  0.7958514179, 0.1756168040, 0.0265507642, 0.0019810140);
    w7_3d = createAndInitArray(64, StdVol*0.0156807540, StdVol*0.0293976870,
			       StdVol*0.0293976870, StdVol*0.0156807540,
			       StdVol*0.0235447608, StdVol*0.0441408300,
			       StdVol*0.0441408300, StdVol*0.0235447608,
			       StdVol*0.0150258564, StdVol*0.0281699100,
			       StdVol*0.0281699100, StdVol*0.0150258564,
			       StdVol*0.0036082374, StdVol*0.0067645878,
			       StdVol*0.0067645878, StdVol*0.0036082374,
			       StdVol*0.0202865376, StdVol*0.0380324358,
			       StdVol*0.0380324358, StdVol*0.0202865376,
			       StdVol*0.0304603764, StdVol*0.0571059660,
			       StdVol*0.0571059660, StdVol*0.0304603764,
			       StdVol*0.0194392824, StdVol*0.0364440336,
			       StdVol*0.0364440336, StdVol*0.0194392824,
			       StdVol*0.0046680564, StdVol*0.0087514968,
			       StdVol*0.0087514968, StdVol*0.0046680564,
			       StdVol*0.0097055322, StdVol*0.0181955664,
			       StdVol*0.0181955664, StdVol*0.0097055322,
			       StdVol*0.0145729242, StdVol*0.0273207684,
			       StdVol*0.0273207684, StdVol*0.0145729242,
			       StdVol*0.0093001866, StdVol*0.0174356394,
			       StdVol*0.0174356394, StdVol*0.0093001866,
			       StdVol*0.0022333026, StdVol*0.0041869110,
			       StdVol*0.0041869110, StdVol*0.0022333026,
			       StdVol*0.0014639124, StdVol*0.0027444882,
			       StdVol*0.0027444882, StdVol*0.0014639124,
			       StdVol*0.0021980748, StdVol*0.0041208678,
			       StdVol*0.0041208678, StdVol*0.0021980748,
			       StdVol*0.0014027730, StdVol*0.0026298660,
			       StdVol*0.0026298660, StdVol*0.0014027730,
			       StdVol*0.0003368550, StdVol*0.0006315234,
			       StdVol*0.0006315234, StdVol*0.0003368550);

    /****************************************************************************/
    /*  build a vector of Quad' quadrature formulars. For quadrature of degree */
    /*  use that of degree (only on function evaluation also)                   */
    /****************************************************************************/

Praetorius, Simon's avatar
Praetorius, Simon committed
1327
1328
1329
1330
1331
1332
1333
1334
    quad_3d[0].reset(new Quadrature("3d Stroud: P_1", 1, 3,  1, x1_3d, w1_3d));   /* P_0  */
    quad_3d[1].reset(new Quadrature("3d Stroud: P_1", 1, 3,  1, x1_3d, w1_3d));   /* P_1  */
    quad_3d[2].reset(new Quadrature("3d Stroud: P_2", 2, 3,  4, x2_3d, w2_3d));   /* P_2  */
    quad_3d[3].reset(new Quadrature("3d Stroud: P_3", 3, 3,  8, x3_3d, w3_3d));   /* P_3  */
    quad_3d[4].reset(new Quadrature("3d ???: P_5", 5, 3, 15, x5_3d, w5_3d));   /* P_4  */
    quad_3d[5].reset(new Quadrature("3d ???: P_5", 5, 3, 15, x5_3d, w5_3d));   /* P_5  */
    quad_3d[6].reset(new Quadrature("3d ???: P_7", 7, 3, 64, x7_3d, w7_3d));   /* P_6  */
    quad_3d[7].reset(new Quadrature("3d ???: P_7", 7, 3, 64, x7_3d, w7_3d));   /* P_7  */
1335
1336
1337
1338
1339
1340
1341
1342


#undef StdVol

    /****************************************************************************/
    /*  integration in different dimensions                                     */
    /****************************************************************************/

Praetorius, Simon's avatar
Praetorius, Simon committed
1343
1344
1345
1346
//     quad_nd[0] = quad_0d;
//     quad_nd[1] = quad_1d;
//     quad_nd[2] = quad_2d;
//     quad_nd[3] = quad_3d;
1347
  }
Praetorius, Simon's avatar
Praetorius, Simon committed
1348
  
1349

1350
1351
1352
  Quadrature* Quadrature::provideQuadrature(int dim_, int degree_)
  {
    FUNCNAME("Quadrature::provideQuadrature()");
Praetorius, Simon's avatar
Praetorius, Simon committed
1353
    static QuadratureFactory factory{};
1354
1355

    switch (dim_) {
1356
1357
1358
1359
    case 0:
      degree_ = 0;
      break;
    case 1:
1360
      degree_ = std::min(degree_, 19);
1361
1362
      break;
    case 2:
1363
      degree_ = std::min(degree_, 17);
1364
1365
      break;
    case 3:
1366
      degree_ = std::min(degree_, 7);
1367
1368
1369
1370
      break;
    default:
      ERROR_EXIT("invalid dim\n");
    }
1371

Praetorius, Simon's avatar
Praetorius, Simon committed
1372
    return factory.get(dim_, degree_);
1373
1374
  }

1375

1376
1377
  double Quadrature::integrateStdSimplex(AbstractFunction<double, DimVec<double> > *f)
  {
1378
1379
1380
    FUNCNAME("Quadrature::integrateStdSimplex()");

    if (!f) {
1381
1382
1383
1384
      ERROR("no function specified\n");
      return 0;
    }

1385
    double result = 0.0;
1386
    // calculate weighted sum over all quadrature-points
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1387
    for (int i = 0; i < n_points; i++)
1388
      result += w[i] * (*f)((*lambda)[i]);
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1389

1390
1391
1392
    return result;
  }

1393

1394
  FastQuadrature* FastQuadrature::provideFastQuadrature(const BasisFunction* bas_fcts,
1395
							const Quadrature& quad,
1396
1397
							Flag init_flag)
  {
1398
    FastQuadrature *quad_fast = NULL;
Praetorius, Simon's avatar
Praetorius, Simon committed
1399
1400
1401
1402
    
    #ifdef _OPENMP
    #pragma omp critical (provideFastQuad)
    #endif
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1403
    {
1404
      list<FastQuadrature*>::iterator fast = fastQuadList.begin();
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1405
      for (; fast != fastQuadList.end(); fast++)
1406
1407
	if ((*fast)->basisFunctions == bas_fcts &&
	    (*fast)->quadrature == &quad)
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1408
	  break;
1409
1410

      if (fast != fastQuadList.end() &&
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1411
1412
	  ((*fast)->init_flag & init_flag) == init_flag) {
	quad_fast = *fast;
1413
      } else {
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1414
	if (fast == fastQuadList.end()) {
1415
1416
	  quad_fast =
	    new FastQuadrature(const_cast<BasisFunction*>(bas_fcts),
Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1417
			       const_cast<Quadrature*>(&quad), 0);
1418

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1419
	  fastQuadList.push_front(quad_fast);
1420

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
1421
1422
1423
1424
	  max_points = std::max(max_points, quad.getNumPoints());
	} else {
	  quad_fast = (*fast);
	}
1425
      }
1426
1427

      quad_fast->init(init_flag);
1428
    }
1429
1430
1431
1432

    return quad_fast;
  }

1433

1434
1435
1436
  void FastQuadrature::init(Flag init_flag)
  {
    int dim = quadrature->getDim();
1437
    int nPoints = quadrature->getNumPoints();
1438
1439
1440
1441
1442
1443
    int nBasFcts = basisFunctions->getNumber();

    DimVec<double> lambda(dim, NO_INIT);

    // ----- initialize phi ---------------------------------------------

1444
1445
    if (num_rows(phi) == 0 && init_flag.isSet(INIT_PHI)) {
      phi.change_dim(nPoints, nBasFcts);
1446
1447

      // fill memory
1448
      for (int i = 0; i< nPoints; i++) {
1449
	lambda = quadrature->getLambda(i);
1450
	for (int j = 0; j < nBasFcts; j++)
1451
1452
	  phi[i][j] = (*(basisFunctions->getPhi(j)))(lambda);
      }
1453

1454
1455
1456
1457
1458
      // update flag
      init_flag |= INIT_PHI;
    }

    // initialize grd_phi
1459
    if (grdPhi.empty() && init_flag.isSet(INIT_GRD_PHI)) {
1460
1461

      // allocate memory
1462
      grdPhi.resize(nPoints);
1463
1464

      // fill memory
1465
      for (int i = 0; i< nPoints; i++) {
1466
	grdPhi[i].resize(nBasFcts);
1467
	lambda = quadrature->getLambda(i);
1468
1469
1470
1471
1472

	for (int j = 0; j < nBasFcts; j++) {
	  grdPhi[i][j].change_dim(dim + 1);
	  (*(basisFunctions->getGrdPhi(j)))(lambda, grdPhi[i][j]);
	}
1473
      }
1474

1475
1476
1477
1478
1479
1480
      // update flag
      init_flag |= INIT_GRD_PHI;
    }

    // initialize D2_phi

1481
    if (!D2Phi && init_flag.isSet(INIT_D2_PHI)) {
1482
1483

      // allocate memory
Thomas Witkowski's avatar
Thomas Witkowski committed
1484
      D2Phi = new MatrixOfFixVecs<DimMat<double> >(dim, nPoints, nBasFcts, NO_INIT);
1485
1486

      // fill memory
1487
      for (int i = 0; i < nPoints; i++) {
1488
	lambda = quadrature->getLambda(i);
1489
	for (int j = 0; j < nBasFcts; j++)
1490
	  (*(basisFunctions->getD2Phi(j)))(lambda, (*(D2Phi))[i][j]);
1491
      }
1492

1493
1494
1495
1496
1497
      // update flag
      init_flag |= INIT_D2_PHI;
    }
  }

1498

1499
1500
  FastQuadrature::FastQuadrature(const FastQuadrature& fastQuad)
  {
1501
    FUNCNAME("FastQuadrature::FastQuadrature()");
1502
1503
1504
1505
1506

    TEST_EXIT(quadrature)("no quadrature!\n");

    int dim = quadrature->getDim();

1507
    if (max_points == 0)
1508
1509
1510
1511
1512
      max_points = Quadrature::maxNQuadPoints[dim];

    init_flag = fastQuad.init_flag;
    basisFunctions = fastQuad.basisFunctions;
    quadrature = fastQuad.quadrature;
1513

1514
    int nPoints = quadrature->getNumPoints();
1515
1516
    int nBasFcts = basisFunctions->getNumber();

1517
1518
1519
    if (num_rows(fastQuad.phi) > 0) {
      phi.change_dim(nPoints, nBasFcts);
      phi = fastQuad.phi;
1520
1521
    }

1522
1523
1524
1525
    if (!fastQuad.grdPhi.empty()) {
      grdPhi.resize(nPoints);
      for (int i = 0; i < nPoints; i++) {
	grdPhi[i].resize(nBasFcts);
1526
	for (int j = 0; j < nBasFcts; j++)
1527
1528
	  grdPhi[i][j] = fastQuad.grdPhi[i][j];
      }
1529
1530
    }

1531
    if (fastQuad.D2Phi) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1532
      D2Phi = new MatrixOfFixVecs<DimMat<double> >(dim, nPoints, nBasFcts, NO_INIT);
1533
1534
      for (int i = 0; i < nPoints; i++)
	for (int j = 0; j < nBasFcts; j++)
1535
1536
1537
1538
	  (*D2Phi)[i][j] = (*(fastQuad.D2Phi))[i][j];
    }
  }

1539

1540
1541
  FastQuadrature::~FastQuadrature()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
1542
    delete D2Phi;
1543
1544
  }

1545

1546
  double FastQuadrature::getSecDer(int q,int i ,int j, int m) const
1547
  {
1548
    return (D2Phi) ? (*D2Phi)[q][i][j][m] : 0.0;
1549
1550
  }

1551

1552
  const VectorOfFixVecs<DimMat<double> > *FastQuadrature::getSecDer(int q) const
1553
  {
1554
    return D2Phi ? (&((*D2Phi)[q])) : NULL;
1555
1556
  }
}