Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_TwoLevelNewton.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_TwoLevelNewton.h,v $
27 //
28 // Purpose : Defines N_NLS_TwoLevelNewton class.
29 //
30 // Special Notes :
31 //
32 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 10/20/02
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.81 $
40 //
41 // Revision Date : $Date: 2014/08/07 23:08:54 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_NLS_TwoLevelNewton_h
47 #define Xyce_N_NLS_TwoLevelNewton_h
48 
49 // ---------- Standard Includes ----------
50 #include <vector>
51 
52 // ---------- Xyce Includes ----------
53 #include <N_UTL_fwd.h>
54 #include <N_ANP_fwd.h>
55 #include <N_NLS_NLParams.h>
56 #include <N_NLS_NonLinearSolver.h>
57 #include <N_NLS_TwoLevelEnum.h>
58 
59 // Loader for RHS and Jacobian
60 class N_LOA_Loader;
61 
62 // Linear Algebra Support
63 class N_LAS_Matrix;
64 class N_LAS_Vector;
65 class N_LAS_System;
66 
67 namespace Xyce {
68 namespace Nonlinear {
69 
70 //-----------------------------------------------------------------------------
71 // Class : TwoLevelNewton
72 // Purpose : This class is the manager for the two level newton
73 // algorithm. Mostly, it will contain a control loop
74 // which repeatedly calls the "true" nonlinear solver
75 // (either DampedNewton's solve, or NOX, depending
76 // on the options specified).
77 //
78 // The idea of two level newton is divide the problem
79 // up into sub-problems and solve them separately
80 // for part or all of the solve.
81 //
82 // The control loop contained in this class repeatedly
83 // loops over all the sub-problems, and also determines
84 // if the total problem has converged.
85 //
86 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
87 // Creation Date : 10/20/02
88 //-----------------------------------------------------------------------------
89 
91 {
92 public:
93  TwoLevelNewton(bool noxFlag, bool noxFlagInner, N_IO_CmdParse & cp);
95 
96  int getNumIterations() const;
97 #ifdef Xyce_DEBUG_NONLINEAR
98  int getDebugLevel () const;
99  bool getScreenOutputFlag () const;
100  double getDebugMinTime() const;
101  double getDebugMaxTime() const;
102  int getDebugMinTimeStep() const;
103  int getDebugMaxTimeStep() const;
104  bool getMMFormat () const;
105 #endif
106  int getContinuationStep() const;
107  int getParameterNumber() const;
108  bool isFirstContinuationParam() const;
109  bool isFirstSolveComplete() const;
110 
111  int solve (NonLinearSolver * nlsTmpPtr=NULL);
112  bool setOptions (const N_UTL_OptionBlock & OB);
113  bool setTranOptions (const N_UTL_OptionBlock & OB);
114  bool setHBOptions (const N_UTL_OptionBlock & OB);
115  bool setTwoLevelOptions (const N_UTL_OptionBlock & OB);
116  bool setTwoLevelTranOptions (const N_UTL_OptionBlock & OB);
117  bool setLocaOptions (const N_UTL_OptionBlock& OB);
118  bool setTwoLevelLocaOptions (const N_UTL_OptionBlock& OB);
119  bool registerLinearSystem(N_LAS_System* ptr);
121  bool registerLoader(N_LOA_Loader* ptr);
122  bool registerOutputMgr (N_IO_OutputMgr * ptr);
123  bool initializeAll ();
125  void setAnalysisMode (AnalysisMode mode);
126  bool setPetraOptions (const N_UTL_OptionBlock & OB);
127  int getContStepNumber ();
128  bool enableSensitivity ();
129 
130  // solver statistics:
131  virtual int getNumResidualLoads();
132  virtual int getNumJacobianLoads();
133  virtual int getNumLinearSolves();
134  virtual int getNumFailedLinearSolves();
135  virtual int getNumJacobianFactorizations();
136  virtual unsigned int getTotalNumLinearIters();
137  virtual double getTotalLinearSolveTime();
138  virtual double getTotalResidualLoadTime();
139  virtual double getTotalJacobianLoadTime();
140 
141  double getMaxNormF() const;
142  int getMaxNormFindex() const;
143 private:
144  TwoLevelNewton();
145 
146  void printStepInfo_(int step, int success, TwoLevelNewtonMode solveType);
147 
148  void zeroInnerLoopStatistics_ ();
149  void calcInnerLoopStatistics_ ();
150 
151  void calcOuterLoopStatistics_ ();
152 
153  bool calcCouplingTerms_ ();
154 
155  int continuationLoop_ ();
156  int locaLoop_ ();
157 
158  int algorithm0_();
159  int algorithm1_();
160  int algorithm2_();
161  int algorithm3_();
162  int algorithm4_();
163  int algorithm5_();
164 
165 public:
166 
167 private:
168  // Pointer to the outer loop nonlinear solver that is being used.
170 
171  // Pointer to the inner loop nonlinear solver that is being used.
173 
174  // Pointer to the time integrator that is being used.
176 
177  // number of iterations for the "outer" loop, if it exists. (algorithm>0)
179 
180  // number of iterations for the inner "voltage stepper" loop.
181  // This parameter is kind of irrelevant, if running with variable step
182  // size.
186 
189 
190  // this variable determines which variant of two level newton
191  // is being used.
192  //
193  // Here's the key:
194  //
195  // 0 = full newton , one level (as though two-level weren't being used)
196  // This is probably the best algorithm for transient.
197  //
198  // 1 = full newton outter loop, device pde newton inner loop.
199  //
200  // 2 = full newton outter loop, with pde device inner loop and
201  // continuation. Sort of a 3-level.
202  //
203  // 3 = ckt only outter loop, with pde device inner loop, which uses
204  // continuation. This is sort of a 3-level Newton. This is
205  // the best algorithm for DCOP.
206  //
208  int twoLevelAlgorithmTran_; // same, but for transient.
209 
210  // this flag indicates if the current solve iteration is of the
211  // outer loop or the inner loop.
213 
215 
218  bool noxFlag_;
220 
221  // inner loop statistics vars:
227  unsigned int totalNumLinearIters_;
231 
233 
234  std::vector<int> numInterfaceNodes_;
235 
237 
238  N_LAS_Vector *savedRHSPtr_;
239  N_LAS_Vector *savedNextSolPtr_;
240  N_LAS_Vector *jdxpVectorPtr_;
241 
247 
249 
251 
253 
254  // continuation parameters used for algorithm 4. (not the
255  // continuationLoop_ function, that's different)
256  std::vector<std::string> paramNameList;
257  std::vector<double> paramFinalVal;
258  std::vector<double> paramCurrentVal;
259 
260  // These options are saved in case they have to be modified
261  // over the course of the solve.
262  N_UTL_OptionBlock innerSolverOptions_;
263  N_UTL_OptionBlock innerLocaOptions_;
264  N_UTL_OptionBlock outerLocaOptions_;
265 
266  // voltage limiter tolerance:
267  double voltLimTol_;
268 };
269 
270 //-----------------------------------------------------------------------------
271 // Function : TwoLevelNewton::getContStepNumber
272 // Purpose : returns the current continuation step number.
273 // Special Notes :
274 // Scope : private
275 // Creator : Eric R. Keiter, SNL, Compuational Sciences
276 // Creation Date : 10/24/02
277 //-----------------------------------------------------------------------------
279 {
280  return contStep_;
281 }
282 
283 //-----------------------------------------------------------------------------
284 // Function : TwoLevelNewton::isFirstSolveComplete
285 // Purpose :
286 // Special Notes :
287 // Scope : private
288 // Creator : Dave Shirley, PSSI
289 // Creation Date : 06/22/06
290 //-----------------------------------------------------------------------------
292 {
293  return true;
294 }
295 
296 #ifdef Xyce_DEBUG_NONLINEAR
297 //-----------------------------------------------------------------------------
298 // Function : TwoLevelNewton::getDebugLevel
299 // Purpose :
300 // Special Notes :
301 // Scope : private
302 // Creator : Eric Keiter, SNL
303 // Creation Date : 09/17/07
304 //-----------------------------------------------------------------------------
305 inline int TwoLevelNewton::getDebugLevel () const
306 {
307  return -100;
308 }
309 
310 //-----------------------------------------------------------------------------
311 // Function : TwoLevelNewton::getScreenOutputFlag
312 // Purpose :
313 // Special Notes :
314 // Scope : private
315 // Creator : Eric Keiter, SNL
316 // Creation Date : 09/17/07
317 //-----------------------------------------------------------------------------
318 inline bool TwoLevelNewton::getScreenOutputFlag () const
319 {
320  return false;
321 }
322 
323 //---------------------------------------------------------------------------
324 // Function : TwoLevelNewton::getDebugMinTime
325 //
326 // Return Type : double
327 //---------------------------------------------------------------------------
328 inline double TwoLevelNewton::getDebugMinTime() const
329 {
330  return 0.0;
331 }
332 
333 //---------------------------------------------------------------------------
334 // Function : TwoLevelNewton::getDebugMaxTime
335 //
336 // Return Type : double
337 //---------------------------------------------------------------------------
338 inline double TwoLevelNewton::getDebugMaxTime() const
339 {
340  return N_UTL_MachineDependentParams::DoubleMax();
341 }
342 
343 //---------------------------------------------------------------------------
344 // Function : TwoLevelNewton::getDebugMinTimeStep
345 //
346 // Return Type : int
347 //---------------------------------------------------------------------------
348 inline int TwoLevelNewton::getDebugMinTimeStep() const
349 {
350  return 0;
351 }
352 
353 //---------------------------------------------------------------------------
354 // Function : TwoLevelNewton::getDebugMaxTimeStep
355 //
356 // Return Type : int
357 //---------------------------------------------------------------------------
358 inline int TwoLevelNewton::getDebugMaxTimeStep() const
359 {
360  return N_UTL_MachineDependentParams::IntMax();
361 }
362 
363 //---------------------------------------------------------------------------
364 // Function : TwoLevelNewton::getMMFormat
365 //
366 // Return Type : bool
367 //---------------------------------------------------------------------------
368 inline bool TwoLevelNewton::getMMFormat () const
369 {
370  return false;
371 }
372 
373 #endif // debug nonlin
374 
375 } // namespace Nonlinear
376 } // namespace Xyce
377 
379 
380 #endif