annotate src/fem_func.cc @ 49:a4ef215d1eed

Check if size of input parameters agree
author gedeone-octave <marco.vassallo@outlook.com>
date Mon, 22 Jul 2013 15:32:27 +0200
parents c73bca616ca7
children fcfecdd3a9b5
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
48
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
5 DEFUN_DLD (fem_func, args, , "-*- texinfo -*-\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
6 @deftypefn {Function File} {[@var{func}]} = \
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
7 fem_func (@var{Functional Space}, @var{Vector}\n\
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\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
10 @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
11 the vector is defined\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
12 @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
13 for the basis functions of @var{Functional Space}\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
14 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
15 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
16 @seealso{fem_plot, fem_save}\n\
c73bca616ca7 Add texinfo description for the DLD functions
gedeone-octave <marco.vassallo@outlook.com>
parents: 46
diff changeset
17 @end deftypefn")
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
18 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
19
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
20 int nargin = args.length ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
21 octave_value retval=0;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
22
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
23 if (nargin < 2 || nargin > 2)
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
24 print_usage ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
25 else
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
26 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
27 if (! functionspace_type_loaded)
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 functionspace::register_type ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
30 functionspace_type_loaded = true;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
31 mlock ();
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 if (args(0).type_id () == functionspace::static_type_id ())
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
34 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
35 const functionspace & fspo =
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
36 static_cast<const functionspace&> (args(0).get_rep ());
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
37 Array <double> myu = args(1).array_value ();
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
38
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
39 if (!error_state)
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
40 {
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
41 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
42
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
43 if (V->dim () != myu.length ())
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
44 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
45 else
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
46 {
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
47 dolfin::Vector du(myu.length ());
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
48 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
49 du.setitem (i, myu(i));
46
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
50
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
51 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
52 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
53
49
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
54 if (! function_type_loaded)
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
55 {
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
56 function::register_type ();
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
57 function_type_loaded = true;
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
58 mlock ();
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
59 }
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
60
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
61 retval = new function (u);
a4ef215d1eed Check if size of input parameters agree
gedeone-octave <marco.vassallo@outlook.com>
parents: 48
diff changeset
62 }
46
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 }
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
65 }
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
66 return retval;
a64e195d0611 Wrapper class for dolfin::Function
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff changeset
67 }