Epetra Package Browser (Single Doxygen Collection) Development
Epetra_LinearProblem.cpp
Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 
00043 #include "Epetra_LinearProblem.h"
00044 #include "Epetra_MultiVector.h"
00045 #include "Epetra_Vector.h"
00046 #include "Epetra_Map.h"
00047 
00048 
00049 //=============================================================================
00050 Epetra_LinearProblem::Epetra_LinearProblem(void) 
00051   : Operator_(0),
00052     A_(0),
00053     X_(0),
00054     B_(0),
00055     OperatorSymmetric_(false),
00056     PDL_(unsure),
00057     LeftScaled_(false),
00058     RightScaled_(false),
00059     LeftScaleVector_(0),
00060     RightScaleVector_(0)
00061 {
00062 }
00063 //=============================================================================
00064 Epetra_LinearProblem::Epetra_LinearProblem(Epetra_RowMatrix * A, 
00065                  Epetra_MultiVector * X,
00066                  Epetra_MultiVector * B) 
00067   : Operator_(0),
00068     A_(A),
00069     X_(X),
00070     B_(B),
00071     OperatorSymmetric_(false),
00072     PDL_(unsure),
00073     LeftScaled_(false),
00074     RightScaled_(false),
00075     LeftScaleVector_(0),
00076     RightScaleVector_(0)
00077 {
00078   Operator_ = dynamic_cast<Epetra_Operator *>(A_); // Try to make matrix an operator
00079 }
00080 //=============================================================================
00081 Epetra_LinearProblem::Epetra_LinearProblem(Epetra_Operator * A, 
00082                  Epetra_MultiVector * X,
00083                  Epetra_MultiVector * B) 
00084   : Operator_(A),
00085     A_(0),
00086     X_(X),
00087     B_(B),
00088     OperatorSymmetric_(false),
00089     PDL_(unsure),
00090     LeftScaled_(false),
00091     RightScaled_(false),
00092     LeftScaleVector_(0),
00093     RightScaleVector_(0)
00094 {
00095   A_ = dynamic_cast<Epetra_RowMatrix *>(Operator_); // Try to make operator a matrix
00096 }
00097 //=============================================================================
00098 Epetra_LinearProblem::Epetra_LinearProblem(const Epetra_LinearProblem& Problem) 
00099   : Operator_(Problem.Operator_),
00100     A_(Problem.A_),
00101     X_(Problem.X_),
00102     B_(Problem.B_),
00103     OperatorSymmetric_(Problem.OperatorSymmetric_),
00104     PDL_(Problem.PDL_),
00105     LeftScaled_(Problem.LeftScaled_),
00106     RightScaled_(Problem.RightScaled_),
00107     LeftScaleVector_(Problem.LeftScaleVector_),
00108     RightScaleVector_(Problem.RightScaleVector_)
00109 {
00110 }
00111 //=============================================================================
00112 Epetra_LinearProblem::~Epetra_LinearProblem(void)  
00113 {
00114 }
00115 //=============================================================================
00116 int Epetra_LinearProblem::LeftScale(const Epetra_Vector & D)
00117 {
00118   if (A_==0) EPETRA_CHK_ERR(-1); // No matrix defined
00119   if (B_==0) EPETRA_CHK_ERR(-2); // No RHS defined
00120   if (A_->UseTranspose()) {
00121     EPETRA_CHK_ERR(A_->RightScale(D));
00122     EPETRA_CHK_ERR(X_->ReciprocalMultiply(1.0, D, *X_, 0.0));
00123   }
00124   else {
00125     EPETRA_CHK_ERR(A_->LeftScale(D));
00126     EPETRA_CHK_ERR(B_->Multiply(1.0, D, *B_, 0.0));
00127   }
00128 
00129   return(0);
00130 }
00131 //=============================================================================
00132 int Epetra_LinearProblem::RightScale(const Epetra_Vector & D)
00133 {
00134   if (A_==0) EPETRA_CHK_ERR(-1); // No matrix defined
00135   if (X_==0) EPETRA_CHK_ERR(-2); // No LHS defined
00136   if (A_->UseTranspose()) {
00137     EPETRA_CHK_ERR(A_->LeftScale(D));
00138     EPETRA_CHK_ERR(B_->Multiply(1.0, D, *B_, 0.0));
00139   }
00140   else {
00141     EPETRA_CHK_ERR(A_->RightScale(D));
00142     EPETRA_CHK_ERR(X_->ReciprocalMultiply(1.0, D, *X_, 0.0));
00143   }
00144   return(0);
00145 }
00146 //=============================================================================
00147 int Epetra_LinearProblem::CheckInput() const {
00148   int ierr = 0;
00149   if (Operator_==0) ierr = -1;
00150   if (X_==0) ierr = -2;
00151   if (B_==0) ierr = -3;
00152 
00153   EPETRA_CHK_ERR(ierr);  // Return now if any essential objects missing
00154 
00155   if (A_==0) EPETRA_CHK_ERR(1); // Return warning error because this problem has no matrix (just an operator)
00156 
00157   if (!A_->OperatorDomainMap().SameAs(X_->Map())) ierr = -4;
00158   if (!A_->OperatorRangeMap().SameAs(B_->Map())) ierr = -5;
00159 
00160   EPETRA_CHK_ERR(ierr);
00161   return(0);
00162 
00163 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines