Xyce  6.1
N_ANP_AnalysisBase.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_ANP_AnalysisBase.h,v $
27 //
28 // Purpose : Base class for Analysis types
29 //
30 // Special Notes : Specify any "hidden" or subtle details of the class here.
31 // Portability details, error handling information, etc.
32 //
33 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
34 //
35 // Creation Date : 01/24/08
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.74 $
41 //
42 // Revision Date : $Date: 2015/10/27 19:24:39 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_ANP_AnalysisBase_h
48 #define Xyce_N_ANP_AnalysisBase_h
49 
50 #include <N_ANP_fwd.h>
51 #include <N_DEV_fwd.h>
52 #include <N_IO_fwd.h>
53 #include <N_LAS_fwd.h>
54 #include <N_LOA_fwd.h>
55 #include <N_NLS_fwd.h>
56 #include <N_TIA_fwd.h>
57 #include <N_TOP_fwd.h>
58 #include <N_UTL_fwd.h>
59 
60 #include <N_UTL_JSON.h>
61 #include <N_UTL_Stats.h>
62 
63 namespace Xyce {
64 namespace Analysis {
65 
66 struct StatCounts
67 {
68  StatCounts();
69  StatCounts &operator+=(const StatCounts &stats);
70 
71  unsigned int successfulStepsTaken_; ///< Number of consecutive successful time-integration steps.
73  unsigned int failedStepsAttempted_; ///< Total number of failed time-integration steps.
74  unsigned int jacobiansEvaluated_;
76  unsigned int linearSolves_;
77  unsigned int failedLinearSolves_;
78  unsigned int linearIters_;
79  unsigned int residualEvaluations_;
84 };
85 
86 Util::JSON &operator<<(Util::JSON &json, const StatCounts &s);
87 
89 {
90 public:
92  {}
93 
94  virtual ~ProcessorBase()
95  {}
96 };
97 
98 
99 //-------------------------------------------------------------------------
100 // Class : AnalysisBase
101 // Purpose : Base class for common analysis functions
102 // Special Notes :
103 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
104 // Creation Date : 01/24/08
105 //-------------------------------------------------------------------------
107 {
108 public:
109  AnalysisBase(AnalysisManager &analysis_manager, const char *name);
110  virtual ~AnalysisBase();
111 
112 private:
113  AnalysisBase(const AnalysisBase &); ///< No copying
114  AnalysisBase &operator=(const AnalysisBase &); ///< No assignment
115 
116 public:
117  void setTranStepNumber(int step)
118  {
119  tranStepNumber = step;
120  }
121 
123  {
124  return tranStepNumber;
125  }
126 
128  {
129  return stepNumber;
130  }
131 
132  void setStepNumber(int step)
133  {
134  stepNumber=step;
135  }
136 
137  virtual const TimeIntg::TIAParams &getTIAParams() const = 0;
138  virtual TimeIntg::TIAParams &getTIAParams() = 0;
139 
140  virtual bool outputFailureStats(std::ostream &os) {return true;}
141 
142  bool run();
143  bool init();
144  bool processSuccessfulStep();
145  bool processFailedStep();
146  bool finish();
147  bool handlePredictor();
148 
149 protected:
150  virtual bool doRun() = 0;
151  virtual bool doInit() = 0;
152  virtual bool doProcessSuccessfulStep() = 0;
153  virtual bool doProcessFailedStep() = 0;
154  virtual bool doFinish() = 0;
155  virtual bool doHandlePredictor() = 0;
156 
157 public:
158  //-----------------------------------------------------------------------------
159  // Function : AnalysisBase::printStepHeader()
160  // Purpose : Prints out step information.
161  // Special Notes :
162  // Scope : public
163  // Creator : Eric Keiter, SNL, Parallel Computational Sciences
164  // Creation Date : 6/26/00
165  //-----------------------------------------------------------------------------
166  virtual void printStepHeader(std::ostream &os)
167  {}
168 
169  //-----------------------------------------------------------------------------
170  // Function : AnalysisBase::printProgress()
171  // Purpose : Outputs run completion percentage and estimated
172  // time-to-completion.
173  // Special Notes :
174  // Scope : public
175  // Creator : Scott A. Hutchinson, SNL, Computational Sciences
176  // Creation Date : 06/07/2002
177  //-----------------------------------------------------------------------------
178  virtual void printProgress(std::ostream &os)
179  {}
180 
181  // Two Level specific
182  virtual bool twoLevelStep() { return true; }
183 
184  virtual bool isAnalysis(int analysis_type) const { return false; }
185 
186  // functions related to PDE problems requiring two DCOP solves
187  bool getDoubleDCOPEnabled() const
188  {
189  return doubleDCOPEnabled_;
190  }
191 
192  void setDoubleDCOPEnabled(bool enable)
193  {
194  doubleDCOPEnabled_ = enable;
195  }
196 
197  virtual bool getDCOPFlag() const = 0;
198 
199  virtual int getDoubleDCOPStep() const
200  {
201  return doubleDCOPStep_;
202  }
203 
204  //-----------------------------------------------------------------------------
205  // Function : AnalysisBase::firstDoubleDCOPStep
206  // Purpose : If the current step is the first step of
207  // a "doubleDCOP", then return "true".
208  //
209  // Explanation:
210  //
211  // If there are PDE semiconductor devices as part of this problem,
212  // there may need to be a "double-pass"
213  //
214  // first pass = nonlinear poisson solution
215  // second pass = drift diffusion solution
216  //
217  // Special Notes : Only PDE problems can ever return true.
218  // Scope :
219  // Creator : Eric Keiter, SNL, Parallel Computational Sciences
220  // Creation Date : 11/21/04
221  //-----------------------------------------------------------------------------
222  bool firstDoubleDCOPStep() const
223  {
225  }
226 
228  {
230  }
231 
232  bool setDCOPOption(const Util::Param &param);
233 
234  bool getNOOP() const
235  {
236  return NOOP_;
237  }
238 
239  void setNOOP(bool noop)
240  {
241  NOOP_ = noop;
242  }
243 
244  virtual bool printLoopInfo(int start, int finish);
245 
247  {
248  beginningIntegration = bif;
249  }
250 
252  {
253  return beginningIntegration;
254  }
255 
256  void setIntegrationMethod(int im)
257  {
259  }
260 
262  {
263  return baseIntegrationMethod_;
264  }
265 
266  void setInputOPFlag(bool initial_conditions_loaded)
267  {
268  inputOPFlag_ = initial_conditions_loaded;
269  }
270 
271  bool getInputOPFlag() const
272  {
273  return inputOPFlag_;
274  }
275 
276  bool resetForStepAnalysis();
277  void resetAll();
278  int saveLoopInfo ();
279 
280  // step statistic functions
281  double getTotalLinearSolutionTime() const;
282  double getTotalResidualLoadTime() const;
283  double getTotalJacobianLoadTime() const;
284 
285  const StatCounts &getStatCounts(int index = -1) const
286  {
287  if (index == -1)
288  return saveStatCountsVector_.back();
289  else
290  return saveStatCountsVector_[index];
291  }
292 
293  const char *getName() const
294  {
295  return name_;
296  }
297 
298 private:
299  const char * name_;
300  bool NOOP_; ///< if true, disable DCOP
301  bool inputOPFlag_; ///< true if starting from an initial condition.
302  bool doubleDCOPEnabled_; ///< true if doing a double-DCOP is possible.
303  int doubleDCOPStep_; ///< current step in the DCOP loop.
306 
307 protected:
309  unsigned int baseIntegrationMethod_; ///< Current time-integration method flag.
310 
311  // NOTE: For now tranStepNumber is the same as stepNumber, but later I will
312  // change it. stepNumber will later include both dcop and tran steps.
313  // I haven't changed it yet b/c I need to check what devices call
314  // getStepNumber, and what they expect to get.
315  unsigned int stepNumber; ///< Time-integration step number counter.
316 
317 protected:
318  unsigned int tranStepNumber;
319 
320 
321  std::vector<StatCounts> saveStatCountsVector_;
322 
323 public:
325 };
326 
327 StatCounts operator-(const StatCounts &s0, const StatCounts &s1);
328 
329 //-----------------------------------------------------------------------------
331 {
333 }
334 
335 //-----------------------------------------------------------------------------
337 {
338  return stats_.residualLoadTime_;
339 }
340 
341 //-----------------------------------------------------------------------------
343 {
344  return stats_.jacobianLoadTime_;
345 }
346 
347 void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status);
348 
349 } // namespace Analysis
350 } // namespace Xyce
351 
352 
353 #endif // Xyce_N_ANP_AnalysisBase_h
virtual const TimeIntg::TIAParams & getTIAParams() const =0
unsigned int successfulStepsTaken_
Number of consecutive successful time-integration steps.
virtual bool doProcessSuccessfulStep()=0
Pure virtual class to augment a linear system.
unsigned int iterationMatrixFactorizations_
int doubleDCOPStep_
current step in the DCOP loop.
unsigned int stepNumber
Time-integration step number counter.
double getTotalLinearSolutionTime() const
void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
Util::JSON & operator<<(Util::JSON &json, const StatCounts &s)
void setBeginningIntegrationFlag(bool bif)
virtual bool doHandlePredictor()=0
virtual int getDoubleDCOPStep() const
unsigned int failedStepsAttempted_
Total number of failed time-integration steps.
StatCounts & operator+=(const StatCounts &stats)
AnalysisBase & operator=(const AnalysisBase &)
No assignment.
virtual bool isAnalysis(int analysis_type) const
bool setDCOPOption(const Util::Param &param)
virtual bool getDCOPFlag() const =0
virtual void printStepHeader(std::ostream &os)
double getTotalJacobianLoadTime() const
virtual bool doProcessFailedStep()=0
virtual bool printLoopInfo(int start, int finish)
StatCounts operator-(const StatCounts &s0, const StatCounts &s1)
void setDoubleDCOPEnabled(bool enable)
bool inputOPFlag_
true if starting from an initial condition.
double getTotalResidualLoadTime() const
bool doubleDCOPEnabled_
true if doing a double-DCOP is possible.
const StatCounts & getStatCounts(int index=-1) const
void setInputOPFlag(bool initial_conditions_loaded)
unsigned int baseIntegrationMethod_
Current time-integration method flag.
AnalysisBase(AnalysisManager &analysis_manager, const char *name)
virtual bool outputFailureStats(std::ostream &os)
unsigned int nonlinearConvergenceFailures_
virtual void printProgress(std::ostream &os)
std::vector< StatCounts > saveStatCountsVector_
const char * getName() const
bool NOOP_
if true, disable DCOP