|
|
@ -1,47 +1,65 @@ |
|
|
|
#include "Attractor.hpp" |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <fstream> |
|
|
|
#include <cstdlib> |
|
|
|
#include <string> |
|
|
|
#include "stfu/stf.hpp" |
|
|
|
|
|
|
|
#include "Projector.hpp" |
|
|
|
|
|
|
|
#include "AttractorKernel.hpp" |
|
|
|
#include "kernels/Logistic.hpp" |
|
|
|
#include "kernels/Lorenz3D.hpp" |
|
|
|
#include "kernels/Polynomial.hpp" |
|
|
|
#include "kernels/PolynomialA3D.hpp" |
|
|
|
#include "kernels/Unravel3D.hpp" |
|
|
|
|
|
|
|
Attractor::Attractor() { |
|
|
|
myAttractor = new Lorenz3D(); |
|
|
|
// TODO: add default parameters
|
|
|
|
} |
|
|
|
|
|
|
|
Attractor::Attractor(const char* const fileName) { |
|
|
|
cout << "Reading file " << fileName << "..." << endl; |
|
|
|
// opening file
|
|
|
|
std::cout << "Reading file " << fileName << "..." << std::endl; |
|
|
|
|
|
|
|
stfu::node system; |
|
|
|
system.read(fileName); |
|
|
|
stfu::node attractor = system.getChild("attractor"); |
|
|
|
|
|
|
|
string attractorType = attractor.getValue("type"); |
|
|
|
const string attractorDimension = attractor.getValue("dimensions"); |
|
|
|
|
|
|
|
// reading basic stuff
|
|
|
|
std::string attractorType = attractor.getValue("type"); |
|
|
|
const std::string attractorDimension = attractor.getValue("dimensions"); |
|
|
|
|
|
|
|
for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) { |
|
|
|
attractorType[i] = tolower(attractorType[i]); |
|
|
|
} |
|
|
|
const unsigned int dimension = atoi(attractorDimension.c_str()); |
|
|
|
|
|
|
|
cout << " Formula: " << attractorType << endl; |
|
|
|
cout << " Dimensions: " << dimension << endl; |
|
|
|
std::cout << " Formula: " << attractorType << std::endl; |
|
|
|
std::cout << " Dimensions: " << dimension << std::endl; |
|
|
|
|
|
|
|
|
|
|
|
// depending on type, make the formula object
|
|
|
|
if ( attractorType == "lorenz" ){ |
|
|
|
if ( dimension == 3 ) { |
|
|
|
myAttractor = new Lorenz3D(); |
|
|
|
} else { |
|
|
|
cerr << "something wrong"; |
|
|
|
std::cerr << "something wrong"; |
|
|
|
exit(37); |
|
|
|
} |
|
|
|
} else if ( attractorType == "polynomial" ) { |
|
|
|
const string attractorOrde = attractor.getValue("orde"); |
|
|
|
const std::string attractorOrde = attractor.getValue("orde"); |
|
|
|
const unsigned int orde = atoi(attractorOrde.c_str()); |
|
|
|
cout << " Orde: " << orde << endl; |
|
|
|
std::cout << " Orde: " << orde << std::endl; |
|
|
|
myAttractor = new Polynomial(dimension, orde); |
|
|
|
|
|
|
|
} else if ( attractorType == "polynomial a" ) { |
|
|
|
if ( dimension == 3 ) { |
|
|
|
myAttractor = new PolynomialA3D(); |
|
|
|
} else { |
|
|
|
cerr << "something wrong"; |
|
|
|
std::cerr << "something wrong"; |
|
|
|
exit(37); |
|
|
|
} |
|
|
|
} else if ( attractorType == "logistic" ) { |
|
|
@ -51,26 +69,29 @@ Attractor::Attractor(const char* const fileName) { |
|
|
|
if ( dimension == 3 ) { |
|
|
|
myAttractor = new Unravel3D(); |
|
|
|
} else { |
|
|
|
cerr << "somtheing wrong"; |
|
|
|
std::cerr << "somtheing wrong"; |
|
|
|
exit(37); |
|
|
|
} |
|
|
|
} else { |
|
|
|
cout << "'" << attractorType << "' not recognized" << endl; |
|
|
|
std::cout << "'" << attractorType << "' not recognized" << std::endl; |
|
|
|
exit(3); |
|
|
|
} |
|
|
|
|
|
|
|
const unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); |
|
|
|
double * & parameters = myAttractor->parameters(); |
|
|
|
|
|
|
|
// read parameters
|
|
|
|
const unsigned int numberOfParameters = myAttractor->numberOfParameters(); |
|
|
|
|
|
|
|
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] << ", "; |
|
|
|
(*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str()); |
|
|
|
std::cout << " Parameter " << i << " set to " << (*myAttractor)[i] << ", "; |
|
|
|
} |
|
|
|
|
|
|
|
cout << endl << " Reading file complete" << endl; |
|
|
|
std::cout << std::endl << " Reading file complete" << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// this should probably done in the projector section
|
|
|
|
void Attractor::init_range() { |
|
|
|
// stabilize attractor
|
|
|
|
for ( unsigned int i = 0; i < 100000; i++ ) { |
|
|
@ -78,11 +99,9 @@ void Attractor::init_range() { |
|
|
|
} |
|
|
|
|
|
|
|
// initialize projectors with dimension and first point
|
|
|
|
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); |
|
|
|
const unsigned int dimension = *dim; |
|
|
|
delete dim; |
|
|
|
const unsigned int dimension = myAttractor->dimension(); |
|
|
|
const double * point = myAttractor->vector(); |
|
|
|
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
(*it)->extern_dim = dimension; |
|
|
|
(*it)->intern_dim = 2; |
|
|
|
(*it)->init(point); |
|
|
@ -92,11 +111,11 @@ void Attractor::init_range() { |
|
|
|
for ( unsigned int i = 0; i < 100000; i++ ) { |
|
|
|
iterate(); |
|
|
|
|
|
|
|
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
(*it)->update_range(point); |
|
|
|
} |
|
|
|
} |
|
|
|
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
(*it)->finish_range(); |
|
|
|
} |
|
|
|
|
|
|
@ -129,11 +148,11 @@ bool Attractor::is_chaos() { |
|
|
|
} |
|
|
|
|
|
|
|
void Attractor::iterate() { |
|
|
|
myAttractor->iterate(); |
|
|
|
(*myAttractor)(); |
|
|
|
} |
|
|
|
|
|
|
|
void Attractor::plot() { |
|
|
|
for ( vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
for ( std::vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { |
|
|
|
const double * point = myAttractor->vector(); |
|
|
|
(*it)->plot(point); |
|
|
|
} |
|
|
@ -144,13 +163,11 @@ void Attractor::plot() { |
|
|
|
IO & control |
|
|
|
*/ |
|
|
|
void Attractor::output() { |
|
|
|
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); |
|
|
|
const unsigned int dimension = *dim; |
|
|
|
delete dim; |
|
|
|
const unsigned int dimension = myAttractor->dimension(); |
|
|
|
const double * point = myAttractor->vector(); |
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < dimension; i++ ) { |
|
|
|
cout << point[i] << " "; |
|
|
|
std::cout << point[i] << " "; |
|
|
|
} |
|
|
|
cout << endl; |
|
|
|
std::cout << std::endl; |
|
|
|
} |
|
|
|