Mercurial > fem-fenics-eugenio
diff src/Function.cc @ 78:670a5d91c397
Rename the function visible from the user accordingly to dolfin interface.
* fem_bc.cc -> DirichletBC.cc
* fem_coeff.cc -> Expression.cc
* fem_func.cc -> Function.cc
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Sat, 03 Aug 2013 14:29:04 +0200 |
parents | src/fem_func.cc@93e538063278 |
children | d03627091414 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Function.cc Sat Aug 03 14:29:04 2013 +0200 @@ -0,0 +1,70 @@ +#include <dolfin.h> +#include "functionspace.h" +#include "function.h" + +DEFUN_DLD (Function, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{func}]} = \ +fem_func (@var{name}, @var{Functional Space}, @var{Vector})\n\ +The input parameters are\n\ +@itemize @bullet \n\ +@item @var{name} is a string representing the name of the function\n\ +@item @var{Functional Space} is the fem-fenics functional space where\ +the vector is defined\n\ +@item @var{Vector} contains the value of the coefficients\ +for the basis functions of @var{Functional Space}\n\ +@end itemize\n\ +The output @var{func} is an object which contain a representation of the\ +function @var{Vector} which can be plotted or saved.\n\ +@seealso{fem_plot, fem_save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval=0; + + if (nargin < 3 || nargin > 3) + print_usage (); + else + { + if (! functionspace_type_loaded) + { + functionspace::register_type (); + functionspace_type_loaded = true; + mlock (); + } + if (args(1).type_id () == functionspace::static_type_id ()) + { + std::string str = args(0).string_value (); + const functionspace & fspo = + static_cast<const functionspace&> (args(1).get_rep ()); + Array <double> myu = args(2).array_value (); + + if (!error_state) + { + const boost::shared_ptr<const dolfin::FunctionSpace> & V = fspo.get_pfsp (); + + if (V->dim () != myu.length ()) + error ("The size of the functional space and of the vector must agree"); + else + { + dolfin::Vector du(myu.length ()); + for (std::size_t i = 0; i < myu.length (); ++i) + du.setitem (i, myu(i)); + + boost::shared_ptr<dolfin::Vector> uu (new dolfin::Vector(du)); + boost::shared_ptr <const dolfin::Function> u (new dolfin::Function(V, uu)); + + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + + retval = new function (str, u); + } + } + } + } + return retval; +}