libMesh
Loading...
Searching...
No Matches
quadrature_test.C
Go to the documentation of this file.
1#include <libmesh/elem.h>
2#include <libmesh/enum_quadrature_type.h>
3#include <libmesh/face_c0polygon.h>
4#include <libmesh/quadrature.h>
5#include <libmesh/string_to_enum.h>
6#include <libmesh/utility.h>
7
8#include <iomanip>
9#include <numeric> // std::iota
10
11#include "libmesh_cppunit.h"
12
13
14using namespace libMesh;
15
16#define MACROCOMMA ,
17
18#if LIBMESH_DIM > 2
19#define TEST_ONE_ORDER(qtype, order, maxorder) \
20 CPPUNIT_TEST( testBuild<qtype MACROCOMMA order> ); \
21 CPPUNIT_TEST( test1DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> ); \
22 CPPUNIT_TEST( test2DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> ); \
23 CPPUNIT_TEST( test3DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> );
24#elif LIBMESH_DIM > 1
25#define TEST_ONE_ORDER(qtype, order, maxorder) \
26 CPPUNIT_TEST( testBuild<qtype MACROCOMMA order> ); \
27 CPPUNIT_TEST( test1DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> ); \
28 CPPUNIT_TEST( test2DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> );
29#else
30#define TEST_ONE_ORDER(qtype, order, maxorder) \
31 CPPUNIT_TEST( testBuild<qtype MACROCOMMA order> ); \
32 CPPUNIT_TEST( test1DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> );
33#endif
34
35// std::min isn't constexpr, and C++03 lacks constexpr anyway
36#define mymin(a, b) (a < b ? a : b)
37
38#define TEST_NINTH_ORDER(qtype, maxorder) \
39 TEST_ONE_ORDER(qtype, FIRST, mymin(1,maxorder)); \
40 TEST_ONE_ORDER(qtype, SECOND, mymin(2,maxorder)); \
41 TEST_ONE_ORDER(qtype, THIRD, mymin(3,maxorder)); \
42 TEST_ONE_ORDER(qtype, FOURTH, mymin(4,maxorder)); \
43 TEST_ONE_ORDER(qtype, FIFTH, mymin(5,maxorder)); \
44 TEST_ONE_ORDER(qtype, SIXTH, mymin(6,maxorder)); \
45 TEST_ONE_ORDER(qtype, SEVENTH, mymin(7,maxorder)); \
46 TEST_ONE_ORDER(qtype, EIGHTH, mymin(8,maxorder)); \
47 TEST_ONE_ORDER(qtype, NINTH, mymin(9,maxorder));
48
49#define TEST_TWENTIETH_ORDER(qtype, maxorder) \
50 TEST_NINTH_ORDER(qtype, maxorder) \
51 TEST_ONE_ORDER(qtype, TENTH, mymin(10,maxorder)); \
52 TEST_ONE_ORDER(qtype, ELEVENTH, mymin(11,maxorder)); \
53 TEST_ONE_ORDER(qtype, TWELFTH, mymin(12,maxorder)); \
54 TEST_ONE_ORDER(qtype, THIRTEENTH, mymin(13,maxorder));\
55 TEST_ONE_ORDER(qtype, FOURTEENTH, mymin(14,maxorder));\
56 TEST_ONE_ORDER(qtype, FIFTEENTH, mymin(15,maxorder)); \
57 TEST_ONE_ORDER(qtype, SIXTEENTH, mymin(16,maxorder)); \
58 TEST_ONE_ORDER(qtype, SEVENTEENTH, mymin(17,maxorder));\
59 TEST_ONE_ORDER(qtype, EIGHTEENTH, mymin(18,maxorder));\
60 TEST_ONE_ORDER(qtype, NINETEENTH, mymin(19,maxorder));\
61 TEST_ONE_ORDER(qtype, TWENTIETH, mymin(20,maxorder));
62
63#define LIBMESH_ASSERT_REALS_EQUAL(first, second, tolerance) \
64 if (std::abs(first-second) >= tolerance) \
65 { \
66 std::cerr << "first = " << first << std::endl; \
67 std::cerr << "second = " << second << std::endl; \
68 std::cerr << "error = " << std::abs(first-second) << std::endl; \
69 std::cerr << "tolerance = " << tolerance << std::endl; \
70 } \
71 CPPUNIT_ASSERT (std::abs(first-second) < tolerance)
72
73class QuadratureTest : public CppUnit::TestCase {
74public:
76
83
84 // In general, QNodal rules (e.g. QTRAP) are only exact for linears.
85 // QSIMPSON is a special case of a nodal quadrature which obtains
86 // higher accuracy.
87 TEST_ONE_ORDER(QNODAL, /*ignored*/FIRST, /*max order=*/1);
88
90
91 // The super-high-order Gauss-Lobatto quadrature rules only take
92 // ~0.2s to test for me these days. - RHS
110
111 // Might as well test super-high 1-D Gauss while we're at it.
112 // Some of the really high order stuff is getting pulled in
113 // indirectly; we'll just hit what lcov says we were missing.
114 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA TWENTYFIRST MACROCOMMA 21> );
115 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA TWENTYFIFTH MACROCOMMA 25> );
116 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA TWENTYSEVENTH MACROCOMMA 27> );
117 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA TWENTYNINTH MACROCOMMA 29> );
118 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA THIRTYFIRST MACROCOMMA 31> );
119 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA THIRTYTHIRD MACROCOMMA 33> );
120 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA THIRTYFIFTH MACROCOMMA 35> );
121 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA THIRTYSEVENTH MACROCOMMA 37> );
122 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA THIRTYNINTH MACROCOMMA 39> );
123 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA FORTYFIRST MACROCOMMA 41> );
124 CPPUNIT_TEST( test1DWeights<QGAUSS MACROCOMMA FORTYTHIRD MACROCOMMA 43> );
125
126 // Test monomial quadrature rules on quads and hexes
128
129 // Test nodal quadrature rules on every specific type
131
132 // Test quadrature rules on Triangles
133#if LIBMESH_DIM > 1
135#endif
136
137 // Test quadrature rules on Tetrahedra
138#if LIBMESH_DIM > 2
140#endif
141
142 // Test Jacobi quadrature rules with special weighting function
144
146
147private:
148
150
151 void testPolynomial(QBase & qrule,
152 int xp, int yp, int zp,
153 Real true_value)
154 {
155 Real sum = 0.;
156 for (unsigned int qp=0; qp<qrule.n_points(); qp++)
157 {
158 const Point p = qrule.qp(qp);
159 Real val = qrule.w(qp) * std::pow(p(0),xp);
160 if (qrule.get_dim() > 1)
161 val *= std::pow(p(1),yp);
162 if (qrule.get_dim() > 2)
163 val *= std::pow(p(2),zp);
164 sum += val;
165 }
166
167 // Make sure that the weighted evaluations add up to the true
168 // integral value we expect
169 LIBMESH_ASSERT_REALS_EQUAL(true_value, sum, quadrature_tolerance);
170 }
171
172 void testPolynomials(QuadratureType qtype, int order,
173 ElemType elem_type,
174 const std::function<Real(int,int,int)> & true_value,
175 int exactorder)
176 {
177 auto elem = Elem::build(elem_type);
178 testPolynomials(qtype, order, *elem, true_value, exactorder);
179 }
180
181 void testPolynomials(QuadratureType qtype, int order,
182 const Elem & elem,
183 const std::function<Real(int,int,int)> & true_value,
184 int exactorder)
185 {
186 const ElemType elem_type = elem.type();
187 unsigned int dim = elem.dim();
188 std::unique_ptr<QBase> qrule =
189 QBase::build(qtype, dim, static_cast<Order>(order));
190
191 // We are testing integration on the reference elements here, so
192 // the element map is not relevant, and we can safely use nodal
193 // Pyramid quadrature.
194 if (elem_type == PYRAMID5 || elem_type == PYRAMID13 ||
195 elem_type == PYRAMID14 || elem_type == PYRAMID18)
196 qrule->allow_nodal_pyramid_quadrature = true;
197
198 qrule->init (elem);
199
200 const int max_y_order = dim>1 ? exactorder : 0;
201 const int max_z_order = dim>2 ? exactorder : 0;
202
203 for (int xp=0; xp <= exactorder; ++xp)
204 for (int yp=0; yp <= max_y_order; ++yp)
205 for (int zp=0; zp <= max_z_order; ++zp)
206 {
207 // Only try to integrate polynomials we can integrate exactly
208 if (xp + yp + zp > exactorder)
209 continue;
210
211 const Real exact = true_value(xp, yp, zp);
212 testPolynomial(*qrule, xp, yp, zp, exact);
213 }
214 }
215
216 const std::function<Real(int,int,int)> edge_integrals =
217 [](int mode, int, int) {
218 return (mode % 2) ? 0 : (Real(2.0) / (mode+1));
219 };
220
221 const std::function<Real(int,int,int)> quad_integrals =
222 [](int modex, int modey, int) {
223 const Real exactx = (modex % 2) ?
224 0 : (Real(2.0) / (modex+1));
225
226 const Real exacty = (modey % 2) ?
227 0 : (Real(2.0) / (modey+1));
228
229 return exactx*exacty;
230 };
231
232 const std::function<Real(int,int,int)> tri_integrals =
233 [](int x_power, int y_power, int) {
234 // Compute the true integral, a! b! / (a + b + 2)!
235 Real analytical = 1.0;
236
237 unsigned
238 larger_power = std::max(x_power, y_power),
239 smaller_power = std::min(x_power, y_power);
240
241 // Cancel the larger of the two numerator terms with the
242 // denominator, and fill in the remaining entries.
243 std::vector<unsigned>
244 numerator(smaller_power > 1 ? smaller_power-1 : 0),
245 denominator(2+smaller_power);
246
247 // Fill up the vectors with sequences starting at the right values.
248 std::iota(numerator.begin(), numerator.end(), 2);
249 std::iota(denominator.begin(), denominator.end(), larger_power+1);
250
251 // The denominator is guaranteed to have more terms...
252 for (std::size_t i=0; i<denominator.size(); ++i)
253 {
254 if (i < numerator.size())
255 analytical *= numerator[i];
256 analytical /= denominator[i];
257 }
258 return analytical;
259 };
260
261 const std::function<Real(int,int,int)> hex_integrals =
262 [](int modex, int modey, int modez) {
263 const Real exactx = (modex % 2) ?
264 0 : (Real(2.0) / (modex+1));
265
266 const Real exacty = (modey % 2) ?
267 0 : (Real(2.0) / (modey+1));
268
269 const Real exactz = (modez % 2) ?
270 0 : (Real(2.0) / (modez+1));
271
272 return exactx*exacty*exactz;
273 };
274
275 const std::function<Real(int,int,int)> tet_integrals =
276 [](int x_power, int y_power, int z_power) {
277 // Compute the true integral, a! b! c! / (a + b + c + 3)!
278 Real analytical = 1.0;
279
280 // Sort the a, b, c values
281 int sorted_powers[3] = {x_power, y_power, z_power};
282 std::sort(sorted_powers, sorted_powers+3);
283
284 // Cancel the largest power with the denominator, fill in the
285 // entries for the remaining numerator terms and the denominator.
286 std::vector<int>
287 numerator_1(sorted_powers[0] > 1 ? sorted_powers[0]-1 : 0),
288 numerator_2(sorted_powers[1] > 1 ? sorted_powers[1]-1 : 0),
289 denominator(3 + sorted_powers[0] + sorted_powers[1]);
290
291 // Fill up the vectors with sequences starting at the right values.
292 std::iota(numerator_1.begin(), numerator_1.end(), 2);
293 std::iota(numerator_2.begin(), numerator_2.end(), 2);
294 std::iota(denominator.begin(), denominator.end(), sorted_powers[2]+1);
295
296 // The denominator is guaranteed to have the most terms...
297 for (std::size_t i=0; i<denominator.size(); ++i)
298 {
299 if (i < numerator_1.size())
300 analytical *= numerator_1[i];
301
302 if (i < numerator_2.size())
303 analytical *= numerator_2[i];
304
305 analytical /= denominator[i];
306 }
307 return analytical;
308 };
309
310 const std::function<Real(int,int,int)> prism_integrals =
311 [this](int modex, int modey, int modez) {
312 const Real exactz = (modez % 2) ?
313 0 : (Real(2.0) / (modez+1));
314
315 return exactz * tri_integrals(modex, modey, 0);
316 };
317
318 const std::function<Real(int,int,int)> pyramid_integrals =
319 [](int modex, int modey, int modez) {
320
321 const int binom = Utility::binomial(modex+modey+modez+2, modez);
322
323 if (modex%2 || modey%2)
324 return Real(0);
325
326 return Real(4)/((modex+1)*(modey+1)*binom*(modex+modey+modez+3));
327 };
328
329
330public:
331 void setUp ()
332 { quadrature_tolerance = TOLERANCE * std::sqrt(TOLERANCE); }
333
334 void tearDown ()
335 {}
336
338 {
339 LOG_UNIT_TEST;
340
341 const std::vector<std::vector<ElemType>> all_types =
342 {{EDGE2, EDGE3, EDGE4},
343 {TRI3, TRI6, TRI7},
344 {QUAD4, QUAD8, QUAD9},
345 {TET4, TET10, TET14},
346 {HEX8, HEX20, HEX27},
349
350 const std::function<Real(int,int,int)> true_values[] =
358
359 for (auto i : index_range(all_types))
360 for (ElemType elem_type : all_types[i])
361 {
362 const unsigned int order = Elem::build(elem_type)->default_order();
363
364 unsigned int exactorder = order;
365 // There are some sad exceptions to the "positive nodal
366 // quadrature can integrate polynomials up to the element
367 // order" rule.
368 //
369 // Some "quadratic" elements can only exactly integrate
370 // linears when mass lumping.
371 if (elem_type == TRI6 || elem_type == QUAD8 ||
372 elem_type == TET10 || elem_type == HEX20 ||
373 elem_type == PRISM15 || elem_type == PRISM18 ||
374 elem_type == PYRAMID13 || elem_type == PYRAMID14 ||
375 // And some partially-cubic elements can only do quadratics
376 elem_type == TET14 || elem_type == PRISM20)
377 exactorder--;
378
379 // And one partially-cubic element can only do linears.
380 // Seriously.
381 if (elem_type == PYRAMID18)
382 exactorder=1;
383
384 // Our PRISM20 rule was only computed in double precision.
385 if ((sizeof(Real) > sizeof(double)) && elem_type == PRISM20)
387 else // restore the default
389
390 testPolynomials(QNODAL, order, elem_type, true_values[i], exactorder);
391 }
392
393#if LIBMESH_DIM > 1
394 // C0Polygon nodal rules depend on the number of sides, so we test
395 // several polygons rather than just the Elem::build() default.
396 // The master polygon is the regular polygon with unit side
397 // lengths; see Polygon::master_point().
398 for (const auto ns : make_range(3u, 9u))
399 {
400 // No nodes are needed to define a master-element rule
401 const C0Polygon poly(ns);
402
403 const Real pi_over_ns = libMesh::pi / ns;
404 const Real apothem = 0.5 / std::tan(pi_over_ns);
405 const Real area = ns * 0.5 * apothem;
406 const Point centroid(0.5, apothem);
407
408 const std::function<Real(int,int,int)> poly_integrals =
409 [area, centroid](int modex, int modey, int) {
410 libmesh_assert_less_equal(modex + modey, 1);
411 if (modex)
412 return area * centroid(0);
413 if (modey)
414 return area * centroid(1);
415 return area;
416 };
417
418 // Equal weights at the vertices of a regular polygon are
419 // exact for linears, but they overweight the boundary for
420 // quadratics.
421 testPolynomials(QNODAL, FIRST, poly, poly_integrals, 1);
422 }
423#endif
424 }
425
426
428 {
429 LOG_UNIT_TEST;
430
431 const std::vector<std::vector<ElemType>> all_types =
432 {{EDGE2}, {QUAD4, TRI3}, {HEX8, TET4, PRISM6, PYRAMID5}};
433 const std::vector<std::vector<std::function<Real(int,int,int)>>>
434 true_values =
438
439 for (auto i : index_range(all_types))
440 for (auto j : index_range(all_types[i]))
441 for (int order=0; order<17; ++order)
442 testPolynomials(QMONOMIAL, order, all_types[i][j], true_values[i][j], order);
443 }
444
446 {
447 LOG_UNIT_TEST;
448
449 // There are 3 different families of quadrature rules for tetrahedra
451
452 int end_order = 7;
453
454 for (int qt=0; qt<3; ++qt)
455 for (int order=0; order<end_order; ++order)
456 {
457 // Our higher order tet rules were only computed to double
458 // precision
459 if ((sizeof(Real) > sizeof(double)) && order > 2)
461 testPolynomials(qtype[qt], order, TET4, tet_integrals, order);
462 }
463 }
464
466 {
467 LOG_UNIT_TEST;
468
470
471 for (int qt=0; qt<4; ++qt)
472 for (int order=0; order<10; ++order)
473 testPolynomials(qtype[qt], order, TRI3, tri_integrals, order);
474 }
475
477 {
478 LOG_UNIT_TEST;
479
480 constexpr int max_order = 43; // We seriously implemented that?!
481
482 // LibMesh supports two different types of Jacobi quadrature
484
485 // The weights of the Jacobi quadrature rules in libmesh have been
486 // scaled based on their intended use:
487 // (alpha=1, beta=0) rule weights sum to 1/2.
488 // (alpha=2, beta=0) rule weights sum to 1/3.
489 Real initial_sum_weights[2] = {.5, 1./3.};
490
491 // The points of the Jacobi rules in LibMesh are also defined on
492 // [0,1]... this has to be taken into account when computing the
493 // exact integral values in Maple! Also note: if you scale the
494 // points to a different interval, you need to also compute what
495 // the sum of the weights should be for that interval, it will not
496 // simply be the element length for weighted quadrature rules like
497 // Jacobi. For general alpha and beta=0, the sum of the weights
498 // on the interval [-1,1] is 2^(alpha+1) / (alpha+1).
499 std::vector<std::vector<Real>> true_integrals(2);
500
501 // alpha=1 integral values
502 // int((1-x)*x^p, x=0..1) = 1 / (p^2 + 3p + 2)
503 true_integrals[0].resize(max_order);
504 for (std::size_t p=0; p<true_integrals[0].size(); ++p)
505 true_integrals[0][p] = 1. / (p*p + 3.*p + 2.);
506
507 // alpha=2 integral values
508 // int((1-x)^2*x^p, x=0..1) = 2 / (p^3 + 6*p^2 + 11*p + 6)
509 true_integrals[1].resize(max_order);
510 for (std::size_t p=0; p<true_integrals[1].size(); ++p)
511 true_integrals[1][p] = 2. / (p*p*p + 6.*p*p + 11.*p + 6.);
512
513 // Test both types of Jacobi quadrature rules
514 for (int qt=0; qt<2; ++qt)
515 {
516 for (int order=0; order<max_order; ++order)
517 {
518 std::unique_ptr<QBase> qrule = QBase::build(qtype[qt],
519 /*dim=*/1,
520 static_cast<Order>(order));
521
522 // Initialize on a 1D element, EDGE2/3/4 should not matter...
523 qrule->init (EDGE2, 0, true);
524
525 // Test the sum of the weights for this order
526 Real sumw = 0.;
527 for (unsigned int qp=0; qp<qrule->n_points(); qp++)
528 sumw += qrule->w(qp);
529
530 // Make sure that the weights add up to the value we expect
531 LIBMESH_ASSERT_REALS_EQUAL(initial_sum_weights[qt], sumw, quadrature_tolerance);
532
533 // Test integrating different polynomial powers
534 for (int testpower=0; testpower<=order; ++testpower)
535 {
536 // Note that the weighting function, (1-x)^alpha *
537 // (1+x)^beta, is built into these quadrature rules;
538 // the polynomials we actually integrate are just the
539 // usual monomials.
540 Real sumq = 0.;
541 for (unsigned int qp=0; qp<qrule->n_points(); qp++)
542 sumq += qrule->w(qp) * std::pow(qrule->qp(qp)(0), testpower);
543
544 // Make sure that the computed integral agrees with the "true" value
545 LIBMESH_ASSERT_REALS_EQUAL(true_integrals[qt][testpower], sumq, quadrature_tolerance);
546 } // end for(testpower)
547 } // end for(order)
548 } // end for(qt)
549 } // testJacobi
550
551
552
553 template <QuadratureType qtype, Order order>
554 void testBuild ()
555 {
556 LOG_UNIT_TEST;
557
558 std::unique_ptr<QBase> qrule1D = QBase::build (qtype, 1, order);
559 std::unique_ptr<QBase> qrule2D = QBase::build (qtype, 2, order);
560 std::unique_ptr<QBase> qrule3D = QBase::build (qtype, 3, order);
561
562 CPPUNIT_ASSERT_EQUAL ( qtype, qrule1D->type() );
563 CPPUNIT_ASSERT_EQUAL ( qtype, qrule2D->type() );
564 CPPUNIT_ASSERT_EQUAL ( qtype, qrule3D->type() );
565
566 // Simpson's Rule is inherently third-order
567 if (qtype != QSIMPSON)
568 {
569 CPPUNIT_ASSERT_EQUAL ( order, qrule1D->get_base_order() );
570 CPPUNIT_ASSERT_EQUAL ( order, qrule2D->get_base_order() );
571 CPPUNIT_ASSERT_EQUAL ( order, qrule3D->get_base_order() );
572 }
573
574 CPPUNIT_ASSERT_EQUAL ( static_cast<unsigned int>(1) , qrule1D->get_dim() );
575 CPPUNIT_ASSERT_EQUAL ( static_cast<unsigned int>(2) , qrule2D->get_dim() );
576 CPPUNIT_ASSERT_EQUAL ( static_cast<unsigned int>(3) , qrule3D->get_dim() );
577
578 // Test the enum-to-string conversion for this qtype is
579 // implemented, but not what the actual value is.
581 }
582
583
584
585 //-------------------------------------------------------
586 // 1D Quadrature Rule Test
587 template <QuadratureType qtype, Order order, unsigned int exactorder>
589 {
590 LOG_UNIT_TEST;
591
592 testPolynomials(qtype, order, EDGE3, edge_integrals, exactorder);
593 }
594
595
596
597 //-------------------------------------------------------
598 // 2D Quadrature Rule Test
599 template <QuadratureType qtype, Order order, unsigned int exactorder>
601 {
602 LOG_UNIT_TEST;
603
604 testPolynomials(qtype, order, QUAD8, quad_integrals, exactorder);
605
606 // We may eventually support Gauss-Lobatto type quadrature on triangles...
607 if (qtype == QGAUSS_LOBATTO)
608 return;
609
610 // QGrid uses equal weights on triangles, so it only gets linears
611 // right
612 if (qtype == QGRID)
613 testPolynomials(qtype, order, TRI6, tri_integrals, std::min(1u,exactorder));
614 // QSimpson doesn't even get all quadratics on a triangle
615 else if (qtype == QSIMPSON)
616 testPolynomials(qtype, order, TRI6, tri_integrals, std::min(1u,exactorder));
617 else
618 {
619 // Our 18th order and higher triangle rules were only computed
620 // in double precision, so we use a lower tolerance here.
621 if ((sizeof(Real) > sizeof(double)) && (order > 17))
623
624 testPolynomials(qtype, order, TRI6, tri_integrals, exactorder);
625 }
626 }
627
628
629
630 //-------------------------------------------------------
631 // 3D Gauss Rule Test
632 template <QuadratureType qtype, Order order, unsigned int exactorder>
634 {
635 LOG_UNIT_TEST;
636
637 testPolynomials(qtype, order, HEX20, hex_integrals, exactorder);
638
639 // We may eventually support Gauss-Lobatto type quadrature on tets and prisms...
640 if (qtype == QGAUSS_LOBATTO)
641 return;
642
643 // QGrid uses equal weights on tets and pyramids, so it only gets
644 // linears right
645 if (qtype == QGRID)
646 {
647 testPolynomials(qtype, order, TET10, tet_integrals, std::min(1u,exactorder));
648 testPolynomials(qtype, order, PYRAMID14, pyramid_integrals, std::min(1u,exactorder));
649 }
650 // QSimpson doesn't get all quadratics on a simplex or its extrusion
651 else if (qtype == QSIMPSON)
652 {
653 testPolynomials(qtype, order, TET10, tet_integrals, std::min(1u,exactorder));
654 testPolynomials(qtype, order, PRISM15, prism_integrals, std::min(1u,exactorder));
655
656 // And on pyramids we gave up and redid QTrap
657 testPolynomials(qtype, order, PYRAMID14, pyramid_integrals, std::min(1u,exactorder));
658 }
659 else
660 {
661 testPolynomials(qtype, order, TET10, tet_integrals, exactorder);
662 testPolynomials(qtype, order, PYRAMID14, pyramid_integrals, exactorder);
663
664 // Our 18th order and higher triangle rules (used to construct
665 // prism rules) were only computed in double precision, so we
666 // use a lower tolerance here.
667 if ((sizeof(Real) > sizeof(double)) && (order > 17))
669
670 testPolynomials(qtype, order, PRISM15, prism_integrals, exactorder);
671 }
672 }
673};
674
unsigned int dim
void ErrorVector unsigned int
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA THIRTYSEVENTH MACROCOMMA 37 >)
CPPUNIT_TEST(testTetQuadrature)
TEST_ONE_ORDER(QGAUSS_LOBATTO, FIFTEENTH, 15)
TEST_NINTH_ORDER(QGRID, 1)
TEST_NINTH_ORDER(QGAUSS_LOBATTO, 9)
const std::function< Real(int, int, int)> prism_integrals
TEST_ONE_ORDER(QGAUSS_LOBATTO, THIRTYSEVENTH, 37)
CPPUNIT_TEST(testNodalQuadrature)
CPPUNIT_TEST(testTriQuadrature)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA THIRTYTHIRD MACROCOMMA 33 >)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA THIRTYFIRST MACROCOMMA 31 >)
void testPolynomials(QuadratureType qtype, int order, const Elem &elem, const std::function< Real(int, int, int)> &true_value, int exactorder)
const std::function< Real(int, int, int)> tet_integrals
TEST_ONE_ORDER(QSIMPSON, FIRST, 1)
void testPolynomial(QBase &qrule, int xp, int yp, int zp, Real true_value)
CPPUNIT_TEST(testMonomialQuadrature)
TEST_ONE_ORDER(QGAUSS_LOBATTO, THIRTEENTH, 13)
void testPolynomials(QuadratureType qtype, int order, ElemType elem_type, const std::function< Real(int, int, int)> &true_value, int exactorder)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA FORTYTHIRD MACROCOMMA 43 >)
void testMonomialQuadrature()
TEST_ONE_ORDER(QGAUSS_LOBATTO, TWENTYTHIRD, 23)
TEST_ONE_ORDER(QGAUSS_LOBATTO, TWENTYFIRST, 21)
TEST_ONE_ORDER(QGAUSS_LOBATTO, FORTYFIRST, 41)
TEST_ONE_ORDER(QGAUSS_LOBATTO, TWENTYSEVENTH, 27)
TEST_ONE_ORDER(QGAUSS_LOBATTO, TWENTYFIFTH, 25)
TEST_ONE_ORDER(QNODAL, FIRST, 1)
const std::function< Real(int, int, int)> quad_integrals
TEST_ONE_ORDER(QTRAP, FIRST, 1)
TEST_ONE_ORDER(QSIMPSON, SECOND, 2)
TEST_ONE_ORDER(QGAUSS_LOBATTO, NINETEENTH, 19)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA TWENTYSEVENTH MACROCOMMA 27 >)
const std::function< Real(int, int, int)> tri_integrals
const std::function< Real(int, int, int)> edge_integrals
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA THIRTYFIFTH MACROCOMMA 35 >)
TEST_ONE_ORDER(QGAUSS_LOBATTO, THIRTYFIFTH, 35)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA TWENTYNINTH MACROCOMMA 29 >)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA TWENTYFIRST MACROCOMMA 21 >)
TEST_ONE_ORDER(QGAUSS_LOBATTO, TWENTYNINTH, 29)
TEST_ONE_ORDER(QGAUSS_LOBATTO, ELEVENTH, 11)
TEST_ONE_ORDER(QSIMPSON, THIRD, 3)
TEST_ONE_ORDER(QGAUSS_LOBATTO, FORTYTHIRD, 43)
TEST_ONE_ORDER(QGAUSS_LOBATTO, THIRTYNINTH, 39)
TEST_TWENTIETH_ORDER(QGAUSS, 9999)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA THIRTYNINTH MACROCOMMA 39 >)
const std::function< Real(int, int, int)> hex_integrals
const std::function< Real(int, int, int)> pyramid_integrals
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA FORTYFIRST MACROCOMMA 41 >)
TEST_ONE_ORDER(QGAUSS_LOBATTO, THIRTYTHIRD, 33)
TEST_ONE_ORDER(QGAUSS_LOBATTO, THIRTYFIRST, 31)
CPPUNIT_TEST(test1DWeights< QGAUSS MACROCOMMA TWENTYFIFTH MACROCOMMA 25 >)
LIBMESH_CPPUNIT_TEST_SUITE(QuadratureTest)
CPPUNIT_TEST(testJacobi)
TEST_ONE_ORDER(QGAUSS_LOBATTO, SEVENTEENTH, 17)
The C0Polygon is an element in 2D with an arbitrary (but fixed) number of first-order (EDGE2) sides.
This is the base class from which all geometric element types are derived.
Definition elem.h:96
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition elem.C:382
virtual unsigned short dim() const =0
virtual ElemType type() const =0
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
The QBase class provides the basic functionality from which various quadrature rules can be derived.
Definition quadrature.h:62
unsigned int n_points() const
Definition quadrature.h:131
Point qp(const unsigned int i) const
Definition quadrature.h:179
unsigned int get_dim() const
Definition quadrature.h:150
Real w(const unsigned int i) const
Definition quadrature.h:188
static std::unique_ptr< QBase > build(std::string_view name, const unsigned int dim, const Order order=INVALID_ORDER)
Builds a specific quadrature rule based on the name string.
T binomial(T n, T k)
Definition utility.h:322
std::string enum_to_string(const T e)
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
ElemType
Defines an enum for geometric element types.
const Real pi
.
Definition libmesh.h:292
QuadratureType
Defines an enum for currently available quadrature rules.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
@ SEVENTEENTH
Definition enum_order.h:58
@ FORTYFIRST
Definition enum_order.h:83
@ TWENTYFIRST
Definition enum_order.h:63
@ THIRTYFIRST
Definition enum_order.h:73
@ FORTYTHIRD
Definition enum_order.h:85
@ THIRTYNINTH
Definition enum_order.h:81
@ THIRTYSEVENTH
Definition enum_order.h:79
@ TWENTYSEVENTH
Definition enum_order.h:69
@ TWENTYNINTH
Definition enum_order.h:71
@ TWENTYTHIRD
Definition enum_order.h:65
@ TWENTYFIFTH
Definition enum_order.h:67
@ FIFTEENTH
Definition enum_order.h:56
@ THIRTYFIFTH
Definition enum_order.h:77
@ NINETEENTH
Definition enum_order.h:61
@ THIRTYTHIRD
Definition enum_order.h:75
@ THIRTEENTH
Definition enum_order.h:54
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176
CPPUNIT_TEST_SUITE_REGISTRATION(QuadratureTest)