Mercurial > fem-fenics-eugenio
comparison src/save_mf.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 | 0b9dc516ba36 |
comparison
equal
deleted
inserted
replaced
258:ab35a8b0deef | 259:598c5e9e0a9e |
---|---|
1 /* | |
2 Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> | |
3 | |
4 This program is free software; you can redistribute it and/or modify it under | |
5 the terms of the GNU General Public License as published by the Free Software | |
6 Foundation; either version 3 of the License, or (at your option) any later | |
7 version. | |
8 | |
9 This program is distributed in the hope that it will be useful, but WITHOUT | |
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
12 details. | |
13 | |
14 You should have received a copy of the GNU General Public License along with | |
15 this program; if not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 #include "meshfunction.h" | |
19 | |
20 DEFUN_DLD (save, args, nargout, "-*- texinfo -*-\n\ | |
21 @deftypefn {Function File} \ | |
22 save (@var{MeshFunction}, @var{Name})\n\ | |
23 Save a meshfunction in XDMF format.\n\ | |
24 The input parameters are\n\ | |
25 @itemize @bullet \n\ | |
26 @item @var{MeshFunction} is the meshfunction that you want to save\n\ | |
27 @item @var{Name} is a string for the output name\n\ | |
28 @end itemize\n\ | |
29 The output is a .xdmf file.\n\ | |
30 @seealso{plot, MeshFunction}\n\ | |
31 @end deftypefn") | |
32 { | |
33 int nargin = args.length (); | |
34 octave_value retval; | |
35 | |
36 if (nargin < 2 || nargin > 2 || nargout > 1) | |
37 print_usage (); | |
38 else | |
39 { | |
40 if (! meshfunction_type_loaded) | |
41 { | |
42 meshfunction::register_type (); | |
43 meshfunction_type_loaded = true; | |
44 mlock (); | |
45 } | |
46 | |
47 if (args(0).type_id () == meshfunction::static_type_id () && | |
48 args(1).is_string ()) | |
49 { | |
50 meshfunction const & mf_arg = | |
51 static_cast<meshfunction const &> (args(0).get_rep ()); | |
52 std::string str = args(1).string_value (); | |
53 | |
54 if (!error_state) | |
55 { | |
56 dolfin::MeshFunction <std::size_t> const & | |
57 mf = mf_arg.get_mf (); | |
58 str += ".xdmf"; | |
59 try | |
60 { | |
61 dolfin::File file (str); | |
62 file << mf; | |
63 } | |
64 catch (std::runtime_error &) | |
65 { error ("error saving meshfunction"); } | |
66 retval = 0; | |
67 } | |
68 } | |
69 else | |
70 error ("invalid input arguments"); | |
71 } | |
72 | |
73 return retval; | |
74 } |