Mercurial > fem-fenics-eugenio
changeset 105:c3cc050b4805
New function for plotting a vector defined on a Mesh
* Plot_2d.cc: it takes as input a 2d Mesh and a vector which specify the
values of the function on each node of the mesh and plot it.
* Plot_3d.cc: it takes as input a 3d Mesh and a vector which specify the
values of the function on each node of the mesh and plot it.
* Plot_2d.ufl, Plot-3d.ufl: definition of the functional environment for
the plot. (CG eleemnt of degrees 1)
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Tue, 20 Aug 2013 11:20:47 +0200 |
parents | 68262f409ac4 |
children | 6b4a77dc734f |
files | src/Makefile.in src/Plot_2d.cc src/Plot_2d.ufl src/Plot_3d.cc src/Plot_3d.ufl |
diffstat | 5 files changed, 135 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile.in Wed Aug 14 12:26:21 2013 +0200 +++ b/src/Makefile.in Tue Aug 20 11:20:47 2013 +0200 @@ -1,4 +1,5 @@ MKOCTFILE ?= mkoctfile +FFC ?= ffc OCTFILES=fem_init_env.oct\ Mesh.oct \ @@ -10,6 +11,8 @@ fem_save.oct \ assemble.oct \ assemble_system.oct \ + Plot_2d.oct \ + Plot_3d.oct \ LIBS += -ldolfin @@ -76,6 +79,18 @@ 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_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 + clean: -rm -f *.o core octave-core *.oct *~ *.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Plot_2d.cc Tue Aug 20 11:20:47 2013 +0200 @@ -0,0 +1,54 @@ +#include "mesh.h" +#include "Plot_2d.h" + +DEFUN_DLD (Plot_2d, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +fem_func (@var{Function})\n\ +The input parameter is the function that you want to plot\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<const mesh&> (args(0).get_rep ()); + Array <double> myu = args(1).array_value (); + + if (!error_state) + { + const dolfin::Mesh & mshd = msh.get_msh (); + boost::shared_ptr <const dolfin::FunctionSpace> V (new Plot_2d::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<dolfin::Vector> uu (new dolfin::Vector(du)); + boost::shared_ptr <const dolfin::Function> u (new dolfin::Function(V, uu)); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + } + } + return retval; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Plot_2d.ufl Tue Aug 20 11:20:47 2013 +0200 @@ -0,0 +1,6 @@ +CG = FiniteElement("Lagrange", triangle, 1) + +u = TrialFunction (CG) +v = TestFunction (CG) + +a = u*v*dx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Plot_3d.cc Tue Aug 20 11:20:47 2013 +0200 @@ -0,0 +1,54 @@ +#include "mesh.h" +#include "Plot_3d.h" + +DEFUN_DLD (Plot_3d, args, , "-*- texinfo -*-\n\ +@deftypefn {Function File} \ +fem_func (@var{Function})\n\ +The input parameter is the function that you want to plot\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<const mesh&> (args(0).get_rep ()); + Array <double> myu = args(1).array_value (); + + if (!error_state) + { + const dolfin::Mesh & mshd = msh.get_msh (); + boost::shared_ptr <const dolfin::FunctionSpace> 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<dolfin::Vector> uu (new dolfin::Vector(du)); + boost::shared_ptr <const dolfin::Function> u (new dolfin::Function(V, uu)); + dolfin::plot (*u); + dolfin::interactive (); + retval = 0; + } + } + } + } + return retval; +}