Epetra_LinearProblem.cpp

Go to the documentation of this file.
```00001
00003 // ************************************************************************
00004 //
00005 //               Epetra: Linear Algebra Services Package
00006 //                 Copyright (2001) Sandia Corporation
00007 //
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 //
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00015 //
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00026 //
00027 // ************************************************************************
00029
00030 #include "Epetra_LinearProblem.h"
00031 #include "Epetra_MultiVector.h"
00032 #include "Epetra_Vector.h"
00033 #include "Epetra_Map.h"
00034
00035
00036 //=============================================================================
00037 Epetra_LinearProblem::Epetra_LinearProblem(void)
00038   : Operator_(0),
00039     A_(0),
00040     X_(0),
00041     B_(0),
00042     OperatorSymmetric_(false),
00043     PDL_(unsure),
00044     LeftScaled_(false),
00045     RightScaled_(false),
00046     LeftScaleVector_(0),
00047     RightScaleVector_(0)
00048 {
00049 }
00050 //=============================================================================
00051 Epetra_LinearProblem::Epetra_LinearProblem(Epetra_RowMatrix * A,
00052                  Epetra_MultiVector * X,
00053                  Epetra_MultiVector * B)
00054   : Operator_(0),
00055     A_(A),
00056     X_(X),
00057     B_(B),
00058     OperatorSymmetric_(false),
00059     PDL_(unsure),
00060     LeftScaled_(false),
00061     RightScaled_(false),
00062     LeftScaleVector_(0),
00063     RightScaleVector_(0)
00064 {
00065   Operator_ = dynamic_cast<Epetra_Operator *>(A_); // Try to make matrix an operator
00066 }
00067 //=============================================================================
00068 Epetra_LinearProblem::Epetra_LinearProblem(Epetra_Operator * A,
00069                  Epetra_MultiVector * X,
00070                  Epetra_MultiVector * B)
00071   : Operator_(A),
00072     A_(0),
00073     X_(X),
00074     B_(B),
00075     OperatorSymmetric_(false),
00076     PDL_(unsure),
00077     LeftScaled_(false),
00078     RightScaled_(false),
00079     LeftScaleVector_(0),
00080     RightScaleVector_(0)
00081 {
00082   A_ = dynamic_cast<Epetra_RowMatrix *>(Operator_); // Try to make operator a matrix
00083 }
00084 //=============================================================================
00085 Epetra_LinearProblem::Epetra_LinearProblem(const Epetra_LinearProblem& Problem)
00086   : Operator_(Problem.Operator_),
00087     A_(Problem.A_),
00088     X_(Problem.X_),
00089     B_(Problem.B_),
00090     OperatorSymmetric_(Problem.OperatorSymmetric_),
00091     PDL_(Problem.PDL_),
00092     LeftScaled_(Problem.LeftScaled_),
00093     RightScaled_(Problem.RightScaled_),
00094     LeftScaleVector_(Problem.LeftScaleVector_),
00095     RightScaleVector_(Problem.RightScaleVector_)
00096 {
00097 }
00098 //=============================================================================
00099 Epetra_LinearProblem::~Epetra_LinearProblem(void)
00100 {
00101 }
00102 //=============================================================================
00103 int Epetra_LinearProblem::LeftScale(const Epetra_Vector & D)
00104 {
00105   if (A_==0) EPETRA_CHK_ERR(-1); // No matrix defined
00106   if (B_==0) EPETRA_CHK_ERR(-2); // No RHS defined
00107   if (A_->UseTranspose()) {
00108     EPETRA_CHK_ERR(A_->RightScale(D));
00109     EPETRA_CHK_ERR(X_->ReciprocalMultiply(1.0, D, *X_, 0.0));
00110   }
00111   else {
00112     EPETRA_CHK_ERR(A_->LeftScale(D));
00113     EPETRA_CHK_ERR(B_->Multiply(1.0, D, *B_, 0.0));
00114   }
00115
00116   return(0);
00117 }
00118 //=============================================================================
00119 int Epetra_LinearProblem::RightScale(const Epetra_Vector & D)
00120 {
00121   if (A_==0) EPETRA_CHK_ERR(-1); // No matrix defined
00122   if (X_==0) EPETRA_CHK_ERR(-2); // No LHS defined
00123   if (A_->UseTranspose()) {
00124     EPETRA_CHK_ERR(A_->LeftScale(D));
00125     EPETRA_CHK_ERR(B_->Multiply(1.0, D, *B_, 0.0));
00126   }
00127   else {
00128     EPETRA_CHK_ERR(A_->RightScale(D));
00129     EPETRA_CHK_ERR(X_->ReciprocalMultiply(1.0, D, *X_, 0.0));
00130   }
00131   return(0);
00132 }
00133 //=============================================================================
00134 int Epetra_LinearProblem::CheckInput() const {
00135   int ierr = 0;
00136   if (Operator_==0) ierr = -1;
00137   if (X_==0) ierr = -2;
00138   if (B_==0) ierr = -3;
00139
00140   EPETRA_CHK_ERR(ierr);  // Return now if any essential objects missing
00141
00142   if (A_==0) EPETRA_CHK_ERR(1); // Return warning error because this problem has no matrix (just an operator)
00143
00144   if (!A_->OperatorDomainMap().SameAs(X_->Map())) ierr = -4;
00145   if (!A_->OperatorRangeMap().SameAs(B_->Map())) ierr = -5;
00146
00147   EPETRA_CHK_ERR(ierr);
00148   return(0);
00149
00150 }
```

Generated on Thu Sep 18 12:37:57 2008 for Epetra Package Browser (Single Doxygen Collection) by  1.3.9.1