LifeV
SolverOperatorAlgo.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/SolverOperatorAlgo.hpp>
38 
39 #include <Teuchos_RCPBoostSharedPtrConversions.hpp>
40 
41 namespace LifeV
42 {
43 
44 namespace Operators
45 {
46 
47 SolverOperatorAlgo::SolverOperatorAlgo ( boost::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 SolverOperatorAlgo::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 SolverOperatorAlgo::setParameters ( const Teuchos::ParameterList& _pList )
95 {
96  M_pList = Teuchos::rcp ( new Teuchos::ParameterList ( _pList ), true );
98 }
99 
100 void SolverOperatorAlgo::setTolerance ( const Real& tolerance )
101 {
102  M_tolerance = tolerance;
103 }
104 
105 void SolverOperatorAlgo::setUsedForPreconditioning ( const bool& enable )
106 {
107  M_printSubiterationCount = enable;
108 }
109 
111 {
113  M_prec.reset();
114  M_oper.reset();
115 }
116 
117 int SolverOperatorAlgo::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 SetUseTranspose(bool useTranspose)
If set true, transpose of this operator will be applied.
operatorPtr_Type M_prec
The preconditioner operator.
void setOperator(operatorPtr_Type _oper)
bool M_printSubiterationCount
Print the number of iteration (used only for preconditioner LinearSolver)
void updateInverseJacobian(const UInt &iQuadPt)
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. ...
bool M_useTranspose
Whenever to use the transpose.
void setTolerance(const Real &tolerance)
#define ASSERT_PRE(X, A)
Definition: LifeAssert.hpp:96
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.
int M_numIterations
Number of iterations performed by the solver.
void setUsedForPreconditioning(const bool &enable)
double Real
Generic real data.
Definition: LifeV.hpp:175
SolverOperatorAlgo(boost::shared_ptr< Epetra_Comm > comm=boost::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
std::shared_ptr< operator_Type > operatorPtr_Type
void setPreconditioner(operatorPtr_Type _prec)
operatorPtr_Type M_oper
The operator to be solved.
SolverOperatorStatusType M_converged
Status to see if the solver has converged.
SolverOperatorStatusType M_lossOfAccuracy
Status to see if there is a loss of accuracy.
void setParameters(const Teuchos::ParameterList &_pList)
virtual int doApplyInverse(const vector_Type &X, vector_Type &Y) const =0
int M_numCumulIterations
Number of cumulated iterations performed by the solver.