Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.76 $
41 //
42 // Revision Date : $Date: 2014/02/24 23:49:24 $
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_NonLinearSolver.h>
52 #include <N_NLS_NLParams.h>
53 #include <N_NLS_ParamMgr.h>
54 #include <N_NLS_ReturnCodes.h>
55 
56 class N_NLS_ConstraintBT;
58 
59 //-----------------------------------------------------------------------------
60 // Class : N_NLS_DampedNewton
61 // Purpose : This class implements a damped Newton nonlinear solver.
62 // Special Notes :
63 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
64 // Creation Date : 5/03/00
65 //-----------------------------------------------------------------------------
67 {
68 public:
69 
70  N_NLS_DampedNewton(N_IO_CmdParse & cp);
72 
73  bool setOptions(const N_UTL_OptionBlock& OB);
74  bool setTranOptions(const N_UTL_OptionBlock& OB);
75  bool setHBOptions(const N_UTL_OptionBlock& OB);
76 
77  bool initializeAll();
78 
79  int solve (N_NLS_NonLinearSolver * nlsTmpPtr = NULL);
80 
81  int takeFirstSolveStep (N_NLS_NonLinearSolver * nlsTmpPtr = NULL);
82  int takeOneSolveStep ();
83 
84  int getNumIterations() const;
85 #ifdef Xyce_DEBUG_NONLINEAR
86  int getDebugLevel() const;
87  bool getScreenOutputFlag () const;
88  double getDebugMinTime() const;
89  double getDebugMaxTime() const;
90  int getDebugMinTimeStep() const;
91  int getDebugMaxTimeStep() const;
92  bool getMMFormat () const;
93 #endif
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  N_LAS_Vector* searchDirectionPtr_;
203 
204  // Needed for some reason
205  N_LAS_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 : N_NLS_DampedNewton::getNumIterations
233 //
234 // Return Type : Integer (current number of nonlinear iterations)
235 //---------------------------------------------------------------------------
237 {
238  return nlStep_;
239 }
240 
241 #ifdef Xyce_DEBUG_NONLINEAR
242 //---------------------------------------------------------------------------
243 // Function : N_NLS_DampedNewton::getDebugLevel
244 //
245 // Return Type : int
246 //---------------------------------------------------------------------------
247 inline int N_NLS_DampedNewton::getDebugLevel() const
248 {
249  return nlParams.getDebugLevel();
250 }
251 
252 //---------------------------------------------------------------------------
253 // Function : N_NLS_DampedNewton::getScreenOutputFlag
254 //
255 // Return Type : int
256 //---------------------------------------------------------------------------
257 inline bool N_NLS_DampedNewton::getScreenOutputFlag () const
258 {
259  return nlParams.getScreenOutputFlag ();
260 }
261 
262 //---------------------------------------------------------------------------
263 // Function : N_NLS_DampedNewton::getDebugMinTime
264 //
265 // Return Type : double
266 //---------------------------------------------------------------------------
267 inline double N_NLS_DampedNewton::getDebugMinTime() const
268 {
269  return nlParams.getDebugMinTime();
270 }
271 
272 //---------------------------------------------------------------------------
273 // Function : N_NLS_DampedNewton::getDebugMaxTime
274 //
275 // Return Type : double
276 //---------------------------------------------------------------------------
277 inline double N_NLS_DampedNewton::getDebugMaxTime() const
278 {
279  return nlParams.getDebugMaxTime();
280 }
281 
282 //---------------------------------------------------------------------------
283 // Function : N_NLS_DampedNewton::getDebugMinTimeStep
284 //
285 // Return Type : int
286 //---------------------------------------------------------------------------
287 inline int N_NLS_DampedNewton::getDebugMinTimeStep() const
288 {
289  return nlParams.getDebugMinTimeStep();
290 }
291 
292 //---------------------------------------------------------------------------
293 // Function : N_NLS_DampedNewton::getDebugMaxTimeStep
294 //
295 // Return Type : int
296 //---------------------------------------------------------------------------
297 inline int N_NLS_DampedNewton::getDebugMaxTimeStep() const
298 {
299  return nlParams.getDebugMaxTimeStep();
300 }
301 
302 //---------------------------------------------------------------------------
303 // Function : N_NLS_DampedNewton::getMMFormat
304 //
305 // Return Type : bool
306 //---------------------------------------------------------------------------
307 inline bool N_NLS_DampedNewton::getMMFormat () const
308 {
309  return nlParams.getMMFormat ();
310 }
311 
312 #endif // debug nonlin
313 
314 //---------------------------------------------------------------------------
315 // Function : N_NLS_DampedNewton::setAnalysisMode
316 //
317 // Purpose : Specify the analysis mode to be used by the nonlinear
318 // solver in the next call to solve(). This *may* affect
319 // the parameters used by the solver.
320 //
321 // See Also : setOptions, setTranOptions
322 //
323 // - Input Arguments -
324 //
325 // mode : Mode to be used in the next nonlinear solve.
326 //---------------------------------------------------------------------------
328 {
330 }
331 
332 //---------------------------------------------------------------------------
333 // Function : N_NLS_DampedNewton::resetCountersAndTimers_
334 // Purpose : Reset the counters and timers
335 //---------------------------------------------------------------------------
337 {
339  resConvRate_ = 0.0;
340  wtUpdateConvRate_ = 1.0;
341 }
342 
343 //---------------------------------------------------------------------------
344 // Function : N_NLS_DampedNewton::resetCountersAndTimers_
345 // Purpose : Reset the counters and timers
346 //---------------------------------------------------------------------------
348 {
349  return true;
350 }
351 #endif
352