Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_LinearProblem.cpp
Go to the documentation of this file.
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
43 #include "Epetra_LinearProblem.h"
44 #include "Epetra_MultiVector.h"
45 #include "Epetra_Vector.h"
46 #include "Epetra_Map.h"
47 
48 
49 //=============================================================================
51  : Operator_(0),
52  A_(0),
53  X_(0),
54  B_(0),
55  OperatorSymmetric_(false),
56  PDL_(unsure),
57  LeftScaled_(false),
58  RightScaled_(false),
59  LeftScaleVector_(0),
60  RightScaleVector_(0)
61 {
62 }
63 //=============================================================================
67  : Operator_(0),
68  A_(A),
69  X_(X),
70  B_(B),
71  OperatorSymmetric_(false),
72  PDL_(unsure),
73  LeftScaled_(false),
74  RightScaled_(false),
75  LeftScaleVector_(0),
76  RightScaleVector_(0)
77 {
78  Operator_ = dynamic_cast<Epetra_Operator *>(A_); // Try to make matrix an operator
79 }
80 //=============================================================================
84  : Operator_(A),
85  A_(0),
86  X_(X),
87  B_(B),
88  OperatorSymmetric_(false),
89  PDL_(unsure),
90  LeftScaled_(false),
91  RightScaled_(false),
92  LeftScaleVector_(0),
93  RightScaleVector_(0)
94 {
95  A_ = dynamic_cast<Epetra_RowMatrix *>(Operator_); // Try to make operator a matrix
96 }
97 //=============================================================================
99  : Operator_(Problem.Operator_),
100  A_(Problem.A_),
101  X_(Problem.X_),
102  B_(Problem.B_),
103  OperatorSymmetric_(Problem.OperatorSymmetric_),
104  PDL_(Problem.PDL_),
105  LeftScaled_(Problem.LeftScaled_),
106  RightScaled_(Problem.RightScaled_),
107  LeftScaleVector_(Problem.LeftScaleVector_),
108  RightScaleVector_(Problem.RightScaleVector_)
109 {
110 }
111 //=============================================================================
113 {
114 }
115 //=============================================================================
117 {
118  if (A_==0) EPETRA_CHK_ERR(-1); // No matrix defined
119  if (B_==0) EPETRA_CHK_ERR(-2); // No RHS defined
120  if (A_->UseTranspose()) {
122  EPETRA_CHK_ERR(X_->ReciprocalMultiply(1.0, D, *X_, 0.0));
123  }
124  else {
126  EPETRA_CHK_ERR(B_->Multiply(1.0, D, *B_, 0.0));
127  }
128 
129  return(0);
130 }
131 //=============================================================================
133 {
134  if (A_==0) EPETRA_CHK_ERR(-1); // No matrix defined
135  if (X_==0) EPETRA_CHK_ERR(-2); // No LHS defined
136  if (A_->UseTranspose()) {
138  EPETRA_CHK_ERR(B_->Multiply(1.0, D, *B_, 0.0));
139  }
140  else {
142  EPETRA_CHK_ERR(X_->ReciprocalMultiply(1.0, D, *X_, 0.0));
143  }
144  return(0);
145 }
146 //=============================================================================
148  int ierr = 0;
149  if (Operator_==0) ierr = -1;
150  if (X_==0) ierr = -2;
151  if (B_==0) ierr = -3;
152 
153  EPETRA_CHK_ERR(ierr); // Return now if any essential objects missing
154 
155  if (A_==0) EPETRA_CHK_ERR(1); // Return warning error because this problem has no matrix (just an operator)
156 
157  if (!A_->OperatorDomainMap().SameAs(X_->Map())) ierr = -4;
158  if (!A_->OperatorRangeMap().SameAs(B_->Map())) ierr = -5;
159 
160  EPETRA_CHK_ERR(ierr);
161  return(0);
162 
163 }
Epetra_MultiVector: A class for constructing and using dense multi-vectors, vectors and matrices in p...
virtual int RightScale(const Epetra_Vector &x)=0
Scales the Epetra_RowMatrix on the right with a Epetra_Vector x.
Epetra_MultiVector * X_
int CheckInput() const
Check input parameters for existence and size consistency.
bool SameAs(const Epetra_BlockMap &Map) const
Returns true if this and Map are identical maps.
#define EPETRA_CHK_ERR(a)
virtual const Epetra_Map & OperatorDomainMap() const =0
Returns the Epetra_Map object associated with the domain of this operator.
Epetra_Vector: A class for constructing and using dense vectors on a parallel computer.
virtual int LeftScale(const Epetra_Vector &x)=0
Scales the Epetra_RowMatrix on the left with a Epetra_Vector x.
Epetra_MultiVector * B_
virtual const Epetra_Map & OperatorRangeMap() const =0
Returns the Epetra_Map object associated with the range of this operator.
virtual bool UseTranspose() const =0
Returns the current UseTranspose setting.
int LeftScale(const Epetra_Vector &D)
Perform left scaling of a linear problem.
Epetra_Operator * Operator_
Epetra_LinearProblem(void)
Epetra_LinearProblem Default Constructor.
int Multiply(char TransA, char TransB, double ScalarAB, const Epetra_MultiVector &A, const Epetra_MultiVector &B, double ScalarThis)
Matrix-Matrix multiplication, this = ScalarThis*this + ScalarAB*A*B.
Epetra_Operator: A pure virtual class for using real-valued double-precision operators.
Epetra_LinearProblem: The Epetra Linear Problem Class.
virtual ~Epetra_LinearProblem(void)
Epetra_LinearProblem Destructor.
Epetra_RowMatrix: A pure virtual class for using real-valued double-precision row matrices...
int RightScale(const Epetra_Vector &D)
Perform right scaling of a linear problem.
const Epetra_BlockMap & Map() const
Returns the address of the Epetra_BlockMap for this multi-vector.
int ReciprocalMultiply(double ScalarAB, const Epetra_MultiVector &A, const Epetra_MultiVector &B, double ScalarThis)
Multiply a Epetra_MultiVector by the reciprocal of another, element-by-element.