Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_LinearOpWithSolveBase_decl.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 #ifndef THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00030 #define THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00031 
00032 #include "Thyra_OperatorSolveTypes.hpp"
00033 #include "Thyra_LinearOpBase.hpp"
00034 #include "Thyra_MultiVectorBase.hpp"
00035 #include "Thyra_VectorSpaceBase.hpp"
00036 #include "Thyra_SolveSupportTypes.hpp"
00037 #include "Teuchos_VerboseObject.hpp"
00038 
00039 
00040 namespace Thyra {
00041 
00042 
00294 template<class Scalar>
00295 class LinearOpWithSolveBase
00296   : virtual public LinearOpBase<Scalar>
00297   , virtual public Teuchos::VerboseObject<LinearOpWithSolveBase<Scalar> >
00298 {
00299 public:
00300 
00303 
00304   // 2010/08/22: rabartl: To properly handle the new SolveCriteria struct with
00305   // redution functionals (bug 4915) the function solveSupports() must be
00306   // refactored.  Here is how this refactoring can be done incrementally and
00307   // safely:
00308   //
00309   // (*) Create new override solveSupports(transp, solveCriteria) that calls
00310   // virtual solveSupportsNewImpl(transp, solveCriteria).
00311   //
00312   // (*) One by one, refactor existing LOWSB subclasses to implement
00313   // solveSupportsNewImpl(transp, solveCriteria).  This can be done by
00314   // basically copying the existing solveSupportsSolveMeasureTypeImpl()
00315   // override.  Then have each of the existing
00316   // solveSupportsSolveMeasureTypeImpl() overrides call
00317   // solveSupportsNewImpl(transp, solveCriteria) to make sure that
00318   // solveSupportsNewImpl() is getting tested right away.  Also, have the
00319   // existing solveSupportsImpl(...) overrides call
00320   // solveSupportsNewImpl(transp, null).  This will make sure that all
00321   // functionality is now going through solveSupportsNewImpl(...) and is
00322   // getting tested.
00323   //
00324   // (*) Refactor Teko software.
00325   //
00326   // (*) Once all LOWSB subclasses implement solveSupportsNewImpl(transp,
00327   // solveCriteria), finish off the refactoring in one shot:
00328   //
00329   //   (-) Remove the function solveSupports(transp), give solveCriteria a
00330   //   default null in solveSupports(transp, solveCriteria).
00331   //
00332   //   (-) Run all tests.
00333   //
00334   //   (-) Remove all of the solveSupportsImpl(transp) overrides, rename solve
00335   //   solveSupportsNewImpl() to solveSupportsImpl(), and make
00336   //   solveSupportsImpl(...) pure virtual.
00337   //
00338   //   (-) Run all tests.
00339   //
00340   //   (-) Change solveSupportsSolveMeasureType(transp, solveMeasureType) to
00341   //   call solveSupportsImpl(transp, solveCriteria) by setting
00342   //   solveMeasureType on a temp SolveCriteria object.  Also, deprecate the
00343   //   function solveSupportsSolveMeasureType(...).
00344   //
00345   //   (-) Run all tests.
00346   //
00347   //   (-) Remove all of the eixsting solveSupportsSolveMeasureTypeImpl()
00348   //   overrides.
00349   //
00350   //   (-) Run all tests.
00351   //
00352   //   (-) Clean up all deprecated working about calling
00353   //   solveSupportsSolveMeasureType() and instead have them call
00354   //   solveSupports(...) with a SolveCritera object.
00355   //
00356   // (*) Enter an item about this breaking backward compatiblilty for existing
00357   // subclasses of LOWSB.
00358   //
00359   // This refactoring will be done by and by has bug 4915 is implemented.
00360   // 
00361 
00367   bool solveSupports(EOpTransp transp) const
00368     { return solveSupportsImpl(transp); }
00369 
00374   bool solveSupports(EOpTransp transp,
00375     const Ptr<const SolveCriteria<Scalar> > solveCriteria) const
00376     { return solveSupportsNewImpl(transp, solveCriteria); }
00377 
00384   bool solveSupportsSolveMeasureType(EOpTransp transp,
00385     const SolveMeasureType& solveMeasureType
00386     ) const
00387     { return solveSupportsSolveMeasureTypeImpl(transp, solveMeasureType); }
00388 
00437   SolveStatus<Scalar> solve(
00438     const EOpTransp A_trans,
00439     const MultiVectorBase<Scalar> &B,
00440     const Ptr<MultiVectorBase<Scalar> > &X,
00441     const Ptr<const SolveCriteria<Scalar> > solveCriteria = Teuchos::null
00442     ) const 
00443     { return solveImpl(A_trans, B, X, solveCriteria); }
00444 
00446 
00449 
00451   THYRA_DEPRECATED
00452   bool solveSupportsConj(EConj conj) const;
00453 
00455   THYRA_DEPRECATED
00456   bool solveTransposeSupportsConj(EConj conj) const;
00457 
00459   THYRA_DEPRECATED
00460   void solve(
00461     const EConj conj,
00462     const MultiVectorBase<Scalar> &B,
00463     MultiVectorBase<Scalar> *X,
00464     const int numBlocks = 0,
00465     const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00466     SolveStatus<Scalar> blockSolveStatus[] = NULL
00467     ) const;
00468 
00470   THYRA_DEPRECATED
00471   bool solveSupportsSolveMeasureType(EConj conj,
00472     const SolveMeasureType& solveMeasureType) const;
00473 
00475   THYRA_DEPRECATED
00476   bool solveTransposeSupportsSolveMeasureType(EConj conj,
00477     const SolveMeasureType& solveMeasureType) const;
00478 
00480   THYRA_DEPRECATED
00481   void solveTranspose(
00482     const EConj conj,
00483     const MultiVectorBase<Scalar> &B,
00484     MultiVectorBase<Scalar> *X,
00485     const int numBlocks = 0,
00486     const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00487     SolveStatus<Scalar> blockSolveStatus[] = NULL
00488     ) const;
00489 
00491 
00492 protected:
00493 
00496 
00498   virtual bool solveSupportsImpl(EOpTransp transp) const;
00499 
00501   virtual bool solveSupportsNewImpl(EOpTransp transp,
00502     const Ptr<const SolveCriteria<Scalar> > solveCriteria
00503     ) const
00504     {
00505       TEST_FOR_EXCEPT(true);
00506       return(false);
00507     }
00508 
00510   virtual bool solveSupportsSolveMeasureTypeImpl(EOpTransp transp,
00511     const SolveMeasureType& solveMeasureType) const;
00512 
00514   virtual SolveStatus<Scalar> solveImpl(
00515     const EOpTransp transp,
00516     const MultiVectorBase<Scalar> &B,
00517     const Ptr<MultiVectorBase<Scalar> > &X,
00518     const Ptr<const SolveCriteria<Scalar> > solveCriteria
00519     ) const = 0;
00520 
00522 
00523 private:
00524 
00525   // Deprecated.  NOTE: I could not mark with THYRA_DEPRECATED because newer
00526   // versions of g++ give warnings when deprecated code calls other
00527   // depreciated code.
00528   static Ptr<const SolveCriteria<Scalar> >
00529   convertBlockSolveCriteriaToSolveCritiera(
00530     const int numBlocks,
00531     const BlockSolveCriteria<Scalar> blockSolveCriteria[]
00532     );
00533 
00534 private:
00535   
00536   // Not defined and not to be called
00537   LinearOpWithSolveBase<Scalar>&
00538   operator=(const LinearOpWithSolveBase<Scalar>&);
00539 
00540 };
00541 
00542 
00547 template<class Scalar>
00548 inline
00549 bool solveSupports(const LinearOpWithSolveBase<Scalar> &A, const EOpTransp transp)
00550 {
00551   return A.solveSupports(transp);
00552 }
00553 
00554 
00559 template<class Scalar>
00560 inline
00561 bool solveSupports(
00562   const LinearOpWithSolveBase<Scalar> &A,
00563   const EOpTransp transp,
00564   const Ptr<const SolveCriteria<Scalar> > solveCriteria
00565   )
00566 {
00567   return A.solveSupports(transp, solveCriteria);
00568 }
00569 
00570 
00575 template<class Scalar>
00576 inline
00577 SolveStatus<Scalar> solve(
00578   const LinearOpWithSolveBase<Scalar> &A,
00579   const EOpTransp A_trans,
00580   const MultiVectorBase<Scalar> &B,
00581   const Ptr<MultiVectorBase<Scalar> > &X,
00582   const Ptr<const SolveCriteria<Scalar> > solveCriteria = Teuchos::null
00583   )
00584 {
00585   return A.solve(A_trans, B, X, solveCriteria);
00586 }
00587 
00588 
00589 // Deprecated
00590 
00591 
00597 template<class Scalar>
00598 inline
00599 bool solveSupportsSolveMeasureType(
00600   const LinearOpWithSolveBase<Scalar> &A,
00601   const EOpTransp transp,
00602   const SolveMeasureType &solveMeasureType
00603   )
00604 {
00605   return A.solveSupportsSolveMeasureType(transp, solveMeasureType);
00606 }
00607 
00608 
00613 template<class Scalar>
00614 THYRA_DEPRECATED
00615 void solve(
00616   const LinearOpWithSolveBase<Scalar> &M,
00617   const EOpTransp M_trans,
00618   const MultiVectorBase<Scalar> &B,
00619   MultiVectorBase<Scalar> *X,
00620   const int numBlocks,
00621   const BlockSolveCriteria<Scalar> blockSolveCriteria[],
00622   SolveStatus<Scalar> blockSolveStatus[]
00623   )
00624 {
00625   if (real_trans(M_trans) == NOTRANS) {
00626     M.solve(transToConj(M_trans),
00627       B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00628   }
00629   else {
00630     M.solveTranspose(transToConj(M_trans),
00631       B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00632   }
00633 }
00634 
00635 
00640 template<class Scalar>
00641 THYRA_DEPRECATED
00642 SolveStatus<Scalar> solve(
00643   const LinearOpWithSolveBase<Scalar> &A,
00644   const EOpTransp A_trans,
00645   const MultiVectorBase<Scalar> &B,
00646   MultiVectorBase<Scalar> *X,
00647   const SolveCriteria<Scalar> *solveCriteria = NULL
00648   )
00649 {
00650   using Teuchos::ptr;
00651   return A.solve(A_trans, B, ptr(X), ptr(solveCriteria));
00652 }
00653 
00654 
00662 template<class Scalar>
00663 THYRA_DEPRECATED
00664 SolveStatus<Scalar>
00665 solve(
00666   const LinearOpWithSolveBase<Scalar> &A,
00667   const EConj conj,
00668   const MultiVectorBase<Scalar> &B,
00669   MultiVectorBase<Scalar> *X,
00670   const SolveCriteria<Scalar> *solveCriteria = NULL
00671   )
00672 {
00673   typedef SolveCriteria<Scalar> SC;
00674   typedef BlockSolveCriteria<Scalar> BSC;
00675   typedef SolveStatus<Scalar> BSS;
00676   SC defaultSolveCriteria;
00677   BSC blockSolveCriteria[1];
00678   BSS blockSolveStatus[1];
00679   blockSolveCriteria[0] = BSC(
00680     solveCriteria ? *solveCriteria : defaultSolveCriteria,
00681     B.domain()->dim() );
00682   A.solve(
00683     conj,B,X,1,
00684     blockSolveCriteria,
00685     blockSolveStatus
00686     );
00687   return blockSolveStatus[0];
00688 }
00689 
00690 
00698 template<class Scalar>
00699 THYRA_DEPRECATED
00700 SolveStatus<Scalar>
00701 solveTranspose(
00702   const LinearOpWithSolveBase<Scalar> &A,
00703   const EConj conj,
00704   const MultiVectorBase<Scalar> &B,
00705   MultiVectorBase<Scalar> *X,
00706   const SolveCriteria<Scalar> *solveCriteria = NULL
00707   )
00708 {
00709   typedef SolveCriteria<Scalar> SC;
00710   typedef BlockSolveCriteria<Scalar> BSC;
00711   typedef SolveStatus<Scalar> BSS;
00712   SC defaultSolveCriteria;
00713   BSC blockSolveCriteria[1];
00714   BSS blockSolveStatus[1];
00715   blockSolveCriteria[0] = BSC(
00716     solveCriteria ? *solveCriteria : defaultSolveCriteria,
00717     B.domain()->dim());
00718   A.solveTranspose(
00719     conj,B,X,1,
00720     blockSolveCriteria,
00721     blockSolveStatus
00722     );
00723   return blockSolveStatus[0];
00724 }
00725 
00726 
00734 template<class Scalar>
00735 THYRA_DEPRECATED
00736 void solve(
00737   const LinearOpWithSolveBase<Scalar> &A,
00738   const EConj conj,
00739   const MultiVectorBase<Scalar> &B,
00740   MultiVectorBase<Scalar> *X,
00741   const int numBlocks,
00742   const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00743   SolveStatus<Scalar> blockSolveStatus[] = NULL
00744   )
00745 {
00746   A.solve(conj,B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00747 }
00748 
00749 
00757 template<class Scalar>
00758 THYRA_DEPRECATED
00759 void solveTranspose(
00760   const LinearOpWithSolveBase<Scalar> &A,
00761   const EConj conj,
00762   const MultiVectorBase<Scalar> &B,
00763   MultiVectorBase<Scalar> *X,
00764   const int numBlocks,
00765   const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00766   SolveStatus<Scalar> blockSolveStatus[] = NULL
00767   )
00768 {
00769   A.solveTranspose(conj,B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00770 }
00771 
00772 
00773 } // namespace Thyra
00774 
00775 
00776 #endif // THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines