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

Have nonlinearities propagate their kinks

parent 240b5e07
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,8 @@ template <int dim> class EllipticEnergy { ...@@ -21,6 +21,8 @@ template <int dim> class EllipticEnergy {
shared_ptr<NonlinearityType const> phi, int ignore = dim) shared_ptr<NonlinearityType const> phi, int ignore = dim)
: A(A), b(b), phi(phi), ignore(ignore) {} : A(A), b(b), phi(phi), ignore(ignore) {}
std::vector<double> const &get_kinks() const { return phi->get_kinks(); }
double operator()(SmallVector const &v) const { double operator()(SmallVector const &v) const {
SmallVector y(0); SmallVector y(0);
A.usmv(0.5, v, y); // 1/2 Av A.usmv(0.5, v, y); // 1/2 Av
......
...@@ -20,6 +20,8 @@ template <int dimension> class LocalNonlinearity { ...@@ -20,6 +20,8 @@ template <int dimension> class LocalNonlinearity {
LocalNonlinearity(shared_ptr<NiceFunction const> func) : func(func) {} LocalNonlinearity(shared_ptr<NiceFunction const> func) : func(func) {}
std::vector<double> const &get_kinks() const { return func->get_kinks(); }
double operator()(VectorType const &x) const { double operator()(VectorType const &x) const {
return func->evaluate(x.two_norm()); return func->evaluate(x.two_norm());
} }
......
...@@ -147,8 +147,7 @@ void minimisationInitialiser(Functional const &J, Bisection const &bisection, ...@@ -147,8 +147,7 @@ void minimisationInitialiser(Functional const &J, Bisection const &bisection,
typename Functional::SmallVector &startingPoint) { typename Functional::SmallVector &startingPoint) {
typedef typename Functional::SmallVector SmallVector; typedef typename Functional::SmallVector SmallVector;
std::vector<double> const kinks = { 5, 10, std::vector<double> const &kinks = J.get_kinks();
15 }; // FIXME: We happen to know these
SmallVector x_old(0); SmallVector x_old(0);
double Jx_old = J(x_old); double Jx_old = J(x_old);
......
...@@ -10,7 +10,17 @@ ...@@ -10,7 +10,17 @@
namespace Dune { namespace Dune {
class NiceFunction { class NiceFunction {
protected:
NiceFunction(std::vector<double> const &_kinks) : kinks(_kinks) {}
private:
std::vector<double> const kinks;
public: public:
std::vector<double> const &get_kinks() const { return kinks; }
NiceFunction() : kinks() {}
virtual ~NiceFunction() {} virtual ~NiceFunction() {}
double virtual leftDifferential(double s) const = 0; double virtual leftDifferential(double s) const = 0;
...@@ -32,7 +42,8 @@ class RuinaFunction : public NiceFunction { ...@@ -32,7 +42,8 @@ class RuinaFunction : public NiceFunction {
public: public:
RuinaFunction(double coefficient, double a, double mu, double eta, RuinaFunction(double coefficient, double a, double mu, double eta,
double normalStress, double b, double state, double L, double h) double normalStress, double b, double state, double L, double h)
: a(a), : NiceFunction(),
a(a),
eta(eta), eta(eta),
h(h), h(h),
coefficientProduct(coefficient * normalStress), coefficientProduct(coefficient * normalStress),
...@@ -83,6 +94,8 @@ class RuinaFunction : public NiceFunction { ...@@ -83,6 +94,8 @@ class RuinaFunction : public NiceFunction {
class TrivialFunction : public NiceFunction { class TrivialFunction : public NiceFunction {
public: public:
TrivialFunction() : NiceFunction() {}
double virtual evaluate(double) const { return 0; } double virtual evaluate(double) const { return 0; }
double virtual leftDifferential(double) const { return 0; } double virtual leftDifferential(double) const { return 0; }
......
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
namespace Dune { namespace Dune {
class MyFunction : public NiceFunction { class MyFunction : public NiceFunction {
protected:
MyFunction(std::vector<double> const &_kinks) : NiceFunction(_kinks) {}
public:
MyFunction() : NiceFunction() {}
double virtual second_deriv(double) const { double virtual second_deriv(double) const {
assert(false); assert(false);
return 0; return 0;
...@@ -34,7 +40,7 @@ class Parabola : public MyFunction { ...@@ -34,7 +40,7 @@ class Parabola : public MyFunction {
class LinearFunction : public MyFunction { class LinearFunction : public MyFunction {
public: public:
LinearFunction(double a) : coefficient(a) {} LinearFunction(double a) : MyFunction(), coefficient(a) {}
double virtual evaluate(double x) const { return coefficient * x; } double virtual evaluate(double x) const { return coefficient * x; }
...@@ -52,6 +58,8 @@ class LinearFunction : public MyFunction { ...@@ -52,6 +58,8 @@ class LinearFunction : public MyFunction {
template <int slope> class SampleFunction : public MyFunction { template <int slope> class SampleFunction : public MyFunction {
public: public:
SampleFunction() : MyFunction({ 1 }) {}
double virtual evaluate(double x) const { double virtual evaluate(double x) const {
return (x < 1) ? x : (slope * (x - 1) + 1); return (x < 1) ? x : (slope * (x - 1) + 1);
} }
...@@ -76,6 +84,8 @@ class SteepFunction : public MyFunction { ...@@ -76,6 +84,8 @@ class SteepFunction : public MyFunction {
// slope in [n-1,n] is n // slope in [n-1,n] is n
class HorribleFunction : public MyFunction { class HorribleFunction : public MyFunction {
// TODO: Handle kinks
public: public:
double virtual evaluate(double x) const { double virtual evaluate(double x) const {
double const fl = floor(x); double const fl = floor(x);
...@@ -103,6 +113,8 @@ class HorribleFunction : public MyFunction { ...@@ -103,6 +113,8 @@ class HorribleFunction : public MyFunction {
// slope in [n-1,n] is log(n+1) // slope in [n-1,n] is log(n+1)
class HorribleFunctionLogarithmic : public MyFunction { class HorribleFunctionLogarithmic : public MyFunction {
public: public:
// TODO: Handle kinks
double virtual evaluate(double x) const { double virtual evaluate(double x) const {
double y = 0; double y = 0;
size_t const fl = floor(x); size_t const fl = floor(x);
...@@ -131,14 +143,14 @@ class HorribleFunctionLogarithmic : public MyFunction { ...@@ -131,14 +143,14 @@ class HorribleFunctionLogarithmic : public MyFunction {
}; };
class ThreeKinkFunction : public MyFunction { class ThreeKinkFunction : public MyFunction {
private:
std::vector<double> kinks = { 5, 10, 15 };
public: public:
ThreeKinkFunction() : MyFunction({ 5, 10, 15 }) {}
double virtual evaluate(double x) const { double virtual evaluate(double x) const {
double acc = 0; double acc = 0;
double last_kink = 0; double last_kink = 0;
int i; int i;
auto const &kinks = this->get_kinks();
for (i = 0; i < kinks.size(); ++i) { for (i = 0; i < kinks.size(); ++i) {
if (x <= kinks[i]) if (x <= kinks[i])
break; break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment