My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

109 lines
2.6 KiB

#include "Attractor.hpp"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include "stfu/stf.hpp"
#include "AttractorKernel.hpp"
#include "Projector.hpp"
Attractor::Attractor(const char* const fileName) {
// opening file
std::cout << "Reading file " << fileName << "..." << std::endl;
stfu::node system;
system.read(fileName);
stfu::node attractor = system.getChild("AttractorKernel");
myAttractor = AttractorKernel::createAttractorKernel(attractor);
}
Attractor::~Attractor(){
delete myAttractor;
}
// this should probably done in the projector section
void Attractor::init_range() {
// stabilize attractor
for ( unsigned int i = 0; i < 100000; i++ ) {
iterate();
}
// initialize projectors with dimension and first point
const unsigned int dimension = myAttractor->getDimension();
const double * point = myAttractor->vector();
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->extern_dim = dimension;
(*it)->intern_dim = 2;
(*it)->init(point);
}
// update ranges
for ( unsigned int i = 0; i < 100000; i++ ) {
iterate();
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->update_range(point);
}
}
for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->finish_range();
}
}
bool Attractor::is_chaos() {
/*
check existence of attractor:
Escaping
Single point attractor
Lyapunov exponent
*/
/*
double sum = 0;
for ( unsigned int i = 0; i < dim; i++ ) {
const double dist = 0; //new_point[i] - point[i];
sum += dist*dist;
}
if ( sum >= 1.0e7 ) {
// big change => Escaping
return false;
}
if ( sum <= 1.0e-7 ) {
// small change => singularity
return false;
}
return true;
*/
return true;
}
void Attractor::iterate() {
(*myAttractor)();
}
void Attractor::plot() {
for ( std::vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
const double * point = myAttractor->vector();
(*it)->plot(point);
}
}
/*
IO & control
*/
void Attractor::output() {
const unsigned int dimension = myAttractor->getDimension();
const double * point = myAttractor->vector();
for ( unsigned int i = 0; i < dimension; i++ ) {
std::cout << point[i] << " ";
}
std::cout << std::endl;
}