|
Belos Version of the Day
|
00001 //@HEADER 00002 // ************************************************************************ 00003 // 00004 // Belos: Block Linear Solvers Package 00005 // Copyright 2004 Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // ************************************************************************ 00040 //@HEADER 00041 00042 #ifndef __Belos_MonomialOpAkx_hpp 00043 #define __Belos_MonomialOpAkx_hpp 00044 00045 #include <BelosOpAkx.hpp> 00046 00047 namespace Belos { 00048 00056 template<class Scalar, class MV, class OP> 00057 class MonomialOpAkx : public OpAkx<Scalar, MV, OP> { 00058 public: 00059 MonomialOpAkx (const Teuchos::RCP<const OP>& A, 00060 const Teuchos::RCP<const OP>& M_left, 00061 const Teuchos::RCP<const OP>& M_right, 00062 const int recommendedBasisLength) : 00063 OpAkx (A, M_left, M_right, recommendedBasisLength) {} 00064 00065 void 00066 computeBasis (const MV& q_last, MV& V_cur, const int s) 00067 { 00068 using Teuchos::Range1D; 00069 using Teuchos::RCP; 00070 using Teuchos::rcp_const_cast; 00071 typedef MultiVecTraits<Scalar, MV> MVT; 00072 00073 TEUCHOS_TEST_FOR_EXCEPTION(s < 0, std::invalid_argument, 00074 "Number of basis vectors to compute (s = " 00075 << s << ") is invalid; it must be positive."); 00076 if (s == 0) 00077 return; // Nothing to do 00078 TEUCHOS_TEST_FOR_EXCEPTION(MVT::GetNumberVecs(V_cur) < s, std::invalid_argument, 00079 "You're asking to compute s = " << s << " basis " 00080 "vectors, but only have room for " 00081 << MVT::GetNumberVecs(V_cur) << "."); 00082 RCP<const MV> v_prv = Teuchos::rcpFromRef (q_last); 00083 for (int k = 0; k < s; ++k, v_prv) 00084 { 00085 RCP<MV> v_cur = MVT::CloneViewNonConst (V_cur, Range1D(k,k)); 00086 applyOp (v_prv, v_cur); 00087 v_prv = rcp_const_cast<const MV> (v_cur); 00088 } 00089 } 00090 00091 void 00092 computeFlexibleBasis (const MV& q_last, 00093 MV& Z_cur, 00094 MV& V_cur, 00095 const int s) 00096 { 00097 using Teuchos::Range1D; 00098 using Teuchos::RCP; 00099 using Teuchos::rcp_const_cast; 00100 typedef MultiVecTraits<Scalar, MV> MVT; 00101 00102 TEUCHOS_TEST_FOR_EXCEPTION(s < 0, std::invalid_argument, 00103 "Number of basis vectors to compute (s = " 00104 << s << ") is invalid; it must be positive."); 00105 if (s == 0) 00106 return; // Nothing to do 00107 TEUCHOS_TEST_FOR_EXCEPTION(MVT::GetNumberVecs(V_cur) < s, std::invalid_argument, 00108 "You're asking to compute s = " << s << " basis " 00109 "vectors, but only have room for " 00110 << MVT::GetNumberVecs(V_cur) << " in V_cur."); 00111 TEUCHOS_TEST_FOR_EXCEPTION(MVT::GetNumberVecs(Z_cur) < s, std::invalid_argument, 00112 "You're asking to compute s = " << s << " basis " 00113 "vectors, but only have room for " 00114 << MVT::GetNumberVecs(Z_cur) << " in Z_cur."); 00115 RCP<const MV> v_prv = Teuchos::rcpFromRef (q_last); 00116 for (int k = 0; k < s; ++k, v_prv) 00117 { 00118 RCP<MV> z_cur = MVT::CloneViewNonConst (Z_cur, Range1D(k,k)); 00119 RCP<MV> v_cur = MVT::CloneViewNonConst (V_cur, Range1D(k,k)); 00120 applyFlexibleOp (v_prv, z_cur, v_cur); 00121 v_prv = rcp_const_cast<const MV> (v_cur); 00122 } 00123 } 00124 00125 Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,Scalar> > 00126 changeOfBasisMatrix (const int s) 00127 { 00128 using Teuchos::rcp; 00129 typedef Teuchos::SerialDenseMatrix<int,Scalar> mat_type; 00130 typedef Teuchos::ScalarTraits<Scalar> STS; 00131 00132 if (B_.is_null()) 00133 B_ = makeChangeOfBasisMatrix (s); 00134 else if (B_->numRows() != s+1 || B_->numCols() != s) 00135 B_ = makeChangeOfBasisMatrix (s); 00136 return B_; 00137 } 00138 00139 void 00140 updateBasis (const Teuchos::ArrayView<const magnitude_type>& realParts, 00141 const Teuchos::ArrayView<const magnitude_type>& imagParts, 00142 const Teuchos::ArrayView<const int>& multiplicities, 00143 const int numValues) 00144 { // The monomial basis doesn't do anything with approximate 00145 // eigenvalue information. Quiet any compiler warnings about 00146 // unused values. 00147 (void) realParts; 00148 (void) imagParts; 00149 (void) multiplicities; 00150 (void) numValues; 00151 } 00152 00153 private: 00155 static Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,Scalar> > 00156 makeChangeOfBasisMatrix (const int s) 00157 { 00158 using Teuchos::RCP; 00159 typedef Teuchos::SerialDenseMatrix<int,Scalar> mat_type; 00160 typedef Teuchos::ScalarTraits<Scalar> STS; 00161 00162 RCP<mat_type> B (new mat_type (s+1, s)); 00163 for (int j = 0; j < s; ++j) 00164 (*B)(j+1, j) = STS::one(); 00165 return B; 00166 } 00167 00171 Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,Scalar> > B_; 00172 }; 00173 00174 00175 } // namespace Belos 00176 00177 #endif // __Belos_MonomialOpAkx_hpp
1.7.4