IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
Ifpack_TriDiContainer.h
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 #ifndef IFPACK_TRIDICONTAINER_H
00044 #define IFPACK_TRIDICONTAINER_H
00045 
00046 #include "Ifpack_ConfigDefs.h"
00047 #include "Ifpack_Container.h"
00048 #include "Ifpack_SerialTriDiMatrix.h"
00049 #include "Ifpack_SerialTriDiSolver.h"
00050 #include "Epetra_IntSerialDenseVector.h" // Is this needed \cbl
00051 #include "Epetra_SerialDenseVector.h"
00052 class Epetra_RowMatrix;
00053 
00055 
00118 class Ifpack_TriDiContainer : public Ifpack_Container {
00119 
00120 public:
00121 
00123 
00125   Ifpack_TriDiContainer(const int NumRows_in, const int NumVectors_in = 1) :
00126     NumRows_(NumRows_in),
00127     NumVectors_(NumVectors_in),
00128     KeepNonFactoredMatrix_(false),
00129     IsInitialized_(false),
00130     IsComputed_(false),
00131     ComputeFlops_(0.0),
00132     ApplyFlops_(0.0),
00133     ApplyInverseFlops_(0.0)
00134   {}
00135 
00137   Ifpack_TriDiContainer(const Ifpack_TriDiContainer& rhs) :
00138     NumRows_(rhs.NumRows()),
00139     NumVectors_(rhs.NumVectors()),
00140     KeepNonFactoredMatrix_(rhs.KeepNonFactoredMatrix()),
00141     IsInitialized_(rhs.IsInitialized()),
00142     IsComputed_(rhs.IsComputed())
00143   {
00144     Matrix_ = rhs.Matrix();
00145     if (KeepNonFactoredMatrix_)
00146       NonFactoredMatrix_ = rhs.NonFactoredMatrix();
00147     LHS_ = rhs.LHS();
00148     RHS_ = rhs.RHS();
00149     ID_ = rhs.ID();
00150   }
00151     
00153   virtual ~Ifpack_TriDiContainer()
00154   {}
00156 
00158 
00160   Ifpack_TriDiContainer& operator=(const Ifpack_TriDiContainer& rhs)
00161   {
00162     if (&rhs == this)
00163       return(*this);
00164 
00165     NumRows_ = rhs.NumRows();
00166     NumVectors_ = rhs.NumVectors();
00167     IsComputed_ = rhs.IsComputed();
00168     KeepNonFactoredMatrix_ = rhs.KeepNonFactoredMatrix();
00169     Matrix_ = rhs.Matrix();
00170     if (KeepNonFactoredMatrix_)
00171       NonFactoredMatrix_ = rhs.NonFactoredMatrix();
00172     LHS_ = rhs.LHS();
00173     RHS_ = rhs.RHS();
00174     ID_ = rhs.ID();
00175 
00176     return(*this);
00177   }
00178 
00180 
00182 
00184   virtual int NumRows() const;
00185 
00187   virtual int NumVectors() const
00188   {
00189     return(NumVectors_);
00190   }
00191 
00193   virtual int SetNumVectors(const int NumVectors_in)
00194   {
00195     if (NumVectors_ == NumVectors_in) 
00196       return(0);
00197 
00198     NumVectors_ = NumVectors_in;
00199     IFPACK_CHK_ERR(RHS_.Reshape(NumRows_,NumVectors_));
00200     IFPACK_CHK_ERR(LHS_.Reshape(NumRows_,NumVectors_));
00201     // zero out vector elements
00202     for (int i = 0 ; i < NumRows_ ; ++i)
00203       for (int j = 0 ; j < NumVectors_ ; ++j) {
00204     LHS_(i,j) = 0.0;
00205     RHS_(i,j) = 0.0;
00206       }
00207      if (NumRows_!=0)
00208        {
00209        IFPACK_CHK_ERR(Solver_.SetVectors(LHS_,RHS_));
00210        }
00211     return(0);
00212   }
00213 
00215   virtual double& LHS(const int i, const int Vector = 0);
00216   
00218   virtual double& RHS(const int i, const int Vector = 0);
00219 
00221 
00230   virtual int& ID(const int i);
00231 
00233   virtual int SetMatrixElement(const int row, const int col,
00234                    const double value);
00235 
00237   virtual int SetParameters(Teuchos::ParameterList& List)
00238   {
00239     return(0);
00240   }
00241 
00243   virtual bool IsInitialized() const
00244   {
00245     return(IsInitialized_);
00246   }
00247 
00249   virtual bool IsComputed() const
00250   {
00251     return(IsComputed_);
00252   }
00253 
00255   virtual const char* Label() const
00256   {
00257     return(Label_.c_str());
00258   }
00259 
00261   virtual int SetKeepNonFactoredMatrix(const bool flag)
00262   {
00263     KeepNonFactoredMatrix_ = flag;
00264     return(0);
00265   }
00266 
00268   virtual bool KeepNonFactoredMatrix() const
00269   {
00270     return(KeepNonFactoredMatrix_);
00271   }
00272 
00274   virtual const Epetra_SerialDenseMatrix& LHS() const
00275   {
00276     return(LHS_);
00277   }
00278 
00280   virtual const Epetra_SerialDenseMatrix& RHS() const
00281   {
00282     return(RHS_);
00283   }
00284 
00286   virtual const Ifpack_SerialTriDiMatrix& Matrix() const
00287   {
00288     return(Matrix_);
00289   }
00290 
00292   virtual const Ifpack_SerialTriDiMatrix& NonFactoredMatrix() const
00293   {
00294     return(NonFactoredMatrix_);
00295   }
00296 
00298   virtual const Epetra_IntSerialDenseVector& ID() const
00299   {
00300     return(ID_);
00301   }
00302 
00304 
00306 
00307   virtual int Initialize();
00308 
00310   virtual int Compute(const Epetra_RowMatrix& Matrix_in);
00311 
00313   virtual int Apply();
00314 
00316   virtual int ApplyInverse();
00317 
00319 
00320   virtual double InitializeFlops() const
00321   {
00322     return(0.0);
00323   }
00324 
00325   virtual double ComputeFlops() const
00326   {
00327     return(ComputeFlops_);
00328   }
00329 
00330   virtual double ApplyFlops() const
00331   {
00332     return(ApplyFlops_);
00333   }
00334 
00335   virtual double ApplyInverseFlops() const
00336   {
00337     return(ApplyInverseFlops_);
00338   }
00339 
00341   virtual ostream& Print(std::ostream& os) const;
00342 
00343 private:
00344   
00346   virtual int Extract(const Epetra_RowMatrix& Matrix_in);
00347 
00349   int NumRows_; 
00351   int NumVectors_;
00353   Ifpack_SerialTriDiMatrix NonFactoredMatrix_;
00355   Ifpack_SerialTriDiMatrix Matrix_;
00357   Epetra_SerialDenseMatrix LHS_;
00359   Epetra_SerialDenseMatrix RHS_;
00361   Ifpack_SerialTriDiSolver Solver_;
00363   Epetra_IntSerialDenseVector ID_;
00365   bool KeepNonFactoredMatrix_;
00367   bool IsInitialized_;
00369   bool IsComputed_;
00371   string Label_;
00372 
00374   double ComputeFlops_;
00376   double ApplyFlops_;
00378   double ApplyInverseFlops_;
00379 };
00380 
00381 #endif
 All Classes Files Functions Variables Enumerations Friends