trilinos_preconditioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #include "libmesh/libmesh_common.h"
19 
20 #ifdef LIBMESH_HAVE_TRILINOS
21 
22 // C++ includes
23 
24 // Local Includes
28 #include "libmesh/libmesh_common.h"
29 
30 #include "Ifpack.h"
31 #include "Ifpack_DiagPreconditioner.h"
32 #include "Ifpack_AdditiveSchwarz.h"
33 #include "Ifpack_ILU.h"
34 #include "Ifpack_ILUT.h"
35 #include "Ifpack_IC.h"
36 #include "Ifpack_ICT.h"
37 
38 #ifdef LIBMESH_HAVE_ML
39 #include "ml_MultiLevelPreconditioner.h"
40 #endif
41 
42 namespace libMesh
43 {
44 
45 template <typename T>
47  NumericVector<T> & /* y */ )
48 {
49 }
50 
51 
52 
53 
54 template <typename T>
56 {
57  if(!this->_matrix)
58  {
59  libMesh::err << "ERROR: No matrix set for PetscPreconditioner, but init() called" << std::endl;
60  libmesh_error();
61  }
62 
63  // Clear the preconditioner in case it has been created in the past
64  if (!this->_is_initialized)
65  {
66  EpetraMatrix<T> * matrix = libmesh_cast_ptr<EpetraMatrix<T>*, SparseMatrix<T> >(this->_matrix);
67  _mat = matrix->mat();
68  }
69 
70  set_preconditioner_type(this->_preconditioner_type);
71 
72  this->_is_initialized = true;
73 }
74 
75 
76 template <typename T>
77 void
78 TrilinosPreconditioner<T>::set_params(Teuchos::ParameterList & list)
79 {
80  _param_list = list;
81 }
82 
83 
84 template <typename T>
85 void
87 {
88  Ifpack_Preconditioner * ifpack = NULL;
89 #ifdef LIBMESH_HAVE_ML
90  ML_Epetra::MultiLevelPreconditioner * ml = NULL;
91 #endif
92 
93  switch (this->_preconditioner_type)
94  {
95  // IFPACK preconditioners
96  case ILU_PRECOND:
97  case SOR_PRECOND:
98  ifpack = dynamic_cast<Ifpack_Preconditioner *>(_prec);
99  ifpack->Compute();
100  break;
101 
102 #ifdef LIBMESH_HAVE_ML
103  // ML preconditioners
104  case AMG_PRECOND:
105  ml = dynamic_cast<ML_Epetra::MultiLevelPreconditioner *>(_prec);
106  ml->ComputePreconditioner();
107  break;
108 #endif
109 
110  default:
111  // no nothing here
112  break;
113  }
114 }
115 
116 
117 template <typename T>
118 void
120 {
121  Ifpack_Preconditioner * pc = NULL;
122 #ifdef LIBMESH_HAVE_ML
123  ML_Epetra::MultiLevelPreconditioner * ml = NULL;
124 #endif
125 
126  switch (preconditioner_type)
127  {
128  case IDENTITY_PRECOND:
129 // pc = new Ifpack_DiagPreconditioner();
130  break;
131 
132  case CHOLESKY_PRECOND:
133  break;
134 
135  case ICC_PRECOND:
136  break;
137 
138  case ILU_PRECOND:
139  pc = new Ifpack_ILU(_mat);
140  pc->SetParameters(_param_list);
141  pc->Initialize();
142  _prec = pc;
143  break;
144 
145  case LU_PRECOND:
146  break;
147 
148  case ASM_PRECOND:
149  break;
150 
151  case JACOBI_PRECOND:
152  break;
153 
155  break;
156 
157  case SOR_PRECOND:
158  break;
159 
160  case EISENSTAT_PRECOND:
161  break;
162 
163 #ifdef LIBMESH_HAVE_ML
164  case AMG_PRECOND:
165  ml = new ML_Epetra::MultiLevelPreconditioner(*_mat, _param_list, false);;
166  _prec = ml;
167  break;
168 #endif
169 
170  default:
171  libMesh::err << "ERROR: Unsupported Trilinos Preconditioner: "
172  << preconditioner_type << std::endl
173  << "Continuing with Trilinos defaults" << std::endl;
174  }
175 
176 }
177 
178 
179 template <typename T>
180 int
182 {
183  return _prec->SetUseTranspose(UseTranspose);
184 }
185 
186 template <typename T>
187 int
188 TrilinosPreconditioner<T>::Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
189 {
190  return _prec->Apply(X, Y);
191 }
192 
193 template <typename T>
194 int
195 TrilinosPreconditioner<T>::ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const
196 {
197  return _prec->ApplyInverse(r, z);
198 }
199 
200 template <typename T>
201 double
203 {
204  return _prec->NormInf();
205 }
206 
207 template <typename T>
208 const char *
210 {
211  return _prec->Label();
212 }
213 
214 template <typename T>
215 bool
217 {
218  return _prec->UseTranspose();
219 }
220 
221 template <typename T>
222 bool
224 {
225  return _prec->HasNormInf();
226 }
227 
228 template <typename T>
229 const Epetra_Comm &
231 {
232  return _prec->Comm();
233 }
234 
235 template <typename T>
236 const Epetra_Map &
238 {
239  return _prec->OperatorDomainMap();
240 }
241 
242 template <typename T>
243 const Epetra_Map &
245 {
246  return _prec->OperatorRangeMap();
247 }
248 
249 //------------------------------------------------------------------
250 // Explicit instantiations
251 template class TrilinosPreconditioner<Number>;
252 
253 } // namespace libMesh
254 
255 #endif // #ifdef LIBMESH_HAVE_TRILINOS

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo