Thyra Version of the Day
Thyra_LinearOpWithSolveBase_decl.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 // 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 #ifndef THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00043 #define THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
00044 
00045 #include "Thyra_OperatorSolveTypes.hpp"
00046 #include "Thyra_LinearOpBase.hpp"
00047 #include "Thyra_MultiVectorBase.hpp"
00048 #include "Thyra_VectorSpaceBase.hpp"
00049 #include "Thyra_SolveSupportTypes.hpp"
00050 #include "Teuchos_VerboseObject.hpp"
00051 
00052 
00053 namespace Thyra {
00054 
00055 
00307 template<class Scalar>
00308 class LinearOpWithSolveBase
00309   : virtual public LinearOpBase<Scalar>
00310   , virtual public Teuchos::VerboseObject<LinearOpWithSolveBase<Scalar> >
00311 {
00312 public:
00313 
00316 
00317   // 2010/08/22: rabartl: To properly handle the new SolveCriteria struct with
00318   // redution functionals (bug 4915) the function solveSupports() must be
00319   // refactored.  Here is how this refactoring can be done incrementally and
00320   // safely:
00321   //
00322   // (*) Create new override solveSupports(transp, solveCriteria) that calls
00323   // virtual solveSupportsNewImpl(transp, solveCriteria).
00324   //
00325   // (*) One by one, refactor existing LOWSB subclasses to implement
00326   // solveSupportsNewImpl(transp, solveCriteria).  This can be done by
00327   // basically copying the existing solveSupportsSolveMeasureTypeImpl()
00328   // override.  Then have each of the existing
00329   // solveSupportsSolveMeasureTypeImpl() overrides call
00330   // solveSupportsNewImpl(transp, solveCriteria) to make sure that
00331   // solveSupportsNewImpl() is getting tested right away.  Also, have the
00332   // existing solveSupportsImpl(...) overrides call
00333   // solveSupportsNewImpl(transp, null).  This will make sure that all
00334   // functionality is now going through solveSupportsNewImpl(...) and is
00335   // getting tested.
00336   //
00337   // (*) Refactor Teko software.
00338   //
00339   // (*) Once all LOWSB subclasses implement solveSupportsNewImpl(transp,
00340   // solveCriteria), finish off the refactoring in one shot:
00341   //
00342   //   (-) Remove the function solveSupports(transp), give solveCriteria a
00343   //   default null in solveSupports(transp, solveCriteria).
00344   //
00345   //   (-) Run all tests.
00346   //
00347   //   (-) Remove all of the solveSupportsImpl(transp) overrides, rename solve
00348   //   solveSupportsNewImpl() to solveSupportsImpl(), and make
00349   //   solveSupportsImpl(...) pure virtual.
00350   //
00351   //   (-) Run all tests.
00352   //
00353   //   (-) Change solveSupportsSolveMeasureType(transp, solveMeasureType) to
00354   //   call solveSupportsImpl(transp, solveCriteria) by setting
00355   //   solveMeasureType on a temp SolveCriteria object.  Also, deprecate the
00356   //   function solveSupportsSolveMeasureType(...).
00357   //
00358   //   (-) Run all tests.
00359   //
00360   //   (-) Remove all of the eixsting solveSupportsSolveMeasureTypeImpl()
00361   //   overrides.
00362   //
00363   //   (-) Run all tests.
00364   //
00365   //   (-) Clean up all deprecated working about calling
00366   //   solveSupportsSolveMeasureType() and instead have them call
00367   //   solveSupports(...) with a SolveCritera object.
00368   //
00369   // (*) Enter an item about this breaking backward compatiblilty for existing
00370   // subclasses of LOWSB.
00371   //
00372   // This refactoring will be done by and by has bug 4915 is implemented.
00373   // 
00374 
00380   bool solveSupports(EOpTransp transp) const
00381     { return solveSupportsImpl(transp); }
00382 
00387   bool solveSupports(EOpTransp transp,
00388     const Ptr<const SolveCriteria<Scalar> > solveCriteria) const
00389     { return solveSupportsNewImpl(transp, solveCriteria); }
00390 
00397   bool solveSupportsSolveMeasureType(EOpTransp transp,
00398     const SolveMeasureType& solveMeasureType
00399     ) const
00400     { return solveSupportsSolveMeasureTypeImpl(transp, solveMeasureType); }
00401 
00450   SolveStatus<Scalar> solve(
00451     const EOpTransp A_trans,
00452     const MultiVectorBase<Scalar> &B,
00453     const Ptr<MultiVectorBase<Scalar> > &X,
00454     const Ptr<const SolveCriteria<Scalar> > solveCriteria = Teuchos::null
00455     ) const 
00456     { return solveImpl(A_trans, B, X, solveCriteria); }
00457 
00459 
00462 
00464   THYRA_DEPRECATED
00465   bool solveSupportsConj(EConj conj) const;
00466 
00468   THYRA_DEPRECATED
00469   bool solveTransposeSupportsConj(EConj conj) const;
00470 
00472   THYRA_DEPRECATED
00473   void solve(
00474     const EConj conj,
00475     const MultiVectorBase<Scalar> &B,
00476     MultiVectorBase<Scalar> *X,
00477     const int numBlocks = 0,
00478     const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00479     SolveStatus<Scalar> blockSolveStatus[] = NULL
00480     ) const;
00481 
00483   THYRA_DEPRECATED
00484   bool solveSupportsSolveMeasureType(EConj conj,
00485     const SolveMeasureType& solveMeasureType) const;
00486 
00488   THYRA_DEPRECATED
00489   bool solveTransposeSupportsSolveMeasureType(EConj conj,
00490     const SolveMeasureType& solveMeasureType) const;
00491 
00493   THYRA_DEPRECATED
00494   void solveTranspose(
00495     const EConj conj,
00496     const MultiVectorBase<Scalar> &B,
00497     MultiVectorBase<Scalar> *X,
00498     const int numBlocks = 0,
00499     const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00500     SolveStatus<Scalar> blockSolveStatus[] = NULL
00501     ) const;
00502 
00504 
00505 protected:
00506 
00509 
00511   virtual bool solveSupportsImpl(EOpTransp transp) const;
00512 
00514   virtual bool solveSupportsNewImpl(EOpTransp transp,
00515     const Ptr<const SolveCriteria<Scalar> > solveCriteria
00516     ) const
00517     {
00518       TEUCHOS_TEST_FOR_EXCEPT(true);
00519       return(false);
00520     }
00521 
00523   virtual bool solveSupportsSolveMeasureTypeImpl(EOpTransp transp,
00524     const SolveMeasureType& solveMeasureType) const;
00525 
00527   virtual SolveStatus<Scalar> solveImpl(
00528     const EOpTransp transp,
00529     const MultiVectorBase<Scalar> &B,
00530     const Ptr<MultiVectorBase<Scalar> > &X,
00531     const Ptr<const SolveCriteria<Scalar> > solveCriteria
00532     ) const = 0;
00533 
00535 
00536 private:
00537 
00538   // Deprecated.  NOTE: I could not mark with THYRA_DEPRECATED because newer
00539   // versions of g++ give warnings when deprecated code calls other
00540   // depreciated code.
00541   static Ptr<const SolveCriteria<Scalar> >
00542   convertBlockSolveCriteriaToSolveCritiera(
00543     const int numBlocks,
00544     const BlockSolveCriteria<Scalar> blockSolveCriteria[]
00545     );
00546 
00547 private:
00548   
00549   // Not defined and not to be called
00550   LinearOpWithSolveBase<Scalar>&
00551   operator=(const LinearOpWithSolveBase<Scalar>&);
00552 
00553 };
00554 
00555 
00560 template<class Scalar>
00561 inline
00562 bool solveSupports(const LinearOpWithSolveBase<Scalar> &A, const EOpTransp transp)
00563 {
00564   return A.solveSupports(transp);
00565 }
00566 
00567 
00572 template<class Scalar>
00573 inline
00574 bool solveSupports(
00575   const LinearOpWithSolveBase<Scalar> &A,
00576   const EOpTransp transp,
00577   const Ptr<const SolveCriteria<Scalar> > solveCriteria
00578   )
00579 {
00580   return A.solveSupports(transp, solveCriteria);
00581 }
00582 
00583 
00588 template<class Scalar>
00589 inline
00590 SolveStatus<Scalar> solve(
00591   const LinearOpWithSolveBase<Scalar> &A,
00592   const EOpTransp A_trans,
00593   const MultiVectorBase<Scalar> &B,
00594   const Ptr<MultiVectorBase<Scalar> > &X,
00595   const Ptr<const SolveCriteria<Scalar> > solveCriteria = Teuchos::null
00596   )
00597 {
00598   return A.solve(A_trans, B, X, solveCriteria);
00599 }
00600 
00601 
00602 // Deprecated
00603 
00604 
00610 template<class Scalar>
00611 inline
00612 bool solveSupportsSolveMeasureType(
00613   const LinearOpWithSolveBase<Scalar> &A,
00614   const EOpTransp transp,
00615   const SolveMeasureType &solveMeasureType
00616   )
00617 {
00618   return A.solveSupportsSolveMeasureType(transp, solveMeasureType);
00619 }
00620 
00621 
00626 template<class Scalar>
00627 THYRA_DEPRECATED
00628 void solve(
00629   const LinearOpWithSolveBase<Scalar> &M,
00630   const EOpTransp M_trans,
00631   const MultiVectorBase<Scalar> &B,
00632   MultiVectorBase<Scalar> *X,
00633   const int numBlocks,
00634   const BlockSolveCriteria<Scalar> blockSolveCriteria[],
00635   SolveStatus<Scalar> blockSolveStatus[]
00636   )
00637 {
00638   if (real_trans(M_trans) == NOTRANS) {
00639     M.solve(transToConj(M_trans),
00640       B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00641   }
00642   else {
00643     M.solveTranspose(transToConj(M_trans),
00644       B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00645   }
00646 }
00647 
00648 
00653 template<class Scalar>
00654 THYRA_DEPRECATED
00655 SolveStatus<Scalar> solve(
00656   const LinearOpWithSolveBase<Scalar> &A,
00657   const EOpTransp A_trans,
00658   const MultiVectorBase<Scalar> &B,
00659   MultiVectorBase<Scalar> *X,
00660   const SolveCriteria<Scalar> *solveCriteria = NULL
00661   )
00662 {
00663   using Teuchos::ptr;
00664   return A.solve(A_trans, B, ptr(X), ptr(solveCriteria));
00665 }
00666 
00667 
00675 template<class Scalar>
00676 THYRA_DEPRECATED
00677 SolveStatus<Scalar>
00678 solve(
00679   const LinearOpWithSolveBase<Scalar> &A,
00680   const EConj conj,
00681   const MultiVectorBase<Scalar> &B,
00682   MultiVectorBase<Scalar> *X,
00683   const SolveCriteria<Scalar> *solveCriteria = NULL
00684   )
00685 {
00686   typedef SolveCriteria<Scalar> SC;
00687   typedef BlockSolveCriteria<Scalar> BSC;
00688   typedef SolveStatus<Scalar> BSS;
00689   SC defaultSolveCriteria;
00690   BSC blockSolveCriteria[1];
00691   BSS blockSolveStatus[1];
00692   blockSolveCriteria[0] = BSC(
00693     solveCriteria ? *solveCriteria : defaultSolveCriteria,
00694     B.domain()->dim() );
00695   A.solve(
00696     conj,B,X,1,
00697     blockSolveCriteria,
00698     blockSolveStatus
00699     );
00700   return blockSolveStatus[0];
00701 }
00702 
00703 
00711 template<class Scalar>
00712 THYRA_DEPRECATED
00713 SolveStatus<Scalar>
00714 solveTranspose(
00715   const LinearOpWithSolveBase<Scalar> &A,
00716   const EConj conj,
00717   const MultiVectorBase<Scalar> &B,
00718   MultiVectorBase<Scalar> *X,
00719   const SolveCriteria<Scalar> *solveCriteria = NULL
00720   )
00721 {
00722   typedef SolveCriteria<Scalar> SC;
00723   typedef BlockSolveCriteria<Scalar> BSC;
00724   typedef SolveStatus<Scalar> BSS;
00725   SC defaultSolveCriteria;
00726   BSC blockSolveCriteria[1];
00727   BSS blockSolveStatus[1];
00728   blockSolveCriteria[0] = BSC(
00729     solveCriteria ? *solveCriteria : defaultSolveCriteria,
00730     B.domain()->dim());
00731   A.solveTranspose(
00732     conj,B,X,1,
00733     blockSolveCriteria,
00734     blockSolveStatus
00735     );
00736   return blockSolveStatus[0];
00737 }
00738 
00739 
00747 template<class Scalar>
00748 THYRA_DEPRECATED
00749 void solve(
00750   const LinearOpWithSolveBase<Scalar> &A,
00751   const EConj conj,
00752   const MultiVectorBase<Scalar> &B,
00753   MultiVectorBase<Scalar> *X,
00754   const int numBlocks,
00755   const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00756   SolveStatus<Scalar> blockSolveStatus[] = NULL
00757   )
00758 {
00759   A.solve(conj,B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00760 }
00761 
00762 
00770 template<class Scalar>
00771 THYRA_DEPRECATED
00772 void solveTranspose(
00773   const LinearOpWithSolveBase<Scalar> &A,
00774   const EConj conj,
00775   const MultiVectorBase<Scalar> &B,
00776   MultiVectorBase<Scalar> *X,
00777   const int numBlocks,
00778   const BlockSolveCriteria<Scalar> blockSolveCriteria[] = NULL,
00779   SolveStatus<Scalar> blockSolveStatus[] = NULL
00780   )
00781 {
00782   A.solveTranspose(conj,B,X,numBlocks,blockSolveCriteria,blockSolveStatus);
00783 }
00784 
00785 
00786 } // namespace Thyra
00787 
00788 
00789 #endif // THYRA_LINEAR_OP_WITH_SOLVE_BASE_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines