Skip to content

Commit 0f22a8f

Browse files
committed
Merge branch 'development' into feature/travis-different-boost
Conflicts: .travis.yml
2 parents 3d914c1 + 6283b97 commit 0f22a8f

File tree

9 files changed

+400
-109
lines changed

9 files changed

+400
-109
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ language:
33

44
cache: apt
55

6+
notifications:
7+
email:
8+
on_success: change # default: change
9+
on_failure: always # default: always
10+
611
# why does Travis not allow for multi-dimensional build matrices?!?
712
# -> https://github.com/travis-ci/travis-ci/issues/1519
813
env:

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ XXX: DOI: [10.5281/zenodo.11047](http://dx.doi.org/10.5281/zenodo.11047)
1414
stage in a block mode with fixed iterations.
1515
([#46][], [#57][], [#59][])
1616

17-
* Addition of a simple scalar example.
18-
([#61][])
17+
* Addition of a simple scalar example and appropriate tests.
18+
([#61][], [#76][])
1919

2020
* Various tidying
2121
()
@@ -24,16 +24,19 @@ XXX: DOI: [10.5281/zenodo.11047](http://dx.doi.org/10.5281/zenodo.11047)
2424
[#57]: https://github.com/Parallel-in-Time/PFASST/pull/56
2525
[#59]: https://github.com/Parallel-in-Time/PFASST/pull/59
2626
[#61]: https://github.com/Parallel-in-Time/PFASST/pull/61
27+
[#76]: https://github.com/Parallel-in-Time/PFASST/pull/76
2728

2829
### Contributors
2930

3031
* Matthew Emmett, Lawrence Berkeley National Laboratory ([memmett][])
3132
* Torbjörn Klatt, Jülich Supercomputing Centre ([torbjoernk][])
3233
* Daniel Ruprecht, Institute of Computational Science, University of Lugano ([danielru][])
34+
* Robert Speck, Jülich Supercomputing Centre ([pancetta][])
3335

3436
[memmett]: https://github.com/memmett
3537
[torbjoernk]: https://github.com/torbjoernk
3638
[danielru]: https://github.com/danielru
39+
[pancetta]: https://github.com/pancetta
3740

3841
## v0.1.0 -- First Release (2014/07/25)
3942

examples/scalar/scalar_sdc.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
*/
1919

2020
double run_scalar_sdc(const size_t nsteps, const double dt, const size_t nnodes,
21-
const size_t niters, const complex<double> lambda)
21+
const size_t niters, const complex<double> lambda,
22+
const pfasst::QuadratureType nodetype)
2223
{
2324
pfasst::SDC<> sdc;
2425

2526
const complex<double> y0 = complex<double>(1.0, 0.0);
26-
auto nodes = pfasst::compute_nodes(nnodes, pfasst::QuadratureType::GaussLobatto);
27+
28+
auto nodes = pfasst::compute_nodes(nnodes, nodetype);
2729
auto factory = make_shared<pfasst::encap::VectorFactory<complex<double>>>(1);
2830
auto sweeper = make_shared<ScalarSweeper<>>(lambda, y0);
2931

@@ -50,7 +52,8 @@ int main(int /*argc*/, char** /*argv*/)
5052
const size_t nnodes = 4;
5153
const size_t niters = 6;
5254
const complex<double> lambda = complex<double>(-1.0, 1.0);
53-
54-
run_scalar_sdc(nsteps, dt, nnodes, niters, lambda);
55+
const pfasst::QuadratureType nodetype = pfasst::QuadratureType::GaussLobatto;
56+
57+
run_scalar_sdc(nsteps, dt, nnodes, niters, lambda, nodetype);
5558
}
5659
#endif

include/pfasst/quadrature.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,17 @@ namespace pfasst
160160
return p2;
161161
}
162162
};
163-
164-
enum class QuadratureType { GaussLegendre, GaussLobatto, GaussRadau, ClenshawCurtis, Uniform };
163+
164+
165+
enum class QuadratureType {
166+
GaussLegendre
167+
, GaussLobatto
168+
, GaussRadau
169+
, ClenshawCurtis
170+
, Uniform
171+
};
172+
173+
165174
template<typename node = time_precision>
166175
vector<node> compute_nodes(size_t nnodes, QuadratureType qtype)
167176
{

tests/examples/scalar/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ include_directories(
55
)
66

77
set(TESTS
8-
test_scalar
8+
test_scalar_conv
9+
test_scalar_highprec
910
)
1011

1112
foreach(test ${TESTS})
@@ -22,4 +23,4 @@ foreach(test ${TESTS})
2223
add_test(NAME ${test}
2324
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/examples/scalar/${test} --gtest_output=xml:${test}_out.xml
2425
)
25-
endforeach(test)
26+
endforeach(test)

tests/examples/scalar/test_scalar.cpp

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* Tests for the scalar example solving the test equation
3+
*/
4+
#include <cmath>
5+
6+
#include <gtest/gtest.h>
7+
#include <gmock/gmock.h>
8+
9+
using namespace ::testing;
10+
11+
#include <pfasst/quadrature.hpp>
12+
13+
#define PFASST_UNIT_TESTING
14+
#include "../examples/scalar/scalar_sdc.cpp"
15+
#undef PFASST_UNIT_TESTING
16+
17+
/*
18+
* parameterized test fixture with number of nodes as parameter
19+
*/
20+
class ConvergenceTest
21+
: public TestWithParam<tuple<size_t, pfasst::QuadratureType>>
22+
{
23+
protected:
24+
size_t nnodes; // parameter
25+
26+
complex<double> lambda;
27+
double Tend;
28+
vector<size_t> nsteps;
29+
size_t nsteps_l;
30+
vector<double> err;
31+
vector<double> convrate;
32+
double dt;
33+
size_t niters;
34+
pfasst::QuadratureType nodetype;
35+
size_t nnodes_in_call;
36+
37+
// set parameters base on node type
38+
void set_parameters()
39+
{
40+
switch (this->nodetype)
41+
{
42+
case pfasst::QuadratureType::GaussLobatto:
43+
this->niters = 2 * this->nnodes - 2;
44+
this->Tend = 4.0;
45+
this->lambda = complex<double>(-1.0, 1.0);
46+
this->nsteps = { 2, 5, 10, 15, 20 };
47+
this->nnodes_in_call = this->nnodes;
48+
break;
49+
50+
case pfasst::QuadratureType::GaussLegendre:
51+
this->niters = 2 * this->nnodes;
52+
this->Tend = 6.0;
53+
this->lambda = complex<double>(-1.0, 2.0);
54+
this->nsteps = { 2, 4, 6, 8, 10 };
55+
this->nnodes_in_call = this->nnodes + 2;
56+
break;
57+
58+
case pfasst::QuadratureType::GaussRadau:
59+
this->niters = 2 * this->nnodes - 1;
60+
this->Tend = 5.0;
61+
this->lambda = complex<double>(-1.0, 2.0);
62+
this->nsteps = { 4, 6, 8, 10, 12 };
63+
this->nnodes_in_call = this->nnodes + 1;
64+
break;
65+
66+
// NOTE: At the moment, both Clenshaw Curtis and equidistant nodes do not
67+
// reproduce the expected convergence rate... something is wrong, either with
68+
// the test or with the nodes
69+
70+
// Also: What is the ACTUAL number of quadrature nodes in both cases?
71+
case pfasst::QuadratureType::ClenshawCurtis:
72+
this->niters = this->nnodes;
73+
this->Tend = 1.0;
74+
this->lambda = complex<double>(-1.0, 1.0);
75+
this->nsteps = {3, 5, 7, 9, 11};
76+
this->nnodes_in_call = this->nnodes + 1;
77+
break;
78+
79+
case pfasst::QuadratureType::Uniform:
80+
this->niters = this->nnodes;
81+
this->Tend = 5.0;
82+
this->lambda = complex<double>(-1.0, 1.0);
83+
this->nsteps = {3, 5, 7, 9, 11};
84+
this->nnodes_in_call = this->nnodes;
85+
break;
86+
87+
88+
default:
89+
break;
90+
}
91+
}
92+
93+
public:
94+
virtual void SetUp()
95+
{
96+
this->nnodes = get<0>(GetParam());
97+
this->nodetype = get<1>(GetParam());
98+
this->set_parameters();
99+
this->nsteps_l = this->nsteps.size();
100+
this->err.resize(this->nsteps.size());
101+
this->convrate.resize(this->nsteps.size());
102+
103+
// run to compute errors
104+
for (size_t i = 0; i <= this->nsteps_l - 1; ++i) {
105+
this->dt = this->Tend / double(this->nsteps[i]);
106+
this->err[i] = run_scalar_sdc(this->nsteps[i], this->dt, this->nnodes_in_call,
107+
this->niters, this->lambda, this->nodetype);
108+
}
109+
110+
// compute convergence rates
111+
for (size_t i = 0; i <= this->nsteps_l - 2; ++i) {
112+
this->convrate[i] = log10(this->err[i+1] / this->err[i]) /
113+
log10(double(this->nsteps[i]) / double(this->nsteps[i + 1]));
114+
}
115+
}
116+
117+
virtual void TearDown()
118+
{}
119+
};
120+
121+
/*
122+
* The test below verifies that the code approximately (up to a safety factor) reproduces
123+
* the theoretically expected rate of convergence
124+
*/
125+
TEST_P(ConvergenceTest, AllNodes)
126+
{
127+
for (size_t i = 0; i <= nsteps_l - 2; ++i) {
128+
switch (this->nodetype)
129+
{
130+
case pfasst::QuadratureType::GaussLobatto:
131+
// Expect convergence rate of 2*nodes-2 from collocation formula, doing an identical number
132+
// of iteration should suffice to reach this as each iteration should increase order by one
133+
EXPECT_THAT(convrate[i],
134+
DoubleNear(double(2 * nnodes - 2), 0.99)) << "Convergence rate for "
135+
<< this->nnodes
136+
<< " Gauss-Lobatto nodes "
137+
<< " at node " << i
138+
<< " not within expected range.";
139+
break;
140+
141+
case pfasst::QuadratureType::GaussLegendre:
142+
// convergence rates for Legendre nodes should be 2*nodes but are actually better, so
143+
// use Ge here
144+
EXPECT_THAT(convrate[i], Ge<double>(2 * this->nnodes)) << "Convergence rate for "
145+
<< this->nnodes
146+
<< " Gauss-Legendre nodes "
147+
<< " at node " << i
148+
<< " not within expected range.";
149+
break;
150+
151+
152+
case pfasst::QuadratureType::GaussRadau:
153+
// convergence rate for Radau nodes should be 2*nodes-1
154+
// For some case, the convergence rate is ALMOST that value, hence put in the 0.99
155+
EXPECT_THAT(convrate[i], Ge<double>(0.99* 2 * this->nnodes - 1)) << "Convergence rate for "
156+
<< this->nnodes
157+
<< " Gauss-Radu nodes "
158+
<< " at node " << i
159+
<< " not within expected range.";
160+
break;
161+
162+
case pfasst::QuadratureType::ClenshawCurtis:
163+
// Clenshaw Curtis should be of order nnodes
164+
EXPECT_THAT(convrate[i], Ge<double>(this->nnodes)) << "Convergence rate for "
165+
<< this->nnodes
166+
<< " Clenshaw-Curtis nodes "
167+
<< " at node " << i
168+
<< " not within expected range.";
169+
break;
170+
171+
case pfasst::QuadratureType::Uniform:
172+
// Equidistant nodes should be of order nnodes
173+
EXPECT_THAT(convrate[i], Ge<double>(this->nnodes)) << "Convergence rate for "
174+
<< this->nnodes
175+
<< " equidistant nodes "
176+
<< " at node " << i
177+
<< " not within expected range.";
178+
break;
179+
180+
181+
default:
182+
EXPECT_TRUE(false);
183+
break;
184+
}
185+
}
186+
}
187+
188+
INSTANTIATE_TEST_CASE_P(ScalarSDC, ConvergenceTest,
189+
Combine(Range<size_t>(2, 7),
190+
Values(pfasst::QuadratureType::GaussLobatto,
191+
pfasst::QuadratureType::GaussLegendre,
192+
pfasst::QuadratureType::GaussRadau/*,
193+
pfasst::QuadratureType::ClenshawCurtis,
194+
pfasst::QuadratureType::Uniform*/))
195+
);
196+
197+
int main(int argc, char** argv)
198+
{
199+
testing::InitGoogleTest(&argc, argv);
200+
return RUN_ALL_TESTS();
201+
}
202+
203+

0 commit comments

Comments
 (0)