# HG changeset patch # User Eugenio Gianniti # Date 1403721364 -7200 # Node ID 0f14cdbcaed3f0e58823025385fb36ca710f2860 # Parent a57001686abb2459cb667a7217192ae77505add4 feval.cc: stop computation after an error occurs diff -r a57001686abb -r 0f14cdbcaed3 src/feval.cc --- a/src/feval.cc Wed Jun 25 10:13:22 2014 +0200 +++ b/src/feval.cc Wed Jun 25 20:36:04 2014 +0200 @@ -1,5 +1,6 @@ /* Copyright (C) 2013 Marco Vassallo + Copyright (C) 2014 Eugenio Gianniti 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 @@ -80,49 +81,60 @@ std::string msg = "all the input matrices should"; msg += " have the same size"; error (msg.c_str ()); + break; } } coordinates.push_back (aux); } } - octave_idx_type vdim = f->value_dimension (0); - if (nargout != vdim) - error ("wrong number of output arguments"); - - std::vector evaluations; - for (octave_idx_type out = 0; out < vdim; ++out) - evaluations.push_back (Matrix (dims)); + if (! error_state) + { + octave_idx_type vdim = f->value_dimension (0); + if (nargout != vdim) + error ("wrong number of output arguments"); + else + { + std::vector evaluations; + for (octave_idx_type out = 0; out < vdim; ++out) + evaluations.push_back (Matrix (dims)); - for (octave_idx_type k = 0; k < dims.numel (); ++k) - { - Array point (dim_vector (pdim, 1)); - for (octave_idx_type el = 0; el < pdim; ++el) - point (el) = coordinates[el] (k); - dolfin::Array - x (point.length (), point.fortran_vec ()); + for (octave_idx_type k = 0; k < dims.numel (); ++k) + { + Array point (dim_vector (pdim, 1)); + for (octave_idx_type el = 0; el < pdim; ++el) + point (el) = coordinates[el] (k); + dolfin::Array + x (point.length (), point.fortran_vec ()); - Array res (dim_vector (vdim, 1)); - dolfin::Array - values (res.length (), res.fortran_vec ()); - try - { - f->eval (values, x); + Array res (dim_vector (vdim, 1)); + dolfin::Array + values (res.length (), res.fortran_vec ()); + try + { + f->eval (values, x); + } + catch (std::runtime_error & err) + { + std::string msg = "cannot evaluate a function"; + msg += " outside of its domain"; + error (msg.c_str ()); + break; + } + + for (octave_idx_type el = 0; el < vdim; ++el) + evaluations[el] (k) = res (el); + } + + if (! error_state) + { + for (std::vector::iterator it = + evaluations.begin (); + it != evaluations.end (); ++it) + retval.append (octave_value (*it)); + } } - catch (std::runtime_error & err) - { - std::string msg = "cannot evaluate a function"; - msg += " outside of its domain"; - error (msg.c_str ()); - } - - for (octave_idx_type el = 0; el < vdim; ++el) - evaluations[el] (k) = res (el); } - - for (std::vector::iterator it = evaluations.begin (); - it != evaluations.end (); ++it) - retval.append (octave_value (*it)); } } }