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 {
ptime now = microsec_clock::local_time();
time_duration td = now-t0;
return td.total_microseconds();
};
}
inline long getRandomSeed(int param = 0) {
using namespace boost::posix_time;
......@@ -338,7 +338,7 @@ namespace Helpers {
long value2 = random_seed_initial_value++;
return value0 + value1 + value2 + param;
};
}
} // end namespace Helpers
......
......@@ -527,24 +527,24 @@ namespace tools {
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));
for_each<I-1>::eval(vec1,vec2,f);
};
}
template<int I>
template<typename Container1, typename Container2, typename T, typename Tertiary_Functor>
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);
for_each<I-1>::accumulate(vec1,vec2,value,f);
};
}
template<typename Container1, typename Container2, typename Binary_Functor>
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));
};
}
template<typename Container1, typename Container2, typename T, typename Tertiary_Functor>
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);
};
}
} // namespace tools
......
......@@ -54,7 +54,7 @@ static double signedDist2D(const WorldVector<double> x, const WorldVector<double
}
return (norm_xy - (*radius)(alpha));
};
}
static double signedDist3D(const WorldVector<double> x, const WorldVector<double> midPoint,
BinaryAbstractFunction<double, double, double> *radius, double eps)
......@@ -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);
return (norm_xyz - (*radius)(alpha, beta));
};
}
// radius-functions
// ================
......@@ -92,8 +92,8 @@ static double signedDist3D(const WorldVector<double> x, const WorldVector<double
class CircleRadius : public AbstractFunction<double, double>
{
public:
CircleRadius(double radius_) : radius(radius_) {};
double operator()(const double& alpha) const { return radius; };
CircleRadius(double radius_) : radius(radius_) {}
double operator()(const double& alpha) const { return radius; }
protected:
double radius;
};
......@@ -101,8 +101,8 @@ protected:
class BallRadius : public BinaryAbstractFunction<double, double, double>
{
public:
BallRadius(double radius_) : radius(radius_) {};
double operator()(const double &alpha, const double &beta) const { return radius; };
BallRadius(double radius_) : radius(radius_) {}
double operator()(const double &alpha, const double &beta) const { return radius; }
protected:
double radius;
};
......@@ -112,15 +112,15 @@ class PerturbedCircleRadius : public AbstractFunction<double, double>
public:
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_) :
radius(radius_), strength(strength_), rotation(rotation_), period(period_) {};
radius(radius_), strength(strength_), rotation(rotation_), period(period_) {}
double operator()(const double &alpha) const
{
double result = 1.0 + strength * cos(period * alpha + rotation);
result *= radius;
return result;
};
}
protected:
......@@ -135,13 +135,13 @@ class PerturbedBallRadius : public BinaryAbstractFunction<double, double, double
public:
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 result = 1.0 + strength * (cos(period*alpha) + cos(period*beta) * cos(period*alpha));
result *= radius;
return result;
};
}
protected:
......@@ -155,13 +155,13 @@ class LemniskateRadius : public AbstractFunction<double, double>
{
public:
LemniskateRadius(const double breite_) : breite(breite_) {};
LemniskateRadius(const double breite_) : breite(breite_) {}
double operator()(const double &alpha) const
{
double result = 2*cos(2*alpha);
result = breite*result;
return result;
};
}
protected:
......@@ -173,12 +173,12 @@ class Lemniskate3D : public BinaryAbstractFunction<double, double, double>
{
public:
Lemniskate3D(const double breite_) : breite(breite_) {};
Lemniskate3D(const double breite_) : breite(breite_) {}
double operator()(const double &alpha, const double &beta) const
{
double result = 2*breite*cos(2*alpha)*sin(beta);
return result;
};
}
protected:
......@@ -190,12 +190,12 @@ class EllipseRadius : public AbstractFunction<double, double>
public:
EllipseRadius(const double a_, const double b_) :
a(a_), b(b_) {};
a(a_), b(b_) {}
double operator()(const double &alpha) const
{
double x=b*cos(alpha), y=a*sin(alpha);
return a*b / sqrt(x*x+y*y);
};
}
protected:
......@@ -207,7 +207,7 @@ class EllipsoidRadius : public BinaryAbstractFunction<double, double, double>
public:
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 sa = sin(alpha), sb = sin(beta);
......@@ -215,7 +215,7 @@ public:
double x = a*sa*cb, y = b*sa*sb, z = c*ca;
return sqrt(x*x+y*y+z*z);
};
}
protected:
......@@ -236,7 +236,7 @@ public:
x_temp= cos(theta)*x[0] - sin(theta)*x[1];
// x_temp[1]= sin(theta)*x[0] + cos(theta)*x[1];
return factor*(shift-x_temp);
};
}
private:
......@@ -255,7 +255,7 @@ public:
double operator()(const WorldVector<double>& x) const
{
return factor*(shift-x[component]);
};
}
private:
......@@ -270,7 +270,7 @@ public:
double operator()(const WorldVector<double>& x) const
{
return 1.0;
};
}
};
class Rectangle : public AbstractFunction<double, WorldVector<double> >
......@@ -296,7 +296,7 @@ public:
result = norm(corner);
}
return result;
};
}
void only2D() { TEST_EXIT(shift.getSize()==2)("Rectangle is defined only for 2 dimension!\n"); }
private:
......@@ -323,7 +323,7 @@ public:
}
result = sqrt(result)-radius;
return factor * result;
};
}
private:
......@@ -349,7 +349,7 @@ public:
}
result = sqrt(result)-radius;
return -result;
};
}
private:
......@@ -408,7 +408,7 @@ public:
result1 = sqrt(result1)-radius;
result2 = sqrt(result2)-radius;
return -std::min(result1,result2);
};
}
private:
......@@ -436,7 +436,7 @@ public:
result = signedDist3D(x, midPoint, &perturbedBall, 1.e-6);
}
return result;
};
}
private:
......@@ -491,7 +491,7 @@ public:
result = signedDist3D(x, midPoint, &lemniskate, 1.e-6);
}
return result;
};
}
private:
......@@ -520,7 +520,7 @@ public:
}
result = 1.0-sqrt(result);
return result;
};
}
private:
......@@ -545,7 +545,7 @@ public:
result = sqrt(result)-r2;
return result;
};
}
private:
......
......@@ -31,7 +31,7 @@ const WorldVector<T>& operator*=(WorldVector<T>& v1, const WorldVector<T>& v2)
*v1It *= *v2It;
return v1;
};
}
// x ~= y
template<typename T>
......@@ -41,6 +41,7 @@ public:
bool operator()(const T &x, const T &y) const { return sqrt((x-y)*(x-y))<tol; }
double tol;
};
template<typename T1, typename T2, int component>
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
return x.first<y.first;
}
};
template<typename T1, typename T2>
struct compare1 : public binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool>
{
......@@ -98,7 +100,7 @@ namespace vector_operations {
{
typedef std::size_t type;
type operator()(const Value[Size]) { return Size; }
};
};
/// size implementation for (2D and higher) arrays interpreted as matrices
template <typename Value, unsigned Rows, unsigned Cols>
......@@ -106,7 +108,7 @@ namespace vector_operations {
{
typedef std::size_t type;
type operator()(const Value[Rows][Cols]) { return Rows; }
};
};
/// size implementation for AMDiS WorldVectors
template <typename Value>
......@@ -114,7 +116,7 @@ namespace vector_operations {
{
typedef std::size_t type;
type operator()(const WorldVector<Value>& v) { return static_cast<size_t>(v.getSize()); }
};
};
/// size implementation for AMDiS WorldMatrices
template <typename Value>
......@@ -122,7 +124,7 @@ namespace vector_operations {
{
typedef std::size_t type;
type operator()(const WorldMatrix<Value>& v) { return static_cast<size_t>(v.getNumRows()); }
};
};
/// size implementation for arithmetic types (double, float, int, ...)
template <typename Value>
......@@ -144,7 +146,7 @@ namespace vector_operations {
{
typedef std::size_t type;
type operator()(const WorldMatrix<Value>& v) { return static_cast<size_t>(v.getNumCols()); }
};
};
//________________________________________________________________________________
......@@ -161,7 +163,7 @@ namespace vector_operations {
TEST_EXIT(Global::getGeo(WORLD) == r)
("WorldVectors can not be resized!\n");
}
};
};
/// change_dim implementation for STL vectors
template <typename Value>
......@@ -171,7 +173,7 @@ namespace vector_operations {
void operator()(std::vector<Value>& v, size_t r) {
v.resize(r);
}
};
};
/// change_dim implementation for MTL4 vectors
template <typename Value>
......@@ -341,11 +343,11 @@ namespace vector_operations {
for (size_t i = 0; i < num_rows(b); ++i)
value += sqr(b[i]);
return sqrt(value);
};
}
/// 2-norm for MTL4 vectors
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
template<typename Matrix>
......@@ -359,7 +361,7 @@ namespace vector_operations {
asum += abs(M[i][j]);
}
return static_cast<double>(asum);
};
}
/// 2-norm for vectors with eps-pertubation
......@@ -368,7 +370,7 @@ namespace vector_operations {
norm(const Vector &b, const double eps)
{
return std::max(static_cast<double>(norm(b)), eps);
};
}
/// trace of a matrix
template<typename Matrix>
......@@ -395,7 +397,7 @@ namespace vector_operations {
for (size_t i = 0; i < num_rows(v1); ++i)
result[i] = v1[i] * v2[i];
return result;
};
}
template<typename Matrix, typename Vector, typename ResultVector>
typename boost::enable_if< boost::mpl::and_< is_matrix<Matrix>, is_vector<Vector> >, ResultVector >::type
......@@ -410,7 +412,7 @@ namespace vector_operations {
result[i] += at(A,i,j) * x[j];
}
return result;
};
}
template<typename Matrix, typename Vector1, typename Vector2, typename ResultVector>
typename boost::enable_if< boost::mpl::and_< is_matrix<Matrix>, is_vector<Vector1>, is_vector<Vector2> >,
......@@ -427,7 +429,7 @@ namespace vector_operations {
result[i] += at(A,i,j) * x[j];
}
return result;
};
}
// copy v -> w
template<typename VectorIn, typename VectorOut>
......@@ -436,7 +438,7 @@ namespace vector_operations {
{
for (size_t i = 0; i < std::min(num_rows(v), num_rows(w)); i++)
w[i] = v[i];
};
}
template<class MatrixIn, class MatrixOut>
typename boost::enable_if< boost::mpl::and_< is_matrix<MatrixIn>, is_matrix<MatrixOut> >, void >::type
......@@ -448,7 +450,7 @@ namespace vector_operations {
at(m,i,j) = at(m_in,i,j);
}
}
};
}
template<class MatrixIn, class MatrixOut>
typename boost::enable_if< boost::mpl::and_< is_matrix<MatrixIn>, is_matrix<MatrixOut> >, void >::type
......@@ -468,7 +470,7 @@ namespace vector_operations {
v3[i] = v1[i];
for (size_t j = 0; j < num_rows(v2); j++)
v3[j + num_rows(v1)] = v2[j];
};
}
template<typename Vector>
void getMin(const Vector &v, typename ValueType<Vector>::type &minVal, size_t &minIdx)
......@@ -484,7 +486,7 @@ namespace vector_operations {
minIdx = i;
}
}
};
}
template<typename Vector>
void getMax(const Vector &v, typename ValueType<Vector>::type &maxVal, size_t &maxIdx)
......@@ -500,7 +502,7 @@ namespace vector_operations {
maxIdx = i;
}
}
};
}
template<typename Vector>
typename ValueType<Vector>::type
......@@ -510,7 +512,7 @@ namespace vector_operations {
size_t minIdx;
getMin(vec, minVal, minIdx);
return minVal;
};
}
template<typename Vector>
typename ValueType<Vector>::type
......@@ -520,7 +522,7 @@ namespace vector_operations {
size_t maxIdx;
getMax(vec, maxVal, maxIdx);
return maxVal;
};
}
template<typename Vector>
typename ValueType<Vector>::type
......@@ -536,7 +538,7 @@ namespace vector_operations {
}
}
return minVal;
};
}
template<typename Vector>
typename ValueType<Vector>::type
......@@ -552,7 +554,7 @@ namespace vector_operations {
}
}
return maxVal;
};
}
template<typename Vector>
typename ValueType<Vector>::type
......@@ -567,7 +569,7 @@ namespace vector_operations {
value += v[i];
}
return value;
};
}
template<typename Vector>
inline typename ValueType<Vector>::type
......@@ -575,13 +577,13 @@ namespace vector_operations {
{
double N = static_cast<double>(num_rows(v));
return sum(v) * (1.0 / N);
};
}
template<typename Vector>
void getMean(const Vector &v, typename ValueType<Vector>::type &meanValue)
{
meanValue = mean(v);
};
}
template<typename T1, typename T2, typename Compare>
void sort(std::vector<T1> &vec1, std::vector<T2> &vec2, Compare &comp)
......@@ -600,13 +602,13 @@ namespace vector_operations {
vec1[i] = order[i].first;
vec2[i] = order[i].second;
}
};
}
template<typename T1, typename T2, typename Compare>
void sort(std::vector<std::pair<T1,T2> > &vec, Compare &comp)
{
std::sort(vec.begin(), vec.end(), comp);
};
}
inline void unique(std::vector<WorldVector<double> > &vec, double tol, std::vector<unsigned> &ind)
{
......@@ -621,7 +623,7 @@ namespace vector_operations {
if(!inNew) {vec[newVec]=vec[i]; newVec++; ind.push_back(i);}
}
vec.erase(vec.begin()+newVec,vec.end());
};
}
template<typename T1, typename T2>
void unique(std::vector<std::pair<T1,T2> > &vec, double tol, int uniqueBy=1)
......@@ -637,7 +639,7 @@ namespace vector_operations {
// if(!inNew) {vec[newVec]=vec[i]; newVec++;}
// }
// vec.erase(vec.begin()+newVec,vec.end());
};
}
template<typename T>
inline void filter(std::vector<T> &x, const std::vector<bool> &filter)
......@@ -652,7 +654,7 @@ namespace vector_operations {
}
}
x.erase(x.begin()+j,x.end());
};
}
template<typename T>
void filter(std::vector<T> &x, const std::vector<int> &filter)
......@@ -661,8 +663,8 @@ namespace vector_operations {
for (size_t i = 0; i < num_rows(filter); ++i)
x_[i] = x[filter[i]];
swap(x, x_);
};
}
template<typename Vector1, typename Vector2>
typename ProductType<typename ValueType<Vector1>::type, typename ValueType<Vector2>::type>::type
dot(const Vector1 &vec1, const Vector2 &vec2)
......@@ -677,7 +679,7 @@ namespace vector_operations {
value += vec1[i] * vec2[i];
}
return value;
};
}
}
#endif // VECTOR_OPERATIONS_H
......@@ -208,7 +208,7 @@ protected:
void setDefaultValue(T& value0_)
{
value0 = value0_;
};
}
DOFVector<T> *vector;
T value0;
......@@ -411,28 +411,28 @@ inline T evalAtPoint(const DOFVector<T> &obj, WorldVector<double> &p, ElInfo* ol
}
delete elInfo;
return value;
};
}
// DOFView can be accessed by own method
template<typename T >
inline T evalAtPoint(const DOFView<T> &obj, WorldVector<double> &p, ElInfo* elInfo = NULL)
{
return obj.evalAtPoint(p, elInfo);
};
}
// intrinsic types can return values directly
template<typename T>
inline T evalAtPoint(T &obj, WorldVector<double> &p, ElInfo* elInfo = NULL)
{
return obj;
};
}
// AbstractFunctions with argument-type = WorldVector can be accessed directly
template<typename T>
inline T evalAtPoint(AbstractFunction<T, WorldVector<double> > &obj, WorldVector<double> &p, ElInfo* elInfo = NULL)
{
return obj(p);
};
}
/// transformDOF by coords (independent of mesh and feSpace)
/// ________________________________________________________________________________________________
......@@ -450,7 +450,7 @@ inline void interpol_coords(Vector &vec, DOFVector<TOut> &result)
for (it_coords.reset(), it_result.reset(); !it_coords.end(); ++it_coords, ++it_result) {
*it_result = evalAtPoint<T>(vec, *it_coords);
}
};
}
// result = op(vec)
template<typename TOut, typename Vector>
......@@ -468,7 +468,7 @@ inline void transformDOF_coords(Vector &vec,