# HG changeset patch # User gedeone-octave # Date 1375532944 -7200 # Node ID 670a5d91c397204e6cc3263e6ecf2e93ba3a24f1 # Parent ff95326e6f13754bb98352262f2d1242b7eb09fd Rename the function visible from the user accordingly to dolfin interface. * fem_bc.cc -> DirichletBC.cc * fem_coeff.cc -> Expression.cc * fem_func.cc -> Function.cc diff -r ff95326e6f13 -r 670a5d91c397 src/DirichletBC.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/DirichletBC.cc Sat Aug 03 14:29:04 2013 +0200 @@ -0,0 +1,94 @@ +/* + 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 . +*/ + +#include "boundarycondition.h" +#include "functionspace.h" +#include "expression.h" + +DEFUN_DLD (DirichletBC, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{bc}]} = \ +DirichletBC (@var{Functional Space}, @var{Function handle}, \ +@var{Boundary Label}) \n\ +The input parameters are\n\ +@itemize @bullet \n\ +@item @var{Functional Space} is a fem-fenics functional space where\ +we want to apply the BC\n\ +@item @var{Functio handle} is a function handle which contains the expression\ +that we want to apply on the BC\n\ +@item @var{Boundary} is an Array which specify the label of the \ +sides where the BC is applied\n\ +@end itemize\n\ +The output @var{BC} is an object which contains the boundary conditions\n\ +@seealso{fem_init_mesh, fem_fs}\n\ +@end deftypefn") +{ + int nargin = args.length (); + octave_value retval; + + if (nargin < 3 || nargin > 3) + print_usage (); + else + { + + if (! functionspace_type_loaded) + { + functionspace::register_type (); + functionspace_type_loaded = true; + mlock (); + } + + if (args(0).type_id () == functionspace::static_type_id ()) + { + const functionspace & fspo = static_cast (args(0).get_rep ()); + octave_fcn_handle * fh = args(1).fcn_handle_value (); + Array side = args(2).array_value (); + + if (!error_state) + { + const boost::shared_ptr & V (fspo.get_pfsp ()); + + octave_value_list b (3, 1); + octave_value_list tmp = feval (fh->function_value (), b); + Array 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 f (pf); + + if (! boundarycondition_type_loaded) + { + boundarycondition::register_type (); + boundarycondition_type_loaded = true; + mlock (); + } + + boundarycondition * pbc = new boundarycondition (); + + for (octave_idx_type i = 0; i < side.length (); ++i) + pbc->add_bc (V, f, side(i)); + + retval = octave_value (pbc); + } + } + } + return retval; +} diff -r ff95326e6f13 -r 670a5d91c397 src/Expression.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Expression.cc Sat Aug 03 14:29:04 2013 +0200 @@ -0,0 +1,66 @@ +/* + 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 . +*/ + +#include "coefficient.h" + +DEFUN_DLD (Expression, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{f}]} = \ +Expression (@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\ +@end itemize\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; + + 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 (! coefficient_type_loaded) + { + coefficient::register_type (); + coefficient_type_loaded = true; + mlock (); + } + + if (!error_state) + { + octave_value_list b (3, 1); + octave_value_list tmp = feval (fh->function_value (), b); + Array 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); + } + + } + + return retval; +} diff -r ff95326e6f13 -r 670a5d91c397 src/Function.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Function.cc Sat Aug 03 14:29:04 2013 +0200 @@ -0,0 +1,70 @@ +#include +#include "functionspace.h" +#include "function.h" + +DEFUN_DLD (Function, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{func}]} = \ +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\ +for the basis functions of @var{Functional Space}\n\ +@end itemize\n\ +The output @var{func} is an object which contain a representation of the\ +function @var{Vector} which can be plotted or saved.\n\ +@seealso{fem_plot, fem_save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval=0; + + if (nargin < 3 || nargin > 3) + print_usage (); + else + { + if (! functionspace_type_loaded) + { + functionspace::register_type (); + functionspace_type_loaded = true; + mlock (); + } + if (args(1).type_id () == functionspace::static_type_id ()) + { + std::string str = args(0).string_value (); + const functionspace & fspo = + static_cast (args(1).get_rep ()); + Array myu = args(2).array_value (); + + if (!error_state) + { + const boost::shared_ptr & V = fspo.get_pfsp (); + + if (V->dim () != myu.length ()) + error ("The size of the functional space and of the vector must agree"); + else + { + dolfin::Vector du(myu.length ()); + for (std::size_t i = 0; i < myu.length (); ++i) + du.setitem (i, myu(i)); + + boost::shared_ptr uu (new dolfin::Vector(du)); + boost::shared_ptr u (new dolfin::Function(V, uu)); + + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + + retval = new function (str, u); + } + } + } + } + return retval; +} diff -r ff95326e6f13 -r 670a5d91c397 src/fem_bc.cc --- a/src/fem_bc.cc Fri Aug 02 23:18:01 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - 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 . -*/ - -#include "boundarycondition.h" -#include "functionspace.h" -#include "expression.h" - -DEFUN_DLD (fem_bc, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} {[@var{bc}]} = \ -fem_get_mesh (@var{Functional Space}, @var{Functio handle}, \ -@var{Boundary}) \n\ -The input parameters are\n\ -@itemize @bullet \n\ -@item @var{Functional Space} is a fem-fenics functional space where\ -we want to apply the BC\n\ -@item @var{Functio handle} is a function handle which contains the expression\ -that we want to apply on the BC\n\ -@item @var{Boundary} is an Array which specify the label of the \ -sides where the BC is applied\n\ -@end itemize\n\ -The output @var{BC} is an object which contains the boundary conditions\n\ -@seealso{fem_init_mesh, fem_fs}\n\ -@end deftypefn") -{ - int nargin = args.length (); - octave_value retval; - - if (nargin < 3 || nargin > 3) - print_usage (); - else - { - - if (! functionspace_type_loaded) - { - functionspace::register_type (); - functionspace_type_loaded = true; - mlock (); - } - - if (args(0).type_id () == functionspace::static_type_id ()) - { - const functionspace & fspo = static_cast (args(0).get_rep ()); - octave_fcn_handle * fh = args(1).fcn_handle_value (); - Array side = args(2).array_value (); - - if (!error_state) - { - const boost::shared_ptr & V (fspo.get_pfsp ()); - - octave_value_list b (3, 1); - octave_value_list tmp = feval (fh->function_value (), b); - Array 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 f (pf); - - if (! boundarycondition_type_loaded) - { - boundarycondition::register_type (); - boundarycondition_type_loaded = true; - mlock (); - } - - boundarycondition * pbc = new boundarycondition (); - - for (octave_idx_type i = 0; i < side.length (); ++i) - pbc->add_bc (V, f, side(i)); - - retval = octave_value (pbc); - } - } - } - return retval; -} diff -r ff95326e6f13 -r 670a5d91c397 src/fem_coeff.cc --- a/src/fem_coeff.cc Fri Aug 02 23:18:01 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - 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 . -*/ - -#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\ -@end itemize\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 (! coefficient_type_loaded) - { - coefficient::register_type (); - coefficient_type_loaded = true; - mlock (); - } - - if (!error_state) - { - octave_value_list b (3, 1); - octave_value_list tmp = feval (fh->function_value (), b); - Array 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); - } - - } - - return retval; -} diff -r ff95326e6f13 -r 670a5d91c397 src/fem_func.cc --- a/src/fem_func.cc Fri Aug 02 23:18:01 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -#include -#include "functionspace.h" -#include "function.h" - -DEFUN_DLD (fem_func, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} {[@var{func}]} = \ -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\ -for the basis functions of @var{Functional Space}\n\ -@end itemize\n\ -The output @var{func} is an object which contain a representation of the\ -function @var{Vector} which can be plotted or saved.\n\ -@seealso{fem_plot, fem_save}\n\ -@end deftypefn") -{ - - int nargin = args.length (); - octave_value retval=0; - - if (nargin < 3 || nargin > 3) - print_usage (); - else - { - if (! functionspace_type_loaded) - { - functionspace::register_type (); - functionspace_type_loaded = true; - mlock (); - } - if (args(1).type_id () == functionspace::static_type_id ()) - { - std::string str = args(0).string_value (); - const functionspace & fspo = - static_cast (args(1).get_rep ()); - Array myu = args(2).array_value (); - - if (!error_state) - { - const boost::shared_ptr & V = fspo.get_pfsp (); - - if (V->dim () != myu.length ()) - error ("The size of the functional space and of the vector must agree"); - else - { - dolfin::Vector du(myu.length ()); - for (std::size_t i = 0; i < myu.length (); ++i) - du.setitem (i, myu(i)); - - boost::shared_ptr uu (new dolfin::Vector(du)); - boost::shared_ptr u (new dolfin::Function(V, uu)); - - if (! function_type_loaded) - { - function::register_type (); - function_type_loaded = true; - mlock (); - } - - retval = new function (str, u); - } - } - } - } - return retval; -}