Epetra Package Browser (Single Doxygen Collection) Development
Epetra_MultiVector.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_MULTIVECTOR_H
00045 #define EPETRA_MULTIVECTOR_H
00046 
00047 class Epetra_Comm;
00048 class Epetra_BlockMap;
00049 class Epetra_Map;
00050 class Epetra_Import;
00051 class Epetra_Export;
00052 class Epetra_Distributor;
00053 class Epetra_Vector;
00054 
00055 #include "Epetra_ConfigDefs.h"
00056 #include "Epetra_DistObject.h"
00057 #include "Epetra_CompObject.h"
00058 #include "Epetra_BLAS.h"
00059 #include "Epetra_Util.h"
00060 
00062 
00183 //==========================================================================
00184 class EPETRA_LIB_DLL_EXPORT Epetra_MultiVector: public Epetra_DistObject, public Epetra_CompObject, public Epetra_BLAS {
00185 
00186  public:
00187 
00189 
00190 
00191 
00208   Epetra_MultiVector(const Epetra_BlockMap& Map, int NumVectors, bool zeroOut = true);
00209 
00211   
00212   Epetra_MultiVector(const Epetra_MultiVector& Source);
00213   
00215 
00234   Epetra_MultiVector(Epetra_DataAccess CV, const Epetra_BlockMap& Map, 
00235          double *A, int MyLDA, int NumVectors);
00236 
00238 
00253   Epetra_MultiVector(Epetra_DataAccess CV, const Epetra_BlockMap& Map, 
00254          double **ArrayOfPointers, int NumVectors);
00255 
00257 
00271   Epetra_MultiVector(Epetra_DataAccess CV,  
00272          const Epetra_MultiVector& Source, int *Indices, int NumVectors);
00273 
00275 
00289   Epetra_MultiVector(Epetra_DataAccess CV, 
00290          const Epetra_MultiVector& Source, int StartIndex, 
00291          int NumVectors);
00292   
00294   virtual ~Epetra_MultiVector();
00296 
00298 
00299 
00301 
00320   int ReplaceGlobalValue(int GlobalRow, int VectorIndex, double ScalarValue);
00321 
00322 
00324 
00342   int ReplaceGlobalValue(int GlobalBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00343 
00344 
00346 
00365   int SumIntoGlobalValue(int GlobalRow, int VectorIndex, double ScalarValue);
00366 
00367 
00369 
00387   int SumIntoGlobalValue(int GlobalBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00388 
00390 
00414   int ReplaceMyValue(int MyRow, int VectorIndex, double ScalarValue);
00415 
00416 
00418 
00436   int ReplaceMyValue(int MyBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00437 
00438 
00440 
00459   int SumIntoMyValue(int MyRow, int VectorIndex, double ScalarValue);
00460 
00461 
00463 
00481   int SumIntoMyValue(int MyBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00482 
00484 
00490   int PutScalar (double ScalarConstant);
00491   
00493 
00499   int Random();
00500 
00502 
00504 
00505 
00507 
00521   int ExtractCopy(double *A, int MyLDA) const;
00522 
00524 
00534   int ExtractCopy(double **ArrayOfPointers) const;
00535 
00536   // ExtractView functions
00537 
00538   
00540 
00554   int ExtractView(double **A, int *MyLDA) const;
00555 
00557 
00567   int ExtractView(double ***ArrayOfPointers) const;
00568 
00570 
00572 
00573 
00575 
00583   int Dot(const Epetra_MultiVector& A, double *Result) const;
00584 
00586 
00596   int Abs(const Epetra_MultiVector& A);
00597 
00599 
00614   int Reciprocal(const Epetra_MultiVector& A);
00615 
00617 
00625   int Scale(double ScalarValue);
00626 
00628 
00638   int Scale(double ScalarA, const Epetra_MultiVector& A);
00639 
00641 
00653   int Update(double ScalarA, const Epetra_MultiVector& A, double ScalarThis);
00654 
00656 
00672   int Update(double ScalarA, const Epetra_MultiVector& A, 
00673        double ScalarB, const Epetra_MultiVector& B, double ScalarThis);
00674 
00676 
00683   int Norm1   (double * Result) const;
00684 
00686 
00693   int Norm2   (double * Result) const;
00694 
00696 
00702   int NormInf (double * Result) const;
00703 
00705 
00720   int NormWeighted   (const Epetra_MultiVector& Weights, double * Result) const;
00721 
00723 
00732   int MinValue  (double * Result) const;
00733 
00735 
00744   int MaxValue  (double * Result) const;
00745 
00747 
00754   int MeanValue (double * Result) const;
00755   
00756   
00758 
00810   int Multiply(char TransA, char TransB, double ScalarAB, 
00811          const Epetra_MultiVector& A, const Epetra_MultiVector& B,
00812          double ScalarThis );
00813   
00814 
00815 
00817 
00823   int Multiply(double ScalarAB, const Epetra_MultiVector& A, const Epetra_MultiVector& B,
00824          double ScalarThis );
00825 
00826 
00828 
00834   int ReciprocalMultiply(double ScalarAB, const Epetra_MultiVector& A, const Epetra_MultiVector& B,
00835        double ScalarThis );
00836 
00838 
00840 
00841 
00842 
00844 
00850   int SetSeed(unsigned int Seed_in){return(Util_.SetSeed(Seed_in));};
00851 
00853 
00856   unsigned int Seed(){return(Util_.Seed());};
00857 
00859 
00861 
00862 
00864 
00870   Epetra_MultiVector& operator = (const Epetra_MultiVector& Source);
00871   
00872   // Local element access functions
00873 
00874   // 
00875 
00877 
00880   double*& operator [] (int i) { return Pointers_[i]; }
00882 
00885   //  const double*& operator [] (int i) const;
00886   double * const & operator [] (int i) const { return Pointers_[i]; }
00887 
00889 
00892   Epetra_Vector * & operator () (int i);
00894 
00897   const Epetra_Vector * & operator () (int i) const;
00898 
00900 
00902 
00903   
00905   int NumVectors() const {return(NumVectors_);};
00906 
00908   int MyLength() const {return(MyLength_);};
00909 
00911   int GlobalLength() const {return(GlobalLength_);};
00912 
00914   int Stride() const {return(Stride_);};
00915   
00917   bool ConstantStride() const {return(ConstantStride_);};
00919 
00923   int ReplaceMap(const Epetra_BlockMap& map);
00924 
00926 
00927 
00929   virtual void Print(ostream & os) const;
00931 
00933 
00934 
00936 
00955   int ResetView(double ** ArrayOfPointers);
00956 
00958   double* Values() const {return Values_;};
00959 
00961   double** Pointers() const {return Pointers_;};
00963 
00964   // Expert-only function
00965   int Reduce(); 
00966 
00967  protected:
00968 
00969   // Internal utilities
00970   void Assign(const Epetra_MultiVector& rhs);
00971   int CheckInput();
00972 
00973   double *Values_;    // local MultiVector coefficients
00974 
00975  private:
00976 
00977 
00978   // Internal utilities
00979 
00980   int AllocateForCopy(void);
00981   int DoCopy(void);
00982 
00983   inline void UpdateDoubleTemp() const
00984   {if (DoubleTemp_==0) DoubleTemp_=new double[NumVectors_+1]; return;}
00985 
00986   inline void UpdateVectors()  const {if (Vectors_==0) { Vectors_ = new Epetra_Vector *[NumVectors_]; 
00987     for (int i=0; i<NumVectors_; i++) Vectors_[i] = 0;}
00988     return;
00989   }
00990 
00991   int AllocateForView(void);
00992   int DoView(void);
00993   int ChangeGlobalValue(int GlobalBlockRow,
00994                         int BlockRowOffset, 
00995                         int VectorIndex,
00996                         double ScalarValue,
00997                         bool SumInto);
00998   int ChangeMyValue(int MyBlockRow,
00999                     int BlockRowOffset, 
01000                     int VectorIndex,
01001                     double ScalarValue,
01002                     bool SumInto);
01003 
01004   int CheckSizes(const Epetra_SrcDistObject& A);
01005 
01006   int CopyAndPermute(const Epetra_SrcDistObject & Source,
01007                      int NumSameIDs, 
01008                      int NumPermuteIDs,
01009                      int * PermuteToLIDs,
01010                      int * PermuteFromLIDs,
01011                      const Epetra_OffsetIndex * Indexor);
01012 
01013   int PackAndPrepare(const Epetra_SrcDistObject & Source,
01014                      int NumExportIDs,
01015                      int * ExportLIDs,
01016                      int & LenExports,
01017                      char * & Exports,
01018                      int & SizeOfPacket,
01019                      int * Sizes,
01020                      bool & VarSizes,
01021                      Epetra_Distributor & Distor);
01022   
01023   int UnpackAndCombine(const Epetra_SrcDistObject & Source,
01024                        int NumImportIDs,
01025                        int * ImportLIDs, 
01026                        int LenImports, 
01027                        char * Imports,
01028                        int & SizeOfPacket, 
01029                        Epetra_Distributor & Distor,
01030                        Epetra_CombineMode CombineMode,
01031                        const Epetra_OffsetIndex * Indexor );
01032 
01033   double **Pointers_;        // Pointers to each vector;
01034   
01035   int MyLength_;
01036   int GlobalLength_;
01037   int NumVectors_;
01038   bool UserAllocated_;
01039   bool ConstantStride_;
01040   int Stride_;
01041   bool Allocated_;
01042   mutable double * DoubleTemp_;
01043   mutable Epetra_Vector ** Vectors_;
01044   Epetra_Util Util_;
01045 
01046 };
01047 
01048 #endif /* EPETRA_MULTIVECTOR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines