annotate src/Function.cc @ 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 d03627091414
children 9486cbdc0a2e
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}]} = \
119
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
7 Function (@var{name}, @var{Functional Space} or @var{Function},\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
8 @var{Vector} or @var{index})\n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
9 These function can be used in two ways\n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
10 @itemize @bullet \n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
11 @item To create a function from a vector. In this case, the arguments are:\n\
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
12 @itemize @bullet \n\
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
13 @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
14 @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
15 the vector is defined\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
16 @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
17 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
18 @end itemize\n\
119
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
19 @item To extract a scalar field from a vectorial one\n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
20 @itemize @bullet \n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
21 @item @var{name} is a string representing the name of the function\n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
22 @item @var{Function} is the vector valued Function\n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
23 @item @var{Index} contains the index of the scalar field to extract.\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
24 Index starts from 1. \n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
25 @end itemize\n\
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
26 @end itemize \n\
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
27 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
28 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
29 @seealso{fem_plot, fem_save}\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
30 @end deftypefn")
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
31 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
32
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
33 int nargin = args.length ();
119
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
34 octave_value retval;
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
35
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
36 if (nargin < 3 || nargin > 3)
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
37 print_usage ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
38 else
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
39 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
40 if (! functionspace_type_loaded)
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
41 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
42 functionspace::register_type ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
43 functionspace_type_loaded = true;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
44 mlock ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
45 }
87
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
46
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
47 if (! function_type_loaded)
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
48 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
49 function::register_type ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
50 function_type_loaded = true;
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
51 mlock ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
52 }
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
53
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
54 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
55 {
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
56 std::string str = args(0).string_value ();
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
57 const functionspace & fspo =
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
58 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
59 Array <double> myu = args(2).array_value ();
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
60
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
61 if (!error_state)
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
62 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
63 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
64
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
65 if (V->dim () != myu.length ())
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
66 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
67 else
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
68 {
119
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
69 std::cout <<"creating function from vector..."<< std::endl;
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
70 dolfin::Vector du(myu.length ());
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
71 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
72 du.setitem (i, myu(i));
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
73
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
74 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
75 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
76
61
93e538063278 Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents: 50
diff changeset
77 retval = new function (str, u);
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
78 }
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
79 }
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
80 }
87
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
81 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
82 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
83 std::string str = args(0).string_value ();
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
84 const function & fspo =
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
85 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
86 int idx = args(2).int_value ();
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 if (!error_state)
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
89 {
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
90 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
91
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
92 if (f->value_rank () < 1)
119
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
93 error ("Function: The function you provided isn't a vecotr field");
87
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
94 else
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
95 {
119
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
96 std::cout <<"Extracting function..."<< std::endl;
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
97 if (idx < 1 || idx > f->value_dimension (0))
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
98 error ("Function: index out of bounds");
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
99 else
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
100 {
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
101 boost::shared_ptr <const dolfin::Function> u (new dolfin::Function((*f)[idx - 1]));
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
102 retval = new function (str, u);
4b8b705e22a7 Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents: 87
diff changeset
103 }
87
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
104 }
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
105 }
d03627091414 New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents: 78
diff changeset
106 }
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
107 }
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
108 return retval;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
109 }