diff options
Diffstat (limited to 'chaos/src')
35 files changed, 260 insertions, 426 deletions
diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index f084c67..c720e1b 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -25,21 +25,15 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bernoulli: - public map_base + public map_base<1> { public: - bernoulli(): - map_base(1) + bernoulli() { CHAOS_SYS_INIT(x,0.5,0); } - ~bernoulli() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 4d4836b..fd098f3 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -33,21 +33,15 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bungalow_tent: - public map_base + public map_base<1> { public: - bungalow_tent(): - map_base(1) + bungalow_tent() { CHAOS_SYS_INIT(x, 0.6,0); CHAOS_PAR_INIT(r, 0.5); } - ~bungalow_tent() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 5c87bed..4b984d9 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,7 +1,7 @@ // // // chaos~ -// Copyright (C) 2004 Tim Blechmann +// Copyright (C) 2004, 2006 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 @@ -23,26 +23,23 @@ #include "chaos.hpp" #include <map> -#define MAXDIMENSION 5 // this should be enough for the first - +template <int dimensions> class chaos_base { public: - chaos_base(int n): - m_num_eq(n) + chaos_base() { - m_data = new data_t[n]; } - inline t_sample get_data(unsigned int i) { + assert(i<dimensions); return (t_sample)m_data[i]; /* this is not save, but fast */ } inline int get_num_eq() const { - return m_num_eq; + return dimensions; } inline void m_perform() @@ -53,16 +50,15 @@ public: } std::map<const t_symbol*,int> attr_ind; - // TableAnyMap attr_ind; /* thomas fragen :-) */ // check the integrity of the system - virtual void m_verify() + inline void m_verify() { } inline void m_bash_denormals() { - for (int i = 0; i != get_num_eq(); ++i) + for (int i = 0; i != dimensions; ++i) { #ifndef DOUBLE_PRECISION if (PD_BIGORSMALL(m_data[i])) @@ -71,28 +67,13 @@ public: } }; - data_t * m_data; // state of the system + data_t m_data[dimensions]; // state of the system protected: - virtual void m_step() = 0; // iteration - const int m_num_eq; // number of equations of the system + virtual void m_step() = 0; // iteration flext::AtomList Parameter; // parameter flext::AtomList System; // system }; -#define CHAOS_CALLBACKS \ -public: \ -void get_dimension(int &i) \ -{ \ - i = m_system->get_num_eq(); \ -} \ -FLEXT_CALLGET_I(get_dimension); - - -#define CHAOS_ATTRIBUTES \ -FLEXT_ADDATTR_GET("dimension",get_dimension); - - - #define __chaos_base_hpp #endif /* __chaos_base_hpp */ diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index bf8607c..c4e68a5 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -100,11 +100,11 @@ data_t m_##NAME; public: \ void get_##NAME(t_float &f) \ { \ - f = m_system->get_##NAME(); \ + f = m_system.get_##NAME(); \ } \ void set_##NAME(t_float &f) \ { \ - m_system->set_##NAME(f); \ + m_system.set_##NAME(f); \ } \ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); @@ -113,11 +113,11 @@ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); public: \ void get_##NAME(int &i) \ { \ - i = m_system->get_##NAME(); \ + i = m_system.get_##NAME(); \ } \ void set_##NAME(int &i) \ { \ - m_system->set_##NAME(i); \ + m_system.set_##NAME(i); \ } \ FLEXT_CALLVAR_I(get_##NAME, set_##NAME); diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 786bee3..9f6dd75 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -20,13 +20,68 @@ #include "chaos_base.hpp" -template <class system> class chaos_dsp +template <class system> +class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp); +protected: + chaos_dsp(int argc, t_atom* argv) + { + m_sr = 44100; /* assume default sampling rate */ + int size = m_system.get_num_eq(); + + m_values = new t_float[size]; + m_slopes = new t_float[size]; + m_nextvalues = new t_float[size]; + m_nextmidpts = new t_float[size]; + m_curves = new t_float[size]; + + /* create inlets and zero arrays*/ + for (int i = 0; i != size; ++i) + { + AddOutSignal(); + m_values[i] = 0; + m_slopes[i] = 0; + m_nextvalues[i] = 0; + m_nextmidpts[i] = 0; + m_curves[i] = 0; + } + + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); + + if (argc > 0) + { + CHAOS_INIT(freq, GetAInt(argv[0])); + } + else + { + CHAOS_INIT(freq, 440); + } + + if (argc > 1) + { + CHAOS_INIT(imethod, GetAInt(argv[1])); + } + else + { + CHAOS_INIT(imethod, 0); + } + m_phase = 0; + } + + ~chaos_dsp() + { + delete[] m_values; + delete[] m_slopes; + delete[] m_nextvalues; + delete[] m_nextmidpts; + delete[] m_curves; + } + public: - /* signal functions: */ /* for frequency = sr */ void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); @@ -58,7 +113,7 @@ public: 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 */ + system m_system; /* the system */ t_sample * m_values; /* actual value */ t_sample * m_slopes; /* actual slope for cubic interpolation */ @@ -106,15 +161,15 @@ public: } if (imethod == 0) - for (int j = 0; j != m_system->get_num_eq(); ++j) + for (int j = 0; j != m_system.get_num_eq(); ++j) { - m_values[j] = m_system->get_data(j); + m_values[j] = m_system.get_data(j); m_slopes[j] = 0; } if(i == 2 && imethod != 2) { - for (int j = 0; j != m_system->get_num_eq(); ++j) + for (int j = 0; j != m_system.get_num_eq(); ++j) { m_phase = 0; /* reschedule to avoid click, find a better way later*/ m_nextvalues[j] = m_values[j]; @@ -183,67 +238,13 @@ public: #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp<SYSTEM>) \ \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_sr = 44100; /* assume default sampling rate */ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - m_values = new t_float[size]; \ - m_slopes = new t_float[size]; \ - m_nextvalues = new t_float[size]; \ - m_nextmidpts = new t_float[size]; \ - m_curves = new t_float[size]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ - FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ - \ - if (argc > 0) \ - { \ - CHAOS_INIT(freq, GetAInt(argv[0])); \ - } \ - else \ - { \ - CHAOS_INIT(freq, 440); \ - } \ - \ - if (argc > 1) \ - { \ - CHAOS_INIT(imethod, GetAInt(argv[1])); \ - } \ - else \ - { \ - CHAOS_INIT(imethod, 0); \ - } \ - \ - m_phase = 0; \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ +SYSTEM##_dsp(int argc, t_atom* argv): \ + chaos_dsp<SYSTEM>(argc, argv) \ { \ - delete m_system; \ - delete[] m_values; \ - delete[] m_slopes; \ - delete[] m_nextvalues; \ - delete[] m_nextmidpts; \ - delete[] m_curves; \ + ATTRIBUTES; \ } \ \ -FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_F(m_freq); \ FLEXT_ATTRVAR_I(m_imethod); @@ -252,14 +253,14 @@ template <class system> void chaos_dsp<system>::m_signal_(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); for (int i = 0; i!=n; ++i) { - m_system->m_perform(); + m_system.m_perform(); for (int j = 0; j != outlets; ++j) { - outsigs[j][i] = m_system->get_data(j); + outsigs[j][i] = m_system.get_data(j); } } } @@ -269,7 +270,7 @@ template <class system> void chaos_dsp<system>::m_signal_n_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -278,7 +279,7 @@ void chaos_dsp<system>::m_signal_n_hf(int n, t_sample *const *insigs, { while (phase <= 0) { - m_system->m_perform(); + m_system.m_perform(); phase += m_sr * m_invfreq; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -287,7 +288,7 @@ void chaos_dsp<system>::m_signal_n_hf(int n, t_sample *const *insigs, for (int i = 0; i != outlets; ++i) { - SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + SetSamples(outsigs[i]+offset, next, m_system.get_data(i)); } offset += next; } @@ -299,7 +300,7 @@ template <class system> void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -308,7 +309,7 @@ void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); } @@ -318,7 +319,7 @@ void chaos_dsp<system>::m_signal_n(int n, t_sample *const *insigs, for (int i = 0; i != outlets; ++i) { - SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + SetSamples(outsigs[i]+offset, next, m_system.get_data(i)); } offset += next; } @@ -330,7 +331,7 @@ template <class system> void chaos_dsp<system>::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -340,11 +341,11 @@ void chaos_dsp<system>::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + 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; + m_slopes[j] = (m_system.get_data(j) - m_values[j]) / phase; } int next = (phase < n) ? phase : n; @@ -370,7 +371,7 @@ template <class system> void chaos_dsp<system>::m_signal_l_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -380,11 +381,11 @@ void chaos_dsp<system>::m_signal_l_hf(int n, t_sample *const *insigs, { if (phase <= 0) { - m_system->m_perform(); + m_system.m_perform(); phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + m_slopes[j] = (m_system.get_data(j) - m_values[j]) / phase; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -409,7 +410,7 @@ template <class system> void chaos_dsp<system>::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -419,14 +420,14 @@ void chaos_dsp<system>::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; for (int j = 0; j != outlets; ++j) { t_sample value = m_nextvalues[j]; - m_nextvalues[j]= m_system->get_data(j); + m_nextvalues[j]= m_system.get_data(j); m_values[j] = m_nextmidpts[j]; m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; @@ -461,7 +462,7 @@ template <class system> void chaos_dsp<system>::m_signal_c_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -471,14 +472,14 @@ void chaos_dsp<system>::m_signal_c_hf(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; for (int j = 0; j != outlets; ++j) { t_sample value = m_nextvalues[j]; - m_nextvalues[j]= m_system->get_data(j); + m_nextvalues[j]= m_system.get_data(j); m_values[j] = m_nextmidpts[j]; m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 357ff6a..9025273 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -20,29 +20,34 @@ #include "chaos_base.hpp" -template <class system> class chaos_msg - : public flext_base +template <class system> +class chaos_msg: + public flext_base { FLEXT_HEADER(chaos_msg, flext_base); - ~chaos_msg() - { - delete m_system; - } +protected: + chaos_msg(int argc, t_atom* argv) + { + int size = m_system.get_num_eq(); + + for (int i = 0; i != size; ++i) + AddOutFloat(); + FLEXT_ADDBANG(0, m_bang); + } public: - /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ void m_bang() { - m_system->m_perform(); - int outlets = m_system->get_num_eq(); + m_system.m_perform(); + int outlets = m_system.get_num_eq(); while (outlets--) { - ToOutFloat(outlets, m_system->get_data(outlets)); + ToOutFloat(outlets, m_system.get_data(outlets)); } } @@ -54,15 +59,8 @@ public: #define CHAOS_MSG_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_msg, chaos_msg<SYSTEM>) \ \ -SYSTEM##_msg(int argc, t_atom* argv ) \ +SYSTEM##_msg(int argc, t_atom* argv ): \ +chaos_msg<SYSTEM>(argc, argv) \ { \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - for (int i = 0; i != size; ++i) \ - AddOutFloat(); \ - \ ATTRIBUTES; \ - FLEXT_ADDBANG(0, m_bang); \ } diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp index a7fc44d..1b812a0 100644 --- a/chaos/src/chaos_search.hpp +++ b/chaos/src/chaos_search.hpp @@ -20,6 +20,8 @@ #include "chaos_base.hpp" +#define MAXDIMENSION 5 + template <class system> class chaos_search : public flext_base { @@ -28,7 +30,7 @@ template <class system> class chaos_search public: /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ data_t min[MAXDIMENSION]; /* minimal coordinates */ @@ -75,11 +77,11 @@ public: - send lyapunov exponent to 4 */ - for (std::map<const t_symbol*,int>::iterator it = m_system->attr_ind.begin(); - it != m_system->attr_ind.end(); ++it) + for (std::map<const t_symbol*,int>::iterator it = m_system.attr_ind.begin(); + it != m_system.attr_ind.end(); ++it) { post("key %s", it->first->s_name); - post("value %f", m_system->get_data(it->second)); + post("value %f", m_system.get_data(it->second)); } } @@ -99,9 +101,7 @@ FLEXT_HEADER(SYSTEM##_search, chaos_search<SYSTEM>) \ \ SYSTEM##_search(int argc, t_atom* argv ) \ { \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ + int size = m_system.get_num_eq(); \ \ \ m_asymptotic_steps = 10000; \ @@ -119,10 +119,6 @@ SYSTEM##_search(int argc, t_atom* argv ) \ FLEXT_ADDMETHOD_(0,"search", m_search); \ } \ \ -~SYSTEM##_search() \ -{ \ - delete m_system; \ -} \ \ FLEXT_ATTRVAR_I(m_transient_steps); \ FLEXT_ATTRVAR_I(m_asymptotic_steps); @@ -132,7 +128,7 @@ FLEXT_ATTRVAR_I(m_asymptotic_steps); template <class system> void chaos_search<system>::m_search() { - int dimensions = m_system->get_num_eq(); + int dimensions = m_system.get_num_eq(); ly = 0; data_t diff_old = 0.1; @@ -141,12 +137,12 @@ void chaos_search<system>::m_search() /* transient dynamics */ for (int i = 0; i != m_transient_steps; ++i) { - m_system->m_perform(); + m_system.m_perform(); } for (int i = 0; i != dimensions; ++i) { - last[i] = min[i] = max[i] = m_system->m_data[i]; + last[i] = min[i] = max[i] = m_system.m_data[i]; } /* now we start the analysis */ @@ -154,13 +150,13 @@ void chaos_search<system>::m_search() for (int i = 0; i != m_asymptotic_steps; ++i) { - m_system->m_perform(); + m_system.m_perform(); data_t diff = 0; for (int j = 0; j != dimensions; ++j) { /* update min/max */ - data_t datum = m_system->m_data[j]; + data_t datum = m_system.m_data[j]; if (datum > max[j]) max[j] = datum; else if (datum < min[j]) diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index 997116c..f8c6e31 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -31,11 +31,10 @@ // taken from Viktor Avrutin: lecture notes class chua: - public ode_base + public ode_base<3> { public: - chua(): - ode_base(3) + chua() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.05); @@ -50,10 +49,6 @@ public: CHAOS_PAR_INIT(beta,30); } - ~chua() - { - } - virtual void m_system(data_t* deriv, data_t* data) { data_t x1 = data[0]; diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 0a52993..294b7d6 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -27,11 +27,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class circle_map: - public map_base + public map_base<1> { public: circle_map() - : map_base(1) { CHAOS_SYS_INIT(x, 0.4,0); @@ -39,10 +38,6 @@ public: CHAOS_PAR_INIT(r, 3); } - ~circle_map() - { - - } virtual void m_step() { diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 2e4b160..048aae1 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class coupled_logistic: - public map_base + public map_base<2> { public: - coupled_logistic(): - map_base(2) + coupled_logistic() { CHAOS_PAR_INIT(e, 0.06); CHAOS_PAR_INIT(r, 3.7); @@ -39,11 +38,7 @@ public: CHAOS_SYS_INIT(y, 0.2,1); } - ~coupled_logistic() - { - } - - virtual void m_step() + virtual inline void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; @@ -56,7 +51,7 @@ public: CHAOS_SYSPAR_FUNCS(e); CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); - bool m_pred_r(t_float f) + static bool m_pred_r(t_float f) { return (f > 0) && (f < 4); } @@ -64,12 +59,12 @@ public: CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_xy); CHAOS_SYSVAR_FUNCS_PRED(y, 0, m_pred_xy); - bool m_pred_xy(t_float f) + static bool m_pred_xy(t_float f) { return (f > 0) && (f < 1); } - virtual void m_verify() + inline void m_verify() { data_t x = m_data[0]; data_t y = m_data[1]; @@ -83,8 +78,6 @@ public: m_data[1] += -rand_range(0,0.2); } } - - }; #define COUPLED_LOGISTIC_CALLBACKS \ diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index 47360e7..3db7e27 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -26,11 +26,10 @@ // taken from E. Atlee Jackson: Perspective of nonlinear dynamics (Vol. 2) class delayed_logistic: - public map_base + public map_base<1> { public: - delayed_logistic(): - map_base(1) + delayed_logistic() { CHAOS_SYS_INIT(x, 0.5, 0); CHAOS_PAR_INIT(alpha, 3.8); @@ -38,10 +37,7 @@ public: m_delayed = get_x(); /* the initial state of the delay */ } - ~delayed_logistic() - { - - } + virtual void m_step() { diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 2d72071..7d6bfd6 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -29,11 +29,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_anharmonic - : public ode_base + : public ode_base<2> { public: - driven_anharmonic(): - ode_base(2) + driven_anharmonic() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -50,10 +49,7 @@ public: m_t = 0; } - - ~driven_anharmonic() - { - } + virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index e538185..3c034d2 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -30,11 +30,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_van_der_pol - : public ode_base + : public ode_base<3> { public: - driven_van_der_pol(): - ode_base(3) + driven_van_der_pol() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -48,9 +47,7 @@ public: CHAOS_PAR_INIT(k,5); } - ~driven_van_der_pol() - { - } + virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp index 6cdafd6..ee7f7fb 100644 --- a/chaos/src/duffing.hpp +++ b/chaos/src/duffing.hpp @@ -26,11 +26,10 @@ class duffing: - public ode_base + public ode_base<2> { public: - duffing(): - ode_base(2) + duffing() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -45,9 +44,6 @@ public: t = 0; } - ~duffing() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index f0e3001..46fecbf 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -26,11 +26,10 @@ // taken from Viktor Avrutin: AnT-Demos-4.669 class duffing_map: - public map_base + public map_base<2> { public: - duffing_map(): - map_base(2) + duffing_map() { CHAOS_SYS_INIT(x1, 0.5, 0); CHAOS_SYS_INIT(x2, 0.5, 1); @@ -38,10 +37,7 @@ public: CHAOS_PAR_INIT(b, 0.5); } - ~duffing_map() - { - - } + virtual void m_step() { diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 641b93a..d013bae 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -28,19 +28,14 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class gauss_map: - public map_base + public map_base<1> { public: - gauss_map(): - map_base(1) + gauss_map() { CHAOS_SYS_INIT(x,0.5, 0); } - ~gauss_map() - { - - } virtual void m_step() { diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index 9b2b8ca..c6aaf1e 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -26,11 +26,10 @@ // taken from Robert C. Hilborn: Chaos and Nonlinear Dynamics class gaussian_map: - public map_base + public map_base<1> { public: - gaussian_map(): - map_base(1) + gaussian_map() { CHAOS_SYS_INIT(x, 0.5, 0); @@ -38,10 +37,7 @@ public: CHAOS_PAR_INIT(c,0.5); } - ~gaussian_map() - { - - } + virtual void m_step() { diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index bb1c6c7..014fa68 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class henon: - public map_base + public map_base<2> { public: - henon(): - map_base(2) + henon() { CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); @@ -39,10 +38,6 @@ public: CHAOS_PAR_INIT(b,0.3); } - ~henon() - { - - } virtual void m_step() { diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp index 6df6088..cec6ae3 100644 --- a/chaos/src/hydrogen.hpp +++ b/chaos/src/hydrogen.hpp @@ -24,13 +24,12 @@ // hydrogen atom in a magnetic field class hydrogen - : public ode_base + : public ode_base<4> { public: - hydrogen(): - ode_base(4) + hydrogen() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -45,9 +44,6 @@ public: reset = 0; } - ~hydrogen() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 3c4d587..60e3a77 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -32,11 +32,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class ikeda_laser_map: - public map_base + public map_base<1> { public: - ikeda_laser_map(): - map_base(1) + ikeda_laser_map() { CHAOS_PAR_INIT(c1,0.4); CHAOS_PAR_INIT(c2,0.9); @@ -47,10 +46,6 @@ public: CHAOS_SYS_INIT(y,0.5,1); } - ~ikeda_laser_map() - { - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index eec6116..47abc33 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -28,11 +28,10 @@ // taken from Pickover: Chaos In Wonderland class latoocarfian - : public map_base + : public map_base<2> { public: - latoocarfian(): - map_base(2) + latoocarfian() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0,1); @@ -42,10 +41,6 @@ public: CHAOS_PAR_INIT(c,0.765145); CHAOS_PAR_INIT(d,0.744728); } - - ~latoocarfian() - { - } virtual void m_step() { diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ac4f28d..255829a 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutalpha - : public map_base + : public map_base<2> { public: - latoomutalpha(): - map_base(2) + latoomutalpha() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.2,1); @@ -41,10 +40,6 @@ public: CHAOS_PAR_INIT(c,0.765145); } - ~latoomutalpha() - { - - } virtual void m_step() { diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index 3a048cd..d663761 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutbeta - : public map_base + : public map_base<2> { public: - latoomutbeta(): - map_base(2) + latoomutbeta() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); @@ -40,11 +39,6 @@ public: CHAOS_PAR_INIT(b,2.879879); } - ~latoomutbeta() - { - - } - virtual void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 5e55225..022e651 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutgamma - : public map_base + : public map_base<2> { public: - latoomutgamma(): - map_base(2) + latoomutgamma() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); @@ -39,11 +38,6 @@ public: CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); } - - ~latoomutgamma() - { - - } virtual void m_step() { @@ -59,7 +53,7 @@ public: /* function has a fix point for x1 == x2 == 0 */ - virtual void m_verify() + void m_verify() { if (m_data[0] == 0 && m_data[1] == 0) for (int i = 0; i != 2; ++i) diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index bc3536a..f6ce961 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -25,11 +25,10 @@ // taken from Julien C. Sprott, Chaos and Time-Series Analysis class linear_congruental: - public map_base + public map_base<2> { public: - linear_congruental(): - map_base(1) + linear_congruental() { CHAOS_SYS_INIT(x, 0, 0); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 3e0ef24..7880d21 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -25,11 +25,10 @@ // 0 <= alpha <= 4 class logistic: - public map_base + public map_base<1> { public: - logistic(): - map_base(1) + logistic() { CHAOS_PAR_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5,0); 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); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index dee6b0d..24096a6 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lozi_map: - public map_base + public map_base<2> { public: - lozi_map(): - map_base(2) + lozi_map() { CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); @@ -39,11 +38,6 @@ public: CHAOS_PAR_INIT(b,0.3); } - ~lozi_map() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 1395bb8..92016b1 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -23,26 +23,18 @@ #include "chaos_base.hpp" +template <int dimensions> class map_base - : public chaos_base + : public chaos_base<dimensions> { protected: - map_base(int n): - chaos_base(n) - { - } - virtual void m_step() { } }; -#define MAP_CALLBACKS \ -CHAOS_CALLBACKS - - -#define MAP_ATTRIBUTES \ -CHAOS_ATTRIBUTES; +#define MAP_CALLBACKS +#define MAP_ATTRIBUTES #define __map_base_hpp #endif /* __map_base_hpp */ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index 2830c2f..004a1b3 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -20,55 +20,4 @@ #include "ode_base.hpp" -void ode_base::rk1() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += m_dt * m_k[0][i]; -} - - -void ode_base::rk2() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - m_k[0][i] = m_k[0][i] * 0.5 * m_dt + m_data[i]; - - m_system (m_k[1], m_k[0]); - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += m_dt * m_k[1][i]; -} - - -void ode_base::rk4() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[0][i] *= m_dt; - m_tmp[i] = m_data[i] + 0.5 * m_k[0][i]; - } - - m_system (m_k[1], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[1][i] *= m_dt; - m_tmp[i] = m_data[i] + 0.5 * m_k[1][i]; - } - - m_system (m_k[2], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[2][i] *= m_dt; - m_tmp[i] = m_data[i] + m_k[2][i]; - } - - m_system (m_k[3], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - m_k[3][i] *= m_dt; - - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += (m_k[0][i] + 2. * (m_k[1][i] + m_k[2][i]) + m_k[3][i]) - / 6.; -} 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 <int dimensions> +class ode_base: + public chaos_base<dimensions> { 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<dimensions>::rk1; break; case 1: - m_routine = &ode_base::rk2; + m_routine = &ode_base<dimensions>::rk2; break; case 2: - m_routine = &ode_base::rk4; + m_routine = &ode_base<dimensions>::rk4; } } else @@ -86,27 +68,75 @@ public: } protected: - void (ode_base::*m_routine)(void); + void (ode_base<dimensions>::*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); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index fd65d4e..aa03a47 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -23,14 +23,13 @@ // roessler model: dx1/dt = - (x2 + x3) // dx2/dt = x1 + a * x2 // dx3/dt = b + (x1 - c) * x3 -// taken from Peitgen / Jürgens / Saupe: Chaos and Fractals +// taken from Peitgen / J�rgens / Saupe: Chaos and Fractals class roessler - : public ode_base + : public ode_base<3> { public: - roessler(): - ode_base(3) + roessler() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.001); @@ -44,9 +43,6 @@ public: CHAOS_PAR_INIT(c,4); } - ~roessler() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 3d69065..8a11281 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -26,12 +26,11 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class sine_map: - public map_base + public map_base<1> { public: - sine_map(): - map_base(1) + sine_map() { CHAOS_SYS_INIT(x,0,0); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 4df1eb9..8798edc 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -27,11 +27,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class standard_map: - public map_base + public map_base<2> { public: - standard_map(): - map_base(2) + standard_map() { CHAOS_SYS_INIT(I,0.1,0); CHAOS_SYS_INIT(theta,0.2,1); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 9bd8e62..2e716ac 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -26,19 +26,14 @@ class tent_map: - public map_base + public map_base<1> { public: - tent_map(): - map_base(1) + tent_map() { CHAOS_SYS_INIT(x, 0.6,0); } - ~tent_map() - { - - } virtual void m_step() { |