diff --git a/src/@function/feval.cc b/src/@function/feval.cc --- a/src/@function/feval.cc +++ b/src/@function/feval.cc @@ -20,8 +20,9 @@ #include #include #include "dolfin_compat.h" +#include -DEFUN_DLD (feval, args, nargout, "-*- texinfo -*-\n\ +DEFMETHOD_DLD (feval, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{fx}, @var{fy}, @var{fz}]} = \ feval (@var{function_name}, @var{x}, @var{y}, @var{z})\n\ Evaluate a function at a specific point of the domain and return the value. \n\ @@ -44,7 +45,7 @@ This is the expected call for a scalar f { function::register_type (); function_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == function::static_type_id ()) @@ -52,7 +53,6 @@ This is the expected call for a scalar f const function & fspo = static_cast (args(0).get_rep ()); - if (!error_state) { const SHARED_PTR & f = fspo.get_pfun (); @@ -67,7 +67,7 @@ This is the expected call for a scalar f for (octave_idx_type in = 1; in <= pdim; ++in) { - if (! args(in).is_real_type ()) + if (! args(in).isreal ()) { error ("invalid argument"); } else { @@ -81,7 +81,7 @@ This is the expected call for a scalar f { std::string msg = "all the input matrices should"; msg += " have the same size"; - error (msg.c_str ()); + error ("%s", msg.c_str ()); break; } } @@ -89,7 +89,6 @@ This is the expected call for a scalar f } } - if (! error_state) { octave_idx_type vdim = f->value_dimension (0); if (nargout != vdim) @@ -119,7 +118,7 @@ This is the expected call for a scalar f { std::string msg = "cannot evaluate a function"; msg += " outside of its domain"; - error (msg.c_str ()); + error ("%s", msg.c_str ()); break; } @@ -127,7 +126,6 @@ This is the expected call for a scalar f { evaluations[el] (k) = res (el); } } - if (! error_state) { for (std::vector::iterator it = evaluations.begin (); diff --git a/src/@function/plot.cc b/src/@function/plot.cc --- a/src/@function/plot.cc +++ b/src/@function/plot.cc @@ -17,8 +17,9 @@ #include "function.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (plot, args, , "-*- texinfo -*-\n\ +DEFMETOD_DLD (plot, interp, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} \ plot (@var{Function})\n\ Plot a Function. \n\ @@ -37,7 +38,7 @@ Plot a Function. \n\ { function::register_type (); function_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == function::static_type_id ()) diff --git a/src/@function/save.cc b/src/@function/save.cc --- a/src/@function/save.cc +++ b/src/@function/save.cc @@ -17,8 +17,9 @@ #include "function.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (save, args, , "-*- texinfo -*-\n\ +DEFMETHOD_DLD (save, interp, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} \ save (@var{Function}, @var{Name})\n\ Save a function in vtu format.\n\ @@ -43,7 +44,7 @@ The output is a file in format .vtu\n\ { function::register_type (); function_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == function::static_type_id ()) { diff --git a/src/@mesh/plot.cc b/src/@mesh/plot.cc --- a/src/@mesh/plot.cc +++ b/src/@mesh/plot.cc @@ -20,8 +20,9 @@ #include "Plot_2d.h" #include "Plot_3d.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (plot, args, , "-*- texinfo -*-\n\ +DEFMETHOD_DLD (plot, interp, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} \ plot (@var{Mesh}, @var{Nodal_Values}(OPTIONAL))\n\ Plot a Mesh. \n\ @@ -42,7 +43,7 @@ the values of a function at each node.\n { mesh::register_type (); mesh_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == mesh::static_type_id ()) @@ -51,7 +52,6 @@ the values of a function at each node.\n if (nargin == 1) { - if (!error_state) { const SHARED_PTR & mshd = msho.get_pmsh (); @@ -65,7 +65,6 @@ the values of a function at each node.\n { Array myu = args(1).array_value (); - if (!error_state) { const SHARED_PTR & mshd = msho.get_pmsh (); SHARED_PTR V; diff --git a/src/@mesh/save.cc b/src/@mesh/save.cc --- a/src/@mesh/save.cc +++ b/src/@mesh/save.cc @@ -16,8 +16,9 @@ */ #include "mesh.h" +#include -DEFUN_DLD (save, args, nargout, "-*- texinfo -*-\n\ +DEFMETHOD_DLD (save, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} \ save (@var{Mesh}, @var{Name})\n\ Save a mesh in XDMF format.\n\ @@ -41,7 +42,7 @@ The output is a .xdmf file.\n\ { mesh::register_type (); mesh_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == mesh::static_type_id () && @@ -51,7 +52,6 @@ The output is a .xdmf file.\n\ static_cast (args(0).get_rep ()); std::string str = args(1).string_value (); - if (!error_state) { dolfin::Mesh const & msh = msh_arg.get_msh (); str += ".xdmf"; diff --git a/src/@meshfunction/save.cc b/src/@meshfunction/save.cc --- a/src/@meshfunction/save.cc +++ b/src/@meshfunction/save.cc @@ -16,8 +16,9 @@ */ #include "meshfunction.h" +#include -DEFUN_DLD (save, args, nargout, "-*- texinfo -*-\n\ +DEFMETHOD_DLD (save, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} \ save (@var{MeshFunction}, @var{Name})\n\ Save a meshfunction in XDMF format.\n\ @@ -41,7 +42,7 @@ The output is a .xdmf file.\n\ { meshfunction::register_type (); meshfunction_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == meshfunction::static_type_id () && diff --git a/src/DirichletBC.cc b/src/DirichletBC.cc --- a/src/DirichletBC.cc +++ b/src/DirichletBC.cc @@ -20,8 +20,9 @@ #include "expression.h" #include "meshfunction.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (DirichletBC, args, , +DEFMETHOD_DLD (DirichletBC, interp, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{bc}]} = \ DirichletBC (@var{FunctionSpace}, @var{Function_handle}, [@var{Boundaries},] \ @@ -56,21 +57,21 @@ The output @var{bc} is an object which c { functionspace::register_type (); functionspace_type_loaded = true; - mlock (); + interp.mlock (); } if (! boundarycondition_type_loaded) { boundarycondition::register_type (); boundarycondition_type_loaded = true; - mlock (); + interp.mlock (); } if (! meshfunction_type_loaded) { meshfunction::register_type (); meshfunction_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == functionspace::static_type_id ()) @@ -83,13 +84,12 @@ The output @var{bc} is an object which c { Array side = args(2).array_value (); - if (!error_state) { const SHARED_PTR & V (fspo.get_pfsp ()); octave_value_list b (3, 1); - octave_value_list tmp = feval (fh->function_value (), b); + octave_value_list tmp = interp.feval (fh->function_value (), b); Array res = tmp(0).array_value (); std::size_t l = res.numel (); @@ -114,13 +114,12 @@ The output @var{bc} is an object which c meshfunction const & mf = static_cast (args(2).get_rep ()); - if (! error_state) { const SHARED_PTR & V (fspo.get_pfsp ()); octave_value_list b (3, 1); - octave_value_list tmp = feval (fh->function_value (), b); + octave_value_list tmp = interp.feval (fh->function_value (), b); Array res = tmp(0).array_value (); std::size_t l = res.numel (); diff --git a/src/Expression.cc b/src/Expression.cc --- a/src/Expression.cc +++ b/src/Expression.cc @@ -16,8 +16,9 @@ */ #include "coefficient.h" +#include -DEFUN_DLD (Expression, args, , +DEFMETHOD_DLD (Expression, interp, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{f}]} = \ Expression (@var{name}, @var{Function_handle})\n\ @@ -48,13 +49,12 @@ of the function\n\ { coefficient::register_type (); coefficient_type_loaded = true; - mlock (); + interp.mlock (); } - if (!error_state) { octave_value_list b (3, 1); - octave_value_list tmp = feval (fh->function_value (), b); + octave_value_list tmp = interp.feval (fh->function_value (), b); Array res = tmp(0).array_value (); std::size_t l = res.numel (); diff --git a/src/Function.cc b/src/Function.cc --- a/src/Function.cc +++ b/src/Function.cc @@ -24,10 +24,11 @@ #include #include #endif +#include void copy_vector (Array const &, SHARED_PTR ); -DEFUN_DLD (Function, args, , "-*- texinfo -*-\n\ +DEFMETHOD_DLD (Function, interp, args, , "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{func}]} = \ Function (@var{name}, @var{FunctionSpace}, @var{Vector})\n\ @deftypefnx {Function File} {[@var{func}]} = \ @@ -71,14 +72,14 @@ of its domain.\n\ { functionspace::register_type (); functionspace_type_loaded = true; - mlock (); + interp.mlock (); } if (! function_type_loaded) { function::register_type (); function_type_loaded = true; - mlock (); + interp.mlock (); } if (args(1).type_id () == functionspace::static_type_id ()) @@ -88,7 +89,6 @@ of its domain.\n\ static_cast (args(1).get_rep ()); Array myu = args(2).array_value (); - if (!error_state) { const SHARED_PTR & V = fspo.get_pfsp (); @@ -116,7 +116,6 @@ of its domain.\n\ static_cast (args(1).get_rep ()); int idx = args(2).int_value (); - if (!error_state) { const SHARED_PTR & f = fspo.get_pfun (); diff --git a/src/Mesh.cc b/src/Mesh.cc --- a/src/Mesh.cc +++ b/src/Mesh.cc @@ -22,6 +22,7 @@ #ifdef LATEST_DOLFIN #include #endif +#include octave_value compute_facet_markers (SHARED_PTR , @@ -32,7 +33,7 @@ compute_cell_markers (SHARED_PTR const &, std::size_t const); -DEFUN_DLD (Mesh, args, nargout, "-*- texinfo -*-\n\ +DEFMETHOD_DLD (Mesh, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{mesh}]} = Mesh (@var{file}) \n\ @deftypefnx {Function File} {[@var{mesh}, @var{facets}, @var{cells}]} = \ Mesh (@var{pet_mesh}) \n\ @@ -60,14 +61,13 @@ The easiest way for dealing with meshes { print_usage (); } else { - if (!error_state) { if (! mesh_type_loaded) { mesh::register_type (); mesh_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).is_string () == true) @@ -97,14 +97,13 @@ The easiest way for dealing with meshes } } - else if (args(0).is_map () == true) + else if (args(0).isstruct () == true) { octave_scalar_map a = args(0).scalar_map_value (); Array p = a.contents ("p").matrix_value (); Array t = a.contents ("t").matrix_value (); Array e = a.contents ("e").matrix_value (); - if (! error_state) { retval(0) = new mesh (p, e, t); @@ -114,7 +113,7 @@ The easiest way for dealing with meshes { meshfunction::register_type (); meshfunction_type_loaded = true; - mlock (); + interp.mlock (); } mesh const & msh_ov = diff --git a/src/MeshFunction.cc b/src/MeshFunction.cc --- a/src/MeshFunction.cc +++ b/src/MeshFunction.cc @@ -19,8 +19,9 @@ #include "mesh.h" #include "meshfunction.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (MeshFunction, args, nargout, "-*- texinfo -*-\n\ +DEFMETHOD_DLD (MeshFunction, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{meshfunc}]} = \ MeshFunction (@var{Mesh}, @var{filename})\n\ @deftypefnx {Function File} {[@var{meshfunc}]} = \ @@ -53,14 +54,14 @@ of its values to @var{value}, which is a { mesh::register_type (); mesh_type_loaded = true; - mlock (); + interp.mlock (); } if (! meshfunction_type_loaded) { meshfunction::register_type (); meshfunction_type_loaded = true; - mlock (); + interp.mlock (); } octave_idx_type offset = 0; @@ -80,7 +81,7 @@ of its values to @var{value}, which is a if (args(1 + offset).is_string ()) { std::string filename = args(1 + offset).string_value (); - if (!error_state) + { SHARED_PTR const & pmsh = msh_arg.get_pmsh (); @@ -97,7 +98,6 @@ of its values to @var{value}, which is a std::size_t dim = args(1 + offset).ulong_value (); std::size_t value = args(2 + offset).ulong_value (); - if (!error_state) { SHARED_PTR const & pmsh = msh_arg.get_pmsh (); diff --git a/src/SubDomain.cc b/src/SubDomain.cc --- a/src/SubDomain.cc +++ b/src/SubDomain.cc @@ -17,8 +17,9 @@ #include #include "subdomain.h" +#include -DEFUN_DLD (SubDomain, args, nargout, +DEFMETHOD_DLD (SubDomain, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{subdomain}]} = \ SubDomain (@var{inside}, @var{boundary})\n\ @@ -41,7 +42,7 @@ entities. @var{subdomain} can be used to { subdomain::register_type (); subdomain_type_loaded = true; - mlock (); + interp.mlock (); } octave_fcn_handle * pfh = args(0).fcn_handle_value (); diff --git a/src/assemble.cc b/src/assemble.cc --- a/src/assemble.cc +++ b/src/assemble.cc @@ -19,8 +19,9 @@ #include "boundarycondition.h" #include "femfenics_factory.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (assemble, args, nargout, +DEFMETHOD_DLD (assemble, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{A}], [@var{x}(Optional)]} = \ assemble (@var{form_a}, @var{DirichletBC}) \n\ @@ -54,14 +55,14 @@ to the HyperElasticity example. \n\ { boundarycondition::register_type (); boundarycondition_type_loaded = true; - mlock (); + interp.mlock (); } if (! form_type_loaded) { form::register_type (); form_type_loaded = true; - mlock (); + interp.mlock (); } if (nargout == 1) @@ -74,7 +75,6 @@ to the HyperElasticity example. \n\ { const form & frm = static_cast (args(0).get_rep ()); - if (! error_state) { const dolfin::Form & a = frm.get_form (); a.check (); @@ -163,7 +163,6 @@ to the HyperElasticity example. \n\ static_cast (args(0).get_rep ()); const Array myx = args(1).array_value (); - if (! error_state) { const dolfin::Form & a = frm.get_form (); a.check (); diff --git a/src/assemble_system.cc b/src/assemble_system.cc --- a/src/assemble_system.cc +++ b/src/assemble_system.cc @@ -19,8 +19,9 @@ #include "boundarycondition.h" #include "femfenics_factory.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (assemble_system, args, nargout, +DEFMETHOD_DLD (assemble_system, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{A}], [@var{b}], [@var{x}(Optional)]} = \ assemble_system (@var{form_a}, @var{form_L}, @var{DirichletBC})\n\ @@ -47,14 +48,14 @@ to the HyperElasticity example. \n\ { form::register_type (); form_type_loaded = true; - mlock (); + interp.mlock (); } if (! boundarycondition_type_loaded) { boundarycondition::register_type (); boundarycondition_type_loaded = true; - mlock (); + interp.mlock (); } if (nargout == 2) @@ -72,7 +73,6 @@ to the HyperElasticity example. \n\ const form & frm2 = static_cast (args(1).get_rep ()); - if (! error_state) { const dolfin::Form & a = frm1.get_form (); const dolfin::Form & b = frm2.get_form (); @@ -112,8 +112,11 @@ to the HyperElasticity example. \n\ retval(1) = factory.vector (B); } } +#if 0 + // USE try and catch execution error if you want specific error message here. else { error ("assemble_system: unknown size"); } +#endif } } } @@ -132,7 +135,6 @@ to the HyperElasticity example. \n\ static_cast (args(1).get_rep ()); const Array myx = args(2).array_value (); - if (! error_state) { const dolfin::Form & a = frm1.get_form (); const dolfin::Form & b = frm2.get_form (); @@ -183,8 +185,11 @@ to the HyperElasticity example. \n\ retval(2) = factory.vector (x); } } +#if 0 + // USE try and catch execution error if you want specific error message here. else { error ("assemble_system: unknown size"); } +#endif } } } diff --git a/src/expression.h b/src/expression.h --- a/src/expression.h +++ b/src/expression.h @@ -25,6 +25,7 @@ #include #include #include +#include class expression : public dolfin::Expression { @@ -50,7 +51,8 @@ class expression : public dolfin::Expres b.resize (x.size ()); for (std::size_t i = 0; i < x.size (); ++i) b(i) = x[i]; - octave_value_list tmp = feval (f->function_value (), b); + octave::interpreter *interp = octave::interpreter::the_interpreter (); + octave_value_list tmp = interp->feval (f->function_value (), b); Array res = tmp(0).array_value (); for (std::size_t i = 0; i < values.size (); ++i) diff --git a/src/femfenics_factory.cc b/src/femfenics_factory.cc --- a/src/femfenics_factory.cc +++ b/src/femfenics_factory.cc @@ -18,6 +18,7 @@ #include "femfenics_factory.h" #include "PETSc_factory.h" #include +#include femfenics_base_factory const & femfenics_factory::factory (void) const @@ -31,7 +32,8 @@ femfenics_factory::factory (void) const std::string femfenics_factory::linear_algebra_backend (void) const { - octave_value_list ovl = feval ("linear_algebra_backend"); + octave::interpreter *interp = octave::interpreter::the_interpreter (); + octave_value_list ovl = interp->feval ("linear_algebra_backend"); std::string retval = ovl (0).string_value (); return retval; } diff --git a/src/function.h b/src/function.h --- a/src/function.h +++ b/src/function.h @@ -24,6 +24,7 @@ #include #include #include "dolfin_compat.h" +#include class function : public octave_base_value { @@ -74,9 +75,8 @@ public: subsref (const std::string & type, const std::list & idx) { - octave_value retval; - retval = subsref (type, idx, 1); - return retval; + octave_value_list tmp = subsref (type, idx, 1); + return tmp.length () > 0 ? tmp(0) : octave_value (); } octave_value_list @@ -115,7 +115,8 @@ public: octave_value_list retval; std::list args (1, idx); args.push_front (octave_value (new function (*this))); - retval = feval ("feval", args, nargout); + octave::interpreter *interp = octave::interpreter::the_interpreter (); + retval = interp->feval ("feval", args, nargout); return retval; } diff --git a/src/interpolate.cc b/src/interpolate.cc --- a/src/interpolate.cc +++ b/src/interpolate.cc @@ -20,8 +20,9 @@ #include "functionspace.h" #include #include "dolfin_compat.h" +#include -DEFUN_DLD (interpolate, args, nargout, "-*- texinfo -*-\n\ +DEFMETHOD_DLD (interpolate, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} @var{interp} = \ interpolate (@var{name}, @var{u}, @var{v})\n\ Interpolate a function on a FunctionSpace.\n\ @@ -46,21 +47,21 @@ it will default to the one assigned to @ { function::register_type (); function_type_loaded = true; - mlock (); + interp.mlock (); } if (! coefficient_type_loaded) { coefficient::register_type (); coefficient_type_loaded = true; - mlock (); + interp.mlock (); } if (! functionspace_type_loaded) { functionspace::register_type (); functionspace_type_loaded = true; - mlock (); + interp.mlock (); } octave_idx_type offset = 0; @@ -76,7 +77,6 @@ it will default to the one assigned to @ const functionspace & u1 = static_cast (args(1 + offset).get_rep ()); - if (! error_state) { SHARED_PTR output (new dolfin::Function (u1.get_pfsp ())); @@ -86,14 +86,13 @@ it will default to the one assigned to @ const function & u0 = static_cast (args(0 + offset).get_rep ()); - if (! error_state) { try { output->interpolate (u0.get_fun ()); } catch (std::runtime_error &) { error ("unable to interpolate on this function space"); } - if (! error_state) + { if (name.empty ()) { name = u0.get_str (); } @@ -107,14 +106,13 @@ it will default to the one assigned to @ const coefficient & u0 = static_cast (args(0 + offset).get_rep ()); - if (! error_state) { try { output->interpolate (* u0.get_expr ()); } catch (std::runtime_error &) { error ("unable to interpolate on this function space"); } - if (! error_state) + { if (name.empty ()) { name = u0.get_str (); } @@ -131,7 +129,6 @@ it will default to the one assigned to @ const function & u0 = static_cast (args(1 + offset).get_rep ()); - if (! error_state) { SHARED_PTR output (new dolfin::Function (u0.get_fun ())); @@ -141,14 +138,13 @@ it will default to the one assigned to @ const function & u1 = static_cast (args(0 + offset).get_rep ()); - if (! error_state) { try { output->interpolate (u1.get_fun ()); } catch (std::runtime_error &) { error ("unable to interpolate on this function space"); } - if (! error_state) + { if (name.empty ()) { name = u1.get_str (); } @@ -162,14 +158,13 @@ it will default to the one assigned to @ const coefficient & u1 = static_cast (args(0 + offset).get_rep ()); - if (! error_state) { try { output->interpolate (* u1.get_expr ()); } catch (std::runtime_error &) { error ("unable to interpolate on this function space"); } - if (! error_state) + { if (name.empty ()) { name = u1.get_str (); } diff --git a/src/mark.cc b/src/mark.cc --- a/src/mark.cc +++ b/src/mark.cc @@ -19,8 +19,9 @@ #include "meshfunction.h" #include "subdomain.h" #include "dolfin_compat.h" +#include -DEFUN_DLD (mark, args, nargout, +DEFMETHOD_DLD (mark, interp, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} {[@var{markers}]} = \ mark (@var{subdomain}, @var{meshfunction}, @var{number})\n\ @@ -41,13 +42,13 @@ where entities inside @var{subdomain} ar { meshfunction::register_type (); meshfunction_type_loaded = true; - mlock (); + interp.mlock (); } if (! subdomain_type_loaded) { subdomain::register_type (); subdomain_type_loaded = true; - mlock (); + interp.mlock (); } if (args(0).type_id () == subdomain::static_type_id () && @@ -60,7 +61,6 @@ where entities inside @var{subdomain} ar meshfunction const & mf = static_cast (args(1).get_rep ()); - if (! error_state) { dolfin::MeshFunction out = mf.get_mf (); SHARED_PTR const & sdrep = sd.get_psd (); diff --git a/src/subdomain_rep.h b/src/subdomain_rep.h --- a/src/subdomain_rep.h +++ b/src/subdomain_rep.h @@ -25,6 +25,7 @@ #include #include #include +#include class subdomain_rep : public dolfin::SubDomain { @@ -46,7 +47,8 @@ public: b.resize (x.size ()); for (std::size_t i = 0; i < x.size (); ++i) { b(i) = x[i]; } - octave_value_list tmp = feval (pfh->function_value (), b); + octave::interpreter *interp = octave::interpreter::the_interpreter (); + octave_value_list tmp = interp->feval (pfh->function_value (), b); bool retval = tmp(0).bool_value (); if (check_boundary) { retval = retval && on_boundary; }