Skip to content
Snippets Groups Projects
Commit 75b74acc authored by Ian Bell's avatar Ian Bell
Browse files

Add simple euler to odeint test

parent 29927c31
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp> #include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp> #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
#include <boost/numeric/odeint/stepper/euler.hpp>
/* The type of container used to hold the state vector */ /* The type of container used to hold the state vector */
typedef std::vector< double > state_type; typedef std::vector< double > state_type;
...@@ -29,7 +30,7 @@ int main(int /* argc */ , char** /* argv */ ) ...@@ -29,7 +30,7 @@ int main(int /* argc */ , char** /* argv */ )
state_type x0 = {1.0, 0.0}; // Starting point state_type x0 = {1.0, 0.0}; // Starting point
// First integrate, adaptively, until you get as close to the end as you can // First integrate, adaptively, until you get as close to the end as you can
double t = 0, dt = 0.001, tmax = 100.0; double t = 0, dt = 0.001, tmax = 10.0;
auto write = [&]() { std::cout << t << " " << x0[0] << "," << x0[1] << std::endl; }; auto write = [&]() { std::cout << t << " " << x0[0] << "," << x0[1] << std::endl; };
for (auto i = 0; t < tmax; ++i){ for (auto i = 0; t < tmax; ++i){
if (t + dt > tmax) { break; } if (t + dt > tmax) { break; }
...@@ -41,4 +42,23 @@ int main(int /* argc */ , char** /* argv */ ) ...@@ -41,4 +42,23 @@ int main(int /* argc */ , char** /* argv */ )
double dtfinal = tmax - t; double dtfinal = tmax - t;
auto status = controlled_stepper.try_step(xprime, x0, t, dtfinal); auto status = controlled_stepper.try_step(xprime, x0, t, dtfinal);
write(); write();
{
state_type x0 = { 1.0, 0.0 }; // Starting point
euler<state_type> eul;
double t = 0, dt = 0.01, tmax = 10.0;
auto write = [&]() { std::cout << t << " " << x0[0] << "," << x0[1] << std::endl; };
for (auto i = 0; t < tmax; ++i) {
if (t + dt > tmax) { break; }
write();
eul.do_step(xprime, x0, t, dt);
t += dt;
}
write();
double dtfinal = tmax - t;
eul.do_step(xprime, x0, t, dt);
write();
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment