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

Move evaluate from octave to dune

parent 2e62f69b
No related branches found
No related tags found
No related merge requests found
...@@ -49,3 +49,4 @@ run-octave: duneevaluate.oct duneminimise.oct ...@@ -49,3 +49,4 @@ run-octave: duneevaluate.oct duneminimise.oct
octave --path $(abs_builddir) --path $(abs_srcdir) octave --path $(abs_builddir) --path $(abs_srcdir)
include $(srcdir)/duneminimise.mk include $(srcdir)/duneminimise.mk
include $(srcdir)/duneevaluate.mk
/* -*- 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));
}
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 $@ $<
...@@ -8,15 +8,11 @@ y = (-300:10:300)'; ...@@ -8,15 +8,11 @@ y = (-300:10:300)';
v = ones(length(x),1); v = ones(length(x),1);
X = v * x; X = v * x;
Y = y * v'; 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 i=1:length(x)
for j=1:length(y) for j=1:length(y)
vec = [ X(i,j); Y(i,j) ]; vec = [ X(i,j); Y(i,j) ];
val = myfunc(vec); val = duneevaluate(vec);
f(i,j) = val; f(i,j) = val;
end end
end end
...@@ -30,7 +26,7 @@ for i=1:6 ...@@ -30,7 +26,7 @@ for i=1:6
newvec=duneminimise(oldvec); newvec=duneminimise(oldvec);
line([oldvec(1) newvec(1)], ... line([oldvec(1) newvec(1)], ...
[oldvec(2) newvec(2)], ... [oldvec(2) newvec(2)], ...
[myfunc(oldvec) myfunc(newvec)], ... [duneevaluate(oldvec) duneevaluate(newvec)], ...
'color', 'r'); 'color', 'r');
norm(oldvec-newvec) norm(oldvec-newvec)
oldvec=newvec; oldvec=newvec;
......
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