Thyra_DiagonalEpetraLinearOpWithSolveFactory.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
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 
00029 #ifndef __sun
00030 
00031 #include "Thyra_DiagonalEpetraLinearOpWithSolveFactory.hpp"
00032 #include "Thyra_DefaultDiagonalLinearOpWithSolve.hpp"
00033 #include "Thyra_EpetraLinearOp.hpp"
00034 #include "Thyra_EpetraThyraWrappers.hpp"
00035 #include "Teuchos_dyn_cast.hpp"
00036 
00037 #include "Epetra_RowMatrix.h"
00038 #include "Epetra_Vector.h"
00039 #include "Epetra_Map.h"
00040 
00041 namespace Thyra {
00042 
00043 bool DiagonalEpetraLinearOpWithSolveFactory::isCompatible(
00044   const LinearOpSourceBase<double> &fwdOpSrc
00045   ) const
00046 {
00047   Teuchos::RefCountPtr<const LinearOpBase<double> >
00048     fwdOp = fwdOpSrc.getOp();
00049   const EpetraLinearOpBase *eFwdOp = NULL;
00050   if( ! (eFwdOp = dynamic_cast<const EpetraLinearOpBase*>(&*fwdOp)) )
00051     return false;
00052   Teuchos::RefCountPtr<const Epetra_Operator> epetraFwdOp;
00053   ETransp                                     epetraFwdOpTransp;
00054   EApplyEpetraOpAs                            epetraFwdOpApplyAs;
00055   EAdjointEpetraOp                            epetraFwdOpAdjointSupport;
00056   eFwdOp->getEpetraOpView(
00057     &epetraFwdOp,&epetraFwdOpTransp,&epetraFwdOpApplyAs,&epetraFwdOpAdjointSupport
00058     );
00059   if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
00060     return false;
00061   return true;
00062 }
00063 
00064 Teuchos::RefCountPtr<LinearOpWithSolveBase<double> >
00065 DiagonalEpetraLinearOpWithSolveFactory::createOp() const
00066 {
00067   return Teuchos::rcp(new DefaultDiagonalLinearOpWithSolve<double>());
00068 }
00069 
00070 void DiagonalEpetraLinearOpWithSolveFactory::initializeOp(
00071   const Teuchos::RefCountPtr<const LinearOpSourceBase<double> >    &fwdOpSrc
00072   ,LinearOpWithSolveBase<double>                                   *Op
00073   ,const ESupportSolveUse                                          supportSolveUse
00074   ) const
00075 {
00076   TEST_FOR_EXCEPT(Op==NULL);
00077   TEST_FOR_EXCEPT(fwdOpSrc.get()==NULL);
00078   TEST_FOR_EXCEPT(fwdOpSrc->getOp().get()==NULL);
00079   Teuchos::RefCountPtr<const LinearOpBase<double> > fwdOp = fwdOpSrc->getOp();
00080   const EpetraLinearOpBase &eFwdOp = Teuchos::dyn_cast<const EpetraLinearOpBase>(*fwdOp);
00081   Teuchos::RefCountPtr<const Epetra_Operator> epetraFwdOp;
00082   ETransp                                     epetraFwdOpTransp;
00083   EApplyEpetraOpAs                            epetraFwdOpApplyAs;
00084   EAdjointEpetraOp                            epetraFwdOpAdjointSupport;
00085   eFwdOp.getEpetraOpView(
00086     &epetraFwdOp,&epetraFwdOpTransp,&epetraFwdOpApplyAs,&epetraFwdOpAdjointSupport
00087     );
00088   const Epetra_RowMatrix &eRMOp  = Teuchos::dyn_cast<const Epetra_RowMatrix>(*epetraFwdOp);
00089   const Epetra_Map &map = eRMOp.OperatorDomainMap();
00090   Teuchos::RefCountPtr<Epetra_Vector>
00091     e_diag = Teuchos::rcp(new Epetra_Vector(map));
00092   eRMOp.ExtractDiagonalCopy(*e_diag);
00093   Teuchos::RefCountPtr< const SpmdVectorSpaceBase<double> >
00094     space = create_VectorSpace(Teuchos::rcp(new Epetra_Map(map)));
00095   Teuchos::RefCountPtr< const SpmdVectorBase<double> >
00096     diag = create_Vector(e_diag,space);
00097   Teuchos::set_extra_data<Teuchos::RefCountPtr<const LinearOpSourceBase<double> > >(
00098     fwdOpSrc, "Thyra::DiagonalEpetraLinearOpWithSolveFactory::fwdOpSrc", &diag
00099     );
00100   Teuchos::dyn_cast< DefaultDiagonalLinearOpWithSolve<double> >(*Op).initialize(
00101     Teuchos::rcp_implicit_cast<const VectorBase<double> >(diag)
00102     );
00103   // Above cast is questionable but should be okay based on use.
00104 }
00105 
00106 void DiagonalEpetraLinearOpWithSolveFactory::uninitializeOp(
00107   LinearOpWithSolveBase<double>                               *Op
00108   ,Teuchos::RefCountPtr<const LinearOpSourceBase<double> >    *fwdOpSrc
00109   ,Teuchos::RefCountPtr<const PreconditionerBase<double> >    *prec
00110   ,Teuchos::RefCountPtr<const LinearOpSourceBase<double> >    *approxFwdOpSrc
00111   ,ESupportSolveUse                                           *supportSolveUse
00112   ) const
00113 {
00114   using Teuchos::get_extra_data;
00115   TEST_FOR_EXCEPT(Op==NULL);
00116   DefaultDiagonalLinearOpWithSolve<double>
00117     &diagOp = Teuchos::dyn_cast<DefaultDiagonalLinearOpWithSolve<double> >(*Op);
00118   Teuchos::RefCountPtr< const VectorBase<double> >
00119     diag = diagOp.getDiag();
00120   if( fwdOpSrc ) {
00121     if(diag.get()) {
00122       *fwdOpSrc =
00123         get_extra_data<Teuchos::RefCountPtr<const LinearOpSourceBase<double> > >(
00124           diag,"Thyra::DiagonalEpetraLinearOpWithSolveFactory::fwdOpSrc"
00125           );
00126     }
00127   }
00128   else {
00129     *fwdOpSrc = Teuchos::null;
00130   }
00131   if(prec) *prec = Teuchos::null; // We never keep a preconditioner!
00132   if(approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null; // We never keep a preconditioner!
00133 }
00134 
00135 // Overridden from ParameterListAcceptor
00136 
00137 void DiagonalEpetraLinearOpWithSolveFactory::setParameterList(
00138   Teuchos::RefCountPtr<Teuchos::ParameterList> const& paramList
00139   )
00140 {}
00141 
00142 Teuchos::RefCountPtr<Teuchos::ParameterList>
00143 DiagonalEpetraLinearOpWithSolveFactory::getParameterList()
00144 {
00145   return Teuchos::null;
00146 }
00147 
00148 Teuchos::RefCountPtr<Teuchos::ParameterList>
00149 DiagonalEpetraLinearOpWithSolveFactory::unsetParameterList()
00150 {
00151   return Teuchos::null;
00152 }
00153 
00154 Teuchos::RefCountPtr<const Teuchos::ParameterList>
00155 DiagonalEpetraLinearOpWithSolveFactory::getParameterList() const
00156 {
00157   return Teuchos::null;
00158 }
00159 
00160 Teuchos::RefCountPtr<const Teuchos::ParameterList>
00161 DiagonalEpetraLinearOpWithSolveFactory::getValidParameters() const
00162 {
00163   return Teuchos::null;
00164 }
00165 
00166 } // namespace Thyra
00167 
00168 #endif // __sun
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 

Generated on Thu Sep 18 12:37:48 2008 for Epetra to Thyra Adapter Software by doxygen 1.3.9.1