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/lorenz.hpp | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 chaos/src/lorenz.hpp (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp new file mode 100644 index 0000000..70dad4d --- /dev/null +++ b/chaos/src/lorenz.hpp @@ -0,0 +1,150 @@ +// +// +// 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. + +#include "ode_base.hpp" + +// lorenz model: dx1/dt = sigma * (x2 - x1) +// dx2/dt = - x1 * x3 + r * x1 - x2 +// dx3/dt = x1 * x2 - b * x3 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class lorenz + : protected ode_base +{ +public: + logistic() + : m_sigma(16), m_b(4), m_r(40) + { + m_num_eq = 3; + m_data = new data_t[3]; + set_x1(0.8f); + set_x2(0.8f); + set_x3(0.8f); + set_method(0); + } + + ~logistic() + { + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0], x2 = data[1], x3 = data[2]; + + deriv[0] = m_sigma * (x2 - x1); + deriv[1] = - x1 * x3 + m_r * x1 - x2; + deriv[3] = x1 * x2 - m_b * x3; + } + + void set_x1(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x1() + { + return (t_float)m_data[0]; + } + + void set_x2(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_x2() + { + return (t_float)m_data[1]; + } + + void set_x3(t_float f) + { + m_data[2] = (data_t) f; + } + + t_float get_x3() + { + return (t_float)m_data[2]; + } + + + void set_sigma(t_float f) + { + if (f > 0) + m_sigma = (data_t) f; + else + post("value for sigma %f out of range", f); + } + + t_float get_sigma() + { + return (t_float)m_sigma; + } + + + void set_r(t_float f) + { + if (f > 0) + m_r = (data_t) f; + else + post("value for r %f out of range", f); + } + + t_float get_r() + { + return (t_float)m_r; + } + + void set_b(t_float f) + { + if (f > 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + + +private: + data_t m_sigma, m_r, m_b; +}; + + +#define LORENZ_CALLBACKS \ +ODE_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_sigma, m_system->set_sigma); \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x1, m_system->set_x1); \ +FLEXT_CALLVAR_F(m_system->get_x2, m_system->set_x2); \ +FLEXT_CALLVAR_F(m_system->get_x3, m_system->set_x3); + +#define LORENZ_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("sigma",m_system->get_sigma, m_system->set_sigma); \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("b",m_system->get_g, m_system->set_g); \ +FLEXT_ADDATTR_VAR("x1",m_system->get_x1, m_system->set_x1); \ +FLEXT_ADDATTR_VAR("x2",m_system->get_x2, m_system->set_x2); \ +FLEXT_ADDATTR_VAR("x3",m_system->get_x3, m_system->set_x3); -- cgit v1.2.1 From 404bfef9e23dfc3166cb2005367e7e8a41863914 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 23 Dec 2004 10:07:17 +0000 Subject: base class macros svn path=/trunk/externals/tb/; revision=2426 --- chaos/src/lorenz.hpp | 129 ++++++++++++++------------------------------------- 1 file changed, 36 insertions(+), 93 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index 70dad4d..e3e5ccd 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -30,13 +30,17 @@ class lorenz { public: logistic() - : m_sigma(16), m_b(4), m_r(40) { m_num_eq = 3; m_data = new data_t[3]; - set_x1(0.8f); - set_x2(0.8f); - set_x3(0.8f); + + CHAOS_SYS_INIT(x1,0.8); + CHAOS_SYS_INIT(x2,0.8); + CHAOS_SYS_INIT(x3,0.8); + CHAOS_SYS_INIT(sigma,16); + CHAOS_SYS_INIT(b,4); + CHAOS_SYS_INIT(r,40); + set_method(0); } @@ -49,102 +53,41 @@ public: { data_t x1 = data[0], x2 = data[1], x3 = data[2]; - deriv[0] = m_sigma * (x2 - x1); - deriv[1] = - x1 * x3 + m_r * x1 - x2; - deriv[3] = x1 * x2 - m_b * x3; - } - - void set_x1(t_float f) - { - m_data[0] = (data_t) f; + deriv[0] = CHAOS_PARAMETER(sigma) * (x2 - x1); + deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; + deriv[3] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } - t_float get_x1() - { - return (t_float)m_data[0]; - } - - void set_x2(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_x2() - { - return (t_float)m_data[1]; - } - - void set_x3(t_float f) - { - m_data[2] = (data_t) f; - } - - t_float get_x3() - { - return (t_float)m_data[2]; - } + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + CHAOS_SYSPAR_FUNCS_PRED(sigma, m_pred); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred); - void set_sigma(t_float f) + bool m_pred (t_float f) { - if (f > 0) - m_sigma = (data_t) f; - else - post("value for sigma %f out of range", f); + return (f > 0); } - t_float get_sigma() - { - return (t_float)m_sigma; - } - - - void set_r(t_float f) - { - if (f > 0) - m_r = (data_t) f; - else - post("value for r %f out of range", f); - } - - t_float get_r() - { - return (t_float)m_r; - } - - void set_b(t_float f) - { - if (f > 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - - -private: - data_t m_sigma, m_r, m_b; }; -#define LORENZ_CALLBACKS \ -ODE_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_sigma, m_system->set_sigma); \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x1, m_system->set_x1); \ -FLEXT_CALLVAR_F(m_system->get_x2, m_system->set_x2); \ -FLEXT_CALLVAR_F(m_system->get_x3, m_system->set_x3); - -#define LORENZ_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("sigma",m_system->get_sigma, m_system->set_sigma); \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("b",m_system->get_g, m_system->set_g); \ -FLEXT_ADDATTR_VAR("x1",m_system->get_x1, m_system->set_x1); \ -FLEXT_ADDATTR_VAR("x2",m_system->get_x2, m_system->set_x2); \ -FLEXT_ADDATTR_VAR("x3",m_system->get_x3, m_system->set_x3); +#define LORENZ_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); \ +CHAOS_SYS_CALLBACKS(sigma); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(b); + +#define LORENZ_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); \ +CHAOS_SYS_ATTRIBUTE(sigma); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(b); -- 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/lorenz.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index e3e5ccd..700e4a1 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -26,14 +26,16 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lorenz - : protected ode_base + : public ode_base { public: - logistic() + lorenz() { m_num_eq = 3; m_data = new data_t[3]; + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,1); CHAOS_SYS_INIT(x1,0.8); CHAOS_SYS_INIT(x2,0.8); CHAOS_SYS_INIT(x3,0.8); @@ -44,7 +46,7 @@ public: set_method(0); } - ~logistic() + ~lorenz() { delete m_data; } -- 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/lorenz.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index 700e4a1..fdae428 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -32,7 +32,7 @@ public: lorenz() { m_num_eq = 3; - m_data = new data_t[3]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(method,0); CHAOS_SYS_INIT(dt,1); @@ -43,11 +43,14 @@ public: CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(r,40); + ode_base_alloc(); + set_method(0); } ~lorenz() { + ode_base_free(); delete m_data; } -- cgit v1.2.1 From eced45909ba691a454fec179360ec1c2663f773a Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 25 Dec 2004 12:50:41 +0000 Subject: getting stable svn path=/trunk/externals/tb/; revision=2429 --- chaos/src/lorenz.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index fdae428..a31c151 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -35,10 +35,10 @@ public: m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,1); + CHAOS_SYS_INIT(dt,0.01); CHAOS_SYS_INIT(x1,0.8); - CHAOS_SYS_INIT(x2,0.8); - CHAOS_SYS_INIT(x3,0.8); + CHAOS_SYS_INIT(x2,0.7); + CHAOS_SYS_INIT(x3,0.6); CHAOS_SYS_INIT(sigma,16); CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(r,40); @@ -60,7 +60,7 @@ public: deriv[0] = CHAOS_PARAMETER(sigma) * (x2 - x1); deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; - deriv[3] = x1 * x2 - CHAOS_PARAMETER(b) * x3; + deriv[2] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } CHAOS_SYSVAR_FUNCS(x1, 0); -- cgit v1.2.1 From 6963657b3f3ee4321394953a2cc67cd7386cce2d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 27 Dec 2004 22:55:41 +0000 Subject: additions and better code reuse svn path=/trunk/externals/tb/; revision=2433 --- chaos/src/lorenz.hpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index a31c151..c876b4a 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -44,8 +44,6 @@ public: CHAOS_SYS_INIT(r,40); ode_base_alloc(); - - set_method(0); } ~lorenz() -- cgit v1.2.1 From 2434290915cda6ed855e4dc2249312153b995817 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 9 Jun 2005 12:52:17 +0000 Subject: changed initialisation svn path=/trunk/externals/tb/; revision=3145 --- chaos/src/lorenz.hpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index c876b4a..ee4e516 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -31,25 +31,28 @@ class lorenz public: lorenz() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); - CHAOS_SYS_INIT(x1,0.8); - CHAOS_SYS_INIT(x2,0.7); - CHAOS_SYS_INIT(x3,0.6); - CHAOS_SYS_INIT(sigma,16); - CHAOS_SYS_INIT(b,4); - CHAOS_SYS_INIT(r,40); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + CHAOS_SYS_INIT(x1,0.8,0); + CHAOS_SYS_INIT(x2,0.7,1); + CHAOS_SYS_INIT(x3,0.6,2); + + CHAOS_PAR_INIT(sigma,16); + CHAOS_PAR_INIT(b,4); + CHAOS_PAR_INIT(r,40); + + CHAOS_POSTCONSTRUCTOR; + ode_base_alloc(); } ~lorenz() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) -- 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/lorenz.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index ee4e516..e94f027 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -63,6 +63,16 @@ public: deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; deriv[2] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } + + + /* function has a fix point for x1 == x2 == x3 == 0 */ + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); -- 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/lorenz.hpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index e94f027..b27f954 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -29,10 +29,9 @@ class lorenz : public ode_base { public: - lorenz() + lorenz(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -43,16 +42,10 @@ public: CHAOS_PAR_INIT(sigma,16); CHAOS_PAR_INIT(b,4); CHAOS_PAR_INIT(r,40); - - CHAOS_POSTCONSTRUCTOR; - - ode_base_alloc(); } ~lorenz() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) -- 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/lorenz.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'chaos/src/lorenz.hpp') diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index b27f954..cf0fa14 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lorenz - : public ode_base + : public ode_base<3> { public: - lorenz(): - ode_base(3) + lorenz() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); -- cgit v1.2.1