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