Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NOX_NearConvergenceTest.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2014 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_NLS_NOX_NearConvergenceTest.C,v $
27 //
28 // Purpose : Status test.
29 //
30 // Special Notes :
31 //
32 // Creator : Roger Pawlowski, SNL 9233
33 //
34 // Creation Date : 04/02/2003
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.12 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:25 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 
49 // ---------- Standard Includes ----------
50 
51 // ---------- Xyce Includes ----------
52 
54 #include "N_NLS_NOX_Vector.h"
55 #include "N_LAS_Vector.h"
56 #include "NOX.H"
57 #include "NOX_Solver_LineSearchBased.H"
58 
59 // ---------- Namespaces ----------
60 
61 using namespace N_NLS_NOX;
62 
63 // ---------- Code ----------
64 
66  double convRate,
67  double relativeConvRate) :
68  maxIters_(maxIters),
69  nIters_(0),
70  requestedConvRate_(convRate),
71  currentConvRate_(1.0),
72  requestedRelativeConvRate_(relativeConvRate),
73  currentRelativeConvRate_(1.0),
74  normResidualInit_(1.0),
75  status_(NOX::StatusTest::Unconverged)
76 {
77 
78 }
79 
81 {
82 
83 }
84 
85 
86 NOX::StatusTest::StatusType NearConvergenceTest::checkStatus(const NOX::Solver::Generic& problem)
87 {
88  status_ = NOX::StatusTest::Unconverged;
89 
90  nIters_ = problem.getNumIterations();
91 
92  if (nIters_ == 0)
93  normResidualInit_ = problem.getSolutionGroup().getNormF();
94 
95  // Test only if we hit the max number of iterations
96  if (nIters_ >= maxIters_) {
97 
98  // ||F(x_current)|| / ||F(x_previous)||
99  currentConvRate_ = (problem.getSolutionGroup().getNormF()) /
100  (problem.getPreviousSolutionGroup().getNormF());
101 
102  // ||F(x)|| / ||F(x_init)||
103  currentRelativeConvRate_ = (problem.getSolutionGroup().getNormF()) /
105 
108  status_ = NOX::StatusTest::Converged;
109  }
110  else
111  status_ = NOX::StatusTest::Failed;
112  }
113 
114  return status_;
115 }
116 
117 std::ostream& NearConvergenceTest::print(std::ostream& stream, int indent) const
118 {
119  for (int j = 0; j < indent; ++j )
120  stream << ' ';
121 
122  stream << status_;
123 
124  stream << "Near Convergence = ";
125 
126  if (status_ == NOX::StatusTest::Converged)
127  stream << "Yes\n";
128  else
129  stream << "No\n";
130 
131  for (int j = 0; j < indent; ++j )
132  stream << ' ';
133  stream << " (Max Iters = " << nIters_ << " = " << maxIters_ << ")\n";
134 
135  for (int j = 0; j < indent; ++j )
136  stream << ' ';
137  stream << " (Conv Rate = " << NOX::Utils::sciformat(currentConvRate_,3) << " < " << NOX::Utils::sciformat(requestedConvRate_,3) << ")\n";
138 
139  for (int j = 0; j < indent; ++j )
140  stream << ' ';
141  stream << " (Rel Conv Rate = " << NOX::Utils::sciformat(currentRelativeConvRate_, 3) << " < " << NOX::Utils::sciformat(requestedRelativeConvRate_, 3) << ")";
142 
143  stream << std::endl;
144 
145  return stream;
146 }
147