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>
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> );
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> );
30#define TEST_ONE_ORDER(qtype, order, maxorder) \
31 CPPUNIT_TEST( testBuild<qtype MACROCOMMA order> ); \
32 CPPUNIT_TEST( test1DWeights<qtype MACROCOMMA order MACROCOMMA maxorder> );
36#define mymin(a, b) (a < b ? a : b)
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));
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));
63#define LIBMESH_ASSERT_REALS_EQUAL(first, second, tolerance) \
64 if (std::abs(first-second) >= tolerance) \
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; \
71 CPPUNIT_ASSERT (std::abs(first-second) < tolerance)
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> );
152 int xp,
int yp,
int zp,
156 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
159 Real val = qrule.
w(qp) * std::pow(p(0),xp);
161 val *= std::pow(p(1),yp);
163 val *= std::pow(p(2),zp);
174 const std::function<
Real(
int,
int,
int)> & true_value,
183 const std::function<
Real(
int,
int,
int)> & true_value,
187 unsigned int dim = elem.
dim();
188 std::unique_ptr<QBase> qrule =
196 qrule->allow_nodal_pyramid_quadrature =
true;
200 const int max_y_order =
dim>1 ? exactorder : 0;
201 const int max_z_order =
dim>2 ? exactorder : 0;
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)
208 if (xp + yp + zp > exactorder)
211 const Real exact = true_value(xp, yp, zp);
218 return (mode % 2) ? 0 : (
Real(2.0) / (mode+1));
222 [](
int modex,
int modey,
int) {
223 const Real exactx = (modex % 2) ?
224 0 : (
Real(2.0) / (modex+1));
226 const Real exacty = (modey % 2) ?
227 0 : (
Real(2.0) / (modey+1));
229 return exactx*exacty;
233 [](
int x_power,
int y_power,
int) {
235 Real analytical = 1.0;
238 larger_power = std::max(x_power, y_power),
239 smaller_power = std::min(x_power, y_power);
243 std::vector<unsigned>
244 numerator(smaller_power > 1 ? smaller_power-1 : 0),
245 denominator(2+smaller_power);
248 std::iota(numerator.begin(), numerator.end(), 2);
249 std::iota(denominator.begin(), denominator.end(), larger_power+1);
252 for (std::size_t i=0; i<denominator.size(); ++i)
254 if (i < numerator.size())
255 analytical *= numerator[i];
256 analytical /= denominator[i];
262 [](
int modex,
int modey,
int modez) {
263 const Real exactx = (modex % 2) ?
264 0 : (
Real(2.0) / (modex+1));
266 const Real exacty = (modey % 2) ?
267 0 : (
Real(2.0) / (modey+1));
269 const Real exactz = (modez % 2) ?
270 0 : (
Real(2.0) / (modez+1));
272 return exactx*exacty*exactz;
276 [](
int x_power,
int y_power,
int z_power) {
278 Real analytical = 1.0;
281 int sorted_powers[3] = {x_power, y_power, z_power};
282 std::sort(sorted_powers, sorted_powers+3);
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]);
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);
297 for (std::size_t i=0; i<denominator.size(); ++i)
299 if (i < numerator_1.size())
300 analytical *= numerator_1[i];
302 if (i < numerator_2.size())
303 analytical *= numerator_2[i];
305 analytical /= denominator[i];
311 [
this](
int modex,
int modey,
int modez) {
312 const Real exactz = (modez % 2) ?
313 0 : (
Real(2.0) / (modez+1));
319 [](
int modex,
int modey,
int modez) {
323 if (modex%2 || modey%2)
326 return Real(4)/((modex+1)*(modey+1)*binom*(modex+modey+modez+3));
341 const std::vector<std::vector<ElemType>> all_types =
350 const std::function<
Real(
int,
int,
int)> true_values[] =
360 for (
ElemType elem_type : all_types[i])
362 const unsigned int order =
Elem::build(elem_type)->default_order();
364 unsigned int exactorder = order;
371 if (elem_type ==
TRI6 || elem_type ==
QUAD8 ||
385 if ((
sizeof(
Real) >
sizeof(
double)) && elem_type ==
PRISM20)
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);
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);
412 return area * centroid(0);
414 return area * centroid(1);
431 const std::vector<std::vector<ElemType>> all_types =
433 const std::vector<std::vector<std::function<
Real(
int,
int,
int)>>>
441 for (
int order=0; order<17; ++order)
454 for (
int qt=0; qt<3; ++qt)
455 for (
int order=0; order<end_order; ++order)
459 if ((
sizeof(
Real) >
sizeof(
double)) && order > 2)
471 for (
int qt=0; qt<4; ++qt)
472 for (
int order=0; order<10; ++order)
480 constexpr int max_order = 43;
489 Real initial_sum_weights[2] = {.5, 1./3.};
499 std::vector<std::vector<Real>> true_integrals(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.);
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.);
514 for (
int qt=0; qt<2; ++qt)
516 for (
int order=0; order<max_order; ++order)
520 static_cast<Order>(order));
523 qrule->init (
EDGE2, 0,
true);
527 for (
unsigned int qp=0; qp<qrule->n_points(); qp++)
528 sumw += qrule->w(qp);
534 for (
int testpower=0; testpower<=order; ++testpower)
541 for (
unsigned int qp=0; qp<qrule->n_points(); qp++)
542 sumq += qrule->w(qp) * std::pow(qrule->qp(qp)(0), testpower);
553 template <QuadratureType qtype, Order order>
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);
562 CPPUNIT_ASSERT_EQUAL ( qtype, qrule1D->type() );
563 CPPUNIT_ASSERT_EQUAL ( qtype, qrule2D->type() );
564 CPPUNIT_ASSERT_EQUAL ( qtype, qrule3D->type() );
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() );
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() );
587 template <QuadratureType qtype, Order order,
unsigned int exactorder>
599 template <QuadratureType qtype, Order order,
unsigned int exactorder>
621 if ((
sizeof(
Real) >
sizeof(
double)) && (order > 17))
632 template <QuadratureType qtype, Order order,
unsigned int exactorder>
667 if ((
sizeof(
Real) >
sizeof(
double)) && (order > 17))
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)
void testNodalQuadrature()
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)
TEST_ONE_ORDER(QGAUSS_LOBATTO, SEVENTEENTH, 17)
Real quadrature_tolerance
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.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
virtual unsigned short dim() const =0
virtual ElemType type() const =0
A Point defines a location in LIBMESH_DIM dimensional Real space.
The QBase class provides the basic functionality from which various quadrature rules can be derived.
unsigned int n_points() const
Point qp(const unsigned int i) const
unsigned int get_dim() const
Real w(const unsigned int i) const
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.
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...
ElemType
Defines an enum for geometric element types.
QuadratureType
Defines an enum for currently available quadrature rules.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...
CPPUNIT_TEST_SUITE_REGISTRATION(QuadratureTest)