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.63.2.1 $
41 //
42 // Revision Date : $Date: 2015/04/02 18:20:06 $
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_IO_fwd.h>
52 #include <N_LOA_fwd.h>
53 #include <N_NLS_fwd.h>
54 #include <N_TIA_fwd.h>
55 #include <N_UTL_fwd.h>
56 
57 #include <N_UTL_JSON.h>
58 #include <N_UTL_Stats.h>
59 
60 namespace Xyce {
61 namespace Analysis {
62 
63 struct StatCounts
64 {
65  StatCounts();
66  StatCounts &operator+=(const StatCounts &stats);
67 
68  unsigned int successfulStepsTaken_; ///< Number of consecutive successful time-integration steps.
70  unsigned int failedStepsAttempted_; ///< Total number of failed time-integration steps.
71  unsigned int jacobiansEvaluated_;
73  unsigned int linearSolves_;
74  unsigned int failedLinearSolves_;
75  unsigned int linearIters_;
76  unsigned int residualEvaluations_;
81 };
82 
83 Util::JSON &operator<<(Util::JSON &json, const StatCounts &s);
84 
85 //-------------------------------------------------------------------------
86 // Class : AnalysisBase
87 // Purpose : Base class for common analysis functions
88 // Special Notes :
89 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
90 // Creation Date : 01/24/08
91 //-------------------------------------------------------------------------
93 {
94 public:
95  AnalysisBase(AnalysisManager &analysis_manager, const char *name);
96  virtual ~AnalysisBase();
97 
98 private:
99  AnalysisBase(const AnalysisBase &); ///< No copying
100  AnalysisBase &operator=(const AnalysisBase &); ///< No assignment
101 
102 public:
103  void setTranStepNumber(int step) {
104  tranStepNumber = step;
105  }
106 
108  {
109  return tranStepNumber;
110  }
111 
113  return stepNumber;
114  }
115 
116  void setStepNumber(int step) {
117  stepNumber=step;
118  }
119 
120  virtual const TimeIntg::TIAParams &getTIAParams() const = 0;
121  virtual TimeIntg::TIAParams &getTIAParams() = 0;
122 
123  virtual bool outputFailureStats(std::ostream &os) {return true;}
124 
125  bool run();
126  bool init();
127  bool loopProcess();
128  bool processSuccessfulStep();
129  bool processFailedStep();
130  bool finish();
131  bool handlePredictor();
132 
133  virtual bool doRun() = 0;
134  virtual bool doInit() = 0;
135  virtual bool doLoopProcess() = 0;
136  virtual bool doProcessSuccessfulStep() = 0;
137  virtual bool doProcessFailedStep() = 0;
138  virtual bool doFinish() = 0;
139  virtual bool doHandlePredictor() = 0;
140 
141  //-----------------------------------------------------------------------------
142  // Function : AnalysisBase::printStepHeader()
143  // Purpose : Prints out step information.
144  // Special Notes :
145  // Scope : public
146  // Creator : Eric Keiter, SNL, Parallel Computational Sciences
147  // Creation Date : 6/26/00
148  //-----------------------------------------------------------------------------
149  virtual void printStepHeader(std::ostream &os)
150  {}
151 
152  //-----------------------------------------------------------------------------
153  // Function : AnalysisBase::printProgress()
154  // Purpose : Outputs run completion percentage and estimated
155  // time-to-completion.
156  // Special Notes :
157  // Scope : public
158  // Creator : Scott A. Hutchinson, SNL, Computational Sciences
159  // Creation Date : 06/07/2002
160  //-----------------------------------------------------------------------------
161  virtual void printProgress(std::ostream &os)
162  {}
163 
164  // Two Level specific
165  virtual bool twoLevelStep() { return true; }
166 
167  // Utility function for AnalysisManager to determine if a complex analysis type (like HB)
168  // is performing another type of analysis under the hood. This is necessary for populating
169  // the TimeIntg::TimeIntInfo struct. For straightforward analysis types, this method is not
170  // needed because the AnalysisManager already knows which analysis is being performed.
171  virtual bool isAnalysis(int analysis_type) const { return false; }
172 
173  virtual bool getDCOPFlag() const = 0;
174 
175  virtual int getDoubleDCOPStep() const
176  {
177  return doubleDCOPStep_ ;
178  }
179 
180  virtual bool printLoopInfo(int start, int finish);
181 
183  {
184  beginningIntegration = bif;
185  }
186 
188  {
189  return beginningIntegration;
190  }
191 
192  void setIntegrationMethod(int im)
193  {
195  }
196 
198  {
199  return baseIntegrationMethod_;
200  }
201 
202  void setInputOPFlag(bool initial_conditions_loaded) {
203  inputOPFlag_ = initial_conditions_loaded;
204  }
205 
206  bool getInputOPFlag() const
207  {
208  return inputOPFlag_;
209  }
210 
211  bool resetForStepAnalysis();
212  void resetAll();
213  int saveLoopInfo ();
214 
215  // step statistic functions
216  double getTotalLinearSolutionTime() const;
217  double getTotalResidualLoadTime() const;
218  double getTotalJacobianLoadTime() const;
219 
220  // functions related to PDE problems requiring two DCOP solves
221  bool getDoubleDCOPEnabled() const
222  {
223  return doubleDCOPFlag_;
224  }
225 
226  bool firstDoubleDCOPStep();
227 
228  const StatCounts &getStatCounts(int index = -1) const
229  {
230  if (index == -1)
231  return saveStatCountsVector_.back();
232  else
233  return saveStatCountsVector_[index];
234  }
235 
236  bool setDCOPOption(const Util::Param &param);
237 
238  int getLastDCOPStep() const {
239  return lastDCOPStep_;
240  }
241 
242  int getFirstDCOPStep() const
243  {
244  return firstDCOPStep_;
245  }
246 
247  bool getNOOP() const
248  {
249  return NOOP_;
250  }
251 
252  void setNOOP(bool noop)
253  {
254  NOOP_ = noop;
255  }
256 
257  const char *getName() const
258  {
259  return name_;
260  }
261 
262 
263 
264 private:
265  const char * name_;
266 
267  bool inputOPFlag_; ///< true if starting from an initial condition.
268 
269 protected:
271  unsigned int baseIntegrationMethod_; ///< Current time-integration method flag.
272 
273  // NOTE: For now tranStepNumber is the same as stepNumber, but later I will
274  // change it. stepNumber will later include both dcop and tran steps.
275  // I haven't changed it yet b/c I need to check what devices call
276  // getStepNumber, and what they expect to get.
277  unsigned int stepNumber; ///< Time-integration step number counter.
278 
279 protected:
280  unsigned int tranStepNumber;
281 
282  bool NOOP_;
283  bool doubleDCOPFlag_; ///< true if doing a double-DCOP is possible.
284  int doubleDCOPStep_; ///< current step in the DCOP loop.
287 
288  std::vector<StatCounts> saveStatCountsVector_;
289 
290 public:
292 };
293 
294 StatCounts operator-(const StatCounts &s0, const StatCounts &s1);
295 
296 //-----------------------------------------------------------------------------
298 {
300 }
301 
302 //-----------------------------------------------------------------------------
304 {
305  return stats_.residualLoadTime_;
306 }
307 
308 //-----------------------------------------------------------------------------
310 {
311  return stats_.jacobianLoadTime_;
312 }
313 
314 void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status);
315 
316 } // namespace Analysis
317 } // namespace Xyce
318 
319 
320 #endif // Xyce_N_ANP_AnalysisBase_h
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
virtual const TimeIntg::TIAParams & getTIAParams() const =0
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 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)
bool inputOPFlag_
true if starting from an initial condition.
double getTotalResidualLoadTime() const
const StatCounts & getStatCounts(int index=-1) const
void setInputOPFlag(bool initial_conditions_loaded)
virtual bool doLoopProcess()=0
bool doubleDCOPFlag_
true if doing a double-DCOP is possible.
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_
virtual bool getDCOPFlag() const =0
const char * getName() const