Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ifpack_OverlapGraph.cpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #include "Ifpack_OverlapGraph.h"
44 #include "Epetra_CrsGraph.h"
45 #include "Epetra_RowMatrix.h"
46 #include "Epetra_BlockMap.h"
47 #include "Epetra_Map.h"
48 
49 #include <Teuchos_ParameterList.hpp>
50 #include <ifp_parameters.h>
51 
52 //==============================================================================
53 Ifpack_OverlapGraph::Ifpack_OverlapGraph(const Teuchos::RefCountPtr<const Epetra_CrsGraph>& UserMatrixGraph_in, int OverlapLevel_in)
54  : UserMatrixGraph_(UserMatrixGraph_in),
55  OverlapLevel_(OverlapLevel_in)
56 {
57  // Test for non-trivial overlap here so we can use it later.
58  IsOverlapped_ = (OverlapLevel_in>0 && UserMatrixGraph_in->DomainMap().DistributedGlobal());
59 
60  ConstructOverlapGraph(UserMatrixGraph_in);
61 
62 }
63 //==============================================================================
64 Ifpack_OverlapGraph::Ifpack_OverlapGraph(const Teuchos::RefCountPtr<const Epetra_RowMatrix>& UserMatrix_in, int OverlapLevel_in)
65  : UserMatrix_(UserMatrix_in),
66  OverlapLevel_(OverlapLevel_in)
67 {
68  // Test for non-trivial overlap here so we can use it later.
69  IsOverlapped_ = (OverlapLevel_in>0 && UserMatrix_in->OperatorDomainMap().DistributedGlobal());
70 
71  throw ReportError("This constructor is not implemented yet. Need to add Epetra_SrcObject support to Epetra_Import/Export", -1);
72 }
73 //==============================================================================
75  : OverlapGraph_(Source.OverlapGraph_),
76  UserMatrixGraph_(Source.UserMatrixGraph_),
77  UserMatrix_(Source.UserMatrix_),
78  OverlapRowMap_(Source.OverlapRowMap_),
79  OverlapLevel_(Source.OverlapLevel_),
80  IsOverlapped_(Source.IsOverlapped_)
81 {
82  if (IsOverlapped_) {
85  }
86 
87 }
88 
89 //==========================================================================
91  bool cerr_warning_if_unused)
92 {
93  Ifpack::param_struct params;
95 
96  Ifpack::set_parameters(parameterlist, params, cerr_warning_if_unused);
97 
99  return(0);
100 }
101 
102 //==============================================================================
103 int Ifpack_OverlapGraph::ConstructOverlapGraph(const Teuchos::RefCountPtr<const Epetra_CrsGraph>& UserMatrixGraph) {
104 
105  if (!IsOverlapped_) {
106  OverlapGraph_ = Teuchos::rcp_const_cast<Epetra_CrsGraph>( UserMatrixGraph );
107  OverlapRowMap_ = Teuchos::rcp( (Epetra_BlockMap *) &UserMatrixGraph->RowMap(), false );
108  return(0); // All done
109  }
110 
111  Teuchos::RefCountPtr<Epetra_CrsGraph> OldGraph;
112  Teuchos::RefCountPtr<Epetra_BlockMap> OldRowMap;
113  const Epetra_BlockMap DomainMap = UserMatrixGraph->DomainMap();
114  const Epetra_BlockMap RangeMap = UserMatrixGraph->RangeMap();
115 
116  for (int level=1; level <= OverlapLevel_; level++) {
117  OldGraph = OverlapGraph_;
118  OldRowMap = OverlapRowMap_;
119 
120  OverlapImporter_ = Teuchos::rcp( (Epetra_Import *) OldGraph->Importer(), false );
122 
123  if (level<OverlapLevel_)
124  OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(Copy, *OverlapRowMap_, 0) );
125  else
126  // On last iteration, we want to filter out all columns except those that correspond
127  // to rows in the graph. This assures that our matrix is square
128  OverlapGraph_ = Teuchos::rcp( new Epetra_CrsGraph(Copy, *OverlapRowMap_, *OverlapRowMap_, 0) );
129 
130  EPETRA_CHK_ERR(OverlapGraph_->Import( *UserMatrixGraph, *OverlapImporter_, Insert));
131  if (level<OverlapLevel_) {
132  EPETRA_CHK_ERR(OverlapGraph_->FillComplete(DomainMap, RangeMap));
133  }
134  else {
135  // Copy last OverlapImporter because we will use it later
136  OverlapImporter_ = Teuchos::rcp( new Epetra_Import(*OverlapRowMap_, DomainMap) );
137  EPETRA_CHK_ERR(OverlapGraph_->FillComplete(DomainMap, RangeMap));
138  }
139 
140  }
141 
142  return(0);
143 }
144 
Ifpack_OverlapGraph: Constructs a graph for use with Ifpack preconditioners.
int int_params[LAST_INT_PARAM-FIRST_INT_PARAM+1]
Teuchos::RefCountPtr< Epetra_BlockMap > OverlapRowMap_
#define EPETRA_CHK_ERR(a)
#define FIRST_INT_PARAM
Ifpack_OverlapGraph(const Teuchos::RefCountPtr< const Epetra_CrsGraph > &UserMatrixGraph_in, int OverlapLevel_in)
Constructor using Epetra_CrsGraph.
int ConstructOverlapGraph(const Teuchos::RefCountPtr< const Epetra_CrsGraph > &UserMatrixGraph)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RefCountPtr< Epetra_CrsGraph > OverlapGraph_
int SetParameters(const Teuchos::ParameterList &parameterlist, bool cerr_warning_if_unused=false)
Set parameters using a Teuchos::ParameterList object.
#define false
Teuchos::RefCountPtr< Epetra_Import > OverlapImporter_
void set_parameters(const Teuchos::ParameterList &parameterlist, param_struct &params, bool cerr_warning_if_unused)