Browse Source

almost all kernels made

master
Joshua 14 years ago
parent
commit
ca8cc66a0a
  1. 66
      Attractor.cpp
  2. 2
      Attractor.hpp
  3. 10
      AwesomeAttractor.cbp
  4. 2
      kernels/Lorenz3D.cpp
  5. 0
      kernels/Lorenz3D.hpp
  6. 134
      kernels/Polynomial.cpp
  7. 48
      kernels/Polynomial.hpp
  8. 60
      kernels/PolynomialA3D.cpp
  9. 42
      kernels/PolynomialA3D.hpp
  10. 2
      kernels/Unravel3D.cpp
  11. 0
      kernels/Unravel3D.hpp
  12. 4
      main.cpp

66
Attractor.cpp

@ -100,21 +100,7 @@ void Attractor::init(unsigned int dim_in, FormulaChoice formula_in, unsigned int
orde = orde_in;
switch (formula) {
case POLY_N: {
double n_coef = orde + 1;
for (unsigned int i = 2; i <= dim; i++) {
n_coef = n_coef*(orde + i)/(i - 1);
}
par = (unsigned int) n_coef;
break;
}
case LORENZ: {
assert(dim == 3 || dim == 4);
par = dim + 1;
break;
}
case POLY_A: {
case POLY_A: {4
par = dim;
break;
}
@ -122,11 +108,6 @@ void Attractor::init(unsigned int dim_in, FormulaChoice formula_in, unsigned int
par = dim;
break;
}
case UNRAVEL: {
assert(dim == 3);
par = 7;
break;
}
default: {
cout << "Formula not recognized" << endl;
exit(1);
@ -231,18 +212,11 @@ void Attractor::iterate() {
// calculations
switch (formula) {
case POLY_N:
polynome();
break;
case POLY_A:
poly_A();
break;
case POLY_2:
poly_2();
break;
case LOGISTIC:
logistic();
break;
@ -267,40 +241,6 @@ void Attractor::iterate() {
#endif
}
void Attractor::polynome() {
unsigned int m = 0;
for ( unsigned int i = 0; i < dim; i++ ) {
#ifdef HARDDEBUG
cout << "Entering new dimension: " << i << " With m = " << m << endl;
#endif
new_point[i] = param[m];
m++;
recur(i, 0, 1, m);
}
}
void Attractor::recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product) {
double product;
for (unsigned int i = prev_i; i < dim; i++) {
#ifdef HARDDEBUG
for ( unsigned int j = 0; j < n; j++ )
cout << " ";
cout << "Calculation in dimension: " << i << " With m = " << m << " And depth = " << n << endl;
#endif
product = prev_product * point[i];
new_point[curr_dimension] += param[m] * product;
m++;
if (n < orde) {
recur(curr_dimension, i, n+1, m, product);
}
}
}
void Attractor::poly_A() {
switch (dim) {
case 3:
@ -316,10 +256,6 @@ void Attractor::poly_A() {
}
}
void Attractor::poly_2() {
exit(2);
}
void Attractor::logistic() {
for ( unsigned int i = 0; i < dim; i++ ) {
new_point[i] = param[i]*point[i]*(1.0 - point[i]);

2
Attractor.hpp

@ -47,8 +47,6 @@ public:
// TODO : optimaliseren voor lage graads veeltermen
void iterate();
void polynome();
void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product = 1.0);
void poly_A();
void poly_2();
void logistic();

10
AwesomeAttractor.cbp

@ -46,10 +46,12 @@
<Unit filename="attr/test.attr" />
<Unit filename="attr/test2.attr" />
<Unit filename="attr/waardes.txt" />
<Unit filename="kernels/Lorenz.cpp" />
<Unit filename="kernels/Lorenz.hpp" />
<Unit filename="kernels/Unravel.cpp" />
<Unit filename="kernels/Unravel.hpp" />
<Unit filename="kernels/Lorenz3D.cpp" />
<Unit filename="kernels/Lorenz3D.hpp" />
<Unit filename="kernels/Polynomial.cpp" />
<Unit filename="kernels/Polynomial.hpp" />
<Unit filename="kernels/Unravel3D.cpp" />
<Unit filename="kernels/Unravel3D.hpp" />
<Unit filename="main.cpp" />
<Unit filename="myMath.hpp" />
<Unit filename="pngwriter/pngwriter.cc" />

2
kernels/Lorenz.cpp → kernels/Lorenz3D.cpp

@ -1,4 +1,4 @@
#include "Lorenz.hpp"
#include "Lorenz3D.hpp"
Lorenz::Lorenz() {
init();

0
kernels/Lorenz.hpp → kernels/Lorenz3D.hpp

134
kernels/Polynomial.cpp

@ -0,0 +1,134 @@
//
// $filename
// $projectname
//
// Created by Joshua moerman on $TODAY.
// Copyright 2010 Joshua Moerman. All rights reserved.
//
Polynomial::Polynomial() {
dimension = 3;
orde = 2;
init();
}
Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde):
dimension(dimension), orde(orde) {
init();
}
void Polynomial::init(){
calculateNumberOfParameters();
if ( myParameters != NULL ) {
delete myParameters;
}
myParameters = new double[numberOfParameters];
if ( vectorNew != NULL ) {
delete vectorNew;
}
vectorNew = new double[dimension];
if ( vectorOld != NULL ) {
delete vectorOld;
}
vectorOld = new double[dimension];
assert(myParameters != NULL);
assert(vectorNew != NULL);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
}
void Polynomial::calculateNumberOfParameters(){
double n_coef = orde + 1;
for (unsigned int i = 2; i <= dim; i++) {
n_coef = n_coef*(orde + i)/(i - 1);
}
numberOfParameters = (unsigned int) n_coef;
}
void Polynomial::iterate() {
unsigned int m = 0;
for ( unsigned int i = 0; i < dim; i++ ) {
#ifdef HARDDEBUG
cout << "Entering new dimension: " << i << " With m = " << m << endl;
#endif
new_point[i] = param[m];
m++;
recur(i, 0, 1, m);
}
}
void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product) {
double product;
for (unsigned int i = prev_i; i < dim; i++) {
#ifdef HARDDEBUG
for ( unsigned int j = 0; j < n; j++ )
cout << " ";
cout << "Calculation in dimension: " << i << " With m = " << m << " And depth = " << n << endl;
#endif
product = prev_product * point[i];
new_point[curr_dimension] += param[m] * product;
m++;
if (n < orde) {
recur(curr_dimension, i, n+1, m, product);
}
}
}
// setters, getters, all i/o to other classes/objects
void * Polynomial::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
} else if ( identifier == "orde" ) {
unsigned int * _return = new unsigned int;
*_return = orde;
return _return;
}
return NULL;
}
void Polynomial::setProperty(const string identifier, const void * _value) {
if ( identifier == "dimension" ) {
unsigned int * value = (unsigned int*) _value;
dimension = *value;
init();
} else if ( identifier == "orde" ) {
unsigned int * value = (unsigned int*) _value;
orde = *value;
init();
}
}
double * & Polynomial::parameters() {
return myParameters;
}
double & Polynomial::parameter(const unsigned int index) {
return myParameters[index];
}
double * & Polynomial::vector() {
return vectorNew;
}
double * & Polynomial::previousVector() {
return vectorOld;
}

48
kernels/Polynomial.hpp

@ -0,0 +1,48 @@
#ifndef POLYNOMIAL_HPP
#define POLYNOMIAL_HPP
#include "../AttractorKernel.hpp"
class Polynomial : public AttractorKernel {
double * myParameters;
double * vectorNew;
double * vectorOld;
unsigned int dimension;
unsigned int orde;
unsigned int numberOfParameters;
void init();
void calculateNumberOfParameters();
void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product);
public:
Polynomial();
Polynomial(const unsigned int dimensions, const unsigned int orde);
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index);
virtual double*& parameters();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value);
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
virtual double * & vector();
virtual double * & previousVector();
};
#endif // POLYNOMIAL_HPP

60
kernels/PolynomialA3D.cpp

@ -0,0 +1,60 @@
//
// $filename
// $projectname
//
// Created by Joshua moerman on $TODAY.
// Copyright 2010 Joshua Moerman. All rights reserved.
//
const static unsigned int dimension = 3;
const static unsigned int numberOfParameters = 3;
PolynomialA3D::PolynomialA3D(){
init();
}
void PolynomialA3D::init(){
myParameters = new double[numberOfParameters];
vectorNew = new double[dimension];
vectorOld = new double[dimension];
assert(myParameters != NULL);
assert(vectorNew != NULL);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
}
// setters, getters, all i/o to other classes/objects
void * PolynomialA3D::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
void PolynomialA3D::setProperty(const string identifier, const void * _value) {
}
double * & PolynomialA3D::parameters() {
return myParameters;
}
double & PolynomialA3D::parameter(const unsigned int index) {
return myParameters[index];
}
double * & PolynomialA3D::vector() {
return vectorNew;
}
double * & PolynomialA3D::previousVector() {
return vectorOld;
}

42
kernels/PolynomialA3D.hpp

@ -0,0 +1,42 @@
#ifndef POLYNOMIALA3D_HPP
#define POLYNOMIALA3D_HPP
#include "../AttractorKernel.hpp"
class PolynomialA3D : public AttractorKernel {
// of course this can be seen as a subclasse of Polynomial
double * myParameters;
double * vectorNew;
double * vectorOld;
void init();
public:
PolynomialA3D();
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index);
virtual double*& parameters();
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier);
virtual void setProperty(const string identifier, const void * value);
// iterate his formula
// vector pointers will be swapped! so new remains new and old remains old
virtual void iterate();
// getter functions for teh resulta
virtual double * & vector();
virtual double * & previousVector();
};
#endif // POLYNOMIALA3D_HPP

2
kernels/Unravel.cpp → kernels/Unravel3D.cpp

@ -1,4 +1,4 @@
#include "Unravel.hpp"
#include "Unravel3D.hpp"
Unravel::Unravel(){
init();

0
kernels/Unravel.hpp → kernels/Unravel3D.hpp

4
main.cpp

@ -6,14 +6,12 @@ using namespace std;
#include "Projector.hpp"
#include "AttractorKernel.hpp"
#include "kernels/Lorenz.hpp"
#include "kernels/Lorenz3D.hpp"
// TODO : Allemaal files inlezen, voor makkelijker gebruik
int main(int argc, char *argv[]) {
// even iets te committen hebben
AttractorKernel * mijnAttractortje;
mijnAttractortje = new Lorenz();
AttractorKernel &attractor = *mijnAttractortje;