LifeV
AztecooOperator.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief AztecooOperator
30 
31  @author Umberto Villa <umberto.villa@gmail.com>
32 
33  @date 03-09-2010
34  */
35 
36 #include <lifev/core/operator/AztecooOperator.hpp>
37 
38 namespace LifeV
39 {
40 
41 namespace Operators
42 {
43 
46  M_linSolver ( new SolverType )
47 {
48  M_name = "AztecOOOperator";
49 }
50 
51 int
53 {
54  M_numIterations = 0;
55 
56  vector_Type Xcopy ( X );
57  Y.PutScalar ( 0.0 );
58  if ( M_tolerance > 0 )
59  {
60  M_pList->sublist ( "Trilinos: AztecOO List" ).set ( "tol", M_tolerance );
61  }
62  M_linSolver->SetParameters ( M_pList->sublist ( "Trilinos: AztecOO List" ) );
63  M_linSolver->SetRHS ( &Xcopy );
64  M_linSolver->SetLHS ( &Y );
65 
66  M_linSolver->SetUserOperator ( M_oper.get() );
67 
68  if ( M_prec.get() != 0 )
69  {
70  M_linSolver->SetPrecOperator ( (Epetra_Operator*) M_prec.get() );
71  }
72 
73  int maxIter ( M_pList->sublist ( "Trilinos: AztecOO List" ).get<int> ( "max_iter" ) );
74  double tol ( M_pList->sublist ( "Trilinos: AztecOO List" ).get<double> ( "tol" ) );
75 
76  // Solving the system
77  int retValue = M_linSolver->Iterate (maxIter, tol);
78 
79  /* try to solve again (reason may be:
80  -2 "Aztec status AZ_breakdown: numerical breakdown"
81  -3 "Aztec status AZ_loss: loss of precision"
82  -4 "Aztec status AZ_ill_cond: GMRES hessenberg ill-conditioned"
83  This method was used in the old AztecOO solver.
84  */
85  if ( retValue <= -2 )
86  {
87  M_numIterations += M_linSolver->NumIters();
88  retValue = M_linSolver->Iterate (maxIter, tol);
89  }
90 
91  // Update the number of performed iterations
92  M_numIterations += M_linSolver->NumIters();
93 
94  // Update of the status
95  Real status[AZ_STATUS_SIZE];
96  M_linSolver->GetAllAztecStatus ( status );
97 
98  if ( status[AZ_why] == AZ_normal )
99  {
100  M_converged = yes;
101  }
102  else
103  {
104  M_converged = no;
105  }
106 
107  if ( status[AZ_why] == AZ_loss )
108  {
110  }
111  else
112  {
114  }
115 
116  return retValue;
117 }
118 
119 void
121 {
122 
123 }
124 
125 void
127 {
128 
129 }
130 
131 void
133 {
134  M_linSolver->SetParameters ( M_pList->sublist ( "Trilinos: AztecOO List" ) );
135 }
136 
137 void
139 {
140  if ( M_linSolver )
141  {
142  M_linSolver->DestroyPreconditioner();
143  }
144 }
145 
146 } // Namespace Operators
147 
148 } // Namespace LifeV
SolverOperatorStatusType M_lossOfAccuracy
Status to see if there is a loss of accuracy.
SolverOperator(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
void updateInverseJacobian(const UInt &iQuadPt)
SolverOperatorStatusType M_converged
Status to see if the solver has converged.
Abstract class which defines the interface of an Invertible Linear Operator.
Real M_tolerance
Solver tolerance.
virtual int doApplyInverse(const vector_Type &X, vector_Type &Y) const
int M_numIterations
Number of iterations performed by the solver.