Commit ed16a716 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

several changes concerning quadrature degrees for operators

parent 7b9f8d5a
......@@ -28,7 +28,7 @@ namespace AMDiS {
template<typename T>
struct Id : public AbstractFunction<T,T>
{
Id() : AbstractFunction<T,T>(1) {}
Id(int degree = 1) : AbstractFunction<T,T>(degree) {}
T operator()(const T &v) const { return v; }
};
......@@ -44,7 +44,7 @@ private:
template<typename T=double>
struct Factor : public AbstractFunction<T,T>
{
Factor(double fac_) : AbstractFunction<T,T>(1), fac(fac_) {}
Factor(double fac_, int degree = 1) : AbstractFunction<T,T>(degree), fac(fac_) {}
T operator()(const T& x) const { return fac*x; }
private:
double fac;
......@@ -53,14 +53,14 @@ private:
template<typename T=double>
struct Add : public BinaryAbstractFunction<T,T,T>
{
Add() : BinaryAbstractFunction<T,T,T>(1) {}
Add(int degree = 1) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return v1+v2; }
};
template<typename T=double>
struct AddFactor : public BinaryAbstractFunction<T,T,T>
{
AddFactor(double factor_ = 1.0) : BinaryAbstractFunction<T,T,T>(1), factor(factor_) {}
AddFactor(double factor_ = 1.0, int degree = 1) : BinaryAbstractFunction<T,T,T>(degree), factor(factor_) {}
T operator()(const T &v1, const T &v2) const { return v1 + factor*v2; }
private:
double factor;
......@@ -69,14 +69,14 @@ private:
template<typename T=double>
struct Subtract : public BinaryAbstractFunction<T,T,T>
{
Subtract() : BinaryAbstractFunction<T,T,T>(1) {}
Subtract(int degree = 1) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return v1-v2; }
};
template<typename T=double>
struct AddScal : public AbstractFunction<T,T>
{
AddScal(T scal_) : AbstractFunction<T,T>(1), scal(scal_) {}
AddScal(T scal_, int degree = 1) : AbstractFunction<T,T>(degree), scal(scal_) {}
T operator()(const T &v) const { return v+scal; }
private:
T scal;
......@@ -85,21 +85,21 @@ private:
template<typename T>
struct Mult : public BinaryAbstractFunction<T,T,T>
{
Mult() : BinaryAbstractFunction<T,T,T>(2) {}
Mult(int degree = 2) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return v1*v2; }
};
template<typename T1, typename T2, typename T3>
struct Mult2 : public BinaryAbstractFunction<T1,T2,T3>
{
Mult2() : BinaryAbstractFunction<T1,T2,T3>(2) {}
Mult2(int degree = 2) : BinaryAbstractFunction<T1,T2,T3>(degree) {}
T1 operator()(const T2 &v1, const T3 &v2) const { return v1*v2; }
};
template<typename T>
struct MultScal : public BinaryAbstractFunction<T,T,T>
{
MultScal(T scal_) : BinaryAbstractFunction<T,T,T>(2), scal(scal_) {}
MultScal(T scal_, int degree = 2) : BinaryAbstractFunction<T,T,T>(degree), scal(scal_) {}
T operator()(const T &v1, const T &v2) const { return v1*v2*scal; }
private:
T scal;
......@@ -108,28 +108,28 @@ private:
template<typename T>
struct Max : public BinaryAbstractFunction<T,T,T>
{
Max() : BinaryAbstractFunction<T,T,T>(1) {}
Max(int degree = 1) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return std::max(v1,v2); }
};
template<typename T>
struct Min : public BinaryAbstractFunction<T,T,T>
{
Min() : BinaryAbstractFunction<T,T,T>(1) {}
Min(int degree = 1) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return std::min(v1,v2); }
};
template<typename T>
struct Diff : public BinaryAbstractFunction<T,T,T>
{
Diff() : BinaryAbstractFunction<T,T,T>(1) {}
Diff(int degree = 1) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return abs(v1-v2); }
};
template<typename T=double>
struct Abs : public AbstractFunction<T,T>
{
Abs() : AbstractFunction<T,T>(1) {}
Abs(int degree = 1) : AbstractFunction<T,T>(degree) {}
T operator()(const T &v) const { return abs(v); }
};
......@@ -143,13 +143,14 @@ struct Signum : public AbstractFunction<T,T>
template<typename T=double>
struct Sqr : public AbstractFunction<T,T>
{
Sqr() : AbstractFunction<T, T>(2) {}
Sqr(int degree = 2) : AbstractFunction<T, T>(degree) {}
T operator()(const T &v) const { return sqr(v); }
};
template<typename T=double>
struct Sqrt : public AbstractFunction<T,T>
{
Sqrt(int degree = 4) : AbstractFunction<T,T>(degree) {}
T operator()(const T &v) const { return sqrt(v); }
};
......@@ -177,7 +178,7 @@ namespace detail {
template<int p, typename T=double>
struct Pow : public AbstractFunction<T,T>
{
Pow(double factor_=1.0) : AbstractFunction<T,T>(p), factor(factor_) {}
Pow(double factor_=1.0, int degree = p) : AbstractFunction<T,T>(degree), factor(factor_) {}
T operator()(const T &v) const { return factor * detail::Pow<p>::eval(v); }
private:
double factor;
......@@ -186,42 +187,42 @@ private:
template<typename T1, typename T2 = ProductType<T1, T1> >
struct Norm2 : public AbstractFunction<T1, T2>
{
Norm2() : AbstractFunction<T1, T2>(2) {}
Norm2(int degree = 4) : AbstractFunction<T1, T2>(degree) {}
T1 operator()(const T2 &v) const { return sqrt(v*v); }
};
template<typename T1, typename T2>
struct Norm2Sqr : public AbstractFunction<T1, T2>
{
Norm2Sqr() : AbstractFunction<T1, T2>(2) {}
Norm2Sqr(int degree = 2) : AbstractFunction<T1, T2>(degree) {}
T1 operator()(const T2 &v) const { return v*v; }
};
template<typename T>
struct Norm2_comp2 : public BinaryAbstractFunction<T,T,T>
{
Norm2_comp2() : BinaryAbstractFunction<T,T,T>(2) {}
Norm2_comp2(int degree = 4) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return sqrt(sqr(v1)+sqr(v2)); }
};
template<typename T>
struct Norm2Sqr_comp2 : public BinaryAbstractFunction<T,T,T>
{
Norm2Sqr_comp2() : BinaryAbstractFunction<T,T,T>(2) {}
Norm2Sqr_comp2(int degree = 2) : BinaryAbstractFunction<T,T,T>(degree) {}
T operator()(const T &v1, const T &v2) const { return sqr(v1)+sqr(v2); }
};
template<typename T>
struct Norm2_comp3 : public TertiaryAbstractFunction<T,T,T,T>
{
Norm2_comp3() : TertiaryAbstractFunction<T,T,T,T>(2) {}
Norm2_comp3(int degree = 4) : TertiaryAbstractFunction<T,T,T,T>(degree) {}
T operator()(const T &v1, const T &v2, const T &v3) const { return sqrt(sqr(v1)+sqr(v2)+sqr(v3)); }
};
template<typename T>
struct Norm2Sqr_comp3 : public TertiaryAbstractFunction<T,T,T,T>
{
Norm2Sqr_comp3() : TertiaryAbstractFunction<T,T,T,T>(2) {}
Norm2Sqr_comp3(int degree = 2) : TertiaryAbstractFunction<T,T,T,T>(degree) {}
T operator()(const T &v1, const T &v2, const T &v3) const { return sqr(v1)+sqr(v2)+sqr(v3); }
};
......@@ -267,7 +268,7 @@ struct Vec3WorldVec : public TertiaryAbstractFunction<WorldVector<T>,T,T,T>
template<int c, typename T=double>
struct Component : public AbstractFunction<T, WorldVector<T> >
{
Component() : AbstractFunction<T, WorldVector<T> >(1) {}
Component(int degree = 1) : AbstractFunction<T, WorldVector<T> >(degree) {}
T operator()(const WorldVector<T> &x) const {
return x[c];
}
......
......@@ -27,9 +27,10 @@ namespace AMDiS {
// ========== VecAtQP_ZOT ==========
VecAtQP_ZOT::VecAtQP_ZOT(DOFVectorBase<double> *dv,
AbstractFunction<double, double> *af)
AbstractFunction<double, double> *af,
double factor_)
: ZeroOrderTerm(af ? af->getDegree() : dv->getFeSpace()->getBasisFcts()->getDegree()),
vec(dv), f(af)
vec(dv), f(af), factor(factor_)
{
FUNCNAME("VecAtQP_ZOT::VecAtQP_ZOT()");
......@@ -60,10 +61,10 @@ namespace AMDiS {
{
if (f) {
for (int iq = 0; iq < nPoints; iq++)
C[iq] += (*f)(vecAtQPs[iq]);
C[iq] += (*f)(vecAtQPs[iq]) * factor;
} else {
for (int iq = 0; iq < nPoints; iq++)
C[iq] += vecAtQPs[iq];
C[iq] += vecAtQPs[iq] * factor;
}
}
......@@ -75,12 +76,13 @@ namespace AMDiS {
mtl::dense_vector<double>& result,
double fac)
{
double fac_ = fac * factor;
if (f) {
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * (*f)(vecAtQPs[iq]) * uhAtQP[iq];
result[iq] += fac_ * (*f)(vecAtQPs[iq]) * uhAtQP[iq];
} else {
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * vecAtQPs[iq] * uhAtQP[iq];
result[iq] += fac_ * vecAtQPs[iq] * uhAtQP[iq];
}
}
......@@ -90,9 +92,11 @@ namespace AMDiS {
MultVecAtQP_ZOT::MultVecAtQP_ZOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2,
AbstractFunction<double, double> *af1,
AbstractFunction<double, double> *af2)
AbstractFunction<double, double> *af2,
double factor_
)
: ZeroOrderTerm(af1->getDegree() + af2->getDegree()),
vec1(dv1), vec2(dv2), f1(af1), f2(af2)
vec1(dv1), vec2(dv2), f1(af1), f2(af2), factor(factor_)
{
TEST_EXIT(dv1)("No first vector!\n");
TEST_EXIT(dv2)("No second vector!\n");
......@@ -114,7 +118,7 @@ namespace AMDiS {
void MultVecAtQP_ZOT::getC(const ElInfo *, int nPoints, ElementVector& C)
{
for (int iq = 0; iq < nPoints; iq++)
C[iq] += (*f1)(vecAtQPs1[iq]) * (*f2)(vecAtQPs2[iq]);
C[iq] += (*f1)(vecAtQPs1[iq]) * (*f2)(vecAtQPs2[iq]) * factor;
}
......@@ -125,8 +129,9 @@ namespace AMDiS {
mtl::dense_vector<double>& result,
double fac)
{
double fac_ = fac * factor;
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * (*f1)(vecAtQPs1[iq]) * (*f2)(vecAtQPs2[iq]) * uhAtQP[iq];
result[iq] += fac_ * (*f1)(vecAtQPs1[iq]) * (*f2)(vecAtQPs2[iq]) * uhAtQP[iq];
}
......@@ -134,11 +139,14 @@ namespace AMDiS {
Vec2AtQP_ZOT::Vec2AtQP_ZOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2,
BinaryAbstractFunction<double, double, double> *af)
BinaryAbstractFunction<double, double, double> *af,
double factor_
)
: ZeroOrderTerm((af ? af->getDegree() : dv1->getFeSpace()->getBasisFcts()->getDegree()+dv2->getFeSpace()->getBasisFcts()->getDegree())),
vec1(dv1),
vec2(dv2),
f(af)
f(af),
factor(factor_)
{
TEST_EXIT(dv1)("No first vector!\n");
TEST_EXIT(dv2)("No second vector!\n");
......@@ -171,10 +179,10 @@ namespace AMDiS {
{
if (f) {
for (int iq = 0; iq < nPoints; iq++)
C[iq] += (*f)(vecAtQPs1[iq], vecAtQPs2[iq]);
C[iq] += (*f)(vecAtQPs1[iq], vecAtQPs2[iq]) * factor;
} else {
for (int iq = 0; iq < nPoints; iq++)
C[iq] += vecAtQPs1[iq] * vecAtQPs2[iq];
C[iq] += vecAtQPs1[iq] * vecAtQPs2[iq] * factor;
}
}
......@@ -185,12 +193,13 @@ namespace AMDiS {
mtl::dense_vector<double>& result,
double fac)
{
double fac_ = fac * factor;
if (f) {
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * (*f)(vecAtQPs1[iq], vecAtQPs2[iq]) * uhAtQP[iq];
result[iq] += fac_ * (*f)(vecAtQPs1[iq], vecAtQPs2[iq]) * uhAtQP[iq];
} else {
for (int iq = 0; iq < nPoints; iq++)
result[iq] += fac * vecAtQPs1[iq] * vecAtQPs2[iq] * uhAtQP[iq];
result[iq] += fac_ * vecAtQPs1[iq] * vecAtQPs2[iq] * uhAtQP[iq];
}
}
......@@ -200,14 +209,17 @@ namespace AMDiS {
Vec3AtQP_ZOT::Vec3AtQP_ZOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2,
DOFVectorBase<double> *dv3,
TertiaryAbstractFunction<double, double, double, double> *af)
TertiaryAbstractFunction<double, double, double, double> *af,
double factor_
)
: ZeroOrderTerm((af ? af->getDegree() : dv1->getFeSpace()->getBasisFcts()->getDegree()
+ dv2->getFeSpace()->getBasisFcts()->getDegree()
+ dv3->getFeSpace()->getBasisFcts()->getDegree())),
vec1(dv1),
vec2(dv2),
vec3(dv3),
f(af)
f(af),
factor(factor_)
{
TEST_EXIT(dv1)("No first vector!\n");
TEST_EXIT(dv2)("No second vector!\n");
......@@ -231,10 +243,10 @@ namespace AMDiS {
{
if (f) {
for (int iq = 0; iq < nPoints; iq++)
C[iq] += (*f)(vecAtQPs1[iq], vecAtQPs2[iq], vecAtQPs3[iq]);
C[iq] += (*f)(vecAtQPs1[iq], vecAtQPs2[iq], vecAtQPs3[iq]) * factor;
} else {
for (int iq = 0; iq < nPoints; iq++)
C[iq] += vecAtQPs1[iq] * vecAtQPs2[iq] * vecAtQPs3[iq];
C[iq] += vecAtQPs1[iq] * vecAtQPs2[iq] * vecAtQPs3[iq] * factor;
}
}
......@@ -245,14 +257,15 @@ namespace AMDiS {
mtl::dense_vector<double>& result,
double fac)
{
double fac_ = fac * factor;
if (f) {
for (int iq = 0; iq < nPoints; iq++)
result[iq] +=
fac * (*f)(vecAtQPs1[iq], vecAtQPs2[iq], vecAtQPs3[iq]) * uhAtQP[iq];
fac_ * (*f)(vecAtQPs1[iq], vecAtQPs2[iq], vecAtQPs3[iq]) * uhAtQP[iq];
} else {
for (int iq = 0; iq < nPoints; iq++)
result[iq] +=
fac * vecAtQPs1[iq] * vecAtQPs2[iq] * vecAtQPs3[iq] * uhAtQP[iq];
fac_ * vecAtQPs1[iq] * vecAtQPs2[iq] * vecAtQPs3[iq] * uhAtQP[iq];
}
}
......
......@@ -99,7 +99,9 @@ namespace AMDiS {
public:
/// Constructor.
VecAtQP_ZOT(DOFVectorBase<double> *dv,
AbstractFunction<double, double> *ab = NULL);
AbstractFunction<double, double> *ab = NULL,
double factor_ = 1.0
);
/// Implementation of \ref OperatorTerm::initElement().
void initElement(const ElInfo* elInfo,
......@@ -126,6 +128,9 @@ namespace AMDiS {
protected:
/// DOFVector to be evaluated at quadrature points.
DOFVectorBase<double>* vec;
/// Constant factor of zero order term.
double factor;
/// Vector v at quadrature points.
mtl::dense_vector<double> vecAtQPs;
......@@ -148,7 +153,9 @@ namespace AMDiS {
MultVecAtQP_ZOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2,
AbstractFunction<double, double> *f1,
AbstractFunction<double, double> *f2);
AbstractFunction<double, double> *f2,
double factor_ = 1.0
);
/// Implementation of \ref OperatorTerm::initElement().
void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
......@@ -169,7 +176,10 @@ namespace AMDiS {
/// DOFVectorBase to be evaluated at quadrature points.
DOFVectorBase<double>* vec1;
DOFVectorBase<double>* vec2;
/// Constant factor of zero order term.
double factor;
/// Vector v at quadrature points.
mtl::dense_vector<double> vecAtQPs1;
mtl::dense_vector<double> vecAtQPs2;
......@@ -192,7 +202,9 @@ namespace AMDiS {
/// Constructor.
Vec2AtQP_ZOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2,
BinaryAbstractFunction<double, double, double> *f = NULL);
BinaryAbstractFunction<double, double, double> *f = NULL,
double factor_ = 1.0
);
/// Implementation of \ref OperatorTerm::initElement().
void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
......@@ -220,6 +232,9 @@ namespace AMDiS {
DOFVectorBase<double>* vec1;
/// Second DOFVector to be evaluated at quadrature points.
DOFVectorBase<double>* vec2;
/// Constant factor of zero order term.
double factor;
/// Values of the first DOFVector at the quadrature points.
mtl::dense_vector<double> vecAtQPs1;
......@@ -244,7 +259,9 @@ namespace AMDiS {
Vec3AtQP_ZOT(DOFVectorBase<double> *dv1,
DOFVectorBase<double> *dv2,
DOFVectorBase<double> *dv3,
TertiaryAbstractFunction<double, double, double, double> *f = NULL);
TertiaryAbstractFunction<double, double, double, double> *f = NULL,
double factor_ = 1.0
);
/// Implementation of \ref OperatorTerm::initElement().
void initElement(const ElInfo* elInfo, SubAssembler* subAssembler,
......@@ -264,6 +281,9 @@ namespace AMDiS {
protected:
/// DOFVectors to be evaluated at quadrature points.
DOFVectorBase<double> *vec1, *vec2, *vec3;
/// Constant factor of zero order term.
double factor;
/// Vectors at quadrature points.
mtl::dense_vector<double> vecAtQPs1, vecAtQPs2, vecAtQPs3;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment