Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NonLinearSolver.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_NonLinearSolver.h,v $
27 //
28 // Purpose : Specification file which declares an interface common to
29 // all supported nonlinear solver algorithms. The Manager
30 // class uses this interface to call a concrete algorithm.
31 //
32 // Special Notes : This is the "Strategy" class in the Strategy design
33 // pattern.
34 //
35 // Creator : Scott A. Hutchinson, SNL, Parallel Computational Sciences
36 //
37 // Creation Date : 04/28/00
38 //
39 // Revision Information:
40 // ---------------------
41 //
42 // Revision Number: $Revision: 1.118 $
43 //
44 // Revision Date : $Date: 2014/08/07 23:08:54 $
45 //
46 // Current Owner : $Author: dgbaur $
47 //-------------------------------------------------------------------------
48 
49 #ifndef Xyce_N_NLS_NonLinearSolver_h
50 #define Xyce_N_NLS_NonLinearSolver_h
51 
52 // ---------- Standard Includes ----------
53 
54 #include <Teuchos_RefCountPtr.hpp>
55 using Teuchos::RefCountPtr;
56 using Teuchos::rcp;
57 
58 // ---------- Xyce Includes ----------
59 
60 #include <N_NLS_Manager.h> // for definition of AnalysisMode
61 #include <N_UTL_Misc.h>
62 #include <N_UTL_fwd.h>
63 #include <N_ANP_fwd.h>
64 #include <N_IO_fwd.h>
65 #include <N_NLS_fwd.h>
66 #include <N_NLS_ReturnCodes.h>
67 #include <N_NLS_NonLinInfo.h>
68 #include <N_TOP_Topology.h>
69 
70 // ---------- Forward Declarations ----------
71 
72 class N_LAS_Vector;
73 class N_LAS_Matrix;
74 class N_LAS_System;
75 
76 class N_LAS_Solver;
77 class N_LAS_Problem;
78 
79 class N_LOA_Loader;
80 
81 class N_LAS_PrecondFactory;
82 
83 class N_PDS_Manager;
84 
85 // ---------- Using Declarations ----------
86 using Teuchos::RefCountPtr;
87 
88 namespace Xyce {
89 namespace Nonlinear {
90 
91 //-----------------------------------------------------------------------------
92 // Class : NonLinearSolver
93 // Purpose : Nonlinear Solver Abstract Class
94 // Special Notes : Many of the virtual functions should not, in general,
95 // be redefined in derived classes. Check the Virtual Notes
96 // on each function.
97 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
98 // Creation Date : 5/01/00
99 //-----------------------------------------------------------------------------
101 {
102 
103 public:
104 
105  NonLinearSolver(N_IO_CmdParse & cp);
106  virtual ~NonLinearSolver();
107 
108  virtual bool setOptions(const N_UTL_OptionBlock& OB) = 0;
109  virtual bool setTranOptions(const N_UTL_OptionBlock& OB) = 0;
110  virtual bool setHBOptions(const N_UTL_OptionBlock& OB) = 0;
111  virtual bool setLocaOptions(const N_UTL_OptionBlock& OB);
112  virtual bool setTwoLevelLocaOptions(const N_UTL_OptionBlock& OB);
113  virtual bool setTwoLevelOptions (const N_UTL_OptionBlock& OB);
114  virtual bool setTwoLevelTranOptions(const N_UTL_OptionBlock& OB);
115  virtual bool setPetraOptions(const N_UTL_OptionBlock& OB);
116  virtual bool setDCOPRestartOptions(const N_UTL_OptionBlock& OB);
117  virtual bool setICOptions(const N_UTL_OptionBlock& OB);
118  virtual bool setNodeSetOptions(const N_UTL_OptionBlock& OB);
119 
120  virtual bool registerRHSVector(N_LAS_Vector* ptr);
121  virtual bool registerLoader(N_LOA_Loader* ptr);
122  virtual bool registerLinearSystem(N_LAS_System* ptr);
123  virtual bool registerTwoLevelSolver (TwoLevelNewton * ptr);
124  virtual bool registerParamMgr (ParamMgr * ptr);
125  virtual bool registerTopology(N_TOP_Topology * ptr);
126  virtual bool registerPrecondFactory(const RefCountPtr<N_LAS_PrecondFactory>& ptr);
127  virtual bool registerParallelMgr(N_PDS_Manager * pdsMgrPtr);
128  virtual bool registerAnalysisManager(N_ANP_AnalysisManager* tmp_anaIntPtr);
129  virtual bool registerOutputMgr (N_IO_OutputMgr * outPtr);
130  virtual bool registerTIADataStore(N_TIA_DataStore * tiaDSPtr);
131 
132  virtual bool initializeAll();
133 
134  virtual int solve (NonLinearSolver * nlsTmpPtr = NULL) = 0;
135  virtual inline int takeFirstSolveStep (NonLinearSolver * nlsTmpPtr = NULL);
136  virtual inline int takeOneSolveStep ();
137 
138  virtual int getNumIterations() const = 0;
139 #ifdef Xyce_DEBUG_NONLINEAR
140  virtual int getDebugLevel() const = 0;
141  virtual bool getScreenOutputFlag () const=0;
142  virtual double getDebugMinTime() const = 0;
143  virtual double getDebugMaxTime() const = 0;
144  virtual int getDebugMinTimeStep() const = 0;
145  virtual int getDebugMaxTimeStep() const = 0;
146  virtual bool getMMFormat () const = 0;
147 #endif
148 
149  virtual bool isFirstContinuationParam() const = 0;
150  virtual bool isFirstSolveComplete() const = 0;
151  virtual int getContinuationStep() const = 0;
152  virtual int getParameterNumber() const = 0;
153 
154  virtual bool getLocaFlag ();
155 
156  virtual inline int getNumResidualLoads();
157  virtual inline int getNumJacobianLoads();
158  virtual inline int getNumLinearSolves();
159  virtual inline int getNumFailedLinearSolves();
160  virtual inline int getNumJacobianFactorizations();
161  virtual inline unsigned int getTotalNumLinearIters();
162  virtual inline double getTotalLinearSolveTime();
163  virtual inline double getTotalResidualLoadTime();
164  virtual inline double getTotalJacobianLoadTime();
165 
167 
168  virtual void setAnalysisMode(AnalysisMode mode) = 0;
169  virtual void resetAll (AnalysisMode mode);
170  virtual void setReturnCodes (const ReturnCodes & retCodesTmp);
171  virtual bool enableSensitivity () {return true;}
172  virtual bool getMatrixFreeFlag();
173  virtual void setMatrixFreeFlag(bool matrixFreeFlag);
174 
175  virtual double getMaxNormF() const = 0;
176  virtual int getMaxNormFindex () const = 0;
177 
178 #ifdef Xyce_DEBUG_NONLINEAR
179  // use for debugging:
180  void debugOutput1 (N_LAS_Matrix & jacobian, N_LAS_Vector & rhs);
181  void debugOutput3 (N_LAS_Vector & dxVector, N_LAS_Vector & xVector);
182 
183  void debugOutputDAE();
184 
185 #ifdef Xyce_DEBUG_VOLTLIM
186  void debugOutputJDX_VOLTLIM ();
187 #endif
188 
189  void setDebugFlags ();
190 #endif
191 
192  virtual bool applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result);
193 
194 protected:
195 
196  virtual void resetCountersAndTimers_();
197  virtual bool setX0_();
198  virtual bool rhs_();
199  virtual bool jacobian_();
200  virtual bool newton_();
201  virtual bool gradient_();
202 
203 protected:
204 
205  std::string netlistFileName_;
206  N_LAS_Vector** nextSolVectorPtrPtr_;
207  N_LAS_Vector** currSolVectorPtrPtr_;
208  N_LAS_Vector** tmpSolVectorPtrPtr_;
209  N_LAS_Vector* rhsVectorPtr_;
210 
211 #ifdef Xyce_DEBUG_VOLTLIM
212  N_LAS_Matrix* jacTestMatrixPtr_;
213  N_LAS_Matrix* dFdxTestMatrixPtr_;
214  N_LAS_Matrix* dQdxTestMatrixPtr_;
215  N_LAS_Vector* dxVoltlimVectorPtr_;
216  N_LAS_Vector* jdxVLVectorPtr_; // old-DAE
217  N_LAS_Vector* fdxVLVectorPtr_; // new-DAE
218  N_LAS_Vector* qdxVLVectorPtr_; // new-DAE
219 #endif
220 
221  N_LAS_Matrix* jacobianMatrixPtr_;
222  N_LAS_Vector* gradVectorPtr_;
223  N_LAS_Vector* NewtonVectorPtr_;
224  N_LAS_Vector* solWtVectorPtr_;
225  N_LAS_System* lasSysPtr_;
226  N_LAS_Solver * lasSolverPtr_;
227  RefCountPtr<N_LAS_Problem> lasProblemRCPtr_;
228  RefCountPtr<N_LAS_PrecondFactory> lasPrecPtr_;
229  N_UTL_OptionBlock* petraOptionBlockPtr_;
230  N_LOA_Loader* loaderPtr_;
234  N_IO_OutputMgr * outMgrPtr_;
235  Teuchos::RefCountPtr<N_TOP_Topology> topologyRcp_;
236  N_PDS_Manager * pdsMgrPtr_;
238 
244  unsigned int totalNumLinearIters_;
250 
251  N_IO_CmdParse & commandLine_;
252 
253  friend class ConductanceExtractor;
254  friend class Sensitivity;
255  friend class TwoLevelNewton;
256  friend class Manager;
257 
258  int outputStepNumber_; // this is either the time step number or the dc
259  // sweep step number, depending on the mode. It
260  // is only used in setting up output file names.
262 
264 };
265 
266 //---------------------------------------------------------------------------
267 // Function : NonLinearSolver::getNumResidualLoads
268 // Return Type : Integer (Get the total number of residual loads)
269 //---------------------------------------------------------------------------
271 {
272  return numResidualLoads_;
273 }
274 
275 //---------------------------------------------------------------------------
276 // Function : NonLinearSolver::getNumJacobianLoads
277 // Return Type : Integer (Get the total number of Jacobian loads)
278 //---------------------------------------------------------------------------
280 {
281  return numJacobianLoads_;
282 }
283 
284 //---------------------------------------------------------------------------
285 // Function : NonLinearSolver::getNumLinearSolves
286 // Return Type : Integer (total number of successful linear solves)
287 //---------------------------------------------------------------------------
289 {
290  return numLinearSolves_;
291 }
292 
293 //---------------------------------------------------------------------------
294 // Function : NonLinearSolver::getNumFailedLinearSolves
295 // Return Type : Integer (total number of failed linear solves)
296 //---------------------------------------------------------------------------
298 {
299  return numFailedLinearSolves_;
300 }
301 
302 //---------------------------------------------------------------------------
303 // Function : NonLinearSolver::getNumJacobianFactorizations
304 // Return Type : Integer (total number of Jacobian factorizations)
305 //---------------------------------------------------------------------------
307 {
309 }
310 
311 //---------------------------------------------------------------------------
312 // Function : NonLinearSolver::getTotalNumLinearIters
313 // Return Type : unsigned int (total number of iterative linear solver
314 // iterations)
315 //---------------------------------------------------------------------------
317 {
318  return totalNumLinearIters_;
319 }
320 
321 //---------------------------------------------------------------------------
322 // Function : NonLinearSolver::getTotalLinearSolveTime
323 // Return Type : double (total linear solve time in seconds)
324 //---------------------------------------------------------------------------
326 {
327  return totalLinearSolveTime_;
328 }
329 
330 //---------------------------------------------------------------------------
331 // Function : NonLinearSolver::getTotalResidualLoadTime
332 // Return Type : double (total residual load (claculation) time in seconds)
333 //---------------------------------------------------------------------------
335 {
336  return totalResidualLoadTime_;
337 }
338 
339 //---------------------------------------------------------------------------
340 // Function : NonLinearSolver::getTotalJacobianLoadTime
341 // Return Type : double (total Jacobian load (claculation) time in seconds)
342 //---------------------------------------------------------------------------
344 {
345  return totalJacobianLoadTime_;
346 }
347 
348 //---------------------------------------------------------------------------
349 // Function : NonLinearSolver::takeFirstSolveStep
350 // Return Type : int
351 //---------------------------------------------------------------------------
353  (NonLinearSolver * nlsTmpPtr)
354 {
355  return -1;
356 }
357 
358 //---------------------------------------------------------------------------
359 // Function : NonLinearSolver::takeOneSolveStep
360 // Return Type : int
361 //---------------------------------------------------------------------------
363 {
364  return -1;
365 }
366 
367 //---------------------------------------------------------------------------
368 // Function : NonLinearSolver::resetAll
369 // Return Type : void
370 //---------------------------------------------------------------------------
372 {
373  setAnalysisMode(mode);
374 }
375 //-----------------------------------------------------------------------------
376 // Function : NonLinearSolver::setReturnCodes
377 // Purpose : Allows the user to set return codes.
378 //
379 // Special Notes : This was put in place mainly to help with continuation
380 // solves. If running continuation, I don't want the
381 // solver to consider "nearConvergence" to be a success.
382 // There are other circumstances that I may wish to turn
383 // this off as well. For example, if running with the
384 // predictor/corrector step error control turned off (this
385 // is an option), I also would not want "nearConverged" to
386 // be good enough.
387 //
388 // The rational for having a "nearConverged" option is the
389 // idea that we can just let the time integrator handle
390 // things and let it use the predictor/corrector stuff to
391 // determine whether or not to reject the step. If that
392 // stuff is turned off, you otherwise unavailable, you
393 // don't want to do this.
394 //
395 // This way, the calling code can, if it wants, decide for
396 // itself what senarios will be considered a solver success.
397 //
398 // Scope : public
399 // Creator : Eric R. Keiter, 9233
400 // Creation Date : 10/30/04
401 //-----------------------------------------------------------------------------
403  (const ReturnCodes & retCodesTmp)
404 {
405  retCodes_ = retCodesTmp;
406 }
407 
408 //-----------------------------------------------------------------------------
409 // Function : NonLinearSolver::getLocaFlag
410 // Purpose :
411 // Special Notes :
412 // Scope : public
413 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
414 // Creation Date : 3/09/05
415 //-----------------------------------------------------------------------------
417 {
418  return false;
419 }
420 
421 } // namespace Nonlinear
422 } // namespace Xyce
423 
425 
426 #endif
427