IFPACK Development
Ifpack_DenseContainer.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_DENSECONTAINER_H
00044 #define IFPACK_DENSECONTAINER_H
00045 
00046 #include "Ifpack_ConfigDefs.h"
00047 #include "Ifpack_Container.h"
00048 #include "Epetra_SerialDenseMatrix.h"
00049 #include "Epetra_SerialDenseSolver.h"
00050 #include "Epetra_IntSerialDenseVector.h"
00051 class Epetra_RowMatrix;
00052 
00054 
00117 class Ifpack_DenseContainer : public Ifpack_Container {
00118 
00119 public:
00120 
00122 
00124   Ifpack_DenseContainer(const int NumRows_in, const int NumVectors_in = 1) :
00125     NumRows_(NumRows_in),
00126     NumVectors_(NumVectors_in),
00127     KeepNonFactoredMatrix_(false),
00128     IsInitialized_(false),
00129     IsComputed_(false),
00130     ComputeFlops_(0.0),
00131     ApplyFlops_(0.0),
00132     ApplyInverseFlops_(0.0)
00133   {}
00134 
00136   Ifpack_DenseContainer(const Ifpack_DenseContainer& rhs) :
00137     NumRows_(rhs.NumRows()),
00138     NumVectors_(rhs.NumVectors()),
00139     KeepNonFactoredMatrix_(rhs.KeepNonFactoredMatrix()),
00140     IsInitialized_(rhs.IsInitialized()),
00141     IsComputed_(rhs.IsComputed())
00142   {
00143     Matrix_ = rhs.Matrix();
00144     if (KeepNonFactoredMatrix_)
00145       NonFactoredMatrix_ = rhs.NonFactoredMatrix();
00146     LHS_ = rhs.LHS();
00147     RHS_ = rhs.RHS();
00148     ID_ = rhs.ID();
00149   }
00150     
00152   virtual ~Ifpack_DenseContainer()
00153   {}
00155 
00157 
00159   Ifpack_DenseContainer& operator=(const Ifpack_DenseContainer& rhs)
00160   {
00161     if (&rhs == this)
00162       return(*this);
00163 
00164     NumRows_ = rhs.NumRows();
00165     NumVectors_ = rhs.NumVectors();
00166     IsComputed_ = rhs.IsComputed();
00167     KeepNonFactoredMatrix_ = rhs.KeepNonFactoredMatrix();
00168     Matrix_ = rhs.Matrix();
00169     if (KeepNonFactoredMatrix_)
00170       NonFactoredMatrix_ = rhs.NonFactoredMatrix();
00171     LHS_ = rhs.LHS();
00172     RHS_ = rhs.RHS();
00173     ID_ = rhs.ID();
00174 
00175     return(*this);
00176   }
00177 
00179 
00181 
00183   virtual int NumRows() const;
00184 
00186   virtual int NumVectors() const
00187   {
00188     return(NumVectors_);
00189   }
00190 
00192   virtual int SetNumVectors(const int NumVectors_in)
00193   {
00194     if (NumVectors_ == NumVectors_in) 
00195       return(0);
00196 
00197     NumVectors_ = NumVectors_in;
00198     IFPACK_CHK_ERR(RHS_.Reshape(NumRows_,NumVectors_));
00199     IFPACK_CHK_ERR(LHS_.Reshape(NumRows_,NumVectors_));
00200     // zero out vector elements
00201     for (int i = 0 ; i < NumRows_ ; ++i)
00202       for (int j = 0 ; j < NumVectors_ ; ++j) {
00203     LHS_(i,j) = 0.0;
00204     RHS_(i,j) = 0.0;
00205       }
00206      if (NumRows_!=0)
00207        {
00208        IFPACK_CHK_ERR(Solver_.SetVectors(LHS_,RHS_));
00209        }
00210     return(0);
00211   }
00212 
00214   virtual double& LHS(const int i, const int Vector = 0);
00215   
00217   virtual double& RHS(const int i, const int Vector = 0);
00218 
00220 
00229   virtual int& ID(const int i);
00230 
00232   virtual int SetMatrixElement(const int row, const int col,
00233                    const double value);
00234 
00236   virtual int SetParameters(Teuchos::ParameterList& List)
00237   {
00238     return(0);
00239   }
00240 
00242   virtual bool IsInitialized() const
00243   {
00244     return(IsInitialized_);
00245   }
00246 
00248   virtual bool IsComputed() const
00249   {
00250     return(IsComputed_);
00251   }
00252 
00254   virtual const char* Label() const
00255   {
00256     return(Label_.c_str());
00257   }
00258 
00260   virtual int SetKeepNonFactoredMatrix(const bool flag)
00261   {
00262     KeepNonFactoredMatrix_ = flag;
00263     return(0);
00264   }
00265 
00267   virtual bool KeepNonFactoredMatrix() const
00268   {
00269     return(KeepNonFactoredMatrix_);
00270   }
00271 
00273   virtual const Epetra_SerialDenseMatrix& LHS() const
00274   {
00275     return(LHS_);
00276   }
00277 
00279   virtual const Epetra_SerialDenseMatrix& RHS() const
00280   {
00281     return(RHS_);
00282   }
00283 
00285   virtual const Epetra_SerialDenseMatrix& Matrix() const
00286   {
00287     return(Matrix_);
00288   }
00289 
00291   virtual const Epetra_SerialDenseMatrix& NonFactoredMatrix() const
00292   {
00293     return(NonFactoredMatrix_);
00294   }
00295 
00297   virtual const Epetra_IntSerialDenseVector& ID() const
00298   {
00299     return(ID_);
00300   }
00301 
00303 
00305 
00306   virtual int Initialize();
00307 
00309   virtual int Compute(const Epetra_RowMatrix& Matrix_in);
00310 
00312   virtual int Apply();
00313 
00315   virtual int ApplyInverse();
00316 
00318 
00319   virtual double InitializeFlops() const
00320   {
00321     return(0.0);
00322   }
00323 
00324   virtual double ComputeFlops() const
00325   {
00326     return(ComputeFlops_);
00327   }
00328 
00329   virtual double ApplyFlops() const
00330   {
00331     return(ApplyFlops_);
00332   }
00333 
00334   virtual double ApplyInverseFlops() const
00335   {
00336     return(ApplyInverseFlops_);
00337   }
00338 
00340   virtual ostream& Print(std::ostream& os) const;
00341 
00342 private:
00343   
00345   virtual int Extract(const Epetra_RowMatrix& Matrix_in);
00346 
00348   int NumRows_; 
00350   int NumVectors_;
00352   Epetra_SerialDenseMatrix NonFactoredMatrix_;
00354   Epetra_SerialDenseMatrix Matrix_;
00356   Epetra_SerialDenseMatrix LHS_;
00358   Epetra_SerialDenseMatrix RHS_;
00360   Epetra_SerialDenseSolver Solver_;
00362   Epetra_IntSerialDenseVector ID_;
00364   bool KeepNonFactoredMatrix_;
00366   bool IsInitialized_;
00368   bool IsComputed_;
00370   string Label_;
00371 
00373   double ComputeFlops_;
00375   double ApplyFlops_;
00377   double ApplyInverseFlops_;
00378 };
00379 
00380 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends