Xyce  6.1
N_NLS_DampedNewton.h
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-2015 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_DampedNewton.h,v $
27 //
28 // Purpose : Specification file for the implemenation of the Newton
29 // trust-region related methods.
30 //
31 // Special Notes :
32 //
33 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences.
34 //
35 // Creation Date : 04/28/00
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.90 $
41 //
42 // Revision Date : $Date: 2015/08/08 04:49:43 $
43 //
44 // Current Owner : $Author: erkeite $
45 //-------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_NLS_DampedNewton_h
48 #define Xyce_N_NLS_DampedNewton_h
49 
50 #include <N_IO_fwd.h>
51 #include <N_NLS_fwd.h>
52 #include <N_NLS_NonLinearSolver.h>
53 #include <N_NLS_NLParams.h>
54 #include <N_NLS_ParamMgr.h>
55 #include <N_NLS_ReturnCodes.h>
56 
57 namespace Xyce {
58 namespace Nonlinear {
59 
60 //-----------------------------------------------------------------------------
61 // Class : DampedNewton
62 // Purpose : This class implements a damped Newton nonlinear solver.
63 // Special Notes :
64 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
65 // Creation Date : 5/03/00
66 //-----------------------------------------------------------------------------
68 {
69 public:
70  DampedNewton(const IO::CmdParse & cp);
71 
72  ~DampedNewton();
73 
74  bool setOptions(const Util::OptionBlock& OB);
75  bool setTranOptions(const Util::OptionBlock& OB);
76  bool setHBOptions(const Util::OptionBlock& OB);
77  bool setNLPOptions(const Util::OptionBlock& OB);
78 
79  bool initializeAll();
80 
81  int solve (NonLinearSolver * nlsTmpPtr = NULL);
82 
83  int takeFirstSolveStep (NonLinearSolver * nlsTmpPtr = NULL);
84  int takeOneSolveStep ();
85 
86  int getNumIterations() const;
87 
88  int getDebugLevel() const;
89  bool getScreenOutputFlag () const;
90  double getDebugMinTime() const;
91  double getDebugMaxTime() const;
92  int getDebugMinTimeStep() const;
93  int getDebugMaxTimeStep() const;
94  bool getMMFormat () const;
95 
96  int getContinuationStep() const;
97  int getParameterNumber() const;
98 
99  bool isFirstContinuationParam() const;
100  bool isFirstSolveComplete() const;
101 
102  void setAnalysisMode(AnalysisMode mode);
103 
104  double getMaxNormF() const
105  { return maxNormRHS_; };
106 
107  int getMaxNormFindex() const
108  { return maxNormRHSindex_; };
109 
110 protected:
111 
112 private:
113 
114  void updateWeights_();
115 
116  void printHeader_(std::ostream &os);
117  void printFooter_(std::ostream &os);
118  void printStepInfo_(std::ostream &os, int step);
119 
120  bool rhs_();
121  bool newton_();
122 
123  void direction_();
124  void updateX_();
125  bool computeStepLength_();
126 
127  bool divide_();
128  bool backtrack_();
129  bool fullNewton_();
130  bool simpleBacktrack_();
131  bool simpleBt_(double gsinit, double finit);
132 
133  double constrain_();
134  void setForcing_(const double);
135  void evalModNewton_();
136  int converged_();
137 
139 
140 public:
141 
142 protected:
143 
144 private:
145  //! Convergence Rate
146  double resConvRate_;
147 
148  //! Weighted convergence Rate
150 
151  //! Constraint object pointer
153 
154  // Current RHS norms:
155  double normRHS_;
156  double maxNormRHS_;
158 
159  double normRHS_init_; // used in calculating the relative norm.
160 
161  // Current dx norm:
162  double normDX_;
163 
164  // Current weighted dx norm:
165  double wtNormDX_;
166 
167  // Current relative RHS norm:
168  double normRHS_rel_;
169 
170  // Current solution norm:
171  double normSoln_;
172 
173  // step length:
174  double stepLength_;
175 
176  // backtracking upper and lower bounds and percentage change (0..1):
177  double BTUpper_;
178  double BTLower_;
179 
180  // constraint factor:
182 
183  // current nonlinear solver step:
184  unsigned nlStep_;
185 
186  // current Newton step:
187  unsigned newtonStep_;
188 
189  // current modified Newton step:
190  unsigned modNewtonStep_;
191 
192  // current steepest descent step:
193  unsigned descentStep_;
194 
195  // current line-search step:
196  unsigned searchStep_;
197 
198  //! Pointer to direction vector
199  /*! \todo Is this vector internal or external?? Is it allocated or just a pointer?? */
200  Linear::Vector* searchDirectionPtr_;
201 
202  // Needed for some reason
203  Linear::Vector* tmpVectorPtr_;
204 
206 
207  double delta_;
208 
209  // Flag for controlling the loading of the Jacobian matrix.
211 
212  // Flag for determining if this solver has been called
213  // before, and deltaXTol. The first time the solver is
214  // called we may want to tighten up the convergence tolerance
215  // a la Petzold, et al. These were static variables
216  // down in the "solve" function of this class. ERK.
217  bool firstTime;
219 
221 
222  double etaOld;
223  double nlResNormOld;
224  double tmpConvRate;
225 
227 
228  int count;
229 };
230 
231 //---------------------------------------------------------------------------
232 // Function : DampedNewton::getNumIterations
233 //
234 // Return Type : Integer (current number of nonlinear iterations)
235 //---------------------------------------------------------------------------
237 {
238  return nlStep_;
239 }
240 
241 //---------------------------------------------------------------------------
242 // Function : DampedNewton::getDebugLevel
243 //
244 // Return Type : int
245 //---------------------------------------------------------------------------
246 inline int DampedNewton::getDebugLevel() const
247 {
248  return nlParams.getDebugLevel();
249 }
250 
251 //---------------------------------------------------------------------------
252 // Function : DampedNewton::getScreenOutputFlag
253 //
254 // Return Type : int
255 //---------------------------------------------------------------------------
257 {
258  return nlParams.getScreenOutputFlag ();
259 }
260 
261 //---------------------------------------------------------------------------
262 // Function : DampedNewton::getDebugMinTime
263 //
264 // Return Type : double
265 //---------------------------------------------------------------------------
266 inline double DampedNewton::getDebugMinTime() const
267 {
268  return nlParams.getDebugMinTime();
269 }
270 
271 //---------------------------------------------------------------------------
272 // Function : DampedNewton::getDebugMaxTime
273 //
274 // Return Type : double
275 //---------------------------------------------------------------------------
276 inline double DampedNewton::getDebugMaxTime() const
277 {
278  return nlParams.getDebugMaxTime();
279 }
280 
281 //---------------------------------------------------------------------------
282 // Function : DampedNewton::getDebugMinTimeStep
283 //
284 // Return Type : int
285 //---------------------------------------------------------------------------
287 {
288  return nlParams.getDebugMinTimeStep();
289 }
290 
291 //---------------------------------------------------------------------------
292 // Function : DampedNewton::getDebugMaxTimeStep
293 //
294 // Return Type : int
295 //---------------------------------------------------------------------------
297 {
298  return nlParams.getDebugMaxTimeStep();
299 }
300 
301 //---------------------------------------------------------------------------
302 // Function : DampedNewton::getMMFormat
303 //
304 // Return Type : bool
305 //---------------------------------------------------------------------------
306 inline bool DampedNewton::getMMFormat () const
307 {
308  return nlParams.getMMFormat ();
309 }
310 
311 //---------------------------------------------------------------------------
312 // Function : DampedNewton::setAnalysisMode
313 //
314 // Purpose : Specify the analysis mode to be used by the nonlinear
315 // solver in the next call to solve(). This *may* affect
316 // the parameters used by the solver.
317 //
318 // See Also : setOptions, setTranOptions
319 //
320 // - Input Arguments -
321 //
322 // mode : Mode to be used in the next nonlinear solve.
323 //---------------------------------------------------------------------------
325 {
327 }
328 
329 //---------------------------------------------------------------------------
330 // Function : DampedNewton::resetCountersAndTimers_
331 // Purpose : Reset the counters and timers
332 //---------------------------------------------------------------------------
334 {
336  resConvRate_ = 0.0;
337  wtUpdateConvRate_ = 1.0;
338 }
339 
340 //---------------------------------------------------------------------------
341 // Function : DampedNewton::resetCountersAndTimers_
342 // Purpose : Reset the counters and timers
343 //---------------------------------------------------------------------------
345 {
346  return true;
347 }
348 
349 } // namespace Nonlinear
350 } // namespace Xyce
351 
352 #endif
353 
bool simpleBt_(double gsinit, double finit)
Pure virtual class to augment a linear system.
bool setAnalysisMode(AnalysisMode mode)
void printStepInfo_(std::ostream &os, int step)
double resConvRate_
Convergence Rate.
void setAnalysisMode(AnalysisMode mode)
bool setNLPOptions(const Util::OptionBlock &OB)
double getDebugMinTime() const
bool setHBOptions(const Util::OptionBlock &OB)
bool getScreenOutputFlag() const
double getDebugMaxTime() const
void printHeader_(std::ostream &os)
Linear::Vector * searchDirectionPtr_
Pointer to direction vector.
int takeFirstSolveStep(NonLinearSolver *nlsTmpPtr=NULL)
double wtUpdateConvRate_
Weighted convergence Rate.
bool setTranOptions(const Util::OptionBlock &OB)
DampedNewton(const IO::CmdParse &cp)
int solve(NonLinearSolver *nlsTmpPtr=NULL)
ConstraintBT * nlConstraintPtr_
Constraint object pointer.
bool setOptions(const Util::OptionBlock &OB)
void printFooter_(std::ostream &os)