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_BlockVector.h" 00030 #include "EpetraExt_BlockUtility.h" 00031 #include "Epetra_Map.h" 00032 #include "Epetra_Comm.h" 00033 00034 namespace EpetraExt { 00035 00036 //============================================================================= 00037 // EpetraExt::BlockVector Constructor 00038 BlockVector::BlockVector( 00039 const Epetra_BlockMap & BaseMap, 00040 const Epetra_BlockMap & GlobalMap) 00041 : Epetra_Vector( GlobalMap ), 00042 BaseMap_( BaseMap ), 00043 Offset_( BlockUtility::CalculateOffset( BaseMap ) ) 00044 { 00045 } 00046 00047 //========================================================================== 00048 // Copy Constructor 00049 BlockVector::BlockVector(const BlockVector& Source) 00050 : Epetra_Vector( dynamic_cast<const Epetra_Vector &>(Source) ), 00051 BaseMap_( Source.BaseMap_ ), 00052 Offset_( Source.Offset_ ) 00053 { 00054 } 00055 00056 //========================================================================= 00057 BlockVector::~BlockVector() 00058 { 00059 } 00060 00061 //========================================================================= 00062 int BlockVector::ExtractBlockValues(Epetra_Vector & BaseVector, int GlobalBlockRow) const 00063 { 00064 int IndexOffset = GlobalBlockRow * Offset_; 00065 int localIndex=0; 00066 00067 // For each entry in the base vector, translate its global ID 00068 // by the IndexOffset and extract the value from this blockVector 00069 for (int i=0; i<BaseMap_.NumMyElements(); i++) { 00070 localIndex = this->Map().LID((IndexOffset + BaseMap_.GID(i))); 00071 if (localIndex==-1) { 00072 cout << "Error in BlockVector::GetBlock: " << i << " " 00073 << IndexOffset << " " << BaseMap_.GID(i) << endl; 00074 return -1; 00075 } 00076 BaseVector[i] = Values_[localIndex]; 00077 } 00078 00079 return 0; 00080 } 00081 00082 //========================================================================= 00083 int BlockVector::LoadBlockValues(const Epetra_Vector & BaseVector, int GlobalBlockRow) 00084 { 00085 int IndexOffset = GlobalBlockRow * Offset_; 00086 int localIndex=0; 00087 00088 // For each entry in the base vector, translate its global ID 00089 // by the IndexOffset and load into this blockVector 00090 for (int i=0; i<BaseMap_.NumMyElements(); i++) { 00091 localIndex = this->Map().LID((IndexOffset + BaseMap_.GID(i))); 00092 if (localIndex==-1) { 00093 cout << "Error in BlockVector::GetBlock: " << i << " " 00094 << IndexOffset << " " << BaseMap_.GID(i) << endl; 00095 return -1; 00096 } 00097 (*this)[localIndex] = BaseVector[i]; 00098 } 00099 00100 return 0; 00101 } 00102 00103 00104 } //namespace EpetraExt
1.4.7