|
Anasazi
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Anasazi: Block Eigensolvers Package 00005 // Copyright (2004) 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00033 #ifndef ANASAZI_TRACEMIN_DAVIDSON_HPP 00034 #define ANASAZI_TRACEMIN_DAVIDSON_HPP 00035 00036 #include "AnasaziConfigDefs.hpp" 00037 #include "AnasaziEigensolver.hpp" 00038 #include "AnasaziMultiVecTraits.hpp" 00039 #include "AnasaziMatOrthoManager.hpp" 00040 #include "AnasaziOperatorTraits.hpp" 00041 #include "AnasaziTraceMinBase.hpp" 00042 00043 #include "Teuchos_ScalarTraits.hpp" 00044 #include "Teuchos_SerialDenseMatrix.hpp" 00045 #include "Teuchos_ParameterList.hpp" 00046 #include "Teuchos_TimeMonitor.hpp" 00047 00048 00049 namespace Anasazi { 00050 namespace Experimental { 00051 00066 template <class ScalarType, class MV, class OP> 00067 class TraceMinDavidson : public TraceMinBase<ScalarType,MV,OP> { 00068 public: 00069 00078 TraceMinDavidson( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, 00079 const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter, 00080 const Teuchos::RCP<OutputManager<ScalarType> > &printer, 00081 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &tester, 00082 const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho, 00083 Teuchos::ParameterList ¶ms 00084 ); 00085 00086 private: 00087 // 00088 // Convenience typedefs 00089 // 00090 typedef MultiVecTraits<ScalarType,MV> MVT; 00091 typedef OperatorTraits<ScalarType,MV,OP> OPT; 00092 typedef Teuchos::ScalarTraits<ScalarType> SCT; 00093 typedef typename SCT::magnitudeType MagnitudeType; 00094 00095 // TraceMin specific methods 00096 void addToBasis(const Teuchos::RCP<const MV> Delta); 00097 }; 00098 00101 // 00102 // Implementations 00103 // 00106 00107 00108 00110 // Constructor 00111 template <class ScalarType, class MV, class OP> 00112 TraceMinDavidson<ScalarType,MV,OP>::TraceMinDavidson( 00113 const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem, 00114 const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter, 00115 const Teuchos::RCP<OutputManager<ScalarType> > &printer, 00116 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &tester, 00117 const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho, 00118 Teuchos::ParameterList ¶ms 00119 ) : 00120 TraceMinBase<ScalarType,MV,OP>(problem,sorter,printer,tester,ortho,params) 00121 { 00122 } 00123 00124 00126 // 1. Project Delta so that V' M Delta = 0 and Q' M Delta = 0 00127 // 2. Normalize Delta so that Delta' M Delta = I 00128 // 3. Add Delta to the end of V: V = [V Delta] 00129 // 4. Update KV and MV 00130 template <class ScalarType, class MV, class OP> 00131 void TraceMinDavidson<ScalarType,MV,OP>::addToBasis(Teuchos::RCP<const MV> Delta) 00132 { 00133 // TODO: We should also test the row length and map, etc... 00134 TEUCHOS_TEST_FOR_EXCEPTION(MVT::GetNumberVecs(*Delta) != this->blockSize_, std::invalid_argument, 00135 "Anasazi::TraceMinDavidson::addToBasis(): Delta does not have blockSize_ columns"); 00136 00137 int rank; 00138 // Vector of indices 00139 std::vector<int> curind(this->curDim_), newind(this->blockSize_); 00140 // Pointer to the meaningful parts of V, KV, and MV 00141 Teuchos::RCP<MV> lclV, lclKV, lclMV; 00142 // Holds the vectors we project against 00143 Teuchos::Array< Teuchos::RCP<const MV> > projVecs = this->auxVecs_; 00144 00145 // Get the existing parts of the basis and add them to the list of things we project against 00146 for(int i=0; i<this->curDim_; i++) 00147 curind[i] = i; 00148 lclV = MVT::CloneViewNonConst(*this->V_,curind); 00149 projVecs.push_back(lclV); 00150 00151 // Get the new part of the basis (where we're going to insert Delta) 00152 for (int i=0; i<this->blockSize_; ++i) 00153 newind[i] = this->curDim_ + i; 00154 lclV = MVT::CloneViewNonConst(*this->V_,newind); 00155 00156 // Insert Delta at the end of V 00157 MVT::SetBlock(*Delta,newind,*this->V_); 00158 this->curDim_ += this->blockSize_; 00159 00160 // Project out the components of Delta in the direction of V 00161 if(this->hasM_) 00162 { 00163 // It is more efficient to provide the orthomanager with MV 00164 Teuchos::Array< Teuchos::RCP<const MV> > MprojVecs = this->MauxVecs_; 00165 lclMV = MVT::CloneViewNonConst(*this->MV_,curind); 00166 MprojVecs.push_back(lclMV); 00167 00168 // Compute M*Delta 00169 lclMV = MVT::CloneViewNonConst(*this->MV_,newind); 00170 { 00171 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 00172 Teuchos::TimeMonitor lcltimer( *this->timerMOp_ ); 00173 #endif 00174 this->count_ApplyM_+= this->blockSize_; 00175 OPT::Apply(*this->MOp_,*lclV,*lclMV); 00176 } 00177 00178 { 00179 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 00180 Teuchos::TimeMonitor lcltimer( *this->timerOrtho_ ); 00181 #endif 00182 00183 // Project and normalize Delta 00184 rank = this->orthman_->projectAndNormalizeMat(*lclV,projVecs, 00185 Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)), 00186 Teuchos::null,lclMV,MprojVecs); 00187 } 00188 00189 MprojVecs.pop_back(); 00190 } 00191 else 00192 { 00193 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 00194 Teuchos::TimeMonitor lcltimer( *this->timerOrtho_ ); 00195 #endif 00196 00197 // Project and normalize Delta 00198 rank = this->orthman_->projectAndNormalizeMat(*lclV,projVecs); 00199 } 00200 00201 projVecs.pop_back(); 00202 00203 TEUCHOS_TEST_FOR_EXCEPTION(rank != this->blockSize_,TraceMinBaseOrthoFailure, 00204 "Anasazi::TraceMinDavidson::addToBasis(): Couldn't generate basis of full rank."); 00205 00206 // Update KV 00207 if(this->Op_ != Teuchos::null) 00208 { 00209 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR 00210 Teuchos::TimeMonitor lcltimer( *this->timerOp_ ); 00211 #endif 00212 this->count_ApplyOp_+= this->blockSize_; 00213 00214 lclKV = MVT::CloneViewNonConst(*this->KV_,newind); 00215 OPT::Apply(*this->Op_,*lclV,*lclKV); 00216 } 00217 } 00218 00219 }} // End of namespace Anasazi 00220 00221 #endif 00222 00223 // End of file AnasaziTraceMinDavidson.hpp
1.7.6.1