view src/MeshFunction.cc @ 259:598c5e9e0a9e

Add utilities for meshfunction * src/save_mf.cc: save meshfunction to .xml * src/MeshFunction.cc: import meshfunction from .xml * src/meshfunction.h: add print method
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Wed, 06 Aug 2014 16:48:25 +0200
parents
children a61fc34334ca
line wrap: on
line source

/*
 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/>.
*/

#include <dolfin.h>
#include "mesh.h"
#include "meshfunction.h"
#include "dolfin_compat.h"

DEFUN_DLD (MeshFunction, args, nargout, "-*- texinfo -*-\n\
@deftypefn {Function File} {[@var{meshfunc}]} = \
MeshFunction (@var{Mesh}, @var{filename})\n\
Initialize a meshfunction with the values contained in a XDMF file.\n\
The output @var{meshfunc} is an object which contains a representation of the \
meshfunction in @var{filename} which can be used to mark subdomains or \
facets where Dirichlet boundary conditions are to be applied.\n\
@seealso{DirichletBC, save}\n\
@end deftypefn")
{

  int nargin = args.length ();
  octave_value retval;
  
  if (nargin < 2 || nargin > 2 || nargout > 1)
    print_usage ();
  else
    {
      if (! mesh_type_loaded)
        {
          mesh::register_type ();
          mesh_type_loaded = true;
          mlock ();
        }

      if (! meshfunction_type_loaded)
        {
          meshfunction::register_type ();
          meshfunction_type_loaded = true;
          mlock ();
        }

      if (args(0).type_id () == mesh::static_type_id ()
          && args(1).is_string ())
        {
          std::string filename = args(1).string_value ();
          mesh const & msh_arg =
            static_cast<mesh const &> (args(0).get_rep ());

          if (!error_state)
            {
              SHARED_PTR <dolfin::Mesh const> const &
                pmsh = msh_arg.get_pmsh ();
              filename += ".xdmf";

              try
                { retval = new meshfunction (pmsh, filename); }
              catch (std::runtime_error &)
                { error ("error reading file"); }
            }
        }
      else
        error ("invalid input arguments");
    }

  return retval;
}