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