AbstractLinAlgPack_assert_print_nan_inf.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <ostream>
00030 #include <iomanip>
00031 
00032 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
00033 #include "AbstractLinAlgPack_Vector.hpp"
00034 #include "RTOp_ROp_find_nan_inf.h"
00035 #include "RTOpPack_RTOpC.hpp"
00036 #include "check_nan_inf.h"
00037 #include "Teuchos_TestForException.hpp"
00038 
00039 namespace {
00040 
00041 // Find a NaN or Inf element!
00042 static RTOpPack::RTOpC                               find_nan_inf_op;
00043 static Teuchos::RCP<RTOpPack::ReductTarget>  find_nan_inf_targ;
00044 
00045 class init_rtop_server_t {
00046 public:
00047   init_rtop_server_t() {
00048     TEST_FOR_EXCEPT(0!=RTOp_ROp_find_nan_inf_construct(&find_nan_inf_op.op() ));
00049     find_nan_inf_targ = find_nan_inf_op.reduct_obj_create();
00050   }
00051 }; 
00052 
00053 init_rtop_server_t  init_rtop_server;
00054 
00055 } // end namespace
00056 
00057 bool AbstractLinAlgPack::assert_print_nan_inf( const value_type& val, char name[]
00058   , bool throw_excpt, std::ostream* out )
00059 {
00060   if( RTOp_is_nan_inf(val) ) {
00061     std::ostringstream omsg;
00062     omsg
00063       << "The scalar \"" << name
00064       << "\" = " << val << " is not a valid bounded number";
00065     if(out)
00066       *out << omsg.str() << std::endl;
00067     TEST_FOR_EXCEPTION(
00068       throw_excpt,NaNInfException
00069       ,"assert_print_nan_inf(...) : Error, " << omsg.str() );
00070     return false;
00071   }
00072   return true;
00073 }
00074 
00075 bool AbstractLinAlgPack::assert_print_nan_inf(
00076   const Vector& v, char name[]
00077   ,bool throw_excpt, std::ostream* out
00078   )
00079 {
00080   find_nan_inf_op.reduct_obj_reinit(&*find_nan_inf_targ);
00081   const Vector* vecs[1] = { &v };
00082   apply_op(find_nan_inf_op,1,vecs,0,NULL,&*find_nan_inf_targ);
00083   RTOp_ROp_find_nan_inf_reduct_obj_t
00084     ele =RTOp_ROp_find_nan_inf_val(find_nan_inf_op(*find_nan_inf_targ));
00085   if(out && ele.i) {
00086     *out
00087       << "The vector \"" << name << "\" has the first following NaN or Inf element\n"
00088       << name << "(" << ele.i << ") = " << ele.v0_i << std::endl;
00089   }
00090   TEST_FOR_EXCEPTION(
00091     ele.i && throw_excpt, NaNInfException
00092     ,"assert_print_nan_inf(...) : Error, the vector named "
00093     << name << " has at least one element which is NaN or Inf" );
00094   
00095   return ele.i == 0;
00096 }

Generated on Tue Jul 13 09:30:49 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7