Anasazi  Version of the Day
AnasaziTraceMin.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Anasazi: Block Eigensolvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 //
42 // Anasazi: Block Eigensolvers Package
43 //
44 
49 #ifndef ANASAZI_TRACEMIN_HPP
50 #define ANASAZI_TRACEMIN_HPP
51 
52 #include "AnasaziTypes.hpp"
53 #include "AnasaziBasicSort.hpp"
54 #include "AnasaziTraceMinBase.hpp"
55 
56 #include "Epetra_Operator.h"
57 
58 #include "AnasaziEigensolver.hpp"
61 #include "Teuchos_ScalarTraits.hpp"
62 
64 #include "AnasaziSolverUtils.hpp"
65 
66 #include "Teuchos_LAPACK.hpp"
67 #include "Teuchos_BLAS.hpp"
68 #include "Teuchos_SerialDenseMatrix.hpp"
69 #include "Teuchos_SerialDenseSolver.hpp"
70 #include "Teuchos_ParameterList.hpp"
71 #include "Teuchos_TimeMonitor.hpp"
72 
73 // TODO: TraceMin performs some unnecessary computations upon restarting. Fix it!
74 
75 namespace Anasazi {
76 namespace Experimental {
128  template <class ScalarType, class MV, class OP>
129  class TraceMin : public TraceMinBase<ScalarType,MV,OP> {
130  public:
132 
133 
174  TraceMin( const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
175  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
176  const Teuchos::RCP<OutputManager<ScalarType> > &printer,
177  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &tester,
178  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
179  Teuchos::ParameterList &params
180  );
181 
182  private:
183  //
184  // Convenience typedefs
185  //
189  typedef Teuchos::ScalarTraits<ScalarType> SCT;
190  typedef typename SCT::magnitudeType MagnitudeType;
191  const MagnitudeType ONE;
192  const MagnitudeType ZERO;
193  const MagnitudeType NANVAL;
194 
195  // TraceMin specific methods
196  void addToBasis(const Teuchos::RCP<const MV> Delta);
197 
198  void harmonicAddToBasis(const Teuchos::RCP<const MV> Delta);
199  };
200 
203  //
204  // Implementations
205  //
208 
209 
211  // Constructor
212  template <class ScalarType, class MV, class OP>
214  const Teuchos::RCP<Eigenproblem<ScalarType,MV,OP> > &problem,
215  const Teuchos::RCP<SortManager<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> > &sorter,
216  const Teuchos::RCP<OutputManager<ScalarType> > &printer,
217  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &tester,
218  const Teuchos::RCP<MatOrthoManager<ScalarType,MV,OP> > &ortho,
219  Teuchos::ParameterList &params
220  ) :
221  TraceMinBase<ScalarType,MV,OP>(problem,sorter,printer,tester,ortho,params),
222  ONE(Teuchos::ScalarTraits<MagnitudeType>::one()),
223  ZERO(Teuchos::ScalarTraits<MagnitudeType>::zero()),
224  NANVAL(Teuchos::ScalarTraits<MagnitudeType>::nan())
225  {
226  }
227 
228 
229  template <class ScalarType, class MV, class OP>
230  void TraceMin<ScalarType,MV,OP>::addToBasis(const Teuchos::RCP<const MV> Delta)
231  {
232  MVT::MvAddMv(ONE,*this->X_,-ONE,*Delta,*this->V_);
233 
234  if(this->hasM_)
235  {
236 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
237  Teuchos::TimeMonitor lcltimer( *this->timerMOp_ );
238 #endif
239  this->count_ApplyM_+= this->blockSize_;
240 
241  OPT::Apply(*this->MOp_,*this->V_,*this->MV_);
242  }
243 
244  int rank;
245  {
246 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
247  Teuchos::TimeMonitor lcltimer( *this->timerOrtho_ );
248 #endif
249 
250  if(this->numAuxVecs_ > 0)
251  {
252  rank = this->orthman_->projectAndNormalizeMat(*this->V_,this->auxVecs_,
253  Teuchos::tuple(Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > >(Teuchos::null)),
254  Teuchos::null,this->MV_,this->MauxVecs_);
255  }
256  else
257  {
258  rank = this->orthman_->normalizeMat(*this->V_,Teuchos::null,this->MV_);
259  }
260  }
261 
262  // FIXME (mfh 07 Oct 2014) This variable is currently unused, but
263  // it would make sense to use it to check whether the block is
264  // rank deficient.
265  (void) rank;
266 
267  if(this->Op_ != Teuchos::null)
268  {
269 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
270  Teuchos::TimeMonitor lcltimer( *this->timerOp_ );
271 #endif
272  this->count_ApplyOp_+= this->blockSize_;
273  OPT::Apply(*this->Op_,*this->V_,*this->KV_);
274  }
275  }
276 
277 
278 
279  template <class ScalarType, class MV, class OP>
280  void TraceMin<ScalarType,MV,OP>::harmonicAddToBasis(const Teuchos::RCP<const MV> Delta)
281  {
282  // V = X - Delta
283  MVT::MvAddMv(ONE,*this->X_,-ONE,*Delta,*this->V_);
284 
285  // Project out auxVecs
286  if(this->numAuxVecs_ > 0)
287  {
288 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
289  Teuchos::TimeMonitor lcltimer( *this->timerOrtho_ );
290 #endif
291  this->orthman_->projectMat(*this->V_,this->auxVecs_);
292  }
293 
294  // Compute KV
295  if(this->Op_ != Teuchos::null)
296  {
297 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
298  Teuchos::TimeMonitor lcltimer( *this->timerOp_ );
299 #endif
300  this->count_ApplyOp_+= this->blockSize_;
301 
302  OPT::Apply(*this->Op_,*this->V_,*this->KV_);
303  }
304 
305  // Normalize lclKV
306  RCP< Teuchos::SerialDenseMatrix<int,ScalarType> > gamma = rcp(new Teuchos::SerialDenseMatrix<int,ScalarType>(this->blockSize_,this->blockSize_));
307  int rank = this->orthman_->normalizeMat(*this->KV_,gamma);
308  // FIXME (mfh 18 Feb 2015) It would make sense to check the rank.
309  (void) rank;
310 
311  // lclV = lclV/gamma
312  Teuchos::SerialDenseSolver<int,ScalarType> SDsolver;
313  SDsolver.setMatrix(gamma);
314  SDsolver.invert();
315  RCP<MV> tempMV = MVT::CloneCopy(*this->V_);
316  MVT::MvTimesMatAddMv(ONE,*tempMV,*gamma,ZERO,*this->V_);
317 
318  // Compute MV
319  if(this->hasM_)
320  {
321 #ifdef ANASAZI_TEUCHOS_TIME_MONITOR
322  Teuchos::TimeMonitor lcltimer( *this->timerMOp_ );
323 #endif
324  this->count_ApplyM_+= this->blockSize_;
325 
326  OPT::Apply(*this->MOp_,*this->V_,*this->MV_);
327  }
328  }
329 
330 }} // End of namespace Anasazi
331 
332 #endif
333 
334 // End of file AnasaziTraceMin.hpp
static void MvTimesMatAddMv(const ScalarType alpha, const MV &A, const Teuchos::SerialDenseMatrix< int, ScalarType > &B, const ScalarType beta, MV &mv)
Update mv with .
Abstract base class for trace minimization eigensolvers.
This class implements a TraceMIN iteration, a preconditioned iteration for solving linear symmetric p...
Templated virtual class for providing orthogonalization/orthonormalization methods with matrix-based ...
This class defines the interface required by an eigensolver and status test class to compute solution...
Declaration of basic traits for the multivector type.
Virtual base class which defines basic traits for the operator type.
TraceMin(const Teuchos::RCP< Eigenproblem< ScalarType, MV, OP > > &problem, const Teuchos::RCP< SortManager< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > > &sorter, const Teuchos::RCP< OutputManager< ScalarType > > &printer, const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &tester, const Teuchos::RCP< MatOrthoManager< ScalarType, MV, OP > > &ortho, Teuchos::ParameterList &params)
TraceMin constructor with eigenproblem, solver utilities, and parameter list of solver options...
static void Apply(const OP &Op, const MV &x, MV &y)
Application method which performs operation y = Op*x. An OperatorError exception is thrown if there i...
Basic implementation of the Anasazi::SortManager class.
Pure virtual base class which describes the basic interface to the iterative eigensolver.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
Anasazi&#39;s templated, static class providing utilities for the solvers.
Anasazi&#39;s templated virtual class for providing routines for orthogonalization and orthonormalization...
Output managers remove the need for the eigensolver to know any information about the required output...
Traits class which defines basic operations on multivectors.
static Teuchos::RCP< MV > CloneCopy(const MV &mv)
Creates a new MV and copies contents of mv into the new vector (deep copy).
Virtual base class which defines basic traits for the operator type.
static void MvAddMv(const ScalarType alpha, const MV &A, const ScalarType beta, const MV &B, MV &mv)
Replace mv with .
Types and exceptions used within Anasazi solvers and interfaces.
This is an abstract base class for the trace minimization eigensolvers.
Anasazi&#39;s templated pure virtual class for managing the sorting of approximate eigenvalues computed b...
Common interface of stopping criteria for Anasazi&#39;s solvers.
Class which provides internal utilities for the Anasazi solvers.