ShyLU  Version of the Day
shylu_amesos_schur_operator.cpp
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // ShyLU: Hybrid preconditioner package
6 // Copyright 2012 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 
51 #include "shylu_amesos_schur_operator.h"
52 
54  A_(A),
55  IsParallel_(true),
56  IsInitialized_(false),
57  IsComputed_(false),
58  Label_(),
59  NumApplyInverse_(0),
60  Time_(A_->Comm())
61 {
62 }
63 
64 void AmesosSchurOperator::Destroy()
65 {
66  if (IsInitialized_)
67  {
68  }
69  if (IsComputed_)
70  {
71  }
72 }
73 
75 {
76  if(Comm().NumProc() != 1)
77  IsParallel_ = true;
78  else
79  IsParallel_ = false;
80 
81  LP_ = Teuchos::RCP<Epetra_LinearProblem> (new Epetra_LinearProblem());
82  Amesos Factory;
83  const char* SolverType = "Amesos_Klu";
84  // mfh 25 May 2015: Remember that in a release build (NDEBUG not
85  // defined), assert() gets defined to nothing. This results in an
86  // unused variable warning for IsAvailable. I've rewritten the
87  // code so that in a release build, the query result is ignored.
88  // This is still a bad idea -- inexpensive error checks in
89  // non-performance-critical code should stay in a release build --
90  // but it's not my place to rewrite this code that I didn't write.
91 #ifdef NDEBUG
92  (void) Factory.Query(SolverType);
93 #else
94  bool IsAvailable = Factory.Query(SolverType);
95  assert(IsAvailable == true);
96 #endif // NDEBUG
97  Solver_ = Teuchos::RCP<Amesos_BaseSolver> (Factory.Create(SolverType,
98  *LP_));
99 
101  aList.set("Reindex", true);
102 
103  LP_->SetOperator(A_);
104  Solver_->SetParameters(aList);
105  LP_->SetLHS(0); LP_->SetRHS(0);
106 
107  Solver_->SymbolicFactorization();
108 
109  IsInitialized_ = true;
110  return 0;
111 }
112 
114 {
115  List_ = parameterlist;
116  return 0;
117 }
118 
120 {
121  IsComputed_ = true;
122  Solver_->NumericFactorization();
123  return 0;
124 }
125 
126 int AmesosSchurOperator::ApplyInverse(const Epetra_MultiVector& X,
127  Epetra_MultiVector& Y) const
128 {
129  NumApplyInverse_++;
130  LP_->SetRHS(const_cast<Epetra_MultiVector *>(&X));
131  LP_->SetLHS(&Y);
132  Solver_->Solve();
133  return 0;
134 }
135 
137 ostream& AmesosSchurOperator::Print(ostream& os) const
138 {
139  os << " !!!!!!!!! " << endl;
140  return os;
141 }
virtual ostream & Print(ostream &os) const
Prints on stream basic information about this object.
int Compute()
Compute ILU factors L and U using the specified parameters.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
AmesosSchurOperator(Epetra_CrsMatrix *A)
Constructor.
int Initialize()
Initialize the preconditioner, does not touch matrix values.
int SetParameters(Teuchos::ParameterList &parameterlist)
Set parameters using a Teuchos::ParameterList object.
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.