Mercurial > fem-fenics-eugenio
annotate src/Function.cc @ 182:b40f22aad4af
Improve the documentation for the pkg release.
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Fri, 08 Nov 2013 00:29:56 +0000 |
parents | 9e944b0d0fc8 |
children | a57001686abb |
rev | line source |
---|---|
151 | 1 /* |
2 Copyright (C) 2013 Marco Vassallo <gedeone-octave@users.sourceforge.net> | |
3 | |
4 This program is free software; you can redistribute it and/or modify it under | |
5 the terms of the GNU General Public License as published by the Free Software | |
6 Foundation; either version 3 of the License, or (at your option) any later | |
7 version. | |
8 | |
9 This program is distributed in the hope that it will be useful, but WITHOUT | |
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
12 details. | |
13 | |
14 You should have received a copy of the GNU General Public License along with | |
15 this program; if not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
18 #include <dolfin.h> |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
19 #include "functionspace.h" |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
20 #include "function.h" |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
21 |
78
670a5d91c397
Rename the function visible from the user accordingly to dolfin interface.
gedeone-octave <marcovass89@hotmail.it>
parents:
61
diff
changeset
|
22 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
|
23 @deftypefn {Function File} {[@var{func}]} = \ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
24 Function (@var{name}, @var{FunctionSpace} (or @var{Function}),\ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
25 @var{Vector} (or @var{index}))\n\ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
26 Initialize an object with the values specified in a vector or extracting \ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
27 a component from a vectorial field.\n\ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
28 This function can be used in two different ways\n\ |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
29 @itemize @bullet \n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
30 @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
|
31 @itemize @bullet \n\ |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
32 @item @var{name} is a string representing the name of the function\n\ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
33 @item @var{FunctionSpace} is the fem-fenics function space where \ |
48
c73bca616ca7
Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents:
46
diff
changeset
|
34 the vector is defined\n\ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
35 @item @var{Vector} specifies the values of the coefficients\ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
36 for each basisc function of the @var{FunctioSpace}\n\ |
50
fcfecdd3a9b5
Maint: improve the documentation
gedeone-octave <marco.vassallo@outlook.com>
parents:
49
diff
changeset
|
37 @end itemize\n\ |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
38 @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
|
39 @itemize @bullet \n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
40 @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
|
41 @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
|
42 @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
|
43 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
|
44 @end itemize\n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
45 @end itemize \n\ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
46 The output @var{func} is an object which contains a representation of the \ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
47 function @var{Vector} which can be plotted or saved or passed as argument \ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
48 for a variational problem.\n\ |
143
9486cbdc0a2e
Maint: update the documentation
gedeone-octave <marcovass89@hotmail.it>
parents:
119
diff
changeset
|
49 @seealso{Constant, Expression, plot, save}\n\ |
48
c73bca616ca7
Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents:
46
diff
changeset
|
50 @end deftypefn") |
46
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 |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
53 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
|
54 octave_value retval; |
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 if (nargin < 3 || nargin > 3) |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
57 print_usage (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
58 else |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
59 { |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
60 if (! functionspace_type_loaded) |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
61 { |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
62 functionspace::register_type (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
63 functionspace_type_loaded = true; |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
64 mlock (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
65 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
66 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
67 if (! function_type_loaded) |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
68 { |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
69 function::register_type (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
70 function_type_loaded = true; |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
71 mlock (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
72 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
73 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
74 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
|
75 { |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
76 std::string str = args(0).string_value (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
77 const functionspace & fspo = |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
78 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
|
79 Array <double> myu = args(2).array_value (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
80 |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
81 if (!error_state) |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
82 { |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
83 const boost::shared_ptr<const dolfin::FunctionSpace> |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
84 & V = fspo.get_pfsp (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
85 |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
86 if (V->dim () != myu.length ()) |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
87 error("The size of the functional space \ |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
88 and of the vector must agree"); |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
89 else |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
90 { |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
91 dolfin::Vector du(myu.length ()); |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
92 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
|
93 du.setitem (i, myu(i)); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
94 |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
95 boost::shared_ptr<dolfin::Vector> |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
96 uu (new dolfin::Vector(du)); |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
97 |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
98 boost::shared_ptr <const dolfin::Function> |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
99 u (new dolfin::Function(V, uu)); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
100 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
101 retval = new function (str, u); |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
102 } |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
103 } |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
104 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
105 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
|
106 { |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
107 std::string str = args(0).string_value (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
108 const function & fspo = |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
109 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
|
110 int idx = args(2).int_value (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
111 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
112 if (!error_state) |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
113 { |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
114 const boost::shared_ptr<const dolfin::Function> |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
115 & f = fspo.get_pfun (); |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
116 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
117 if (f->value_rank () < 1) |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
118 error ("Function: The function you provided\ |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
119 isn't a vecotr field"); |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
120 else |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
121 { |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
122 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
|
123 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
|
124 else |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
125 { |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
126 boost::shared_ptr <const dolfin::Function> |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
127 u (new dolfin::Function((*f)[idx - 1])); |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
128 |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
129 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
|
130 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
131 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
132 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
133 } |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
134 } |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
135 return retval; |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
136 } |