Commit bad6d74c authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de
Browse files

Update NormFunctional and functiontest to newer interface

parent 853b343b
#ifndef DUNE_TNNMG_FUNCTIONALS_NORMFUNCTIONAL_HH
#define DUNE_TNNMG_FUNCTIONALS_NORMFUNCTIONAL_HH
#include <limits>
#include <dune/common/exceptions.hh>
#include <dune/solvers/common/interval.hh>
#include <dune/solvers/common/resize.hh>
#include <dune/tnnmg/problem-classes/nonlinearity.hh>
#include <dune/tnnmg/functionals/nonsmoothconvexfunctional.hh>
namespace Dune {
......@@ -264,12 +267,13 @@ public:
d[1] = std::numeric_limits<double>::max();
}
void subDiff(double z, Dune::Solvers::Interval<double>& dJ) const
Solvers::Interval<double> subDifferential(double z) const
{
Solvers::Interval<double> result(0.0);
double tolerance = 1e-15;
dJ = 0.0;
for (size_t row=0; row<(*origin_).size(); ++row)
for (size_t row=0; row<origin_->size(); ++row)
{
auto p = (*origin_)[row];
p.axpy(z, (*direction_)[row]);
......@@ -284,14 +288,17 @@ public:
for (size_t i=0; i<p.size(); i++)
gradient[i] += (*coefficients_)[row][0] * p[i] / norm;
dJ += gradient * (*direction_)[row];
result += gradient * (*direction_)[row];
}
else
{
dJ[0] -= (*coefficients_)[row][0] * (*direction_)[row].two_norm();
dJ[1] += (*coefficients_)[row][0] * (*direction_)[row].two_norm();
result[0] -= (*coefficients_)[row][0] * (*direction_)[row].two_norm();
result[1] += (*coefficients_)[row][0] * (*direction_)[row].two_norm();
}
}
return result;
}
protected:
......
......@@ -395,8 +395,7 @@ void testDirectionalRestrictionSubdifferential(const Functional& functional,
for (auto v : testParameters)
{
// Test the subdifferential of the restriction
Solvers::Interval<double> subDifferential;
restriction.subDiff(v, subDifferential);
Solvers::Interval<double> subDifferential = restriction.subDifferential(v);
// Step size. Best value: square root of the machine precision
const double eps = std::sqrt(std::numeric_limits<double>::epsilon());
......
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