Belos Version of the Day
BelosMonomialOpAkx.hpp
Go to the documentation of this file.
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 
00053   template<class Scalar, class MV, class OP>
00054   class MonomialOpAkx : public OpAkx<Scalar, MV, OP> {
00055   public:
00056     MonomialOpAkx (const Teuchos::RCP<const OP>& A, 
00057        const Teuchos::RCP<const OP>& M_left,
00058        const Teuchos::RCP<const OP>& M_right,
00059        const int recommendedBasisLength) :
00060       OpAkx (A, M_left, M_right, recommendedBasisLength) {}
00061 
00062     void 
00063     computeBasis (const MV& q_last, MV& V_cur, const int s) 
00064     {
00065       using Teuchos::Range1D;
00066       using Teuchos::RCP;
00067       using Teuchos::rcp_const_cast;
00068       typedef MultiVecTraits<Scalar, MV> MVT;
00069 
00070       TEST_FOR_EXCEPTION(s < 0, std::invalid_argument, 
00071        "Number of basis vectors to compute (s = " 
00072        << s << ") is invalid; it must be positive.");
00073       if (s == 0)
00074   return; // Nothing to do
00075       TEST_FOR_EXCEPTION(MVT::GetNumberVecs(V_cur) < s, std::invalid_argument,
00076        "You're asking to compute s = " << s << " basis "
00077        "vectors, but only have room for " 
00078        << MVT::GetNumberVecs(V_cur) << ".");
00079       RCP<const MV> v_prv = Teuchos::rcpFromRef (q_last);
00080       for (int k = 0; k < s; ++k, v_prv)
00081   {
00082     RCP<MV> v_cur = MVT::CloneViewNonConst (V_cur, Range1D(k,k));
00083     applyOp (v_prv, v_cur);
00084     v_prv = rcp_const_cast<const MV> (v_cur);
00085   }
00086     }
00087 
00088     void 
00089     computeFlexibleBasis (const MV& q_last, 
00090         MV& Z_cur, 
00091         MV& V_cur, 
00092         const int s)
00093     {
00094       using Teuchos::Range1D;
00095       using Teuchos::RCP;
00096       using Teuchos::rcp_const_cast;
00097       typedef MultiVecTraits<Scalar, MV> MVT;
00098 
00099       TEST_FOR_EXCEPTION(s < 0, std::invalid_argument, 
00100        "Number of basis vectors to compute (s = " 
00101        << s << ") is invalid; it must be positive.");
00102       if (s == 0)
00103   return; // Nothing to do
00104       TEST_FOR_EXCEPTION(MVT::GetNumberVecs(V_cur) < s, std::invalid_argument,
00105        "You're asking to compute s = " << s << " basis "
00106        "vectors, but only have room for " 
00107        << MVT::GetNumberVecs(V_cur) << " in V_cur.");
00108       TEST_FOR_EXCEPTION(MVT::GetNumberVecs(Z_cur) < s, std::invalid_argument,
00109        "You're asking to compute s = " << s << " basis "
00110        "vectors, but only have room for " 
00111        << MVT::GetNumberVecs(Z_cur) << " in Z_cur.");
00112       RCP<const MV> v_prv = Teuchos::rcpFromRef (q_last);
00113       for (int k = 0; k < s; ++k, v_prv)
00114   {
00115     RCP<MV> z_cur = MVT::CloneViewNonConst (Z_cur, Range1D(k,k));
00116     RCP<MV> v_cur = MVT::CloneViewNonConst (V_cur, Range1D(k,k));
00117     applyFlexibleOp (v_prv, z_cur, v_cur);
00118     v_prv = rcp_const_cast<const MV> (v_cur);
00119   }
00120     }
00121 
00122     Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,Scalar> > 
00123     changeOfBasisMatrix (const int s) 
00124     {
00125       using Teuchos::rcp;
00126       typedef Teuchos::SerialDenseMatrix<int,Scalar> mat_type;
00127       typedef Teuchos::ScalarTraits<Scalar> STS;
00128       
00129       if (B_.is_null())
00130   B_ = makeChangeOfBasisMatrix (s);
00131       else if (B_->numRows() != s+1 || B_->numCols() != s)
00132   B_ = makeChangeOfBasisMatrix (s);
00133       return B_;
00134     }
00135 
00136     void
00137     updateBasis (const Teuchos::ArrayView<const magnitude_type>& realParts,
00138      const Teuchos::ArrayView<const magnitude_type>& imagParts,
00139      const Teuchos::ArrayView<const int>& multiplicities,
00140      const int numValues)
00141     { // The monomial basis doesn't do anything with approximate
00142       // eigenvalue information.  Quiet any compiler warnings about
00143       // unused values.
00144       (void) realParts;
00145       (void) imagParts;
00146       (void) multiplicities;
00147       (void) numValues;
00148     }
00149 
00150   private:
00152     static Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,Scalar> >
00153     makeChangeOfBasisMatrix (const int s)
00154     {
00155       using Teuchos::RCP;
00156       typedef Teuchos::SerialDenseMatrix<int,Scalar> mat_type;
00157       typedef Teuchos::ScalarTraits<Scalar> STS;
00158 
00159       RCP<mat_type> B (new mat_type (s+1, s));
00160       for (int j = 0; j < s; ++j)
00161   (*B)(j+1, j) = STS::one();
00162       return B;
00163     }
00164 
00168     Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,Scalar> > B_;
00169   };
00170 
00171 
00172 } // namespace Belos
00173 
00174 #endif // __Belos_MonomialOpAkx_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines