LifeV
SolverOperator.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 SolverOperator
30 
31  @author Umberto Villa <umberto.villa@gmail.com>
32  @contributor Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33 
34  @date 03-09-2010
35  */
36 
37 #include <lifev/core/operator/SolverOperator.hpp>
38 
39 #include <Teuchos_RCPBoostSharedPtrConversions.hpp>
40 
41 namespace LifeV
42 {
43 
44 namespace Operators
45 {
46 
47 SolverOperator::SolverOperator ( std::shared_ptr<Epetra_Comm> comm ) :
48  M_name ( "SolverOperator" ),
49  M_useTranspose ( false ),
52  M_numIterations ( 0 ),
54  M_tolerance ( -1. ),
55  M_printSubiterationCount ( false ),
56  M_comm ( comm )
57 { }
58 
60 {
61  M_prec.reset();
62  M_oper.reset();
63 }
64 
65 int SolverOperator::SetUseTranspose ( bool useTranspose )
66 {
67  M_useTranspose = useTranspose;
68 
69  int ierr ( 0 );
70  if ( M_useTranspose )
71  {
72  ierr = -1;
73  }
74 
75  return ierr;
76 }
77 
79 {
80  ASSERT_PRE ( _oper.get() != this, "Can't self assign" );
81  ASSERT_PRE ( _oper.get() != 0, "Can't assign a null pointer" );
82  M_oper = _oper;
84 }
85 
87 {
88  ASSERT_PRE ( _prec.get() != this, "Self Assignment is forbidden" );
89  ASSERT_PRE ( _prec.get() != 0, "Can't assign a null pointer" );
90  M_prec = _prec;
92 }
93 
94 void SolverOperator::setParameters ( const Teuchos::ParameterList& _pList )
95 {
96  M_pList = Teuchos::rcp ( new Teuchos::ParameterList ( _pList ), true );
98 }
99 
100 void SolverOperator::setTolerance ( const Real& tolerance )
101 {
102  M_tolerance = tolerance;
103 }
104 
105 void SolverOperator::setUsedForPreconditioning ( const bool& enable )
106 {
107  M_printSubiterationCount = enable;
108 }
109 
111 {
113  M_prec.reset();
114  M_oper.reset();
115 }
116 
117 int SolverOperator::Apply ( const vector_Type& X, vector_Type& Y ) const
118 {
119  ASSERT_PRE ( X.Map().SameAs ( M_oper->OperatorDomainMap() ), "X and domain map do no coincide \n" );
120  ASSERT_PRE ( Y.Map().SameAs ( M_oper->OperatorRangeMap() ) , "Y and range map do no coincide \n" );
121 
122  return M_oper->Apply ( X, Y );
123 }
124 
126 {
127  ASSERT_PRE ( Y.Map().SameAs ( M_oper->OperatorDomainMap() ), "Y and domain map do no coincide \n" );
128  ASSERT_PRE ( X.Map().SameAs ( M_oper->OperatorRangeMap() ) , "X and range map do no coincide \n" );
129 
130  if ( M_useTranspose )
131  {
132  return -1;
133  }
134  int result = doApplyInverse ( X, Y );
135 
137 
138  if ( M_comm->MyPID() == 0 && M_printSubiterationCount )
139  {
140  std::cout << "> " << numIterations() << " subiterations" << std::endl;
141  }
142 
143  return result;
144 }
145 
146 } // Namespace Operators
147 
148 } // Namespace LifeV
virtual int ApplyInverse(const vector_Type &X, vector_Type &Y) const
Returns the result of a Epetra_Operator inverse applied to an vector_Type X in Y. ...
void setTolerance(const Real &tolerance)
SolverOperatorStatusType M_lossOfAccuracy
Status to see if there is a loss of accuracy.
virtual void doSetParameterList()=0
SolverOperator(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
virtual int Apply(const vector_Type &X, vector_Type &Y) const
Returns the result of a Epetra_Operator applied to a vector_Type X in Y.
void updateInverseJacobian(const UInt &iQuadPt)
SolverOperatorStatusType M_converged
Status to see if the solver has converged.
void setPreconditioner(operatorPtr_Type _prec)
#define ASSERT_PRE(X, A)
Definition: LifeAssert.hpp:96
operatorPtr_Type M_oper
The operator to be solved.
void setUsedForPreconditioning(const bool &enable)
bool M_printSubiterationCount
Print the number of iteration (used only for preconditioner LinearSolver)
void setOperator(operatorPtr_Type _oper)
double Real
Generic real data.
Definition: LifeV.hpp:175
virtual void doSetPreconditioner()=0
operatorPtr_Type M_prec
The preconditioner operator.
std::shared_ptr< operator_Type > operatorPtr_Type
virtual int SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
bool M_useTranspose
Whenever to use the transpose.
Real M_tolerance
Solver tolerance.
int M_numCumulIterations
Number of cumulated iterations performed by the solver.
virtual int doApplyInverse(const vector_Type &X, vector_Type &Y) const =0
void setParameters(const Teuchos::ParameterList &_pList)
int M_numIterations
Number of iterations performed by the solver.