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

Add some functions for debugging

parent 6c18988e
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,22 @@ ...@@ -15,6 +15,22 @@
#include "mydirectionalconvexfunction.hh" #include "mydirectionalconvexfunction.hh"
#include "samplefunctional.hh" #include "samplefunctional.hh"
/* Just for debugging */
template <int dim, class VectorType, class MatrixType>
double computeEnergy(
MatrixType const &A, VectorType const &b,
Dune::GlobalNonlinearity<dim, VectorType, MatrixType> const &phi,
VectorType const &x) {
double ret;
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
* modified gradient method */ * modified gradient method */
template <class MyConvexProblemTypeTEMPLATE> class MyBlockProblem { template <class MyConvexProblemTypeTEMPLATE> class MyBlockProblem {
......
...@@ -17,6 +17,13 @@ template <class NonlinearityType> class MyDirectionalConvexFunction { ...@@ -17,6 +17,13 @@ template <class NonlinearityType> class MyDirectionalConvexFunction {
phi_.directionalDomain(u_, v_, dom_); phi_.directionalDomain(u_, v_, dom_);
} }
/* Just for debugging */
double operator()(double x) const {
VectorType tmp = v_;
tmp *= x;
return (0.5 * A * x * x) - (b * x) + phi_(tmp);
}
double quadraticPart() const { return A; } double quadraticPart() const { return A; }
double linearPart() const { return b; } double linearPart() const { return b; }
......
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