BelosEpetraOperator.cpp

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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 // @HEADER
00028 
00034 #include "BelosEpetraOperator.h"
00035 
00036 using namespace Belos;
00037 
00038 //--------------------------------------------------------------
00039 //
00040 // implementation of the EpetraOperator class.
00041 //
00042 // Constructor.
00043 //
00044 EpetraOperator::EpetraOperator( const RCP<LinearProblem<double,Epetra_MultiVector,Epetra_Operator> >& lp,
00045         const RCP<Teuchos::ParameterList>& plist,
00046                                 bool initSolnVec )
00047   : lp_(lp), 
00048     plist_(plist),
00049     initSolnVec_(initSolnVec)
00050 {
00051   std::string solver = plist_->get("Solver", "BlockGmres");
00052   
00053   // Copy std::string to character array.  
00054   // Not using conversion routine copy() because it's not supported by RW on Janus. (HKT 11/13/2003) 
00055   Solver.resize(solver.length()+1);
00056   for (int i=0; i<(int)solver.length()+1; i++) {
00057     Solver[i] = solver[i];
00058   } 
00059   Solver[solver.length()] = 0;
00060 
00061   //
00062   // Create solver and solve problem.  This is inefficient, an instance of the solver should
00063   // exist already and just be reset with a new RHS.
00064   //
00065   if (solver == "BlockGmres") {
00066     solver_ = Teuchos::rcp( new BlockGmresSolMgr<double,Epetra_MultiVector,Epetra_Operator>( lp_, plist_ ) );
00067   } 
00068   else if (solver == "PseudoBlockGmres") {
00069     solver_ = Teuchos::rcp( new PseudoBlockGmresSolMgr<double,Epetra_MultiVector,Epetra_Operator>( lp_, plist_ ) );
00070   }
00071   else if (solver == "BlockCG") {
00072     solver_ = Teuchos::rcp( new BlockCGSolMgr<double,Epetra_MultiVector,Epetra_Operator>( lp_, plist) );
00073   }
00074 }
00075 
00076 const Epetra_Comm& EpetraOperator::Comm() const 
00077 { 
00078   return (lp_->getOperator()->Comm());
00079 }
00080   
00081 const Epetra_Map& EpetraOperator::OperatorDomainMap() const 
00082 { 
00083   return (lp_->getOperator()->OperatorDomainMap());
00084 }
00085 
00086 const Epetra_Map& EpetraOperator::OperatorRangeMap() const 
00087 { 
00088   return (lp_->getOperator()->OperatorRangeMap());
00089 }
00090 
00091 int EpetraOperator::Apply( const Epetra_MultiVector &X, Epetra_MultiVector &Y ) const
00092 {
00093   RCP<const Epetra_MultiVector> vec_X;
00094   RCP<Epetra_MultiVector> vec_Y;
00095   vec_X = rcp( &X, false );
00096   vec_Y = rcp( &Y, false );
00097   if (initSolnVec_)
00098     vec_Y->PutScalar( 0.0 );
00099   lp_->setProblem( vec_Y, vec_X );
00100   Belos::ReturnType ret = solver_->solve();
00101   
00102   if (ret != Converged) 
00103     return(-1);
00104 
00105   return(0);
00106 }
00107 
00108 int EpetraOperator::ApplyInverse( const Epetra_MultiVector &X, Epetra_MultiVector &Y ) const
00109 {
00110   RCP<const Epetra_MultiVector> vec_X;
00111   RCP<Epetra_MultiVector> vec_Y;
00112   vec_X = rcp( &X, false );
00113   vec_Y = rcp( &Y, false );
00114   if (initSolnVec_)
00115     vec_Y->PutScalar( 0.0 );
00116   lp_->setProblem( vec_Y, vec_X );
00117   Belos::ReturnType ret = solver_->solve();
00118   
00119   if (ret != Converged) 
00120     return(-1);
00121 
00122   return(0);
00123 }
00124 
00125 

Generated on Tue Oct 20 12:48:34 2009 for Belos by doxygen 1.4.7