00001 // $Id: NOX_StatusTest_Stagnation.C,v 1.8 2006/08/22 00:01:28 rppawlo Exp $ 00002 // $Source: /space/CVS/Trilinos/packages/nox/src/NOX_StatusTest_Stagnation.C,v $ 00003 00004 //@HEADER 00005 // ************************************************************************ 00006 // 00007 // NOX: An Object-Oriented Nonlinear Solver Package 00008 // Copyright (2002) Sandia Corporation 00009 // 00010 // LOCA: Library of Continuation Algorithms Package 00011 // Copyright (2005) Sandia Corporation 00012 // 00013 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00014 // license for use of this work by or on behalf of the U.S. Government. 00015 // 00016 // This library is free software; you can redistribute it and/or modify 00017 // it under the terms of the GNU Lesser General Public License as 00018 // published by the Free Software Foundation; either version 2.1 of the 00019 // License, or (at your option) any later version. 00020 // 00021 // This library is distributed in the hope that it will be useful, but 00022 // WITHOUT ANY WARRANTY; without even the implied warranty of 00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 // Lesser General Public License for more details. 00025 // 00026 // You should have received a copy of the GNU Lesser General Public 00027 // License along with this library; if not, write to the Free Software 00028 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00029 // USA 00030 // 00031 // Questions? Contact Roger Pawlowski (rppawlo@sandia.gov) or 00032 // Eric Phipps (etphipp@sandia.gov), Sandia National Laboratories. 00033 // ************************************************************************ 00034 // CVS Information 00035 // $Source: /space/CVS/Trilinos/packages/nox/src/NOX_StatusTest_Stagnation.C,v $ 00036 // $Author: rppawlo $ 00037 // $Date: 2006/08/22 00:01:28 $ 00038 // $Revision: 1.8 $ 00039 // ************************************************************************ 00040 //@HEADER 00041 00042 #include "NOX_StatusTest_Stagnation.H" // class definition 00043 #include "NOX_Common.H" 00044 #include "NOX_Solver_Generic.H" 00045 #include "NOX_Abstract_Group.H" 00046 00047 NOX::StatusTest::Stagnation::Stagnation(int maxSteps_, double tolerance_) : 00048 maxSteps(maxSteps_), 00049 numSteps(0), 00050 lastIteration(-1), 00051 tolerance(tolerance_), 00052 convRate(1.0), 00053 status(NOX::StatusTest::Unevaluated) 00054 { 00055 00056 } 00057 00058 NOX::StatusTest::Stagnation::~Stagnation() 00059 { 00060 } 00061 00062 NOX::StatusTest::StatusType 00063 NOX::StatusTest::Stagnation:: 00064 checkStatus(const Solver::Generic& problem, 00065 NOX::StatusTest::CheckType checkType) 00066 { 00067 status = Unconverged; 00068 00069 // This test should ignore the checkType! This test must be run 00070 // each iteration because it triggers after a set number of 00071 // iterations. 00072 00073 // First time through we don't do anything 00074 int niters = problem.getNumIterations(); 00075 if (niters == 0) { 00076 lastIteration = 0; 00077 numSteps = 0; 00078 return Unconverged; 00079 } 00080 00081 // Make sure we have not already counted the last nonlinear iteration. 00082 // This protects against multiple calls to checkStatus() in between 00083 // nonlinear iterations. 00084 bool isCounted = false; 00085 if (niters == lastIteration) { 00086 isCounted = true; 00087 } 00088 else 00089 lastIteration = niters; 00090 00091 // Compute the convergence rate and set counter appropriately 00092 if (!isCounted) { 00093 00094 convRate = problem.getSolutionGroup().getNormF() / 00095 problem.getPreviousSolutionGroup().getNormF(); 00096 00097 if (convRate >= tolerance) 00098 numSteps ++; 00099 else 00100 numSteps = 0; 00101 00102 } 00103 00104 if (numSteps >= maxSteps) 00105 status = Failed; 00106 00107 return status; 00108 } 00109 00110 NOX::StatusTest::StatusType NOX::StatusTest::Stagnation::getStatus() const 00111 { 00112 return status; 00113 } 00114 00115 ostream& NOX::StatusTest::Stagnation::print(ostream& stream, int indent) const 00116 { 00117 for (int j = 0; j < indent; j ++) 00118 stream << ' '; 00119 stream << status; 00120 stream << "Stagnation Count = " << numSteps << " < " << maxSteps << "\n"; 00121 00122 for (int j = 0; j < indent; j ++) 00123 stream << ' '; 00124 stream << " (convergence rate = " << convRate << ")"; 00125 stream << endl; 00126 return stream; 00127 } 00128 00129 00130 int NOX::StatusTest::Stagnation::getMaxNumSteps() const 00131 { 00132 return maxSteps; 00133 } 00134 00135 int NOX::StatusTest::Stagnation::getCurrentNumSteps() const 00136 { 00137 return numSteps; 00138 } 00139 00140 double NOX::StatusTest::Stagnation::getTolerance() const 00141 { 00142 return tolerance; 00143 } 00144 00145 double NOX::StatusTest::Stagnation::getConvRate() const 00146 { 00147 return convRate; 00148 }