changeset 17:efec39fccff3

DLD function for Functional Space in Octave * fem_fs.cc: new DLD function which take as input a fem-fenics mesh and return a fem-fenics functionspace * functionspace.h: now uses boost::shared_ptr <const dolfin::FunctionSpace> instead of dolfin::FunctionSpace
author gedeone-octave <marco.vassallo@outlook.com>
date Thu, 11 Jul 2013 18:24:15 +0200
parents 448e01d4411f
children c725b4be09e3
files src/fem_fs.cc src/functionspace.h
diffstat 2 files changed, 56 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fem_fs.cc	Thu Jul 11 18:24:15 2013 +0200
@@ -0,0 +1,41 @@
+/*
+ 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 "functionspace.h"
+#include "mesh.h"
+#include "Laplace.h"
+
+DEFUN_DLD (fem_fs, args, , "initialize a fs from a mesh declared with fem_init_mesh")
+{
+  int nargin = args.length ();
+  octave_value retval;
+
+  if (nargin < 1 || nargin > 1)
+    print_usage ();
+  else
+    {
+      if (args(0).type_id () == mesh::static_type_id ())
+        {
+          const mesh & msho = static_cast<const mesh&> (args(0).get_rep ());
+          const dolfin::Mesh & mshd = msho.get_msh ();
+          boost::shared_ptr <const dolfin::FunctionSpace> g (new Laplace::FunctionSpace (mshd));
+          retval = new functionspace(g);
+        }
+    }
+  return retval;
+}
--- a/src/functionspace.h	Thu Jul 11 18:00:26 2013 +0200
+++ b/src/functionspace.h	Thu Jul 11 18:24:15 2013 +0200
@@ -18,57 +18,40 @@
 #ifndef _FUNCTIONSPACE_OCTAVE_
 #define _FUNCTIONSPACE_OCTAVE_
 
+#include <memory>
+#include <vector>
 #include <dolfin.h>
 #include <octave/oct.h>
 
-class functionspace : public dolfin::FunctionSpace, public octave_base_value
+class functionspace : public octave_base_value
 {
 
  public:
 
-  // Constructors
+  functionspace () : octave_base_value (), fsp () { }
 
-  /*
-  Default constructor: it is necessary because it is requested by
-  DEFINE_OCTAVE_ALLOCATOR and DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA .
-  dolfin::FunctionSpace doesn't provide a default constructor, and thus
-  we add as private members __msh, __elm, __dfm, which are needed only for
-  creating our own default constructor functionspace()
-  for dolfin::FunctionSpace() we use the protected constructor of the class
-  which needs only a dolfin::Mesh
-  */
+  functionspace (boost::shared_ptr <const dolfin::FunctionSpace> _fsp) :
+  octave_base_value (), fsp( _fsp) { }
 
-  functionspace () :
-  dolfin::FunctionSpace (__msh), octave_base_value (), fsp (__msh, __elm, __dfm)
-  {}
-
+  void print (std::ostream& os, bool pr_as_read_syntax = false) const
+  { os << "Functional Space : " << (*fsp).str(true) << std::endl; }
 
-  functionspace (const dolfin::FunctionSpace & _fsp)
-  : octave_base_value (), fsp (_fsp), dolfin::FunctionSpace (_fsp) {}
-
-  //a method for printing
-  void print (std::ostream& os, bool pr_as_read_syntax = false) const
-  { os << "fsp : " << fsp.str(true) << std::endl; }
-
-  //destructor
-  ~functionspace(void) { };
+  ~functionspace(void) { std::cout << "delete fsp "<< std::endl; }
 
   bool is_defined (void) const { return true; }
 
-  //get the information from the private member
   const dolfin::FunctionSpace & get_fsp (void) const
-  { return fsp; }
+  { return (*fsp); }
 
-  // set the value of the private member
   void set_fsp (dolfin::FunctionSpace & _fsp)
-  { fsp = _fsp; }
+  {
+    dolfin::FunctionSpace * p = new dolfin::FunctionSpace (_fsp);
+    fsp = boost::shared_ptr<const dolfin::FunctionSpace> (p);
+  }
 
  private:
 
-  dolfin::FunctionSpace fsp;
-  boost::shared_ptr<const dolfin::Mesh> __msh;
-  boost::shared_ptr<dolfin::FiniteElement> __elm;
-  boost::shared_ptr<dolfin::GenericDofMap> __dfm;
+  boost::shared_ptr <const dolfin::FunctionSpace> fsp;
 
   DECLARE_OCTAVE_ALLOCATOR;
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA;