EpetraExt Package Browser (Single Doxygen Collection) Development
EpetraExt_PointToBlockDiagPermute.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_POINTTOBLOCKDIAGPERMUTE_H
00043 #define EPETRAEXT_POINTTOBLOCKDIAGPERMUTE_H
00044 
00045 #include "Epetra_ConfigDefs.h"
00046 #include "Epetra_DistObject.h"
00047 #include "Epetra_BlockMap.h"
00048 #include "Epetra_BlockMap.h"
00049 #include "Epetra_Map.h"
00050 #include "Epetra_Operator.h"
00051 #include "Epetra_CrsMatrix.h"
00052 #include "Epetra_FECrsMatrix.h"
00053 #include "Teuchos_ParameterList.hpp"
00054 
00055 class Epetra_Comm;
00056 class Epetra_Import;
00057 class Epetra_Export;
00058 class EpetraExt_BlockDiagMatrix;
00059 
00061 
00069 // NTS: Map() == RowMap is the convention
00070 
00071 //=========================================================================
00072 class EpetraExt_PointToBlockDiagPermute : public virtual Epetra_Operator, public Epetra_DistObject {
00073 public:
00074 
00076 
00077 
00078   EpetraExt_PointToBlockDiagPermute(const Epetra_CrsMatrix& MAT);
00080 
00082 
00083 
00084   virtual ~EpetraExt_PointToBlockDiagPermute();
00086 
00087 
00089 
00090 
00092   virtual int SetParameters(Teuchos::ParameterList & List);
00093 
00100   virtual int SetUseTranspose (bool useTranspose) {return -1;}
00101 
00103   virtual int Compute();
00104 
00106 
00108 
00109 
00111 
00119   virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00120 
00122 
00133   virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
00134 
00136   virtual double NormInf() const {return -1;}
00138 
00140 
00141 
00143   virtual const char * Label() const{return "Fix Me";}
00144 
00146   virtual bool UseTranspose() const {return false;}
00147 
00149   virtual bool HasNormInf() const {return false;}
00150 
00152   virtual const Epetra_Comm & Comm() const {return Map().Comm();}
00153 
00155   virtual const Epetra_Map & OperatorDomainMap() const {return Matrix_->OperatorDomainMap();}
00156 
00158   virtual const Epetra_Map & OperatorRangeMap() const {return Matrix_->OperatorRangeMap();}
00159 
00161   virtual const EpetraExt_BlockDiagMatrix & BlockMatrix(){return *BDMat_;}
00162 
00166   virtual Epetra_FECrsMatrix * CreateFECrsMatrix();
00167 
00169 
00170 
00172   virtual void Print(std::ostream& os) const;
00173 
00175 
00176 
00177 
00179 
00191   int Import(const Epetra_SrcDistObject& A, const Epetra_Import& Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
00192 
00194 
00206   int Import(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
00207 
00209 
00221   int Export(const Epetra_SrcDistObject& A, const Epetra_Import & Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
00222 
00224 
00236   int Export(const Epetra_SrcDistObject& A, const Epetra_Export& Exporter, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex * Indexor = 0);
00238 
00239  protected:
00240 
00241 
00243 
00244 
00245   virtual int CheckSizes(const Epetra_SrcDistObject& Source);
00247   virtual int CopyAndPermute(const Epetra_SrcDistObject& Source,
00248                              int NumSameIDs,
00249                              int NumPermuteIDs,
00250                              int * PermuteToLIDs,
00251                              int * PermuteFromLIDs,
00252                              const Epetra_OffsetIndex * Indexor,
00253                              Epetra_CombineMode CombineMode = Zero);
00254 
00256   virtual int PackAndPrepare(const Epetra_SrcDistObject& Source,
00257                              int NumExportIDs,
00258                              int* ExportLIDs,
00259                              int& LenExports,
00260                              char*& Exports,
00261                              int& SizeOfPacket,
00262                              int* Sizes,
00263                              bool & VarSizes,
00264                              Epetra_Distributor& Distor);
00265 
00267   virtual int UnpackAndCombine(const Epetra_SrcDistObject& Source,
00268                                int NumImportIDs,
00269                                int* ImportLIDs,
00270                                int LenImports,
00271                                char* Imports,
00272                                int& SizeOfPacket,
00273                                Epetra_Distributor& Distor,
00274                                Epetra_CombineMode CombineMode,
00275                                const Epetra_OffsetIndex * Indexor);
00276 
00278 
00279 private:
00281   int ExtractBlockDiagonal();
00282 
00284   int SetupContiguousMode();
00285   int CleanupContiguousMode();
00286 
00287   // Copied from Epetra_CrsMatrix
00288   void UpdateImportVector(int NumVectors) const;
00289   void UpdateExportVector(int NumVectors) const;
00290 
00291   Teuchos::ParameterList List_;
00292   const Epetra_CrsMatrix* Matrix_;
00293   bool PurelyLocalMode_;
00294 
00295   // For contiguous blocking only
00296   bool ContiguousBlockMode_;
00297   int ContiguousBlockSize_;
00298 
00299   int NumBlocks_;
00300   int *Blockstart_;
00301   int *Blockids_int_;
00302 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00303   long long *Blockids_LL_;
00304 #endif
00305   Epetra_BlockMap *BDMap_;
00306   Epetra_Map *CompatibleMap_; //A map compatible with BD's block map - used for imports
00307   EpetraExt_BlockDiagMatrix* BDMat_;
00308   Epetra_Import *Importer_;
00309   Epetra_Export *Exporter_;
00310   mutable Epetra_MultiVector *ImportVector_;
00311   mutable Epetra_MultiVector *ExportVector_;
00312 
00313   template<typename int_type>
00314   Epetra_FECrsMatrix * TCreateFECrsMatrix();
00315 
00316   template<typename int_type>
00317   int TSetupContiguousMode();
00318 
00319   template<typename int_type>
00320   int TExtractBlockDiagonal();
00321 
00322   template<typename int_type>
00323   int TSetParameters(Teuchos::ParameterList & List);
00324 
00325   template<typename int_type>
00326   const int_type* Blockids_const_ptr() const;
00327 
00328   template<typename int_type>
00329   int_type*& Blockids_ref();
00330 
00331 };  /* EPETRAEXT_POINTTOBLOCKDIAGPERMUTE_H */
00332 
00333 template<> inline const int* EpetraExt_PointToBlockDiagPermute::Blockids_const_ptr<int>() const { return Blockids_int_; }
00334 
00335 template<> inline int*& EpetraExt_PointToBlockDiagPermute::Blockids_ref<int>() { return Blockids_int_; }
00336 
00337 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00338 template<> inline const long long* EpetraExt_PointToBlockDiagPermute::Blockids_const_ptr<long long>() const { return Blockids_LL_; }
00339 template<> inline long long*& EpetraExt_PointToBlockDiagPermute::Blockids_ref<long long>() { return Blockids_LL_; }
00340 #endif
00341 
00342 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines