IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
Ifpack_ReorderFilter.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_ConfigDefs.h"
00044 #include "Ifpack_ReorderFilter.h"
00045 #include "Ifpack_Reordering.h"
00046 #include "Epetra_ConfigDefs.h"
00047 #include "Epetra_RowMatrix.h"
00048 #include "Epetra_Comm.h"
00049 #include "Epetra_Map.h"
00050 #include "Epetra_MultiVector.h"
00051 #include "Epetra_Vector.h"
00052 
00053 //==============================================================================
00054 Ifpack_ReorderFilter::Ifpack_ReorderFilter(const Teuchos::RefCountPtr<Epetra_RowMatrix>& Matrix_in,
00055                                            const Teuchos::RefCountPtr<Ifpack_Reordering>& Reordering_in) :
00056   A_(Matrix_in),
00057   Reordering_(Reordering_in),
00058   NumMyRows_(Matrix_in->NumMyRows()),
00059   MaxNumEntries_(Matrix_in->MaxNumEntries())
00060 {
00061 }
00062 
00063 //==============================================================================
00064 Ifpack_ReorderFilter::Ifpack_ReorderFilter(const Ifpack_ReorderFilter& RHS) :
00065   A_(Matrix()),
00066   Reordering_(Reordering()),
00067   NumMyRows_(RHS.NumMyRows()),
00068   MaxNumEntries_(RHS.MaxNumEntries())
00069 {
00070   strcpy(Label_,RHS.Label());
00071 }
00072 
00073 //==============================================================================
00074 Ifpack_ReorderFilter& 
00075 Ifpack_ReorderFilter::operator=(const Ifpack_ReorderFilter& RHS)
00076 {
00077   if (this == &RHS)
00078     return (*this);
00079 
00080   A_ = RHS.Matrix();
00081 
00082   Reordering_ = RHS.Reordering();
00083   MaxNumEntries_ = RHS.MaxNumEntries();
00084   NumMyRows_ = RHS.NumMyRows();
00085 
00086   strcpy(Label_,RHS.Label());
00087   return(*this);
00088 }
00089 
00090 //==============================================================================
00091 int Ifpack_ReorderFilter::
00092 ExtractMyRowCopy(int MyRow, int Length, int & NumEntries, 
00093                  double *Values, int * Indices) const
00094 {
00095   int MyReorderdRow = Reordering_->InvReorder(MyRow);
00096 
00097   IFPACK_CHK_ERR(Matrix()->ExtractMyRowCopy(MyReorderdRow,MaxNumEntries_,
00098                                            NumEntries, Values,Indices));
00099 
00100   // suppose all elements are local. Note that now
00101   // Indices can have indices in non-increasing order.
00102   for (int i = 0 ; i < NumEntries ; ++i) {
00103     Indices[i] = Reordering_->Reorder(Indices[i]);
00104   }
00105 
00106   return(0);
00107 }
00108 
00109 //==============================================================================
00110 int Ifpack_ReorderFilter::
00111 ExtractDiagonalCopy(Epetra_Vector & Diagonal) const
00112 {
00113   Epetra_Vector DiagonalTilde(Diagonal.Map());
00114   IFPACK_CHK_ERR(Matrix()->ExtractDiagonalCopy(DiagonalTilde));
00115   IFPACK_CHK_ERR((Reordering_->P(DiagonalTilde,Diagonal)));
00116   return(0);
00117 }
00118 
00119 //==============================================================================
00120 int Ifpack_ReorderFilter::
00121 Multiply(bool TransA, const Epetra_MultiVector& X, 
00122          Epetra_MultiVector& Y) const
00123 {
00124   // need two additional vectors
00125   Epetra_MultiVector Xtilde(X.Map(),X.NumVectors());
00126   Epetra_MultiVector Ytilde(Y.Map(),Y.NumVectors());
00127   // bring X back to original ordering
00128   Reordering_->Pinv(X,Xtilde);
00129   // apply original matrix
00130   IFPACK_CHK_ERR(Matrix()->Multiply(TransA,Xtilde,Ytilde));
00131   // now reorder result
00132   Reordering_->P(Ytilde,Y);
00133 
00134 
00135   return(0);
00136 }
00137 
00138 //==============================================================================
00139 int Ifpack_ReorderFilter::
00140 Solve(bool Upper, bool Trans, bool UnitDiagonal, 
00141       const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
00142 {
00143   IFPACK_CHK_ERR(-98);
00144 }
00145 
00146 //==============================================================================
00147 int Ifpack_ReorderFilter::
00148 Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const
00149 {
00150   int ierr = Multiply(UseTranspose(),X,Y);
00151   IFPACK_RETURN(ierr);
00152 }
 All Classes Files Functions Variables Enumerations Friends