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.79 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:24 $
42 //
43 // Current Owner : $Author: tvrusso $
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 //-----------------------------------------------------------------------------
68 // Class : N_NLS_TwoLevelNewton
69 // Purpose : This class is the manager for the two level newton
70 // algorithm. Mostly, it will contain a control loop
71 // which repeatedly calls the "true" nonlinear solver
72 // (either N_NLS_DampedNewton's solve, or NOX, depending
73 // on the options specified).
74 //
75 // The idea of two level newton is divide the problem
76 // up into sub-problems and solve them separately
77 // for part or all of the solve.
78 //
79 // The control loop contained in this class repeatedly
80 // loops over all the sub-problems, and also determines
81 // if the total problem has converged.
82 //
83 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
84 // Creation Date : 10/20/02
85 //-----------------------------------------------------------------------------
86 
88 {
89 public:
90  N_NLS_TwoLevelNewton(bool noxFlag, bool noxFlagInner, N_IO_CmdParse & cp);
92 
93  int getNumIterations() const;
94 #ifdef Xyce_DEBUG_NONLINEAR
95  int getDebugLevel () const;
96  bool getScreenOutputFlag () const;
97  double getDebugMinTime() const;
98  double getDebugMaxTime() const;
99  int getDebugMinTimeStep() const;
100  int getDebugMaxTimeStep() const;
101  bool getMMFormat () const;
102 #endif
103  int getContinuationStep() const;
104  int getParameterNumber() const;
105  bool isFirstContinuationParam() const;
106  bool isFirstSolveComplete() const;
107 
108  int solve (N_NLS_NonLinearSolver * nlsTmpPtr=NULL);
109  bool setOptions (const N_UTL_OptionBlock & OB);
110  bool setTranOptions (const N_UTL_OptionBlock & OB);
111  bool setHBOptions (const N_UTL_OptionBlock & OB);
112  bool setTwoLevelOptions (const N_UTL_OptionBlock & OB);
113  bool setTwoLevelTranOptions (const N_UTL_OptionBlock & OB);
114  bool setLocaOptions (const N_UTL_OptionBlock& OB);
115  bool setTwoLevelLocaOptions (const N_UTL_OptionBlock& OB);
116  bool registerLinearSystem(N_LAS_System* ptr);
118  bool registerLoader(N_LOA_Loader* ptr);
119  bool registerOutputMgr (N_IO_OutputMgr * ptr);
120  bool initializeAll ();
122  void setAnalysisMode (AnalysisMode mode);
123  bool setPetraOptions (const N_UTL_OptionBlock & OB);
124  int getContStepNumber ();
125  bool enableSensitivity ();
126 
127  // solver statistics:
128  virtual int getNumResidualLoads();
129  virtual int getNumJacobianLoads();
130  virtual int getNumLinearSolves();
131  virtual int getNumFailedLinearSolves();
132  virtual int getNumJacobianFactorizations();
133  virtual unsigned int getTotalNumLinearIters();
134  virtual double getTotalLinearSolveTime();
135  virtual double getTotalResidualLoadTime();
136  virtual double getTotalJacobianLoadTime();
137 
138  double getMaxNormF() const;
139  int getMaxNormFindex() const;
140 private:
142 
143  void printStepInfo_(int step, int success, TwoLevelNewtonMode solveType);
144 
145  void zeroInnerLoopStatistics_ ();
146  void calcInnerLoopStatistics_ ();
147 
148  void calcOuterLoopStatistics_ ();
149 
150  bool calcCouplingTerms_ ();
151 
152  int continuationLoop_ ();
153  int locaLoop_ ();
154 
155  int algorithm0_();
156  int algorithm1_();
157  int algorithm2_();
158  int algorithm3_();
159  int algorithm4_();
160  int algorithm5_();
161 
162 public:
163 
164 private:
165  // Pointer to the outer loop nonlinear solver that is being used.
167 
168  // Pointer to the inner loop nonlinear solver that is being used.
170 
171  // Pointer to the time integrator that is being used.
173 
174  // number of iterations for the "outer" loop, if it exists. (algorithm>0)
176 
177  // number of iterations for the inner "voltage stepper" loop.
178  // This parameter is kind of irrelevant, if running with variable step
179  // size.
183 
186 
187  // this variable determines which variant of two level newton
188  // is being used.
189  //
190  // Here's the key:
191  //
192  // 0 = full newton , one level (as though two-level weren't being used)
193  // This is probably the best algorithm for transient.
194  //
195  // 1 = full newton outter loop, device pde newton inner loop.
196  //
197  // 2 = full newton outter loop, with pde device inner loop and
198  // continuation. Sort of a 3-level.
199  //
200  // 3 = ckt only outter loop, with pde device inner loop, which uses
201  // continuation. This is sort of a 3-level Newton. This is
202  // the best algorithm for DCOP.
203  //
205  int twoLevelAlgorithmTran_; // same, but for transient.
206 
207  // this flag indicates if the current solve iteration is of the
208  // outer loop or the inner loop.
210 
212 
215  bool noxFlag_;
217 
218  // inner loop statistics vars:
224  unsigned int totalNumLinearIters_;
228 
230 
231  std::vector<int> numInterfaceNodes_;
232 
234 
235  N_LAS_Vector *savedRHSPtr_;
236  N_LAS_Vector *savedNextSolPtr_;
237  N_LAS_Vector *jdxpVectorPtr_;
238 
244 
246 
248 
250 
251  // continuation parameters used for algorithm 4. (not the
252  // continuationLoop_ function, that's different)
253  std::vector<std::string> paramNameList;
254  std::vector<double> paramFinalVal;
255  std::vector<double> paramCurrentVal;
256 
257  // These options are saved in case they have to be modified
258  // over the course of the solve.
259  N_UTL_OptionBlock innerSolverOptions_;
260  N_UTL_OptionBlock innerLocaOptions_;
261  N_UTL_OptionBlock outerLocaOptions_;
262 
263  // voltage limiter tolerance:
264  double voltLimTol_;
265 };
266 
267 //-----------------------------------------------------------------------------
268 // Function : N_NLS_TwoLevelNewton::getContStepNumber
269 // Purpose : returns the current continuation step number.
270 // Special Notes :
271 // Scope : private
272 // Creator : Eric R. Keiter, SNL, Compuational Sciences
273 // Creation Date : 10/24/02
274 //-----------------------------------------------------------------------------
276 {
277  return contStep_;
278 }
279 
280 //-----------------------------------------------------------------------------
281 // Function : N_NLS_TwoLevelNewton::isFirstSolveComplete
282 // Purpose :
283 // Special Notes :
284 // Scope : private
285 // Creator : Dave Shirley, PSSI
286 // Creation Date : 06/22/06
287 //-----------------------------------------------------------------------------
289 {
290  return true;
291 }
292 
293 #ifdef Xyce_DEBUG_NONLINEAR
294 //-----------------------------------------------------------------------------
295 // Function : N_NLS_TwoLevelNewton::getDebugLevel
296 // Purpose :
297 // Special Notes :
298 // Scope : private
299 // Creator : Eric Keiter, SNL
300 // Creation Date : 09/17/07
301 //-----------------------------------------------------------------------------
302 inline int N_NLS_TwoLevelNewton::getDebugLevel () const
303 {
304  return -100;
305 }
306 
307 //-----------------------------------------------------------------------------
308 // Function : N_NLS_TwoLevelNewton::getScreenOutputFlag
309 // Purpose :
310 // Special Notes :
311 // Scope : private
312 // Creator : Eric Keiter, SNL
313 // Creation Date : 09/17/07
314 //-----------------------------------------------------------------------------
315 inline bool N_NLS_TwoLevelNewton::getScreenOutputFlag () const
316 {
317  return false;
318 }
319 
320 //---------------------------------------------------------------------------
321 // Function : N_NLS_TwoLevelNewton::getDebugMinTime
322 //
323 // Return Type : double
324 //---------------------------------------------------------------------------
325 inline double N_NLS_TwoLevelNewton::getDebugMinTime() const
326 {
327  return 0.0;
328 }
329 
330 //---------------------------------------------------------------------------
331 // Function : N_NLS_TwoLevelNewton::getDebugMaxTime
332 //
333 // Return Type : double
334 //---------------------------------------------------------------------------
335 inline double N_NLS_TwoLevelNewton::getDebugMaxTime() const
336 {
337  return N_UTL_MachineDependentParams::DoubleMax();
338 }
339 
340 //---------------------------------------------------------------------------
341 // Function : N_NLS_TwoLevelNewton::getDebugMinTimeStep
342 //
343 // Return Type : int
344 //---------------------------------------------------------------------------
345 inline int N_NLS_TwoLevelNewton::getDebugMinTimeStep() const
346 {
347  return 0;
348 }
349 
350 //---------------------------------------------------------------------------
351 // Function : N_NLS_TwoLevelNewton::getDebugMaxTimeStep
352 //
353 // Return Type : int
354 //---------------------------------------------------------------------------
355 inline int N_NLS_TwoLevelNewton::getDebugMaxTimeStep() const
356 {
357  return N_UTL_MachineDependentParams::IntMax();
358 }
359 
360 //---------------------------------------------------------------------------
361 // Function : N_NLS_TwoLevelNewton::getMMFormat
362 //
363 // Return Type : bool
364 //---------------------------------------------------------------------------
365 inline bool N_NLS_TwoLevelNewton::getMMFormat () const
366 {
367  return false;
368 }
369 
370 #endif // debug nonlin
371 #endif