Xyce  6.1
N_ANP_AnalysisBase.C
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.C,v $
27 // Purpose : Base class analysis functions.
28 // Special Notes :
29 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
30 // Creation Date : 01/24/08
31 //
32 // Revision Information:
33 // ---------------------
34 // Revision Number: $Revision: 1.82 $
35 // Revision Date : $Date: 2015/04/09 17:11:47 $
36 // Current Owner : $Author: dgbaur $
37 //-----------------------------------------------------------------------------
38 #include <Xyce_config.h>
39 
40 #include <N_ANP_AnalysisBase.h>
41 #include <N_ANP_AnalysisManager.h>
42 #include <N_ANP_SweepParam.h>
43 #include <N_ERH_Message.h>
44 #include <N_LOA_Loader.h>
46 #include <N_NLS_Manager.h>
47 #include <N_PDS_Comm.h>
49 #include <N_TIA_StepErrorControl.h>
50 #include <N_TIA_TIAParams.h>
51 #include <N_UTL_FeatureTest.h>
52 #include <N_UTL_MachDepParams.h>
53 #include <N_UTL_OptionBlock.h>
54 
55 namespace Xyce {
56 namespace Analysis {
57 
59  : successfulStepsTaken_(0),
60  successStepsThisParameter_(0),
61  failedStepsAttempted_(0),
62  jacobiansEvaluated_(0),
63  iterationMatrixFactorizations_(0),
64  linearSolves_(0),
65  failedLinearSolves_(0),
66  linearIters_(0),
67  residualEvaluations_(0),
68  nonlinearConvergenceFailures_(0),
69  linearSolutionTime_(0.0),
70  residualLoadTime_(0.0),
71  jacobianLoadTime_(0.0)
72 {}
73 
74 StatCounts &
76  const StatCounts & stats)
77 {
85  linearIters_ += stats.linearIters_;
91 
92  return *this;
93 }
94 
95 
96 Util::JSON &operator<<(Util::JSON &json, const StatCounts &s)
97 {
98  json << Util::JSON::open
99  << Util::nameValuePair("successfulStepsTaken", s.successfulStepsTaken_) << Util::JSON::sep
100  << Util::nameValuePair("failedStepsAttempted", s.failedStepsAttempted_) << Util::JSON::sep
101  << Util::nameValuePair("jacobiansEvaluated", s.jacobiansEvaluated_) << Util::JSON::sep
102  << Util::nameValuePair("iterationMatrixFactorizations", s.iterationMatrixFactorizations_) << Util::JSON::sep
103  << Util::nameValuePair("linearSolves", s.linearSolves_) << Util::JSON::sep
104  << Util::nameValuePair("failedLinearSolves", s.failedLinearSolves_) << Util::JSON::sep
105  << Util::nameValuePair("linearIters", s.linearIters_) << Util::JSON::sep
106  << Util::nameValuePair("residualEvaluations", s.residualEvaluations_) << Util::JSON::sep
107  << Util::nameValuePair("nonlinearConvergenceFailures", s.nonlinearConvergenceFailures_) << Util::JSON::sep
108  << Util::nameValuePair("residualLoadTime", s.residualLoadTime_) << Util::JSON::sep
109  << Util::nameValuePair("jacobianLoadTime", s.jacobianLoadTime_) << Util::JSON::sep
110  << Util::nameValuePair("linearSolutionTime", s.linearSolutionTime_)
111  << Util::JSON::close;
112 
113  return json;
114 }
115 
116 //-----------------------------------------------------------------------------
117 // Function : AnalysisBase::AnalysisBase
118 // Purpose : Constructor
119 // Special Notes :
120 // Scope : public
121 // Creator : Todd S. Coffey, SNL.
122 // Creation Date : 01/29/08
123 //-----------------------------------------------------------------------------
124 AnalysisBase::AnalysisBase(AnalysisManager &analysis_manager, const char *name )
125  : name_(name),
126  beginningIntegration(true),
127  baseIntegrationMethod_(TimeIntg::NoTimeIntegration::type),
128  stepNumber(0),
129  tranStepNumber(0),
130  NOOP_(false),
131  doubleDCOPEnabled_(false),
132  doubleDCOPStep_(0),
133  firstDCOPStep_(-1),
134  lastDCOPStep_(-1),
135  inputOPFlag_(false),
136  saveStatCountsVector_(),
137  stats_()
138 {}
139 
140 //-----------------------------------------------------------------------------
141 // Function : AnalysisBase::~AnalysisBase()
142 // Purpose : destructor
143 // Special Notes :
144 // Scope :
145 // Creator : Todd S. Coffey, SNL.
146 // Creation Date : 01/29/08
147 //-----------------------------------------------------------------------------
149 {}
150 
151 bool
153 {
154  Stats::StatTop _analysis(name_);
155 
156  return doRun();
157 }
158 
159 bool
161 {
162  Stats::StatTop _analysis(name_);
163 
164  return doInit();
165 }
166 
167 bool
169 {
170  return doProcessSuccessfulStep();
171 }
172 
173 bool
175 {
176  return doProcessFailedStep();
177 }
178 
179 bool
181 {
182  return doFinish();
183 }
184 
185 
186 bool
188 {
189  return doHandlePredictor();
190 }
191 
192 
193 //-----------------------------------------------------------------------------
194 // Function : AnalysisBase::resetForStepAnalysis()
195 // Purpose : When doing a .STEP sweep, some data must be reset to its
196 // initial state.
197 // Special Notes :
198 // Scope : public
199 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
200 // Creation Date : 8/26/04
201 //-----------------------------------------------------------------------------
203 {
205  stepNumber = 0;
206  beginningIntegration = true;
207 
208  return true;
209 }
210 
211 
212 
213 //-----------------------------------------------------------------------------
214 // Function : AnalysisBase::resetAll
215 // Purpose :
216 // Special Notes :
217 // Scope : public
218 // Creator : Eric R. Keiter
219 // Creation Date : 12/16/10
220 //-----------------------------------------------------------------------------
222 {
223  stepNumber = 0;
224  tranStepNumber = 0;
225 
226  stats_ = StatCounts();
227 }
228 
229 //-----------------------------------------------------------------------------
230 // Function : AnalysisBase::saveLoopInfo
231 // Purpose :
232 // Special Notes :
233 // Scope : public
234 // Creator : Eric R. Keiter
235 // Creation Date : 12/16/10
236 //-----------------------------------------------------------------------------
238 {
239  if (saveStatCountsVector_.empty()) // push back empty stats as sentinel
240  saveStatCountsVector_.push_back(StatCounts());
241 
242  saveStatCountsVector_.push_back(stats_);
243 
244  return saveStatCountsVector_.size() - 1;
245 }
246 
249  const StatCounts & s0,
250  const StatCounts & s1)
251 {
252  StatCounts s;
253 
260 
261  if (s0.linearIters_ > s1.linearIters_)
263 
269 
270  return s;
271 }
272 
273 //-----------------------------------------------------------------------------
274 // Function : AnalysisBase::printLoopInfo
275 // Purpose : Prints out time loop information.
276 // Special Notes : Prints stats from save point start to save point finish.
277 // Special case 0,0 is entire run to this point
278 // Scope : public
279 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
280 // Creation Date : 6/26/00
281 //-----------------------------------------------------------------------------
282 bool AnalysisBase::printLoopInfo(int t1, int t2)
283 {
284  bool bsuccess = true;
285 
286  if (t1 == 0 && t2 == 0)
287  {
288  t2 = saveLoopInfo();
289  }
290 
291  lout() << "\tNumber Successful Steps Taken:\t\t" << saveStatCountsVector_[t2].successfulStepsTaken_ - saveStatCountsVector_[t1].successfulStepsTaken_ << std::endl
292  << "\tNumber Failed Steps Attempted:\t\t" << saveStatCountsVector_[t2].failedStepsAttempted_ - saveStatCountsVector_[t1].failedStepsAttempted_ << std::endl
293  << "\tNumber Jacobians Evaluated:\t\t" << saveStatCountsVector_[t2].jacobiansEvaluated_ - saveStatCountsVector_[t1].jacobiansEvaluated_ << std::endl
294  << "\tNumber Iteration Matrix Factorizations:\t" << saveStatCountsVector_[t2].iterationMatrixFactorizations_ - saveStatCountsVector_[t1].iterationMatrixFactorizations_ << std::endl
295  << "\tNumber Linear Solves:\t\t\t" << saveStatCountsVector_[t2].linearSolves_ - saveStatCountsVector_[t1].linearSolves_ << std::endl
296  << "\tNumber Failed Linear Solves:\t\t" << saveStatCountsVector_[t2].failedLinearSolves_ - saveStatCountsVector_[t1].failedLinearSolves_ << std::endl;
297 
298  if (saveStatCountsVector_[t2].linearIters_ > saveStatCountsVector_[t1].linearIters_)
299  {
300  lout() << "\tNumber Linear Solver Iterations:\t" << saveStatCountsVector_[t2].linearIters_ - saveStatCountsVector_[t1].linearIters_ << std::endl;
301  }
302  lout() << "\tNumber Residual Evaluations:\t\t" << saveStatCountsVector_[t2].residualEvaluations_ - saveStatCountsVector_[t1].residualEvaluations_ << std::endl
303  << "\tNumber Nonlinear Convergence Failures:\t" << saveStatCountsVector_[t2].nonlinearConvergenceFailures_ - saveStatCountsVector_[t1].nonlinearConvergenceFailures_ << std::endl
304  << "\tTotal Residual Load Time:\t\t" << saveStatCountsVector_[t2].residualLoadTime_ - saveStatCountsVector_[t1].residualLoadTime_ << " seconds" << std::endl
305  << "\tTotal Jacobian Load Time:\t\t" << saveStatCountsVector_[t2].jacobianLoadTime_ - saveStatCountsVector_[t1].jacobianLoadTime_ << " seconds" << std::endl
306  << "\tTotal Linear Solution Time:\t\t" << saveStatCountsVector_[t2].linearSolutionTime_ - saveStatCountsVector_[t1].linearSolutionTime_ << " seconds" << std::endl << std::endl;
307 
308  return bsuccess;
309 }
310 
311 void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
312 {
313  if (newton_convergence_status <= 0) {
315  }
316 
317  stats.jacobiansEvaluated_ += nonlinear_solver.getNumJacobianLoads();
318  stats.linearSolves_ += nonlinear_solver.getNumLinearSolves();
319  stats.failedLinearSolves_ += nonlinear_solver.getNumFailedLinearSolves();
320  stats.linearIters_ += nonlinear_solver.getTotalNumLinearIters();
321  stats.residualEvaluations_ += nonlinear_solver.getNumResidualLoads();
323  stats.linearSolutionTime_ += nonlinear_solver.getTotalLinearSolveTime();
324  stats.residualLoadTime_ += nonlinear_solver.getTotalResidualLoadTime();
325  stats.jacobianLoadTime_ += nonlinear_solver.getTotalJacobianLoadTime();
326 }
327 
328 //-----------------------------------------------------------------------------
329 // Function : setTimeIntegratorOptions
330 // Purpose :
331 // Special Notes : These are from '.options timeint'
332 // Scope : public
333 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
334 // Creation Date : 04/18/02
335 //-----------------------------------------------------------------------------
336 bool
338  const Util::Param & param)
339 {
340  if (param.uTag() == "DOUBLEDCOP") {
341  const std::string &double_dcop_options = param.stringValue();
342  if (equal_nocase(double_dcop_options, "NL_POISSON,DRIFT_DIFFUSION")) {
343  firstDCOPStep_ = 0;
344  lastDCOPStep_ = 1;
346  return true;
347  }
348  else if (equal_nocase(double_dcop_options, "NL_POISSON")) {
349  firstDCOPStep_ = 0;
350  lastDCOPStep_ = 0;
352  return true;
353  }
354  else if (equal_nocase(double_dcop_options, "DRIFT_DIFFUSION")) {
355  firstDCOPStep_ = 1;
356  lastDCOPStep_ = 1;
358  return true;
359  }
360  else
361  Report::UserError0() << "Unknown DOUBLEDCOP option " << double_dcop_options;
362  }
363 
364  return false;
365 }
366 
367 } // namespace Analysis
368 } // namespace Xyce
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.
void gatherStepStatistics(StatCounts &stats, Nonlinear::NonLinearSolver &nonlinear_solver, int newton_convergence_status)
Util::JSON & operator<<(Util::JSON &json, const StatCounts &s)
virtual bool doHandlePredictor()=0
unsigned int failedStepsAttempted_
Total number of failed time-integration steps.
StatCounts & operator+=(const StatCounts &stats)
bool setDCOPOption(const Util::Param &param)
virtual unsigned int getTotalNumLinearIters()
virtual bool doProcessFailedStep()=0
virtual bool printLoopInfo(int start, int finish)
StatCounts operator-(const StatCounts &s0, const StatCounts &s1)
AnalysisBase(AnalysisManager &analysis_manager, const char *name)
unsigned int nonlinearConvergenceFailures_
std::vector< StatCounts > saveStatCountsVector_