1+ /*
2+ * Tests for the scalar example solving the test equation
3+ */
4+
5+ #include < cmath>
6+ #include < gtest/gtest.h>
7+ #include < gmock/gmock.h>
8+
9+ #define PFASST_UNIT_TESTING
10+ #include " ../examples/scalar/scalar_sdc.cpp"
11+ #undef PFASST_UNIT_TESTING
12+
13+ MATCHER (DoubleMore, " " )
14+ {
15+ return get<0 >(arg) > get<1 >(arg);
16+ }
17+
18+
19+ /*
20+ * For Lobatto nodes, the resulting method should of order 2*M-2 with M=number of nodes
21+ * The test below verifies that the code approximately (up to a safety factor) reproduces
22+ * the theoretically expected rate of convergence
23+ */
24+ TEST (ConvergenceTest, ScalarSDC)
25+ {
26+
27+ const complex <double > lambda = complex <double >(-1.0 , 1.0 );
28+ const double Tend = 4.0 ;
29+ const vector<size_t > nsteps = { 2 , 5 , 10 , 15 , 20 };
30+ size_t nsteps_l = nsteps.size ();
31+
32+ vector<double > err (nsteps.size ());
33+ vector<double > convrate (nsteps.size ()-1 );
34+
35+ double dt;
36+
37+ // Test converge up to 6 nodes: For more nodes, errors are of the order of machine
38+ // precision and convergence can no longer be monitored
39+ for ( size_t nnodes = 2 ; nnodes<=6 ; ++nnodes)
40+ {
41+ // Expect convergence rate of 2*nodes-2 from collocation formula,
42+ // doing an identical number of iteration should suffice to reach this as each
43+ // iteration should increase order by one
44+ size_t niters = 2 *nnodes-2 ;
45+
46+ for ( size_t i = 0 ; i<=nsteps_l-1 ; ++i)
47+ {
48+ dt = Tend/double (nsteps[i]);
49+ err[i] = run_scalar_sdc (nsteps[i], dt, nnodes, niters, lambda);
50+ }
51+
52+ for ( size_t i = 0 ; i<=nsteps_l-2 ; ++i)
53+ {
54+ convrate[i] = log10 (err[i+1 ]/err[i])/log10 (double (nsteps[i])/double (nsteps[i+1 ]));
55+
56+ EXPECT_THAT (convrate[i], testing::DoubleNear (double (2 *nnodes-2 ), 0.99 )) << " Convergence rate at node " << i << " not within expected range" ;
57+ }
58+
59+ // NOTE: There is probably a much more elegant way to test this, because
60+ // expected_cr contains the same value in all entries. But I could not so far figure
61+ // out how to build a more clever MATCHER here so far....
62+ // EXPECT_THAT(convrate, testing::Pointwise(DoubleMore(), expected_cr ));
63+
64+ }
65+ }
66+
67+ int main (int argc, char ** argv)
68+ {
69+ testing::InitGoogleTest (&argc, argv);
70+ return RUN_ALL_TESTS ();
71+ }
0 commit comments