|
EpetraExt Development
|
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 // EpetraExt::BlockVector Constructor 00049 BlockVector::BlockVector( 00050 Epetra_DataAccess CV, 00051 const Epetra_BlockMap & BaseMap, 00052 const Epetra_Vector & BlockVec) 00053 : Epetra_Vector( CV, BlockVec, 0 ), 00054 BaseMap_( BaseMap ), 00055 Offset_( BlockUtility::CalculateOffset( BaseMap ) ) 00056 { 00057 } 00058 00059 //========================================================================== 00060 // Copy Constructor 00061 BlockVector::BlockVector(const BlockVector& Source) 00062 : Epetra_Vector( dynamic_cast<const Epetra_Vector &>(Source) ), 00063 BaseMap_( Source.BaseMap_ ), 00064 Offset_( Source.Offset_ ) 00065 { 00066 } 00067 00068 //========================================================================= 00069 BlockVector::~BlockVector() 00070 { 00071 } 00072 00073 //========================================================================= 00074 int BlockVector::ExtractBlockValues(Epetra_Vector & BaseVector, int GlobalBlockRow) const 00075 { 00076 int IndexOffset = GlobalBlockRow * Offset_; 00077 int localIndex=0; 00078 00079 // For each entry in the base vector, translate its global ID 00080 // by the IndexOffset and extract the value from this blockVector 00081 for (int i=0; i<BaseMap_.NumMyElements(); i++) { 00082 localIndex = this->Map().LID((IndexOffset + BaseMap_.GID(i))); 00083 if (localIndex==-1) { 00084 cout << "Error in BlockVector::GetBlock: " << i << " " 00085 << IndexOffset << " " << BaseMap_.GID(i) << endl; 00086 return -1; 00087 } 00088 BaseVector[i] = Values_[localIndex]; 00089 } 00090 00091 return 0; 00092 } 00093 00094 //========================================================================= 00095 int BlockVector::LoadBlockValues(const Epetra_Vector & BaseVector, int GlobalBlockRow) 00096 { 00097 int IndexOffset = GlobalBlockRow * Offset_; 00098 int localIndex=0; 00099 00100 // For each entry in the base vector, translate its global ID 00101 // by the IndexOffset and load into this blockVector 00102 for (int i=0; i<BaseMap_.NumMyElements(); i++) { 00103 localIndex = this->Map().LID((IndexOffset + BaseMap_.GID(i))); 00104 if (localIndex==-1) { 00105 cout << "Error in BlockVector::GetBlock: " << i << " " 00106 << IndexOffset << " " << BaseMap_.GID(i) << endl; 00107 return -1; 00108 } 00109 (*this)[localIndex] = BaseVector[i]; 00110 } 00111 00112 return 0; 00113 } 00114 //========================================================================= 00115 int BlockVector::BlockSumIntoGlobalValues(int NumIndices, double* Values, 00116 int* Indices, int GlobalBlockRow) 00117 { 00118 int IndexOffset = GlobalBlockRow * Offset_; 00119 int localIndex=0; 00120 00121 // For each entry in the base vector, translate its global ID 00122 // by the IndexOffset and load into this blockVector 00123 for (int i=0; i<NumIndices; i++) { 00124 localIndex = this->Map().LID((IndexOffset + Indices[i])); 00125 if (localIndex==-1) { 00126 cout << "Error in BlockVector::BlockSumIntoGlobalValues: " << i 00127 << " " << IndexOffset << " " << Indices[i] << endl; 00128 return -1; 00129 } 00130 (*this)[localIndex] += Values[i]; 00131 } 00132 00133 return 0; 00134 } 00135 //========================================================================= 00136 int BlockVector::BlockReplaceGlobalValues(int NumIndices, double* Values, 00137 int* Indices, int GlobalBlockRow) 00138 { 00139 int IndexOffset = GlobalBlockRow * Offset_; 00140 int localIndex=0; 00141 00142 // For each entry in the base vector, translate its global ID 00143 // by the IndexOffset and load into this blockVector 00144 for (int i=0; i<NumIndices; i++) { 00145 localIndex = this->Map().LID((IndexOffset + Indices[i])); 00146 if (localIndex==-1) { 00147 cout << "Error in BlockVector::BlockReplaceGlobalValues: " << i 00148 << " " << IndexOffset << " " << Indices[i] << endl; 00149 return -1; 00150 } 00151 (*this)[localIndex] = Values[i]; 00152 } 00153 00154 return 0; 00155 } 00156 00157 //========================================================================= 00158 Teuchos::RCP<const Epetra_Vector> 00159 BlockVector::GetBlock(int GlobalBlockRow) const 00160 { 00161 int offset = GlobalBlockRow * BaseMap_.NumMyElements(); 00162 return Teuchos::rcp(new Epetra_Vector(View, BaseMap_, Values_+offset)); 00163 } 00164 00165 //========================================================================= 00166 Teuchos::RCP<Epetra_Vector> 00167 BlockVector::GetBlock(int GlobalBlockRow) 00168 { 00169 int offset = GlobalBlockRow * BaseMap_.NumMyElements(); 00170 return Teuchos::rcp(new Epetra_Vector(View, BaseMap_, Values_+offset)); 00171 } 00172 00173 //========================================================================= 00174 const Epetra_BlockMap& 00175 BlockVector::GetBaseMap() const 00176 { 00177 return BaseMap_; 00178 } 00179 00180 00181 } //namespace EpetraExt
1.7.4