IFPACK Development
Loading...
Searching...
No Matches
Ifpack_ReorderFilter.cpp
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_ConfigDefs.h"
44#include "Ifpack_ReorderFilter.h"
45#include "Ifpack_Reordering.h"
46#include "Epetra_ConfigDefs.h"
47#include "Epetra_RowMatrix.h"
48#include "Epetra_Comm.h"
49#include "Epetra_Map.h"
50#include "Epetra_MultiVector.h"
51#include "Epetra_Vector.h"
52
53//==============================================================================
54Ifpack_ReorderFilter::Ifpack_ReorderFilter(const Teuchos::RefCountPtr<Epetra_RowMatrix>& Matrix_in,
55 const Teuchos::RefCountPtr<Ifpack_Reordering>& Reordering_in) :
56 A_(Matrix_in),
57 Reordering_(Reordering_in),
58 NumMyRows_(Matrix_in->NumMyRows()),
59 MaxNumEntries_(Matrix_in->MaxNumEntries())
60{
61}
62
63//==============================================================================
64Ifpack_ReorderFilter::Ifpack_ReorderFilter(const Ifpack_ReorderFilter& RHS) :
65 A_(Matrix()),
66 Reordering_(Reordering()),
67 NumMyRows_(RHS.NumMyRows()),
68 MaxNumEntries_(RHS.MaxNumEntries())
69{
70 strcpy(Label_,RHS.Label());
71}
72
73//==============================================================================
76{
77 if (this == &RHS)
78 return (*this);
79
80 A_ = RHS.Matrix();
81
82 Reordering_ = RHS.Reordering();
83 MaxNumEntries_ = RHS.MaxNumEntries();
84 NumMyRows_ = RHS.NumMyRows();
85
86 strcpy(Label_,RHS.Label());
87 return(*this);
88}
89
90//==============================================================================
91int Ifpack_ReorderFilter::
92ExtractMyRowCopy(int MyRow, int /* Length */, int & NumEntries,
93 double *Values, int * Indices) const
94{
95 int MyReorderdRow = Reordering_->InvReorder(MyRow);
96
97 IFPACK_CHK_ERR(Matrix()->ExtractMyRowCopy(MyReorderdRow,MaxNumEntries_,
98 NumEntries, Values,Indices));
99
100 // suppose all elements are local. Note that now
101 // Indices can have indices in non-increasing order.
102 for (int i = 0 ; i < NumEntries ; ++i) {
103 Indices[i] = Reordering_->Reorder(Indices[i]);
104 }
105
106 return(0);
107}
108
109//==============================================================================
111ExtractDiagonalCopy(Epetra_Vector & Diagonal) const
112{
113 Epetra_Vector DiagonalTilde(Diagonal.Map());
114 IFPACK_CHK_ERR(Matrix()->ExtractDiagonalCopy(DiagonalTilde));
115 IFPACK_CHK_ERR((Reordering_->P(DiagonalTilde,Diagonal)));
116 return(0);
117}
118
119//==============================================================================
121Multiply(bool TransA, const Epetra_MultiVector& X,
122 Epetra_MultiVector& Y) const
123{
124 // need two additional vectors
125 Epetra_MultiVector Xtilde(X.Map(),X.NumVectors());
126 Epetra_MultiVector Ytilde(Y.Map(),Y.NumVectors());
127 // bring X back to original ordering
128 Reordering_->Pinv(X,Xtilde);
129 // apply original matrix
130 IFPACK_CHK_ERR(Matrix()->Multiply(TransA,Xtilde,Ytilde));
131 // now reorder result
132 Reordering_->P(Ytilde,Y);
133
134
135 return(0);
136}
137
138//==============================================================================
140Solve(bool /* Upper */, bool /* Trans */, bool /* UnitDiagonal */,
141 const Epetra_MultiVector& /* X */, Epetra_MultiVector& /* Y */) const
142{
143 IFPACK_CHK_ERR(-98);
144}
145
146//==============================================================================
149{
150 int ierr = Multiply(UseTranspose(),X,Y);
151 IFPACK_RETURN(ierr);
152}
const Epetra_BlockMap & Map() const
int NumVectors() const
Ifpack_ReorderFilter: a class for light-weight reorder of local rows and columns of an Epetra_RowMatr...
bool UseTranspose() const
Returns true if the transpose of this matrix is used.
Teuchos::RefCountPtr< Epetra_RowMatrix > Matrix() const
Returns a reference-counted pointer to the internally stored pointer to Epetra_RowMatrix.
virtual int Multiply(bool TransA, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Multiplies multi-vector X with the reordered matrix, returns result in Y.
virtual int ExtractDiagonalCopy(Epetra_Vector &Diagonal) const
Extracts a copy of the diagonal of the reordered matrix.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the reordered matrix to multi-vector X, returns the result in Y.
Ifpack_ReorderFilter & operator=(const Ifpack_ReorderFilter &RHS)
Operator assignment.
virtual int Solve(bool Upper, bool Trans, bool UnitDiagonal, const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Solve, not implemented.