# HG changeset patch # User gedeone-octave # Date 1374497915 -7200 # Node ID fe29ca22b1ec4278703aa0e62d945ad47b1ddd68 # Parent a64e195d061125e8d42e8fecd58a6e68d0f5c63e Functions which plot and save a function object. * fem_plot: plot an object of type function, using dolfin * fem_save: save an object of type function, in the .pvd format * Makefile: compile also these new functions diff -r a64e195d0611 -r fe29ca22b1ec src/Makefile.in --- a/src/Makefile.in Mon Jul 22 14:56:51 2013 +0200 +++ b/src/Makefile.in Mon Jul 22 14:58:35 2013 +0200 @@ -8,6 +8,9 @@ fem_coeff.oct \ fem_lhs.oct \ fem_rhs.oct \ + fem_func.oct \ + fem_plot.oct \ + fem_save.oct \ LIBS += -ldolfin @@ -16,7 +19,7 @@ fem_init_env.oct: fem_init_env.o $(MKOCTFILE) $(CPPFLAGS) -s fem_init_env.o -o $@ $(LDFLAGS) $(LIBS) -fem_init_env.o: fem_init_env.cc mesh.h functionspace.h boundarycondition.h +fem_init_env.o: fem_init_env.cc mesh.h functionspace.h boundarycondition.h function.h coefficient.h $(MKOCTFILE) $(CPPFLAGS) -c fem_init_env.cc $(LDFLAGS) -o $@ -I. fem_init_mesh.oct: mesh.o fem_init_mesh.o fem_init_env.o @@ -64,6 +67,24 @@ fem_rhs.o: fem_rhs.cc expression.h Laplace.h $(MKOCTFILE) $(CPPFLAGS) -c fem_rhs.cc $(LDFLAGS) -o $@ -I. +fem_func.oct: fem_func.o fem_init_env.o + $(MKOCTFILE) $(CPPFLAGS) -s fem_init_env.o fem_func.o -o $@ $(LDFLAGS) $(LIBS) + +fem_func.o: fem_func.cc function.h + $(MKOCTFILE) $(CPPFLAGS) -c fem_func.cc $(LDFLAGS) -o $@ -I. + +fem_plot.oct: fem_plot.o fem_init_env.o + $(MKOCTFILE) $(CPPFLAGS) -s fem_init_env.o fem_plot.o -o $@ $(LDFLAGS) $(LIBS) + +fem_plot.o: fem_plot.cc + $(MKOCTFILE) $(CPPFLAGS) -c fem_plot.cc $(LDFLAGS) -o $@ -I. + +fem_save.oct: fem_save.o fem_init_env.o + $(MKOCTFILE) $(CPPFLAGS) -s fem_init_env.o fem_save.o -o $@ $(LDFLAGS) $(LIBS) + +fem_save.o: fem_save.cc + $(MKOCTFILE) $(CPPFLAGS) -c fem_save.cc $(LDFLAGS) -o $@ -I. + Laplace.h: Laplace.ufl ffc -l dolfin Laplace.ufl @@ -71,7 +92,8 @@ -rm -f *.o core octave-core *.oct *~ *.xml cleanall: - -rm -f *.o core octave-core *.oct *~ *.xml *.status *.log octave-workspace configure Laplace.h + -rm -f *.o core octave-core *.oct *~ *.xml *.status *.log \ + octave-workspace configure Laplace.h *.pvd *.vtu -rm -r autom4te.cache -rm -f Makefile diff -r a64e195d0611 -r fe29ca22b1ec src/fem_plot.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fem_plot.cc Mon Jul 22 14:58:35 2013 +0200 @@ -0,0 +1,35 @@ +#include +#include "function.h" + +DEFUN_DLD (fem_plot, args, , "fem_plot: functionspace V, vector u") +{ + + 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 a64e195d0611 -r fe29ca22b1ec src/fem_save.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fem_save.cc Mon Jul 22 14:58:35 2013 +0200 @@ -0,0 +1,37 @@ +#include +#include "function.h" + +DEFUN_DLD (fem_save, args, , "fem_save: function V, string name") +{ + + 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; +}