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

Make NiceFunction a proper (ctor-)parameter

parent e50a0fc7
No related branches found
No related tags found
No related merge requests found
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
#include "nicefunction.hh" #include "nicefunction.hh"
namespace Dune { namespace Dune {
template <int dimension, class OuterFunction = Dune::TrivialFunction> template <int dimension> class MyNonlinearity {
class MyNonlinearity {
public: public:
typedef Dune::FieldVector<double, dimension> SmallVector; typedef Dune::FieldVector<double, dimension> SmallVector;
typedef Dune::FieldMatrix<double, dimension, dimension> SmallMatrix; typedef Dune::FieldMatrix<double, dimension, dimension> SmallMatrix;
...@@ -22,6 +21,8 @@ class MyNonlinearity { ...@@ -22,6 +21,8 @@ class MyNonlinearity {
typedef SmallVector VectorType; typedef SmallVector VectorType;
typedef SmallMatrix MatrixType; typedef SmallMatrix MatrixType;
MyNonlinearity(NiceFunction const &func) : func_(func) {}
double operator()(VectorType const x) const { double operator()(VectorType const x) const {
double ret; double ret;
func_.evaluate(x.two_norm(), ret); func_.evaluate(x.two_norm(), ret);
...@@ -65,7 +66,7 @@ class MyNonlinearity { ...@@ -65,7 +66,7 @@ class MyNonlinearity {
} }
private: private:
OuterFunction func_; NiceFunction const &func_;
}; };
} }
#endif #endif
...@@ -20,9 +20,11 @@ class SampleFunctional { ...@@ -20,9 +20,11 @@ class SampleFunctional {
typedef Dune::FieldVector<double, dimension> SmallVector; typedef Dune::FieldVector<double, dimension> SmallVector;
typedef Dune::FieldMatrix<double, dimension, dimension> SmallMatrix; typedef Dune::FieldMatrix<double, dimension, dimension> SmallMatrix;
typedef MyNonlinearity<dimension, Function> NonlinearityType; typedef MyNonlinearity<dimension> NonlinearityType;
SampleFunctional(SmallMatrix _A, SmallVector _b) : A(_A), b(_b) {} SampleFunctional(SmallMatrix _A, SmallVector _b,
MyNonlinearity<dimension> _phi)
: A(_A), b(_b), phi(_phi) {}
double operator()(const SmallVector v) const { double operator()(const SmallVector v) const {
SmallVector y; SmallVector y;
......
...@@ -41,7 +41,8 @@ void testSampleFunction() { ...@@ -41,7 +41,8 @@ void testSampleFunction() {
b[0] = 1; b[0] = 1;
b[1] = 2; b[1] = 2;
SampleFunctional J(A, b); Dune::SampleFunction f;
SampleFunctional J(A, b, Dune::MyNonlinearity<dim>(f));
SampleFunctional::SmallVector start = b; SampleFunctional::SmallVector start = b;
start *= 17; start *= 17;
...@@ -88,7 +89,8 @@ void testSampleFunctionNonsmooth() { ...@@ -88,7 +89,8 @@ void testSampleFunctionNonsmooth() {
b[0] = 1; b[0] = 1;
b[1] = 2; b[1] = 2;
SampleFunctional J(A, b); Dune::SampleFunction f;
SampleFunctional J(A, b, Dune::MyNonlinearity<dim>(f));
SampleFunctional::SmallVector start; SampleFunctional::SmallVector start;
SampleFunctional::SmallVector error; SampleFunctional::SmallVector error;
...@@ -149,7 +151,8 @@ void testTrivialFunction() { ...@@ -149,7 +151,8 @@ void testTrivialFunction() {
b[0] = 1; b[0] = 1;
b[1] = 2; b[1] = 2;
SampleFunctional J(A, b); Dune::TrivialFunction f;
SampleFunctional J(A, b, Dune::MyNonlinearity<dim>(f));
SampleFunctional::SmallVector start = b; SampleFunctional::SmallVector start = b;
start *= 17; start *= 17;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment