changeset 241:0f14cdbcaed3

feval.cc: stop computation after an error occurs
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Wed, 25 Jun 2014 20:36:04 +0200
parents a57001686abb
children 958a0e0e8102
files src/feval.cc
diffstat 1 files changed, 45 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- 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 <gedeone-octave@users.sourceforge.net>
+ Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
 
  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 <Matrix> 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 <Matrix> 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<double> point (dim_vector (pdim, 1));
-                  for (octave_idx_type el = 0; el < pdim; ++el)
-                    point (el) = coordinates[el] (k);
-                  dolfin::Array<double> 
-                    x (point.length (), point.fortran_vec ());
+                      for (octave_idx_type k = 0; k < dims.numel (); ++k)
+                        {
+                          Array<double> point (dim_vector (pdim, 1));
+                          for (octave_idx_type el = 0; el < pdim; ++el)
+                            point (el) = coordinates[el] (k);
+                          dolfin::Array<double> 
+                            x (point.length (), point.fortran_vec ());
 
-                  Array<double> res (dim_vector (vdim, 1));
-                  dolfin::Array<double> 
-                    values (res.length (), res.fortran_vec ());
-                  try
-                    {
-                      f->eval (values, x);
+                          Array<double> res (dim_vector (vdim, 1));
+                          dolfin::Array<double> 
+                            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<Matrix>::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<Matrix>::iterator it = evaluations.begin ();
-                   it != evaluations.end (); ++it)
-                retval.append (octave_value (*it));
             }
         }
     }