# HG changeset patch # User Eugenio Gianniti # Date 1405272303 -7200 # Node ID 8f309b85bb7eb9c0ba7e1ddfa7aa29e7c66aea86 # Parent f56525533e54aa834a02756bf6a0d54b6945db94 Add function to set linear algebra back-end diff -r f56525533e54 -r 8f309b85bb7e INDEX --- 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 diff -r f56525533e54 -r 8f309b85bb7e inst/linear_algebra_backend.m --- /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 +## +## 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 . + +## -*- 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 diff -r f56525533e54 -r 8f309b85bb7e src/femfenics_factory.cc --- 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 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 diff -r f56525533e54 -r 8f309b85bb7e src/femfenics_factory.h --- 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 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; };