Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DefaultSerialDenseLinearOpWithSolve_def.hpp
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 
00030 #ifndef THYRA_DEFAULT_SERIAL_DENSE_LINEAR_OP_WITH_SOLVE_HPP
00031 #define THYRA_DEFAULT_SERIAL_DENSE_LINEAR_OP_WITH_SOLVE_HPP
00032 
00033 
00034 #include "Thyra_DefaultSerialDenseLinearOpWithSolve_decl.hpp"
00035 #include "Thyra_LinearOpWithSolveBase.hpp"
00036 #include "Thyra_DetachedMultiVectorView.hpp"
00037 #include "Thyra_MultiVectorStdOps.hpp"
00038 #include "Thyra_AssertOp.hpp"
00039 #include "Teuchos_Assert.hpp"
00040 
00041 
00042 namespace Thyra {
00043 
00044   
00045 // Constructors/initializers/accessors
00046 
00047 
00048 template<class Scalar>
00049 DefaultSerialDenseLinearOpWithSolve<Scalar>::DefaultSerialDenseLinearOpWithSolve()
00050 {}
00051 
00052 
00053 template<class Scalar>
00054 void DefaultSerialDenseLinearOpWithSolve<Scalar>::initialize(
00055   const RCP<const MultiVectorBase<Scalar> > &M )
00056 {
00057   using Teuchos::outArg;
00058 #ifdef TEUCHOS_DEBUG
00059   TEUCHOS_ASSERT(!is_null(M));
00060   TEUCHOS_ASSERT(isFullyInitialized(*M));
00061   TEUCHOS_ASSERT(M->range()->hasInCoreView());
00062   TEUCHOS_ASSERT(M->domain()->hasInCoreView());
00063   THYRA_ASSERT_VEC_SPACES("", *M->range(), *M->domain());
00064 #endif
00065   factorize(*M, outArg(LU_), outArg(ipiv_));
00066   M_ = M;
00067 }
00068 
00069 template<class Scalar>
00070 RCP<const LinearOpBase<Scalar> > DefaultSerialDenseLinearOpWithSolve<Scalar>::getFwdOp() const
00071 {
00072   return M_;
00073 }
00074 
00075 // Overridden from LinearOpBase
00076 
00077 
00078 template<class Scalar>
00079 RCP<const VectorSpaceBase<Scalar> >
00080 DefaultSerialDenseLinearOpWithSolve<Scalar>::range() const
00081 {
00082   if (!is_null(M_))
00083     return M_->range();
00084   return Teuchos::null;
00085 }
00086 
00087 
00088 template<class Scalar>
00089 RCP<const VectorSpaceBase<Scalar> >
00090 DefaultSerialDenseLinearOpWithSolve<Scalar>::domain() const
00091 {
00092   if (!is_null(M_))
00093     return M_->domain();
00094   return Teuchos::null;
00095 }
00096 
00097 
00098 // protected
00099 
00100 
00101 // Overridden from LinearOpBase
00102 
00103 
00104 template<class Scalar>
00105 bool DefaultSerialDenseLinearOpWithSolve<Scalar>::opSupportedImpl(
00106   EOpTransp M_trans) const
00107 {
00108   return Thyra::opSupported(*M_, M_trans);
00109 }
00110 
00111 
00112 template<class Scalar>
00113 void DefaultSerialDenseLinearOpWithSolve<Scalar>::applyImpl(
00114   const EOpTransp M_trans,
00115   const MultiVectorBase<Scalar> &X,
00116   const Ptr<MultiVectorBase<Scalar> > &Y,
00117   const Scalar alpha,
00118   const Scalar beta
00119   ) const
00120 {
00121   Thyra::apply( *M_, M_trans, X, Y, alpha, beta );
00122 }
00123 
00124 
00125 // Overridden from LinearOpWithSolveBase
00126 
00127 
00128 template<class Scalar>
00129 bool DefaultSerialDenseLinearOpWithSolve<Scalar>::solveSupportsImpl(
00130   EOpTransp M_trans) const
00131 {
00132   typedef Teuchos::ScalarTraits<Scalar> ST;
00133   return ( ST::isComplex ? ( M_trans!=CONJ ) : true );
00134 }
00135 
00136 
00137 template<class Scalar>
00138 bool DefaultSerialDenseLinearOpWithSolve<Scalar>::solveSupportsSolveMeasureTypeImpl(
00139   EOpTransp M_trans, const SolveMeasureType& solveMeasureType) const
00140 {
00141   // We support all solve measures since we are a direct solver
00142   return this->solveSupportsImpl(M_trans);
00143 }
00144 
00145 
00146 template<class Scalar>
00147 SolveStatus<Scalar>
00148 DefaultSerialDenseLinearOpWithSolve<Scalar>::solveImpl(
00149   const EOpTransp M_trans,
00150   const MultiVectorBase<Scalar> &B,
00151   const Ptr<MultiVectorBase<Scalar> > &X,
00152   const Ptr<const SolveCriteria<Scalar> > solveCriteria
00153   ) const
00154 {
00155 #ifdef TEUCHOS_DEBUG
00156   THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(
00157     "DefaultSerialDenseLinearOpWithSolve<Scalar>::solve(...)",
00158     *this, M_trans, *X, &B );
00159 #endif
00160   backsolve( LU_, ipiv_, M_trans, B, X );
00161   SolveStatus<Scalar> solveStatus;
00162   solveStatus.solveStatus = SOLVE_STATUS_CONVERGED;\
00163   return solveStatus;
00164 }
00165 
00166 
00167 // private
00168 
00169 
00170 template<class Scalar>
00171 void DefaultSerialDenseLinearOpWithSolve<Scalar>::factorize(
00172   const MultiVectorBase<Scalar> &M,
00173   const Ptr<RTOpPack::ConstSubMultiVectorView<Scalar> > &LU,
00174   const Ptr<Array<int> > &ipiv
00175   )
00176 {
00177   using Teuchos::outArg;
00178   const ConstDetachedMultiVectorView<Scalar> dM(M);
00179   const int dim = dM.subDim();
00180   ipiv->resize(dim);
00181   RTOpPack::SubMultiVectorView<Scalar> LU_tmp(dim, dim);
00182   RTOpPack::assign_entries<Scalar>( outArg(LU_tmp), dM.smv() );
00183   int rank = -1;
00184   RTOpPack::getrf<Scalar>( LU_tmp, (*ipiv)(), outArg(rank) );
00185   TEUCHOS_ASSERT_EQUALITY( dim, rank );
00186   *LU = LU_tmp; // Weak copy
00187 }
00188 
00189 
00190 template<class Scalar>
00191 void DefaultSerialDenseLinearOpWithSolve<Scalar>::backsolve(
00192   const RTOpPack::ConstSubMultiVectorView<Scalar> &LU,
00193   const ArrayView<const int> ipiv,
00194   const EOpTransp transp,
00195   const MultiVectorBase<Scalar> &B,
00196   const Ptr<MultiVectorBase<Scalar> > &X
00197   )
00198 {
00199   using Teuchos::outArg;
00200   assign( X, B );
00201   DetachedMultiVectorView<Scalar> dX(*X);
00202   RTOpPack::getrs<Scalar>( LU, ipiv, convertToRTOpPackETransp(transp),
00203     outArg(dX.smv()) );
00204 }
00205 
00206 
00207 } // end namespace Thyra
00208 
00209 
00210 #endif  // THYRA_DEFAULT_SERIAL_DENSE_LINEAR_OP_WITH_SOLVE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines