Mercurial > fem-fenics-eugenio
comparison src/interpolate.cc @ 221:470586565dc7
Changed order in interpolate signature
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Mon, 19 May 2014 23:18:33 +0200 |
parents | a13b7d744b86 |
children | 958a0e0e8102 |
comparison
equal
deleted
inserted
replaced
220:9adf76893ce4 | 221:470586565dc7 |
---|---|
19 #include "function.h" | 19 #include "function.h" |
20 #include "functionspace.h" | 20 #include "functionspace.h" |
21 | 21 |
22 DEFUN_DLD (interpolate, args, nargout, "-*- texinfo -*-\n\ | 22 DEFUN_DLD (interpolate, args, nargout, "-*- texinfo -*-\n\ |
23 @deftypefn {Function File} @var{interp} = \ | 23 @deftypefn {Function File} @var{interp} = \ |
24 interpolate (@var{Function}, @var{v})\n\ | 24 interpolate (@var{name}, @var{u}, @var{v})\n\ |
25 interpolate (@var{v}, @var{FunctionSpace})\n\ | |
26 Interpolate a function on a FunctionSpace.\n\ | 25 Interpolate a function on a FunctionSpace.\n\ |
27 This function can be used in two ways:\n\ | 26 @var{u} is the Function, Expression or Constant \ |
28 @itemize @bullet\n\ | 27 to interpolate. @var{v} may be a FunctionSpace \ |
29 @item To interpolate a Function, Expression or Constant, \ | 28 or a Function. In the latter case @var{u} is interpolated \ |
30 @var{v}, on the same FunctionSpace of a @var{Function}\n\ | 29 on the same FunctionSpace where @var{v} is defined.\n\ |
31 @item To interpolate a Function, Expression or Constant, \ | 30 Note that @var{name} is optional: if not provided, \ |
32 @var{v}, on a given @var{FunctionSpace}\n\ | 31 it will default to the one assigned to @var{u}.\n\ |
33 @end itemize\n\ | |
34 @seealso{Function, Expression, Constant, FunctionSpace}\n\ | 32 @seealso{Function, Expression, Constant, FunctionSpace}\n\ |
35 @end deftypefn") | 33 @end deftypefn") |
36 { | 34 { |
37 | 35 |
38 int nargin = args.length (); | 36 int nargin = args.length (); |
39 octave_value retval; | 37 octave_value retval; |
40 | 38 |
41 if (nargin < 2 || nargin > 2 || nargout > 1) | 39 if (nargin < 2 || nargin > 3 || nargout > 1) |
42 print_usage (); | 40 print_usage (); |
43 else | 41 else |
44 { | 42 { |
45 if (! function_type_loaded) | 43 if (! function_type_loaded) |
46 { | 44 { |
61 functionspace::register_type (); | 59 functionspace::register_type (); |
62 functionspace_type_loaded = true; | 60 functionspace_type_loaded = true; |
63 mlock (); | 61 mlock (); |
64 } | 62 } |
65 | 63 |
66 if (args(1).type_id () == functionspace::static_type_id ()) | 64 octave_idx_type offset = 0; |
65 std::string name; | |
66 if (args(0).is_string ()) | |
67 { | |
68 name = args(0).string_value (); | |
69 offset = 1; | |
70 } | |
71 | |
72 if (args(1+offset).type_id () == functionspace::static_type_id ()) | |
67 { | 73 { |
68 const functionspace & u1 = | 74 const functionspace & u1 = |
69 static_cast<const functionspace&> (args(1).get_rep ()); | 75 static_cast<const functionspace&> (args(1+offset).get_rep ()); |
70 | 76 |
71 if (! error_state) | 77 if (! error_state) |
72 { | 78 { |
73 boost::shared_ptr<dolfin::Function> | 79 boost::shared_ptr<dolfin::Function> |
74 output (new dolfin::Function (u1.get_pfsp ())); | 80 output (new dolfin::Function (u1.get_pfsp ())); |
75 | 81 |
76 if (args(0).type_id () == function::static_type_id ()) | 82 if (args(0+offset).type_id () == function::static_type_id ()) |
77 { | 83 { |
78 const function & u0 = | 84 const function & u0 = |
79 static_cast<const function&> (args(0).get_rep ()); | 85 static_cast<const function&> (args(0+offset).get_rep ()); |
80 | 86 |
81 if (! error_state) | 87 if (! error_state) |
82 { | 88 { |
83 output->interpolate (u0.get_fun ()); | 89 output->interpolate (u0.get_fun ()); |
84 std::string name = u0.get_str (); | 90 if (name.empty ()) |
91 name = u0.get_str (); | |
85 retval = new function (name, output); | 92 retval = new function (name, output); |
86 } | 93 } |
87 } | 94 } |
88 else if (args(0).type_id () == coefficient::static_type_id ()) | 95 else if (args(0+offset).type_id () == |
96 coefficient::static_type_id ()) | |
89 { | 97 { |
90 const coefficient & u0 = | 98 const coefficient & u0 = |
91 static_cast<const coefficient&> (args(0).get_rep ()); | 99 static_cast<const coefficient&> (args(0+offset).get_rep ()); |
92 | 100 |
93 if (! error_state) | 101 if (! error_state) |
94 { | 102 { |
95 output->interpolate (* u0.get_expr ()); | 103 output->interpolate (* u0.get_expr ()); |
96 std::string name = u0.get_str (); | 104 if (name.empty ()) |
105 name = u0.get_str (); | |
97 retval = new function (name, output); | 106 retval = new function (name, output); |
98 } | 107 } |
99 } | 108 } |
100 else | 109 else |
101 error ("interpolate: invalid arguments"); | 110 error ("interpolate: invalid arguments"); |
102 } | 111 } |
103 } | 112 } |
104 else if (args(0).type_id () == function::static_type_id ()) | 113 else if (args(1+offset).type_id () == function::static_type_id ()) |
105 { | 114 { |
106 const function & u0 = | 115 const function & u0 = |
107 static_cast<const function&> (args(0).get_rep ()); | 116 static_cast<const function&> (args(1+offset).get_rep ()); |
108 | 117 |
109 if (! error_state) | 118 if (! error_state) |
110 { | 119 { |
111 boost::shared_ptr<dolfin::Function> | 120 boost::shared_ptr<dolfin::Function> |
112 output (new dolfin::Function (u0.get_fun ())); | 121 output (new dolfin::Function (u0.get_fun ())); |
113 | 122 |
114 if (args(1).type_id () == function::static_type_id ()) | 123 if (args(0+offset).type_id () == function::static_type_id ()) |
115 { | 124 { |
116 const function & u1 = | 125 const function & u1 = |
117 static_cast<const function&> (args(1).get_rep ()); | 126 static_cast<const function&> (args(0+offset).get_rep ()); |
118 | 127 |
119 if (! error_state) | 128 if (! error_state) |
120 { | 129 { |
121 output->interpolate (u1.get_fun ()); | 130 output->interpolate (u1.get_fun ()); |
122 std::string name = u1.get_str (); | 131 if (name.empty ()) |
132 name = u1.get_str (); | |
123 retval = new function (name, output); | 133 retval = new function (name, output); |
124 } | 134 } |
125 } | 135 } |
126 else if (args(1).type_id () == coefficient::static_type_id ()) | 136 else if (args(0+offset).type_id () == |
137 coefficient::static_type_id ()) | |
127 { | 138 { |
128 const coefficient & u1 = | 139 const coefficient & u1 = |
129 static_cast<const coefficient&> (args(1).get_rep ()); | 140 static_cast<const coefficient&> (args(0+offset).get_rep ()); |
130 | 141 |
131 if (! error_state) | 142 if (! error_state) |
132 { | 143 { |
133 output->interpolate (* u1.get_expr ()); | 144 output->interpolate (* u1.get_expr ()); |
134 std::string name = u1.get_str (); | 145 if (name.empty ()) |
146 name = u1.get_str (); | |
135 retval = new function (name, output); | 147 retval = new function (name, output); |
136 } | 148 } |
137 } | 149 } |
138 else | 150 else |
139 error ("interpolate: invalid arguments"); | 151 error ("interpolate: invalid arguments"); |