Xyce  6.1
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-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_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.150 $
43 //
44 // Revision Date : $Date: 2015/07/28 22:21:49 $
45 //
46 // Current Owner : $Author: hkthorn $
47 //-------------------------------------------------------------------------
48 
49 #ifndef Xyce_N_NLS_NonLinearSolver_h
50 #define Xyce_N_NLS_NonLinearSolver_h
51 
52 // ---------- Standard Includes ----------
53 
54 #include <Teuchos_RCP.hpp>
55 using Teuchos::RCP;
56 using Teuchos::rcp;
57 
58 #include <N_UTL_fwd.h>
59 #include <N_ANP_fwd.h>
60 #include <N_IO_fwd.h>
61 #include <N_LAS_fwd.h>
62 #include <N_LOA_fwd.h>
63 #include <N_PDS_fwd.h>
64 #include <N_NLS_fwd.h>
65 #include <N_TIA_fwd.h>
66 
67 #include <N_NLS_ReturnCodes.h>
68 #include <N_NLS_NonLinInfo.h>
69 #include <N_UTL_Stats.h>
70 
71 // ---------- Using Declarations ----------
72 using Teuchos::RCP;
73 
74 namespace Xyce {
75 namespace Nonlinear {
76 
77 //-----------------------------------------------------------------------------
78 // Class : NonLinearSolver
79 // Purpose : Nonlinear Solver Abstract Class
80 // Special Notes : Many of the virtual functions should not, in general,
81 // be redefined in derived classes. Check the Virtual Notes
82 // on each function.
83 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
84 // Creation Date : 5/01/00
85 //-----------------------------------------------------------------------------
87 {
88  friend class ConductanceExtractor;
89  friend class Sensitivity;
90  friend class TwoLevelNewton;
91 
92 public:
93  NonLinearSolver(const IO::CmdParse & cp);
94  virtual ~NonLinearSolver();
95 
96 protected:
98  {
99  return *analysisManager_;
100  }
101 
103  {
104  return *analysisManager_;
105  }
106 
107 public:
108  bool getMatrixFreeFlag() const
109  {
110  return matrixFreeFlag_;
111  }
112 
113  void setMatrixFreeFlag(bool matrixFreeFlag)
114  {
115  matrixFreeFlag_ = matrixFreeFlag;
116  }
117 
118  virtual bool setOptions(const Util::OptionBlock& OB) = 0;
119  virtual bool setTranOptions(const Util::OptionBlock& OB) = 0;
120  virtual bool setHBOptions(const Util::OptionBlock& OB) = 0;
121  virtual bool setNLPOptions(const Util::OptionBlock& OB) = 0;
122  virtual bool setLocaOptions(const Util::OptionBlock& OB);
123  virtual bool setTwoLevelLocaOptions(const Util::OptionBlock& OB);
124  virtual bool setTwoLevelOptions (const Util::OptionBlock& OB);
125  virtual bool setTwoLevelTranOptions(const Util::OptionBlock& OB);
126  virtual bool setLinsolOptions(const Util::OptionBlock& OB);
127  virtual bool setDCOPRestartOptions(const Util::OptionBlock& OB);
128  virtual bool setICOptions(const Util::OptionBlock& OB);
129  virtual bool setNodeSetOptions(const Util::OptionBlock& OB);
130 
131  virtual bool registerLinearSystem(Linear::System* ptr);
132  virtual bool registerAnalysisManager(Analysis::AnalysisManager* tmp_anaIntPtr);
134  virtual bool registerTIADataStore(TimeIntg::DataStore * ptr);
135  virtual bool registerParallelMgr(N_PDS_Manager * ptr);
136 
137  bool registerRHSVector(Linear::Vector* ptr);
139  bool registerParamMgr (ParamMgr * ptr);
140  bool registerPrecondFactory(const Linear::PrecondFactory *ptr);
141  bool registerOutputMgr (IO::OutputMgr * outPtr);
142  bool registerInitialConditionsManager(IO::InitialConditionsManager * outPtr);
143 
144  virtual bool initializeAll();
145 
146  virtual int solve(NonLinearSolver * nlsTmpPtr = NULL) = 0;
147  virtual inline int takeFirstSolveStep (NonLinearSolver * nlsTmpPtr = NULL);
148  virtual inline int takeOneSolveStep ();
149 
150  virtual int getNumIterations() const = 0;
151 
152  virtual int getDebugLevel() const = 0;
153  virtual bool getScreenOutputFlag () const = 0;
154  virtual double getDebugMinTime() const = 0;
155  virtual double getDebugMaxTime() const = 0;
156  virtual int getDebugMinTimeStep() const = 0;
157  virtual int getDebugMaxTimeStep() const = 0;
158  virtual bool getMMFormat () const = 0;
159 
160  virtual bool isFirstContinuationParam() const = 0;
161  virtual bool isFirstSolveComplete() const = 0;
162  virtual int getContinuationStep() const = 0;
163  virtual int getParameterNumber() const = 0;
164 
165  virtual bool getLocaFlag ();
166 
167  virtual inline int getNumResidualLoads();
168  virtual inline int getNumJacobianLoads();
169  virtual inline int getNumLinearSolves();
170  virtual inline int getNumFailedLinearSolves();
171  virtual inline int getNumJacobianFactorizations();
172  virtual inline unsigned int getTotalNumLinearIters();
173  virtual inline double getTotalLinearSolveTime();
174  virtual inline double getTotalResidualLoadTime();
175  virtual inline double getTotalJacobianLoadTime();
176 
178 
179  virtual void setAnalysisMode(AnalysisMode mode) = 0;
180  virtual void resetAll (AnalysisMode mode);
181  virtual void setReturnCodes (const ReturnCodes & retCodesTmp);
182  virtual bool enableSensitivity () {return true;}
183  virtual double getMaxNormF() const = 0;
184  virtual int getMaxNormFindex () const = 0;
185 
186  // use for debugging:
187  void debugOutput1(Linear::Matrix & jacobian, Linear::Vector & rhs);
188  void debugOutput3(Linear::Vector & dxVector, Linear::Vector & xVector);
189 
190  void debugOutputDAE();
191 
192  void debugOutputJDX_VOLTLIM ();
193 
194  void setDebugFlags(int output_step_number, double time);
195 
196  virtual bool applyJacobian(const Linear::Vector& input, Linear::Vector& result);
197 
198 public:
199  // for now.
200 #ifdef Xyce_ROL
201  Linear::Vector* rhsVectorPtr_;
202  Linear::Vector* NewtonVectorPtr_;
203  Linear::Solver * lasSolverPtr_;
204 #endif
205 
206 protected:
207 
208  virtual void resetCountersAndTimers_();
209  virtual bool setX0_();
210  virtual bool rhs_();
211  virtual bool jacobian_();
212  virtual bool newton_();
213  virtual bool gradient_();
214 
215 protected:
216  const IO::CmdParse & commandLine_;
217  std::string netlistFilename_;
218  Linear::Vector** nextSolVectorPtrPtr_;
219  Linear::Vector** currSolVectorPtrPtr_;
220  Linear::Vector** tmpSolVectorPtrPtr_;
221 #ifndef Xyce_ROL
222  Linear::Vector* rhsVectorPtr_;
223 #endif
224 
225  Linear::Matrix* jacTestMatrixPtr_;
226  Linear::Matrix* dFdxTestMatrixPtr_;
227  Linear::Matrix* dQdxTestMatrixPtr_;
228  Linear::Vector* dxVoltlimVectorPtr_;
229  Linear::Vector* jdxVLVectorPtr_; // old-DAE
230  Linear::Vector* fdxVLVectorPtr_; // new-DAE
231  Linear::Vector* qdxVLVectorPtr_; // new-DAE
232 
233  Linear::Matrix* jacobianMatrixPtr_;
234  Linear::Vector* gradVectorPtr_;
235 #ifndef Xyce_ROL
236  Linear::Vector* NewtonVectorPtr_;
237 #endif
238  Linear::Vector* solWtVectorPtr_;
239  Linear::System* lasSysPtr_;
240 #ifndef Xyce_ROL
241  Linear::Solver * lasSolverPtr_;
242 #endif
243  RCP<Linear::Problem> lasProblemRCPtr_;
244  const Linear::PrecondFactory * lasPrecPtr_;
245  Util::OptionBlock* linsolOptionBlockPtr_;
249  IO::OutputMgr * outMgrPtr_;
250  IO::InitialConditionsManager * initialConditionsManager_;
251  N_PDS_Manager * pdsMgrPtr_;
253 
259  unsigned int totalNumLinearIters_;
264 
266 
268 
269 private:
271  int outputStepNumber_; // this is either the time step number or the dc sweep step number,
272  // depending on the mode. It is only used in setting up output file
273  // names.
275 };
276 
277 //---------------------------------------------------------------------------
278 // Function : NonLinearSolver::getNumResidualLoads
279 // Return Type : Integer (Get the total number of residual loads)
280 //---------------------------------------------------------------------------
282 {
283  return numResidualLoads_;
284 }
285 
286 //---------------------------------------------------------------------------
287 // Function : NonLinearSolver::getNumJacobianLoads
288 // Return Type : Integer (Get the total number of Jacobian loads)
289 //---------------------------------------------------------------------------
291 {
292  return numJacobianLoads_;
293 }
294 
295 //---------------------------------------------------------------------------
296 // Function : NonLinearSolver::getNumLinearSolves
297 // Return Type : Integer (total number of successful linear solves)
298 //---------------------------------------------------------------------------
300 {
301  return numLinearSolves_;
302 }
303 
304 //---------------------------------------------------------------------------
305 // Function : NonLinearSolver::getNumFailedLinearSolves
306 // Return Type : Integer (total number of failed linear solves)
307 //---------------------------------------------------------------------------
309 {
310  return numFailedLinearSolves_;
311 }
312 
313 //---------------------------------------------------------------------------
314 // Function : NonLinearSolver::getNumJacobianFactorizations
315 // Return Type : Integer (total number of Jacobian factorizations)
316 //---------------------------------------------------------------------------
318 {
320 }
321 
322 //---------------------------------------------------------------------------
323 // Function : NonLinearSolver::getTotalNumLinearIters
324 // Return Type : unsigned int (total number of iterative linear solver
325 // iterations)
326 //---------------------------------------------------------------------------
328 {
329  return totalNumLinearIters_;
330 }
331 
332 //---------------------------------------------------------------------------
333 // Function : NonLinearSolver::getTotalLinearSolveTime
334 // Return Type : double (total linear solve time in seconds)
335 //---------------------------------------------------------------------------
337 {
338  return totalLinearSolveTime_;
339 }
340 
341 //---------------------------------------------------------------------------
342 // Function : NonLinearSolver::getTotalResidualLoadTime
343 // Return Type : double (total residual load (claculation) time in seconds)
344 //---------------------------------------------------------------------------
346 {
347  return totalResidualLoadTime_;
348 }
349 
350 //---------------------------------------------------------------------------
351 // Function : NonLinearSolver::getTotalJacobianLoadTime
352 // Return Type : double (total Jacobian load (claculation) time in seconds)
353 //---------------------------------------------------------------------------
355 {
356  return totalJacobianLoadTime_;
357 }
358 
359 //---------------------------------------------------------------------------
360 // Function : NonLinearSolver::takeFirstSolveStep
361 // Return Type : int
362 //---------------------------------------------------------------------------
364  NonLinearSolver * nlsTmpPtr)
365 {
366  return -1;
367 }
368 
369 //---------------------------------------------------------------------------
370 // Function : NonLinearSolver::takeOneSolveStep
371 // Return Type : int
372 //---------------------------------------------------------------------------
374 {
375  return -1;
376 }
377 
378 //---------------------------------------------------------------------------
379 // Function : NonLinearSolver::resetAll
380 // Return Type : void
381 //---------------------------------------------------------------------------
383 {
384  setAnalysisMode(mode);
385 }
386 //-----------------------------------------------------------------------------
387 // Function : NonLinearSolver::setReturnCodes
388 // Purpose : Allows the user to set return codes.
389 //
390 // Special Notes : This was put in place mainly to help with continuation
391 // solves. If running continuation, I don't want the
392 // solver to consider "nearConvergence" to be a success.
393 // There are other circumstances that I may wish to turn
394 // this off as well. For example, if running with the
395 // predictor/corrector step error control turned off (this
396 // is an option), I also would not want "nearConverged" to
397 // be good enough.
398 //
399 // The rational for having a "nearConverged" option is the
400 // idea that we can just let the time integrator handle
401 // things and let it use the predictor/corrector stuff to
402 // determine whether or not to reject the step. If that
403 // stuff is turned off, you otherwise unavailable, you
404 // don't want to do this.
405 //
406 // This way, the calling code can, if it wants, decide for
407 // itself what senarios will be considered a solver success.
408 //
409 // Scope : public
410 // Creator : Eric R. Keiter, 9233
411 // Creation Date : 10/30/04
412 //-----------------------------------------------------------------------------
413 inline void
415  const ReturnCodes & ret_codes)
416 {
417  retCodes_ = ret_codes;
418 }
419 
420 //-----------------------------------------------------------------------------
421 // Function : NonLinearSolver::getLocaFlag
422 // Purpose :
423 // Special Notes :
424 // Scope : public
425 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
426 // Creation Date : 3/09/05
427 //-----------------------------------------------------------------------------
429 {
430  return false;
431 }
432 
433 } // namespace Nonlinear
434 } // namespace Xyce
435 
436 #endif
437 
virtual int getMaxNormFindex() const =0
virtual bool isFirstContinuationParam() const =0
void debugOutput3(Linear::Vector &dxVector, Linear::Vector &xVector)
void setMatrixFreeFlag(bool matrixFreeFlag)
virtual bool setTwoLevelLocaOptions(const Util::OptionBlock &OB)
virtual int getContinuationStep() const =0
virtual int solve(NonLinearSolver *nlsTmpPtr=NULL)=0
virtual bool setTranOptions(const Util::OptionBlock &OB)=0
virtual bool setTwoLevelOptions(const Util::OptionBlock &OB)
virtual int takeFirstSolveStep(NonLinearSolver *nlsTmpPtr=NULL)
virtual bool setNodeSetOptions(const Util::OptionBlock &OB)
Pure virtual class to augment a linear system.
virtual bool setNLPOptions(const Util::OptionBlock &OB)=0
virtual bool applyJacobian(const Linear::Vector &input, Linear::Vector &result)
virtual double getMaxNormF() const =0
virtual void setReturnCodes(const ReturnCodes &retCodesTmp)
virtual bool setICOptions(const Util::OptionBlock &OB)
virtual void resetAll(AnalysisMode mode)
virtual int getDebugLevel() const =0
NonLinearSolver(const IO::CmdParse &cp)
const Analysis::AnalysisManager & getAnalysisManager() const
virtual bool isFirstSolveComplete() const =0
void setDebugFlags(int output_step_number, double time)
virtual bool getScreenOutputFlag() const =0
void debugOutput1(Linear::Matrix &jacobian, Linear::Vector &rhs)
bool registerTwoLevelSolver(TwoLevelNewton *ptr)
virtual unsigned int getTotalNumLinearIters()
const Linear::PrecondFactory * lasPrecPtr_
bool registerInitialConditionsManager(IO::InitialConditionsManager *outPtr)
virtual TwoLevelNewtonMode getCouplingMode()
bool registerPrecondFactory(const Linear::PrecondFactory *ptr)
Analysis::AnalysisManager & getAnalysisManager()
virtual double getDebugMinTime() const =0
virtual int getDebugMinTimeStep() const =0
Analysis::AnalysisManager * analysisManager_
Loader::NonlinearEquationLoader * nonlinearEquationLoader_
virtual bool registerTIADataStore(TimeIntg::DataStore *ptr)
virtual bool getMMFormat() const =0
virtual int getDebugMaxTimeStep() const =0
virtual bool registerLinearSystem(Linear::System *ptr)
virtual bool setLinsolOptions(const Util::OptionBlock &OB)
IO::InitialConditionsManager * initialConditionsManager_
virtual bool registerParallelMgr(N_PDS_Manager *ptr)
virtual bool registerAnalysisManager(Analysis::AnalysisManager *tmp_anaIntPtr)
virtual int getParameterNumber() const =0
virtual void setAnalysisMode(AnalysisMode mode)=0
virtual bool setHBOptions(const Util::OptionBlock &OB)=0
virtual double getDebugMaxTime() const =0
bool registerOutputMgr(IO::OutputMgr *outPtr)
bool registerRHSVector(Linear::Vector *ptr)
virtual bool setDCOPRestartOptions(const Util::OptionBlock &OB)
virtual bool setOptions(const Util::OptionBlock &OB)=0
virtual int getNumIterations() const =0
virtual bool registerNonlinearEquationLoader(Loader::NonlinearEquationLoader *ptr)
virtual bool setTwoLevelTranOptions(const Util::OptionBlock &OB)
virtual bool setLocaOptions(const Util::OptionBlock &OB)