Ifpack_OverlapGraph.cpp

00001 /*@HEADER
00002 // ***********************************************************************
00003 // 
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) 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 
00030 #include "Ifpack_OverlapGraph.h"
00031 #include "Epetra_CrsGraph.h"
00032 #include "Epetra_RowMatrix.h"
00033 #include "Epetra_BlockMap.h"
00034 #include "Epetra_Map.h"
00035 
00036 #include <Teuchos_ParameterList.hpp>
00037 #include <ifp_parameters.h>
00038 
00039 //==============================================================================
00040 Ifpack_OverlapGraph::Ifpack_OverlapGraph(const Teuchos::RefCountPtr<const Epetra_CrsGraph>& UserMatrixGraph_in, int OverlapLevel_in)
00041   : UserMatrixGraph_(UserMatrixGraph_in),
00042     OverlapLevel_(OverlapLevel_in)
00043 {
00044   // Test for non-trivial overlap here so we can use it later.
00045   IsOverlapped_ = (OverlapLevel_in>0 && UserMatrixGraph_in->DomainMap().DistributedGlobal());
00046 
00047   ConstructOverlapGraph(UserMatrixGraph_in);
00048 
00049 }
00050 //==============================================================================
00051 Ifpack_OverlapGraph::Ifpack_OverlapGraph(const Teuchos::RefCountPtr<const Epetra_RowMatrix>& UserMatrix_in, int OverlapLevel_in)
00052   : UserMatrix_(UserMatrix_in),
00053     OverlapLevel_(OverlapLevel_in)
00054 {
00055   // Test for non-trivial overlap here so we can use it later.
00056   IsOverlapped_ = (OverlapLevel_in>0 && UserMatrix_in->OperatorDomainMap().DistributedGlobal());
00057   
00058   throw ReportError("This constructor is not implemented yet.  Need to add Epetra_SrcObject support to Epetra_Import/Export", -1);
00059 }
00060 //==============================================================================
00061 Ifpack_OverlapGraph::Ifpack_OverlapGraph(const Ifpack_OverlapGraph & Source)
00062   : OverlapGraph_(Source.OverlapGraph_),
00063     UserMatrixGraph_(Source.UserMatrixGraph_),
00064     UserMatrix_(Source.UserMatrix_),
00065     OverlapRowMap_(Source.OverlapRowMap_),
00066     OverlapLevel_(Source.OverlapLevel_),
00067     IsOverlapped_(Source.IsOverlapped_)
00068 {
00069   if (IsOverlapped_) {
00070     if (OverlapGraph_!=Teuchos::null) OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(*OverlapGraph_) );
00071     if (OverlapRowMap_!=Teuchos::null) OverlapRowMap_ = Teuchos::rcp( new Epetra_BlockMap(*OverlapRowMap_) );
00072   }
00073   
00074 }
00075 
00076 //==========================================================================
00077 int Ifpack_OverlapGraph::SetParameters(const Teuchos::ParameterList& parameterlist,
00078                        bool cerr_warning_if_unused)
00079 {
00080   Ifpack::param_struct params;
00081   params.int_params[Ifpack::level_overlap-FIRST_INT_PARAM] = OverlapLevel_;
00082 
00083   Ifpack::set_parameters(parameterlist, params, cerr_warning_if_unused);
00084 
00085   OverlapLevel_ = params.int_params[Ifpack::level_overlap-FIRST_INT_PARAM];
00086   return(0);
00087 }
00088 
00089 //==============================================================================
00090 int Ifpack_OverlapGraph::ConstructOverlapGraph(const Teuchos::RefCountPtr<const Epetra_CrsGraph>& UserMatrixGraph) {
00091 
00092   if (!IsOverlapped_) {
00093     OverlapGraph_ = Teuchos::rcp_const_cast<Epetra_CrsGraph>( UserMatrixGraph );
00094     OverlapRowMap_ = Teuchos::rcp( (Epetra_BlockMap *) &UserMatrixGraph->RowMap(), false );
00095     return(0); // All done
00096   }
00097 
00098   Teuchos::RefCountPtr<Epetra_CrsGraph> OldGraph;
00099   Teuchos::RefCountPtr<Epetra_BlockMap> OldRowMap;
00100   const Epetra_BlockMap DomainMap = UserMatrixGraph->DomainMap();
00101   const Epetra_BlockMap RangeMap = UserMatrixGraph->RangeMap();
00102 
00103   for (int level=1; level <= OverlapLevel_; level++) {
00104     OldGraph = OverlapGraph_;
00105     OldRowMap = OverlapRowMap_;
00106 
00107     OverlapImporter_ = Teuchos::rcp( (Epetra_Import *) OldGraph->Importer(), false );
00108     OverlapRowMap_ = Teuchos::rcp( new Epetra_BlockMap(OverlapImporter_->TargetMap()) );
00109 
00110     if (level<OverlapLevel_)
00111       OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(Copy, *OverlapRowMap_, 0) );
00112     else
00113       // On last iteration, we want to filter out all columns except those that correspond
00114       // to rows in the graph.  This assures that our matrix is square
00115       OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(Copy, *OverlapRowMap_, *OverlapRowMap_, 0) );
00116 
00117     EPETRA_CHK_ERR(OverlapGraph_->Import( *UserMatrixGraph, *OverlapImporter_, Insert));
00118     if (level<OverlapLevel_) {
00119       EPETRA_CHK_ERR(OverlapGraph_->FillComplete(DomainMap, RangeMap));
00120     }
00121     else {
00122       // Copy last OverlapImporter because we will use it later
00123       OverlapImporter_ = Teuchos::rcp( new Epetra_Import(*OverlapRowMap_, DomainMap) );
00124       EPETRA_CHK_ERR(OverlapGraph_->FillComplete(DomainMap, RangeMap));
00125     }
00126 
00127   }
00128 
00129   return(0);
00130 }
00131 

Generated on Tue Jul 13 09:27:13 2010 for IFPACK by  doxygen 1.4.7