Skip to content

Commit 3de244b

Browse files
committed
tests: Add test-advection-diffusion.cpp.
This provides a unit test for the errors of the vanilla SDC algorithm. Signed-off-by: Matthew Emmett <[email protected]>
1 parent 01b98db commit 3de244b

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

examples/advection_diffusion/advection_diffusion_sweeper.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class AdvectionDiffusionSweeper
102102
(pair<size_t, size_t>(n, k), max));
103103
}
104104

105+
auto get_errors()
106+
{
107+
return errors;
108+
}
109+
105110
void predict(bool initial)
106111
{
107112
pfasst::encap::IMEXSweeper<time>::predict(initial);

examples/advection_diffusion/vanilla_sdc.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "advection_diffusion_sweeper.hpp"
1616

17-
int main(int argc, char** argv)
17+
auto run_vanilla_sdc()
1818
{
1919
pfasst::SDC<> sdc;
2020

@@ -41,4 +41,14 @@ int main(int argc, char** argv)
4141
sdc.run();
4242

4343
fftw_cleanup();
44+
45+
return sweeper->get_errors();
46+
}
47+
48+
49+
#ifndef PFASST_UNIT_TESTING
50+
int main(int argc, char** argv)
51+
{
52+
run_vanilla_sdc();
4453
}
54+
#endif

tests/test-advection-diffusion.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Tests for the advection-diffusion examples.
3+
*/
4+
5+
#include <algorithm>
6+
#include <iostream>
7+
#include <tuple>
8+
#include <vector>
9+
10+
#include <gtest/gtest.h>
11+
#include <gmock/gmock.h>
12+
13+
#define PFASST_UNIT_TESTING
14+
#include "../examples/advection_diffusion/vanilla_sdc.cpp"
15+
#undef PFASST_UNIT_TESTING
16+
17+
using namespace std;
18+
19+
20+
MATCHER(DoubleNear, "")
21+
{
22+
return abs(get<0>(arg) - get<1>(arg)) < 1e-15;
23+
}
24+
25+
MATCHER(DoubleLess, "")
26+
{
27+
return get<0>(arg) < get<1>(arg);
28+
}
29+
30+
TEST(ErrorTest, VanillaSDC)
31+
{
32+
typedef pair<pair<size_t, size_t>, double> vtype;
33+
34+
auto errors = run_vanilla_sdc();
35+
auto get_iter = [](const vtype x) { return get<1>(get<0>(x)); };
36+
auto get_step = [](const vtype x) { return get<0>(get<0>(x)); };
37+
auto get_error = [](const vtype x) { return get<1>(x); };
38+
39+
auto max_iter = get_iter(*std::max_element(errors.begin(), errors.end(),
40+
[get_iter](const vtype p1, const vtype p2) { return get_iter(p1) < get_iter(p2); }));
41+
42+
vector<double> tol = { 7e-9, 7e-9, 7e-9, 7e-9 };
43+
vector<double> err;
44+
for (auto& x: errors) {
45+
if (get_iter(x) == max_iter) {
46+
err.push_back(get_error(x));
47+
}
48+
}
49+
50+
EXPECT_THAT(err, testing::Pointwise(DoubleLess(), tol));
51+
}
52+
53+
int main(int argc, char** argv)
54+
{
55+
testing::InitGoogleTest(&argc, argv);
56+
return RUN_ALL_TESTS();
57+
}

0 commit comments

Comments
 (0)