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

Copy directionalconvexfunction; use the copy

Allows us to make the nonlinearity a constant reference
parent 91c1acef
No related branches found
No related tags found
No related merge requests found
// Copied from dune/tnnmg/problem-classes/directionalconvexfunction.hh
#ifndef MY_DIRECTIONAL_CONVEX_FUNCTION_HH
#define MY_DIRECTIONAL_CONVEX_FUNCTION_HH
#include <dune/fufem/interval.hh>
template <class NonlinearityType> class MyDirectionalConvexFunction {
public:
typedef typename NonlinearityType::VectorType VectorType;
typedef typename NonlinearityType::MatrixType MatrixType;
MyDirectionalConvexFunction(double A, double b, NonlinearityType const& phi,
const VectorType& u, const VectorType& v)
: A(A), b(b), phi_(phi), u_(u), v_(v), temp_u_(u) {
phi_.directionalDomain(u_, v_, dom_);
}
double quadraticPart() const { return A; }
double linearPart() const { return b; }
void subDiff(double x, Interval<double>& D) const {
temp_u_ = u_;
temp_u_.axpy(x, v_);
phi_.directionalSubDiff(temp_u_, v_, D);
D[0] += A * x - b;
D[1] += A * x - b;
}
void domain(Interval<double>& domain) const {
domain[0] = this->dom_[0];
domain[1] = this->dom_[1];
}
double A;
double b;
private:
NonlinearityType const& phi_;
const VectorType& u_;
const VectorType& v_;
mutable VectorType temp_u_;
Interval<double> dom_;
};
#endif
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include <dune/fufem/interval.hh> #include <dune/fufem/interval.hh>
#include <dune/tnnmg/problem-classes/bisection.hh> #include <dune/tnnmg/problem-classes/bisection.hh>
#include <dune/tnnmg/problem-classes/directionalconvexfunction.hh>
#include "mydirectionalconvexfunction.hh"
#include "localnonlinearity.hh" #include "localnonlinearity.hh"
#include "curvedfunction.hh" #include "curvedfunction.hh"
...@@ -156,7 +156,6 @@ void minimise(Functional const J, typename Functional::SmallVector &x, ...@@ -156,7 +156,6 @@ void minimise(Functional const J, typename Functional::SmallVector &x,
return; return;
typedef typename Functional::NonlinearityType LocalNonlinearityType; typedef typename Functional::NonlinearityType LocalNonlinearityType;
LocalNonlinearityType phi = *J.phi; // copy, see below
if (linesearchp) { if (linesearchp) {
// {{{ Construct a restriction of J to the line x + t * descDir // {{{ Construct a restriction of J to the line x + t * descDir
...@@ -176,11 +175,9 @@ void minimise(Functional const J, typename Functional::SmallVector &x, ...@@ -176,11 +175,9 @@ void minimise(Functional const J, typename Functional::SmallVector &x,
J.A.mmv(x, tmp); // b-Au J.A.mmv(x, tmp); // b-Au
double const JRestb = tmp * descDir; // <b-Au,v> double const JRestb = tmp * descDir; // <b-Au,v>
typedef DirectionalConvexFunction<LocalNonlinearityType> typedef MyDirectionalConvexFunction<LocalNonlinearityType>
MyDirectionalConvexFunctionType; MyDirectionalConvexFunctionType;
// FIXME: We cannot pass J.phi directly because the constructor MyDirectionalConvexFunctionType JRest(JRestA, JRestb, *J.phi, x, descDir);
// does not allow for constant arguments
MyDirectionalConvexFunctionType JRest(JRestA, JRestb, phi, x, descDir);
// }}} // }}}
{ // Debug { // Debug
...@@ -219,7 +216,7 @@ void minimise(Functional const J, typename Functional::SmallVector &x, ...@@ -219,7 +216,7 @@ void minimise(Functional const J, typename Functional::SmallVector &x,
slowBisection.setFastQuadratic(false); slowBisection.setFastQuadratic(false);
typedef CurvedFunction<LocalNonlinearityType> MyCurvedFunctionType; typedef CurvedFunction<LocalNonlinearityType> MyCurvedFunctionType;
MyCurvedFunctionType JRest(J.A, J.b, phi, x, descDir); MyCurvedFunctionType JRest(J.A, J.b, *J.phi, x, descDir);
int count; int count;
double const stepsize = slowBisection.minimize(JRest, 0.0, 1.0, count); double const stepsize = slowBisection.minimize(JRest, 0.0, 1.0, count);
......
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