aboutsummaryrefslogtreecommitdiff
path: root/chaos/src
diff options
context:
space:
mode:
authorTim Blechmann <timblech@users.sourceforge.net>2005-01-01 11:06:58 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:11:58 +0200
commit2a0d532e5965402f19f74f70dfdcc7efd1055b15 (patch)
tree65cf38a9d098e9867287b7a274220da401cb6b57 /chaos/src
parent2f98df88850ab893c7acf8ea2b9000c03c2e17da (diff)
speedup using function pointers
svn path=/trunk/externals/tb/; revision=2439
Diffstat (limited to 'chaos/src')
-rw-r--r--chaos/src/Makefile.am1
-rw-r--r--chaos/src/bernoulli_map.hpp2
-rw-r--r--chaos/src/bungalow_tent_map.hpp2
-rw-r--r--chaos/src/chaos.hpp1
-rw-r--r--chaos/src/chaos_base.hpp17
-rw-r--r--chaos/src/chaos_dsp.hpp70
-rw-r--r--chaos/src/chaos_msg.hpp2
-rw-r--r--chaos/src/chua.hpp109
-rw-r--r--chaos/src/chua_dsp.cpp24
-rw-r--r--chaos/src/chua_msg.cpp24
-rw-r--r--chaos/src/circle_map.hpp2
-rw-r--r--chaos/src/coupled_logistic.hpp2
-rw-r--r--chaos/src/gauss_map.hpp2
-rw-r--r--chaos/src/henon_map.hpp2
-rw-r--r--chaos/src/henon_map_dsp.cpp2
-rw-r--r--chaos/src/henon_map_msg.cpp2
-rw-r--r--chaos/src/ikeda_laser_map.hpp2
-rw-r--r--chaos/src/ikeda_laser_map_dsp.cpp2
-rw-r--r--chaos/src/ikeda_laser_map_msg.cpp2
-rw-r--r--chaos/src/logistic_map.hpp14
-rw-r--r--chaos/src/lozi_map.hpp2
-rw-r--r--chaos/src/lozi_map_dsp.cpp2
-rw-r--r--chaos/src/lozi_map_msg.cpp2
-rw-r--r--chaos/src/main.cpp1
-rw-r--r--chaos/src/map_base.hpp5
-rw-r--r--chaos/src/ode_base.cpp16
-rw-r--r--chaos/src/ode_base.hpp20
-rw-r--r--chaos/src/roessler.hpp1
-rw-r--r--chaos/src/sine_map.hpp2
-rw-r--r--chaos/src/standard_map.hpp2
-rw-r--r--chaos/src/tent_map.hpp23
-rw-r--r--chaos/src/tent_map_dsp.cpp2
-rw-r--r--chaos/src/tent_map_msg.cpp2
33 files changed, 273 insertions, 91 deletions
diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am
index cbaa287..213e313 100644
--- a/chaos/src/Makefile.am
+++ b/chaos/src/Makefile.am
@@ -5,6 +5,7 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \
bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \
circle_map_dsp.cpp circle_map_msg.cpp \
coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \
+ chua_dsp.cpp chua_msg.cpp \
driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \
driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \
duffing_map_dsp.cpp duffing_map_msg.cpp \
diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp
index 25d19f8..821f24f 100644
--- a/chaos/src/bernoulli_map.hpp
+++ b/chaos/src/bernoulli_map.hpp
@@ -31,7 +31,7 @@ public:
bernoulli()
{
m_num_eq = 1;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(x,0.5);
}
diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp
index 185753a..0dfe709 100644
--- a/chaos/src/bungalow_tent_map.hpp
+++ b/chaos/src/bungalow_tent_map.hpp
@@ -39,7 +39,7 @@ public:
bungalow_tent()
{
m_num_eq = 1;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(x, 0.6);
CHAOS_SYS_INIT(r, 0.5);
}
diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp
index 231ecdc..a1a3467 100644
--- a/chaos/src/chaos.hpp
+++ b/chaos/src/chaos.hpp
@@ -24,6 +24,7 @@
#include "flext.h"
#include "chaos_defs.hpp"
+#include <cmath>
/* internal we can work with a higher precision than pd */
#ifdef DOUBLE_PRECISION
diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp
index ce6fc11..a2072d0 100644
--- a/chaos/src/chaos_base.hpp
+++ b/chaos/src/chaos_base.hpp
@@ -36,16 +36,31 @@ public:
return m_num_eq;
}
- virtual void m_step()
+ void m_perform()
{
+ m_step();
+ m_verify();
}
+ virtual void m_verify()
+ {
+ for (int i = 0; i != get_num_eq(); ++i)
+ {
+#ifndef DOUBLE_PRECISION
+ if (PD_BIGORSMALL(m_data[i]))
+ m_data[i] = 0;
+#endif
+ }
+ };
+
data_t * m_data; // state of the system
protected:
+ virtual void m_step();
int m_num_eq; // number of equations of the system
};
+
#define CHAOS_CALLBACKS \
public: \
void get_dimension(int &i) \
diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp
index c2f78b3..9704432 100644
--- a/chaos/src/chaos_dsp.hpp
+++ b/chaos/src/chaos_dsp.hpp
@@ -37,13 +37,17 @@ public:
/* cubic interpolatio */
void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs);
- virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs);
+ virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs)
+ {
+ (this->*m_routine)(n,insigs,outsigs);
+ }
virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs)
{
m_sr = Samplerate();
}
-
+
+ void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs);
/* local data for system, output and interpolation */
system * m_system; /* the system */
@@ -57,12 +61,13 @@ public:
/* local data for signal functions */
float m_freq; /* frequency of oscillations */
+ float m_invfreq; /* inverse frequency */
int m_phase; /* phase counter */
float m_sr; /* sample rate */
int m_imethod; /* interpolation method */
- int get_imethod(int &i)
+ void get_imethod(int &i)
{
i = m_imethod;
}
@@ -70,7 +75,21 @@ public:
void set_imethod(int i)
{
if( (i >= 0) && (i <= 2) )
+ {
m_imethod = i;
+ switch (i)
+ {
+ case 0:
+ m_routine = &thisType::m_signal_n;
+ break;
+ case 1:
+ m_routine = &thisType::m_signal_l;
+ break;
+ case 2:
+ m_routine = &thisType::m_signal_c;
+ break;
+ }
+ }
else
{
post("interpolation method out of range");
@@ -88,7 +107,7 @@ public:
}
- int get_freq(float &f)
+ void get_freq(float &f)
{
f = m_freq;
}
@@ -96,7 +115,10 @@ public:
void set_freq(float f)
{
if( (f >= 0) && (f <= m_sr*0.5) )
+ {
m_freq = f;
+ m_invfreq = 1.f / f;
+ }
else
post("frequency out of range");
}
@@ -112,7 +134,7 @@ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp<SYSTEM>) \
\
SYSTEM##_dsp(int argc, t_atom* argv ) \
{ \
- m_sr = 44100; /* assume default sampling rate (for max frequency) */ \
+ m_sr = 44100; /* assume default sampling rate */ \
m_system = new SYSTEM; \
\
int size = m_system->get_num_eq(); \
@@ -176,30 +198,6 @@ FLEXT_ATTRVAR_I(m_imethod);
template <class system>
-void chaos_dsp<system>::m_signal(int n, t_sample *const *insigs,
- t_sample *const *outsigs)
-{
- if (m_freq >= m_sr * 0.5)
- {
- m_signal_(n, insigs, outsigs);
- return;
- }
-
- switch (m_imethod)
- {
- case 0:
- m_signal_n(n, insigs, outsigs);
- return;
- case 1:
- m_signal_l(n, insigs, outsigs);
- return;
- case 2:
- m_signal_c(n, insigs, outsigs);
- return;
- }
-}
-
-template <class system>
void chaos_dsp<system>::m_signal_(int n, t_sample *const *insigs,
t_sample *const *outsigs)
{
@@ -207,7 +205,7 @@ void chaos_dsp<system>::m_signal_(int n, t_sample *const *insigs,
for (int i = 0; i!=n; ++i)
{
- m_system->m_step();
+ m_system->m_perform();
for (int j = 0; j != outlets; ++j)
{
outsigs[j][i] = m_system->get_data(j);
@@ -230,8 +228,8 @@ void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs,
{
if (phase == 0)
{
- m_system->m_step();
- phase = int (m_sr / m_freq);
+ m_system->m_perform();
+ phase = int (m_sr * m_invfreq);
}
int next = (phase < n) ? phase : n;
@@ -266,8 +264,8 @@ void chaos_dsp<system>::m_signal_l(int n, t_sample *const *insigs,
{
if (phase == 0)
{
- m_system->m_step();
- phase = int (m_sr / m_freq);
+ m_system->m_perform();
+ phase = int (m_sr * m_invfreq);
for (int j = 0; j != outlets; ++j)
m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase;
@@ -305,8 +303,8 @@ void chaos_dsp<system>::m_signal_c(int n, t_sample *const *insigs,
{
if (phase == 0)
{
- m_system->m_step();
- phase = int (m_sr / m_freq);
+ m_system->m_perform();
+ phase = int (m_sr * m_invfreq);
phase = (phase > 2) ? phase : 2;
for (int j = 0; j != outlets; ++j)
diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp
index 78bca06..3f80101 100644
--- a/chaos/src/chaos_msg.hpp
+++ b/chaos/src/chaos_msg.hpp
@@ -32,7 +32,7 @@ public:
void m_bang()
{
- m_system->m_step();
+ m_system->m_perform();
int outlets = m_system->get_num_eq();
while (outlets--)
diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp
new file mode 100644
index 0000000..a5db1cb
--- /dev/null
+++ b/chaos/src/chua.hpp
@@ -0,0 +1,109 @@
+//
+//
+// 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"
+
+// chua system: dx1/dt = alpha * (x2 - x1 - h(x1))
+// dx2/dt = x1 - x2 + x3
+// dx3/dt = - beta * x2
+//
+// with h(x) = b*x + a - b (for x > 1)
+// a*x (for -1 <= x <= 1
+// b*x - a + b (for x < -1)
+//
+// taken from Viktor Avrutin: lecture note
+
+class chua:
+ public ode_base
+{
+public:
+ chua()
+ {
+ m_num_eq = 3;
+ m_data = new data_t[m_num_eq];
+ CHAOS_SYS_INIT(x1,1);
+ CHAOS_SYS_INIT(x2,1);
+ CHAOS_SYS_INIT(x3,1);
+ CHAOS_SYS_INIT(a,1.4);
+ CHAOS_SYS_INIT(b,0.3);
+ CHAOS_SYS_INIT(alpha,0.3);
+ CHAOS_SYS_INIT(beta,0.3);
+
+ ode_base_alloc();
+ }
+
+ ~chua()
+ {
+ ode_base_free();
+ delete m_data;
+ }
+
+ virtual void m_system(data_t* deriv, data_t* data)
+ {
+ data_t x1 = data[0];
+ data_t x2 = data[1];
+ data_t x3 = data[2];
+
+ data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b);
+
+ data_t h;
+
+ if (x1 > 1)
+ h = b*x1 + a - b;
+ else if (x1 < -1)
+ h = b*x1 - a + b;
+ else
+ h = a*x1;
+
+ deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h);
+ deriv[1] = x1 - x2 + x3;
+ deriv[2] = - CHAOS_PARAMETER(beta) * x2;
+ }
+
+ CHAOS_SYSVAR_FUNCS(x1, 0);
+ CHAOS_SYSVAR_FUNCS(x2, 1);
+ CHAOS_SYSVAR_FUNCS(x3, 2);
+
+ CHAOS_SYSPAR_FUNCS(a);
+ CHAOS_SYSPAR_FUNCS(b);
+ CHAOS_SYSPAR_FUNCS(alpha);
+ CHAOS_SYSPAR_FUNCS(beta);
+};
+
+
+#define CHUA_CALLBACKS \
+ODE_CALLBACKS; \
+CHAOS_SYS_CALLBACKS(alpha); \
+CHAOS_SYS_CALLBACKS(beta); \
+CHAOS_SYS_CALLBACKS(a); \
+CHAOS_SYS_CALLBACKS(b); \
+CHAOS_SYS_CALLBACKS(x1); \
+CHAOS_SYS_CALLBACKS(x2); \
+CHAOS_SYS_CALLBACKS(x3);
+
+#define CHUA_ATTRIBUTES \
+ODE_ATTRIBUTES; \
+CHAOS_SYS_ATTRIBUTE(a); \
+CHAOS_SYS_ATTRIBUTE(b); \
+CHAOS_SYS_ATTRIBUTE(alpha); \
+CHAOS_SYS_ATTRIBUTE(beta); \
+CHAOS_SYS_ATTRIBUTE(x1); \
+CHAOS_SYS_ATTRIBUTE(x2); \
+CHAOS_SYS_ATTRIBUTE(x3);
diff --git a/chaos/src/chua_dsp.cpp b/chaos/src/chua_dsp.cpp
new file mode 100644
index 0000000..6ae151c
--- /dev/null
+++ b/chaos/src/chua_dsp.cpp
@@ -0,0 +1,24 @@
+//
+//
+// 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 "chua.hpp"
+#include "chaos_dsp.hpp"
+
+CHAOS_DSP_CLASS(chua,CHUA);
diff --git a/chaos/src/chua_msg.cpp b/chaos/src/chua_msg.cpp
new file mode 100644
index 0000000..b00aa7f
--- /dev/null
+++ b/chaos/src/chua_msg.cpp
@@ -0,0 +1,24 @@
+//
+//
+// 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 "chua.hpp"
+#include "chaos_msg.hpp"
+
+CHAOS_MSG_CLASS(chua,CHUA);
diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp
index 0e12ad0..91f11d6 100644
--- a/chaos/src/circle_map.hpp
+++ b/chaos/src/circle_map.hpp
@@ -33,7 +33,7 @@ public:
circle_map()
{
m_num_eq = 1;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(omega, 0.1);
CHAOS_SYS_INIT(r, 3);
CHAOS_SYS_INIT(x, 0.4);
diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp
index eb5b326..85b6928 100644
--- a/chaos/src/coupled_logistic.hpp
+++ b/chaos/src/coupled_logistic.hpp
@@ -32,7 +32,7 @@ public:
coupled_logistic()
{
m_num_eq = 2;
- m_data = new data_t[2];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(e, 0.06);
CHAOS_SYS_INIT(r, 3.7);
CHAOS_SYS_INIT(x, 0.1);
diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp
index 523b1ca..4d62654 100644
--- a/chaos/src/gauss_map.hpp
+++ b/chaos/src/gauss_map.hpp
@@ -34,7 +34,7 @@ public:
gauss_map()
{
m_num_eq = 1;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(x,0.5);
}
diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp
index 9e379ae..b43034a 100644
--- a/chaos/src/henon_map.hpp
+++ b/chaos/src/henon_map.hpp
@@ -32,7 +32,7 @@ public:
henon()
{
m_num_eq = 2;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(x,0);
CHAOS_SYS_INIT(y,0);
diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp
index f7e6103..7d73412 100644
--- a/chaos/src/henon_map_dsp.cpp
+++ b/chaos/src/henon_map_dsp.cpp
@@ -21,4 +21,4 @@
#include "henon_map.hpp"
#include "chaos_dsp.hpp"
-CHAOS_DSP_CLASS_NAME(henon, HENON, "henon~");
+CHAOS_DSP_CLASS_NAME(henon, HENON, henon~);
diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp
index 22cddde..e70624f 100644
--- a/chaos/src/henon_map_msg.cpp
+++ b/chaos/src/henon_map_msg.cpp
@@ -21,4 +21,4 @@
#include "henon_map.hpp"
#include "chaos_msg.hpp"
-CHAOS_MSG_CLASS_NAME(henon, HENON, "henon");
+CHAOS_MSG_CLASS_NAME(henon, HENON, henon);
diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp
index e267204..c62bc15 100644
--- a/chaos/src/ikeda_laser_map.hpp
+++ b/chaos/src/ikeda_laser_map.hpp
@@ -38,7 +38,7 @@ public:
ikeda_laser_map()
{
m_num_eq = 2;
- m_data = new data_t[2];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(c1,0.4);
CHAOS_SYS_INIT(c2,0.9);
CHAOS_SYS_INIT(c3,9);
diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp
index ea18e21..fe2339b 100644
--- a/chaos/src/ikeda_laser_map_dsp.cpp
+++ b/chaos/src/ikeda_laser_map_dsp.cpp
@@ -22,5 +22,5 @@
#include "chaos_dsp.hpp"
-CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda");
+CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, ikeda~);
diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp
index 1659159..e1c318d 100644
--- a/chaos/src/ikeda_laser_map_msg.cpp
+++ b/chaos/src/ikeda_laser_map_msg.cpp
@@ -21,4 +21,4 @@
#include "ikeda_laser_map.hpp"
#include "chaos_msg.hpp"
-CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda~");
+CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, ikeda);
diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp
index 1808baa..ef2f603 100644
--- a/chaos/src/logistic_map.hpp
+++ b/chaos/src/logistic_map.hpp
@@ -21,7 +21,7 @@
#include "map_base.hpp"
// logistic map: x[n+1] = alpha * x[n] * (1 - x[n])
-// 0 <= x[n] < 1
+// 0 < x[n] < 1
// 0 <= alpha <= 4
class logistic:
@@ -43,9 +43,9 @@ public:
virtual void m_step()
{
- data_t data = m_data[0];
+ data_t x = m_data[0];
data_t alpha = CHAOS_PARAMETER(alpha);
- m_data[0] = alpha * data * (1.f - data);
+ m_data[0] = alpha * x * (1.f - x);
}
CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha);
@@ -60,6 +60,14 @@ public:
{
return (f > 0) && (f < 1);
}
+
+ virtual void m_verify()
+ {
+ data_t x = m_data[0];
+ if (m_pred_x(x))
+ return;
+ m_data[0] = 0.5;
+ }
};
#define LOGISTIC_CALLBACKS \
diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp
index 37cab54..9219390 100644
--- a/chaos/src/lozi_map.hpp
+++ b/chaos/src/lozi_map.hpp
@@ -32,7 +32,7 @@ public:
lozi_map()
{
m_num_eq = 2;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(x,0);
CHAOS_SYS_INIT(y,0);
CHAOS_SYS_INIT(a,1.4);
diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp
index 0448412..06c603d 100644
--- a/chaos/src/lozi_map_dsp.cpp
+++ b/chaos/src/lozi_map_dsp.cpp
@@ -21,4 +21,4 @@
#include "lozi_map.hpp"
#include "chaos_dsp.hpp"
-CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, "lozi");
+CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, lozi~);
diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp
index 099cbec..719cf61 100644
--- a/chaos/src/lozi_map_msg.cpp
+++ b/chaos/src/lozi_map_msg.cpp
@@ -21,4 +21,4 @@
#include "lozi_map.hpp"
#include "chaos_msg.hpp"
-CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, "lozi");
+CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, lozi);
diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp
index eabb8d4..dcb7ea8 100644
--- a/chaos/src/main.cpp
+++ b/chaos/src/main.cpp
@@ -29,6 +29,7 @@ void chaos_library_setup()
CHAOS_ADD(bungalow_tent);
CHAOS_ADD(circle_map);
CHAOS_ADD(coupled_logistic);
+ CHAOS_ADD(chua);
CHAOS_ADD(driven_anharmonic);
CHAOS_ADD(driven_van_der_pol);
CHAOS_ADD(duffing_map);
diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp
index c88f9ba..e71fe61 100644
--- a/chaos/src/map_base.hpp
+++ b/chaos/src/map_base.hpp
@@ -26,7 +26,10 @@
class map_base
: public chaos_base
{
-
+protected:
+ virtual void m_step()
+ {
+ }
};
#define MAP_CALLBACKS \
diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp
index 9665d83..2830c2f 100644
--- a/chaos/src/ode_base.cpp
+++ b/chaos/src/ode_base.cpp
@@ -72,19 +72,3 @@ void ode_base::rk4()
/ 6.;
}
-void ode_base::m_step()
-{
- switch (m_method)
- {
- case 0:
- rk1();
- break;
- case 1:
- rk2();
- break;
- case 2:
- rk4();
- break;
- }
-
-}
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 */
diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp
index 85272ee..4b36666 100644
--- a/chaos/src/roessler.hpp
+++ b/chaos/src/roessler.hpp
@@ -41,6 +41,7 @@ public:
CHAOS_SYS_INIT(a,4);
CHAOS_SYS_INIT(b,4);
CHAOS_SYS_INIT(c,4);
+ CHAOS_SYS_INIT(dt,0.01);
ode_base_alloc();
}
diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp
index 376a245..8746345 100644
--- a/chaos/src/sine_map.hpp
+++ b/chaos/src/sine_map.hpp
@@ -33,7 +33,7 @@ public:
sine_map()
{
m_num_eq = 1;
- m_data = new data_t[1];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(x,0);
}
diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp
index c0f0b8d..cadcf1e 100644
--- a/chaos/src/standard_map.hpp
+++ b/chaos/src/standard_map.hpp
@@ -33,7 +33,7 @@ public:
standard_map()
{
m_num_eq = 2;
- m_data = new data_t[2];
+ m_data = new data_t[m_num_eq];
CHAOS_SYS_INIT(I,0.1);
CHAOS_SYS_INIT(theta,0.2);
diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp
index 9ab59ec..8c00a19 100644
--- a/chaos/src/tent_map.hpp
+++ b/chaos/src/tent_map.hpp
@@ -20,10 +20,10 @@
#include "map_base.hpp"
-// tent map: x[n+1] = 2 * x[n] (for 0 < x <= 0.5)
-// 2 * (1 - x[n]) (else)
-// 0 <= x[n] < 1
-// taken from Willi-Hans Steeb: Chaos and Fractals
+// tent map: x[n+1] = 1 - 2*abs(x[n])
+// -1 < x[n] < 1
+// taken from Julien C. Sprott, Strange Attractors: Creating Patterns in Chaos
+
class tent_map:
public map_base
@@ -32,8 +32,8 @@ public:
tent_map()
{
m_num_eq = 1;
- m_data = new data_t[1];
- CHAOS_SYS_INIT(x, 0.5);
+ m_data = new data_t[m_num_eq];
+ CHAOS_SYS_INIT(x, 0.6);
}
~tent_map()
@@ -44,17 +44,14 @@ public:
virtual void m_step()
{
data_t data = m_data[0];
-
- if (data < 0.5f)
- m_data[0] = 2.f * data;
- else
- m_data[0] = 2.f * (1.f - data);
+
+ m_data[0] = 1 - 2*CHAOS_ABS(data);
}
- CHAOS_SYSPAR_FUNCS_PRED(x, m_pred_x);
+ CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x);
bool m_pred_x(t_float f)
{
- return (f >= 0) && (f < 1);
+ return (f > -1) && (f < 1);
}
};
diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp
index 44c909d..0abf7d5 100644
--- a/chaos/src/tent_map_dsp.cpp
+++ b/chaos/src/tent_map_dsp.cpp
@@ -23,4 +23,4 @@
-CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, "tent~");
+CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, tent~);
diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp
index 3da82ab..b2d5d8d 100644
--- a/chaos/src/tent_map_msg.cpp
+++ b/chaos/src/tent_map_msg.cpp
@@ -21,4 +21,4 @@
#include "tent_map.hpp"
#include "chaos_msg.hpp"
-CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, "tent");
+CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, tent);