|
@ -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 |
|
|
string attractorType = attractor.getValue("type"); |
|
|
|
|
|
const string attractorDimension = attractor.getValue("dimensions"); |
|
|
3.24454 |
|
|
|
|
|
1.25 |
|
|
for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) { |
|
|
.... |
|
|
attractorType[i] = tolower(attractorType[i]); |
|
|
*/ |
|
|
} |
|
|
|
|
|
const unsigned int dimension = atoi(attractorDimension.c_str()); |
|
|
string fileFormula; |
|
|
|
|
|
file >> fileFormula; |
|
|
cout << " Formula: " << attractorType << endl; |
|
|
|
|
|
cout << " Dimensions: " << dimension << endl; |
|
|
for ( unsigned int i = 0; fileFormula[i] != '\0'; i++ ) { |
|
|
|
|
|
fileFormula[i] = tolower(fileFormula[i]); |
|
|
if ( attractorType == "lorenz" ){ |
|
|
} |
|
|
if ( dimension == 3 ) { |
|
|
|
|
|
myAttractor = new Lorenz3D(); |
|
|
unsigned int fileDim; |
|
|
} else { |
|
|
file >> fileDim; |
|
|
cerr << "something wrong"; |
|
|
|
|
|
exit(37); |
|
|
unsigned int fileOrde; |
|
|
} |
|
|
file >> fileOrde; |
|
|
} else if ( attractorType == "polynomial" ) { |
|
|
|
|
|
const string attractorOrde = attractor.getValue("orde"); |
|
|
cout << " Formula: " << fileFormula << endl; |
|
|
const unsigned int orde = atoi(attractorOrde.c_str()); |
|
|
cout << " Dimensions: " << fileDim << endl; |
|
|
cout << " Orde: " << orde << endl; |
|
|
cout << " Orde: " << fileOrde << endl; |
|
|
myAttractor = new Polynomial(dimension, orde); |
|
|
|
|
|
|
|
|
if ( fileFormula == "lorenz" ) |
|
|
} else if ( attractorType == "polynomial a" ) { |
|
|
init(fileDim, LORENZ, fileOrde); |
|
|
if ( dimension == 3 ) { |
|
|
else if ( fileFormula == "poly_n" ) |
|
|
myAttractor = new PolynomialA3D(); |
|
|
init(fileDim, POLY_N, fileOrde); |
|
|
} else { |
|
|
else if ( fileFormula == "poly_a" ) |
|
|
cerr << "something wrong"; |
|
|
init(fileDim, POLY_A, fileOrde); |
|
|
exit(37); |
|
|
else if ( fileFormula == "logistic" ) |
|
|
} |
|
|
init(fileDim, LOGISTIC, fileOrde); |
|
|
} else if ( attractorType == "logistic" ) { |
|
|
else if ( fileFormula == "unravel" ) |
|
|
myAttractor = new Logistic(dimension); |
|
|
init(fileDim, UNRAVEL, fileOrde); |
|
|
|
|
|
else { |
|
|
} else if ( attractorType == "unravel" ) { |
|
|
cout << " Formula not (yet) supported" << endl; |
|
|
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] << ", "; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cout << endl << " Reading file complete" << endl; |
|
|
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] << ", "; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Attractor::init(unsigned int dim_in, FormulaChoice formula_in, unsigned int orde_in) { |
|
|
cout << endl << " Reading file complete" << endl; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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; |
|
|
} |
|
|
} |
|
|