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.143.2.1 $
43 //
44 // Revision Date : $Date: 2015/04/02 18:20:17 $
45 //
46 // Current Owner : $Author: tvrusso $
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  virtual bool setOptions(const Util::OptionBlock& OB) = 0;
109  virtual bool setTranOptions(const Util::OptionBlock& OB) = 0;
110  virtual bool setHBOptions(const Util::OptionBlock& OB) = 0;
111  virtual bool setLocaOptions(const Util::OptionBlock& OB);
112  virtual bool setTwoLevelLocaOptions(const Util::OptionBlock& OB);
113  virtual bool setTwoLevelOptions (const Util::OptionBlock& OB);
114  virtual bool setTwoLevelTranOptions(const Util::OptionBlock& OB);
115  virtual bool setPetraOptions(const Util::OptionBlock& OB);
116  virtual bool setDCOPRestartOptions(const Util::OptionBlock& OB);
117  virtual bool setICOptions(const Util::OptionBlock& OB);
118  virtual bool setNodeSetOptions(const Util::OptionBlock& OB);
119 
120  bool registerRHSVector(Linear::Vector* ptr);
122  bool registerLinearSystem(Linear::System* ptr);
124  bool registerParamMgr (ParamMgr * ptr);
125  bool registerPrecondFactory(const Linear::PrecondFactory *ptr);
126  bool registerParallelMgr(N_PDS_Manager * pdsMgrPtr);
128  bool registerOutputMgr (IO::OutputMgr * outPtr);
129  bool registerInitialConditionsManager(IO::InitialConditionsManager * outPtr);
130  bool registerTIADataStore(TimeIntg::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 
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 
148  virtual bool isFirstContinuationParam() const = 0;
149  virtual bool isFirstSolveComplete() const = 0;
150  virtual int getContinuationStep() const = 0;
151  virtual int getParameterNumber() const = 0;
152 
153  virtual bool getLocaFlag ();
154 
155  virtual inline int getNumResidualLoads();
156  virtual inline int getNumJacobianLoads();
157  virtual inline int getNumLinearSolves();
158  virtual inline int getNumFailedLinearSolves();
159  virtual inline int getNumJacobianFactorizations();
160  virtual inline unsigned int getTotalNumLinearIters();
161  virtual inline double getTotalLinearSolveTime();
162  virtual inline double getTotalResidualLoadTime();
163  virtual inline double getTotalJacobianLoadTime();
164 
166 
167  virtual void setAnalysisMode(AnalysisMode mode) = 0;
168  virtual void resetAll (AnalysisMode mode);
169  virtual void setReturnCodes (const ReturnCodes & retCodesTmp);
170  virtual bool enableSensitivity () {return true;}
171  virtual bool getMatrixFreeFlag();
172  virtual void setMatrixFreeFlag(bool matrixFreeFlag);
173 
174  virtual double getMaxNormF() const = 0;
175  virtual int getMaxNormFindex () const = 0;
176 
177  // use for debugging:
178  void debugOutput1(Linear::Matrix & jacobian, Linear::Vector & rhs);
179  void debugOutput3(Linear::Vector & dxVector, Linear::Vector & xVector);
180 
181  void debugOutputDAE();
182 
183  void debugOutputJDX_VOLTLIM ();
184 
185  void setDebugFlags(int output_step_number, double time);
186 
187  virtual bool applyJacobian(const Linear::Vector& input, Linear::Vector& result);
188 
189 protected:
190 
191  virtual void resetCountersAndTimers_();
192  virtual bool setX0_();
193  virtual bool rhs_();
194  virtual bool jacobian_();
195  virtual bool newton_();
196  virtual bool gradient_();
197 
198 protected:
199  const IO::CmdParse & commandLine_;
200  std::string netlistFilename_;
201  Linear::Vector** nextSolVectorPtrPtr_;
202  Linear::Vector** currSolVectorPtrPtr_;
203  Linear::Vector** tmpSolVectorPtrPtr_;
204  Linear::Vector* rhsVectorPtr_;
205 
206  Linear::Matrix* jacTestMatrixPtr_;
207  Linear::Matrix* dFdxTestMatrixPtr_;
208  Linear::Matrix* dQdxTestMatrixPtr_;
209  Linear::Vector* dxVoltlimVectorPtr_;
210  Linear::Vector* jdxVLVectorPtr_; // old-DAE
211  Linear::Vector* fdxVLVectorPtr_; // new-DAE
212  Linear::Vector* qdxVLVectorPtr_; // new-DAE
213 
214  Linear::Matrix* jacobianMatrixPtr_;
215  Linear::Vector* gradVectorPtr_;
216  Linear::Vector* NewtonVectorPtr_;
217  Linear::Vector* solWtVectorPtr_;
218  Linear::System* lasSysPtr_;
219  Linear::Solver * lasSolverPtr_;
220  RCP<Linear::Problem> lasProblemRCPtr_;
221  const Linear::PrecondFactory * lasPrecPtr_;
222  Util::OptionBlock* petraOptionBlockPtr_;
226  IO::OutputMgr * outMgrPtr_;
227  IO::InitialConditionsManager * initialConditionsManager_;
228  N_PDS_Manager * pdsMgrPtr_;
230 
236  unsigned int totalNumLinearIters_;
242 
244 
246 
247 private:
249  int outputStepNumber_; // this is either the time step number or the dc sweep step number,
250  // depending on the mode. It is only used in setting up output file
251  // names.
252 };
253 
254 //---------------------------------------------------------------------------
255 // Function : NonLinearSolver::getNumResidualLoads
256 // Return Type : Integer (Get the total number of residual loads)
257 //---------------------------------------------------------------------------
259 {
260  return numResidualLoads_;
261 }
262 
263 //---------------------------------------------------------------------------
264 // Function : NonLinearSolver::getNumJacobianLoads
265 // Return Type : Integer (Get the total number of Jacobian loads)
266 //---------------------------------------------------------------------------
268 {
269  return numJacobianLoads_;
270 }
271 
272 //---------------------------------------------------------------------------
273 // Function : NonLinearSolver::getNumLinearSolves
274 // Return Type : Integer (total number of successful linear solves)
275 //---------------------------------------------------------------------------
277 {
278  return numLinearSolves_;
279 }
280 
281 //---------------------------------------------------------------------------
282 // Function : NonLinearSolver::getNumFailedLinearSolves
283 // Return Type : Integer (total number of failed linear solves)
284 //---------------------------------------------------------------------------
286 {
287  return numFailedLinearSolves_;
288 }
289 
290 //---------------------------------------------------------------------------
291 // Function : NonLinearSolver::getNumJacobianFactorizations
292 // Return Type : Integer (total number of Jacobian factorizations)
293 //---------------------------------------------------------------------------
295 {
297 }
298 
299 //---------------------------------------------------------------------------
300 // Function : NonLinearSolver::getTotalNumLinearIters
301 // Return Type : unsigned int (total number of iterative linear solver
302 // iterations)
303 //---------------------------------------------------------------------------
305 {
306  return totalNumLinearIters_;
307 }
308 
309 //---------------------------------------------------------------------------
310 // Function : NonLinearSolver::getTotalLinearSolveTime
311 // Return Type : double (total linear solve time in seconds)
312 //---------------------------------------------------------------------------
314 {
315  return totalLinearSolveTime_;
316 }
317 
318 //---------------------------------------------------------------------------
319 // Function : NonLinearSolver::getTotalResidualLoadTime
320 // Return Type : double (total residual load (claculation) time in seconds)
321 //---------------------------------------------------------------------------
323 {
324  return totalResidualLoadTime_;
325 }
326 
327 //---------------------------------------------------------------------------
328 // Function : NonLinearSolver::getTotalJacobianLoadTime
329 // Return Type : double (total Jacobian load (claculation) time in seconds)
330 //---------------------------------------------------------------------------
332 {
333  return totalJacobianLoadTime_;
334 }
335 
336 //---------------------------------------------------------------------------
337 // Function : NonLinearSolver::takeFirstSolveStep
338 // Return Type : int
339 //---------------------------------------------------------------------------
341  NonLinearSolver * nlsTmpPtr)
342 {
343  return -1;
344 }
345 
346 //---------------------------------------------------------------------------
347 // Function : NonLinearSolver::takeOneSolveStep
348 // Return Type : int
349 //---------------------------------------------------------------------------
351 {
352  return -1;
353 }
354 
355 //---------------------------------------------------------------------------
356 // Function : NonLinearSolver::resetAll
357 // Return Type : void
358 //---------------------------------------------------------------------------
360 {
361  setAnalysisMode(mode);
362 }
363 //-----------------------------------------------------------------------------
364 // Function : NonLinearSolver::setReturnCodes
365 // Purpose : Allows the user to set return codes.
366 //
367 // Special Notes : This was put in place mainly to help with continuation
368 // solves. If running continuation, I don't want the
369 // solver to consider "nearConvergence" to be a success.
370 // There are other circumstances that I may wish to turn
371 // this off as well. For example, if running with the
372 // predictor/corrector step error control turned off (this
373 // is an option), I also would not want "nearConverged" to
374 // be good enough.
375 //
376 // The rational for having a "nearConverged" option is the
377 // idea that we can just let the time integrator handle
378 // things and let it use the predictor/corrector stuff to
379 // determine whether or not to reject the step. If that
380 // stuff is turned off, you otherwise unavailable, you
381 // don't want to do this.
382 //
383 // This way, the calling code can, if it wants, decide for
384 // itself what senarios will be considered a solver success.
385 //
386 // Scope : public
387 // Creator : Eric R. Keiter, 9233
388 // Creation Date : 10/30/04
389 //-----------------------------------------------------------------------------
390 inline void
392  const ReturnCodes & ret_codes)
393 {
394  retCodes_ = ret_codes;
395 }
396 
397 //-----------------------------------------------------------------------------
398 // Function : NonLinearSolver::getLocaFlag
399 // Purpose :
400 // Special Notes :
401 // Scope : public
402 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
403 // Creation Date : 3/09/05
404 //-----------------------------------------------------------------------------
406 {
407  return false;
408 }
409 
410 } // namespace Nonlinear
411 } // namespace Xyce
412 
413 #endif
414 
virtual int getMaxNormFindex() const =0
virtual bool getScreenOutputFlag() const =0
void debugOutput3(Linear::Vector &dxVector, Linear::Vector &xVector)
bool registerLoader(Loader::NonlinearEquationLoader *ptr)
virtual void setMatrixFreeFlag(bool matrixFreeFlag)
virtual bool setTwoLevelLocaOptions(const Util::OptionBlock &OB)
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)
bool registerTIADataStore(TimeIntg::DataStore *tiaDSPtr)
bool registerParallelMgr(N_PDS_Manager *pdsMgrPtr)
Pure virtual class to augment a linear system.
virtual bool applyJacobian(const Linear::Vector &input, Linear::Vector &result)
virtual int getNumIterations() const =0
virtual double getDebugMaxTime() const =0
virtual void setReturnCodes(const ReturnCodes &retCodesTmp)
virtual bool setICOptions(const Util::OptionBlock &OB)
virtual bool isFirstSolveComplete() const =0
virtual bool isFirstContinuationParam() const =0
virtual void resetAll(AnalysisMode mode)
virtual bool setPetraOptions(const Util::OptionBlock &OB)
NonLinearSolver(const IO::CmdParse &cp)
virtual int getParameterNumber() const =0
virtual int getDebugLevel() const =0
const Analysis::AnalysisManager & getAnalysisManager() const
void setDebugFlags(int output_step_number, double time)
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()
Analysis::AnalysisManager * analysisManager_
virtual bool getMMFormat() const =0
virtual int getContinuationStep() const =0
bool registerLinearSystem(Linear::System *ptr)
virtual int getDebugMaxTimeStep() const =0
IO::InitialConditionsManager * initialConditionsManager_
virtual double getDebugMinTime() const =0
bool registerAnalysisManager(Analysis::AnalysisManager *tmp_anaIntPtr)
virtual void setAnalysisMode(AnalysisMode mode)=0
virtual bool setHBOptions(const Util::OptionBlock &OB)=0
virtual int getDebugMinTimeStep() const =0
Loader::NonlinearEquationLoader * loaderPtr_
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 bool setTwoLevelTranOptions(const Util::OptionBlock &OB)
virtual double getMaxNormF() const =0
virtual bool setLocaOptions(const Util::OptionBlock &OB)