diff options
author | Tim Blechmann <timblech@users.sourceforge.net> | 2005-01-01 11:06:58 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@iem.at> | 2015-10-14 15:11:58 +0200 |
commit | 2a0d532e5965402f19f74f70dfdcc7efd1055b15 (patch) | |
tree | 65cf38a9d098e9867287b7a274220da401cb6b57 /chaos/src/ode_base.hpp | |
parent | 2f98df88850ab893c7acf8ea2b9000c03c2e17da (diff) |
speedup using function pointers
svn path=/trunk/externals/tb/; revision=2439
Diffstat (limited to 'chaos/src/ode_base.hpp')
-rw-r--r-- | chaos/src/ode_base.hpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index cc526ae..a15dc08 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -30,7 +30,20 @@ public: void set_method(int i) { if (i >=0 && i <4) + { m_method = (unsigned char) i; + switch (i) + { + case 0: + m_routine = &ode_base::rk1; + break; + case 1: + m_routine = &ode_base::rk2; + break; + case 2: + m_routine = &ode_base::rk4; + } + } else post("no such method"); } @@ -47,7 +60,10 @@ public: return (f >= 0); } - virtual void m_step(); + virtual void m_step() + { + (this->*m_routine)(); + } void ode_base_alloc() { @@ -67,11 +83,11 @@ public: { delete m_k[i]; } - delete m_tmp; } protected: + void (ode_base::*m_routine)(); unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ data_t* m_k[3]; /* temporary arrays for runge kutta */ |