PFASST++
vdp_sdc.cpp
Go to the documentation of this file.
1 
6 #include <pfasst.hpp>
7 #include <pfasst/config.hpp>
8 #include <pfasst/logging.hpp>
10 #include <pfasst/encap/vector.hpp>
11 
12 #include "vdp_sweeper.hpp"
13 
14 namespace pfasst
15 {
16  namespace examples
17  {
18  namespace vdp
19  {
23  double run_vdp_sdc(const size_t nsteps, const double dt, const size_t nnodes,
24  const size_t niters, const double nu, const double x0,
25  const double y0, const quadrature::QuadratureType nodetype)
26  {
27  SDC<> sdc;
28 
29  auto quad = quadrature::quadrature_factory(nnodes, nodetype);
30 
31  // van der Pol oscillator (as first order system) has two components
32  auto factory = make_shared<encap::VectorFactory<double>>(2);
33  // input is parameter nu and initial values for position and velocity
34  auto sweeper = make_shared<VdpSweeper<>>(nu, x0, y0);
35 
36  sweeper->set_quadrature(quad);
37  sweeper->set_factory(factory);
38 
39  sdc.add_level(sweeper);
40 
41  // Final time Tend = dt*nsteps
42  sdc.set_duration(0.0, dt*nsteps, dt, niters);
43  sdc.setup();
44 
45  auto q0 = sweeper->get_start_state();
46  sweeper->exact(q0, 0.0);
47 
48  sdc.run();
49 
50  return sweeper->get_errors();
51  }
52  } // ::pfasst::examples::vdp
53  } // ::pfasst::examples
54 } // ::pfasst
55 
56 
57 #ifndef PFASST_UNIT_TESTING
58 int main(int argc, char** argv)
59 {
60  const double x0 = 2.0,
61  y0 = 0.0;
62  const size_t nsteps = 1000;
63  const double dt = 50.0/( (double) nsteps);
64  const size_t nnodes = 3;
65  const size_t niters = 1;
66  const double nu = 5.0;
68 
69  pfasst::init(argc, argv);
70  ML_LOG(INFO, "Used timestep:" << dt);
71 
72  pfasst::examples::vdp::run_vdp_sdc(nsteps, dt, nnodes, niters, nu, x0, y0, nodetype);
73 }
74 #endif
virtual void run()
Run vanilla SDC.
Definition: sdc_impl.hpp:22
int main(int argc, char **argv)
Definition: vdp_sdc.cpp:58
QuadratureType
Quadrature type descriptors.
Definition: interface.hpp:32
virtual void add_level(shared_ptr< ISweeper< time >> sweeper, shared_ptr< ITransfer< time >> transfer=shared_ptr< ITransfer< time >>(nullptr), bool coarse=true)
Adding a level to the controller.
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
static void init(int argc, char **argv, std::function< void()> opts=nullptr, std::function< void()> logs=nullptr)
Definition: pfasst.hpp:13
#define ML_LOG(level, x)
same as LOG(level, x) from easylogging++
Definition: logging.hpp:110
virtual void set_duration(time t0, time tend, time dt, size_t niters)
Set basic time scope of the Controller.
shared_ptr< IQuadrature< precision > > quadrature_factory(const size_t nnodes, const QuadratureType qtype)
Instantiates quadrature handler for given number of nodes and type descriptor.
Definition: quadrature.hpp:53
Vanilla SDC controller.
Definition: sdc.hpp:24
virtual void setup()
Basic setup routine for this controller.
float dt
Definition: plot.py:10