comparison 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
comparison
equal deleted inserted replaced
252:7f33554e439a 253:5e9b5bbdc56b
16 */ 16 */
17 17
18 #include <dolfin.h> 18 #include <dolfin.h>
19 #include "functionspace.h" 19 #include "functionspace.h"
20 #include "function.h" 20 #include "function.h"
21 #include "dolfin_compat.h"
21 22
22 DEFUN_DLD (Function, args, , "-*- texinfo -*-\n\ 23 DEFUN_DLD (Function, args, , "-*- texinfo -*-\n\
23 @deftypefn {Function File} {[@var{func}]} = \ 24 @deftypefn {Function File} {[@var{func}]} = \
24 Function (@var{name}, @var{FunctionSpace} (or @var{Function}),\ 25 Function (@var{name}, @var{FunctionSpace} (or @var{Function}),\
25 @var{Vector} (or @var{index}))\n\ 26 @var{Vector} (or @var{index}))\n\
79 static_cast<const functionspace&> (args(1).get_rep ()); 80 static_cast<const functionspace&> (args(1).get_rep ());
80 Array <double> myu = args(2).array_value (); 81 Array <double> myu = args(2).array_value ();
81 82
82 if (!error_state) 83 if (!error_state)
83 { 84 {
84 const boost::shared_ptr<const dolfin::FunctionSpace> 85 const SHARED_PTR <const dolfin::FunctionSpace>
85 & V = fspo.get_pfsp (); 86 & V = fspo.get_pfsp ();
86 87
87 if (V->dim () != myu.length ()) 88 if (V->dim () != myu.length ())
88 error("The size of the functional space \ 89 error("The size of the functional space \
89 and of the vector must agree"); 90 and of the vector must agree");
90 else 91 else
91 { 92 {
93 #ifdef LATEST_DOLFIN
94 dolfin::Vector du (MPI_COMM_WORLD, myu.length ());
95 #else
92 dolfin::Vector du(myu.length ()); 96 dolfin::Vector du(myu.length ());
97 #endif
93 for (std::size_t i = 0; i < myu.length (); ++i) 98 for (std::size_t i = 0; i < myu.length (); ++i)
94 du.setitem (i, myu(i)); 99 du.setitem (i, myu(i));
95 100
96 boost::shared_ptr<dolfin::Vector> 101 SHARED_PTR <dolfin::Vector>
97 uu (new dolfin::Vector(du)); 102 uu (new dolfin::Vector(du));
98 103
99 boost::shared_ptr <const dolfin::Function> 104 SHARED_PTR <const dolfin::Function>
100 u (new dolfin::Function(V, uu)); 105 u (new dolfin::Function(V, uu));
101 106
102 retval = new function (str, u); 107 retval = new function (str, u);
103 } 108 }
104 } 109 }
110 static_cast<const function&> (args(1).get_rep ()); 115 static_cast<const function&> (args(1).get_rep ());
111 int idx = args(2).int_value (); 116 int idx = args(2).int_value ();
112 117
113 if (!error_state) 118 if (!error_state)
114 { 119 {
115 const boost::shared_ptr<const dolfin::Function> 120 const SHARED_PTR <const dolfin::Function>
116 & f = fspo.get_pfun (); 121 & f = fspo.get_pfun ();
117 122
118 if (f->value_rank () < 1) 123 if (f->value_rank () < 1)
119 error ("Function: The function you provided\ 124 error ("Function: The function you provided\
120 isn't a vecotr field"); 125 isn't a vecotr field");
122 { 127 {
123 if (idx < 1 || idx > f->value_dimension (0)) 128 if (idx < 1 || idx > f->value_dimension (0))
124 error ("Function: index out of bounds"); 129 error ("Function: index out of bounds");
125 else 130 else
126 { 131 {
127 boost::shared_ptr <const dolfin::Function> 132 SHARED_PTR <const dolfin::Function>
128 u (new dolfin::Function((*f)[idx - 1])); 133 u (new dolfin::Function((*f)[idx - 1]));
129 134
130 retval = new function (str, u); 135 retval = new function (str, u);
131 } 136 }
132 } 137 }