Mercurial > fem-fenics-eugenio
comparison src/function.h @ 234:94895618701f
Add function evaluation with coordinates inside brackets
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Sat, 21 Jun 2014 16:07:42 +0200 |
parents | 9e944b0d0fc8 |
children | 568aff85dfa9 |
comparison
equal
deleted
inserted
replaced
233:b07ec30369ab | 234:94895618701f |
---|---|
20 | 20 |
21 #include <memory> | 21 #include <memory> |
22 #include <vector> | 22 #include <vector> |
23 #include <dolfin.h> | 23 #include <dolfin.h> |
24 #include <octave/oct.h> | 24 #include <octave/oct.h> |
25 #include <octave/parse.h> | |
25 | 26 |
26 class function : public octave_base_value | 27 class function : public octave_base_value |
27 { | 28 { |
28 | 29 |
29 public: | 30 public: |
32 : octave_base_value (), fun () {} | 33 : octave_base_value (), fun () {} |
33 | 34 |
34 function (std::string & _str, | 35 function (std::string & _str, |
35 boost::shared_ptr <const dolfin::Function> _fun) | 36 boost::shared_ptr <const dolfin::Function> _fun) |
36 : octave_base_value (), str(_str), fun (_fun) {} | 37 : octave_base_value (), str(_str), fun (_fun) {} |
38 | |
39 function (function const& _func) | |
40 : octave_base_value () | |
41 { | |
42 str = _func.get_str (); | |
43 fun = _func.get_pfun (); | |
44 } | |
37 | 45 |
38 void | 46 void |
39 print (std::ostream& os, | 47 print (std::ostream& os, |
40 bool pr_as_read_syntax = false) const | 48 bool pr_as_read_syntax = false) const |
41 { os << "Function " << str << ": " << fun->str (true) << std::endl; } | 49 { os << "Function " << str << ": " << fun->str (true) << std::endl; } |
63 | 71 |
64 const std::string & | 72 const std::string & |
65 get_str (void) const | 73 get_str (void) const |
66 { return str; } | 74 { return str; } |
67 | 75 |
76 octave_value | |
77 subsref (const std::string& type, | |
78 const std::list<octave_value_list>& idx) | |
79 { | |
80 octave_value retval; | |
81 | |
82 switch (type[0]) | |
83 { | |
84 case '(': | |
85 { | |
86 std::list<octave_value_list> args; | |
87 args.push_back (octave_value (new function (*this))); | |
88 args.push_back (idx.front ()); | |
89 retval = feval ("feval", args); | |
90 } | |
91 break; | |
92 | |
93 case '{': | |
94 case '.': | |
95 { | |
96 std::string nm = type_name (); | |
97 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); | |
98 } | |
99 break; | |
100 | |
101 default: | |
102 panic_impossible (); | |
103 } | |
104 | |
105 return retval; | |
106 } | |
107 | |
108 octave_value_list | |
109 subsref (const std::string& type, | |
110 const std::list<octave_value_list>& idx, | |
111 int) | |
112 { | |
113 octave_value_list retval; | |
114 retval = subsref (type, idx); | |
115 return retval; | |
116 } | |
117 | |
68 private: | 118 private: |
69 | 119 |
70 std::string str; | 120 std::string str; |
71 boost::shared_ptr <const dolfin::Function> fun; | 121 boost::shared_ptr <const dolfin::Function> fun; |
72 | 122 |