Mercurial > fem-fenics-eugenio
annotate src/Function.cc @ 253:5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
* src/dolfin_compat.h: use a macro to set the correct shared_ptr (std or boost)
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Tue, 29 Jul 2014 18:05:56 +0200 |
parents | a57001686abb |
children | 8fe68d94ab76 |
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" |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
21 #include "dolfin_compat.h" |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
22 |
78
670a5d91c397
Rename the function visible from the user accordingly to dolfin interface.
gedeone-octave <marcovass89@hotmail.it>
parents:
61
diff
changeset
|
23 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
|
24 @deftypefn {Function File} {[@var{func}]} = \ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
25 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
|
26 @var{Vector} (or @var{index}))\n\ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
27 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
|
28 a component from a vectorial field.\n\ |
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
29 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
|
30 @itemize @bullet \n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
31 @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
|
32 @itemize @bullet \n\ |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
33 @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
|
34 @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
|
35 the vector is defined\n\ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
36 @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
|
37 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
|
38 @end itemize\n\ |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
39 @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
|
40 @itemize @bullet \n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
41 @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
|
42 @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
|
43 @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
|
44 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
|
45 @end itemize\n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
46 @end itemize \n\ |
182
b40f22aad4af
Improve the documentation for the pkg release.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
47 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
|
48 function @var{Vector} which can be plotted or saved or passed as argument \ |
240
a57001686abb
Document function evaluation
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
182
diff
changeset
|
49 for a variational problem. Moreover, it is possible to evaluate it on points \ |
a57001686abb
Document function evaluation
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
182
diff
changeset
|
50 of its domain.\n\ |
143
9486cbdc0a2e
Maint: update the documentation
gedeone-octave <marcovass89@hotmail.it>
parents:
119
diff
changeset
|
51 @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
|
52 @end deftypefn") |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
53 { |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
54 |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
55 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
|
56 octave_value retval; |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
57 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
58 if (nargin < 3 || nargin > 3) |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
59 print_usage (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
60 else |
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 if (! functionspace_type_loaded) |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
63 { |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
64 functionspace::register_type (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
65 functionspace_type_loaded = true; |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
66 mlock (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
67 } |
87
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 if (! function_type_loaded) |
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 function::register_type (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
72 function_type_loaded = true; |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
73 mlock (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
74 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
75 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
76 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
|
77 { |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
78 std::string str = args(0).string_value (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
79 const functionspace & fspo = |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
80 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
|
81 Array <double> myu = args(2).array_value (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
82 |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
83 if (!error_state) |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
84 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
85 const SHARED_PTR <const dolfin::FunctionSpace> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
86 & V = fspo.get_pfsp (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
87 |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
88 if (V->dim () != myu.length ()) |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
89 error("The size of the functional space \ |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
90 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
|
91 else |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
92 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
93 #ifdef LATEST_DOLFIN |
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
94 dolfin::Vector du (MPI_COMM_WORLD, myu.length ()); |
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
95 #else |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
96 dolfin::Vector du(myu.length ()); |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
97 #endif |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
98 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
|
99 du.setitem (i, myu(i)); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
100 |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
101 SHARED_PTR <dolfin::Vector> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
102 uu (new dolfin::Vector(du)); |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
103 |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
104 SHARED_PTR <const dolfin::Function> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
105 u (new dolfin::Function(V, uu)); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
106 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
107 retval = new function (str, u); |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
108 } |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
109 } |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
110 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
111 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
|
112 { |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
113 std::string str = args(0).string_value (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
114 const function & fspo = |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
115 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
|
116 int idx = args(2).int_value (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
117 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
118 if (!error_state) |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
119 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
120 const SHARED_PTR <const dolfin::Function> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
121 & f = fspo.get_pfun (); |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
122 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
123 if (f->value_rank () < 1) |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
124 error ("Function: The function you provided\ |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
125 isn't a vecotr field"); |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
126 else |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
127 { |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
128 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
|
129 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
|
130 else |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
131 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
240
diff
changeset
|
132 SHARED_PTR <const dolfin::Function> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
133 u (new dolfin::Function((*f)[idx - 1])); |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
168
diff
changeset
|
134 |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
135 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
|
136 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
137 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
138 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
139 } |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
140 } |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
141 return retval; |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
142 } |