added bash script to clean up code
This commit is contained in:
parent
49b3649891
commit
a0f07490e3
10 changed files with 45 additions and 33 deletions
|
@ -12,20 +12,20 @@ private:
|
|||
AttractorKernel * myAttractor;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// should be private really
|
||||
std::vector<Projector *> projectors;
|
||||
|
||||
|
||||
Attractor(const char* const filename);
|
||||
~Attractor();
|
||||
|
||||
|
||||
void init_range();
|
||||
bool is_chaos();
|
||||
|
||||
|
||||
void iterate();
|
||||
void plot();
|
||||
void output();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ATTRACTOR_HPP
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
AttractorKernel::AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters) :
|
||||
numberOfParameters(numberOfParameters), dimension(dimension){
|
||||
|
||||
|
||||
try {
|
||||
allocate();
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ numberOfParameters(numberOfParameters), dimension(dimension){
|
|||
std::cout << "Couldn't construct AttractorKernel: " << e.what() << std::endl;
|
||||
dealloc();
|
||||
}
|
||||
|
||||
|
||||
std::fill_n(parameters, numberOfParameters, 0.0);
|
||||
std::fill_n(vectorNew, dimension, 0.0);
|
||||
std::fill_n(vectorOld, dimension, 0.0);
|
||||
|
@ -93,22 +93,22 @@ unsigned int AttractorKernel::getDimension() const{
|
|||
#include "kernels/Unravel3D.hpp"
|
||||
|
||||
AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){
|
||||
|
||||
|
||||
AttractorKernel * myAttractor = NULL;
|
||||
|
||||
|
||||
// reading basic stuff
|
||||
const std::string attractorType = attractor.getValue("type");
|
||||
const std::string attractorDimension = attractor.getValue("dimensions");
|
||||
|
||||
|
||||
// for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) {
|
||||
// attractorType[i] = tolower(attractorType[i]);
|
||||
// }
|
||||
const unsigned int dimension = atoi(attractorDimension.c_str());
|
||||
|
||||
|
||||
std::cout << " Formula: " << attractorType << std::endl;
|
||||
std::cout << " Dimensions: " << dimension << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
// depending on type, make the formula object
|
||||
if ( attractorType == "lorenz" ){
|
||||
if ( dimension == 3 ) {
|
||||
|
@ -122,7 +122,7 @@ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){
|
|||
const unsigned int orde = atoi(attractorOrde.c_str());
|
||||
std::cout << " Orde: " << orde << std::endl;
|
||||
myAttractor = new Polynomial(dimension, orde);
|
||||
|
||||
|
||||
} else if ( attractorType == "polynomial a" ) {
|
||||
if ( dimension == 3 ) {
|
||||
myAttractor = new PolynomialA3D();
|
||||
|
@ -143,19 +143,19 @@ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){
|
|||
std::cout << "'" << attractorType << "' not recognized" << std::endl;
|
||||
exit(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// read parameters
|
||||
const unsigned int numberOfParameters = myAttractor->getNumberOfParameters();
|
||||
|
||||
|
||||
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
|
||||
stfu::node attractorParameters = attractor.getChild("parameters");
|
||||
(*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str());
|
||||
std::cout << " Parameter " << i << " set to " << (*myAttractor)[i] << ", ";
|
||||
}
|
||||
|
||||
|
||||
std::cout << std::endl << " Reading file complete" << std::endl;
|
||||
|
||||
|
||||
return myAttractor;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
class AttractorKernel {
|
||||
private:
|
||||
|
||||
|
||||
void allocate();
|
||||
void dealloc();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// biggest type first, this will reduce sizeof(AttractorKernel)
|
||||
|
@ -16,14 +16,14 @@ protected:
|
|||
double * parameters;
|
||||
double * vectorNew;
|
||||
double * vectorOld;
|
||||
|
||||
|
||||
unsigned int numberOfParameters;
|
||||
unsigned int dimension;
|
||||
|
||||
// stuff used by subclasses
|
||||
AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters);
|
||||
void reallocParameters(const unsigned int numberOfParameters);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// parameters are stored in a array of doubles
|
||||
|
@ -38,13 +38,13 @@ public:
|
|||
double const * vector() const;
|
||||
double const * previousVector() const;
|
||||
unsigned int getDimension() const;
|
||||
|
||||
|
||||
// dtor, should be virtual for subclasses to be deleted
|
||||
virtual ~AttractorKernel();
|
||||
|
||||
|
||||
// factory function
|
||||
static AttractorKernel * createAttractorKernel(stfu::node& attractorKernel);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // ATTRACTORKERNEL_HPP
|
||||
|
|
|
@ -25,7 +25,7 @@ projections: Applied in order they appear {
|
|||
}
|
||||
:{
|
||||
type: "lineair map"
|
||||
|
||||
|
||||
matrix:
|
||||
{
|
||||
:{ :"1" :"0" :"0" }
|
||||
|
|
12
cleanCode.sh
Normal file
12
cleanCode.sh
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
DIRS="./*.cpp ./*.hpp ./kernels/*.cpp ./kernels/*.hpp ./attractors/*.stf"
|
||||
echo "This program will delete all trailing whitespaces and will replace spaces with tabs"
|
||||
|
||||
for file in ${DIRS}
|
||||
do
|
||||
echo "yay ${file}"
|
||||
unexpand -t 4 ${file} | sed 's/[ \t]*$//' > ${file}.new
|
||||
cat ${file}.new > ${file}
|
||||
rm ${file}.new
|
||||
done
|
||||
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
class Logistic : public AttractorKernel {
|
||||
private:
|
||||
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
Logistic();
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#pragma mark ctors
|
||||
|
||||
Lorenz3D::Lorenz3D():
|
||||
AttractorKernel(3, 4){
|
||||
AttractorKernel(3, 4){
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class Lorenz3D : public AttractorKernel {
|
||||
private:
|
||||
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
|
|
|
@ -15,7 +15,7 @@ unsigned int calculateNumberOfParameters(const unsigned int dimension, const uns
|
|||
for (unsigned int i = 2; i <= dimension; i++) {
|
||||
n_coef = n_coef*(orde + i)/(i - 1);
|
||||
}
|
||||
|
||||
|
||||
const unsigned int output = (unsigned int) n_coef;
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class Polynomial : public AttractorKernel {
|
||||
private:
|
||||
|
||||
|
||||
unsigned int orde;
|
||||
|
||||
void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0);
|
||||
|
|
Reference in a new issue