From 5233c01a26329306c9f1d08c1a39733aee2cc518 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 21 Dec 2004 09:22:10 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2423, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=2424 --- chaos/src/ode_base.hpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 chaos/src/ode_base.hpp (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp new file mode 100644 index 0000000..5fdd6d1 --- /dev/null +++ b/chaos/src/ode_base.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#ifndef __ode_base_hpp + +#include "chaos_base.hpp" + +class ode_base + : protected chaos_base +{ +public: + void set_method(int i) + { + if (i >=0 && i <4) + m_method = (unsigned char) i; + post("no such method"); + } + + t_int get_method() + { + return (int) m_method; + } + + void set_dt(t_float f) + { + if (f >= 0) + m_dt = (data_t)f; + else + post("invalid value for dt: %f", f); + } + + t_float get_dt() + { + return (t_float) m_dt; + } + + void m_step(); + +protected: + unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ + data_t m_dt; /* step width */ + + data_t* m_k[3]; /* temporary arrays for runge kutta */ + data_t* m_tmp; + + virtual void m_system (data_t* deriv, data_t* data); + + void rk1 (); + void rk2 (); + void rk4 (); +}; + +#define ODE_CALLBACKS \ +CHAOS_CALLBACKS; \ +FLEXT_CALLVAR_I(m_system->get_method, m_system->set_method); \ +FLEXT_CALLVAR_F(m_system->get_dt, m_system->set_dt); + +#define ODE_ATTRIBUTES \ +CHAOS_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("method", m_system->get_method, m_system->set_method); \ +FLEXT_ADDATTR_VAR("dt",m_system->get_dt, m_system->set_dt); + + +#define __ode_base_hpp +#endif /* __ode_base_hpp */ -- cgit v1.2.1 From 45932d6b4b33ecd4f4dc2e7eab9f210dfa46cc34 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Dec 2004 15:31:14 +0000 Subject: xmas's changes svn path=/trunk/externals/tb/; revision=2427 --- chaos/src/ode_base.hpp | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 5fdd6d1..6fa7e27 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -24,14 +24,15 @@ #include "chaos_base.hpp" class ode_base - : protected chaos_base + : public chaos_base { public: void set_method(int i) { if (i >=0 && i <4) m_method = (unsigned char) i; - post("no such method"); + else + post("no such method"); } t_int get_method() @@ -39,44 +40,39 @@ public: return (int) m_method; } - void set_dt(t_float f) - { - if (f >= 0) - m_dt = (data_t)f; - else - post("invalid value for dt: %f", f); - } - - t_float get_dt() + CHAOS_SYSPAR_FUNCS_PRED(dt, m_pred_dt); + + bool m_pred_dt(t_float f) { - return (t_float) m_dt; + return (f >= 0); } - void m_step(); + virtual void m_step(); protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ - data_t m_dt; /* step width */ data_t* m_k[3]; /* temporary arrays for runge kutta */ data_t* m_tmp; - virtual void m_system (data_t* deriv, data_t* data); + virtual void m_system (data_t* deriv, data_t* data) + { + } void rk1 (); void rk2 (); void rk4 (); }; -#define ODE_CALLBACKS \ -CHAOS_CALLBACKS; \ -FLEXT_CALLVAR_I(m_system->get_method, m_system->set_method); \ -FLEXT_CALLVAR_F(m_system->get_dt, m_system->set_dt); +#define ODE_CALLBACKS \ +CHAOS_CALLBACKS; \ +CHAOS_SYS_CALLBACKS_I(method); \ +CHAOS_SYS_CALLBACKS(dt); -#define ODE_ATTRIBUTES \ -CHAOS_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("method", m_system->get_method, m_system->set_method); \ -FLEXT_ADDATTR_VAR("dt",m_system->get_dt, m_system->set_dt); +#define ODE_ATTRIBUTES \ +CHAOS_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(method); \ +CHAOS_SYS_ATTRIBUTE(dt); #define __ode_base_hpp -- cgit v1.2.1 From 5c3670b6322b60b8bc5f60e22d891fe39b854e3e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Dec 2004 23:20:22 +0000 Subject: more changes ... getting stable ... svn path=/trunk/externals/tb/; revision=2428 --- chaos/src/ode_base.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 6fa7e27..cc526ae 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -49,6 +49,28 @@ public: virtual void m_step(); + void ode_base_alloc() + { + int dimension = get_num_eq(); + + for (int i = 0; i != 3; ++i) + { + m_k[i] = new data_t[dimension]; + } + + m_tmp = new data_t[dimension]; + } + + void ode_base_free() + { + for (int i = 0; i != 3; ++i) + { + delete m_k[i]; + } + + delete m_tmp; + } + protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ -- cgit v1.2.1 From 2a0d532e5965402f19f74f70dfdcc7efd1055b15 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 1 Jan 2005 11:06:58 +0000 Subject: speedup using function pointers svn path=/trunk/externals/tb/; revision=2439 --- chaos/src/ode_base.hpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'chaos/src/ode_base.hpp') 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 */ -- cgit v1.2.1 From d1ed55f96f9cecc818844006fb36cd58ca70da5e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 16 Jun 2005 13:02:02 +0000 Subject: - parameter searching (broken) - misc. updates svn path=/trunk/externals/tb/; revision=3192 --- chaos/src/ode_base.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index a15dc08..b7139d2 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -68,7 +68,7 @@ public: void ode_base_alloc() { int dimension = get_num_eq(); - + for (int i = 0; i != 3; ++i) { m_k[i] = new data_t[dimension]; @@ -87,15 +87,14 @@ public: } protected: - void (ode_base::*m_routine)(); + void (ode_base::*m_routine)(void); + unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ data_t* m_k[3]; /* temporary arrays for runge kutta */ data_t* m_tmp; - virtual void m_system (data_t* deriv, data_t* data) - { - } + virtual void m_system (data_t* deriv, data_t* data) = 0; void rk1 (); void rk2 (); -- cgit v1.2.1 From ef53e19b3d9019b1b1f3345390f55ae9229ce390 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 22 Oct 2005 15:11:45 +0000 Subject: cleanups and new system svn path=/trunk/externals/tb/; revision=3750 --- chaos/src/ode_base.hpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index b7139d2..11811f7 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -27,6 +27,26 @@ class ode_base : public chaos_base { public: + ode_base(int n): + chaos_base (n) + { + for (int i = 0; i != 3; ++i) + { + m_k[i] = new data_t[n]; + } + m_tmp = new data_t[n]; + + } + + ~ode_base() + { + for (int i = 0; i != 3; ++i) + { + delete[] m_k[i]; + } + delete[] m_tmp; + } + void set_method(int i) { if (i >=0 && i <4) @@ -65,27 +85,6 @@ public: (this->*m_routine)(); } - void ode_base_alloc() - { - int dimension = get_num_eq(); - - for (int i = 0; i != 3; ++i) - { - m_k[i] = new data_t[dimension]; - } - - m_tmp = new data_t[dimension]; - } - - void ode_base_free() - { - for (int i = 0; i != 3; ++i) - { - delete m_k[i]; - } - delete m_tmp; - } - protected: void (ode_base::*m_routine)(void); -- cgit v1.2.1 From 13cba7a7997e318fbba01a36912219355e387d52 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 May 2006 18:34:34 +0000 Subject: rewrote most stuff using templates svn path=/trunk/externals/tb/; revision=5105 --- chaos/src/ode_base.hpp | 96 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 33 deletions(-) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 11811f7..b198dc5 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -23,45 +23,27 @@ #include "chaos_base.hpp" -class ode_base - : public chaos_base +template +class ode_base: + public chaos_base { public: - ode_base(int n): - chaos_base (n) - { - for (int i = 0; i != 3; ++i) - { - m_k[i] = new data_t[n]; - } - m_tmp = new data_t[n]; - - } - ~ode_base() - { - for (int i = 0; i != 3; ++i) - { - delete[] m_k[i]; - } - delete[] m_tmp; - } - void set_method(int i) { - if (i >=0 && i <4) + if (i >= 0 && i < 4) { m_method = (unsigned char) i; switch (i) { case 0: - m_routine = &ode_base::rk1; + m_routine = &ode_base::rk1; break; case 1: - m_routine = &ode_base::rk2; + m_routine = &ode_base::rk2; break; case 2: - m_routine = &ode_base::rk4; + m_routine = &ode_base::rk4; } } else @@ -86,27 +68,75 @@ public: } protected: - void (ode_base::*m_routine)(void); + void (ode_base::*m_routine)(void); unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ - data_t* m_k[3]; /* temporary arrays for runge kutta */ - data_t* m_tmp; + data_t m_k0[dimensions]; + data_t m_k1[dimensions]; + data_t m_k2[dimensions]; + data_t m_k3[dimensions]; + data_t m_tmp[dimensions]; +// data_t m_tmp[dimensions]; virtual void m_system (data_t* deriv, data_t* data) = 0; - void rk1 (); - void rk2 (); - void rk4 (); + void rk1() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += m_dt * m_k0[i]; + } + + void rk2() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// m_k0[i] = m_k0[i] * 0.5 * m_dt + m_data[i]; +// +// m_system (m_k1, m_k0); +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += m_dt * m_k1[i]; + } + + void rk4() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k0[i] *= m_dt; +// m_tmp[i] = m_data[i] + 0.5 * m_k0[i]; +// } +// +// m_system (m_k1, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k1[i] *= m_dt; +// m_tmp[i] = m_data[i] + 0.5 * m_k1[i]; +// } +// +// m_system (m_k2, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k2[i] *= m_dt; +// m_tmp[i] = m_data[i] + m_k2[i]; +// } +// +// m_system (m_k3, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// m_k3[i] *= m_dt; +// +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) +// / 6.; + } }; #define ODE_CALLBACKS \ -CHAOS_CALLBACKS; \ CHAOS_SYS_CALLBACKS_I(method); \ CHAOS_SYS_CALLBACKS(dt); #define ODE_ATTRIBUTES \ -CHAOS_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(method); \ CHAOS_SYS_ATTRIBUTE(dt); -- cgit v1.2.1 From 2c157bd8aa1f5387169cc0c0910d36c8068c4068 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 May 2006 19:17:04 +0000 Subject: improved inlining for maps svn path=/trunk/externals/tb/; revision=5106 --- chaos/src/ode_base.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index b198dc5..f46332c 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -62,7 +62,7 @@ public: return (f >= 0); } - virtual void m_step() + void m_step() { (this->*m_routine)(); } -- cgit v1.2.1 From fae4d2ec359b596a775973956daf4636856f0141 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 6 Sep 2006 20:32:21 +0000 Subject: cleanups svn path=/trunk/externals/tb/; revision=5880 --- chaos/src/ode_base.hpp | 79 +++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 40 deletions(-) (limited to 'chaos/src/ode_base.hpp') diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index f46332c..42478bc 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -76,59 +76,58 @@ protected: data_t m_k1[dimensions]; data_t m_k2[dimensions]; data_t m_k3[dimensions]; - data_t m_tmp[dimensions]; -// data_t m_tmp[dimensions]; + data_t m_tmp[dimensions]; virtual void m_system (data_t* deriv, data_t* data) = 0; void rk1() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += m_dt * m_k0[i]; + m_system (m_k0, chaos_base::m_data); + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += m_dt * m_k0[i]; } void rk2() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// m_k0[i] = m_k0[i] * 0.5 * m_dt + m_data[i]; -// -// m_system (m_k1, m_k0); -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += m_dt * m_k1[i]; + for (int i = 0; i != dimensions; ++i) + m_k0[i] = m_k0[i] * 0.5 * m_dt + chaos_base::m_data[i]; + + m_system (m_k0, chaos_base::m_data); + m_system (m_k1, m_k0); + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += m_dt * m_k1[i]; } void rk4() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k0[i] *= m_dt; -// m_tmp[i] = m_data[i] + 0.5 * m_k0[i]; -// } -// -// m_system (m_k1, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k1[i] *= m_dt; -// m_tmp[i] = m_data[i] + 0.5 * m_k1[i]; -// } -// -// m_system (m_k2, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k2[i] *= m_dt; -// m_tmp[i] = m_data[i] + m_k2[i]; -// } -// -// m_system (m_k3, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// m_k3[i] *= m_dt; -// -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) -// / 6.; + m_system (m_k0, chaos_base::m_data); + for (int i = 0; i != dimensions; ++i) + { + m_k0[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + 0.5 * m_k0[i]; + } + + m_system (m_k1, m_tmp); + for (int i = 0; i != dimensions; ++i) + { + m_k1[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + 0.5 * m_k1[i]; + } + + m_system (m_k2, m_tmp); + for (int i = 0; i != dimensions; ++i) + { + m_k2[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + m_k2[i]; + } + + m_system (m_k3, m_tmp); + for (int i = 0; i != dimensions; ++i) + m_k3[i] *= m_dt; + + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) + / 6.; } }; -- cgit v1.2.1