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.100 $
40 //
41 // Revision Date : $Date: 2015/07/28 22:21:49 $
42 //
43 // Current Owner : $Author: hkthorn $
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 setNLPOptions (const Util::OptionBlock & OB);
113  bool setTwoLevelOptions (const Util::OptionBlock & OB);
114  bool setTwoLevelTranOptions (const Util::OptionBlock & OB);
115  bool setLocaOptions (const Util::OptionBlock& OB);
116  bool setTwoLevelLocaOptions (const Util::OptionBlock& OB);
117  bool registerLinearSystem(Linear::System* ptr);
118  bool registerAnalysisManager (Analysis::AnalysisManager * analysis_manager);
120  bool registerParallelMgr(N_PDS_Manager * ptr);
121 
123 
124  bool registerOutputMgr (IO::OutputMgr * ptr);
125  bool initializeAll ();
127  void setAnalysisMode (AnalysisMode mode);
128  bool setLinsolOptions (const Util::OptionBlock & OB);
129  int getContStepNumber ();
130  bool enableSensitivity ();
131 
132  // solver statistics:
133  virtual int getNumResidualLoads();
134  virtual int getNumJacobianLoads();
135  virtual int getNumLinearSolves();
136  virtual int getNumFailedLinearSolves();
137  virtual int getNumJacobianFactorizations();
138  virtual unsigned int getTotalNumLinearIters();
139  virtual double getTotalLinearSolveTime();
140  virtual double getTotalResidualLoadTime();
141  virtual double getTotalJacobianLoadTime();
142 
143  double getMaxNormF() const;
144  int getMaxNormFindex() const;
145 
146 private:
147  TwoLevelNewton();
148 
149  void printStepInfo_(int step, int success, TwoLevelNewtonMode solveType);
150 
151  void zeroInnerLoopStatistics_ ();
152  void calcInnerLoopStatistics_ ();
153 
154  void calcOuterLoopStatistics_ ();
155 
156  bool calcCouplingTerms_ ();
157 
158  int continuationLoop_ ();
159  int locaLoop_ ();
160 
161  int algorithm0_(bool nl_poisson_dcop);
162  int algorithm1_();
163  int algorithm2_();
164  int algorithm3_();
165  int algorithm4_();
166  int algorithm5_();
167 
168 private:
169  // Pointer to the outer loop nonlinear solver that is being used.
171 
172  // Pointer to the inner loop nonlinear solver that is being used.
174 
175  // Pointer to the time integrator that is being used.
177 
178  // number of iterations for the "outer" loop, if it exists. (algorithm>0)
180 
181  // number of iterations for the inner "voltage stepper" loop.
182  // This parameter is kind of irrelevant, if running with variable step
183  // size.
187 
190 
191  // this variable determines which variant of two level newton
192  // is being used.
193  //
194  // Here's the key:
195  //
196  // 0 = full newton , one level (as though two-level weren't being used)
197  // This is probably the best algorithm for transient.
198  //
199  // 1 = full newton outter loop, device pde newton inner loop.
200  //
201  // 2 = full newton outter loop, with pde device inner loop and
202  // continuation. Sort of a 3-level.
203  //
204  // 3 = ckt only outter loop, with pde device inner loop, which uses
205  // continuation. This is sort of a 3-level Newton. This is
206  // the best algorithm for DCOP.
207  //
209  int twoLevelAlgorithmTran_; // same, but for transient.
210 
211  // this flag indicates if the current solve iteration is of the
212  // outer loop or the inner loop.
214 
216 
219  bool noxFlag_;
221 
222  // inner loop statistics vars:
228  unsigned int totalNumLinearIters_;
232 
234 
235  std::vector<int> numInterfaceNodes_;
236 
238 
239  Linear::Vector *savedRHSPtr_;
240  Linear::Vector *savedNextSolPtr_;
241  Linear::Vector *jdxpVectorPtr_;
242 
248 
250 
252 
253  // continuation parameters used for algorithm 4. (not the
254  // continuationLoop_ function, that's different)
255  std::vector<std::string> paramNameList;
256  std::vector<double> paramFinalVal;
257  std::vector<double> paramCurrentVal;
258 
259  // These options are saved in case they have to be modified
260  // over the course of the solve.
261  Util::OptionBlock innerSolverOptions_;
262  Util::OptionBlock innerLocaOptions_;
263  Util::OptionBlock outerLocaOptions_;
264 
265  // voltage limiter tolerance:
266  double voltLimTol_;
267 };
268 
269 //-----------------------------------------------------------------------------
270 // Function : TwoLevelNewton::getContStepNumber
271 // Purpose : returns the current continuation step number.
272 // Special Notes :
273 // Scope : private
274 // Creator : Eric R. Keiter, SNL, Compuational Sciences
275 // Creation Date : 10/24/02
276 //-----------------------------------------------------------------------------
278 {
279  return contStep_;
280 }
281 
282 //-----------------------------------------------------------------------------
283 // Function : TwoLevelNewton::isFirstSolveComplete
284 // Purpose :
285 // Special Notes :
286 // Scope : private
287 // Creator : Dave Shirley, PSSI
288 // Creation Date : 06/22/06
289 //-----------------------------------------------------------------------------
291 {
292  return true;
293 }
294 
295 //-----------------------------------------------------------------------------
296 // Function : TwoLevelNewton::getDebugLevel
297 // Purpose :
298 // Special Notes :
299 // Scope : private
300 // Creator : Eric Keiter, SNL
301 // Creation Date : 09/17/07
302 //-----------------------------------------------------------------------------
303 inline int TwoLevelNewton::getDebugLevel () const
304 {
305  return -100;
306 }
307 
308 //-----------------------------------------------------------------------------
309 // Function : TwoLevelNewton::getScreenOutputFlag
310 // Purpose :
311 // Special Notes :
312 // Scope : private
313 // Creator : Eric Keiter, SNL
314 // Creation Date : 09/17/07
315 //-----------------------------------------------------------------------------
317 {
318  return false;
319 }
320 
321 //---------------------------------------------------------------------------
322 // Function : TwoLevelNewton::getDebugMinTime
323 //
324 // Return Type : double
325 //---------------------------------------------------------------------------
326 inline double TwoLevelNewton::getDebugMinTime() const
327 {
328  return 0.0;
329 }
330 
331 //---------------------------------------------------------------------------
332 // Function : TwoLevelNewton::getDebugMaxTime
333 //
334 // Return Type : double
335 //---------------------------------------------------------------------------
336 inline double TwoLevelNewton::getDebugMaxTime() const
337 {
338  return Util::MachineDependentParams::DoubleMax();
339 }
340 
341 //---------------------------------------------------------------------------
342 // Function : TwoLevelNewton::getDebugMinTimeStep
343 //
344 // Return Type : int
345 //---------------------------------------------------------------------------
347 {
348  return 0;
349 }
350 
351 //---------------------------------------------------------------------------
352 // Function : TwoLevelNewton::getDebugMaxTimeStep
353 //
354 // Return Type : int
355 //---------------------------------------------------------------------------
357 {
358  return Util::MachineDependentParams::IntMax();
359 }
360 
361 //---------------------------------------------------------------------------
362 // Function : TwoLevelNewton::getMMFormat
363 //
364 // Return Type : bool
365 //---------------------------------------------------------------------------
366 inline bool TwoLevelNewton::getMMFormat () const
367 {
368  return false;
369 }
370 
371 } // namespace Nonlinear
372 } // namespace Xyce
373 
374 #endif
std::vector< std::string > paramNameList
bool setTwoLevelTranOptions(const Util::OptionBlock &OB)
void setAnalysisMode(AnalysisMode mode)
bool registerLinearSystem(Linear::System *ptr)
bool registerNonlinearEquationLoader(Loader::NonlinearEquationLoader *ptr)
Pure virtual class to augment a linear system.
bool setTranOptions(const Util::OptionBlock &OB)
bool setTwoLevelLocaOptions(const Util::OptionBlock &OB)
bool setLinsolOptions(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 setOptions(const Util::OptionBlock &OB)
virtual unsigned int getTotalNumLinearIters()
bool registerTIADataStore(TimeIntg::DataStore *ptr)
int algorithm0_(bool nl_poisson_dcop)
bool registerOutputMgr(IO::OutputMgr *ptr)
bool setNLPOptions(const Util::OptionBlock &OB)
void printStepInfo_(int step, int success, TwoLevelNewtonMode solveType)
bool registerParallelMgr(N_PDS_Manager *ptr)