Xyce  6.1
N_ANP_Step.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_Step.C,v $
27 // Purpose : .STEP Sweep 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.73.2.1 $
35 // Revision Date : $Date: 2015/04/02 18:20:07 $
36 // Current Owner : $Author: tvrusso $
37 //-----------------------------------------------------------------------------
38 #include <Xyce_config.h>
39 
40 #include <N_ANP_AnalysisManager.h>
41 #include <N_ANP_OutputMgrAdapter.h>
42 #include <N_ANP_SweepParam.h>
43 #include <N_ANP_Step.h>
44 #include <N_ANP_StepEvent.h>
45 #include <N_ERH_Message.h>
46 #include <N_IO_PkgOptionsMgr.h>
47 #include <N_IO_CmdParse.h>
48 #include <N_TIA_StepErrorControl.h>
49 #include <N_TIA_DataStore.h>
50 #include <N_UTL_Diagnostic.h>
51 #include <N_UTL_FeatureTest.h>
52 #include <N_UTL_OptionBlock.h>
53 #include <N_UTL_Timer.h>
54 
55 namespace Xyce {
56 namespace Analysis {
57 
58 //-----------------------------------------------------------------------------
59 // Function : Step::setAnalysisParams
60 // Purpose :
61 // Special Notes :
62 // Scope : public
63 // Creator : Eric R. Keiter, SNL
64 // Creation Date : 6/22/10
65 //-----------------------------------------------------------------------------
66 bool Step::setAnalysisParams(const Util::OptionBlock & paramsBlock)
67 {
68  stepSweepVector_.push_back(parseSweepParams(paramsBlock.begin(), paramsBlock.end()));
70 
71  return true;
72 }
73 
74 const TimeIntg::TIAParams &
76 {
78 }
79 
82 {
84 }
85 
86 //-----------------------------------------------------------------------------
87 // Function : Step::getDCOPFlag()
88 // Purpose :
89 //
90 // Special Notes :
91 // Scope : public
92 // Creator : Eric Keiter, SNL
93 // Creation Date : 3/24/2014
94 //-----------------------------------------------------------------------------
95 bool Step::getDCOPFlag() const
96 {
97  return childAnalysis_.getDCOPFlag();
98 }
99 
100 //-----------------------------------------------------------------------------
101 // Function : Step::run()
102 // Purpose : This is the main controlling loop for Step analysis.
103 //
104 // Special Notes :
105 // Scope : public
106 // Creator : Eric Keiter, SNL
107 // Creation Date : 10/04/00
108 //-----------------------------------------------------------------------------
110 {
111  return doInit() && doLoopProcess() && doFinish();
112 }
113 
114 //-----------------------------------------------------------------------------
115 // Function : Step::init()
116 // Purpose :
117 // Special Notes :
118 // Scope : public
119 // Creator : Eric Keiter, SNL
120 // Creation Date : 03/10/06
121 //-----------------------------------------------------------------------------
123 {
124  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
125  {
126  Xyce::dout() << std::endl << std::endl;
127  Xyce::dout() << section_divider << std::endl;
128  Xyce::dout() << "Step::init" << std::endl;
129  }
130 
132 
133  Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::INITIALIZE, stepLoopSize_));
134 
135  // analysisManager_.setStepLoopInitialized(true);
136 
137  return true;
138 }
139 
140 
141 //-----------------------------------------------------------------------------
142 // Function : Step::loopProcess()
143 // Purpose :
144 // Special Notes :
145 // Scope : public
146 // Creator : Eric Keiter, SNL
147 // Creation Date : 03/10/06
148 //-----------------------------------------------------------------------------
150 {
151  std::string msg;
152  bool integration_status = true;
153 
154  for (int i = 0; i < stepLoopSize_; ++i)
155  {
156  // Tell the manager if any of our sweeps are being reset in this loop iteration.
157  bool reset = updateSweepParams(loader_, i, stepSweepVector_.begin(), stepSweepVector_.end());
158 
160 
162 
163  if (DEBUG_ANALYSIS && isActive(Diag::TIME_PARAMETERS))
164  {
165  for (SweepVector::const_iterator it = stepSweepVector_.begin(), end = stepSweepVector_.end(); it != end; ++it)
166  {
167  Xyce::dout() << "Step Analysis # " << i<<"\t";
168  Xyce::dout() << (*it);
169  }
170  }
171 
172  Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::STEP_STARTED, i));
173 
174  // solve the loop.
175  integration_status = childAnalysis_.run();
176 
178  // this is to try to capture the final sim time when the
179  // underlying simulation (childAnalysis) is transient
180  // and then that simulation time is reported to measure manager's
181  // verbose output.
183  Util::publish<StepEvent>(analysisManager_, anEvent);
184 
186  *(analysisManager_.getDataStore()->currSolutionPtr),
187  *(analysisManager_.getDataStore()->currStatePtr),
188  *(analysisManager_.getDataStore()->currStorePtr),
189  *(analysisManager_.getDataStore()->currLeadCurrentPtr),
190  *(analysisManager_.getDataStore()->currLeadDeltaVPtr));
191 
192  } // end of for loop, and end of step analysis.
193 
194  return integration_status;
195 }
196 
197 //-----------------------------------------------------------------------------
198 // Function : Step::processSuccessfulStep()
199 // Purpose :
200 // Special Notes :
201 // Scope : public
202 // Creator : Eric Keiter, SNL
203 // Creation Date : 03/10/06
204 //-----------------------------------------------------------------------------
206 {
207  return true;
208 }
209 
210 //-----------------------------------------------------------------------------
211 // Function : Step::processFailedStep()
212 // Purpose :
213 // Special Notes :
214 // Scope : public
215 // Creator : Eric Keiter, SNL
216 // Creation Date : 03/10/06
217 //-----------------------------------------------------------------------------
219 {
220  return true;
221 }
222 
223 
224 //-----------------------------------------------------------------------------
225 // Function : Step::doFinish()
226 // Purpose :
227 // Special Notes :
228 // Scope : public
229 // Creator : Eric Keiter, SNL
230 // Creation Date : 03/10/06
231 //-----------------------------------------------------------------------------
233 {
234  Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::FINISH, stepLoopSize_));
235 
237 
238  return true;
239 }
240 
241 namespace {
242 
243 //-----------------------------------------------------------------------------
244 // Class : StepFactory
245 // Purpose :
246 // Special Notes :
247 // Scope : public
248 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
249 // Creation Date : Thu Jan 29 12:53:02 2015
250 //-----------------------------------------------------------------------------
251 ///
252 /// Factory for parsing Step parameters from the netlist and creating Step analysis.
253 ///
254 class StepFactory : public Factory<Step>
255 {
256 public:
257  //-----------------------------------------------------------------------------
258  // Function : StepFactory
259  // Purpose :
260  // Special Notes :
261  // Scope : public
262  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
263  // Creation Date : Thu Jan 29 12:54:09 2015
264  //-----------------------------------------------------------------------------
265  ///
266  /// Constructs the Step analysis factory
267  ///
268  /// @invariant Stores the results of parsing. Multiple Step analysis options may be
269  /// applied and each generates and additional step.
270  ///
271  /// @invariant The existence of the parameters specified in the constructor cannot
272  /// change.
273  ///
274  /// @param analysis_manager
275  /// @param linear_system
276  /// @param nonlinear_manager
277  ///
278  StepFactory(
279  Analysis::AnalysisManager & analysis_manager,
280  Linear::System & linear_system,
281  Nonlinear::Manager & nonlinear_manager)
282  : Factory<Step>(),
283  analysisManager_(analysis_manager),
284  linearSystem_(linear_system),
285  nonlinearManager_(nonlinear_manager)
286  {}
287 
288  virtual ~StepFactory()
289  {}
290 
291  //-----------------------------------------------------------------------------
292  // Function : create
293  // Purpose :
294  // Special Notes :
295  // Scope : public
296  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
297  // Creation Date : Thu Jan 29 12:59:00 2015
298  //-----------------------------------------------------------------------------
299  ///
300  /// Create a new Step analysis and applies the analysis and time integrator option blocks.
301  ///
302  /// @return new Step analysis object
303  ///
304  Step *create() const
305  {
306  Step *step = new Step(analysisManager_, analysisManager_.getAnalysisObject());
307  for (std::vector<Util::OptionBlock>::const_iterator it = stepSweepAnalysisOptionBlock_.begin(), end = stepSweepAnalysisOptionBlock_.end(); it != end; ++it)
308  step->setAnalysisParams(*it);
309 
310  return step;
311  }
312 
313  //-----------------------------------------------------------------------------
314  // Function : setStepAnalysisOptionBlock
315  // Purpose :
316  // Special Notes :
317  // Scope : public
318  // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
319  // Creation Date : Thu Jan 29 13:00:14 2015
320  //-----------------------------------------------------------------------------
321  ///
322  /// Saves the analysis parsed options block in the factory.
323  ///
324  /// @invariant Appends to any previously specified analysis option block.
325  ///
326  /// @param option_block parsed option block
327  ///
328  void setStepAnalysisOptionBlock(const Util::OptionBlock &option_block)
329  {
330  for (std::vector<Util::OptionBlock>::iterator it = stepSweepAnalysisOptionBlock_.begin(), end = stepSweepAnalysisOptionBlock_.end(); it != end; ++it)
331  {
332  if ((*it).compareParamLists(option_block))
333  {
334  (*it) = option_block;
335  return;
336  }
337  }
338 
339  // save the new one.
340  stepSweepAnalysisOptionBlock_.push_back(option_block); // save a copy for later.
341  }
342 
343 public:
344  AnalysisManager & analysisManager_;
345  Linear::System & linearSystem_;
346  Nonlinear::Manager & nonlinearManager_;
347 
348 private:
349  std::vector<Util::OptionBlock> stepSweepAnalysisOptionBlock_;
350 };
351 
352 // .STEP
353 struct StepAnalysisReg : public IO::PkgOptionsReg
354 {
355  StepAnalysisReg(
356  StepFactory & factory)
357  : factory_(factory)
358  {}
359 
360  bool operator()(const Util::OptionBlock &option_block)
361  {
362  factory_.setStepAnalysisOptionBlock(option_block);
363 
364  factory_.analysisManager_.addAnalysis(&factory_);
365 
366  return true;
367  }
368 
369  StepFactory & factory_;
370 };
371 
372 } // namespace <unnamed>
373 
374 
375 bool
377  const std::string & netlist_filename,
378  IO::PkgOptionsMgr & options_manager,
379  AnalysisManager & analysis_manager,
380  Linear::System & linear_system,
381  Nonlinear::Manager & nonlinear_manager)
382 {
383  StepFactory *factory = new StepFactory(analysis_manager, linear_system, nonlinear_manager);
384 
385  analysis_manager.addAnalysisFactory(factory);
386 
387  options_manager.submitRegistration("STEP", netlist_filename, new StepAnalysisReg(*factory));
388 
389  return true;
390 }
391 
392 } // namespace Analysis
393 } // namespace Xyce
void outputResult(const Linear::Vector &currSolutionPtr, const Linear::Vector &currStatePtr, const Linear::Vector &currStorePtr, const Linear::Vector &lead_current_vector, const Linear::Vector &junction_voltage_vector)
virtual bool doProcessFailedStep()
Definition: N_ANP_Step.C:218
Pure virtual class to augment a linear system.
bool updateSweepParams(Loader::Loader &loader, int step_count, std::vector< SweepParam >::iterator begin, std::vector< SweepParam >::iterator end, bool overrideOriginal=false)
StepFactory & factory_
Definition: N_ANP_Step.C:369
AnalysisBase & childAnalysis_
Definition: N_ANP_Step.h:100
Nonlinear::Manager & nonlinearManager_
Definition: N_ANP_Step.C:346
double finalTime
End time for simulation.
SweepVector stepSweepVector_
Definition: N_ANP_Step.h:101
virtual bool doProcessSuccessfulStep()
Definition: N_ANP_Step.C:205
virtual const TimeIntg::TIAParams & getTIAParams() const =0
virtual bool doInit()
Definition: N_ANP_Step.C:122
void setStepSweepVector(const Analysis::SweepVector &sweep_vector)
virtual bool doFinish()
Definition: N_ANP_Step.C:232
virtual bool getDCOPFlag() const
Definition: N_ANP_Step.C:95
bool registerStepFactory(const std::string &netlist_filename, IO::PkgOptionsMgr &options_manager, AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager)
Definition: N_ANP_Step.C:376
std::vector< Util::OptionBlock > stepSweepAnalysisOptionBlock_
Definition: N_ANP_Step.C:349
Linear::System & linearSystem_
Definition: N_ANP_Step.C:345
SweepParam parseSweepParams(Util::ParamList::const_iterator first, Util::ParamList::const_iterator last)
Populate the sweep params from the parameter list.
bool setAnalysisParams(const Util::OptionBlock &paramsBlock)
Definition: N_ANP_Step.C:66
void addAnalysisFactory(Factory< void > *factory)
AnalysisManager & analysisManager_
Definition: N_ANP_Step.h:97
The analysis factory template defines an interface for analysis type testing and analysis creation...
Definition: N_ANP_Factory.h:65
Loader::Loader & loader_
Definition: N_ANP_Step.h:98
OutputMgrAdapter & outputManagerAdapter_
Definition: N_ANP_Step.h:99
virtual bool doLoopProcess()
Definition: N_ANP_Step.C:149
virtual bool doRun()
Definition: N_ANP_Step.C:109
int setupSweepLoop(Loader::Loader &loader, std::vector< SweepParam >::iterator begin, std::vector< SweepParam >::iterator end)
AnalysisManager & analysisManager_
Definition: N_ANP_Step.C:344
virtual bool getDCOPFlag() const =0
const TimeIntg::TIAParams & getTIAParams() const
Definition: N_ANP_Step.C:75