changeset 47:fe29ca22b1ec

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
author gedeone-octave <marco.vassallo@outlook.com>
date Mon, 22 Jul 2013 14:58:35 +0200
parents a64e195d0611
children c73bca616ca7
files src/Makefile.in src/fem_plot.cc src/fem_save.cc
diffstat 3 files changed, 96 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- /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 <dolfin.h>
+#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<const function&> (args(0).get_rep ());
+
+          if (!error_state)
+            {
+              const boost::shared_ptr<const dolfin::Function> & u = uo.get_pfun ();
+              dolfin::plot (*u);
+              dolfin::interactive ();
+              retval = 0;
+            }
+        }
+    }
+  return retval;
+}
--- /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 <dolfin.h>
+#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<const function&> (args(0).get_rep ());
+          std::string str = args(1).string_value ();
+
+          if (!error_state)
+            {
+              const boost::shared_ptr<const dolfin::Function> & u = uo.get_pfun ();
+              str += ".pvd";
+              dolfin::File file (str);
+              file << (*u);
+              retval = 0;
+            }
+        }
+    }
+  return retval;
+}