Xyce  6.1
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-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_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.95.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:17 $
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_LAS_fwd.h>
56 #include <N_LOA_fwd.h>
57 #include <N_NLS_NonLinearSolver.h>
58 #include <N_NLS_TwoLevelEnum.h>
59 #include <N_UTL_MachDepParams.h>
60 
61 namespace Xyce {
62 namespace Nonlinear {
63 
64 //-----------------------------------------------------------------------------
65 // Class : TwoLevelNewton
66 // Purpose : This class is the manager for the two level newton
67 // algorithm. Mostly, it will contain a control loop
68 // which repeatedly calls the "true" nonlinear solver
69 // (either DampedNewton's solve, or NOX, depending
70 // on the options specified).
71 //
72 // The idea of two level newton is divide the problem
73 // up into sub-problems and solve them separately
74 // for part or all of the solve.
75 //
76 // The control loop contained in this class repeatedly
77 // loops over all the sub-problems, and also determines
78 // if the total problem has converged.
79 //
80 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
81 // Creation Date : 10/20/02
82 //-----------------------------------------------------------------------------
83 
85 {
86 public:
88  bool noxFlag,
89  bool noxFlagInner,
90  const IO::CmdParse & cp);
92 
93  int getNumIterations() const;
94 
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 
103  int getContinuationStep() const;
104  int getParameterNumber() const;
105  bool isFirstContinuationParam() const;
106  bool isFirstSolveComplete() const;
107 
108  int solve (NonLinearSolver * nlsTmpPtr=NULL);
109  bool setOptions (const Util::OptionBlock & OB);
110  bool setTranOptions (const Util::OptionBlock & OB);
111  bool setHBOptions (const Util::OptionBlock & OB);
112  bool setTwoLevelOptions (const Util::OptionBlock & OB);
113  bool setTwoLevelTranOptions (const Util::OptionBlock & OB);
114  bool setLocaOptions (const Util::OptionBlock& OB);
115  bool setTwoLevelLocaOptions (const Util::OptionBlock& OB);
116  bool registerLinearSystem(Linear::System* ptr);
117  bool registerAnalysisManager (Analysis::AnalysisManager * analysis_manager);
119  bool registerOutputMgr (IO::OutputMgr * ptr);
120  bool initializeAll ();
122  void setAnalysisMode (AnalysisMode mode);
123  bool setPetraOptions (const Util::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:
141  TwoLevelNewton();
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  Linear::Vector *savedRHSPtr_;
236  Linear::Vector *savedNextSolPtr_;
237  Linear::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  Util::OptionBlock innerSolverOptions_;
260  Util::OptionBlock innerLocaOptions_;
261  Util::OptionBlock outerLocaOptions_;
262 
263  // voltage limiter tolerance:
264  double voltLimTol_;
265 };
266 
267 //-----------------------------------------------------------------------------
268 // Function : 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 : 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 //-----------------------------------------------------------------------------
294 // Function : TwoLevelNewton::getDebugLevel
295 // Purpose :
296 // Special Notes :
297 // Scope : private
298 // Creator : Eric Keiter, SNL
299 // Creation Date : 09/17/07
300 //-----------------------------------------------------------------------------
301 inline int TwoLevelNewton::getDebugLevel () const
302 {
303  return -100;
304 }
305 
306 //-----------------------------------------------------------------------------
307 // Function : TwoLevelNewton::getScreenOutputFlag
308 // Purpose :
309 // Special Notes :
310 // Scope : private
311 // Creator : Eric Keiter, SNL
312 // Creation Date : 09/17/07
313 //-----------------------------------------------------------------------------
315 {
316  return false;
317 }
318 
319 //---------------------------------------------------------------------------
320 // Function : TwoLevelNewton::getDebugMinTime
321 //
322 // Return Type : double
323 //---------------------------------------------------------------------------
324 inline double TwoLevelNewton::getDebugMinTime() const
325 {
326  return 0.0;
327 }
328 
329 //---------------------------------------------------------------------------
330 // Function : TwoLevelNewton::getDebugMaxTime
331 //
332 // Return Type : double
333 //---------------------------------------------------------------------------
334 inline double TwoLevelNewton::getDebugMaxTime() const
335 {
336  return Util::MachineDependentParams::DoubleMax();
337 }
338 
339 //---------------------------------------------------------------------------
340 // Function : TwoLevelNewton::getDebugMinTimeStep
341 //
342 // Return Type : int
343 //---------------------------------------------------------------------------
345 {
346  return 0;
347 }
348 
349 //---------------------------------------------------------------------------
350 // Function : TwoLevelNewton::getDebugMaxTimeStep
351 //
352 // Return Type : int
353 //---------------------------------------------------------------------------
355 {
356  return Util::MachineDependentParams::IntMax();
357 }
358 
359 //---------------------------------------------------------------------------
360 // Function : TwoLevelNewton::getMMFormat
361 //
362 // Return Type : bool
363 //---------------------------------------------------------------------------
364 inline bool TwoLevelNewton::getMMFormat () const
365 {
366  return false;
367 }
368 
369 } // namespace Nonlinear
370 } // namespace Xyce
371 
372 #endif
std::vector< std::string > paramNameList
bool setTwoLevelTranOptions(const Util::OptionBlock &OB)
void setAnalysisMode(AnalysisMode mode)
bool registerLinearSystem(Linear::System *ptr)
Pure virtual class to augment a linear system.
bool setTranOptions(const Util::OptionBlock &OB)
bool setTwoLevelLocaOptions(const Util::OptionBlock &OB)
bool setTwoLevelOptions(const Util::OptionBlock &OB)
Analysis::AnalysisManager * analysisManager_
bool setLocaOptions(const Util::OptionBlock &OB)
bool registerAnalysisManager(Analysis::AnalysisManager *analysis_manager)
bool setHBOptions(const Util::OptionBlock &OB)
int solve(NonLinearSolver *nlsTmpPtr=NULL)
bool registerLoader(Loader::NonlinearEquationLoader *ptr)
bool setOptions(const Util::OptionBlock &OB)
virtual unsigned int getTotalNumLinearIters()
bool setPetraOptions(const Util::OptionBlock &OB)
bool registerOutputMgr(IO::OutputMgr *ptr)
void printStepInfo_(int step, int success, TwoLevelNewtonMode solveType)