# HG changeset patch # User gedeone-octave # Date 1377350856 -7200 # Node ID 011ad0c352f7fc0ecda68c82e4d79e55b896003f # Parent 75780f7dc9f4f65434a5f665012de6230105cdfe New function for the evaluation of an object of type function in a given point * fem_eval: wrapper function for dolfin::eval. The name has to change in future. diff -r 75780f7dc9f4 -r 011ad0c352f7 src/Makefile.in --- a/src/Makefile.in Fri Aug 23 08:26:26 2013 +0200 +++ b/src/Makefile.in Sat Aug 24 15:27:36 2013 +0200 @@ -14,6 +14,7 @@ Plot_2d.oct \ Plot_3d.oct \ SubSpace.oct \ + fem_eval.oct \ LIBS += -ldolfin @@ -92,6 +93,9 @@ SubSpace.oct: SubSpace.cc functionspace.h $(MKOCTFILE) $(CPPFLAGS) -I. SubSpace.cc $(LDFLAGS) $(LIBS) +fem_eval.oct: fem_eval.cc function.h + $(MKOCTFILE) $(CPPFLAGS) -I. fem_eval.cc $(LDFLAGS) $(LIBS) + Plot_3d.h: Plot_3d.ufl $(FFC) -l dolfin Plot_3d.ufl diff -r 75780f7dc9f4 -r 011ad0c352f7 src/fem_eval.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fem_eval.cc Sat Aug 24 15:27:36 2013 +0200 @@ -0,0 +1,47 @@ +#include "function.h" + +DEFUN_DLD (fem_eval, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{value}]} = \ +fem_eval (@var{function_name}, @var{Coordinate})\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval=0; + + if (nargin < 2 || nargin > 2) + print_usage (); + else + { + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + + if (args(0).type_id () == function::static_type_id ()) + { + const function & fspo = + static_cast (args(0).get_rep ()); + Array point= args(1).array_value (); + + if (!error_state) + { + const boost::shared_ptr & f = fspo.get_pfun (); + dim_vector dims; + dims.resize (2); + dims(0) = 1; + dims(1) = f->value_dimension (0); + Array res (dims); + dolfin::Array x(point.length (), point.fortran_vec ()); + dolfin::Array values(res.length (), res.fortran_vec ()); + + f->eval (values, x); + + retval = octave_value (res); + } + } + } + return retval; +}