trilinos_preconditioner.C
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 #include "libmesh/libmesh_common.h" 00019 00020 #ifdef LIBMESH_HAVE_TRILINOS 00021 00022 // C++ includes 00023 00024 // Local Includes 00025 #include "libmesh/trilinos_preconditioner.h" 00026 #include "libmesh/trilinos_epetra_matrix.h" 00027 #include "libmesh/trilinos_epetra_vector.h" 00028 #include "libmesh/libmesh_common.h" 00029 00030 #include "Ifpack.h" 00031 #include "Ifpack_DiagPreconditioner.h" 00032 #include "Ifpack_AdditiveSchwarz.h" 00033 #include "Ifpack_ILU.h" 00034 #include "Ifpack_ILUT.h" 00035 #include "Ifpack_IC.h" 00036 #include "Ifpack_ICT.h" 00037 00038 #ifdef LIBMESH_HAVE_ML 00039 #include "ml_MultiLevelPreconditioner.h" 00040 #endif 00041 00042 namespace libMesh 00043 { 00044 00045 template <typename T> 00046 void TrilinosPreconditioner<T>::apply(const NumericVector<T> & /* x */, 00047 NumericVector<T> & /* y */ ) 00048 { 00049 } 00050 00051 00052 00053 00054 template <typename T> 00055 void TrilinosPreconditioner<T>::init () 00056 { 00057 if(!this->_matrix) 00058 { 00059 libMesh::err << "ERROR: No matrix set for PetscPreconditioner, but init() called" << std::endl; 00060 libmesh_error(); 00061 } 00062 00063 // Clear the preconditioner in case it has been created in the past 00064 if (!this->_is_initialized) 00065 { 00066 EpetraMatrix<T> * matrix = libmesh_cast_ptr<EpetraMatrix<T>*, SparseMatrix<T> >(this->_matrix); 00067 _mat = matrix->mat(); 00068 } 00069 00070 set_preconditioner_type(this->_preconditioner_type); 00071 00072 this->_is_initialized = true; 00073 } 00074 00075 00076 template <typename T> 00077 void 00078 TrilinosPreconditioner<T>::set_params(Teuchos::ParameterList & list) 00079 { 00080 _param_list = list; 00081 } 00082 00083 00084 template <typename T> 00085 void 00086 TrilinosPreconditioner<T>::compute() 00087 { 00088 Ifpack_Preconditioner * ifpack = NULL; 00089 #ifdef LIBMESH_HAVE_ML 00090 ML_Epetra::MultiLevelPreconditioner * ml = NULL; 00091 #endif 00092 00093 switch (this->_preconditioner_type) 00094 { 00095 // IFPACK preconditioners 00096 case ILU_PRECOND: 00097 case SOR_PRECOND: 00098 ifpack = dynamic_cast<Ifpack_Preconditioner *>(_prec); 00099 ifpack->Compute(); 00100 break; 00101 00102 #ifdef LIBMESH_HAVE_ML 00103 // ML preconditioners 00104 case AMG_PRECOND: 00105 ml = dynamic_cast<ML_Epetra::MultiLevelPreconditioner *>(_prec); 00106 ml->ComputePreconditioner(); 00107 break; 00108 #endif 00109 00110 default: 00111 // no nothing here 00112 break; 00113 } 00114 } 00115 00116 00117 template <typename T> 00118 void 00119 TrilinosPreconditioner<T>::set_preconditioner_type (const PreconditionerType & preconditioner_type) 00120 { 00121 Ifpack_Preconditioner * pc = NULL; 00122 #ifdef LIBMESH_HAVE_ML 00123 ML_Epetra::MultiLevelPreconditioner * ml = NULL; 00124 #endif 00125 00126 switch (preconditioner_type) 00127 { 00128 case IDENTITY_PRECOND: 00129 // pc = new Ifpack_DiagPreconditioner(); 00130 break; 00131 00132 case CHOLESKY_PRECOND: 00133 break; 00134 00135 case ICC_PRECOND: 00136 break; 00137 00138 case ILU_PRECOND: 00139 pc = new Ifpack_ILU(_mat); 00140 pc->SetParameters(_param_list); 00141 pc->Initialize(); 00142 _prec = pc; 00143 break; 00144 00145 case LU_PRECOND: 00146 break; 00147 00148 case ASM_PRECOND: 00149 break; 00150 00151 case JACOBI_PRECOND: 00152 break; 00153 00154 case BLOCK_JACOBI_PRECOND: 00155 break; 00156 00157 case SOR_PRECOND: 00158 break; 00159 00160 case EISENSTAT_PRECOND: 00161 break; 00162 00163 #ifdef LIBMESH_HAVE_ML 00164 case AMG_PRECOND: 00165 ml = new ML_Epetra::MultiLevelPreconditioner(*_mat, _param_list, false);; 00166 _prec = ml; 00167 break; 00168 #endif 00169 00170 default: 00171 libMesh::err << "ERROR: Unsupported Trilinos Preconditioner: " 00172 << preconditioner_type << std::endl 00173 << "Continuing with Trilinos defaults" << std::endl; 00174 } 00175 00176 } 00177 00178 00179 template <typename T> 00180 int 00181 TrilinosPreconditioner<T>::SetUseTranspose(bool UseTranspose) 00182 { 00183 return _prec->SetUseTranspose(UseTranspose); 00184 } 00185 00186 template <typename T> 00187 int 00188 TrilinosPreconditioner<T>::Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const 00189 { 00190 return _prec->Apply(X, Y); 00191 } 00192 00193 template <typename T> 00194 int 00195 TrilinosPreconditioner<T>::ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const 00196 { 00197 return _prec->ApplyInverse(r, z); 00198 } 00199 00200 template <typename T> 00201 double 00202 TrilinosPreconditioner<T>::NormInf() const 00203 { 00204 return _prec->NormInf(); 00205 } 00206 00207 template <typename T> 00208 const char * 00209 TrilinosPreconditioner<T>::Label() const 00210 { 00211 return _prec->Label(); 00212 } 00213 00214 template <typename T> 00215 bool 00216 TrilinosPreconditioner<T>::UseTranspose() const 00217 { 00218 return _prec->UseTranspose(); 00219 } 00220 00221 template <typename T> 00222 bool 00223 TrilinosPreconditioner<T>::HasNormInf() const 00224 { 00225 return _prec->HasNormInf(); 00226 } 00227 00228 template <typename T> 00229 const Epetra_Comm & 00230 TrilinosPreconditioner<T>::Comm() const 00231 { 00232 return _prec->Comm(); 00233 } 00234 00235 template <typename T> 00236 const Epetra_Map & 00237 TrilinosPreconditioner<T>::OperatorDomainMap() const 00238 { 00239 return _prec->OperatorDomainMap(); 00240 } 00241 00242 template <typename T> 00243 const Epetra_Map & 00244 TrilinosPreconditioner<T>::OperatorRangeMap() const 00245 { 00246 return _prec->OperatorRangeMap(); 00247 } 00248 00249 //------------------------------------------------------------------ 00250 // Explicit instantiations 00251 template class TrilinosPreconditioner<Number>; 00252 00253 } // namespace libMesh 00254 00255 #endif // #ifdef LIBMESH_HAVE_TRILINOS
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:49 UTC
Hosted By: