Mercurial > fem-fenics-eugenio
changeset 16:448e01d4411f
Introduce the use of boost::shared_ptr for class members
* mesh.h: private memeber is now boost::shared_ptr<const dolfin::Mesh> instead
of dolfin::Mesh
The class now derives only from octave_base_value and no more from
dolfin::Mesh
* mesh.cc: the constructor now takes care of the boost::shared_ptr < >
* fem_get_mesh.cc, fem_init_mesh: now use boost::shared_ptr < >
author | gedeone-octave <marco.vassallo@outlook.com> |
---|---|
date | Thu, 11 Jul 2013 18:00:26 +0200 |
parents | b760ffba8f63 |
children | efec39fccff3 |
files | src/fem_get_mesh.cc src/fem_init_mesh.cc src/mesh.cc src/mesh.h |
diffstat | 4 files changed, 46 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fem_get_mesh.cc Mon Jul 08 21:43:24 2013 +0200 +++ b/src/fem_get_mesh.cc Thu Jul 11 18:00:26 2013 +0200 @@ -17,7 +17,16 @@ #include "mesh.h" -DEFUN_DLD (fem_get_mesh, args, , "return a mesh in the (p, e, t) from a mesh declared with fem_init_mesh") +DEFUN_DLD (fem_get_mesh, args, ,"-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{mesh}]} = \ +fem_get_mesh (@var{fem_mesh}) \n\ +Return a (p, e, t) representation of @var{fem_mesh}\n\ +The @var{mesh_to_read} should be an object created with \ +fem_init_mesh().\n\ +The output @var{mesh} is a PDE-tool like structure\n\ +with matrix fields (p,e,t).\n\ +@seealso{fem_init_mesh}\n\ +@end deftypefn") { int nargin = args.length (); octave_value retval; @@ -32,9 +41,7 @@ retval = octave_value (msh.get_pet ()); } else - error ("fem_get_mesh: the argument is not a mesh type \n\ -maybe the mesh type has not been loaded, try fem_init_env()"); - + error ("fem_get_mesh: the argument is not a mesh type"); } return retval; }
--- a/src/fem_init_mesh.cc Mon Jul 08 21:43:24 2013 +0200 +++ b/src/fem_init_mesh.cc Thu Jul 11 18:00:26 2013 +0200 @@ -17,7 +17,20 @@ #include "mesh.h" -DEFUN_DLD (fem_init_mesh, args, , "initialize a mesh from (p, e, t) or file") +DEFUN_DLD (fem_init_mesh, args, ,"-*- texinfo -*-\n\ +@deftypefn {Function File} {[@var{mesh_out}]} = \ +fem_get_mesh (@var{mesh_in}) \n\ +The @var{mesh_in} should be either\n\ +@itemize @bullet \n\ +@item a string containing the name of the file where the mesh is stored\ +(compatible formats are the ones which are compatible with Fenics\n\ +@item a a PDE-tool like structure with matrix fields (p,e,t)\n\ +@end itemize\n\ +fem_init_mesh().\n\ +The output @var{mesh_out} is a representation of the\n\ +@var{mesh_in} which is compatible with fem-fenics\n\ +@seealso{fem_get_mesh}\n\ +@end deftypefn") { int nargin = args.length (); octave_value retval = 0;
--- a/src/mesh.cc Mon Jul 08 21:43:24 2013 +0200 +++ b/src/mesh.cc Thu Jul 11 18:00:26 2013 +0200 @@ -18,21 +18,10 @@ #include <mesh.h> -const dolfin::Mesh & -mesh::get_msh () const -{ - return msh; -} - -void -mesh::set_msh (dolfin::Mesh & _msh) -{ - msh = _msh; -} - octave_scalar_map mesh::get_pet () const { + const dolfin::Mesh & msh (*pmsh); //p matrix uint D = msh.topology ().dim (); std::size_t num_v = msh.num_vertices (); @@ -120,6 +109,7 @@ else { dolfin::MeshEditor editor; + dolfin::Mesh msh; editor.open (msh, D, D); editor.init_vertices (p.cols ()); editor.init_cells (t.cols ()); @@ -362,5 +352,8 @@ } *(msh.domains ().markers (D)) = cell; + + boost::shared_ptr<const dolfin::Mesh> my_m (new dolfin::Mesh (msh)); + pmsh = my_m; } }
--- a/src/mesh.h Mon Jul 08 21:43:24 2013 +0200 +++ b/src/mesh.h Thu Jul 11 18:00:26 2013 +0200 @@ -22,42 +22,44 @@ #include <octave/oct.h> #include <octave/oct-map.h> -class mesh : public octave_base_value, public dolfin::Mesh +class mesh : public octave_base_value { public: - // Constructors mesh () : octave_base_value () {} - mesh (const dolfin::Mesh& _msh) : octave_base_value (), msh (_msh) {} + mesh (const dolfin::Mesh& _msh) : + octave_base_value (), pmsh (new dolfin::Mesh(_msh)) {} mesh (Array<double>& p, Array<octave_idx_type>& e, Array<octave_idx_type>& t); - mesh (std::string _filename): octave_base_value (), msh (_filename) {} + mesh (std::string _filename): + octave_base_value (), pmsh (new dolfin::Mesh(_filename)) {} - //a method for printing void print (std::ostream& os, bool pr_as_read_syntax = false) const - { os << "msh : " << msh.label() << " with " << msh.num_vertices() + { os << "msh : " << pmsh ->label () << " with " << pmsh -> num_vertices () << " vertices " << std::endl; } - //destructor - ~mesh(void) { }; + ~mesh(void) {} bool is_defined (void) const { return true; } - //get the information from the private member - const dolfin::Mesh & get_msh (void) const; + const dolfin::Mesh & get_msh (void) const + { return *pmsh; } + + const boost::shared_ptr<const dolfin::Mesh> & get_p_msh (void) const + { return pmsh; } + octave_scalar_map get_pet (void) const; - // set the value of the private member - void set_msh (dolfin::Mesh & _msh); - private: - dolfin::Mesh msh; + boost::shared_ptr<const dolfin::Mesh> pmsh; + DECLARE_OCTAVE_ALLOCATOR; DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA; }; + #endif