Mercurial > fem-fenics-eugenio
changeset 39:7909b9af405c
New class and function used to manage coefficient of the variational form
author | gedeone-octave <marco.vassallo@outlook.com> |
---|---|
date | Thu, 18 Jul 2013 14:57:55 +0200 |
parents | 891ee2720e65 |
children | df41c72f4da4 |
files | src/coefficient.h src/fem_coeff.cc |
diffstat | 2 files changed, 105 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/coefficient.h Thu Jul 18 14:57:55 2013 +0200 @@ -0,0 +1,57 @@ +/* + Copyright (C) 2013 Marco Vassallo + + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _COEFFICIENT_OCTAVE_ +#define _COEFFICIENT_OCTAVE_ + +#include "expression.h" + +class coefficient : public octave_base_value +{ + + public: + coefficient () : octave_base_value () {} + + coefficient (std::string & _str, octave_fcn_handle & _f) : + str (_str), expr (new expression (_f)) {} + + void print (std::ostream& os, bool pr_as_read_syntax = false) const + { + os << "Coefficient " << str << " : " << expr->str (true) << std::endl; + } + + ~coefficient (void) {} + + bool is_defined (void) const { return true; } + + const boost::shared_ptr <const expression> & get_expr (void) const + { return expr; } + + const std::string & get_str (void) const + { return str; } + + private: + + std::string str; + boost::shared_ptr <const expression> expr; + + DECLARE_OCTAVE_ALLOCATOR; + DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; + +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fem_coeff.cc Thu Jul 18 14:57:55 2013 +0200 @@ -0,0 +1,48 @@ +/* + Copyright (C) 2013 Marco Vassallo + + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "coefficient.h" + +DEFUN_DLD (fem_coeff, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{f}]} = \ +fem_coeff (@var{name}, @var{Functio handle}\n\ +The input parameters are\n\ +@itemize @bullet \n\ +@item @var{name} is the name of the coefficient declared in the .ufl file\n\ +@item @var{Functio handle} is a function handle which contains the expression\ +that we want to apply for our coefficient\n\ +The output @var{f} is an object which contains a representation of the function\n\ +@seealso{fem_init_mesh, fem_fs}\n\ +@end deftypefn") +{ + int nargin = args.length (); + octave_value retval=0; + + if (nargin < 2 || nargin > 2) + print_usage (); + else + { + std::string str = args(0).string_value (); + octave_fcn_handle * fh = args(1).fcn_handle_value (); + + if (!error_state) + retval = new coefficient (str, *fh); + + } + + return retval; +}