Thyra_LinearOpWithSolveBaseDecl.hpp

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 THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00030 #define THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00031 
00032 #include "Thyra_LinearOpBaseDecl.hpp"
00033 #include "Thyra_SolveSupportTypes.hpp"
00034 #include "Teuchos_VerboseObject.hpp"
00035 
00036 namespace Thyra {
00037 
00337 template <class RangeScalar, class DomainScalar = RangeScalar>
00338 class LinearOpWithSolveBase
00339   : virtual public LinearOpBase<RangeScalar,DomainScalar>
00340   , virtual public Teuchos::VerboseObject<LinearOpWithSolveBase<RangeScalar,DomainScalar> >
00341 {
00342 public:
00343 
00345   typedef typename Teuchos::PromotionTraits<RangeScalar,DomainScalar>::promote PromotedScalar;
00346   
00349 
00405   virtual void solve(
00406     const EConj                                   conj
00407     ,const MultiVectorBase<RangeScalar>           &B
00408     ,MultiVectorBase<DomainScalar>                *X
00409     ,const int                                    numBlocks             = 0
00410     ,const BlockSolveCriteria<PromotedScalar>     blockSolveCriteria[]  = NULL
00411     ,SolveStatus<PromotedScalar>                  blockSolveStatus[]    = NULL
00412     ) const = 0;
00413 
00415 
00418 
00424   virtual bool solveSupportsConj(EConj conj) const;
00425 
00430   virtual bool solveTransposeSupportsConj(EConj conj) const;
00431 
00438   virtual bool solveSupportsSolveMeasureType(EConj conj, const SolveMeasureType& solveMeasureType) const;
00439 
00446   virtual bool solveTransposeSupportsSolveMeasureType(EConj conj, const SolveMeasureType& solveMeasureType) const;
00447 
00504   virtual void solveTranspose(
00505     const EConj                                   conj
00506     ,const MultiVectorBase<DomainScalar>          &B
00507     ,MultiVectorBase<RangeScalar>                 *X
00508     ,const int                                    numBlocks             = 0
00509     ,const BlockSolveCriteria<PromotedScalar>     blockSolveCriteria[]  = NULL
00510     ,SolveStatus<PromotedScalar>                  blockSolveStatus[]    = NULL
00511     ) const;
00512 
00514 
00515 };
00516 
00517 
00523 template<class Scalar>
00524 bool solveSupports(
00525   const LinearOpWithSolveBase<Scalar>   &A
00526   ,const ETransp                        A_trans
00527   )
00528 {
00529   if( real_trans(A_trans) == NOTRANS ) {
00530     return A.solveSupportsConj(
00531       A_trans == NOTRANS ? NONCONJ_ELE : CONJ_ELE
00532       );
00533   }
00534   return A.solveTransposeSupportsConj(
00535     A_trans == TRANS ? NONCONJ_ELE : CONJ_ELE
00536     );
00537 }
00538 
00539 
00545 template<class Scalar>
00546 bool solveSupportsSolveMeasureType(
00547   const LinearOpWithSolveBase<Scalar> &A,
00548   const ETransp A_trans,
00549   const SolveMeasureType &solveMeasureType
00550   )
00551 {
00552   if( real_trans(A_trans) == NOTRANS ) {
00553     return A.solveSupportsSolveMeasureType(
00554       A_trans == NOTRANS ? NONCONJ_ELE : CONJ_ELE,
00555       solveMeasureType
00556       );
00557   }
00558   return A.solveTransposeSupportsSolveMeasureType(
00559     A_trans == TRANS ? NONCONJ_ELE : CONJ_ELE,
00560       solveMeasureType
00561     );
00562 }
00563 
00564 
00570 template<class Scalar>
00571 void solve(
00572   const LinearOpWithSolveBase<Scalar> &M,
00573   const ETransp M_trans,
00574   const MultiVectorBase<Scalar> &B,
00575   MultiVectorBase<Scalar> *X,
00576   const int numBlocks,
00577   const BlockSolveCriteria<Scalar> blockSolveCriteria[],
00578   SolveStatus<Scalar> blockSolveStatus[]
00579   )
00580 {
00581   if (real_trans(M_trans) == NOTRANS)
00582     M.solve(
00583       transToConj(M_trans),B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00584   else
00585     M.solveTranspose(
00586       transToConj(M_trans),B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00587 }
00588 
00589 
00602 template<class Scalar>
00603 SolveStatus<Scalar>
00604 solve(
00605   const LinearOpWithSolveBase<Scalar>   &A
00606   ,const ETransp                        A_trans
00607   ,const MultiVectorBase<Scalar>        &B
00608   ,MultiVectorBase<Scalar>              *X
00609   ,const SolveCriteria<Scalar>          *solveCriteria = NULL
00610   )
00611 {
00612   if(real_trans(A_trans)==NOTRANS)
00613     return solve(A,transToConj(A_trans),B,X,solveCriteria);
00614   return solveTranspose(A,transToConj(A_trans),B,X,solveCriteria);
00615 }
00616 
00624 template<class RangeScalar, class DomainScalar>
00625 SolveStatus<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00626 solve(
00627   const LinearOpWithSolveBase<RangeScalar,DomainScalar>   &A
00628   ,const EConj                                            conj
00629   ,const MultiVectorBase<RangeScalar>                     &B
00630   ,MultiVectorBase<DomainScalar>                          *X
00631   ,const SolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00632                                                           *solveCriteria  = NULL
00633   )
00634 {
00635   typedef SolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>       SC;
00636   typedef BlockSolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>  BSC;
00637   typedef SolveStatus<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>         BSS;
00638   SC  defaultSolveCriteria;
00639   BSC blockSolveCriteria[1];
00640   BSS blockSolveStatus[1];
00641   blockSolveCriteria[0] = BSC(solveCriteria?*solveCriteria:defaultSolveCriteria,B.domain()->dim());
00642   A.solve(
00643     conj,B,X,1
00644     ,blockSolveCriteria
00645     ,blockSolveStatus
00646     );
00647   return blockSolveStatus[0];
00648 }
00649 
00650 
00658 template <class RangeScalar, class DomainScalar>
00659 SolveStatus<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00660 solveTranspose(
00661   const LinearOpWithSolveBase<RangeScalar,DomainScalar>   &A
00662   ,const EConj                                            conj
00663   ,const MultiVectorBase<DomainScalar>                    &B
00664   ,MultiVectorBase<RangeScalar>                           *X
00665   ,const SolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00666                                                           *solveCriteria  = NULL
00667   )
00668 {
00669   typedef SolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>       SC;
00670   typedef BlockSolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>  BSC;
00671   typedef SolveStatus<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>         BSS;
00672   SC  defaultSolveCriteria;
00673   BSC blockSolveCriteria[1];
00674   BSS blockSolveStatus[1];
00675   blockSolveCriteria[0] = BSC(solveCriteria?*solveCriteria:defaultSolveCriteria,B.domain()->dim());
00676   A.solveTranspose(
00677     conj,B,X,1
00678     ,blockSolveCriteria
00679     ,blockSolveStatus
00680     );
00681   return blockSolveStatus[0];
00682 }
00683 
00684 
00692 template<class RangeScalar, class DomainScalar>
00693 void solve(
00694   const LinearOpWithSolveBase<RangeScalar,DomainScalar>   &A
00695   ,const EConj                                            conj
00696   ,const MultiVectorBase<RangeScalar>                     &B
00697   ,MultiVectorBase<DomainScalar>                          *X
00698   ,const int                                              numBlocks
00699   ,const BlockSolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00700                                                           blockSolveCriteria[] = NULL
00701   ,SolveStatus<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00702                                                           blockSolveStatus[] = NULL
00703   )
00704 {
00705   A.solve(conj,B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00706 }
00707 
00708 
00716 template <class RangeScalar, class DomainScalar>
00717 void solveTranspose(
00718   const LinearOpWithSolveBase<RangeScalar,DomainScalar>   &A
00719   ,const EConj                                            conj
00720   ,const MultiVectorBase<DomainScalar>                    &B
00721   ,MultiVectorBase<RangeScalar>                           *X
00722   ,const int                                              numBlocks
00723   ,const BlockSolveCriteria<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00724                                                           blockSolveCriteria[] = NULL
00725   ,SolveStatus<typename LinearOpWithSolveBase<RangeScalar,DomainScalar>::PromotedScalar>
00726                                                           blockSolveStatus[] = NULL
00727   )
00728 {
00729   A.solveTranspose(conj,B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00730 }
00731 
00733 
00734 } // namespace Thyra
00735 
00736 #endif // THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00737 
00738 
00739 
00740 
00741 

Generated on Tue Oct 20 12:46:48 2009 for Thyra ANA Operator Solve Interfaces by doxygen 1.4.7