PFASST++
scalar_sdc.cpp
Go to the documentation of this file.
1 
9 #include <complex>
10 using namespace std;
11 
12 #include <pfasst.hpp>
13 #include <pfasst/config.hpp>
14 #include <pfasst/logging.hpp>
16 #include <pfasst/encap/vector.hpp>
17 
18 #include "scalar_sweeper.hpp"
19 
20 namespace pfasst
21 {
22  namespace examples
23  {
24  namespace scalar
25  {
38  double run_scalar_sdc(const size_t nsteps, const double dt, const size_t nnodes,
39  const size_t niters, const complex<double> lambda,
40  const quadrature::QuadratureType nodetype)
41  {
42  SDC<> sdc;
43 
44  // For test equation, set initial value to \\( 1+0i \\)
45  const complex<double> y0 = complex<double>(1.0, 0.0);
46 
47  auto quad = quadrature::quadrature_factory(nnodes, nodetype);
48 
49  // This is a scalar example, so we use the encap::VectorFactory with fixed length of 1 and
50  // complex type.
51  auto factory = make_shared<encap::VectorFactory<complex<double>>>(1);
52  auto sweeper = make_shared<ScalarSweeper<>>(lambda, y0);
53 
54  sweeper->set_quadrature(quad);
55  sweeper->set_factory(factory);
56 
57  sdc.add_level(sweeper);
58 
59  // Final time Tend = dt*nsteps
60  sdc.set_duration(0.0, dt*nsteps, dt, niters);
61  sdc.setup();
62 
63  auto q0 = sweeper->get_start_state();
64  sweeper->exact(q0, 0.0);
65 
66  sdc.run();
67 
68  return sweeper->get_errors();
69  }
70  } // ::pfasst::examples::scalar
71  } // ::pfasst::examples
72 } // ::pfasst
73 
74 #ifndef PFASST_UNIT_TESTING
75 int main(int argc, char** argv)
76 {
77  const size_t nsteps = 2;
78  const double dt = 1.0;
79  const size_t nnodes = 4;
80  const size_t niters = 6;
81  const complex<double> lambda = complex<double>(-1.0, 1.0);
83 
84  pfasst::init(argc, argv);
85 
86  pfasst::examples::scalar::run_scalar_sdc(nsteps, dt, nnodes, niters, lambda, nodetype);
87 }
88 #endif
virtual void run()
Run vanilla SDC.
Definition: sdc_impl.hpp:22
QuadratureType
Quadrature type descriptors.
Definition: interface.hpp:32
STL namespace.
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.
static void init(int argc, char **argv, std::function< void()> opts=nullptr, std::function< void()> logs=nullptr)
Definition: pfasst.hpp:13
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
int main(int argc, char **argv)
Definition: scalar_sdc.cpp:75
double run_scalar_sdc(const size_t nsteps, const double dt, const size_t nnodes, const size_t niters, const complex< double > lambda, const quadrature::QuadratureType nodetype)
Scalar test equation example using an encapsulated IMEX sweeper.
Definition: scalar_sdc.cpp:38
virtual void setup()
Basic setup routine for this controller.
float dt
Definition: plot.py:10