EpetraExt_SubCopy_CrsMatrix.cpp

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

Generated on Wed May 12 21:24:46 2010 for EpetraExt by  doxygen 1.4.7