EpetraExt_BlockMultiVector.cpp

Go to the documentation of this file.
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_BlockMultiVector.h"
00030 #include "Epetra_Map.h"
00031 
00032 using std::vector;
00033 
00034 namespace EpetraExt {
00035 
00036 //=============================================================================
00037 // EpetraExt::BlockMultiVector Constructor
00038 BlockMultiVector::BlockMultiVector(
00039       const Epetra_BlockMap & BaseMap,
00040       const Epetra_BlockMap & GlobalMap,
00041       int NumVectors )
00042   : Epetra_MultiVector( GlobalMap, NumVectors ),
00043     BaseMap_( BaseMap ),
00044     NumBlocks_(1)
00045 {
00046   AllocateBlocks_();
00047 }
00048 
00049 //=============================================================================
00050 // EpetraExt::BlockMultiVector Constructor
00051 BlockMultiVector::BlockMultiVector(
00052       const Epetra_BlockMap & BaseMap,
00053       const Epetra_BlockMap & GlobalMap,
00054       int NumBlocks,
00055       int NumVectors )
00056   : Epetra_MultiVector( GlobalMap, NumVectors ),
00057     BaseMap_( BaseMap ),
00058     NumBlocks_(NumBlocks)
00059 {
00060   AllocateBlocks_();
00061 }
00062 
00063 //==========================================================================
00064 // Copy Constructor
00065 BlockMultiVector::BlockMultiVector(const BlockMultiVector& Source)
00066   : Epetra_MultiVector( dynamic_cast<const Epetra_MultiVector &>(Source) ),
00067     BaseMap_( Source.BaseMap_ ),
00068     NumBlocks_( Source.NumBlocks_ )
00069 {
00070   AllocateBlocks_();
00071 }
00072 
00073 //=========================================================================
00074 BlockMultiVector::~BlockMultiVector()
00075 {
00076   DeleteBlocks_();
00077 }
00078 
00079 //=========================================================================
00080 void BlockMultiVector::AllocateBlocks_(void)
00081 {
00082   int NumElements = BaseMap_.NumMyElements();
00083   Ptrs_.resize(NumBlocks_);
00084   for( int i = 0; i < NumBlocks_; ++i ) Ptrs_[i] = new double*[NumVectors()];
00085 
00086   double ** OrigPtrs;
00087   ExtractView( &OrigPtrs );
00088 
00089   for( int i = 0; i < NumBlocks_; ++i )
00090   {
00091     for( int j = 0; j < NumVectors(); ++j )
00092       Ptrs_[i][j] = OrigPtrs[j]+(i*NumElements);
00093 
00094     Blocks_[i] = new Epetra_MultiVector( View, BaseMap_, Ptrs_[i], NumVectors() );
00095   }
00096 }
00097 
00098 //=========================================================================
00099 void BlockMultiVector::DeleteBlocks_(void)
00100 {
00101   for( int i = 0; i < NumBlocks_; ++i )
00102   {
00103     delete Blocks_[i];
00104     Blocks_[i] = 0;
00105     delete [] Ptrs_[i];
00106     Ptrs_[i] = 0;
00107   }
00108 }
00109 
00110 } //namespace EpetraExt

Generated on Thu Sep 18 12:31:43 2008 for EpetraExt by doxygen 1.3.9.1