Mercurial > fem-fenics-eugenio
changeset 61:93e538063278
Add a string field to the class function
author | gedeone-octave <marco.vassallo@outlook.com> |
---|---|
date | Fri, 26 Jul 2013 10:20:10 +0200 |
parents | 21eff545a004 |
children | a00f95c0b048 |
files | bin/codeCreator.py src/fem_func.cc src/function.h |
diffstat | 3 files changed, 59 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/codeCreator.py Thu Jul 25 12:53:55 2013 +0200 +++ b/bin/codeCreator.py Fri Jul 26 10:20:10 2013 +0200 @@ -48,22 +48,22 @@ lhs : fem_lhs_$name.oct fem_fs_$name.o: fem_fs_$name.cc - $(MKOCTFILE) -I$(DIR) -I. $(CPPFLAGS) $< -c $@ + $(MKOCTFILE) -I$(DIR) -I. $(CPPFLAGS) $(LDFLAGS) $< -c $@ fem_fs_$name.oct: $name.h fem_fs_$name.o - $(MKOCTFILE) -s fem_fs_$name.o $(DIR)fem_init_env.o $(LIBS) -o $@ + $(MKOCTFILE) -s fem_fs_$name.o $(DIR)fem_init_env.o $(LDFLAGS) $(LIBS) -o $@ fem_rhs_$name.o: fem_rhs_$name.cc - $(MKOCTFILE) -I$(DIR) -I. $(CPPFLAGS) $< -c $@ + $(MKOCTFILE) -I$(DIR) -I. $(LDFLAGS) $(CPPFLAGS) $< -c $@ fem_rhs_$name.oct: $name.h fem_rhs_$name.o - $(MKOCTFILE) -s fem_rhs_$name.o $(DIR)fem_init_env.o $(LIBS) -o $@ + $(MKOCTFILE) -s fem_rhs_$name.o $(DIR)fem_init_env.o $(LDFLAGS) $(LIBS) -o $@ fem_lhs_$name.o: fem_lhs_$name.cc - $(MKOCTFILE) -I$(DIR) -I. $(CPPFLAGS) $< -c $@ + $(MKOCTFILE) -I$(DIR) -I. $(LDFLAGS) $(CPPFLAGS) $< -c $@ fem_lhs_$name.oct: $name.h fem_lhs_$name.o - $(MKOCTFILE) -s fem_lhs_$name.o $(DIR)fem_init_env.o $(LIBS) -o $@ + $(MKOCTFILE) -s fem_lhs_$name.o $(DIR)fem_init_env.o $(LDFLAGS) $(LIBS) -o $@ $name.h: $name.ufl $(FFC) -l dolfin $name.ufl @@ -194,6 +194,13 @@ mlock (); } + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + for (std::size_t i = 1; i < nargin; ++i) { if (args(i).type_id () == coefficient::static_type_id ()) @@ -206,6 +213,17 @@ a.set_coefficient (n, pexp); ++nc; } + + if (args(i).type_id () == function::static_type_id ()) + { + const function & fun + = static_cast <const function&> (args(i).get_rep ()); + + std::size_t n = a.coefficient_number (fun.get_str ()); + const boost::shared_ptr<const dolfin::Function> & pfun = fun.get_pfun (); + a.set_coefficient (n, pfun); + ++nc; + } } if (nc != ncoef) @@ -326,6 +344,14 @@ coefficient_type_loaded = true; mlock (); } + + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + for (std::size_t i = 1; i < nargin; ++i) { if (args(i).type_id () == coefficient::static_type_id ()) @@ -338,6 +364,17 @@ L.set_coefficient (n, pexp); ++nc; } + + if (args(i).type_id () == function::static_type_id ()) + { + const function & fun + = static_cast <const function&> (args(i).get_rep ()); + + std::size_t n = L.coefficient_number (fun.get_str ()); + const boost::shared_ptr<const dolfin::Function> & pfun = fun.get_pfun (); + L.set_coefficient (n, pfun); + ++nc; + } } if (nc != ncoef)
--- a/src/fem_func.cc Thu Jul 25 12:53:55 2013 +0200 +++ b/src/fem_func.cc Fri Jul 26 10:20:10 2013 +0200 @@ -4,9 +4,10 @@ DEFUN_DLD (fem_func, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{func}]} = \ -fem_func (@var{Functional Space}, @var{Vector}\n\ +fem_func (@var{name}, @var{Functional Space}, @var{Vector})\n\ The input parameters are\n\ @itemize @bullet \n\ +@item @var{name} is a string representing the name of the function\n\ @item @var{Functional Space} is the fem-fenics functional space where\ the vector is defined\n\ @item @var{Vector} contains the value of the coefficients\ @@ -21,7 +22,7 @@ int nargin = args.length (); octave_value retval=0; - if (nargin < 2 || nargin > 2) + if (nargin < 3 || nargin > 3) print_usage (); else { @@ -31,11 +32,12 @@ functionspace_type_loaded = true; mlock (); } - if (args(0).type_id () == functionspace::static_type_id ()) + if (args(1).type_id () == functionspace::static_type_id ()) { + std::string str = args(0).string_value (); const functionspace & fspo = - static_cast<const functionspace&> (args(0).get_rep ()); - Array <double> myu = args(1).array_value (); + static_cast<const functionspace&> (args(1).get_rep ()); + Array <double> myu = args(2).array_value (); if (!error_state) { @@ -59,7 +61,7 @@ mlock (); } - retval = new function (u); + retval = new function (str, u); } } }
--- a/src/function.h Thu Jul 25 12:53:55 2013 +0200 +++ b/src/function.h Fri Jul 26 10:20:10 2013 +0200 @@ -30,13 +30,13 @@ function () : octave_base_value (), fun () { } - function (boost::shared_ptr <const dolfin::Function> _fun) : - octave_base_value (), fun (_fun) { } + function (std::string & _str, boost::shared_ptr <const dolfin::Function> _fun) : + octave_base_value (), str(_str), fun (_fun) { } void print (std::ostream& os, bool pr_as_read_syntax = false) const - { os << "Function : " << (*fun).str(true) << std::endl; } + { os << "Function " << str << ": " << fun->str (true) << std::endl; } - ~function(void) {} + ~function(void) { } bool is_defined (void) const { return true; } @@ -52,8 +52,12 @@ fun = boost::shared_ptr<const dolfin::Function> (p); } + const std::string & get_str (void) const + { return str; } + private: + std::string str; boost::shared_ptr <const dolfin::Function> fun; DECLARE_OCTAVE_ALLOCATOR;