# HG changeset patch # User gedeone-octave # Date 1375476942 -7200 # Node ID d6df5cc8ef53c639f8c411b8eba2b452459c488a # Parent d123adbe296bd69ba8368f454dee5ff0cf51c40c Improve the expression class to deal also with vector fields. * Expression.h: new constructor for vector field * coefficient.h: new constructor for the expression member * fem_bc.cc, fem_coeff.cc: initialize the dolfin::Expression accordingly to the number of input passed from the user diff -r d123adbe296b -r d6df5cc8ef53 src/coefficient.h --- a/src/coefficient.h Fri Aug 02 22:51:34 2013 +0200 +++ b/src/coefficient.h Fri Aug 02 22:55:42 2013 +0200 @@ -27,14 +27,17 @@ coefficient () : octave_base_value () {} coefficient (std::string & _str, octave_fcn_handle & _f) : - str (_str), expr (new expression (_f)) {} + str (_str), expr (new expression (_f)) { } + + coefficient (std::string & _str, octave_fcn_handle & _f, std::size_t _n) : + str (_str), expr (new expression (_f, _n)) { } void print (std::ostream& os, bool pr_as_read_syntax = false) const { os << "Coefficient " << str << " : " << expr->str (true) << std::endl; } - ~coefficient (void) {} + ~coefficient (void) { } bool is_defined (void) const { return true; } diff -r d123adbe296b -r d6df5cc8ef53 src/expression.h --- a/src/expression.h Fri Aug 02 22:51:34 2013 +0200 +++ b/src/expression.h Fri Aug 02 22:55:42 2013 +0200 @@ -35,6 +35,9 @@ expression (octave_fcn_handle & _f) : dolfin::Expression (), f (new octave_fcn_handle (_f)) {} + expression (octave_fcn_handle & _f, std::size_t _n) : + dolfin::Expression (_n), f (new octave_fcn_handle (_f)) {} + ~expression (void) { delete f; } @@ -44,12 +47,14 @@ b.resize (x.size ()); for (std::size_t i = 0; i < x.size (); ++i) b(i) = x[i]; - octave_value_list res = feval (f->function_value (), b); - values[0] = res(0).double_value (); + octave_value_list tmp = feval (f->function_value (), b); + Array res = tmp(0).array_value (); + + for (std::size_t i = 0; i < values.size (); ++i) + values[i] = res(i); } private: octave_fcn_handle * f; }; - #endif diff -r d123adbe296b -r d6df5cc8ef53 src/fem_bc.cc --- a/src/fem_bc.cc Fri Aug 02 22:51:34 2013 +0200 +++ b/src/fem_bc.cc Fri Aug 02 22:55:42 2013 +0200 @@ -37,7 +37,7 @@ @end deftypefn") { int nargin = args.length (); - octave_value retval=0; + octave_value retval; if (nargin < 3 || nargin > 3) print_usage (); @@ -60,7 +60,18 @@ if (!error_state) { const boost::shared_ptr & V (fspo.get_pfsp ()); - const expression * pf = new expression (*fh); + + octave_value_list b (3, 1); + octave_value_list tmp = feval (fh->function_value (), b); + Array res = tmp(0).array_value (); + std::size_t l = res.length (); + + expression * pf; + if (l > 1) + pf = new expression (*fh, l); + else + pf = new expression (*fh); + boost::shared_ptr f (pf); if (! boundarycondition_type_loaded) diff -r d123adbe296b -r d6df5cc8ef53 src/fem_coeff.cc --- a/src/fem_coeff.cc Fri Aug 02 22:51:34 2013 +0200 +++ b/src/fem_coeff.cc Fri Aug 02 22:55:42 2013 +0200 @@ -48,7 +48,17 @@ } if (!error_state) - retval = new coefficient (str, *fh); + { + octave_value_list b (3, 1); + octave_value_list tmp = feval (fh->function_value (), b); + Array res = tmp(0).array_value (); + std::size_t l = res.length (); + + if (l > 1) + retval = new coefficient (str, *fh, l); + else + retval = new coefficient (str, *fh); + } }