Mercurial > fem-fenics-eugenio
changeset 119:4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
a Function: now start from 1.
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Sun, 01 Sep 2013 23:14:28 +0200 |
parents | ee608d1bffca |
children | 4096194c31de |
files | src/Expression.cc src/Function.cc |
diffstat | 2 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Expression.cc Sun Sep 01 22:47:21 2013 +0200 +++ b/src/Expression.cc Sun Sep 01 23:14:28 2013 +0200 @@ -49,11 +49,16 @@ if (!error_state) { + std::cout << "Creating expression..."<< std::endl; octave_value_list b (3, 1); octave_value_list tmp = feval (fh->function_value (), b); Array<double> res = tmp(0).array_value (); std::size_t l = res.length (); + /* + Look at the discussion + http://fenicsproject.org/qa/781/scalar-and-vector-valued-expression + */ if (l > 1) retval = new coefficient (str, *fh, l); else
--- a/src/Function.cc Sun Sep 01 22:47:21 2013 +0200 +++ b/src/Function.cc Sun Sep 01 23:14:28 2013 +0200 @@ -4,8 +4,11 @@ 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\ +Function (@var{name}, @var{Functional Space} or @var{Function},\ +@var{Vector} or @var{index})\n\ +These function can be used in two ways\n\ +@itemize @bullet \n\ +@item To create a function from a vector. In this case, the arguments 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\ @@ -13,6 +16,14 @@ @item @var{Vector} contains the value of the coefficients\ for the basis functions of @var{Functional Space}\n\ @end itemize\n\ +@item To extract a scalar field from a vectorial one\n\ +@itemize @bullet \n\ +@item @var{name} is a string representing the name of the function\n\ +@item @var{Function} is the vector valued Function\n\ +@item @var{Index} contains the index of the scalar field to extract.\ +Index starts from 1. \n\ +@end itemize\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\ @@ -20,7 +31,7 @@ { int nargin = args.length (); - octave_value retval=0; + octave_value retval; if (nargin < 3 || nargin > 3) print_usage (); @@ -55,6 +66,7 @@ error ("The size of the functional space and of the vector must agree"); else { + std::cout <<"creating function from vector..."<< std::endl; dolfin::Vector du(myu.length ()); for (std::size_t i = 0; i < myu.length (); ++i) du.setitem (i, myu(i)); @@ -78,11 +90,17 @@ const boost::shared_ptr<const dolfin::Function> & f = fspo.get_pfun (); if (f->value_rank () < 1) - error ("The function you provided isn't a vecotr field"); + error ("Function: The function you provided isn't a vecotr field"); else { - boost::shared_ptr <const dolfin::Function> u (new dolfin::Function((*f)[idx])); - retval = new function (str, u); + std::cout <<"Extracting function..."<< std::endl; + if (idx < 1 || idx > f->value_dimension (0)) + error ("Function: index out of bounds"); + else + { + boost::shared_ptr <const dolfin::Function> u (new dolfin::Function((*f)[idx - 1])); + retval = new function (str, u); + } } } }