Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.31.2.1 $
41 //
42 // Revision Date : $Date: 2014/08/28 21:00:43 $
43 //
44 // Current Owner : $Author: dgbaur $
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_UTL_fwd.h>
52 #include <N_IO_fwd.h>
53 #include <N_TIA_fwd.h>
54 #include <N_NLS_fwd.h>
55 #include <N_UTL_JSON.h>
56 
57 class N_TIA_Assembler;
58 class N_LAS_System;
59 class N_LOA_Loader;
60 
61 namespace Xyce {
62 namespace Analysis {
63 
64 struct StatCounts
65 {
66  StatCounts();
67  StatCounts &operator+=(const StatCounts &stats);
68 
69  unsigned int successfulStepsTaken_; ///< Number of consecutive successful time-integration steps.
71  unsigned int failedStepsAttempted_; ///< Total number of failed time-integration steps.
72  unsigned int jacobiansEvaluated_;
74  unsigned int linearSolves_;
75  unsigned int failedLinearSolves_;
76  unsigned int linearIters_;
77  unsigned int residualEvaluations_;
82 };
83 
84 Util::JSON &operator<<(Util::JSON &json, const StatCounts &s);
85 
86 //-------------------------------------------------------------------------
87 // Class : AnalysisBase
88 // Purpose : Base class for common analysis functions
89 // Special Notes :
90 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
91 // Creation Date : 01/24/08
92 //-------------------------------------------------------------------------
94 {
95  public:
96  AnalysisBase(AnalysisManager &analysis_manager);
97  virtual ~AnalysisBase();
98 
99  public:
100  virtual bool setAnalysisParams(const Util::OptionBlock & paramsBlock) {return true;}
101  virtual bool outputFailureStats() {return true;}
102 
103  virtual void setParamsWithOutputMgrAdapter(OutputMgrAdapter & outputManagerAdapter) {}
104 
105  virtual int getStepIter () { return 0; }
106  virtual int getStepNumber () { return stepNumber; }
107  virtual void setStepNumber (int step) { stepNumber=step; }
108 
109  virtual void setTranStepNumber (int step) { tranStepNumber=step; }
110  virtual int getTranStepNumber () { return tranStepNumber; }
111 
112  virtual void setSensFlag() {sensFlag_=true;}
113  virtual bool getDCOPFlag() = 0;
114 
115  virtual bool run() = 0;
116  virtual bool init() = 0;
117  virtual bool loopProcess() = 0;
118  virtual bool processSuccessfulStep() = 0;
119  virtual bool processFailedStep() = 0;
120  virtual bool finish() = 0;
121  virtual bool handlePredictor() = 0;
122 
123 
124  //-----------------------------------------------------------------------------
125  // Function : AnalysisBase::printStepHeader()
126  // Purpose : Prints out step information.
127  // Special Notes :
128  // Scope : public
129  // Creator : Eric Keiter, SNL, Parallel Computational Sciences
130  // Creation Date : 6/26/00
131  //-----------------------------------------------------------------------------
132  virtual void printStepHeader(std::ostream &os)
133  {}
134 
135  //-----------------------------------------------------------------------------
136  // Function : AnalysisBase::printProgress()
137  // Purpose : Outputs run completion percentage and estimated
138  // time-to-completion.
139  // Special Notes :
140  // Scope : public
141  // Creator : Scott A. Hutchinson, SNL, Computational Sciences
142  // Creation Date : 06/07/2002
143  //-----------------------------------------------------------------------------
144  virtual void printProgress(std::ostream &os)
145  {}
146 
147  // mixed-signal
148  virtual void preStepDetails(double maxTimeStepFromHabanero) {}
149  virtual bool mixedSignalStep() { return true; }
150  virtual bool finalizeStep() { return true; }
151 
152  // Two Level specific
153  virtual bool twoLevelStep() { return true; }
154 
155  // Utility function for AnalysisManager to determine if a complex analysis type (like HB)
156  // is performing another type of analysis under the hood. This is necessary for populating
157  // the N_TIA_TimeIntInfo struct. For straightforward analysis types, this method is not
158  // needed because the AnalysisManager already knows which analysis is being performed.
159  virtual bool isAnalysis( int analysis_type ) { return false; }
160 
161  virtual bool printLoopInfo(int start, int finish);
162 
163  virtual void setBeginningIntegrationFlag(bool bif) {beginningIntegration = bif;}
165 
166  virtual void setIntegrationMethod (int im) {integrationMethod_= im;}
167  virtual unsigned int getIntegrationMethod () {return integrationMethod_;}
168 
169  virtual bool getInputOPFlag(){return inputOPFlag_;}
170 
171  bool resetForStepAnalysis();
172  void resetAll();
173  int saveLoopInfo ();
174 
175  // step statistic functions
176  void gatherStepStatistics_();
177  double getTotalLinearSolutionTime() const;
178  double getTotalResidualLoadTime() const;
179  double getTotalJacobianLoadTime() const;
180 
181  // functions related to PDE problems requiring two DCOP solves
182  bool getDoubleDCOPEnabled();
183  virtual int getDoubleDCOPStep();
184  bool firstDoubleDCOPStep_();
185 
186  const StatCounts &getStatCounts(int index = -1) const
187  {
188  if (index == -1)
189  return saveStatCountsVector_.back();
190  else
191  return saveStatCountsVector_[index];
192  }
193 
194 protected:
196  N_LAS_System & linearSystem_;
197  N_LOA_Loader & loader_;
198  N_LOA_Loader & nonlinearEquationLoader_;
201  N_TIA_StepErrorControl *& stepErrorControl_; ///< Ref to pointer since AnalysisManager will change pointer
202  N_TIA_WorkingIntegrationMethod *& workingIntgMethod_; ///< Ref to pointer since AnalysisManager will change pointer
204 
206 
207  unsigned int integrationMethod_; ///< Current time-integration method flag.
208 
209  // NOTE: For now tranStepNumber is the same as stepNumber, but later I will
210  // change it. stepNumber will later include both dcop and tran steps.
211  // I haven't changed it yet b/c I need to check what devices call
212  // getStepNumber, and what they expect to get.
213 
214  unsigned int stepNumber; ///< Time-integration step number counter.
215  unsigned int tranStepNumber;
216 
217  bool doubleDCOPFlag_; ///< true if doing a double-DCOP is possible.
218  int doubleDCOPStep_; ///< current step in the DCOP loop.
219 
220  bool sensFlag_;
221  bool inputOPFlag_; ///< true if starting from an initial condition.
222 
223  std::vector<StatCounts> saveStatCountsVector_;
224 
225 public:
227 };
228 
229 StatCounts operator-(const StatCounts &s0, const StatCounts &s1);
230 
231 //-----------------------------------------------------------------------------
233 {
235 }
236 
237 //-----------------------------------------------------------------------------
239 {
240  return stats_.residualLoadTime_;
241 }
242 
243 //-----------------------------------------------------------------------------
245 {
246  return stats_.jacobianLoadTime_;
247 }
248 
249 //-----------------------------------------------------------------------------
251 {
252  return doubleDCOPFlag_;
253 }
254 
255 //-----------------------------------------------------------------------------
257 {
258  return doubleDCOPStep_ ;
259 }
260 
261 bool updateSweepParams(N_LOA_Loader &loader, AnalysisManager &analysis_manager, int step_count, std::vector<SweepParam>::iterator begin, std::vector<SweepParam>::iterator end);
262 int setupSweepLoop(N_LOA_Loader &loader, int debug_level, std::vector<SweepParam>::iterator begin, std::vector<SweepParam>::iterator end);
263 
264 } // namespace Analysis
265 } // namespace Xyce
266 
267 
269 
270 #endif
271