# HG changeset patch # User gedeone-octave # Date 1378406976 -7200 # Node ID d3c29e38e5d298a0fdc6c8285b096093dfafcc3e # Parent 64776e1f0530c8030de18bf57943c3dfe934d3a8 New naming convention adopted and Polymorphism for plot and save. * plot_mesh.cc: obtained merging Plot_2d.cc Plot_3d.cc fem_plot.cc * plot_func.cc: obtined from fem_plot.cc * fem_save.cc moved to sace.cc diff -r 64776e1f0530 -r d3c29e38e5d2 obsolete/Plot_2d.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/obsolete/Plot_2d.cc Thu Sep 05 20:49:36 2013 +0200 @@ -0,0 +1,71 @@ +/* + 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 . +*/ +#include "mesh.h" +#include "Plot_2d.h" + +DEFUN_DLD (Plot_2d, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +Plot_2d (@var{msh}, @var{nodal_value})\n\ +The input parameters are a Mesh and a vector which specify the values of the \ +function that you want to plot at each node\n\ +@seealso{fem_func, fem_save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval; + + if (nargin < 2 || nargin > 2) + print_usage (); + else + { + if (! mesh_type_loaded) + { + mesh::register_type (); + mesh_type_loaded = true; + mlock (); + } + if (args(0).type_id () == mesh::static_type_id ()) + { + const mesh & msh = + static_cast (args(0).get_rep ()); + Array myu = args(1).array_value (); + + if (!error_state) + { + const dolfin::Mesh & mshd = msh.get_msh (); + boost::shared_ptr V (new Plot_2d::FunctionSpace (mshd)); + + if (V->dim () != myu.length ()) + error ("Plot_2D: The size of the functional space and of the vector must agree"); + else + { + dolfin::Vector du(myu.length ()); + for (std::size_t i = 0; i < myu.length (); ++i) + du.setitem (i, myu(i)); + + boost::shared_ptr uu (new dolfin::Vector(du)); + boost::shared_ptr u (new dolfin::Function(V, uu)); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + } + } + return retval; +} diff -r 64776e1f0530 -r d3c29e38e5d2 obsolete/Plot_3d.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/obsolete/Plot_3d.cc Thu Sep 05 20:49:36 2013 +0200 @@ -0,0 +1,71 @@ +/* + 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 . +*/ +#include "mesh.h" +#include "Plot_3d.h" + +DEFUN_DLD (Plot_3d, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +Plot_3d (@var{msh}, @var{nodal_value})\n\ +The input parameters are a Mesh and a vector which specify the values of the \ +function that you want to plot at each node\n\ +@seealso{fem_func, fem_save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval; + + if (nargin < 2 || nargin > 2) + print_usage (); + else + { + if (! mesh_type_loaded) + { + mesh::register_type (); + mesh_type_loaded = true; + mlock (); + } + if (args(0).type_id () == mesh::static_type_id ()) + { + const mesh & msh = + static_cast (args(0).get_rep ()); + Array myu = args(1).array_value (); + + if (!error_state) + { + const dolfin::Mesh & mshd = msh.get_msh (); + boost::shared_ptr V (new Plot_3d::FunctionSpace (mshd)); + + if (V->dim () != myu.length ()) + error ("The size of the functional space and of the vector must agree"); + else + { + dolfin::Vector du(myu.length ()); + for (std::size_t i = 0; i < myu.length (); ++i) + du.setitem (i, myu(i)); + + boost::shared_ptr uu (new dolfin::Vector(du)); + boost::shared_ptr u (new dolfin::Function(V, uu)); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + } + } + return retval; +} diff -r 64776e1f0530 -r d3c29e38e5d2 obsolete/plot.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/obsolete/plot.cc Thu Sep 05 20:49:36 2013 +0200 @@ -0,0 +1,86 @@ +/* + 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 . +*/ + +#include "function.h" +#include "mesh.h" +#include "Plot_2d.h" +#include "Plot_3d.h" + +DEFUN_DLD (plot, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +fem_func (@var{Function})\n\ +The input parameter is the object that you want to plot\n\ +It can be either a Function or a Mesh \n\ +@seealso{fem_func, fem_save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval; + + if (nargin < 1 || nargin > 2) + print_usage (); + else + { + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + + if (! mesh_type_loaded) + { + mesh::register_type (); + mesh_type_loaded = true; + mlock (); + } + + if (args(0).type_id () == function::static_type_id ()) + { + const function & uo = + static_cast (args(0).get_rep ()); + + if (!error_state) + { + const boost::shared_ptr & u = uo.get_pfun (); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + + else if (args(0).type_id () == mesh::static_type_id ()) + { + const mesh & msho = static_cast (args(0).get_rep ()); + if (nargin == 1) + { + if (!error_state) + { + const boost::shared_ptr & mshd = msho.get_pmsh (); + dolfin::plot (*mshd); + dolfin::interactive (); + retval = 0; + } + } + else if (nargin == 2) + + } + + } + return retval; +} diff -r 64776e1f0530 -r d3c29e38e5d2 post_install.m --- a/post_install.m Tue Sep 03 00:18:03 2013 +0200 +++ b/post_install.m Thu Sep 05 20:49:36 2013 +0200 @@ -6,7 +6,6 @@ if (status != 1) error ("couldn't create private directory: %s", msg); endif - [status, msg, msgid] = movefile ('./src/*.h', private, 'f'); if (status != 1) error ("couldn't copy file: %s", msg); @@ -18,10 +17,38 @@ error ("couldn't create @function directory: %s", msg); endif + mesh = fullfile (desc.dir, "@mesh"); + [status, msg] = mkdir (func); + if (status != 1) + error ("couldn't create @function directory: %s", msg); + endif + [status, msg, msgid] = movefile ('./src/feval.oct', func, 'f'); if (status != 1) error ("couldn't copy file: %s", msg); endif + delete ('./src/feval.oct'); + [status, msg, msgid] = movefile ('./src/save.oct', func, 'f'); + if (status != 1) + error ("couldn't copy file: %s", msg); + endif + + delete ('./src/save.oct'); + + new_name = fullfile (func, 'plot.oct'); + [status, msg, msgid] = movefile ('./src/plot_func.oct', new_name, 'f'); + if (status != 1) + error ("couldn't copy file: %s", msg); + endif + + new_name = fullfile (mesh, 'plot.oct'); + [status, msg, msgid] = movefile ('./src/plot_mesh.oct', new_name, 'f'); + if (status != 1) + error ("couldn't copy file: %s", msg); + endif + + delete ('./src/plot.oct'); + endfunction diff -r 64776e1f0530 -r d3c29e38e5d2 src/Makefile.in --- a/src/Makefile.in Tue Sep 03 00:18:03 2013 +0200 +++ b/src/Makefile.in Thu Sep 05 20:49:36 2013 +0200 @@ -7,12 +7,11 @@ DirichletBC.oct \ Expression.oct \ Function.oct \ - fem_plot.oct \ - fem_save.oct \ + save.oct \ assemble.oct \ assemble_system.oct \ - Plot_2d.oct \ - Plot_3d.oct \ + plot_func.oct \ + plot_mesh.oct \ SubSpace.oct \ feval.oct \ @@ -69,26 +68,23 @@ assemble_system.o: assemble_system.cc form.h boundarycondition.h $(MKOCTFILE) $(CPPFLAGS) -c assemble_system.cc $(LDFLAGS) -o $@ -I. -fem_plot.oct: fem_plot.o - $(MKOCTFILE) $(CPPFLAGS) -s fem_plot.o -o $@ $(LDFLAGS) $(LIBS) - -fem_plot.o: fem_plot.cc - $(MKOCTFILE) $(CPPFLAGS) -c fem_plot.cc $(LDFLAGS) -o $@ -I. +save.oct: fem_save.o + $(MKOCTFILE) $(CPPFLAGS) -s save.o -o $@ $(LDFLAGS) $(LIBS) -fem_save.oct: fem_save.o - $(MKOCTFILE) $(CPPFLAGS) -s fem_save.o -o $@ $(LDFLAGS) $(LIBS) +save.o: fem_save.cc + $(MKOCTFILE) $(CPPFLAGS) -c save.cc $(LDFLAGS) -o $@ -I. -fem_save.o: fem_save.cc - $(MKOCTFILE) $(CPPFLAGS) -c fem_save.cc $(LDFLAGS) -o $@ -I. - -Plot_2d.oct: Plot_2d.cc Plot_2d.h - $(MKOCTFILE) $(CPPFLAGS) -I. Plot_2d.cc $(LDFLAGS) $(LIBS) +plot_mesh.oct: plot_mesh.cc Plot_2d.h mesh.h Plot_3d.h + $(MKOCTFILE) $(CPPFLAGS) -I. plot_mesh.cc $(LDFLAGS) $(LIBS) Plot_2d.h: Plot_2d.ufl $(FFC) -l dolfin Plot_2d.ufl -Plot_3d.oct: Plot_3d.cc Plot_3d.h - $(MKOCTFILE) $(CPPFLAGS) -I. Plot_3d.cc $(LDFLAGS) $(LIBS) +Plot_3d.h: Plot_3d.ufl + $(FFC) -l dolfin Plot_3d.ufl + +plot_func.oct: plot_func.h function.h + $(MKOCTFILE) $(CPPFLAGS) -I. plot_func.cc $(LDFLAGS) $(LIBS) SubSpace.oct: SubSpace.cc functionspace.h $(MKOCTFILE) $(CPPFLAGS) -I. SubSpace.cc $(LDFLAGS) $(LIBS) @@ -96,8 +92,6 @@ feval.oct: feval.cc function.h $(MKOCTFILE) $(CPPFLAGS) -I. feval.cc $(LDFLAGS) $(LIBS) -Plot_3d.h: Plot_3d.ufl - $(FFC) -l dolfin Plot_3d.ufl clean: -rm -f *.o core octave-core *.oct *~ *.xml diff -r 64776e1f0530 -r d3c29e38e5d2 src/Plot_2d.cc --- a/src/Plot_2d.cc Tue Sep 03 00:18:03 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - 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 . -*/ -#include "mesh.h" -#include "Plot_2d.h" - -DEFUN_DLD (Plot_2d, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} \ -Plot_2d (@var{msh}, @var{nodal_value})\n\ -The input parameters are a Mesh and a vector which specify the values of the \ -function that you want to plot at each node\n\ -@seealso{fem_func, fem_save}\n\ -@end deftypefn") -{ - - int nargin = args.length (); - octave_value retval; - - if (nargin < 2 || nargin > 2) - print_usage (); - else - { - if (! mesh_type_loaded) - { - mesh::register_type (); - mesh_type_loaded = true; - mlock (); - } - if (args(0).type_id () == mesh::static_type_id ()) - { - const mesh & msh = - static_cast (args(0).get_rep ()); - Array myu = args(1).array_value (); - - if (!error_state) - { - const dolfin::Mesh & mshd = msh.get_msh (); - boost::shared_ptr V (new Plot_2d::FunctionSpace (mshd)); - - if (V->dim () != myu.length ()) - error ("Plot_2D: The size of the functional space and of the vector must agree"); - else - { - dolfin::Vector du(myu.length ()); - for (std::size_t i = 0; i < myu.length (); ++i) - du.setitem (i, myu(i)); - - boost::shared_ptr uu (new dolfin::Vector(du)); - boost::shared_ptr u (new dolfin::Function(V, uu)); - dolfin::plot (*u); - dolfin::interactive (); - retval = 0; - } - } - } - } - return retval; -} diff -r 64776e1f0530 -r d3c29e38e5d2 src/Plot_3d.cc --- a/src/Plot_3d.cc Tue Sep 03 00:18:03 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - 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 . -*/ -#include "mesh.h" -#include "Plot_3d.h" - -DEFUN_DLD (Plot_3d, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} \ -Plot_3d (@var{msh}, @var{nodal_value})\n\ -The input parameters are a Mesh and a vector which specify the values of the \ -function that you want to plot at each node\n\ -@seealso{fem_func, fem_save}\n\ -@end deftypefn") -{ - - int nargin = args.length (); - octave_value retval; - - if (nargin < 2 || nargin > 2) - print_usage (); - else - { - if (! mesh_type_loaded) - { - mesh::register_type (); - mesh_type_loaded = true; - mlock (); - } - if (args(0).type_id () == mesh::static_type_id ()) - { - const mesh & msh = - static_cast (args(0).get_rep ()); - Array myu = args(1).array_value (); - - if (!error_state) - { - const dolfin::Mesh & mshd = msh.get_msh (); - boost::shared_ptr V (new Plot_3d::FunctionSpace (mshd)); - - if (V->dim () != myu.length ()) - error ("The size of the functional space and of the vector must agree"); - else - { - dolfin::Vector du(myu.length ()); - for (std::size_t i = 0; i < myu.length (); ++i) - du.setitem (i, myu(i)); - - boost::shared_ptr uu (new dolfin::Vector(du)); - boost::shared_ptr u (new dolfin::Function(V, uu)); - dolfin::plot (*u); - dolfin::interactive (); - retval = 0; - } - } - } - } - return retval; -} diff -r 64776e1f0530 -r d3c29e38e5d2 src/fem_plot.cc --- a/src/fem_plot.cc Tue Sep 03 00:18:03 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - 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 . -*/ - -#include "function.h" -#include "mesh.h" - -DEFUN_DLD (fem_plot, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} \ -fem_func (@var{Function})\n\ -The input parameter is the object that you want to plot\n\ -It can be either a Function or a Mesh \n\ -@seealso{fem_func, fem_save}\n\ -@end deftypefn") -{ - - int nargin = args.length (); - octave_value retval; - - if (nargin < 1 || nargin > 1) - print_usage (); - else - { - if (! function_type_loaded) - { - function::register_type (); - function_type_loaded = true; - mlock (); - } - - if (! mesh_type_loaded) - { - mesh::register_type (); - mesh_type_loaded = true; - mlock (); - } - - if (args(0).type_id () == function::static_type_id ()) - { - const function & uo = - static_cast (args(0).get_rep ()); - - if (!error_state) - { - const boost::shared_ptr & u = uo.get_pfun (); - dolfin::plot (*u); - dolfin::interactive (); - retval = 0; - } - } - - else if (args(0).type_id () == mesh::static_type_id ()) - { - const mesh & msho = static_cast (args(0).get_rep ()); - - if (!error_state) - { - const boost::shared_ptr & mshd = msho.get_pmsh (); - dolfin::plot (*mshd); - dolfin::interactive (); - retval = 0; - } - } - - } - return retval; -} diff -r 64776e1f0530 -r d3c29e38e5d2 src/fem_save.cc --- a/src/fem_save.cc Tue Sep 03 00:18:03 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - 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 . -*/ -#include "function.h" - -DEFUN_DLD (fem_save, args, , "-*- texinfo -*-\n\ -@deftypefn {Function File} \ -fem_save (@var{Function}, @var{Name}\n\ -The input parameters are\n\ -@itemize @bullet \n\ -@item @var{Function} is the parameter of type function that you want to save\n\ -@item @var{Name} is a string for the output name\n\ -@end itemize\n\ -The output is a file in format .pvd\n\ -@seealso{fem_plot, fem_func}\n\ -@end deftypefn") -{ - - int nargin = args.length (); - octave_value retval; - - if (nargin < 2 || nargin > 2) - print_usage (); - else - { - if (! function_type_loaded) - { - function::register_type (); - function_type_loaded = true; - mlock (); - } - if (args(0).type_id () == function::static_type_id ()) - { - const function & uo = - static_cast (args(0).get_rep ()); - std::string str = args(1).string_value (); - - if (!error_state) - { - const boost::shared_ptr & u = uo.get_pfun (); - str += ".pvd"; - dolfin::File file (str); - file << (*u); - retval = 0; - } - } - } - return retval; -} diff -r 64776e1f0530 -r d3c29e38e5d2 src/plot_func.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/plot_func.cc Thu Sep 05 20:49:36 2013 +0200 @@ -0,0 +1,58 @@ +/* + 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 . +*/ + +#include "function.h" + +DEFUN_DLD (plot, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +fem_func (@var{Function})\n\ +The input parameter is the object that you want to plot\n\ +It can be either a Function or a Mesh \n\ +@seealso{fem_func, fem_save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval; + + if (nargin < 1 || nargin > 1) + print_usage (); + else + { + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + + if (args(0).type_id () == function::static_type_id ()) + { + const function & uo = + static_cast (args(0).get_rep ()); + + if (!error_state) + { + const boost::shared_ptr & u = uo.get_pfun (); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + } + return retval; +} diff -r 64776e1f0530 -r d3c29e38e5d2 src/plot_mesh.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/plot_mesh.cc Thu Sep 05 20:49:36 2013 +0200 @@ -0,0 +1,96 @@ +/* + 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 . +*/ + +#include "function.h" +#include "mesh.h" +#include "Plot_2d.h" +#include "Plot_3d.h" + +DEFUN_DLD (plot, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +plot (@var{Mesh}, @var{Nodal_Values}(OPTIONAL))\n\ +The input parameter is the mesh and optionally also a vector representing\ +the values of a function at each node.\n\ +@seealso{Mesh, save}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval; + + if (nargin < 1 || nargin > 2) + print_usage (); + else + { + if (! mesh_type_loaded) + { + mesh::register_type (); + mesh_type_loaded = true; + mlock (); + } + + if (args(0).type_id () == mesh::static_type_id ()) + { + const mesh & msho = static_cast (args(0).get_rep ()); + + if (nargin == 1) + { + if (!error_state) + { + const boost::shared_ptr & mshd = msho.get_pmsh (); + dolfin::plot (*mshd); + dolfin::interactive (); + retval = 0; + } + } + + else if (nargin == 2) + { + Array myu = args(1).array_value (); + + if (!error_state) + { + const dolfin::Mesh & mshd = msh.get_msh (); + boost::shared_ptr V; + if (mshd.topology ().dim () == 2) + *V = new Plot_2d::FunctionSpace (mshd); + else if (mshd.topology ().dim () () == 3) + *V = new Plot_3d::FunctionSpace (mshd); + else + error ("Plot: The size of the mesh must be 2 or 3"); + + if (V->dim () != myu.length ()) + error ("Plot: The size of the functional space and of the vector must agree"); + else + { + dolfin::Vector du(myu.length ()); + for (std::size_t i = 0; i < myu.length (); ++i) + du.setitem (i, myu(i)); + + boost::shared_ptr uu (new dolfin::Vector(du)); + boost::shared_ptr u (new dolfin::Function(V, uu)); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + } + } + + } + return retval; +} diff -r 64776e1f0530 -r d3c29e38e5d2 src/save.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/save.cc Thu Sep 05 20:49:36 2013 +0200 @@ -0,0 +1,62 @@ +/* + 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 . +*/ +#include "function.h" + +DEFUN_DLD (save, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +fem_save (@var{Function}, @var{Name}\n\ +The input parameters are\n\ +@itemize @bullet \n\ +@item @var{Function} is the parameter of type function that you want to save\n\ +@item @var{Name} is a string for the output name\n\ +@end itemize\n\ +The output is a file in format .pvd\n\ +@seealso{fem_plot, fem_func}\n\ +@end deftypefn") +{ + + int nargin = args.length (); + octave_value retval; + + if (nargin < 2 || nargin > 2) + print_usage (); + else + { + if (! function_type_loaded) + { + function::register_type (); + function_type_loaded = true; + mlock (); + } + if (args(0).type_id () == function::static_type_id ()) + { + const function & uo = + static_cast (args(0).get_rep ()); + std::string str = args(1).string_value (); + + if (!error_state) + { + const boost::shared_ptr & u = uo.get_pfun (); + str += ".pvd"; + dolfin::File file (str); + file << (*u); + retval = 0; + } + } + } + return retval; +}