Thyra Version of the Day
Thyra_DefaultInverseLinearOp_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_DEFAULT_INVERSE_LINEAR_OP_DECL_HPP
00043 #define THYRA_DEFAULT_INVERSE_LINEAR_OP_DECL_HPP
00044 
00045 #include "Thyra_InverseLinearOpBase.hpp"
00046 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00047 
00048 
00049 namespace Thyra {
00050 
00051 
00053 enum EThrowOnSolveFailure {
00054   THROW_ON_SOLVE_FAILURE=1 
00055   ,IGNORE_SOLVE_FAILURE=0  
00056 };
00057 
00058 
00082 template<class Scalar>
00083 class DefaultInverseLinearOp : virtual public InverseLinearOpBase<Scalar>
00084 {
00085 public:
00086 
00089 
00093   DefaultInverseLinearOp();
00094 
00097   DefaultInverseLinearOp(
00098     const RCP<LinearOpWithSolveBase<Scalar> > &lows,
00099     const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00100     const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00101     const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00102     const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00103     );
00104 
00110   DefaultInverseLinearOp(
00111     const RCP<const LinearOpWithSolveBase<Scalar> > &lows,
00112     const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00113     const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00114     const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00115     const EThrowOnSolveFailure throwOnAdjSolveFailure  = THROW_ON_SOLVE_FAILURE
00116     );
00117 
00152   void initialize(
00153     const RCP<LinearOpWithSolveBase<Scalar> > &lows,
00154     const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00155     const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00156     const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00157     const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00158     );
00159 
00194   void initialize(
00195     const RCP<const LinearOpWithSolveBase<Scalar> > &lows,
00196     const SolveCriteria<Scalar> *fwdSolveCriteria = NULL,
00197     const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00198     const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00199     const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00200     );
00201 
00210   void uninitialize();
00211 
00213 
00216 
00218   bool isLowsConst() const;
00220   RCP<LinearOpWithSolveBase<Scalar> >
00221   getNonconstLows(); 
00223   RCP<const LinearOpWithSolveBase<Scalar> >
00224   getLows() const; 
00225 
00227 
00230 
00235   RCP< const VectorSpaceBase<Scalar> > range() const;
00236 
00241   RCP< const VectorSpaceBase<Scalar> > domain() const;
00242 
00244   RCP<const LinearOpBase<Scalar> > clone() const;
00245 
00247 
00250                                                 
00252   std::string description() const;
00253 
00255   void describe(
00256     FancyOStream &out,
00257     const Teuchos::EVerbosityLevel verbLevel
00258     ) const;
00259 
00261 
00262 protected:
00263 
00266 
00270   bool opSupportedImpl(EOpTransp M_trans) const;
00271 
00273   void applyImpl(
00274     const EOpTransp M_trans,
00275     const MultiVectorBase<Scalar> &X,
00276     const Ptr<MultiVectorBase<Scalar> > &Y,
00277     const Scalar alpha,
00278     const Scalar beta
00279     ) const;
00280 
00282 
00283 private:
00284 
00285   Teuchos::ConstNonconstObjectContainer<LinearOpWithSolveBase<Scalar> > lows_;
00286   RCP<SolveCriteria<Scalar> > fwdSolveCriteria_;
00287   EThrowOnSolveFailure throwOnFwdSolveFailure_;
00288   RCP<SolveCriteria<Scalar> > adjSolveCriteria_;
00289   EThrowOnSolveFailure throwOnAdjSolveFailure_;
00290   
00291   void assertInitialized() const;
00292 
00293   template<class LOWS>
00294   void initializeImpl(
00295     const RCP<LOWS> &lows,
00296     const SolveCriteria<Scalar> *fwdSolveCriteria,
00297     const EThrowOnSolveFailure throwOnFwdSolveFailure,
00298     const SolveCriteria<Scalar> *adjSolveCriteria,
00299     const EThrowOnSolveFailure throwOnAdjSolveFailure
00300     );
00301 
00302   // Not defined and not to be called
00303   DefaultInverseLinearOp(const DefaultInverseLinearOp&);
00304   DefaultInverseLinearOp& operator=(const DefaultInverseLinearOp&);
00305 
00306 };
00307 
00308 
00313 template<class Scalar>
00314 RCP<LinearOpBase<Scalar> >
00315 nonconstInverse(
00316   const RCP<LinearOpWithSolveBase<Scalar> > &A,
00317   const Ptr<const SolveCriteria<Scalar> > &fwdSolveCriteria = Teuchos::null,
00318   const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00319   const Ptr<const SolveCriteria<Scalar> > &adjSolveCriteria = Teuchos::null,
00320   const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00321   );
00322 
00323 
00328 template<class Scalar>
00329 RCP<LinearOpBase<Scalar> >
00330 inverse(
00331   const RCP<const LinearOpWithSolveBase<Scalar> > &A,
00332   const Ptr<const SolveCriteria<Scalar> > &fwdSolveCriteria = Teuchos::null,
00333   const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00334   const Ptr<const SolveCriteria<Scalar> > &adjSolveCriteria = Teuchos::null,
00335   const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00336   );
00337 
00338 
00339 // /////////////////////////////////
00340 // Inline members
00341 
00342 
00343 template<class Scalar>
00344 inline
00345 void DefaultInverseLinearOp<Scalar>::assertInitialized() const
00346 {
00347 #ifdef TEUCHOS_DEBUG
00348   TEUCHOS_TEST_FOR_EXCEPT( !lows_.getConstObj().get() );
00349 #endif
00350 }
00351 
00352 
00353 //
00354 // Deprecated
00355 //
00356 
00357 
00362 template<class Scalar>
00363 THYRA_DEPRECATED RCP<LinearOpBase<Scalar> >
00364 nonconstInverse(
00365   const RCP<LinearOpWithSolveBase<Scalar> > &A,
00366   const SolveCriteria<Scalar> *fwdSolveCriteria,
00367   const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00368   const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00369   const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00370   )
00371 {
00372   using Teuchos::ptr;
00373   return nonconstInverse<Scalar>(A, ptr(fwdSolveCriteria), throwOnFwdSolveFailure,
00374     ptr(adjSolveCriteria), throwOnAdjSolveFailure);
00375 }
00376 
00377 
00382 template<class Scalar>
00383 THYRA_DEPRECATED RCP<LinearOpBase<Scalar> >
00384 inverse(
00385   const RCP<const LinearOpWithSolveBase<Scalar> > &A,
00386   const SolveCriteria<Scalar> *fwdSolveCriteria,
00387   const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
00388   const SolveCriteria<Scalar> *adjSolveCriteria = NULL,
00389   const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
00390   )
00391 {
00392   using Teuchos::ptr;
00393   return inverse<Scalar>(A, ptr(fwdSolveCriteria), throwOnFwdSolveFailure,
00394     ptr(adjSolveCriteria), throwOnAdjSolveFailure);
00395 }
00396 
00397 
00398 } // end namespace Thyra
00399 
00400 
00401 #endif  // THYRA_DEFAULT_INVERSE_LINEAR_OP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines