|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "Thyra_DiagonalEpetraLinearOpWithSolveFactory.hpp" 00043 #include "Thyra_DefaultDiagonalLinearOpWithSolve.hpp" 00044 #include "Thyra_EpetraLinearOp.hpp" 00045 #include "Thyra_EpetraThyraWrappers.hpp" 00046 #include "Teuchos_dyn_cast.hpp" 00047 00048 #include "Epetra_RowMatrix.h" 00049 #include "Epetra_Vector.h" 00050 #include "Epetra_Map.h" 00051 00052 00053 namespace Thyra { 00054 00055 00056 bool DiagonalEpetraLinearOpWithSolveFactory::isCompatible( 00057 const LinearOpSourceBase<double> &fwdOpSrc 00058 ) const 00059 { 00060 using Teuchos::outArg; 00061 RCP<const LinearOpBase<double> > 00062 fwdOp = fwdOpSrc.getOp(); 00063 const EpetraLinearOpBase *eFwdOp = NULL; 00064 if( ! (eFwdOp = dynamic_cast<const EpetraLinearOpBase*>(&*fwdOp)) ) 00065 return false; 00066 RCP<const Epetra_Operator> epetraFwdOp; 00067 EOpTransp epetraFwdOpTransp; 00068 EApplyEpetraOpAs epetraFwdOpApplyAs; 00069 EAdjointEpetraOp epetraFwdOpAdjointSupport; 00070 eFwdOp->getEpetraOpView(outArg(epetraFwdOp), outArg(epetraFwdOpTransp), 00071 outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport) ); 00072 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) ) 00073 return false; 00074 return true; 00075 } 00076 00077 00078 RCP<LinearOpWithSolveBase<double> > 00079 DiagonalEpetraLinearOpWithSolveFactory::createOp() const 00080 { 00081 return Teuchos::rcp(new DefaultDiagonalLinearOpWithSolve<double>()); 00082 } 00083 00084 00085 void DiagonalEpetraLinearOpWithSolveFactory::initializeOp( 00086 const RCP<const LinearOpSourceBase<double> > &fwdOpSrc 00087 ,LinearOpWithSolveBase<double> *Op 00088 ,const ESupportSolveUse supportSolveUse 00089 ) const 00090 { 00091 using Teuchos::outArg; 00092 TEUCHOS_TEST_FOR_EXCEPT(Op==NULL); 00093 TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc.get()==NULL); 00094 TEUCHOS_TEST_FOR_EXCEPT(fwdOpSrc->getOp().get()==NULL); 00095 RCP<const LinearOpBase<double> > fwdOp = fwdOpSrc->getOp(); 00096 const EpetraLinearOpBase &eFwdOp = Teuchos::dyn_cast<const EpetraLinearOpBase>(*fwdOp); 00097 RCP<const Epetra_Operator> epetraFwdOp; 00098 EOpTransp epetraFwdOpTransp; 00099 EApplyEpetraOpAs epetraFwdOpApplyAs; 00100 EAdjointEpetraOp epetraFwdOpAdjointSupport; 00101 eFwdOp.getEpetraOpView(outArg(epetraFwdOp), outArg(epetraFwdOpTransp), 00102 outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport) ); 00103 const Epetra_RowMatrix &eRMOp = 00104 Teuchos::dyn_cast<const Epetra_RowMatrix>(*epetraFwdOp); 00105 const Epetra_Map &map = eRMOp.OperatorDomainMap(); 00106 RCP<Epetra_Vector> 00107 e_diag = Teuchos::rcp(new Epetra_Vector(map)); 00108 eRMOp.ExtractDiagonalCopy(*e_diag); 00109 RCP< const VectorSpaceBase<double> > 00110 space = create_VectorSpace(Teuchos::rcp(new Epetra_Map(map))); 00111 RCP< const VectorBase<double> > 00112 diag = create_Vector(e_diag,space); 00113 Teuchos::set_extra_data<RCP<const LinearOpSourceBase<double> > >( 00114 fwdOpSrc, "Thyra::DiagonalEpetraLinearOpWithSolveFactory::fwdOpSrc", 00115 Teuchos::inOutArg(diag) 00116 ); 00117 Teuchos::dyn_cast< DefaultDiagonalLinearOpWithSolve<double> >(*Op).initialize( 00118 Teuchos::rcp_implicit_cast<const VectorBase<double> >(diag) 00119 ); 00120 // Above cast is questionable but should be okay based on use. 00121 } 00122 00123 00124 void DiagonalEpetraLinearOpWithSolveFactory::uninitializeOp( 00125 LinearOpWithSolveBase<double> *Op 00126 ,RCP<const LinearOpSourceBase<double> > *fwdOpSrc 00127 ,RCP<const PreconditionerBase<double> > *prec 00128 ,RCP<const LinearOpSourceBase<double> > *approxFwdOpSrc 00129 ,ESupportSolveUse *supportSolveUse 00130 ) const 00131 { 00132 using Teuchos::get_extra_data; 00133 TEUCHOS_TEST_FOR_EXCEPT(Op==NULL); 00134 DefaultDiagonalLinearOpWithSolve<double> 00135 &diagOp = Teuchos::dyn_cast<DefaultDiagonalLinearOpWithSolve<double> >(*Op); 00136 RCP< const VectorBase<double> > 00137 diag = diagOp.getDiag(); 00138 if( fwdOpSrc ) { 00139 if(diag.get()) { 00140 *fwdOpSrc = 00141 get_extra_data<RCP<const LinearOpSourceBase<double> > >( 00142 diag,"Thyra::DiagonalEpetraLinearOpWithSolveFactory::fwdOpSrc" 00143 ); 00144 } 00145 } 00146 else { 00147 *fwdOpSrc = Teuchos::null; 00148 } 00149 if(prec) *prec = Teuchos::null; // We never keep a preconditioner! 00150 if(approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null; // We never keep a preconditioner! 00151 } 00152 00153 00154 // Overridden from ParameterListAcceptor 00155 00156 00157 void DiagonalEpetraLinearOpWithSolveFactory::setParameterList( 00158 RCP<Teuchos::ParameterList> const& paramList 00159 ) 00160 {} 00161 00162 00163 RCP<Teuchos::ParameterList> 00164 DiagonalEpetraLinearOpWithSolveFactory::getNonconstParameterList() 00165 { 00166 return Teuchos::null; 00167 } 00168 00169 00170 RCP<Teuchos::ParameterList> 00171 DiagonalEpetraLinearOpWithSolveFactory::unsetParameterList() 00172 { 00173 return Teuchos::null; 00174 } 00175 00176 00177 RCP<const Teuchos::ParameterList> 00178 DiagonalEpetraLinearOpWithSolveFactory::getParameterList() const 00179 { 00180 return Teuchos::null; 00181 } 00182 00183 00184 RCP<const Teuchos::ParameterList> 00185 DiagonalEpetraLinearOpWithSolveFactory::getValidParameters() const 00186 { 00187 return Teuchos::null; 00188 } 00189 00190 00191 } // namespace Thyra
1.7.6.1