Mercurial > fem-fenics-eugenio
changeset 87:d03627091414
New constructor for the dld function Function
* Function.cc: added the possibility to build a Function from an existing one
extracting a subfunction, which is helpful especially for
extracting scalar field from vector one.
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Mon, 05 Aug 2013 11:42:23 +0200 |
parents | 66e4aa87c9a1 |
children | 6c75701cf394 |
files | src/Function.cc |
diffstat | 1 files changed, 28 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Function.cc Mon Aug 05 11:39:47 2013 +0200 +++ b/src/Function.cc Mon Aug 05 11:42:23 2013 +0200 @@ -32,6 +32,14 @@ functionspace_type_loaded = true; mlock (); } + + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + if (args(1).type_id () == functionspace::static_type_id ()) { std::string str = args(0).string_value (); @@ -54,17 +62,30 @@ 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); } } } + else if (args(1).type_id () == function::static_type_id ()) + { + std::string str = args(0).string_value (); + const function & fspo = + static_cast<const function&> (args(1).get_rep ()); + int idx = args(2).int_value (); + + if (!error_state) + { + 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"); + else + { + boost::shared_ptr <const dolfin::Function> u (new dolfin::Function((*f)[idx])); + retval = new function (str, u); + } + } + } } return retval; }