MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_assert_print_nan_inf.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <ostream>
43 #include <iomanip>
44 
47 #include "RTOp_ROp_find_nan_inf.h"
48 #include "RTOpPack_RTOpC.hpp"
49 #include "check_nan_inf.h"
50 #include "Teuchos_Assert.hpp"
51 
52 namespace {
53 
54 // Find a NaN or Inf element!
55 static RTOpPack::RTOpC find_nan_inf_op;
56 static Teuchos::RCP<RTOpPack::ReductTarget> find_nan_inf_targ;
57 
58 class init_rtop_server_t {
59 public:
60  init_rtop_server_t() {
62  find_nan_inf_targ = find_nan_inf_op.reduct_obj_create();
63  }
64 };
65 
66 init_rtop_server_t init_rtop_server;
67 
68 } // end namespace
69 
70 bool AbstractLinAlgPack::assert_print_nan_inf( const value_type& val, const char name[]
71  , bool throw_excpt, std::ostream* out )
72 {
73  if( RTOp_is_nan_inf(val) ) {
74  std::ostringstream omsg;
75  omsg
76  << "The scalar \"" << name
77  << "\" = " << val << " is not a valid bounded number";
78  if(out)
79  *out << omsg.str() << std::endl;
81  throw_excpt,NaNInfException
82  ,"assert_print_nan_inf(...) : Error, " << omsg.str() );
83  return false;
84  }
85  return true;
86 }
87 
89  const Vector& v, const char name[]
90  ,bool throw_excpt, std::ostream* out
91  )
92 {
93  find_nan_inf_op.reduct_obj_reinit(find_nan_inf_targ.ptr());
94  const Vector* vecs[1] = { &v };
95  apply_op(find_nan_inf_op,1,vecs,0,NULL,&*find_nan_inf_targ);
97  ele =RTOp_ROp_find_nan_inf_val(find_nan_inf_op(*find_nan_inf_targ));
98  if(out && ele.i) {
99  *out
100  << "The vector \"" << name << "\" has the first following NaN or Inf element\n"
101  << name << "(" << ele.i << ") = " << ele.v0_i << std::endl;
102  }
104  ele.i && throw_excpt, NaNInfException
105  ,"assert_print_nan_inf(...) : Error, the vector named "
106  << name << " has at least one element which is NaN or Inf" );
107 
108  return ele.i == 0;
109 }
Adapter subclass that uses a RTOp_RTOp object.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
struct RTOp_ROp_find_nan_inf_reduct_obj_t RTOp_ROp_find_nan_inf_val(RTOp_ReductTarget targ_obj)
int RTOp_ROp_find_nan_inf_construct(struct RTOp_RTOp *op)
Ptr< T > ptr() const
std::ostream * out
RTOp_RTOp & op()
bool assert_print_nan_inf(const value_type &val, const char name[], bool throw_excpt, std::ostream *out)
This function asserts if a value_type scalare is a NaN or Inf and optionally prints out these entires...
int RTOp_is_nan_inf(RTOp_value_type val)
void apply_op(EApplyBy apply_by, const RTOpPack::RTOp &primary_op, const size_t num_multi_vecs, const MultiVector *multi_vecs[], const size_t num_targ_multi_vecs, MultiVectorMutable *targ_multi_vecs[], RTOpPack::ReductTarget *reduct_objs[]=NULL, const index_type primary_first_ele=1, const index_type primary_sub_dim=0, const index_type primary_global_offset=0, const index_type secondary_first_ele=1, const index_type secondary_sub_dim=0)
Apply a reduction/transformation operator column by column and return an array of the reduction objec...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)