|
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_SubCopy_CrsMatrix.h" 00043 00044 #include <Epetra_CrsMatrix.h> 00045 #include <Epetra_Map.h> 00046 #include <Epetra_Import.h> 00047 #include <Epetra_IntSerialDenseVector.h> 00048 00049 #include <vector> 00050 00051 namespace EpetraExt { 00052 00053 CrsMatrix_SubCopy:: 00054 ~CrsMatrix_SubCopy() 00055 { 00056 if( newObj_ ) delete newObj_; 00057 } 00058 00059 CrsMatrix_SubCopy::NewTypeRef 00060 CrsMatrix_SubCopy:: 00061 operator()( OriginalTypeRef orig ) 00062 { 00063 origObj_ = &orig; 00064 00065 //Error, must be local indices 00066 assert( orig.Filled() ); 00067 00068 //test maps, new map must be subset of old 00069 const Epetra_Map & oRowMap = orig.RowMap(); 00070 const Epetra_Map & oColMap = orig.ColMap(); 00071 00072 int oNumRows = oRowMap.NumMyElements(); 00073 int oNumCols = oColMap.NumMyElements(); 00074 int nNumRows = newRowMap_.NumMyElements(); 00075 int nNumDomain = newDomainMap_.NumMyElements(); 00076 00077 bool matched = true; 00078 00079 // Make sure all rows in newRowMap are already on this processor 00080 for( int i = 0; i < nNumRows; ++i ) 00081 matched = matched && ( oRowMap.MyGID(newRowMap_.GID(i)) ); 00082 if( !matched ) cerr << "EDT_CrsMatrix_SubCopy: Bad new_row_Map. GIDs of new row map must be GIDs of the original row map on the same processor.\n"; 00083 00084 // Make sure all GIDs in the new domain map are GIDs in the old domain map 00085 if( !newRangeMap_.SameAs(newDomainMap_) ) { 00086 Epetra_IntSerialDenseVector pidList(nNumDomain); 00087 oColMap.RemoteIDList(newDomainMap_.NumMyElements(), newDomainMap_.MyGlobalElements(), pidList.Values(), 0); 00088 for( int i = 0; i < nNumDomain; ++i ) 00089 matched = matched && ( pidList[i]>=0 ); 00090 } 00091 00092 if( !matched ) cout << "EDT_CrsMatrix_SubCopy: Bad newDomainMap. One or more GIDs in new domain map are not part of original domain map.\n"; 00093 assert( matched ); 00094 00095 00096 // Next build new column map 00097 Epetra_IntSerialDenseVector pidList(oNumCols); 00098 Epetra_IntSerialDenseVector lidList(oNumCols); 00099 Epetra_IntSerialDenseVector sizeList(oNumCols); 00100 newDomainMap_.RemoteIDList(oColMap.NumMyElements(), oColMap.MyGlobalElements(), pidList.Values(), 0); 00101 int numNewCols = 0; 00102 Epetra_IntSerialDenseVector newColMapGidList(oNumCols); 00103 int * origColGidList = oColMap.MyGlobalElements(); 00104 for( int i = 0; i < oNumCols; ++i ) 00105 if (pidList[i] >=0) 00106 newColMapGidList[numNewCols++]= origColGidList[i]; 00107 newColMap_ = Epetra_Map(-1, numNewCols, newColMapGidList.Values(), 0, oColMap.Comm()); 00108 00109 importer_ = new Epetra_Import(newRowMap_, oRowMap); 00110 00111 Epetra_CrsMatrix * newMatrix = new Epetra_CrsMatrix(Copy, newRowMap_, newColMap_, 0); 00112 00113 newObj_ = newMatrix; 00114 00115 newObj_->Import(*origObj_, *importer_, Add); 00116 00117 newObj_->FillComplete(); 00118 00119 return *newObj_; 00120 } 00121 00122 //============================================================================== 00123 bool CrsMatrix_SubCopy::fwd() 00124 { 00125 00126 if (newObj_->Filled()) newObj_->PutScalar(0.0); // zero contents 00127 00128 newObj_->Import(*origObj_, *importer_, Add); 00129 00130 newObj_->FillComplete(); 00131 00132 00133 return (true); 00134 } 00135 00136 //============================================================================== 00137 bool CrsMatrix_SubCopy::rvs() 00138 { 00139 if (!newObj_->Filled()) return(false); // Must have fillCompleted 00140 00141 origObj_->Export(*newObj_, *importer_, Add); 00142 00143 origObj_->FillComplete(); 00144 00145 return (true); 00146 } 00147 00148 } // namespace EpetraExt 00149
1.7.6.1