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

[Cleanup] Helpers for MyDirectionalConvexFunctional

parent ae306d94
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <dune/fufem/arithmetic.hh> #include <dune/fufem/arithmetic.hh>
#include <dune/fufem/interval.hh> #include <dune/fufem/interval.hh>
#include <dune/solvers/computeenergy.hh>
#include <dune/tnnmg/problem-classes/bisection.hh> #include <dune/tnnmg/problem-classes/bisection.hh>
#include "mydirectionalconvexfunction.hh" #include "mydirectionalconvexfunction.hh"
...@@ -21,20 +20,9 @@ void descentMinimisation(Functional const &J, ...@@ -21,20 +20,9 @@ void descentMinimisation(Functional const &J,
using SmallVector = typename Functional::SmallVector; using SmallVector = typename Functional::SmallVector;
using LocalNonlinearityType = typename Functional::NonlinearityType; using LocalNonlinearityType = typename Functional::NonlinearityType;
// {{{ Construct a restriction of J to the line x + t * v
/* We have
1/2 <A(x+tv),x+tv>-<b,x+tv> = 1/2 <Av,v> t^2 - <b-Ax,v> t + <1/2 Ax-b,x>
since A is symmetric.
*/
SmallVector tmp = J.b;
Arithmetic::addProduct(tmp, -1.0, J.A, x);
double const JRestb = tmp * v;
MyDirectionalConvexFunction<LocalNonlinearityType> const JRest( MyDirectionalConvexFunction<LocalNonlinearityType> const JRest(
2.0 * computeEnergy(J.A, v), JRestb, *J.phi, x, v); computeDirectionalA(J.A, v), computeDirectionalb(J.A, J.b, x, v), *J.phi,
x, v);
// }}} // }}}
int count; int count;
......
...@@ -105,22 +105,10 @@ template <class MyConvexProblemTypeTEMPLATE> class MyBlockProblem { ...@@ -105,22 +105,10 @@ template <class MyConvexProblemTypeTEMPLATE> class MyBlockProblem {
Arithmetic::addProduct(tmp, -1.0, problem.A, u); Arithmetic::addProduct(tmp, -1.0, problem.A, u);
double const localb = tmp * v; double const localb = tmp * v;
problem.A.mv(v, tmp);
double const localA = tmp * v;
/*
1/2 <A(u + hv),u + hv> - <b, u + hv>
= 1/2 <Av,v> h^2 - <b - Au, v> h + const.
localA = <Av,v>
localb = <b - Au, v>
*/
MyDirectionalConvexFunction< MyDirectionalConvexFunction<
Dune::GlobalNonlinearity<MatrixType, VectorType>> const psi(localA, Dune::GlobalNonlinearity<MatrixType, VectorType>> const
localb, psi(computeDirectionalA(problem.A, v),
problem.phi, computeDirectionalb(problem.A, problem.f, u, v), problem.phi, u, v);
u, v);
Interval<double> D; Interval<double> D;
psi.subDiff(0, D); psi.subDiff(0, D);
......
...@@ -9,6 +9,29 @@ ...@@ -9,6 +9,29 @@
#include <dune/fufem/interval.hh> #include <dune/fufem/interval.hh>
/*
1/2 <A(u + hv),u + hv> - <b, u + hv>
= 1/2 <Av,v> h^2 - <b - Au, v> h + const.
localA = <Av,v>
localb = <b - Au, v>
*/
template <class MatrixType, class VectorType>
double computeDirectionalA(MatrixType const &A, VectorType const &v) {
VectorType tmp(v.size());
A.mv(v, tmp);
return tmp * v;
}
template <class MatrixType, class VectorType>
double computeDirectionalb(MatrixType const &A, VectorType const &b,
VectorType const &u, VectorType const &v) {
VectorType tmp = b;
Arithmetic::addProduct(tmp, -1.0, A, u);
return tmp * v;
}
template <class NonlinearityType> class MyDirectionalConvexFunction { template <class NonlinearityType> class MyDirectionalConvexFunction {
public: public:
using VectorType = typename NonlinearityType::VectorType; using VectorType = typename NonlinearityType::VectorType;
......
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