MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_TestMatrixSymSecant.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 
45 #include <math.h>
46 
56 
58  const MatrixOp &B
59  ,const Vector &s
60  ,const Vector &y
61  ,value_type warning_tol
62  ,value_type error_tol
63  ,bool print_all_warnings
64  ,std::ostream *out
65  ,bool trase
66  )
67 {
68  using std::setw;
69  using std::endl;
73  using LinAlgOpPack::V_MtV;
74 
75  bool success = true;
76  const char
77  sep_line[] = "\n-----------------------------------------------------------------\n";
78 
79  // Check the secant property (B * s = y)
80  {
81  if( out && trase )
82  *out
83  << sep_line
84  << "\n|(sum(B*s)-sum(y))/||y||inf| = ";
86  Bs = y.space().create_member();
87  V_MtV( Bs.get(), B, BLAS_Cpp::no_trans, s );
88  const value_type
89  sum_Bs = sum(*Bs),
90  sum_y = sum(y),
91  nrm_y = y.norm_inf(),
92  err = ::fabs( (sum_Bs - sum_y) / nrm_y );
93  if( out && trase )
94  *out
95  <<"|("<<sum_Bs<<"-"<<sum_y<<")/"<<nrm_y<<"| = " << err << std::endl;
96  if( err >= error_tol ) {
97  if( out && trase )
98  *out
99  << "Error, above error = " << err << " >= error_tol = " << error_tol
100  << "\nThe test has failed!\n";
101  if(out && print_all_warnings) {
102  *out
103  << "\ns =\n" << s
104  << "\ny =\n" << y
105  << "\nBs =\n" << *Bs
106  << endl;
107  }
108  success = false;
109  }
110  else if( err >= warning_tol ) {
111  if( out && trase )
112  *out
113  << "Warning!, above error = " << err << " >= warning_tol = " << warning_tol << std::endl;
114  }
115  }
116  // Check the secant property (s = inv(B)*y)
117  const MatrixNonsing
118  *B_nonsing = dynamic_cast<const MatrixNonsing*>(&B);
119  if( B_nonsing ) {
120  if( out && trase )
121  *out
122  << sep_line
123  << "\n|(sum(inv(B)*y)-sum(s))/||s||inf| = ";
125  InvBy = s.space().create_member();
126  V_InvMtV( InvBy.get(), *B_nonsing, BLAS_Cpp::no_trans, y );
127  const value_type
128  sum_InvBy = sum(*InvBy),
129  sum_s = sum(s),
130  nrm_s = s.norm_inf(),
131  err = ::fabs( (sum_InvBy - sum_s) / nrm_s );
132  if( out && trase )
133  *out
134  <<"|("<<sum_InvBy<<"-"<<sum_s<<")/"<<nrm_s<<"| = " << err << std::endl;
135  if( err >= error_tol ) {
136  if( out && trase )
137  *out
138  << "Error, above error = " << err << " >= error_tol = " << error_tol
139  << "\nThe test has failed!\n";
140  if(out && print_all_warnings) {
141  *out
142  << "\ns =\n" << s
143  << "\ny =\n" << y
144  << "\ninv(B)*y =\n" << *InvBy
145  << endl;
146  }
147  success = false;
148  }
149  else if( err >= warning_tol ) {
150  if( out && trase )
151  *out
152  << "Warning!, above error = " << err << " >= warning_tol = " << warning_tol << std::endl;
153  }
154  }
155  if( out && trase )
156  *out << sep_line;
157  return success;
158 }
virtual const VectorSpace & space() const =0
Return the vector space that this vector belongs to.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
virtual value_type norm_inf() const
Infinity norm. ||v||_inf = max( |v(i)|, i = 1,,,this->dim() )
T * get() const
Not transposed.
std::ostream * out
const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_dbl_prec const LAPACK_C_Decl::f_int const LAPACK_C_Decl::f_int LAPACK_C_Decl::f_dbl_prec B[]
void V_InvMtV(VectorMutable *v_lhs, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs = inv(op(M_rhs1)) * v_rhs2
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...
Base class for all matrices that support basic matrix operations.
void V_MtV(VectorMutable *v_lhs, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const V &V_rhs2)
v_lhs = op(M_rhs1) * V_rhs2.
bool TestMatrixSymSecant(const MatrixOp &B, const Vector &s, const Vector &y, value_type warning_tol, value_type error_tol, bool print_all_warnings, std::ostream *out, bool trase=true)
Checks the secant condition B*s = y.
value_type sum(const Vector &v_rhs)
result = sum( v_rhs(i), i = 1,,,dim )
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
Abstract base class for all nonsingular polymorphic matrices that can solve for linear system with bu...