rk4.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <iomanip>
10 #include <cmath>
11 #include <boost/program_options.hpp>
12 
13 #include <utl/RK4ODEIntegrator.h>
14 
15 #include "HarmonicOscillator.h"
16 
17 using namespace std;
18 namespace po = boost::program_options;
19 using namespace utl;
20 
21 
22 int
23 main(int argc, char* argv[])
24 {
25  double dx;
26  double x1;
27 
28  po::options_description desc("Allowed options");
29  desc.add_options()
30  ("help,h", "produce help message")
31  ("dx,d", po::value<double>(&dx)->default_value(0.5), "step size")
32  ("x1,1", po::value<double>(&x1)->default_value(1000), "end point")
33  ;
34 
35  po::variables_map vm;
36  po::store(po::parse_command_line(argc, argv, desc), vm);
37  po::notify(vm);
38 
39  if (vm.count("help")) {
40  cout << desc << '\n';
41  return EXIT_SUCCESS;
42  }
43 
44  typedef double Vector[2];
45 
46  const double m = 1;
47  const double k = 1;
48  HarmonicOscillator ho(m, k);
49 
50  const double x0 = 0;
51  const Vector y0 = { 1, 0 };
52 
53  cout << setprecision(16);
54 
56 
57  for (RK4Iterator<HarmonicOscillator, Vector> it = rk4.Begin(x0, y0);
58  it.GetX() <= x1; it += dx)
59  cout << it.GetX() << ' '
60  << it.GetY()[0] << ' '
61  << it.GetY()[1] << '\n';
62 
63  return EXIT_SUCCESS;
64 }
RK4Iterator< DerivativeFunctor, VectorType > Begin(const double x, const VectorType &y)
int main(int argc, char *argv[])
Definition: DBSync.cc:58
Vector object.
Definition: Vector.h:30
constexpr double m
Definition: AugerUnits.h:121

, generated on Tue Sep 26 2023.