LifeV
PreconditionerComposed.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 
26 #include <lifev/core/algorithm/PreconditionerComposed.hpp>
27 
28 namespace LifeV
29 {
30 
31 // ===================================================
32 // Constructurs and Destructor
33 // ===================================================
34 PreconditionerComposed::PreconditionerComposed ( std::shared_ptr<Epetra_Comm> comm) :
35  super_Type (comm ),
36  M_operVector (0),
37  M_prec (new prec_Type (comm) )
38  //M_precType()
39 {
40 }
41 
42 /*
43 PreconditionerComposed::PreconditionerComposed(PreconditionerComposed& P):
44  super_Type(P, std::dynamic_pointer_cast<ComposedOperator<Ifpack_Preconditioner> >(P.preconditionerPtr())->commPtr()),
45  M_operVector(P.operVector()),
46  M_prec(new prec_Type(*std::dynamic_pointer_cast<prec_Type>(P.preconditionerPtr())))
47  //M_precType(P.preconditionerType())
48 {
49  // *M_prec=*P.preconditioner();
50 }
51 */
52 
54 {
55  M_prec.reset();
56  M_operVector.clear();
57 }
58 
59 
60 // ===================================================
61 // Public Methods
62 // ===================================================
63 void
65  const std::string& section )
66 {
67  myCreateParametersList (dataFile, section, "Composed" );
68 }
69 
70 void
72  const GetPot& dataFile,
73  const std::string& section,
74  const std::string& subSection )
75 {
76  myCreateParametersList (dataFile,section,subSection);
77 }
78 
80  const std::string& section,
81  const std::string& subSection)
82 {
83  //! See http://trilinos.sandia.gov/packages/docs/r9.0/packages/ifpack/doc/html/index.html
84  //! for more informations on the parameters
85  ASSERT ( !M_prec->number(), "Error, when initializing the preconditioner, it must be empty" );
86  for ( UInt i (0); i < dataFile.vector_variable_size ( ( section + "/" + subSection + "/list" ).data() ); ++i )
87  {
88  epetraPrecPtr_Type tmp ( PRECFactory::instance().createObject ( dataFile ( ( section + "/" + subSection + "/list" ).data(), "ML", i ) ) );
89  M_prec->push_back (tmp);
90  M_prec->OperatorView() [i]->createParametersList (M_prec->OperatorView() [i]->parametersList(), dataFile, section, dataFile ( ( section + "/" + subSection + "/sections" ).data(), "ML", i ) );
91  }
92 }
93 
94 double
96 {
97  return M_prec->Condest();
98 }
99 
102 {
103  return M_prec.get();
104 }
105 
106 int
108 {
109  //M_prec.reset(new prec_raw_type(M_displayer.comm()));
110  return push_back (oper);
111 }
112 
113 int
115  const bool useInverse,
116  const bool useTranspose)
117 {
118  //M_prec.reset(new prec_raw_type(M_displayer.comm()));
119  return push_back (oper, useInverse, useTranspose);
120 }
121 
122 int
124  const bool useInverse,
125  const bool useTranspose
126  )
127 {
128  if (!M_prec.get() )
129  {
130  M_prec.reset (new prec_Type (M_displayer.comm() ) );
131  }
132  M_operVector.push_back (oper);
133  LifeChrono chrono;
134  epetraPrecPtr_Type prec;
135 
136  this->M_displayer.leaderPrint ( std::string ("ICP- Preconditioner type: ") + M_prec->Operator() [M_operVector.size() - 1]->preconditionerType() + std::string ("\n") );
137  this->M_displayer.leaderPrint ( "ICP- Computing preconditioner ... " );
138  chrono.start();
139  createPrec (oper, M_prec->OperatorView() [M_operVector.size() - 1]);
140  chrono.stop();
141  this->M_displayer.leaderPrintMax ("done in ", chrono.diff() );
142  M_prec->replace (prec, useInverse, useTranspose); // \TODO to reset as push_back
143  if ( M_prec->Operator().size() == M_operVector.size() )
144  {
145  this->M_preconditionerCreated = true;
146  }
147  return EXIT_SUCCESS;
148 }
149 
150 int
152  const UInt index,
153  const bool useInverse,
154  const bool useTranspose)
155 {
156  ASSERT (index <= M_operVector.size(), "PreconditionerComposed::replace: index too large");
157 
158  M_operVector[index] = oper;
159  LifeChrono chrono;
160  //ifpack_prec_type prec;
161  this->M_displayer.leaderPrint ( std::string ("ICP- Preconditioner type: ") + M_prec->Operator() [index]->preconditionerType() + std::string ("\n") );
162  this->M_displayer.leaderPrint ( "ICP- Computing preconditioner ... " );
163  chrono.start();
164  createPrec (oper, M_prec->OperatorView() [index]);
165  chrono.stop();
166  this->M_displayer.leaderPrintMax ("done in ", chrono.diff() );
167 
168  M_prec->replace (M_prec->Operator() [index], index, useInverse, useTranspose);
169 
170  return EXIT_SUCCESS;
171 }
172 
173 void
175 {
176  //M_operVector.reset();
177  M_prec.reset (new prec_Type (M_displayer.comm() ) );
178 
179  this->M_preconditionerCreated = false;
180 }
181 
182 
183 // ===================================================
184 // Private Methods
185 // ===================================================
186 Int
188  std::shared_ptr<Preconditioner>& prec )
189 {
190  return prec->buildPreconditioner ( oper );
191 }
192 
193 
194 
196 
197 } // namespace LifeV
void createParametersList(list_Type &, const GetPot &dataFile, const std::string &section, const std::string &subSection)
Creates the Trilinos Teuchos parameter list reading from data file.
int buildPreconditioner(operatorPtr_Type &A)
same as push_back
void start()
Start the timer.
Definition: LifeChrono.hpp:93
void resetPreconditioner()
resets the pointer to the preconditioner M_prec
double condest()
Returns an estimate of the condition number.
virtual ~PreconditionerComposed()
constructor from matrix A.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void updateInverseJacobian(const UInt &iQuadPt)
int replace(operatorPtr_Type &A, const UInt index, const bool useInverse=false, const bool useTranspose=false)
Builds a preconditioner based on A and replaces it in the composedPreconditioner. ...
void setDataFromGetPot(const GetPot &dataFile, const std::string &section)
Sets the data from GetPot.
Epetra_Operator prec_raw_type
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
int push_back(operatorPtr_Type &A, const bool useInverse=false, const bool useTranspose=false)
Builds a preconditioner based on A and pushes it back in the composedPreconditioner.
int buildPreconditioner(operatorPtr_Type &A, const bool useInverse, const bool useTranspose=false)
same as push_back
void myCreateParametersList(const GetPot &dataFile, const std::string &section, const std::string &subSection)
std::shared_ptr< operator_Type > operatorPtr_Type
PreconditionerComposed(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >())
default constructor.
Preconditioner - Abstract preconditioner class.
Int createPrec(operatorPtr_Type &oper, std::shared_ptr< Preconditioner > &prec)
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100
std::shared_ptr< Preconditioner > epetraPrecPtr_Type
super_Type::prec_raw_type * preconditioner()
returns a raw pointer to the preconditioner base class
std::shared_ptr< operator_raw_type > operator_type
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191