annotate src/Function.cc @ 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 670a5d91c397
children 4b8b705e22a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
1 #include <dolfin.h>
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
2 #include "functionspace.h"
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
3 #include "function.h"
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
4
78
670a5d91c397 Rename the function visible from the user accordingly to dolfin interface.
gedeone-octave <marcovass89@hotmail.it>
parents: 61
diff changeset
5 DEFUN_DLD (Function, args, , "-*- texinfo -*-\n\
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
6 @deftypefn {Function File} {[@var{func}]} = \
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
7 fem_func (@var{name}, @var{Functional Space}, @var{Vector})\n\
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
8 The input parameters are\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
9 @itemize @bullet \n\
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
10 @item @var{name} is a string representing the name of the function\n\
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
11 @item @var{Functional Space} is the fem-fenics functional space where\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
12 the vector is defined\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
13 @item @var{Vector} contains the value of the coefficients\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
14 for the basis functions of @var{Functional Space}\n\
50
fcfecdd3a9b5 Maint: improve the documentation
gedeone-octave <marco.vassallo@outlook.com>
parents: 49
diff changeset
15 @end itemize\n\
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
16 The output @var{func} is an object which contain a representation of the\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
17 function @var{Vector} which can be plotted or saved.\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
18 @seealso{fem_plot, fem_save}\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
19 @end deftypefn")
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
20 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
21
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
22 int nargin = args.length ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
23 octave_value retval=0;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
24
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
25 if (nargin < 3 || nargin > 3)
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
26 print_usage ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
27 else
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
28 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
29 if (! functionspace_type_loaded)
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
30 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
31 functionspace::register_type ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
32 functionspace_type_loaded = true;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
33 mlock ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
34 }
87
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
35
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
36 if (! function_type_loaded)
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
37 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
38 function::register_type ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
39 function_type_loaded = true;
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
40 mlock ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
41 }
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
42
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
43 if (args(1).type_id () == functionspace::static_type_id ())
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
44 {
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
45 std::string str = args(0).string_value ();
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
46 const functionspace & fspo =
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
47 static_cast<const functionspace&> (args(1).get_rep ());
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
48 Array <double> myu = args(2).array_value ();
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
49
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
50 if (!error_state)
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
51 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
52 const boost::shared_ptr<const dolfin::FunctionSpace> & V = fspo.get_pfsp ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
53
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
54 if (V->dim () != myu.length ())
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
55 error ("The size of the functional space and of the vector must agree");
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
56 else
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
57 {
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
58 dolfin::Vector du(myu.length ());
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
59 for (std::size_t i = 0; i < myu.length (); ++i)
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
60 du.setitem (i, myu(i));
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
61
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
62 boost::shared_ptr<dolfin::Vector> uu (new dolfin::Vector(du));
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
63 boost::shared_ptr <const dolfin::Function> u (new dolfin::Function(V, uu));
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
64
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
65 retval = new function (str, u);
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
66 }
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
67 }
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
68 }
87
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
69 else if (args(1).type_id () == function::static_type_id ())
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
70 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
71 std::string str = args(0).string_value ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
72 const function & fspo =
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
73 static_cast<const function&> (args(1).get_rep ());
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
74 int idx = args(2).int_value ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
75
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
76 if (!error_state)
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
77 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
78 const boost::shared_ptr<const dolfin::Function> & f = fspo.get_pfun ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
79
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
80 if (f->value_rank () < 1)
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
81 error ("The function you provided isn't a vecotr field");
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
82 else
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
83 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
84 boost::shared_ptr <const dolfin::Function> u (new dolfin::Function((*f)[idx]));
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
85 retval = new function (str, u);
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
86 }
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
87 }
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
88 }
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
89 }
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
90 return retval;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
91 }