view src/fem_init_mesh.cc @ 12:b7c74c0bdabd

New functions which get a (p,e,t) matrix from a mesh object * Makefile.in: added the option to compile also this function * fem_init_mesh.cc: dld function which call the mesh::get_pet method * mesh.cc mesh.h: added the new method get_pet which return a mesh as an octave_sclar_map. (code similar to mshm_dolfin_read)
author gedeone-octave <marco.vassallo@outlook.com>
date Sat, 06 Jul 2013 00:39:34 +0200
parents 277b60c6618a
children 448e01d4411f
line wrap: on
line source

/*
 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 "mesh.h"

DEFUN_DLD (fem_init_mesh, args, , "initialize a mesh from (p, e, t) or file")
{
  int nargin = args.length ();
  octave_value retval = 0;

  if (nargin < 1 || nargin > 1)
    print_usage ();
  else
    {
      if (!error_state)
        {
          if (args(0).is_string () == true)
            {
              std::string filename = args(0).string_value ();
              //if the filename is not valid, dolfin takes care of it
              retval = new mesh (filename);
            }

           else
             {
               octave_scalar_map a = args(0).scalar_map_value ();
               Array<double> p = a.contents ("p").matrix_value ();
               Array<octave_idx_type> t = a.contents ("t").matrix_value ();
               Array<octave_idx_type> e = a.contents ("e").matrix_value ();

               if (! error_state)
                 {
                   retval = new mesh (p, e, t);
                 }
               else
                 error ("fem_init_mesh: the argument you provide is invalid");
             }
        }
    }
  return retval;
}