changeset 75:d6df5cc8ef53

Improve the expression class to deal also with vector fields. * Expression.h: new constructor for vector field * coefficient.h: new constructor for the expression member * fem_bc.cc, fem_coeff.cc: initialize the dolfin::Expression accordingly to the number of input passed from the user
author gedeone-octave <marcovass89@hotmail.it>
date Fri, 02 Aug 2013 22:55:42 +0200
parents d123adbe296b
children 6cb2a3e3be68
files src/coefficient.h src/expression.h src/fem_bc.cc src/fem_coeff.cc
diffstat 4 files changed, 37 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/coefficient.h	Fri Aug 02 22:51:34 2013 +0200
+++ b/src/coefficient.h	Fri Aug 02 22:55:42 2013 +0200
@@ -27,14 +27,17 @@
   coefficient () : octave_base_value () {}
 
   coefficient (std::string & _str, octave_fcn_handle & _f) :
-               str (_str), expr (new expression (_f)) {}
+               str (_str), expr (new expression (_f)) { }
+
+  coefficient (std::string & _str, octave_fcn_handle & _f, std::size_t _n) :
+               str (_str), expr (new expression (_f, _n)) { }
 
   void print (std::ostream& os, bool pr_as_read_syntax = false) const
   {
     os << "Coefficient " << str << " : " <<  expr->str (true) << std::endl;
   }
 
-  ~coefficient (void) {}
+  ~coefficient (void) { }
 
   bool is_defined (void) const { return true; }
 
--- a/src/expression.h	Fri Aug 02 22:51:34 2013 +0200
+++ b/src/expression.h	Fri Aug 02 22:55:42 2013 +0200
@@ -35,6 +35,9 @@
   expression (octave_fcn_handle & _f) :
              dolfin::Expression (), f (new octave_fcn_handle (_f)) {}
 
+  expression (octave_fcn_handle & _f, std::size_t _n) :
+             dolfin::Expression (_n), f (new octave_fcn_handle (_f)) {}
+
   ~expression (void) { delete f; }
 
 
@@ -44,12 +47,14 @@
     b.resize (x.size ());
     for (std::size_t i = 0; i < x.size (); ++i)
       b(i) = x[i];
-    octave_value_list res = feval (f->function_value (), b);
-    values[0] = res(0).double_value ();
+    octave_value_list tmp = feval (f->function_value (), b);
+    Array<double> res = tmp(0).array_value ();
+
+    for (std::size_t i = 0; i < values.size (); ++i)
+      values[i] = res(i);
   }
 
  private:
   octave_fcn_handle * f;
 };
-
 #endif
--- a/src/fem_bc.cc	Fri Aug 02 22:51:34 2013 +0200
+++ b/src/fem_bc.cc	Fri Aug 02 22:55:42 2013 +0200
@@ -37,7 +37,7 @@
 @end deftypefn")
 {
   int nargin = args.length ();
-  octave_value retval=0;
+  octave_value retval;
 
   if (nargin < 3 || nargin > 3)
     print_usage ();
@@ -60,7 +60,18 @@
           if (!error_state)
             {
               const boost::shared_ptr <const dolfin::FunctionSpace> & V (fspo.get_pfsp ());
-              const expression * pf = new expression (*fh);
+
+              octave_value_list b (3, 1);
+              octave_value_list tmp = feval (fh->function_value (), b);
+              Array<double> res = tmp(0).array_value ();
+              std::size_t l = res.length ();
+
+              expression * pf;
+              if (l > 1)
+                pf = new expression (*fh, l);
+              else
+                pf = new expression (*fh);
+
               boost::shared_ptr<const expression> f (pf);
 
               if (! boundarycondition_type_loaded)
--- a/src/fem_coeff.cc	Fri Aug 02 22:51:34 2013 +0200
+++ b/src/fem_coeff.cc	Fri Aug 02 22:55:42 2013 +0200
@@ -48,7 +48,17 @@
         }
 
       if (!error_state)
-        retval = new coefficient (str, *fh);
+        {
+          octave_value_list b (3, 1);
+          octave_value_list tmp = feval (fh->function_value (), b);
+          Array<double> res = tmp(0).array_value ();
+          std::size_t l = res.length ();
+
+          if (l > 1)
+            retval = new coefficient (str, *fh, l);
+          else
+            retval = new coefficient (str, *fh);
+        }
 
    }