LifeV
PreconditionerLSC.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 PreconditionerLSC class.
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @date 08-11-2010
33  */
34 
36 
37 #ifdef LIFEV_HAVE_TEKO
38 
39 namespace LifeV
40 {
41 
42 PreconditionerLSC::PreconditionerLSC ( std::shared_ptr<Epetra_Comm> comm ) :
43  PreconditionerTeko (),
44  M_precType ( "" ),
45  M_velocityBlockSize ( -1 ),
46  M_pressureBlockSize ( -1 ),
47  M_comm ( comm )
48 {
49 
50 }
51 
52 PreconditionerLSC::~PreconditionerLSC()
53 {
54 
55 }
56 
57 void
58 PreconditionerLSC::setDataFromGetPot ( const GetPot& dataFile,
59  const std::string& section )
60 {
61  this->createParametersList ( M_list, dataFile, section, "LSC" );
62  this->setParameters ( M_list );
63 }
64 
65 void
66 PreconditionerLSC::setParameters ( Teuchos::ParameterList& list )
67 {
68  M_precType = list.get ( "prectype", "LSC" );
69 }
70 
71 void
72 PreconditionerLSC::setFESpace ( FESpacePtr_Type uFESpace, FESpacePtr_Type pFESpace )
73 {
74  // We setup the size of the blocks
75  M_velocityBlockSize = uFESpace->fieldDim() * uFESpace->dof().numTotalDof();
76  M_pressureBlockSize = pFESpace->dof().numTotalDof();
77 }
78 
79 int
80 PreconditionerLSC::buildPreconditioner ( matrixPtr_Type& oper )
81 {
82  if ( ( M_velocityBlockSize < 0 ) || ( M_pressureBlockSize < 0 ) )
83  {
84  std::cout << "You must specify manually the pointers to the FESpaces" << std::endl;
85  exit ( -1 );
86  }
87 
88  // Creating the InverseLibrary from Stratimikos
89  RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromStratimikos();
90 
91  // build the inverse factory needed by the example preconditioner
92  RCP<Teko::InverseFactory> inverse = invLib->getInverseFactory ( "Ifpack" );
93 
94  // Building the LSC strategy
95  RCP<Teko::NS::LSCStrategy> strategy = rcp ( new Teko::NS::InvLSCStrategy ( inverse, true ) );
96 
97  // Building the LSC preconditioner factory
98  RCP<Teko::BlockPreconditionerFactory> precFact
99  = rcp (new Teko::NS::LSCPreconditionerFactory ( strategy ) );
100 
101  // Building Block sizes
102  std::vector<int> blockSizes;
103  blockSizes.push_back ( M_velocityBlockSize );
104  blockSizes.push_back ( M_pressureBlockSize );
105 
106  // Building the LSC preconditioner
107  buildPreconditionerTeko ( precFact, oper, blockSizes );
108 
109  return ( EXIT_SUCCESS );
110 }
111 
112 void
113 PreconditionerLSC::createParametersList ( list_Type& list,
114  const GetPot& dataFile,
115  const std::string& section,
116  const std::string& /* subSection */ )
117 {
118  bool verbose ( M_comm->MyPID() == 0 );
119 
120  //! See http://trilinos.sandia.gov/packages/docs/r9.0/packages/ifpack/doc/html/index.html
121  //! for more informations on the parameters
122 
123  bool displayList = dataFile ( ( section + "/displayList" ).data(), false );
124 
125  std::string precType = dataFile ( ( section + "/prectype" ).data(), "LSC" );
126  list.set ( "prectype", precType );
127 
128  if ( displayList && verbose )
129  {
130  std::cout << "LSC parameters list:" << std::endl;
131  std::cout << "-----------------------------" << std::endl;
132  list.print ( std::cout );
133  std::cout << "-----------------------------" << std::endl;
134  }
135 }
136 
137 Real
138 PreconditionerLSC::condest()
139 {
140  return 0.0;
141 }
142 
143 int
144 PreconditionerLSC::numBlocksRows() const
145 {
146  return 2;
147 }
148 
149 int
150 PreconditionerLSC::numBlocksCols() const
151 {
152  return 2;
153 }
154 
155 } // namespace LifeV
156 
157 #endif // LIFEV_HAVE_TEKO