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