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.86.2.1 $
41 //
42 // Revision Date : $Date: 2015/04/02 18:20:17 $
43 //
44 // Current Owner : $Author: tvrusso $
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 
78  bool initializeAll();
79 
80  int solve (NonLinearSolver * nlsTmpPtr = NULL);
81 
82  int takeFirstSolveStep (NonLinearSolver * nlsTmpPtr = NULL);
83  int takeOneSolveStep ();
84 
85  int getNumIterations() const;
86 
87  int getDebugLevel() const;
88  bool getScreenOutputFlag () const;
89  double getDebugMinTime() const;
90  double getDebugMaxTime() const;
91  int getDebugMinTimeStep() const;
92  int getDebugMaxTimeStep() const;
93  bool getMMFormat () const;
94 
95  int getContinuationStep() const;
96  int getParameterNumber() const;
97 
98  bool isFirstContinuationParam() const;
99  bool isFirstSolveComplete() const;
100 
101  void setAnalysisMode(AnalysisMode mode);
102 
103  double getMaxNormF() const
104  { return maxNormRHS_; };
105 
106  int getMaxNormFindex() const
107  { return maxNormRHSindex_; };
108 
109 protected:
110 
111 private:
112 
113  void updateWeights_();
114 
115  void printHeader_(std::ostream &os);
116  void printFooter_(std::ostream &os);
117  void printStepInfo_(std::ostream &os, int step);
118 
119  bool rhs_();
120  bool newton_();
121 
122  void direction_();
123  void updateX_();
124  bool computeStepLength_();
125 
126  bool divide_();
127  bool backtrack_();
128  bool fullNewton_();
129  bool spiceNewton_();
130  bool bankRose_();
131  bool descent_();
132  bool simpleBacktrack_();
133  bool simpleBt_(double gsinit, double finit);
134 
135  double constrain_();
136  void setForcing_(const double);
137  void evalModNewton_();
138  int converged_();
139 
141 
142 public:
143 
144 protected:
145 
146 private:
147  //! Convergence Rate
148  double resConvRate_;
149 
150  //! Weighted convergence Rate
152 
153  //! Constraint object pointer
155 
156  // Current RHS norms:
157  double normRHS_;
158  double maxNormRHS_;
160 
161  double normRHS_init_; // used in calculating the relative norm.
162 
163  // Current dx norm:
164  double normDX_;
165 
166  // Current weighted dx norm:
167  double wtNormDX_;
168 
169  // Current relative RHS norm:
170  double normRHS_rel_;
171 
172  // Current solution norm:
173  double normSoln_;
174 
175  // step length:
176  double stepLength_;
177 
178  // backtracking upper and lower bounds and percentage change (0..1):
179  double BTUpper_;
180  double BTLower_;
181 
182  // constraint factor:
184 
185  // current nonlinear solver step:
186  unsigned nlStep_;
187 
188  // current Newton step:
189  unsigned newtonStep_;
190 
191  // current modified Newton step:
192  unsigned modNewtonStep_;
193 
194  // current steepest descent step:
195  unsigned descentStep_;
196 
197  // current line-search step:
198  unsigned searchStep_;
199 
200  //! Pointer to direction vector
201  /*! \todo Is this vector internal or external?? Is it allocated or just a pointer?? */
202  Linear::Vector* searchDirectionPtr_;
203 
204  // Needed for some reason
205  Linear::Vector* tmpVectorPtr_;
206 
208 
209  double delta_;
210 
211  // Flag for controlling the loading of the Jacobian matrix.
213 
214  // Flag for determining if this solver has been called
215  // before, and deltaXTol. The first time the solver is
216  // called we may want to tighten up the convergence tolerance
217  // a la Petzold, et al. These were static variables
218  // down in the "solve" function of this class. ERK.
219  bool firstTime;
221 
223 
224  double etaOld;
225  double nlResNormOld;
226  double tmpConvRate;
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)
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)