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

Simplify NiceFunction::evaluate()

parent 59930ae2
No related branches found
No related tags found
No related merge requests found
......@@ -21,9 +21,7 @@ template <int dimension> class LocalNonlinearity {
LocalNonlinearity(shared_ptr<NiceFunction const> func) : func(func) {}
double operator()(VectorType const &x) const {
double ret;
func->evaluate(x.two_norm(), ret);
return ret;
return func->evaluate(x.two_norm());
}
double regularity(VectorType const &x) const {
......
......@@ -23,7 +23,7 @@ class NiceFunction {
// Whether H(|.|) is smooth at zero
bool virtual smoothesNorm() const { return false; }
void virtual evaluate(double const &x, double &y) const {
double virtual evaluate(double x) const {
DUNE_THROW(NotImplemented, "evaluation not implemented");
}
};
......@@ -83,7 +83,7 @@ class RuinaFunction : public NiceFunction {
class TrivialFunction : public NiceFunction {
public:
void virtual evaluate(double const &x, double &y) const { y = 0; }
double virtual evaluate(double) const { return 0; }
double virtual leftDifferential(double) const { return 0; }
......
......@@ -19,7 +19,7 @@ class MyFunction : public NiceFunction {
};
class Parabola : public MyFunction {
void virtual evaluate(double const &x, double &y) const { y = x * x; }
double virtual evaluate(double x) const { return x * x; }
double virtual leftDifferential(double s) const { return 2 * s; }
......@@ -36,9 +36,7 @@ class LinearFunction : public MyFunction {
public:
LinearFunction(double a) : coefficient(a) {}
void virtual evaluate(double const &x, double &y) const {
y = coefficient * x;
}
double virtual evaluate(double x) const { return coefficient * x; }
double virtual leftDifferential(double s) const { return coefficient; }
......@@ -54,8 +52,8 @@ class LinearFunction : public MyFunction {
template <int slope> class SampleFunction : public MyFunction {
public:
void virtual evaluate(double const &x, double &y) const {
y = (x < 1) ? x : (slope * (x - 1) + 1);
double virtual evaluate(double x) const {
return (x < 1) ? x : (slope * (x - 1) + 1);
}
double virtual leftDifferential(double s) const {
......@@ -69,7 +67,7 @@ template <int slope> class SampleFunction : public MyFunction {
class SteepFunction : public MyFunction {
public:
void virtual evaluate(double const &x, double &y) const { y = 100 * x; }
double virtual evaluate(double x) const { return 100 * x; }
double virtual leftDifferential(double s) const { return 100; }
......@@ -79,10 +77,10 @@ class SteepFunction : public MyFunction {
// slope in [n-1,n] is n
class HorribleFunction : public MyFunction {
public:
void virtual evaluate(double const &x, double &y) const {
double virtual evaluate(double x) const {
double const fl = floor(x);
double const sum = fl * (fl + 1) / 2;
y = sum + (fl + 1) * (x - fl);
return sum + (fl + 1) * (x - fl);
}
double virtual leftDifferential(double x) const {
......@@ -105,14 +103,14 @@ class HorribleFunction : public MyFunction {
// slope in [n-1,n] is log(n+1)
class HorribleFunctionLogarithmic : public MyFunction {
public:
void virtual evaluate(double const &x, double &y) const {
y = 0;
double virtual evaluate(double x) const {
double y = 0;
size_t const fl = floor(x);
for (size_t i = 1; i <= fl;)
y += std::log(
++i); // factorials grow to fast so we compute this incrementally
y += std::log(fl + 2) * (x - fl);
return y + std::log(fl + 2) * (x - fl);
}
double virtual leftDifferential(double x) const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment