# HG changeset patch # User Eugenio Gianniti # Date 1400534313 -7200 # Node ID 470586565dc7ad1c8caaa117ee9ca8914b2c1974 # Parent 9adf76893ce4dd5fb5f553428181faabbba3d37d Changed order in interpolate signature diff -r 9adf76893ce4 -r 470586565dc7 src/interpolate.cc --- a/src/interpolate.cc Mon May 19 12:14:44 2014 +0200 +++ b/src/interpolate.cc Mon May 19 23:18:33 2014 +0200 @@ -21,16 +21,14 @@ DEFUN_DLD (interpolate, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} @var{interp} = \ -interpolate (@var{Function}, @var{v})\n\ -interpolate (@var{v}, @var{FunctionSpace})\n\ +interpolate (@var{name}, @var{u}, @var{v})\n\ Interpolate a function on a FunctionSpace.\n\ -This function can be used in two ways:\n\ -@itemize @bullet\n\ -@item To interpolate a Function, Expression or Constant, \ -@var{v}, on the same FunctionSpace of a @var{Function}\n\ -@item To interpolate a Function, Expression or Constant, \ -@var{v}, on a given @var{FunctionSpace}\n\ -@end itemize\n\ +@var{u} is the Function, Expression or Constant \ +to interpolate. @var{v} may be a FunctionSpace \ +or a Function. In the latter case @var{u} is interpolated \ +on the same FunctionSpace where @var{v} is defined.\n\ +Note that @var{name} is optional: if not provided, \ +it will default to the one assigned to @var{u}.\n\ @seealso{Function, Expression, Constant, FunctionSpace}\n\ @end deftypefn") { @@ -38,7 +36,7 @@ int nargin = args.length (); octave_value retval; - if (nargin < 2 || nargin > 2 || nargout > 1) + if (nargin < 2 || nargin > 3 || nargout > 1) print_usage (); else { @@ -63,37 +61,48 @@ mlock (); } - if (args(1).type_id () == functionspace::static_type_id ()) + octave_idx_type offset = 0; + std::string name; + if (args(0).is_string ()) + { + name = args(0).string_value (); + offset = 1; + } + + if (args(1+offset).type_id () == functionspace::static_type_id ()) { const functionspace & u1 = - static_cast (args(1).get_rep ()); + static_cast (args(1+offset).get_rep ()); if (! error_state) { boost::shared_ptr output (new dolfin::Function (u1.get_pfsp ())); - if (args(0).type_id () == function::static_type_id ()) + if (args(0+offset).type_id () == function::static_type_id ()) { const function & u0 = - static_cast (args(0).get_rep ()); + static_cast (args(0+offset).get_rep ()); if (! error_state) { output->interpolate (u0.get_fun ()); - std::string name = u0.get_str (); + if (name.empty ()) + name = u0.get_str (); retval = new function (name, output); } } - else if (args(0).type_id () == coefficient::static_type_id ()) + else if (args(0+offset).type_id () == + coefficient::static_type_id ()) { const coefficient & u0 = - static_cast (args(0).get_rep ()); + static_cast (args(0+offset).get_rep ()); if (! error_state) { output->interpolate (* u0.get_expr ()); - std::string name = u0.get_str (); + if (name.empty ()) + name = u0.get_str (); retval = new function (name, output); } } @@ -101,37 +110,40 @@ error ("interpolate: invalid arguments"); } } - else if (args(0).type_id () == function::static_type_id ()) + else if (args(1+offset).type_id () == function::static_type_id ()) { const function & u0 = - static_cast (args(0).get_rep ()); + static_cast (args(1+offset).get_rep ()); if (! error_state) { boost::shared_ptr output (new dolfin::Function (u0.get_fun ())); - if (args(1).type_id () == function::static_type_id ()) + if (args(0+offset).type_id () == function::static_type_id ()) { const function & u1 = - static_cast (args(1).get_rep ()); + static_cast (args(0+offset).get_rep ()); if (! error_state) { output->interpolate (u1.get_fun ()); - std::string name = u1.get_str (); + if (name.empty ()) + name = u1.get_str (); retval = new function (name, output); } } - else if (args(1).type_id () == coefficient::static_type_id ()) + else if (args(0+offset).type_id () == + coefficient::static_type_id ()) { const coefficient & u1 = - static_cast (args(1).get_rep ()); + static_cast (args(0+offset).get_rep ()); if (! error_state) { output->interpolate (* u1.get_expr ()); - std::string name = u1.get_str (); + if (name.empty ()) + name = u1.get_str (); retval = new function (name, output); } }