LifeV
PreconditionerComposition.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 ************************************************************************
4 
5  This file is part of the LifeV Applications.
6  Copyright (C) 2001-2010 EPFL, Politecnico di Milano, INRIA
7 
8  This library is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as
10  published by the Free Software Foundation; either version 2.1 of the
11  License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  USA
22 
23 ************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief This file contains the PreconditionerComposition class.
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @date 30-11-2010
33 
34  The class provides an efficient way of dealing with preconditioner
35  composed as a multiplication of matrices.
36  */
37 
38 #include <lifev/core/algorithm/PreconditionerComposition.hpp>
39 #include <lifev/core/operator/ConfinedOperator.hpp>
40 
41 // <--Check for necessity
42 #include <Ifpack_config.h>
43 #include <Ifpack.h>
44 #include <Ifpack_Preconditioner.h>
45 #include <ml_MultiLevelPreconditioner.h>
46 #include <Ifpack_AdditiveSchwarz.h>
47 #include <Ifpack_Amesos.h>
48 #include <Ifpack_ILU.h>
49 
50 namespace LifeV
51 {
52 
53 // ===================================================
54 // Constructors & Destructor
55 // ===================================================
56 
57 PreconditionerComposition::PreconditionerComposition ( std::shared_ptr<Epetra_Comm> comm ) :
58  super_Type ( comm ),
59  M_comm ( comm ),
60  M_prec ( new prec_Type ( comm ) )
61 {
62 
63 }
64 
68  M_prec ( new prec_Type ( * ( precComp.M_prec.get() ) ) )
69 {
70 
71 }
72 
74 {
75  M_prec.reset();
76  M_precBaseOperators.clear();
77 }
78 
79 // ===================================================
80 // Methods
81 // ===================================================
82 
83 void
85 {
86  M_prec.reset ( new prec_Type ( M_comm ) );
87  M_precBaseOperators.clear();
88  this->M_preconditionerCreated = false;
89 }
90 
91 Real
93 {
94  // todo Is there a way to obtain condest?
95  //return M_prec->Condest();
96  return 0.0;
97 }
98 
99 // ===================================================
100 // Epetra Operator Interface Methods
101 // ===================================================
102 int
103 PreconditionerComposition::SetUseTranspose ( const bool useTranspose )
104 {
105  return M_prec->SetUseTranspose ( useTranspose );
106 }
107 
108 int
109 PreconditionerComposition::Apply ( const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const
110 {
111  return M_prec->Apply ( X, Y );
112 }
113 
114 int
115 PreconditionerComposition::ApplyInverse ( const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const
116 {
117  return M_prec->ApplyInverse ( X, Y );
118 }
119 
120 bool
122 {
123  return M_prec->UseTranspose();
124 }
125 
126 const Epetra_Map&
128 {
129  return M_prec->OperatorRangeMap();
130 }
131 
132 const Epetra_Map&
134 {
135  return M_prec->OperatorDomainMap();
136 }
137 
138 // ===================================================
139 // Set Methods
140 // ===================================================
141 void
143 {
144  M_comm = comm;
145  M_prec->setComm ( comm );
146 }
147 
148 // ===================================================
149 // Get Methods
150 // ===================================================
151 bool
153 {
154  return M_prec != nullptr ? true : false;
155 }
156 
159 {
160  return M_prec.get();
161 }
162 
165 {
166  return M_prec;
167 }
168 
169 std::string
171 {
172  return M_precType;
173 }
174 
175 UInt
177 {
178  return M_prec->number();
179 }
180 
181 // ===================================================
182 // Protected Methods
183 // ===================================================
184 int
186  const bool useInverse,
187  const bool useTranspose )
188 {
189  //std::cout << "[DEBUG] pushBack() matrix version" << std::endl;
191 
192  return EXIT_SUCCESS;
193 }
194 
195 int
197  const bool useInverse,
198  const bool useTranspose,
200 {
201  if ( baseMatrix.get() != 0 )
202  {
204  }
206 
207  return EXIT_SUCCESS;
208 }
209 
210 int
213  const bool useInverse,
214  const bool useTranspose )
215 {
216  //std::cout << "[DEBUG] pushBack() preconditioner version" << std::endl;
221 
222  return EXIT_SUCCESS;
223 }
224 
225 int
229  const UInt& blockIndex,
230  const MapEpetra& fullMap,
231  const bool useInverse,
232  const bool useTranspose,
233  const bool buildPreconditioner )
234 {
235  // Add the operator
237 
238  // Build the preconditioner
239  if ( buildPreconditioner )
240  {
242  }
244 
245  // Wrap the preconditioner in a ConfinedOperator
252 
253  // Add the operator
255 
256  return EXIT_SUCCESS;
257 }
258 
259 int
262  const UInt& blockIndex,
263  const MapEpetra& fullMap,
264  const bool useInverse,
265  const bool useTranspose )
266 {
267  // Wrap the preconditioner in a ConfinedOperator
274 
275  // Add the operator
277 
278  return EXIT_SUCCESS;
279 }
280 
281 } // Namespace LifeV
Int SetUseTranspose(const bool useTranspose=false)
Set the matrix to be used transposed (or not)
void resetPreconditioner()
Reset the preconditioner.
Int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Apply the inverse of the preconditioner on vector1 and store the result in vector2.
void updateInverseJacobian(const UInt &iQuadPt)
const Epetra_Map & OperatorRangeMap() const
Return the Range map of the operator.
Real condest()
Return an estimation of the conditionement number of the preconditioner.
PreconditionerComposition(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
Constructor.
bool UseTranspose()
Return true if the preconditioner is transposed.
double Real
Generic real data.
Definition: LifeV.hpp:175
const Epetra_Map & OperatorDomainMap() const
Return the Domain map of the operator.
PreconditionerComposition(const PreconditionerComposition &precComp)
Copy constructor.
Int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Apply the inverse of the preconditioner on vector1 and store the result in vector2.