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