PFASST++
test_vdp_zeronu_conv.cpp
Go to the documentation of this file.
1 
5 #include <cmath>
6 using namespace std;
7 
8 #include <gtest/gtest.h>
9 #include <gmock/gmock.h>
10 using namespace ::testing;
11 
12 #include <pfasst/quadrature.hpp>
13 
14 #define PFASST_UNIT_TESTING
15 #include "../examples/vanderpol/vdp_sdc.cpp"
16 #undef PFASST_UNIT_TESTING
17 using namespace pfasst::examples::vdp;
18 
19 /*
20  * parameterized test fixture with number of nodes as parameter
21  */
23  : public TestWithParam<tuple<size_t, pfasst::quadrature::QuadratureType>>
24 {
25  protected:
26  size_t nnodes;
27 
28  const double nu = 0.0;
29  const double x0 = 1.0;
30  const double y0 = 0.5;
31 
32  size_t niters;
33  double end_time;
34  vector<size_t> nsteps;
35  vector<double> err;
36  vector<double> convrate;
38 
39  public:
40  virtual void SetUp()
41  {
42  this->nnodes = get<0>(GetParam());
43  this->nodetype = get<1>(GetParam());
44 
45  switch (this->nodetype)
46  {
48  this->niters = 2 * this->nnodes;
49  this->end_time = 0.88;
50  this->nsteps = { 7, 9, 11 };
51  break;
52 
54  this->niters = 2 * this->nnodes - 1;
55  this->end_time = 0.88;
56  this->nsteps = { 7, 9, 11, 13 };
57  break;
58 
59  default:
60  break;
61  }
62 
63  // run to compute errors
64  for (size_t i = 0; i < this->nsteps.size(); ++i) {
65  auto dt = this->end_time / this->nsteps[i];
66  this->err.push_back(run_vdp_sdc(this->nsteps[i], dt, this->nnodes,
67  this->niters, this->nu, this->x0, this->y0, this->nodetype));
68  }
69 
70  // compute convergence rates
71  for (size_t i = 0; i < this->nsteps.size() - 1; ++i) {
72  this->convrate.push_back(log10(this->err[i+1] / this->err[i]) /
73  log10(double(this->nsteps[i]) / double(this->nsteps[i + 1])));
74  }
75  }
76 
77 };
78 
79 /*
80  * The test below verifies that the code approximately (up to a safety factor) reproduces
81  * the theoretically expected rate of convergence
82  */
84 {
85  int order;
86  string quad;
87 
88  switch (this->nodetype)
89  {
91  order = 2 * this->nnodes;
92  quad = "Gauss-Legendre";
93  break;
95  order = 2 * this->nnodes - 1;
96  quad = "Gauss-Radau";
97  break;
98  default:
99  EXPECT_TRUE(false);
100  break;
101  }
102 
103  for (size_t i = 0; i < this->nsteps.size() - 1; ++i) {
104  EXPECT_THAT(convrate[i], Ge<double>(0.99 * order)) << "Convergence rate for "
105  << this->nnodes << " " << quad << " nodes"
106  << " for nsteps " << this->nsteps[i]
107  << " not within expected range.";
108  }
109 }
110 
112  Combine(Range<size_t>(3, 4),
115 
116 int main(int argc, char** argv)
117 {
118  pfasst::init(argc, argv);
119  testing::InitGoogleTest(&argc, argv);
120  return RUN_ALL_TESTS();
121 }
QuadratureType
Quadrature type descriptors.
Definition: interface.hpp:32
STL namespace.
pfasst::quadrature::QuadratureType nodetype
double run_vdp_sdc(const size_t nsteps, const double dt, const size_t nnodes, const size_t niters, const double nu, const double x0, const double y0, const quadrature::QuadratureType nodetype)
Definition: vdp_sdc.cpp:23
TEST_P(VdPConvergenceTest, AllNodes)
static void init(int argc, char **argv, std::function< void()> opts=nullptr, std::function< void()> logs=nullptr)
Definition: pfasst.hpp:13
INSTANTIATE_TEST_CASE_P(VanDerPol, VdPConvergenceTest, Combine(Range< size_t >(3, 4), Values(pfasst::quadrature::QuadratureType::GaussLegendre, pfasst::quadrature::QuadratureType::GaussRadau)))
int main(int argc, char **argv)
float dt
Definition: plot.py:10
vector< double > convrate