EpetraExt Development
EpetraExt_ProductOperator.h
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2011) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 #ifndef EPETRAEXT_PRODUCT_OPERATOR_H
00043 #define EPETRAEXT_PRODUCT_OPERATOR_H
00044 
00045 #include "Epetra_Operator.h"
00046 #include "Teuchos_RefCountPtr.hpp"
00047 #include "Teuchos_BLAS_types.hpp"
00048 
00049 class Epetra_Vector;
00050 
00051 namespace EpetraExt {
00052 
00132 class ProductOperator : public Epetra_Operator {
00133 public:
00134 
00137 
00139   enum EApplyMode { APPLY_MODE_APPLY, APPLY_MODE_APPLY_INVERSE };
00140 
00142 
00145 
00147   ProductOperator();
00148 
00150   ProductOperator(
00151     const int                                            num_Op
00152     ,const Teuchos::RefCountPtr<const Epetra_Operator>   Op[]
00153     ,const Teuchos::ETransp                              Op_trans[]
00154     ,const EApplyMode                                    Op_inverse[]
00155     );
00156 
00220   void initialize(
00221     const int                                            num_Op
00222     ,const Teuchos::RefCountPtr<const Epetra_Operator>   Op[]
00223     ,const Teuchos::ETransp                              Op_trans[]
00224     ,const EApplyMode                                    Op_inverse[]
00225     );
00226 
00233   void uninitialize(
00234     int                                            *num_Op
00235     ,Teuchos::RefCountPtr<const Epetra_Operator>   Op[]
00236     ,Teuchos::ETransp                              Op_trans[]
00237     ,EApplyMode                                    p_inverse[]
00238     );
00239 
00257   void applyConstituent(
00258     const int                  k
00259     ,Teuchos::ETransp          Op_trans
00260     ,EApplyMode                Op_inverse
00261     ,const Epetra_MultiVector  &X_k
00262     ,Epetra_MultiVector        *Y_k
00263     ) const;
00264 
00270   int num_Op() const;
00271 
00283   Teuchos::RefCountPtr<const Epetra_Operator> Op(int k) const;
00284 
00291   Teuchos::ETransp Op_trans(int k) const;
00292 
00299   EApplyMode Op_inverse(int k) const;
00300 
00302 
00305   
00307   int SetUseTranspose(bool UseTranspose);
00309   int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00311   int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00313   double NormInf() const;
00315   const char * Label() const;
00317   bool UseTranspose() const;
00319   bool HasNormInf() const;
00321   const Epetra_Comm & Comm() const;
00323   const Epetra_Map & OperatorDomainMap() const;
00325   const Epetra_Map & OperatorRangeMap() const;
00326 
00328 
00329 private:
00330 
00331   // ////////////////////////////
00332   // Private types
00333 
00334   typedef std::vector<Teuchos::RefCountPtr<const Epetra_Operator> >  Op_t;
00335   typedef std::vector<Teuchos::ETransp>                        Op_trans_t;
00336   typedef std::vector<EApplyMode>                              Op_inverse_t;
00337   typedef std::vector<Teuchos::RefCountPtr<Epetra_Vector> >    EV_t;
00338 
00339   // ////////////////////////////
00340   // Private data members
00341 
00342   bool          UseTranspose_;
00343   Op_t          Op_;
00344   Op_trans_t    Op_trans_;
00345   Op_inverse_t  Op_inverse_;
00346 
00347   mutable EV_t  range_vecs_;
00348   mutable EV_t  domain_vecs_;
00349 
00350   // ////////////////////////////
00351   // Private member functions
00352 
00353   void assertInitialized() const;
00354   void validateIndex(int k) const;
00355   void initializeTempVecs(bool applyInverse) const;
00356 
00357 }; // class ProductOperator
00358 
00359 // ////////////////////////////
00360 // Inline members
00361 
00362 // public
00363 
00364 inline
00365 int ProductOperator::num_Op() const
00366 {
00367   return Op_.size();
00368 }
00369 
00370 inline
00371 Teuchos::RefCountPtr<const Epetra_Operator>
00372 ProductOperator::Op(int k) const
00373 {
00374   validateIndex(k);
00375   return Op_[k];
00376 }
00377 
00378 inline
00379 Teuchos::ETransp
00380 ProductOperator::Op_trans(int k) const
00381 {
00382   validateIndex(k);
00383   return Op_trans_[k];
00384 }
00385 
00386 inline
00387 ProductOperator::EApplyMode
00388 ProductOperator::Op_inverse(int k) const
00389 {
00390   validateIndex(k);
00391   return Op_inverse_[k];
00392 }
00393 
00394 
00395 // private
00396 
00397 inline
00398 void ProductOperator::assertInitialized() const
00399 {
00400   TEUCHOS_TEST_FOR_EXCEPTION(
00401     Op_.size()==0, std::logic_error
00402     ,"Epetra::ProductOperator: Error, Client has not called initialize(...) yet!"
00403     );
00404 }
00405 
00406 inline
00407 void ProductOperator::validateIndex(int k) const
00408 {
00409   TEUCHOS_TEST_FOR_EXCEPTION(
00410     k < 0 || static_cast<int>(Op_.size())-1 < k, std::logic_error
00411     ,"Epetra::ProductOperator: Error, k = "<<k<< " is not in the range [0,"<<Op_.size()-1<<"]!"
00412     );
00413 }
00414 
00415 } // namespace EpetraExt
00416 
00417 #endif // EPETRAEXT_PRODUCT_OPERATOR_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines