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