00001 //@HEADER 00002 // ************************************************************************ 00003 // 00004 // EpetraExt: Extended Linear Algebra Services Package 00005 // Copyright (2001) 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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // ************************************************************************ 00027 //@HEADER 00028 00029 #include "EpetraExt_BlockMultiVector.h" 00030 #include "EpetraExt_BlockUtility.h" 00031 #include "Epetra_Map.h" 00032 00033 using std::vector; 00034 00035 namespace EpetraExt { 00036 00037 //============================================================================= 00038 // EpetraExt::BlockMultiVector Constructor 00039 BlockMultiVector::BlockMultiVector( 00040 const Epetra_BlockMap & BaseMap, 00041 const Epetra_BlockMap & GlobalMap, 00042 int NumVectors ) 00043 : Epetra_MultiVector( GlobalMap, NumVectors ), 00044 BaseMap_( BaseMap ), 00045 Offset_( BlockUtility::CalculateOffset( BaseMap ) ) 00046 { 00047 } 00048 00049 //========================================================================== 00050 // Copy Constructor 00051 BlockMultiVector::BlockMultiVector(const BlockMultiVector& Source) 00052 : Epetra_MultiVector( dynamic_cast<const Epetra_MultiVector &>(Source) ), 00053 BaseMap_( Source.BaseMap_ ), 00054 Offset_( Source.Offset_ ) 00055 { 00056 } 00057 00058 //========================================================================= 00059 BlockMultiVector::~BlockMultiVector() 00060 { 00061 } 00062 00063 //========================================================================= 00064 int BlockMultiVector::ExtractBlockValues(Epetra_MultiVector & BaseVector, int GlobalBlockRow) const 00065 { 00066 int IndexOffset = GlobalBlockRow * Offset_; 00067 int localIndex=0; 00068 00069 // For each entry in the base vector, translate its global ID 00070 // by the IndexOffset and extract the value from this blockVector 00071 for (int i=0; i<BaseMap_.NumMyElements(); i++) { 00072 localIndex = this->Map().LID((IndexOffset + BaseMap_.GID(i))); 00073 if (localIndex==-1) { 00074 cout << "Error in BlockMultiVector::GetBlock: " << i << " " 00075 << IndexOffset << " " << BaseMap_.GID(i) << endl; 00076 return -1; 00077 } 00078 for (int j=0; j<NumVectors(); j++) 00079 BaseVector[j][i] = (*this)[j][localIndex]; 00080 } 00081 00082 return 0; 00083 } 00084 00085 //========================================================================= 00086 int BlockMultiVector::LoadBlockValues(const Epetra_MultiVector & BaseVector, int GlobalBlockRow) 00087 { 00088 int IndexOffset = GlobalBlockRow * Offset_; 00089 int localIndex=0; 00090 00091 // For each entry in the base vector, translate its global ID 00092 // by the IndexOffset and load into this blockVector 00093 for (int i=0; i<BaseMap_.NumMyElements(); i++) { 00094 localIndex = this->Map().LID((IndexOffset + BaseMap_.GID(i))); 00095 if (localIndex==-1) { 00096 cout << "Error in BlockMultiVector::GetBlock: " << i << " " 00097 << IndexOffset << " " << BaseMap_.GID(i) << endl; 00098 return -1; 00099 } 00100 for (int j=0; j<NumVectors(); j++) 00101 (*this)[j][localIndex] = BaseVector[j][i]; 00102 } 00103 00104 return 0; 00105 } 00106 00107 } //namespace EpetraExt
1.4.7