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

Use computeEnergy()

parent ae94ee7d
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <dune/common/nullptr.hh> #include <dune/common/nullptr.hh>
#include <dune/common/parametertree.hh> #include <dune/common/parametertree.hh>
// Just for debugging
#include "dune/solvers/computeenergy.hh"
#include <dune/fufem/arithmetic.hh> #include <dune/fufem/arithmetic.hh>
#include <dune/tnnmg/problem-classes/bisection.hh> #include <dune/tnnmg/problem-classes/bisection.hh>
...@@ -17,18 +20,11 @@ ...@@ -17,18 +20,11 @@
#include "ellipticenergy.hh" #include "ellipticenergy.hh"
/* Just for debugging */ /* Just for debugging */
template <int dim, class MatrixType, class VectorType> template <class MatrixType, class VectorType>
double computeEnergy( double computeEnergy(
MatrixType const &A, VectorType const &x, VectorType const &b, MatrixType const &A, VectorType const &x, VectorType const &b,
Dune::GlobalNonlinearity<MatrixType, VectorType> const &phi) { Dune::GlobalNonlinearity<MatrixType, VectorType> const &phi) {
double ret; return computeEnergy(A, x, b) + phi(x);
VectorType tmp(x.size());
A.mv(x, tmp); // Ax
ret = 0.5 * (tmp * x); // ret = 1/2 <Ax,x>
ret -= b * x; // ret = 1/2 <Ax,x> - <b,x>
ret += phi(x); // ret = 1/2 <Ax,x> - <b,x> + phi(x)
return ret;
} }
/** \brief Base class for problems where each block can be solved with a /** \brief Base class for problems where each block can be solved with a
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#ifndef MY_CONVEX_PROBLEM_HH #ifndef MY_CONVEX_PROBLEM_HH
#define MY_CONVEX_PROBLEM_HH #define MY_CONVEX_PROBLEM_HH
// Just for debugging
#include "dune/solvers/computeenergy.hh"
#include "globalnonlinearity.hh" #include "globalnonlinearity.hh"
template <class MatrixTypeTEMPLATE, class VectorTypeTEMPLATE> template <class MatrixTypeTEMPLATE, class VectorTypeTEMPLATE>
...@@ -29,10 +32,7 @@ class MyConvexProblem { ...@@ -29,10 +32,7 @@ class MyConvexProblem {
/* Just for debugging */ /* Just for debugging */
double operator()(VectorType const &x) const { double operator()(VectorType const &x) const {
double ret = phi(x) - (f * x); return phi(x) + computeEnergy(A, x, f);
VectorType tmp(x.size());
A.mv(x, tmp);
return ret + 0.5 * (tmp * x);
} }
MatrixType const &A; MatrixType const &A;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#ifndef MY_DIRECTIONAL_CONVEX_FUNCTION_HH #ifndef MY_DIRECTIONAL_CONVEX_FUNCTION_HH
#define MY_DIRECTIONAL_CONVEX_FUNCTION_HH #define MY_DIRECTIONAL_CONVEX_FUNCTION_HH
// just for debugging
#include <dune/solvers/computeenergy.hh>
#include <dune/fufem/interval.hh> #include <dune/fufem/interval.hh>
template <class NonlinearityType> class MyDirectionalConvexFunction { template <class NonlinearityType> class MyDirectionalConvexFunction {
...@@ -21,7 +24,7 @@ template <class NonlinearityType> class MyDirectionalConvexFunction { ...@@ -21,7 +24,7 @@ template <class NonlinearityType> class MyDirectionalConvexFunction {
double operator()(double x) const { double operator()(double x) const {
VectorType tmp = v; VectorType tmp = v;
tmp *= x; tmp *= x;
return (0.5 * A * x * x) - (b * x) + phi(tmp); return computeEnergy(A, x, b) + phi(tmp);
} }
double quadraticPart() const { return A; } double quadraticPart() const { return A; }
......
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