Xyce  6.1
N_ANP_AnalysisManager.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_AnalysisManager.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
33 //
34 // Creation Date : 01/24/08
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.165 $
40 //
41 // Revision Date : $Date: 2015/10/27 19:24:39 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_ANP_AnalysisManager_h
47 #define Xyce_N_ANP_AnalysisManager_h
48 
49 #include <list>
50 #include <set>
51 #include <vector>
52 
53 #include <N_ANP_fwd.h>
54 #include <N_DEV_fwd.h>
55 #include <N_IO_fwd.h>
56 #include <N_LAS_fwd.h>
57 #include <N_LOA_fwd.h>
58 #include <N_NLS_fwd.h>
59 #include <N_PDS_fwd.h>
60 #include <N_TIA_fwd.h>
61 #include <N_TOP_fwd.h>
62 #include <N_UTL_fwd.h>
63 
64 #include <N_ANP_AnalysisBase.h>
65 #include <N_ANP_AnalysisEvent.h>
66 #include <N_ANP_RegisterAnalysis.h>
67 #include <N_ANP_StepEvent.h>
68 #include <N_TIA_TIAParams.h>
69 #include <N_UTL_Factory.h>
70 #include <N_UTL_Listener.h>
71 #include <N_UTL_Stats.h>
72 #include <N_UTL_Timer.h>
73 
74 namespace Xyce {
75 namespace Analysis {
76 
77 typedef std::vector<Util::Factory<AnalysisBase, void> *> CreatorVector;
78 typedef std::set<Util::Factory<ProcessorBase, void> *> CreatorSet;
79 
80 typedef Util::Notifier<StepEvent> StepEventNotifier;
81 typedef Util::Notifier<AnalysisEvent> AnalysisEventNotifier;
82 typedef Util::ListenerAutoSubscribe<StepEvent> StepEventListener;
83 typedef Util::ListenerAutoSubscribe<AnalysisEvent> AnalysisEventListener;
84 
85 //-----------------------------------------------------------------------------
86 // Class :
87 // Purpose : This function converts between Nonlinear::AnalysisMode
88 // : and AnalysisManager.h ANP_Analysis_Mode
89 // Special Notes :
90 // Creator : Todd Coffey, 1414
91 // Creation Date : 07/23/08
92 //-----------------------------------------------------------------------------
94 
95 //-----------------------------------------------------------------------------
96 // Function : analysisModeName
97 // Purpose :
98 // Special Notes :
99 // Scope : public
100 // Creator : David G. Baur Raytheon Sandia National Laboratories 1355
101 // Creation Date : Mon Mar 16 13:56:09 2015
102 //-----------------------------------------------------------------------------
103 ///
104 /// Returns the name of the analysis mode given by mode.
105 ///
106 /// @param mode Analysis mode
107 ///
108 /// @return name of the mode
109 ///
110 ///
111 const char *analysisModeName(Mode mode);
112 
113 //-----------------------------------------------------------------------------
114 // Class : AnalysisManager
115 //
116 // Purpose : This class manages, allocates, and sets up the
117 // various analysis types, such as DC, Tran, HB, etc.
118 //
119 // Special Notes : Some of this class was once in the TimeIntg::ControlAlgorithm
120 // class, which was set up back when Xyce only did transient
121 // simulations. As we added analysis types it became necessary
122 // to refactor the code so that each analysis type had its own
123 // set of classes.
124 //
125 // Creator : Eric Keiter, SNL
126 // Creation Date : 6/01/00 (TimeIntg::ControlAlgorithm, now deprecated)
127 // Creation Date : 1/24/08 (for this version of the class. Date is approximate)
128 //-----------------------------------------------------------------------------
129 class AnalysisManager : public StepEventNotifier,
130  public AnalysisEventNotifier,
131  public StepEventListener,
132  public AnalysisEventListener
133 {
134 public:
136  const IO::CmdParse & command_line,
137  OutputMgrAdapter & output_manager_adapter,
138  Stats::Stat analysis_stat);
139  virtual ~AnalysisManager();
140 
141 private:
144 
145 public:
146  void notify(const StepEvent &step_event);
147  void notify(const AnalysisEvent &analysis_event);
148 
149  void allocateAnalysisObject(AnalysisCreatorRegistry &analysis_registry);
150 
152  const TimeIntg::TIAParams & tia_params,
153  Loader::Loader & loader,
154  Linear::System & linear_system,
155  Nonlinear::Manager & nonlinear_manager,
156  Device::DeviceMgr & device_manager);
157 
158  void resetSolverSystem();
159 
160  // Execute the control loop for the set analysis type.
161  bool run();
162 
163  // Gets the next time-step value.
164  double getTime() const;
165 
166  // Gets the final time-step value.
167  double getFinalTime() const;
168 
169  // Gets the initial time-step value.
170  double getInitialTime() const;
171 
172  // Updates the divided difference values.
173  bool updateDivDiffs();
174 
175  // Calls the time int. method to update the corrector derivatives.
176  bool updateDerivs();
177 
178  // updates state vectors following initial solve with previous operating point constraints
179  bool completeOPStartStep();
180 
181  // updates the State vectors. This function is called from the LOCA interface.
184  const std::vector<std::string> & paramNames,
185  const std::vector<double> & paramVals,
186  Linear::Vector * solnVecPtr );
187 
189 
190  // Compute an estimate of the error in the integration step.
191  bool updateDerivsBlock(const std::list< IndexPair > & solGIDList,
192  const std::list< IndexPair > & staGIDList);
193 
194  // Prints out time loop information.
195  bool printLoopInfo(int start, int finish);
196 
197  DCOPType getDCOPSolve() const;
198 
199  // Get the steady-state flag (true if time int mode is none)
200  bool getDCOPFlag() const;
201 
202  // Get the dcop flag for transient.(true if doing DCOP for transient initialization)
203  bool getTranOPFlag() const;
204 
205  // Get the dcop flag for AC.(true if doing DCOP for AC initialization)
206  bool getACOPFlag() const;
207 
208  bool getDCSweepFlag() const;
209 
211  {
212  return dotOpSpecified_;
213  }
214 
216  {
217  return sweepSourceResetFlag_;
218  }
219 
220  void setSweepSourceResetFlag (bool reset)
221  {
222  sweepSourceResetFlag_ = reset;
223  }
224 
225  bool getTransientFlag () const;
226 
227  // Is the doubleDCOP algorithm enabled?
228  bool getDoubleDCOPEnabled() const;
229 
230  void setTwoLevelMode(TwoLevelMode two_level_mode)
231  {
232  twoLevelMode_ = two_level_mode;
233  }
234 
236  {
237  return twoLevelMode_;
238  }
239 
240  // Get block analysis information for HB
241  bool getBlockAnalysisFlag() const;
242 
243  // gets the index of the DCOP step.
244  // 0 = nonlinear poisson, 1=full TCAD
245  int getDoubleDCOPStep() const;
246 
247  // Gets/sets the step number.
248  int getStepNumber() const;
249  int getTranStepNumber();
250 
251  void setStepNumber(int step);
252  void setTranStepNumber(int step);
253 
254  // This is true only at the beginning of integration, not at a breakpoint.
255  bool getInitTranFlag() const;
256 
257  const IO::CmdParse &getCommandLine() const
258  {
259  return commandLine_;
260  }
261 
262  const std::string &getNetlistFilename() const
263  {
264  return netlistFilename_;
265  }
266 
267  // returns whether transient analysis is completed
268  bool isSimulationComplete();
269 
270  // Gets the size of the restart data (bytes?).
271  int getRestartDataSize( bool pack ) const;
272 
273  // Sets the DC sweep calculation parameters.
274  bool setDCAnalysisParams(const Util::OptionBlock & paramsBlock);
275 
276  // Method to handle OP statements.
277  bool setOPAnalysisParams(const Util::OptionBlock & paramsBlock);
278 
279  // // Sets the DCOP restart parameters.
280  // bool setDCOPRestartParams(const Util::OptionBlock & OB);
281 
282  // Sets the AC Analysis options.
283  bool setACAnalysisParams(const Util::OptionBlock & OB);
284 
285  // Sets the NOISE Analysis options.
286  bool setNOISEAnalysisParams(const Util::OptionBlock & OB);
287 
288  // sets a time at which to pause the simulation
289  void setPauseTime(double pauseTime, double initial_time);
290 
291  // returns time at which to pause the simulation
292  double getPauseTime() const;
293 
294  // returns true if the simulation is currently paused
295  bool isPaused() const;
296 
297  // Sets the sensitivity options.
298  bool setSensOptions(const Util::OptionBlock & OB);
299 
300  // Registers the parallel services manager pointer.
301  bool registerParallelServices(Parallel::Manager * pds_tmp);
302 
303  // Registers the elapsed time timer
304  bool registerElapsedTimer(Util::Timer *);
305 
306  // Writes-out the restart data.
307  bool dumpRestartData(char * buf, int bsize, int & pos, Parallel::Communicator * comm, bool pack);
308 
309  // Restores the restart data.
310  bool restoreRestartData(char * buf, int bsize, int & pos, Parallel::Communicator * comm, bool pack );
311 
312  // Gets the solution variable data.
313  bool getSolnVarData(const int & gid, std::vector< double > & varData) const;
314 
315  // Gets the state variable data.
316  bool getStateVarData(const int & gid, std::vector< double > & varData) const;
317 
318  // Gets the store variable data.
319  bool getStoreVarData(const int & gid, std::vector< double > & varData) const;
320 
321  // Sets the solution variable data.
322  bool setSolnVarData(const int & gid, const std::vector< double > & varData);
323 
324  // Sets the state variable data.
325  bool setStateVarData(const int & gid, const std::vector< double > & varData);
326 
327  // Sets the store variable data.
328  bool setStoreVarData(const int & gid, const std::vector< double > & varData);
329 
330  // set/get beginning integration flag
331  void setBeginningIntegrationFlag(bool bif);
332  bool getBeginningIntegrationFlag() const;
333 
334  // set/get integration method
335  void setIntegrationMethod(int im);
336  int getIntegrationMethod();
337 
338  // Gets the total time spent in the linear solvers.
339  double getTotalLinearSolutionTime() const;
340 
341  // Gets the total time spent in the residual load calculations.
342  double getTotalResidualLoadTime() const;
343 
344  // Gets the total time spent in the Jacobian load calculations.
345  double getTotalJacobianLoadTime() const;
346 
347  // set the next solution vector pointer. Needed for NOX...
348  bool setNextSolVectorPtr (Linear::Vector * solVecPtr);
349 
350  void createTimeIntegratorMethod(const TimeIntg::TIAParams &tia_params, const unsigned int integration_method);
351 
352  //-----------------------------------------------------------------------------
353  // Function : AnalysisManager::getTIAParams
354  // Purpose :
355  // Special Notes :
356  // Scope : public
357  // Creator : Eric R. Keiter, SNL, Computational Sciences
358  // Creation Date : 11/05/04
359  //-----------------------------------------------------------------------------
360  const TimeIntg::TIAParams &getTIAParams() const;
362 
363  bool getSensFlag() const
364  {
365  return sensFlag_;
366  }
367 
368  void addAnalysis(Util::Factory<AnalysisBase, void> *factory)
369  {
370  analysisCreatorVector_.push_back(factory);
371  }
372 
373  void addProcessor(Util::Factory<ProcessorBase, void> *factory)
374  {
375  processorCreatorSet_.insert(factory);
376  }
377 
378  void setDAEStateDerivFlag(bool state)
379  {
380  daeStateDerivFlag_ = state;
381  }
382 
383 public:
385  {
386  return dataStore_;
387  }
388 
390  {
391  return *primaryAnalysisObject_;
392  }
393 
395  {
396  return *primaryAnalysisObject_;
397  }
398 
400  {
401  primaryAnalysisObject_ = primary;
402  }
403 
404  CreatorVector &getCreatorVector()
405  {
406  return analysisCreatorVector_;
407  }
408 
409  Parallel::Manager *getPDSManager() const
410  {
411  return parallelManager_;
412  }
413 
414  Parallel::Machine getComm() const;
415 
416  bool getSwitchIntegrator() const
417  {
418  return switchIntegrator_;
419  }
420 
421  void setSwitchIntegrator(bool switch_itegrator)
422  {
423  switchIntegrator_ = switch_itegrator;
424  }
425 
426  void setNextOutputTime(double next_output_time)
427  {
428  nextOutputTime_ = next_output_time;
429  }
430 
431  double getNextOutputTime() const
432  {
433  return nextOutputTime_;
434  }
435 
436  Util::Timer &getXyceTranTimer()
437  {
438  return xyceTranTimerPtr_;
439  }
440 
442  {
443  return outputManagerAdapter_;
444  }
445 
447  {
448  return *workingIntgMethod_;
449  }
450 
452  {
453  return *workingIntgMethod_;
454  }
455 
457  {
458  return *stepErrorControl_;
459  }
460 
462  {
463  return *stepErrorControl_;
464  }
465 
467  {
468  return *nonlinearEquationLoader_;
469  }
470 
471  void setAnalysisMode(Mode analysis_mode)
472  {
473  analysisMode_ = analysis_mode;
474  }
475 
477  {
478  return analysisMode_;
479  }
480 
481  double getSolverStartTime() const
482  {
483  return solverStartTime_;
484  }
485 
487  {
488  progressFlag_ = false;
489  }
490 
491  bool getProgressFlag() const
492  {
493  return progressFlag_;
494  }
495 
497  {
498  currentAnalysisStack_.push_back(analysis);
499  }
500 
502  {
503  currentAnalysisStack_.pop_back();
504  }
505 
507  {
508  return currentAnalysisStack_.front();
509  }
510 
511  //-----------------------------------------------------------------------------
512  // Function : AnalysisManager::resumeSimulation
513  //
514  // Purpose : set flag to signify that simulation is continuation of
515  // previously paused simulation.
516  //
517  // Special Notes : This is a temporary implementation that I'm using to
518  // begin the process of hiding time integrator internals from
519  // the "N_CIR_Xyce::simulateUntil" method, so that I can
520  // ultimately change those internals without the simulateUntil
521  // method
522  // In the zero order version, just sets tiaParams_.resume=true
523  // Scope : public
524  // Creator : Tom Russo, SNL, Component Information and Models
525  // Creation Date : 04/29/2004
526  //-----------------------------------------------------------------------------
527  void setResumeSimulation(bool resume)
528  {
529  resumeSimulation_ = resume;
530  }
531 
533  {
534  return resumeSimulation_;
535  }
536 
537  bool getSavedAlready() const
538  {
539  return savedAlready_;
540  }
541 
542  void setSavedAlready(bool saved_already)
543  {
544  savedAlready_ = saved_already;
545  }
546 
547 private:
548  const IO::CmdParse & commandLine_; ///< Command line object
549  const std::string netlistFilename_; ///< Netlist file name
550 
551  OutputMgrAdapter & outputManagerAdapter_; ///< Output manager adapter
552 
553  TimeIntg::WorkingIntegrationMethod * workingIntgMethod_; ///< Working integration method
554  TimeIntg::StepErrorControl * stepErrorControl_; ///< Pointer to the TIA step-error control object
555  Loader::NonlinearEquationLoader * nonlinearEquationLoader_; ///< Pointer to the nonlinear equation loader
556 
557  Parallel::Manager * parallelManager_; ///< Pointer to the parallel services manager
558  TimeIntg::DataStore * dataStore_; ///< Data store object
559  IO::ActiveOutput * activeOutput_;
560 
561 
564 
565  bool resumeSimulation_; ///< Resume simulation from a paused transient
566  bool blockAnalysisFlag_; ///< HB Analysis (maybe something with MPDE too)
567  bool daeStateDerivFlag_; ///< .OPTIONS TIMEINT DAESTATEDERIV=
568  bool dotOpSpecified_; ///< Set if .OP
569  bool gui_; ///< Set if -giu appears on command line
573  bool sensFlag_;
575  bool switchIntegrator_; ///< Set to true when Transient::integrationMethod_ is changed
576 
577  Util::Timer xyceTranTimerPtr_; /// Xyce timing utility for timing the transient simulation CPU time.
578  Util::Timer * elapsedTimerPtr_; /// Xyce timing utility for timing elapsed run time
579 
581 
583  // double nextRestartSaveTime_;
584 
585  AnalysisBase * analysisObject_; ///< .STEP, Dakota
586  AnalysisBase * primaryAnalysisObject_; ///< .TRAN, .AC, .HB, ...
587 
588  std::vector<ProcessorBase *> analysisVector_;
589  std::vector<AnalysisBase *> currentAnalysisStack_;
590 
591  CreatorVector analysisCreatorVector_;
593 
594  Stats::Stat analysisStat_;
595 
596 public:
597  unsigned int breakPointRestartStep;
598 };
599 
600 bool registerPkgOptionsMgr(AnalysisManager &analysis_manager, IO::PkgOptionsMgr &options_manager);
601 
602 } // namespace Analysis
603 } // namespace Xyce
604 
605 #endif // Xyce_N_ANP_AnalysisManager_h
bool setNextSolVectorPtr(Linear::Vector *solVecPtr)
void allocateAnalysisObject(AnalysisCreatorRegistry &analysis_registry)
Creates the primary analysis and driving analysis (.STEP, dakota).
bool setDCAnalysisParams(const Util::OptionBlock &paramsBlock)
const char * analysisModeName(Mode mode)
Returns the name of the analysis mode given by mode.
bool run()
Runs the top level analysis.
void notify(const StepEvent &step_event)
Notification that there is a StepEvent.
bool setNOISEAnalysisParams(const Util::OptionBlock &OB)
void setSavedAlready(bool saved_already)
const AnalysisBase * getActiveAnalysis() const
void setNextOutputTime(double next_output_time)
bool getStateVarData(const int &gid, std::vector< double > &varData) const
const std::string netlistFilename_
Netlist file name.
void addProcessor(Util::Factory< ProcessorBase, void > *factory)
Util::ListenerAutoSubscribe< AnalysisEvent > AnalysisEventListener
TimeIntg::DataStore * dataStore_
Data store object.
Pure virtual class to augment a linear system.
bool dumpRestartData(char *buf, int bsize, int &pos, Parallel::Communicator *comm, bool pack)
bool gui_
Set if -giu appears on command line.
void pushActiveAnalysis(AnalysisBase *analysis)
void setAnalysisMode(Mode analysis_mode)
void createTimeIntegratorMethod(const TimeIntg::TIAParams &tia_params, const unsigned int integration_method)
const AnalysisBase & getAnalysisObject() const
std::vector< AnalysisBase * > currentAnalysisStack_
const TimeIntg::StepErrorControl & getStepErrorControl() const
Util::ListenerAutoSubscribe< StepEvent > StepEventListener
Parallel::Machine getComm() const
void addAnalysis(Util::Factory< AnalysisBase, void > *factory)
Parallel::Manager * getPDSManager() const
AnalysisManager & operator=(const AnalysisManager &)
TimeIntg::StepErrorControl & getStepErrorControl()
const std::string & getNetlistFilename() const
TimeIntg::StepErrorControl * stepErrorControl_
Pointer to the TIA step-error control object.
Util::Timer * elapsedTimerPtr_
Xyce timing utility for timing the transient simulation CPU time.
bool registerParallelServices(Parallel::Manager *pds_tmp)
std::set< Util::Factory< ProcessorBase, void > * > CreatorSet
void setPrimaryAnalysisObject(AnalysisBase *primary)
std::vector< ProcessorBase * > analysisVector_
bool restoreRestartData(char *buf, int bsize, int &pos, Parallel::Communicator *comm, bool pack)
TimeIntg::WorkingIntegrationMethod * workingIntgMethod_
Working integration method.
bool initializeSolverSystem(const TimeIntg::TIAParams &tia_params, Loader::Loader &loader, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Device::DeviceMgr &device_manager)
Initializes the solver system.
bool blockAnalysisFlag_
HB Analysis (maybe something with MPDE too)
bool getSolnVarData(const int &gid, std::vector< double > &varData) const
Util::Notifier< StepEvent > StepEventNotifier
bool daeStateDerivFlag_
.OPTIONS TIMEINT DAESTATEDERIV=
void setPauseTime(double pauseTime, double initial_time)
bool getStoreVarData(const int &gid, std::vector< double > &varData) const
Nonlinear::AnalysisMode nonlinearAnalysisMode(Mode mode)
Returns the nonlinear analysis mode given the analysis mode.
bool setACAnalysisParams(const Util::OptionBlock &OB)
bool setStateVarData(const int &gid, const std::vector< double > &varData)
std::vector< Util::Factory< AnalysisBase, void > * > CreatorVector
const TimeIntg::WorkingIntegrationMethod & getWorkingIntegrationMethod() const
AnalysisBase * analysisObject_
.STEP, Dakota
OutputMgrAdapter & getOutputManagerAdapter() const
Util::Notifier< AnalysisEvent > AnalysisEventNotifier
bool setSolnVarData(const int &gid, const std::vector< double > &varData)
Loader::NonlinearEquationLoader & getNonlinearEquationLoader()
const TimeIntg::TIAParams & getTIAParams() const
bool setOPAnalysisParams(const Util::OptionBlock &paramsBlock)
Loader::NonlinearEquationLoader * nonlinearEquationLoader_
Pointer to the nonlinear equation loader.
bool updateDerivsBlock(const std::list< IndexPair > &solGIDList, const std::list< IndexPair > &staGIDList)
bool setSensOptions(const Util::OptionBlock &OB)
const IO::CmdParse & commandLine_
Command line object.
OutputMgrAdapter & outputManagerAdapter_
Output manager adapter.
AnalysisManager(const IO::CmdParse &command_line, OutputMgrAdapter &output_manager_adapter, Stats::Stat analysis_stat)
Constructs the analysis manager.
bool completeHomotopyStep(Loader::NonlinearEquationLoader &loader, const std::vector< std::string > &paramNames, const std::vector< double > &paramVals, Linear::Vector *solnVecPtr)
bool failHomotopyStep(Loader::NonlinearEquationLoader &loader)
TimeIntg::WorkingIntegrationMethod & getWorkingIntegrationMethod()
const IO::CmdParse & getCommandLine() const
double solverStartTime_
Xyce timing utility for timing elapsed run time.
void setSwitchIntegrator(bool switch_itegrator)
bool switchIntegrator_
Set to true when Transient::integrationMethod_ is changed.
TimeIntg::DataStore * getDataStore()
bool getBlockAnalysisFlag() const
Return true if primary analysis is HB or MPDE.
bool setStoreVarData(const int &gid, const std::vector< double > &varData)
bool registerPkgOptionsMgr(AnalysisManager &analysis_manager, IO::PkgOptionsMgr &options_manager)
bool resumeSimulation_
Resume simulation from a paused transient.
void setTwoLevelMode(TwoLevelMode two_level_mode)
Parallel::Manager * parallelManager_
Pointer to the parallel services manager.
AnalysisBase * primaryAnalysisObject_
.TRAN, .AC, .HB, ...
bool printLoopInfo(int start, int finish)