|
IFPACK Development
|
00001 /*@HEADER 00002 // *********************************************************************** 00003 // 00004 // Ifpack: Object-Oriented Algebraic Preconditioner Package 00005 // Copyright (2002) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 */ 00029 00030 #include "Ifpack_ConfigDefs.h" 00031 #include "Ifpack_Condest.h" 00032 #include "Ifpack_CondestType.h" 00033 #include "Ifpack_Preconditioner.h" 00034 #include "Epetra_Vector.h" 00035 #include "Epetra_LinearProblem.h" 00036 #include "Epetra_Map.h" 00037 #include "Epetra_RowMatrix.h" 00038 #ifdef HAVE_IFPACK_AZTECOO 00039 #include "AztecOO.h" 00040 #endif 00041 00042 double Ifpack_Condest(const Ifpack_Preconditioner& IFP, 00043 const Ifpack_CondestType CT, 00044 const int MaxIters, 00045 const double Tol, 00046 Epetra_RowMatrix* Matrix) 00047 { 00048 double ConditionNumberEstimate = -1.0; 00049 00050 if (CT == Ifpack_Cheap) { 00051 00052 // Create a vector with all values equal to one 00053 Epetra_Vector Ones(IFP.OperatorDomainMap()); 00054 Ones.PutScalar(1.0); 00055 // Create the vector of results 00056 Epetra_Vector OnesResult(IFP.OperatorRangeMap()); 00057 // Compute the effect of the solve on the vector of ones 00058 IFPACK_CHK_ERR(IFP.ApplyInverse(Ones, OnesResult)); 00059 // Make all values non-negative 00060 IFPACK_CHK_ERR(OnesResult.Abs(OnesResult)); 00061 // Get the maximum value across all processors 00062 IFPACK_CHK_ERR(OnesResult.MaxValue(&ConditionNumberEstimate)); 00063 00064 } 00065 else if (CT == Ifpack_CG) { 00066 00067 #ifdef HAVE_IFPACK_AZTECOO 00068 if (Matrix == 0) 00069 Matrix = (Epetra_RowMatrix*)&(IFP.Matrix()); 00070 00071 Epetra_Vector LHS(IFP.OperatorDomainMap()); 00072 LHS.PutScalar(0.0); 00073 Epetra_Vector RHS(IFP.OperatorRangeMap()); 00074 RHS.Random(); 00075 Epetra_LinearProblem Problem; 00076 Problem.SetOperator(Matrix); 00077 Problem.SetLHS(&LHS); 00078 Problem.SetRHS(&RHS); 00079 00080 AztecOO Solver(Problem); 00081 Solver.SetAztecOption(AZ_output,AZ_none); 00082 Solver.SetAztecOption(AZ_solver,AZ_cg_condnum); 00083 Solver.Iterate(MaxIters,Tol); 00084 00085 const double* status = Solver.GetAztecStatus(); 00086 ConditionNumberEstimate = status[AZ_condnum]; 00087 #endif 00088 00089 } else if (CT == Ifpack_GMRES) { 00090 00091 #ifdef HAVE_IFPACK_AZTECOO 00092 if (Matrix == 0) 00093 Matrix = (Epetra_RowMatrix*)&(IFP.Matrix()); 00094 00095 Epetra_Vector LHS(IFP.OperatorDomainMap()); 00096 LHS.PutScalar(0.0); 00097 Epetra_Vector RHS(IFP.OperatorRangeMap()); 00098 RHS.Random(); 00099 Epetra_LinearProblem Problem; 00100 Problem.SetOperator(Matrix); 00101 Problem.SetLHS(&LHS); 00102 Problem.SetRHS(&RHS); 00103 00104 AztecOO Solver(Problem); 00105 Solver.SetAztecOption(AZ_solver,AZ_gmres_condnum); 00106 Solver.SetAztecOption(AZ_output,AZ_none); 00107 // the following can be problematic for large problems, 00108 // but any restart would destroy useful information about 00109 // the condition number. 00110 Solver.SetAztecOption(AZ_kspace,MaxIters); 00111 Solver.Iterate(MaxIters,Tol); 00112 00113 const double* status = Solver.GetAztecStatus(); 00114 ConditionNumberEstimate = status[AZ_condnum]; 00115 #endif 00116 } 00117 00118 return(ConditionNumberEstimate); 00119 00120 }
1.7.4