PFASST++
test_mpi_advection_diffusion.cpp
Go to the documentation of this file.
1 /*
2  * Tests for the advection-diffusion examples.
3  */
4 
5 #include <algorithm>
6 #include <iostream>
7 #include <tuple>
8 #include <vector>
9 using namespace std;
10 
11 #include <gtest/gtest.h>
12 #include <gmock/gmock.h>
13 using namespace ::testing;
14 
15 #include <mpi.h>
16 
17 #define PFASST_UNIT_TESTING
18 #include "../examples/advection_diffusion/mpi_pfasst.cpp"
19 #undef PFASST_UNIT_TESTING
21 
22 
23 TEST(ErrorTest, MPIPFASST)
24 {
25  typedef error_map::value_type vtype;
26 
27  auto errors = run_mpi_pfasst(0.0, 0.0, 4, 4, 0.01, 128, 64, 5, 3);
28  auto get_step = [](const vtype x) { return get<0>(get<0>(x)); };
29  auto get_iter = [](const vtype x) { return get<1>(get<0>(x)); };
30  auto get_error = [](const vtype x) { return get<1>(x); };
31 
32  auto max_iter = get_iter(*std::max_element(errors.begin(), errors.end(),
33  [get_iter](const vtype p1, const vtype p2) { return get_iter(p1) < get_iter(p2); }));
34 
35  vector<double> ub = { 1.e-12, 1.e-12, 2.5e-12, 5.e-12 };
36  for (auto& x: errors) {
37  if (get_iter(x) == max_iter) {
38  EXPECT_LE(get_error(x), ub[get_step(x)]);
39  }
40  }
41 }
42 
43 TEST(AdaptiveErrorTest, MPIPFASST)
44 {
45  typedef error_map::value_type vtype;
46 
47  auto errors = run_mpi_pfasst(1.e-8, 0.0, 12, 4, 0.01, 128, 64, 5, 3);
48  auto get_step = [](const vtype x) { return get<0>(get<0>(x)); };
49  auto get_iter = [](const vtype x) { return get<1>(get<0>(x)); };
50  auto get_error = [](const vtype x) { return get<1>(x); };
51 
52  auto max_iter = get_iter(*std::max_element(errors.begin(), errors.end(),
53  [get_iter](const vtype p1, const vtype p2) { return get_iter(p1) < get_iter(p2); }));
54 
55  vector<double> ub = { 5e-8, 5e-8, 5e-8, 5e-8 };
56  for (auto& x: errors) {
57  if (get_iter(x) == max_iter) {
58  EXPECT_LE(get_error(x), ub[get_step(x)]);
59  }
60  }
61 
62  int rank;
63  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
64  vector<size_t> ic = { 1, 1, 2, 2 };
65  ASSERT_EQ(max_iter, (size_t) ic[rank]);
66 }
67 
68 int main(int argc, char** argv)
69 {
70  testing::InitGoogleTest(&argc, argv);
71  MPI_Init(&argc, &argv);
72  pfasst::init(argc, argv,
75  int result = 1, max_result; // GTest return value 1 (failure), 0 (success)
76  // cppcheck-suppress redundantAssignment
77  result = RUN_ALL_TESTS();
78  MPI_Allreduce(&result, &max_result, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
79  MPI_Finalize();
80  return max_result;
81 }
int main(int argc, char **argv)
STL namespace.
static void init(int argc, char **argv, std::function< void()> opts=nullptr, std::function< void()> logs=nullptr)
Definition: pfasst.hpp:13
error_map run_mpi_pfasst(const double abs_res_tol, const double rel_res_tol, const size_t niters, const size_t nsteps, const double dt, const size_t ndofs_f, const size_t ndofs_c, const size_t nnodes_f, const size_t nnodes_c)
Advection/diffusion example using an encapsulated IMEX sweeper.
Definition: mpi_pfasst.cpp:43
advection-diffusion sweeper with semi-implicit time-integration.
TEST(ErrorTest, MPIPFASST)