|
@ -1,98 +1,91 @@ |
|
|
#include <cmath> |
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
#include <fstream> |
|
|
|
|
|
#include <cstdlib> |
|
|
|
|
|
#include <iomanip> |
|
|
|
|
|
#include <cassert> |
|
|
|
|
|
#include <string> |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
|
|
#include "Attractor.hpp" |
|
|
#include "Attractor.hpp" |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
Constructors & initialisers |
|
|
Constructors & initialisers |
|
|
*/ |
|
|
*/ |
|
|
Attractor::Attractor(): |
|
|
Attractor::Attractor() { |
|
|
dim(3), par(4), formula(LORENZ), param(NULL), point(NULL), new_point(NULL) { |
|
|
|
|
|
// Default attractor: 3D Lorenz attrractor
|
|
|
|
|
|
|
|
|
|
|
|
param[0] = 0.001; //dt
|
|
|
myAttractor = new Lorenz3D(); |
|
|
param[1] = 10; //sigma
|
|
|
|
|
|
param[2] = 28; //rho
|
|
|
|
|
|
param[3] = 8.0/3.0; //beta
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Attractor::Attractor(const char* const filename) { |
|
|
Attractor::Attractor(const char* const fileName) { |
|
|
ifstream file(filename); |
|
|
ifstream file(fileName); |
|
|
|
|
|
|
|
|
cout << "Reading file " << filename << "..." << endl; |
|
|
cout << "Reading file " << fileName << "..." << endl; |
|
|
|
|
|
|
|
|
if ( !file ) { |
|
|
if ( !file ) { |
|
|
cout << " Error reading file '" << filename << "' dying now..." << endl; |
|
|
cerr << " Error reading file '" << fileName << "' dying now..." << endl; |
|
|
exit(2); |
|
|
exit(2); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO : Use stfu
|
|
|
// TODO : Use stfu
|
|
|
|
|
|
|
|
|
/*
|
|
|
stfu::node system; |
|
|
file.attr: |
|
|
system.read(file); |
|
|
lorenz |
|
|
stfu::node attractor = system.getChild("attractor"); |
|
|
3 |
|
|
|
|
|
0 |
|
|
|
|
|
|
|
|
|
|
|
3.24454 |
|
|
|
|
|
1.25 |
|
|
|
|
|
.... |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
string fileFormula; |
|
|
string attractorType = attractor.getValue("type"); |
|
|
file >> fileFormula; |
|
|
const string attractorDimension = attractor.getValue("dimensions"); |
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; fileFormula[i] != '\0'; i++ ) { |
|
|
for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) { |
|
|
fileFormula[i] = tolower(fileFormula[i]); |
|
|
attractorType[i] = tolower(attractorType[i]); |
|
|
} |
|
|
} |
|
|
|
|
|
const unsigned int dimension = atoi(attractorDimension.c_str()); |
|
|
|
|
|
|
|
|
|
|
|
cout << " Formula: " << attractorType << endl; |
|
|
|
|
|
cout << " Dimensions: " << dimension << endl; |
|
|
|
|
|
|
|
|
unsigned int fileDim; |
|
|
if ( attractorType == "lorenz" ){ |
|
|
file >> fileDim; |
|
|
if ( dimension == 3 ) { |
|
|
|
|
|
myAttractor = new Lorenz3D(); |
|
|
unsigned int fileOrde; |
|
|
} else { |
|
|
file >> fileOrde; |
|
|
cerr << "something wrong"; |
|
|
|
|
|
exit(37); |
|
|
cout << " Formula: " << fileFormula << endl; |
|
|
} |
|
|
cout << " Dimensions: " << fileDim << endl; |
|
|
} else if ( attractorType == "polynomial" ) { |
|
|
cout << " Orde: " << fileOrde << endl; |
|
|
const string attractorOrde = attractor.getValue("orde"); |
|
|
|
|
|
const unsigned int orde = atoi(attractorOrde.c_str()); |
|
|
if ( fileFormula == "lorenz" ) |
|
|
cout << " Orde: " << orde << endl; |
|
|
init(fileDim, LORENZ, fileOrde); |
|
|
myAttractor = new Polynomial(dimension, orde); |
|
|
else if ( fileFormula == "poly_n" ) |
|
|
|
|
|
init(fileDim, POLY_N, fileOrde); |
|
|
} else if ( attractorType == "polynomial a" ) { |
|
|
else if ( fileFormula == "poly_a" ) |
|
|
if ( dimension == 3 ) { |
|
|
init(fileDim, POLY_A, fileOrde); |
|
|
myAttractor = new PolynomialA3D(); |
|
|
else if ( fileFormula == "logistic" ) |
|
|
} else { |
|
|
init(fileDim, LOGISTIC, fileOrde); |
|
|
cerr << "something wrong"; |
|
|
else if ( fileFormula == "unravel" ) |
|
|
exit(37); |
|
|
init(fileDim, UNRAVEL, fileOrde); |
|
|
} |
|
|
else { |
|
|
} else if ( attractorType == "logistic" ) { |
|
|
cout << " Formula not (yet) supported" << endl; |
|
|
myAttractor = new Logistic(dimension); |
|
|
|
|
|
|
|
|
|
|
|
} else if ( attractorType == "unravel" ) { |
|
|
|
|
|
if ( dimension == 3 ) { |
|
|
|
|
|
myAttractor = new Unravel3D(); |
|
|
|
|
|
} else { |
|
|
|
|
|
cerr << "somtheing wrong"; |
|
|
|
|
|
exit(37); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
cout << "'" << attractorType << "' not recognized" << endl; |
|
|
exit(3); |
|
|
exit(3); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < par; i++ ) { |
|
|
unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); |
|
|
file >> param[i]; |
|
|
double * & parameters = myAttractor->parameters(); |
|
|
cout << " Parameter " << i << " set to " << param[i] << ", "; |
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < numberOfParameters; i++ ) { |
|
|
|
|
|
stfu::node attractorParameters = attractor.getChild("parameters"); |
|
|
|
|
|
parameters[i] = atof(attractorParameters.getValue(i).c_str()); |
|
|
|
|
|
cout << " Parameter " << i << " set to " << parameters[i] << ", "; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cout << endl << " Reading file complete" << endl; |
|
|
cout << endl << " Reading file complete" << endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Attractor::init(unsigned int dim_in, FormulaChoice formula_in, unsigned int orde_in) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Attractor::init_range() { |
|
|
void Attractor::init_range() { |
|
|
|
|
|
/*
|
|
|
// stabilize attractor
|
|
|
// stabilize attractor
|
|
|
for ( unsigned int i = 0; i < 100000; i++ ) { |
|
|
for ( unsigned int i = 0; i < 100000; i++ ) { |
|
|
iterate(); |
|
|
iterate(); |
|
@ -125,6 +118,7 @@ void Attractor::init_range() { |
|
|
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
(*it)->finish_range(); |
|
|
(*it)->finish_range(); |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Attractor::is_chaos() { |
|
|
bool Attractor::is_chaos() { |
|
@ -134,10 +128,10 @@ bool Attractor::is_chaos() { |
|
|
Single point attractor |
|
|
Single point attractor |
|
|
Lyapunov exponent |
|
|
Lyapunov exponent |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
/*
|
|
|
double sum = 0; |
|
|
double sum = 0; |
|
|
for ( unsigned int i = 0; i < dim; i++ ) { |
|
|
for ( unsigned int i = 0; i < dim; i++ ) { |
|
|
const double dist = new_point[i] - point[i]; |
|
|
const double dist = 0; //new_point[i] - point[i];
|
|
|
sum += dist*dist; |
|
|
sum += dist*dist; |
|
|
} |
|
|
} |
|
|
if ( sum >= 1.0e7 ) { |
|
|
if ( sum >= 1.0e7 ) { |
|
@ -149,17 +143,17 @@ bool Attractor::is_chaos() { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
*/ |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Iteration & Math |
|
|
|
|
|
*/ |
|
|
|
|
|
void Attractor::iterate() { |
|
|
void Attractor::iterate() { |
|
|
// attractorKernel->iterate()
|
|
|
myAttractor->iterate(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Attractor::plot() { |
|
|
void Attractor::plot() { |
|
|
for ( vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
for ( vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
|
|
const double * point = myAttractor->vector(); |
|
|
(*it)->plot(point); |
|
|
(*it)->plot(point); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -169,8 +163,13 @@ void Attractor::plot() { |
|
|
IO & control |
|
|
IO & control |
|
|
*/ |
|
|
*/ |
|
|
void Attractor::output() { |
|
|
void Attractor::output() { |
|
|
for ( unsigned int i = 0; i < dim; i++ ) { |
|
|
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); |
|
|
|
|
|
const double * point = myAttractor->vector(); |
|
|
|
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < *dim; i++ ) { |
|
|
cout << point[i] << " "; |
|
|
cout << point[i] << " "; |
|
|
} |
|
|
} |
|
|
cout << endl; |
|
|
cout << endl; |
|
|
|
|
|
|
|
|
|
|
|
delete dim; |
|
|
} |
|
|
} |
|
|