Commit 5e57cec5 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

some corrections in the extensions

parent acf27767
...@@ -326,7 +326,7 @@ namespace Helpers { ...@@ -326,7 +326,7 @@ namespace Helpers {
ptime now = microsec_clock::local_time(); ptime now = microsec_clock::local_time();
time_duration td = now-t0; time_duration td = now-t0;
return td.total_microseconds(); return td.total_microseconds();
}; }
inline long getRandomSeed(int param = 0) { inline long getRandomSeed(int param = 0) {
using namespace boost::posix_time; using namespace boost::posix_time;
...@@ -338,7 +338,7 @@ namespace Helpers { ...@@ -338,7 +338,7 @@ namespace Helpers {
long value2 = random_seed_initial_value++; long value2 = random_seed_initial_value++;
return value0 + value1 + value2 + param; return value0 + value1 + value2 + param;
}; }
} // end namespace Helpers } // end namespace Helpers
......
...@@ -527,24 +527,24 @@ namespace tools { ...@@ -527,24 +527,24 @@ namespace tools {
void for_each<I>::eval(Container1& vec1, Container2& vec2, Binary_Functor& f) { void for_each<I>::eval(Container1& vec1, Container2& vec2, Binary_Functor& f) {
f(boost::fusion::at_c<I>(vec1), boost::fusion::at_c<I>(vec2)); f(boost::fusion::at_c<I>(vec1), boost::fusion::at_c<I>(vec2));
for_each<I-1>::eval(vec1,vec2,f); for_each<I-1>::eval(vec1,vec2,f);
}; }
template<int I> template<int I>
template<typename Container1, typename Container2, typename T, typename Tertiary_Functor> template<typename Container1, typename Container2, typename T, typename Tertiary_Functor>
void for_each<I>::accumulate(Container1& vec1, Container2& vec2, T& value, Tertiary_Functor& f) { void for_each<I>::accumulate(Container1& vec1, Container2& vec2, T& value, Tertiary_Functor& f) {
f(boost::fusion::at_c<I>(vec1), boost::fusion::at_c<I>(vec2), value); f(boost::fusion::at_c<I>(vec1), boost::fusion::at_c<I>(vec2), value);
for_each<I-1>::accumulate(vec1,vec2,value,f); for_each<I-1>::accumulate(vec1,vec2,value,f);
}; }
template<typename Container1, typename Container2, typename Binary_Functor> template<typename Container1, typename Container2, typename Binary_Functor>
void for_each<0>::eval(Container1& vec1, Container2& vec2, Binary_Functor& f) { void for_each<0>::eval(Container1& vec1, Container2& vec2, Binary_Functor& f) {
f(boost::fusion::at_c<0>(vec1), boost::fusion::at_c<0>(vec2)); f(boost::fusion::at_c<0>(vec1), boost::fusion::at_c<0>(vec2));
}; }
template<typename Container1, typename Container2, typename T, typename Tertiary_Functor> template<typename Container1, typename Container2, typename T, typename Tertiary_Functor>
void for_each<0>::accumulate(Container1& vec1, Container2& vec2, T& value, Tertiary_Functor& f) { void for_each<0>::accumulate(Container1& vec1, Container2& vec2, T& value, Tertiary_Functor& f) {
f(boost::fusion::at_c<0>(vec1), boost::fusion::at_c<0>(vec2),value); f(boost::fusion::at_c<0>(vec1), boost::fusion::at_c<0>(vec2),value);
}; }
} // namespace tools } // namespace tools
......
...@@ -54,7 +54,7 @@ static double signedDist2D(const WorldVector<double> x, const WorldVector<double ...@@ -54,7 +54,7 @@ static double signedDist2D(const WorldVector<double> x, const WorldVector<double
} }
return (norm_xy - (*radius)(alpha)); return (norm_xy - (*radius)(alpha));
}; }
static double signedDist3D(const WorldVector<double> x, const WorldVector<double> midPoint, static double signedDist3D(const WorldVector<double> x, const WorldVector<double> midPoint,
BinaryAbstractFunction<double, double, double> *radius, double eps) BinaryAbstractFunction<double, double, double> *radius, double eps)
...@@ -84,7 +84,7 @@ static double signedDist3D(const WorldVector<double> x, const WorldVector<double ...@@ -84,7 +84,7 @@ static double signedDist3D(const WorldVector<double> x, const WorldVector<double
beta = 0.5*m_pi - atan(x_trans[2]/norm_xy); beta = 0.5*m_pi - atan(x_trans[2]/norm_xy);
return (norm_xyz - (*radius)(alpha, beta)); return (norm_xyz - (*radius)(alpha, beta));
}; }
// radius-functions // radius-functions
// ================ // ================
...@@ -92,8 +92,8 @@ static double signedDist3D(const WorldVector<double> x, const WorldVector<double ...@@ -92,8 +92,8 @@ static double signedDist3D(const WorldVector<double> x, const WorldVector<double
class CircleRadius : public AbstractFunction<double, double> class CircleRadius : public AbstractFunction<double, double>
{ {
public: public:
CircleRadius(double radius_) : radius(radius_) {}; CircleRadius(double radius_) : radius(radius_) {}
double operator()(const double& alpha) const { return radius; }; double operator()(const double& alpha) const { return radius; }
protected: protected:
double radius; double radius;
}; };
...@@ -101,8 +101,8 @@ protected: ...@@ -101,8 +101,8 @@ protected:
class BallRadius : public BinaryAbstractFunction<double, double, double> class BallRadius : public BinaryAbstractFunction<double, double, double>
{ {
public: public:
BallRadius(double radius_) : radius(radius_) {}; BallRadius(double radius_) : radius(radius_) {}
double operator()(const double &alpha, const double &beta) const { return radius; }; double operator()(const double &alpha, const double &beta) const { return radius; }
protected: protected:
double radius; double radius;
}; };
...@@ -112,15 +112,15 @@ class PerturbedCircleRadius : public AbstractFunction<double, double> ...@@ -112,15 +112,15 @@ class PerturbedCircleRadius : public AbstractFunction<double, double>
public: public:
PerturbedCircleRadius(const double radius_, const double strength_, const int period_) : PerturbedCircleRadius(const double radius_, const double strength_, const int period_) :
radius(radius_), strength(strength_), rotation(0.0), period(period_) {}; radius(radius_), strength(strength_), rotation(0.0), period(period_) {}
PerturbedCircleRadius(const double radius_, const double strength_, const int period_, const double rotation_) : PerturbedCircleRadius(const double radius_, const double strength_, const int period_, const double rotation_) :
radius(radius_), strength(strength_), rotation(rotation_), period(period_) {}; radius(radius_), strength(strength_), rotation(rotation_), period(period_) {}
double operator()(const double &alpha) const double operator()(const double &alpha) const
{ {
double result = 1.0 + strength * cos(period * alpha + rotation); double result = 1.0 + strength * cos(period * alpha + rotation);
result *= radius; result *= radius;
return result; return result;
}; }
protected: protected:
...@@ -135,13 +135,13 @@ class PerturbedBallRadius : public BinaryAbstractFunction<double, double, double ...@@ -135,13 +135,13 @@ class PerturbedBallRadius : public BinaryAbstractFunction<double, double, double
public: public:
PerturbedBallRadius(const double radius_, const double strength_, const int period_) : PerturbedBallRadius(const double radius_, const double strength_, const int period_) :
radius(radius_), strength(strength_), period(period_) {}; radius(radius_), strength(strength_), period(period_) {}
double operator()(const double &alpha, const double &beta) const double operator()(const double &alpha, const double &beta) const
{ {
double result = 1.0 + strength * (cos(period*alpha) + cos(period*beta) * cos(period*alpha)); double result = 1.0 + strength * (cos(period*alpha) + cos(period*beta) * cos(period*alpha));
result *= radius; result *= radius;
return result; return result;
}; }
protected: protected:
...@@ -155,13 +155,13 @@ class LemniskateRadius : public AbstractFunction<double, double> ...@@ -155,13 +155,13 @@ class LemniskateRadius : public AbstractFunction<double, double>
{ {
public: public:
LemniskateRadius(const double breite_) : breite(breite_) {}; LemniskateRadius(const double breite_) : breite(breite_) {}
double operator()(const double &alpha) const double operator()(const double &alpha) const
{ {
double result = 2*cos(2*alpha); double result = 2*cos(2*alpha);
result = breite*result; result = breite*result;
return result; return result;
}; }
protected: protected:
...@@ -173,12 +173,12 @@ class Lemniskate3D : public BinaryAbstractFunction<double, double, double> ...@@ -173,12 +173,12 @@ class Lemniskate3D : public BinaryAbstractFunction<double, double, double>
{ {
public: public:
Lemniskate3D(const double breite_) : breite(breite_) {}; Lemniskate3D(const double breite_) : breite(breite_) {}
double operator()(const double &alpha, const double &beta) const double operator()(const double &alpha, const double &beta) const
{ {
double result = 2*breite*cos(2*alpha)*sin(beta); double result = 2*breite*cos(2*alpha)*sin(beta);
return result; return result;
}; }
protected: protected:
...@@ -190,12 +190,12 @@ class EllipseRadius : public AbstractFunction<double, double> ...@@ -190,12 +190,12 @@ class EllipseRadius : public AbstractFunction<double, double>
public: public:
EllipseRadius(const double a_, const double b_) : EllipseRadius(const double a_, const double b_) :
a(a_), b(b_) {}; a(a_), b(b_) {}
double operator()(const double &alpha) const double operator()(const double &alpha) const
{ {
double x=b*cos(alpha), y=a*sin(alpha); double x=b*cos(alpha), y=a*sin(alpha);
return a*b / sqrt(x*x+y*y); return a*b / sqrt(x*x+y*y);
}; }
protected: protected:
...@@ -207,7 +207,7 @@ class EllipsoidRadius : public BinaryAbstractFunction<double, double, double> ...@@ -207,7 +207,7 @@ class EllipsoidRadius : public BinaryAbstractFunction<double, double, double>
public: public:
EllipsoidRadius(const double a_, const double b_, const double c_) : EllipsoidRadius(const double a_, const double b_, const double c_) :
a(a_), b(b_), c(c_) {}; a(a_), b(b_), c(c_) {}
double operator()(const double &alpha, const double &beta) const double operator()(const double &alpha, const double &beta) const
{ {
double sa = sin(alpha), sb = sin(beta); double sa = sin(alpha), sb = sin(beta);
...@@ -215,7 +215,7 @@ public: ...@@ -215,7 +215,7 @@ public:
double x = a*sa*cb, y = b*sa*sb, z = c*ca; double x = a*sa*cb, y = b*sa*sb, z = c*ca;
return sqrt(x*x+y*y+z*z); return sqrt(x*x+y*y+z*z);
}; }
protected: protected:
...@@ -236,7 +236,7 @@ public: ...@@ -236,7 +236,7 @@ public:
x_temp= cos(theta)*x[0] - sin(theta)*x[1]; x_temp= cos(theta)*x[0] - sin(theta)*x[1];
// x_temp[1]= sin(theta)*x[0] + cos(theta)*x[1]; // x_temp[1]= sin(theta)*x[0] + cos(theta)*x[1];
return factor*(shift-x_temp); return factor*(shift-x_temp);
}; }
private: private:
...@@ -255,7 +255,7 @@ public: ...@@ -255,7 +255,7 @@ public:
double operator()(const WorldVector<double>& x) const double operator()(const WorldVector<double>& x) const
{ {
return factor*(shift-x[component]); return factor*(shift-x[component]);
}; }
private: private:
...@@ -270,7 +270,7 @@ public: ...@@ -270,7 +270,7 @@ public:
double operator()(const WorldVector<double>& x) const double operator()(const WorldVector<double>& x) const
{ {
return 1.0; return 1.0;
}; }
}; };
class Rectangle : public AbstractFunction<double, WorldVector<double> > class Rectangle : public AbstractFunction<double, WorldVector<double> >
...@@ -296,7 +296,7 @@ public: ...@@ -296,7 +296,7 @@ public:
result = norm(corner); result = norm(corner);
} }
return result; return result;
}; }
void only2D() { TEST_EXIT(shift.getSize()==2)("Rectangle is defined only for 2 dimension!\n"); } void only2D() { TEST_EXIT(shift.getSize()==2)("Rectangle is defined only for 2 dimension!\n"); }
private: private:
...@@ -323,7 +323,7 @@ public: ...@@ -323,7 +323,7 @@ public:
} }
result = sqrt(result)-radius; result = sqrt(result)-radius;
return factor * result; return factor * result;
}; }
private: private:
...@@ -349,7 +349,7 @@ public: ...@@ -349,7 +349,7 @@ public:
} }
result = sqrt(result)-radius; result = sqrt(result)-radius;
return -result; return -result;
}; }
private: private:
...@@ -408,7 +408,7 @@ public: ...@@ -408,7 +408,7 @@ public:
result1 = sqrt(result1)-radius; result1 = sqrt(result1)-radius;
result2 = sqrt(result2)-radius; result2 = sqrt(result2)-radius;
return -std::min(result1,result2); return -std::min(result1,result2);
}; }
private: private:
...@@ -436,7 +436,7 @@ public: ...@@ -436,7 +436,7 @@ public:
result = signedDist3D(x, midPoint, &perturbedBall, 1.e-6); result = signedDist3D(x, midPoint, &perturbedBall, 1.e-6);
} }
return result; return result;
}; }
private: private:
...@@ -491,7 +491,7 @@ public: ...@@ -491,7 +491,7 @@ public:
result = signedDist3D(x, midPoint, &lemniskate, 1.e-6); result = signedDist3D(x, midPoint, &lemniskate, 1.e-6);
} }
return result; return result;
}; }
private: private:
...@@ -520,7 +520,7 @@ public: ...@@ -520,7 +520,7 @@ public:
} }
result = 1.0-sqrt(result); result = 1.0-sqrt(result);
return result; return result;
}; }
private: private:
...@@ -545,7 +545,7 @@ public: ...@@ -545,7 +545,7 @@ public:
result = sqrt(result)-r2; result = sqrt(result)-r2;
return result; return result;
}; }
private: private:
......
...@@ -31,7 +31,7 @@ const WorldVector<T>& operator*=(WorldVector<T>& v1, const WorldVector<T>& v2) ...@@ -31,7 +31,7 @@ const WorldVector<T>& operator*=(WorldVector<T>& v1, const WorldVector<T>& v2)
*v1It *= *v2It; *v1It *= *v2It;
return v1; return v1;
}; }
// x ~= y // x ~= y
template<typename T> template<typename T>
...@@ -41,6 +41,7 @@ public: ...@@ -41,6 +41,7 @@ public:
bool operator()(const T &x, const T &y) const { return sqrt((x-y)*(x-y))<tol; } bool operator()(const T &x, const T &y) const { return sqrt((x-y)*(x-y))<tol; }
double tol; double tol;
}; };
template<typename T1, typename T2, int component> template<typename T1, typename T2, int component>
struct comparePair : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool> struct comparePair : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool>
{ {
...@@ -58,6 +59,7 @@ struct compare0 : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, b ...@@ -58,6 +59,7 @@ struct compare0 : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, b
return x.first<y.first; return x.first<y.first;
} }
}; };
template<typename T1, typename T2> template<typename T1, typename T2>
struct compare1 : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool> struct compare1 : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool>
{ {
...@@ -98,7 +100,7 @@ namespace vector_operations { ...@@ -98,7 +100,7 @@ namespace vector_operations {
{ {
typedef std::size_t type; typedef std::size_t type;
type operator()(const Value[Size]) { return Size; } type operator()(const Value[Size]) { return Size; }
}; };
/// size implementation for (2D and higher) arrays interpreted as matrices /// size implementation for (2D and higher) arrays interpreted as matrices
template <typename Value, unsigned Rows, unsigned Cols> template <typename Value, unsigned Rows, unsigned Cols>
...@@ -106,7 +108,7 @@ namespace vector_operations { ...@@ -106,7 +108,7 @@ namespace vector_operations {
{ {
typedef std::size_t type; typedef std::size_t type;
type operator()(const Value[Rows][Cols]) { return Rows; } type operator()(const Value[Rows][Cols]) { return Rows; }
}; };
/// size implementation for AMDiS WorldVectors /// size implementation for AMDiS WorldVectors
template <typename Value> template <typename Value>
...@@ -114,7 +116,7 @@ namespace vector_operations { ...@@ -114,7 +116,7 @@ namespace vector_operations {
{ {
typedef std::size_t type; typedef std::size_t type;
type operator()(const WorldVector<Value>& v) { return static_cast<size_t>(v.getSize()); } type operator()(const WorldVector<Value>& v) { return static_cast<size_t>(v.getSize()); }
}; };
/// size implementation for AMDiS WorldMatrices /// size implementation for AMDiS WorldMatrices
template <typename Value> template <typename Value>
...@@ -122,7 +124,7 @@ namespace vector_operations { ...@@ -122,7 +124,7 @@ namespace vector_operations {
{ {
typedef std::size_t type; typedef std::size_t type;
type operator()(const WorldMatrix<Value>& v) { return static_cast<size_t>(v.getNumRows()); } type operator()(const WorldMatrix<Value>& v) { return static_cast<size_t>(v.getNumRows()); }
}; };
/// size implementation for arithmetic types (double, float, int, ...) /// size implementation for arithmetic types (double, float, int, ...)
template <typename Value> template <typename Value>
...@@ -144,7 +146,7 @@ namespace vector_operations { ...@@ -144,7 +146,7 @@ namespace vector_operations {
{ {
typedef std::size_t type; typedef std::size_t type;
type operator()(const WorldMatrix<Value>& v) { return static_cast<size_t>(v.getNumCols()); } type operator()(const WorldMatrix<Value>& v) { return static_cast<size_t>(v.getNumCols()); }
}; };
//________________________________________________________________________________ //________________________________________________________________________________
...@@ -161,7 +163,7 @@ namespace vector_operations { ...@@ -161,7 +163,7 @@ namespace vector_operations {
TEST_EXIT(Global::getGeo(WORLD) == r) TEST_EXIT(Global::getGeo(WORLD) == r)
("WorldVectors can not be resized!\n"); ("WorldVectors can not be resized!\n");
} }
}; };
/// change_dim implementation for STL vectors /// change_dim implementation for STL vectors
template <typename Value> template <typename Value>
...@@ -171,7 +173,7 @@ namespace vector_operations { ...@@ -171,7 +173,7 @@ namespace vector_operations {
void operator()(std::vector<Value>& v, size_t r) { void operator()(std::vector<Value>& v, size_t r) {
v.resize(r); v.resize(r);
} }
}; };
/// change_dim implementation for MTL4 vectors /// change_dim implementation for MTL4 vectors
template <typename Value> template <typename Value>
...@@ -341,11 +343,11 @@ namespace vector_operations { ...@@ -341,11 +343,11 @@ namespace vector_operations {
for (size_t i = 0; i < num_rows(b); ++i) for (size_t i = 0; i < num_rows(b); ++i)
value += sqr(b[i]); value += sqr(b[i]);
return sqrt(value); return sqrt(value);
}; }
/// 2-norm for MTL4 vectors /// 2-norm for MTL4 vectors
template<typename T> template<typename T>
T norm(const mtl::dense_vector<T> &b) { return two_norm(b); }; T norm(const mtl::dense_vector<T> &b) { return two_norm(b); }
/// 1-norm for matrices /// 1-norm for matrices
template<typename Matrix> template<typename Matrix>
...@@ -359,7 +361,7 @@ namespace vector_operations { ...@@ -359,7 +361,7 @@ namespace vector_operations {
asum += abs(M[i][j]); asum += abs(M[i][j]);
} }
return static_cast<double>(asum); return static_cast<double>(asum);
}; }
/// 2-norm for vectors with eps-pertubation /// 2-norm for vectors with eps-pertubation
...@@ -368,7 +370,7 @@ namespace vector_operations { ...@@ -368,7 +370,7 @@ namespace vector_operations {
norm(const Vector &b, const double eps) norm(const Vector &b, const double eps)
{ {
return std::max(static_cast<double>(norm(b)), eps); return std::max(static_cast<double>(norm(b)), eps);
}; }
/// trace of a matrix /// trace of a matrix
template<typename Matrix> template<typename Matrix>
...@@ -395,7 +397,7 @@ namespace vector_operations { ...@@ -395,7 +397,7 @@ namespace vector_operations {
for (size_t i = 0; i < num_rows(v1); ++i) for (size_t i = 0; i < num_rows(v1); ++i)
result[i] = v1[i] * v2[i]; result[i] = v1[i] * v2[i];
return result; return result;
}; }
template<typename Matrix, typename Vector, typename ResultVector> template<typename Matrix, typename Vector, typename ResultVector>
typename boost::enable_if< boost::mpl::and_< is_matrix<Matrix>, is_vector<Vector> >, ResultVector >::type