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.
 
 
 

101 lines
2.0 KiB

#include "Attractor.hpp"
#include "Logger.hpp"
#include <fstream>
#include <cstdlib>
#include <string>
#include "stfu/stf.hpp"
#include "AttractorKernel.hpp"
#include "Projector.hpp"
Attractor::Attractor(const std::string& filename) : kernel(0), projector(0) {
// opening file
LogInfo("Reading file '%s'...\n", filename.c_str());
stfu::node system;
system.read(filename.c_str());
kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel"));
projector = Projector::createProjector(system.getChild(system.getChild("Projector")), system);
}
Attractor::~Attractor(){
delete kernel;
}
// this should probably done in the projector section
void Attractor::init_range() {
// stabilize attractor
for ( unsigned int i = 0; i < 100000; i++ ) {
iterate();
}
// initialize projector with dimension and first point
const unsigned int dimension = kernel->getDimension();
const double * point = kernel->vector();
projector->extern_dim = dimension;
projector->intern_dim = 3;
projector->init(point);
// update ranges
for ( unsigned int i = 0; i < 500000; i++ ) {
iterate();
projector->update_range(point);
}
projector->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() {
(*kernel)();
}
void Attractor::plot() {
const double * point = kernel->vector();
projector->plot(point);
}
/*
IO & control
*/
void Attractor::output() {
const unsigned int dimension = kernel->getDimension();
const double * point = kernel->vector();
for ( unsigned int i = 0; i < dimension; i++ ) {
LogMoreInfo("%f, ", point[i]);
}
LogMoreInfo("\n");
}