Mercurial > fem-fenics-eugenio
changeset 250:8f309b85bb7e
Add function to set linear algebra back-end
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Sun, 13 Jul 2014 19:25:03 +0200 |
parents | f56525533e54 |
children | b1dc98050634 |
files | INDEX inst/linear_algebra_backend.m src/femfenics_factory.cc src/femfenics_factory.h |
diffstat | 4 files changed, 59 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/INDEX Sat Jul 12 17:28:08 2014 +0200 +++ b/INDEX Sun Jul 13 19:25:03 2014 +0200 @@ -23,6 +23,7 @@ JacobianForm Functional Creation of the discretized problem + linear_algebra_backend assemble assemble_system Post processing
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inst/linear_algebra_backend.m Sun Jul 13 19:25:03 2014 +0200 @@ -0,0 +1,40 @@ +## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> +## +## 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 3 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/>. + +## -*- texinfo -*- +## @deftypefn {Function File} @var{val} = linear_algebra_backend () +## @deftypefnx {Function File} @var{old_val} = linear_algebra_backend (@var{new_val}) +## +## Query or set the internal variable that specifies the linear algebra back-end +## to use when assembling systems, matrices or vectors. It defaults to "uBLAS". +## +## @end deftypefn + +function output = linear_algebra_backend (varargin) + persistent backend = "uBLAS"; + persistent opts = {"uBLAS"}; + + if (nargin > 1) + print_usage (); + else + output = backend; + if (nargin == 1) + input = validatestring (varargin{1}, opts, "linear_algebra_backend", + "new_val"); + backend = input; + endif + endif + +endfunction \ No newline at end of file
--- a/src/femfenics_factory.cc Sat Jul 12 17:28:08 2014 +0200 +++ b/src/femfenics_factory.cc Sun Jul 13 19:25:03 2014 +0200 @@ -17,11 +17,25 @@ #include "femfenics_factory.h" #include "uBLAS_factory.h" +#include <octave/parse.h> femfenics_base_factory const& femfenics_factory::factory (void) const { - //FIXME: Since just one backend has its interface implemented, this method - // doesn't check which one to provide, yet + std::string backend = linear_algebra_backend (); + /* Here go the returns for other back-ends + if (backend == "PETSc") + return PETSc_factory::instance (); ... + */ + + // Default back-end return uBLAS_factory::instance (); + } + +std::string +femfenics_factory::linear_algebra_backend (void) const + { + octave_value_list ovl = feval ("linear_algebra_backend"); + std::string retval = ovl(0).string_value (); + return retval; } \ No newline at end of file
--- a/src/femfenics_factory.h Sat Jul 12 17:28:08 2014 +0200 +++ b/src/femfenics_factory.h Sun Jul 13 19:25:03 2014 +0200 @@ -19,6 +19,7 @@ #define __FEMFENICS_FACTORY__ #include "femfenics_base_factory.h" +#include <string> class femfenics_factory : public femfenics_base_factory { @@ -39,11 +40,7 @@ femfenics_factory (femfenics_factory const&); femfenics_factory operator = (femfenics_factory const&); - - //FIXME: just one backend implemented - inline char const * linear_algebra_backend (void) const - { return "uBLAS"; } - + std::string linear_algebra_backend (void) const; femfenics_base_factory const& factory (void) const; };