Mercurial > fem-fenics-eugenio
annotate src/Function.cc @ 151:5fe2a157f4eb
Update GPL to v3
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Wed, 11 Sep 2013 08:50:35 +0200 |
parents | 9486cbdc0a2e |
children | 67944f307560 |
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}]} = \ |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
24 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
|
25 @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
|
26 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
|
27 @itemize @bullet \n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
28 @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
|
29 @itemize @bullet \n\ |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
30 @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
|
31 @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
|
32 the vector is defined\n\ |
c73bca616ca7
Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents:
46
diff
changeset
|
33 @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
|
34 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
|
35 @end itemize\n\ |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
36 @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
|
37 @itemize @bullet \n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
38 @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
|
39 @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
|
40 @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
|
41 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
|
42 @end itemize\n\ |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
43 @end itemize \n\ |
48
c73bca616ca7
Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents:
46
diff
changeset
|
44 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
|
45 function @var{Vector} which can be plotted or saved.\n\ |
143
9486cbdc0a2e
Maint: update the documentation
gedeone-octave <marcovass89@hotmail.it>
parents:
119
diff
changeset
|
46 @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
|
47 @end deftypefn") |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
48 { |
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 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
|
51 octave_value retval; |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
52 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
53 if (nargin < 3 || nargin > 3) |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
54 print_usage (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
55 else |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
56 { |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
57 if (! functionspace_type_loaded) |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
58 { |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
59 functionspace::register_type (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
60 functionspace_type_loaded = true; |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
61 mlock (); |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
62 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
63 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
64 if (! function_type_loaded) |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
65 { |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
66 function::register_type (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
67 function_type_loaded = true; |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
68 mlock (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
69 } |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
70 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
71 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
|
72 { |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
73 std::string str = args(0).string_value (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
74 const functionspace & fspo = |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
75 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
|
76 Array <double> myu = args(2).array_value (); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
77 |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
78 if (!error_state) |
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 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
|
81 |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
82 if (V->dim () != myu.length ()) |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
83 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
|
84 else |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
85 { |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
86 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
|
87 dolfin::Vector du(myu.length ()); |
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
88 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
|
89 du.setitem (i, myu(i)); |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
90 |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
91 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
|
92 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
|
93 |
61
93e538063278
Add a string field to the class function
gedeone-octave <marco.vassallo@outlook.com>
parents:
50
diff
changeset
|
94 retval = new function (str, u); |
49
a4ef215d1eed
Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents:
48
diff
changeset
|
95 } |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
96 } |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
97 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
98 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
|
99 { |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
100 std::string str = args(0).string_value (); |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
101 const function & fspo = |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
102 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
|
103 int idx = args(2).int_value (); |
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 if (!error_state) |
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 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
|
108 |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
109 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
|
110 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
|
111 else |
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
112 { |
119
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 else |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
117 { |
4b8b705e22a7
Added new output messagging and changed index convvenction for extracting
gedeone-octave <marcovass89@hotmail.it>
parents:
87
diff
changeset
|
118 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
|
119 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
|
120 } |
87
d03627091414
New constructor for the dld function Function
gedeone-octave <marcovass89@hotmail.it>
parents:
78
diff
changeset
|
121 } |
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 } |
46
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
124 } |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
125 return retval; |
a64e195d0611
Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
126 } |