From 82efa55015656e6941ec2e3e6d62b46058787d2f Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Thu, 24 Nov 2011 17:10:06 +0100 Subject: [PATCH] Copy directionalconvexfunction; use the copy Allows us to make the nonlinearity a constant reference --- dune/tectonic/mydirectionalconvexfunction.hh | 48 ++++++++++++++++++++ dune/tectonic/samplefunctional.hh | 11 ++--- 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 dune/tectonic/mydirectionalconvexfunction.hh diff --git a/dune/tectonic/mydirectionalconvexfunction.hh b/dune/tectonic/mydirectionalconvexfunction.hh new file mode 100644 index 00000000..526c9821 --- /dev/null +++ b/dune/tectonic/mydirectionalconvexfunction.hh @@ -0,0 +1,48 @@ +// 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 diff --git a/dune/tectonic/samplefunctional.hh b/dune/tectonic/samplefunctional.hh index 2a6206f1..780d0d70 100644 --- a/dune/tectonic/samplefunctional.hh +++ b/dune/tectonic/samplefunctional.hh @@ -10,8 +10,8 @@ #include <dune/fufem/interval.hh> #include <dune/tnnmg/problem-classes/bisection.hh> -#include <dune/tnnmg/problem-classes/directionalconvexfunction.hh> +#include "mydirectionalconvexfunction.hh" #include "localnonlinearity.hh" #include "curvedfunction.hh" @@ -156,7 +156,6 @@ void minimise(Functional const J, typename Functional::SmallVector &x, return; typedef typename Functional::NonlinearityType LocalNonlinearityType; - LocalNonlinearityType phi = *J.phi; // copy, see below if (linesearchp) { // {{{ Construct a restriction of J to the line x + t * descDir @@ -176,11 +175,9 @@ void minimise(Functional const J, typename Functional::SmallVector &x, J.A.mmv(x, tmp); // b-Au double const JRestb = tmp * descDir; // <b-Au,v> - typedef DirectionalConvexFunction<LocalNonlinearityType> + typedef MyDirectionalConvexFunction<LocalNonlinearityType> MyDirectionalConvexFunctionType; - // FIXME: We cannot pass J.phi directly because the constructor - // does not allow for constant arguments - MyDirectionalConvexFunctionType JRest(JRestA, JRestb, phi, x, descDir); + MyDirectionalConvexFunctionType JRest(JRestA, JRestb, *J.phi, x, descDir); // }}} { // Debug @@ -219,7 +216,7 @@ void minimise(Functional const J, typename Functional::SmallVector &x, slowBisection.setFastQuadratic(false); 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; double const stepsize = slowBisection.minimize(JRest, 0.0, 1.0, count); -- GitLab