diff --git a/src/Makefile.am b/src/Makefile.am index dabe8d36eb32ee6aa794e7db79a063d0fe5e3447..c0c893ce61b4ee95f3efe54036199e0af139c478 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,3 +49,4 @@ run-octave: duneevaluate.oct duneminimise.oct octave --path $(abs_builddir) --path $(abs_srcdir) include $(srcdir)/duneminimise.mk +include $(srcdir)/duneevaluate.mk diff --git a/src/duneevaluate.cc b/src/duneevaluate.cc new file mode 100644 index 0000000000000000000000000000000000000000..c558374966995142e877bd2304f7bf332fda6e2d --- /dev/null +++ b/src/duneevaluate.cc @@ -0,0 +1,39 @@ +/* -*- mode:c++; mode:semantic -*- */ + +#include <octave/oct.h> + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "samplefunctional.hh" + +#include <cassert> + +DEFUN_DLD(duneevaluate, args, nargout, "the help string") { + assert(args.length() == 1); + ColumnVector point(args(0).matrix_value()); + // FIXME: We're only working with dimension two for now + assert(point.length() == 2); + + int const dim = 2; + typedef Dune::SampleFunctional<dim> SampleFunctional; + + SampleFunctional::SmallMatrix A; + A[0][0] = 3; + A[0][1] = 1.5; + A[1][0] = 1.5; + A[1][1] = 4; + SampleFunctional::SmallVector b; + b[0] = 1; + b[1] = 2; + + SampleFunctional::SmallVector our_point; + our_point[0] = point(0); + our_point[1] = point(1); + + Dune::SampleFunction f; + SampleFunctional J(A, b, Dune::MyNonlinearity<dim>(f)); + + return octave_value(J(our_point)); +} diff --git a/src/duneevaluate.mk b/src/duneevaluate.mk new file mode 100644 index 0000000000000000000000000000000000000000..047d72a1b81aa15d61581fc900770eb0722897e0 --- /dev/null +++ b/src/duneevaluate.mk @@ -0,0 +1,10 @@ +bin_PROGRAMS += duneminimise.oct + +# this would work if shared libraries were only passed via -L and -l, not directly +#duneminimise_LINK = libtool --tag=CXX --mode link $(MKOCTFILE) $(AM_LDFLAGS) -o $@ + +duneevaluate.oct: duneevaluate.o + $(MKOCTFILE) -o $@ $< -ldunecommon + +duneevaluate.o: duneevaluate.cc + $(MKOCTFILE) $(AM_CPPFLAGS) -c -o $@ $< diff --git a/src/foo.m b/src/foo.m index 1a696309d05e7a43e697954df70e8b29bed0ca2a..15e74ba64dd48071d4c3e58d467a4ae90e8270f8 100644 --- a/src/foo.m +++ b/src/foo.m @@ -8,15 +8,11 @@ y = (-300:10:300)'; v = ones(length(x),1); X = v * x; Y = y * v'; -A = [3 1.5; 1.5 4]; -b = [1; 2]; - -myfunc = @(x)(1/2 * (A * x)' * x - b' * x + H(norm(x))); for i=1:length(x) for j=1:length(y) vec = [ X(i,j); Y(i,j) ]; - val = myfunc(vec); + val = duneevaluate(vec); f(i,j) = val; end end @@ -30,7 +26,7 @@ for i=1:6 newvec=duneminimise(oldvec); line([oldvec(1) newvec(1)], ... [oldvec(2) newvec(2)], ... - [myfunc(oldvec) myfunc(newvec)], ... + [duneevaluate(oldvec) duneevaluate(newvec)], ... 'color', 'r'); norm(oldvec-newvec) oldvec=newvec;