Skip to content

Commit f5d2966

Browse files
author
Daniel
committed
test_scalar now also checks legendre nodes, but the test with DoubleNear fail, because we encounter better-than-expected convergence. Need a DoubleMore, but I did not get a corresponding matcher to run properly
1 parent b7a0579 commit f5d2966

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

tests/examples/scalar/test_scalar.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ using namespace ::testing;
1212
#include "../examples/scalar/scalar_sdc.cpp"
1313
#undef PFASST_UNIT_TESTING
1414

15+
MATCHER(MyDoubleMore, "")
16+
{
17+
return get<0>(arg) > get<1>(arg);
18+
}
19+
20+
1521
/*
1622
* parameterized test fixture with number of nodes as parameter
1723
*/
@@ -21,12 +27,12 @@ class ConvergenceTest
2127
protected:
2228
size_t nnodes; // parameter
2329

24-
const complex<double> lambda = complex<double>(-1.0, 1.0);
25-
const double Tend = 4.0;
26-
const vector<size_t> nsteps = { 2, 5, 10, 15, 20 };
30+
complex<double> lambda = complex<double>(-1.0, 1.0);
31+
double Tend = 4.0;
32+
vector<size_t> nsteps = { 2, 5, 10, 15, 20 };
2733
size_t nsteps_l;
2834
vector<double> err;
29-
vector<double> convrate;
35+
vector<double> convrate_lobatto;
3036
vector<double> convrate_legendre;
3137
double dt;
3238
size_t niters;
@@ -38,10 +44,9 @@ class ConvergenceTest
3844
this->nnodes = this->GetParam();
3945
this->nsteps_l = this->nsteps.size();
4046
this->err.resize(this->nsteps.size());
41-
this->convrate.resize(this->nsteps.size());
47+
this->convrate_lobatto.resize(this->nsteps.size());
4248

43-
// Run first for Lobatto nodes
44-
49+
// Run first for Lobatto nodes which is the default nodetype
4550

4651
// Expect convergence rate of 2*nodes-2 from collocation formula,
4752
// doing an identical number of iteration should suffice to reach this as each
@@ -56,17 +61,33 @@ class ConvergenceTest
5661

5762
// compute convergence rates
5863
for (size_t i = 0; i <= nsteps_l - 2; ++i) {
59-
convrate[i] = log10(err[i+1] / err[i]) / log10(double(nsteps[i]) / double(nsteps[i + 1]));
64+
convrate_lobatto[i] = log10(err[i+1] / err[i]) / log10(double(nsteps[i]) / double(nsteps[i + 1]));
6065
}
6166

6267
// Run for Legendre nodes
6368
nodetype = pfasst::QuadratureType::GaussLegendre;
6469
this->convrate_legendre.resize(this->nsteps.size());
6570

71+
// refine parameter
72+
complex<double> lambda = complex<double>(-1.0, 4.0);
73+
this->Tend = 5.0;
74+
this->nsteps = { 5, 7, 9, 11, 13 };
75+
this->niters = 2*nnodes;
76+
77+
// run to compute errors
78+
for (size_t i = 0; i <= nsteps_l - 1; ++i) {
79+
dt = Tend / double(nsteps[i]);
80+
6681
// NOTE: Setting M for Legendre nodes actually only results in M-2 "real" nodes,
67-
// because the first and the last are used for initial and final value.
68-
this->niters = 2*(nnodes-2);
82+
// because the first and the last are used for initial and final value.
83+
// Hence us nnodes+2 as argument
84+
err[i] = run_scalar_sdc(nsteps[i], dt, nnodes+2, niters, lambda, nodetype);
85+
}
6986

87+
for (size_t i = 0; i <= nsteps_l - 2; ++i) {
88+
convrate_legendre[i] = log10(err[i+1] / err[i]) / log10(double(nsteps[i]) / double(nsteps[i + 1]));
89+
}
90+
7091
}
7192

7293
virtual void TearDown()
@@ -78,14 +99,19 @@ class ConvergenceTest
7899
* The test below verifies that the code approximately (up to a safety factor) reproduces
79100
* the theoretically expected rate of convergence
80101
*/
81-
TEST_P(ConvergenceTest, GaussLobattoNodes)
102+
TEST_P(ConvergenceTest, GaussNodes)
82103
{
83104
for (size_t i = 0; i <= nsteps_l - 2; ++i) {
84105

85-
EXPECT_THAT(convrate[i],
106+
EXPECT_THAT(convrate_lobatto[i],
86107
testing::DoubleNear(double(2 * nnodes - 2), 0.99)) << "Convergence rate at node "
87108
<< i
88109
<< " not within expected range";
110+
EXPECT_THAT(convrate_legendre[i],
111+
testing::DoubleNear(double(2 * nnodes ), 0.9)) << "Convergence rate at node "
112+
<< i
113+
<< " not within expected range";
114+
89115
}
90116
}
91117

0 commit comments

Comments
 (0)