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 RefCountPtr<LinearProblem<double,Epetra_MultiVector,Epetra_Operator> >& lp,
00045         const RefCountPtr<StatusTest<double,Epetra_MultiVector,Epetra_Operator> >& stest,
00046         const RefCountPtr<OutputManager<double> >& om,
00047         const RefCountPtr<Teuchos::ParameterList>& plist )
00048   : lp_(lp), 
00049     stest_(stest), 
00050     om_(om), 
00051     plist_(plist), 
00052     Maxits(plist->get("Max Iters", 25))
00053 {
00054   string solver = plist_->get("Solver", "BlockGMRES");
00055   
00056   // Copy string to character array.  
00057   // Not using conversion routine copy() because it's not supported by RW on Janus. (HKT 11/13/2003) 
00058   Solver.resize(solver.length()+1);
00059   for (int i=0; i<(int)solver.length()+1; i++) {
00060     Solver[i] = solver[i];
00061   } 
00062   Solver[solver.length()] = 0;
00063 
00064   //
00065   // Create solver and solve problem.  This is inefficient, an instance of the solver should
00066   // exist already and just be reset with a new RHS.
00067   //
00068   if (strcmp(&Solver[0],"BlockGMRES")==0) {
00069     solver_ = Teuchos::rcp( new BlockGmres<double,Epetra_MultiVector,Epetra_Operator>( lp_, stest_, om_, plist_ ) );
00070   }
00071   if (strcmp(&Solver[0],"BlockCG")==0) {
00072     solver_ = Teuchos::rcp( new BlockCG<double,Epetra_MultiVector,Epetra_Operator>( lp_, stest_, om_) );
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   RefCountPtr<const Epetra_MultiVector> vec_X;
00094   RefCountPtr<Epetra_MultiVector> vec_Y;
00095   vec_X = rcp( &X, false );
00096   vec_Y = rcp( &Y, false );
00097   solver_->Reset();
00098   lp_->Reset( vec_Y, vec_X );
00099   stest_->Reset();
00100   solver_->Solve();
00101   
00102   // Assume a good return right now since Belos doesn't have return types yet.
00103   return(0);
00104 }
00105 
00106 int EpetraOperator::ApplyInverse( const Epetra_MultiVector &X, Epetra_MultiVector &Y ) const
00107 {
00108   RefCountPtr<const Epetra_MultiVector> vec_X;
00109   RefCountPtr<Epetra_MultiVector> vec_Y;
00110   vec_X = rcp( &X, false );
00111   vec_Y = rcp( &Y, false );
00112   solver_->Reset();
00113   lp_->Reset( vec_Y, vec_X );
00114   stest_->Reset();
00115   solver_->Solve();
00116   
00117   // Assume a good return right now since Belos doesn't have return types yet.
00118   return(0);
00119 }
00120 
00121 

Generated on Thu Sep 18 12:30:12 2008 for Belos by doxygen 1.3.9.1