10 #include <gtest/gtest.h>
11 #include <gmock/gmock.h>
13 #include <Eigen/Dense>
15 using namespace ::testing;
26 return abs(get<0>(arg) - get<1>(arg)) < 1e-15;
29 TEST(NodesTest, GaussLegendreNodes)
34 const long double l3e[3] = { 0.11270166537925831,
39 const long double l5e[5] = { 0.046910077030668004,
46 const long double l7e[7] = { 0.025446043828620736,
55 auto l3 = compute_nodes<long double>(3, QuadratureType::GaussLegendre);
56 EXPECT_THAT(l3, Pointwise(DoubleNear(), l3e));
58 auto l5 = compute_nodes<long double>(5, QuadratureType::GaussLegendre);
59 EXPECT_THAT(l5, Pointwise(DoubleNear(), l5e));
61 auto l7 = compute_nodes<long double>(7, QuadratureType::GaussLegendre);
62 EXPECT_THAT(l7, Pointwise(DoubleNear(), l7e));
65 TEST(NodesTest, GaussLobattoNodes)
70 const long double l2e[2] = { 0.0,
74 const long double l3e[3] = { 0.0,
79 const long double l5e[5] = { 0.0,
86 const long double l7e[7] = { 0.0,
95 const long double l9e[9] = { 0.0,
106 auto l2 = compute_nodes<long double>(2, QuadratureType::GaussLobatto);
107 EXPECT_THAT(l2, Pointwise(DoubleNear(), l2e));
109 auto l3 = compute_nodes<long double>(3, QuadratureType::GaussLobatto);
110 EXPECT_THAT(l3, Pointwise(DoubleNear(), l3e));
112 auto l5 = compute_nodes<long double>(5, QuadratureType::GaussLobatto);
113 EXPECT_THAT(l5, Pointwise(DoubleNear(), l5e));
115 auto l7 = compute_nodes<long double>(7, QuadratureType::GaussLobatto);
116 EXPECT_THAT(l7, Pointwise(DoubleNear(), l7e));
118 auto l9 = compute_nodes<long double>(9, QuadratureType::GaussLobatto);
119 EXPECT_THAT(l9, Pointwise(DoubleNear(), l9e));
122 TEST(NodesTest, ClenshawCurtisNodes)
127 const long double cc2e[2] = { 0.0,
131 const long double cc3e[3] = { 0.0,
136 const long double cc5e[5] = { 0.0,
137 0.14644660940672623779957781894757548,
139 0.85355339059327376220042218105242452,
143 const long double cc7e[7] = { 0.0,
144 0.066987298107780676618138414623531908,
148 0.93301270189221932338186158537646809,
152 const long double cc9e[9] = { 0.0,
153 0.038060233744356621935908405301605857,
154 0.14644660940672623779957781894757548,
155 0.30865828381745511413577000798480057,
157 0.69134171618254488586422999201519943,
158 0.85355339059327376220042218105242452,
159 0.96193976625564337806409159469839414,
163 auto cc2 = compute_nodes<long double>(2, QuadratureType::ClenshawCurtis);
164 EXPECT_THAT(cc2, Pointwise(DoubleNear(), cc2e));
166 auto cc3 = compute_nodes<long double>(3, QuadratureType::ClenshawCurtis);
167 EXPECT_THAT(cc3, Pointwise(DoubleNear(), cc3e));
169 auto cc5 = compute_nodes<long double>(5, QuadratureType::ClenshawCurtis);
170 EXPECT_THAT(cc5, Pointwise(DoubleNear(), cc5e));
172 auto cc7 = compute_nodes<long double>(7, QuadratureType::ClenshawCurtis);
173 EXPECT_THAT(cc7, Pointwise(DoubleNear(), cc7e));
175 auto cc9 = compute_nodes<long double>(9, QuadratureType::ClenshawCurtis);
176 EXPECT_THAT(cc9, Pointwise(DoubleNear(), cc9e));
181 EXPECT_TRUE(
Uniform<>(3).left_is_node());
182 EXPECT_TRUE(
Uniform<>(3).right_is_node());
184 const long double u2e[2] = { 0.0,
188 const long double u3e[3] = { 0.0,
193 const long double u5e[5] = { 0.0,
200 auto u2 = compute_nodes<long double>(2, QuadratureType::Uniform);
201 EXPECT_THAT(u2, Pointwise(DoubleNear(), u2e));
203 auto u3 = compute_nodes<long double>(3, QuadratureType::Uniform);
204 EXPECT_THAT(u3, Pointwise(DoubleNear(), u3e));
206 auto u5 = compute_nodes<long double>(5, QuadratureType::Uniform);
207 EXPECT_THAT(u5, Pointwise(DoubleNear(), u5e));
211 TEST(QuadratureTest, GaussLobattoNodes)
214 Eigen::Matrix<double, 3, 3> s_mat_3_expected;
215 s_mat_3_expected << 0.0, 0.0, 0.0,
216 0.20833333333333333, 0.33333333333333333, -0.04166666666666666,
217 -0.04166666666666666, 0.33333333333333333, 0.20833333333333333;
218 for (
size_t row = 0; row < 3; ++row) {
219 for (
size_t col = 0; col < 3; ++col) {
220 EXPECT_THAT(s_mat_3(row, col), ::testing::DoubleNear((s_mat_3_expected(row, col)), (
double)(1e-14)));
225 Eigen::Matrix<double, 5, 5> s_mat_5_expected;
226 s_mat_5_expected << 0.0, 0.0, 0.0, 0.0, 0.0,
227 0.067728432186156897969267419174073482, 0.11974476934341168251615379970493965,
228 -0.021735721866558113665511351745074292, 0.010635824225415491883105056997129926,
229 -0.0037001392424145306021611522544979462,
230 -0.027103432186156897969267419174073483, 0.1834394139796310955018131986775051,
231 0.19951349964433589144328912952285207, -0.041597785326236047678849833157352459,
232 0.013075139242414530602161152254497946,
233 0.013075139242414530602161152254497944, -0.041597785326236047678849833157352467,
234 0.19951349964433589144328912952285207, 0.1834394139796310955018131986775051,
235 -0.027103432186156897969267419174073483,
236 -0.0037001392424145306021611522544979483, 0.010635824225415491883105056997129916,
237 -0.021735721866558113665511351745074289, 0.11974476934341168251615379970493965,
238 0.067728432186156897969267419174073482;
240 for (
size_t row = 0; row < 5; ++row) {
241 for (
size_t col = 0; col < 5; ++col) {
242 EXPECT_THAT(s_mat_5(row, col), ::testing::DoubleNear((s_mat_5_expected(row, col)), (
double)(1e-14)));
249 for (
size_t col = 0; col < 5; ++col) {
250 EXPECT_THAT(q_vec[col], ::testing::DoubleEq(q_mat_5(4, col)));
254 TEST(QuadratureTest, ClenshawCurtisNodes)
257 Eigen::Matrix<double, 4, 4> s_mat_4_expected;
258 s_mat_4_expected << 0.0, 0.0, 0.0, 0.0,
259 0.10243055555555555555555555555555556, 0.16319444444444444444444444444444444,
260 -0.024305555555555555555555555555555556, 0.0086805555555555555555555555555555557,
261 -0.055555555555555555555555555555555556, 0.30555555555555555555555555555555556,
262 0.30555555555555555555555555555555556, -0.055555555555555555555555555555555556,
263 0.0086805555555555555555555555555555545, -0.024305555555555555555555555555555554,
264 0.16319444444444444444444444444444444, 0.10243055555555555555555555555555556;
266 for (
size_t row = 0; row < 4; ++row) {
267 for (
size_t col = 0; col < 4; ++col) {
268 EXPECT_THAT(s_mat_4(row, col), ::testing::DoubleNear((s_mat_4_expected(row, col)), (
double)(1e-14)));
275 :
public ::TestWithParam<tuple<size_t, QuadratureType>>
280 shared_ptr<IQuadrature<long double>>
quad;
285 nnodes = get<0>(GetParam());
286 qtype = get<1>(GetParam());
288 this->quad = quadrature_factory<long double>(nnodes, qtype);
290 cout <<
"Quadrature type no. " << int(qtype) <<
" -- Number of nodes " << nnodes << endl;
296 for (
int m = 0; m < this->quad->get_q_mat().rows(); ++m) {
297 long double qsum = 0;
298 for (
int j = 0; j < this->quad->get_q_mat().cols(); ++j) {
299 qsum += this->quad->get_q_mat()(m,j);
301 EXPECT_NEAR(qsum, this->quad->get_nodes()[m], (
long double)(3E-12));
307 ::Combine(::Range<size_t>(2, 14),
308 Values<QuadratureType>(QuadratureType::GaussLegendre,
309 QuadratureType::GaussLobatto,
310 QuadratureType::GaussRadau,
311 QuadratureType::ClenshawCurtis,
312 QuadratureType::Uniform)));
315 typedef ::testing::Types<GaussLegendre<>,
323 int main(
int argc,
char** argv)
325 InitGoogleTest(&argc, argv);
326 return RUN_ALL_TESTS();
shared_ptr< IQuadrature< long double > > quad
INSTANTIATE_TEST_CASE_P(Quadrature, QmatTest,::Combine(::Range< size_t >(2, 14), Values< QuadratureType >(QuadratureType::GaussLegendre, QuadratureType::GaussLobatto, QuadratureType::GaussRadau, QuadratureType::ClenshawCurtis, QuadratureType::Uniform)))
INSTANTIATE_TYPED_TEST_CASE_P(Quadrature, ConceptsTest, QuadratureTypes)
Quadrature handler for Clenshaw-Curtis quadrature.
QuadratureType
Quadrature type descriptors.
Quadrature handler for Gauss-Lobatto quadrature.
Quadrature handler for Gauss-Radau quadrature.
::testing::Types< GaussLegendre<>, GaussLobatto<>, GaussRadau<>, ClenshawCurtis<>, Uniform<> > QuadratureTypes
Functionality related to computing quadrature nodes and weights.
Quadrature handler for Gauss-Legendre quadrature.
TEST_P(QmatTest, AllNodes)
TEST(NodesTest, GaussLegendreNodes)
int main(int argc, char **argv)