Skip to content
Snippets Groups Projects
Commit 9cfd8843 authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

SmoothesNorm -> SmallestPositivePoint

parent 53028a9c
No related branches found
No related tags found
No related merge requests found
...@@ -18,15 +18,15 @@ class FrictionPotentialWrapper { ...@@ -18,15 +18,15 @@ class FrictionPotentialWrapper {
double virtual differential(double s) const = 0; double virtual differential(double s) const = 0;
double virtual second_deriv(double x) const = 0; double virtual second_deriv(double x) const = 0;
double virtual regularity(double s) const = 0; double virtual regularity(double s) const = 0;
// Whether H(|.|) is smooth at zero
bool virtual smoothesNorm() const { return false; }
double virtual evaluate(double x) const { double virtual evaluate(double x) const {
DUNE_THROW(NotImplemented, "evaluation not implemented"); DUNE_THROW(NotImplemented, "evaluation not implemented");
} }
// Between 0 and this point, the function is constantly zero (and
// thus so are all derivatives)
double virtual smallestPositivePoint() const = 0;
}; };
// phi(V) = V log(V/V_m) - V + V_m if V >= V_m // phi(V) = V log(V/V_m) - V + V_m if V >= V_m
...@@ -87,7 +87,7 @@ class FrictionPotential : public FrictionPotentialWrapper { ...@@ -87,7 +87,7 @@ class FrictionPotential : public FrictionPotentialWrapper {
return std::abs(second_deriv(V)); return std::abs(second_deriv(V));
} }
bool virtual smoothesNorm() const { return true; } double virtual smallestPositivePoint() const { return V_m; }
private: private:
double const coefficientProduct; double const coefficientProduct;
...@@ -104,7 +104,9 @@ class TrivialFunction : public FrictionPotentialWrapper { ...@@ -104,7 +104,9 @@ class TrivialFunction : public FrictionPotentialWrapper {
double virtual regularity(double) const { return 0; } double virtual regularity(double) const { return 0; }
bool virtual smoothesNorm() const { return true; } double virtual smallestPositivePoint() const {
return std::numeric_limits<double>::infinity();
}
}; };
} }
#endif #endif
...@@ -18,16 +18,16 @@ template <int dimension> class LocalFriction { ...@@ -18,16 +18,16 @@ template <int dimension> class LocalFriction {
using VectorType = FieldVector<double, dimension>; using VectorType = FieldVector<double, dimension>;
using MatrixType = FieldMatrix<double, dimension, dimension>; using MatrixType = FieldMatrix<double, dimension, dimension>;
LocalFriction(shared_ptr<FrictionPotentialWrapper const> func) : func(func) {} LocalFriction(shared_ptr<FrictionPotentialWrapper const> func)
: func(func), smp(func->smallestPositivePoint()) {}
double operator()(VectorType const &x) const { double operator()(VectorType const &x) const {
return func->evaluate(x.two_norm()); return func->evaluate(x.two_norm());
} }
double regularity(VectorType const &x) const { double regularity(VectorType const &x) const {
if (!func->smoothesNorm() && x.two_norm() < 1e-14) // TODO: Make this double const xnorm = x.two_norm();
// controllable if (xnorm < 1e-14 && xnorm >= smp)
// (truncationRadius?)
return std::numeric_limits<double>::infinity(); return std::numeric_limits<double>::infinity();
return func->regularity(x.two_norm()); return func->regularity(x.two_norm());
...@@ -37,12 +37,11 @@ template <int dimension> class LocalFriction { ...@@ -37,12 +37,11 @@ template <int dimension> class LocalFriction {
// u and v are assumed to be non-zero // u and v are assumed to be non-zero
void directionalSubDiff(VectorType const &x, VectorType const &v, void directionalSubDiff(VectorType const &x, VectorType const &v,
Interval<double> &D) const { Interval<double> &D) const {
if (x.two_norm() == 0) { double const xnorm = x.two_norm();
D[0] = D[1] = func->differential(0) * v.two_norm(); if (xnorm < smp)
return; D[0] = D[1] = 0;
} else
double const un = x.two_norm(); D[0] = D[1] = func->differential(xnorm) / xnorm * (x * v);
D[0] = D[1] = func->differential(un) * (x * v) / un;
} }
/** Formula for the derivative: /** Formula for the derivative:
...@@ -64,6 +63,8 @@ template <int dimension> class LocalFriction { ...@@ -64,6 +63,8 @@ template <int dimension> class LocalFriction {
void addHessian(VectorType const &x, MatrixType &A) const { void addHessian(VectorType const &x, MatrixType &A) const {
double const xnorm2 = x.two_norm2(); double const xnorm2 = x.two_norm2();
double const xnorm = std::sqrt(xnorm2); double const xnorm = std::sqrt(xnorm2);
if (xnorm < smp)
return;
double const xnorm3 = xnorm * xnorm2; double const xnorm3 = xnorm * xnorm2;
double const H1 = func->differential(xnorm); double const H1 = func->differential(xnorm);
...@@ -110,7 +111,7 @@ template <int dimension> class LocalFriction { ...@@ -110,7 +111,7 @@ template <int dimension> class LocalFriction {
void addGradient(VectorType const &x, VectorType &y) const { void addGradient(VectorType const &x, VectorType &y) const {
double const xnorm = x.two_norm(); double const xnorm = x.two_norm();
if (xnorm == 0 or std::isinf(func->regularity(xnorm))) if (std::isinf(func->regularity(xnorm)))
return; return;
y.axpy(func->differential(xnorm) / xnorm, x); y.axpy(func->differential(xnorm) / xnorm, x);
...@@ -129,6 +130,7 @@ template <int dimension> class LocalFriction { ...@@ -129,6 +130,7 @@ template <int dimension> class LocalFriction {
private: private:
shared_ptr<FrictionPotentialWrapper const> const func; shared_ptr<FrictionPotentialWrapper const> const func;
double const smp;
}; };
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment