basic kernel added, for more code reuse
This commit is contained in:
parent
f77daec80f
commit
1334e7e547
8 changed files with 86 additions and 31 deletions
|
@ -21,7 +21,9 @@
|
||||||
<Option type="1" />
|
<Option type="1" />
|
||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-O2" />
|
<Add option="-fexpensive-optimizations" />
|
||||||
|
<Add option="-O3" />
|
||||||
|
<Add option="-msse4.1" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
<Linker>
|
<Linker>
|
||||||
<Add option="-s" />
|
<Add option="-s" />
|
||||||
|
@ -47,6 +49,8 @@
|
||||||
<Unit filename="attractors/testLorenz.stf" />
|
<Unit filename="attractors/testLorenz.stf" />
|
||||||
<Unit filename="attractors/testPolynomial.stf" />
|
<Unit filename="attractors/testPolynomial.stf" />
|
||||||
<Unit filename="attractors/testUnravel.stf" />
|
<Unit filename="attractors/testUnravel.stf" />
|
||||||
|
<Unit filename="kernels/BasicKernel.cpp" />
|
||||||
|
<Unit filename="kernels/BasicKernel.h" />
|
||||||
<Unit filename="kernels/Logistic.cpp" />
|
<Unit filename="kernels/Logistic.cpp" />
|
||||||
<Unit filename="kernels/Logistic.hpp" />
|
<Unit filename="kernels/Logistic.hpp" />
|
||||||
<Unit filename="kernels/Lorenz3D.cpp" />
|
<Unit filename="kernels/Lorenz3D.cpp" />
|
||||||
|
|
|
@ -118,7 +118,7 @@ void Canvas::output_file(const char * filename){
|
||||||
if ( max_int[i] < int_array[j+i*width*height] ) {
|
if ( max_int[i] < int_array[j+i*width*height] ) {
|
||||||
max_int[i] = int_array[j+i*width*height];
|
max_int[i] = int_array[j+i*width*height];
|
||||||
}
|
}
|
||||||
if ( int_array[j+i*width*height] > 5 ) {
|
if ( int_array[j+i*width*height] ) {
|
||||||
cumulative += int_array[j+i*width*height];
|
cumulative += int_array[j+i*width*height];
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ void Canvas::output_file(const char * filename){
|
||||||
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c];
|
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c];
|
||||||
switch(c){
|
switch(c){
|
||||||
case 0: {
|
case 0: {
|
||||||
r = (pow(norm_value, power[c]))*3.0;
|
r = (pow(norm_value, power[c]))*3.5;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
|
|
|
@ -93,10 +93,10 @@ void Projector::plot(const double * point) {
|
||||||
|
|
||||||
//cout << x << ", " << y << endl;
|
//cout << x << ", " << y << endl;
|
||||||
|
|
||||||
canvas->plot(x, y);
|
canvas->plot(x+0.01*rand()/(double)RAND_MAX-0.005, y+0.01*rand()/(double)RAND_MAX-0.005);
|
||||||
if ( even(point[2]*4.0) )
|
if ( even(point[2]*17) )
|
||||||
canvas->plot(x, y, 1);
|
canvas->plot(x, y, 1);
|
||||||
else
|
if ( even(point[2]*17+0.6) )
|
||||||
canvas->plot(x, y, 2);
|
canvas->plot(x, y, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
kernels/BasicKernel.cpp
Normal file
19
kernels/BasicKernel.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
#include "BasicKernel.h"
|
||||||
|
|
||||||
|
double * & BasicKernel::parameters() {
|
||||||
|
return myParameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
double & BasicKernel::parameter(const unsigned int index) {
|
||||||
|
return myParameters[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
double * & BasicKernel::vector() {
|
||||||
|
return vectorNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
double * & BasicKernel::previousVector() {
|
||||||
|
return vectorOld;
|
||||||
|
}
|
||||||
|
|
31
kernels/BasicKernel.h
Normal file
31
kernels/BasicKernel.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef BASICKERNEL_HPP
|
||||||
|
#define BASICKERNEL_HPP
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "../AttractorKernel.hpp"
|
||||||
|
|
||||||
|
class BasicKernel : public AttractorKernel {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
double * myParameters;
|
||||||
|
|
||||||
|
double * vectorNew;
|
||||||
|
double * vectorOld;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// getter functions for teh resulta
|
||||||
|
virtual double * & vector();
|
||||||
|
virtual double * & previousVector();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // POLYNOMIAL_HPP
|
||||||
|
|
|
@ -57,24 +57,24 @@ void Lorenz3D::setProperty(const string identifier, const void * value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double * & Lorenz3D::parameters() {
|
//double * & Lorenz3D::parameters() {
|
||||||
return myParameters;
|
// return myParameters;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
double & Lorenz3D::parameter(const unsigned int index) {
|
//double & Lorenz3D::parameter(const unsigned int index) {
|
||||||
return myParameters[index];
|
// return myParameters[index];
|
||||||
}
|
//}
|
||||||
|
|
||||||
unsigned int Lorenz3D::getNumberOfParameters() {
|
unsigned int Lorenz3D::getNumberOfParameters() {
|
||||||
return numberOfParameters;
|
return numberOfParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
double * & Lorenz3D::vector() {
|
//double * & Lorenz3D::vector() {
|
||||||
return vectorNew;
|
// return vectorNew;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
double * & Lorenz3D::previousVector() {
|
//double * & Lorenz3D::previousVector() {
|
||||||
return vectorOld;
|
// return vectorOld;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "../AttractorKernel.hpp"
|
#include "../AttractorKernel.hpp"
|
||||||
|
#include "BasicKernel.h"
|
||||||
|
|
||||||
class Lorenz3D : public AttractorKernel {
|
class Lorenz3D : public BasicKernel {
|
||||||
|
|
||||||
double * myParameters;
|
// double * myParameters;
|
||||||
|
//
|
||||||
double * vectorNew;
|
// double * vectorNew;
|
||||||
double * vectorOld;
|
// double * vectorOld;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
@ -25,8 +26,8 @@ class Lorenz3D : public AttractorKernel {
|
||||||
|
|
||||||
// parameters are stored in a array of doubles
|
// parameters are stored in a array of doubles
|
||||||
// if you want to use other types, use the properties
|
// if you want to use other types, use the properties
|
||||||
virtual double& parameter(const unsigned int index);
|
// virtual double& parameter(const unsigned int index);
|
||||||
virtual double*& parameters();
|
// virtual double*& parameters();
|
||||||
|
|
||||||
virtual unsigned int getNumberOfParameters();
|
virtual unsigned int getNumberOfParameters();
|
||||||
|
|
||||||
|
@ -41,8 +42,8 @@ class Lorenz3D : public AttractorKernel {
|
||||||
virtual void iterate();
|
virtual void iterate();
|
||||||
|
|
||||||
// getter functions for teh resulta
|
// getter functions for teh resulta
|
||||||
virtual double * & vector();
|
// virtual double * & vector();
|
||||||
virtual double * & previousVector();
|
// virtual double * & previousVector();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
4
main.cpp
4
main.cpp
|
@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
|
||||||
Attractor myAttractor("attractors/testPolynomial.stf");
|
Attractor myAttractor("attractors/testPolynomial.stf");
|
||||||
|
|
||||||
Projector projection;
|
Projector projection;
|
||||||
Canvas canvas(800, 800, 3);
|
Canvas canvas(8000, 8000, 3);
|
||||||
projection.canvas = &canvas;
|
projection.canvas = &canvas;
|
||||||
|
|
||||||
myAttractor.projectors.push_back(&projection);
|
myAttractor.projectors.push_back(&projection);
|
||||||
|
@ -23,7 +23,7 @@ int main(int argc, char *argv[]) {
|
||||||
projection.output();
|
projection.output();
|
||||||
|
|
||||||
// iterating 4 evah
|
// iterating 4 evah
|
||||||
unsigned int iterations = 2000; // tweeduizend
|
unsigned int iterations = 800000000; // acht honderd miljoen
|
||||||
start = clock();
|
start = clock();
|
||||||
for ( unsigned int j = 1; j <= 100; j++ ) {
|
for ( unsigned int j = 1; j <= 100; j++ ) {
|
||||||
for ( unsigned int i = 0; i <= iterations; i++ ) {
|
for ( unsigned int i = 0; i <= iterations; i++ ) {
|
||||||
|
|
Reference in a new issue