Xyce  6.1
N_ANP_Transient.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_Transient.h,v $
27 //
28 // Purpose : Transient analysis class
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.90 $
41 // Revision Date : $Date: 2015/10/27 19:24:39 $
42 // Current Owner : $Author: tvrusso $
43 //-----------------------------------------------------------------------------
44 
45 #ifndef Xyce_N_ANP_Transient_h
46 #define Xyce_N_ANP_Transient_h
47 
48 #include <N_ANP_fwd.h>
49 #include <N_IO_fwd.h>
50 #include <N_LAS_fwd.h>
51 #include <N_TOP_fwd.h>
52 #include <N_UTL_fwd.h>
53 
54 #include <N_ANP_AnalysisBase.h>
55 #include <N_ANP_RegisterAnalysis.h>
56 #include <N_ANP_StepEvent.h>
57 #include <N_TIA_TIAParams.h>
58 #include <N_UTL_FixedQueue.h>
59 #include <N_UTL_Listener.h>
60 #include <N_UTL_OptionBlock.h>
61 
62 class N_MPDE_Manager;
63 
64 namespace Xyce {
65 namespace Analysis {
66 
67 typedef Util::ListenerAutoSubscribe<StepEvent> StepEventListener;
68 
69 //-------------------------------------------------------------------------
70 // Class : Transient
71 // Purpose : Transient analysis class
72 // Special Notes :
73 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
74 // Creation Date : 01/24/08
75 //-------------------------------------------------------------------------
76 class Transient : public AnalysisBase, public StepEventListener
77 {
78 public:
79  Transient(
80  AnalysisManager & analysis_manager,
81  Linear::System & linear_system,
82  Nonlinear::Manager & nonlinear_manager,
83  Loader::Loader & loader,
84  Topo::Topology & topology,
85  IO::InitialConditionsManager & initial_conditions_manager,
86  IO::RestartMgr & restart_manager,
87  OutputAdapter * output_adapter = 0,
88  HB * hb_analysis = 0, // HACK TO GET US MOVING FORWARD, should pass output adapter or something
89  N_MPDE_Manager * mpde_manager = 0); // HACK TO GET US MOVING FORWARD, should pass output adapter or something
90 
91  virtual ~Transient()
92  {}
93 
94  void notify(const StepEvent &event);
95 
96  void setTIAParams(const TimeIntg::TIAParams &tia_params)
97  {
98  tiaParams_ = tia_params;
99  }
100 
102  {
103  return tiaParams_;
104  }
105 
107  {
108  return tiaParams_;
109  }
110 
111  bool setAnalysisParams(const Util::OptionBlock & paramsBlock);
112  bool setTimeIntegratorOptions(const Util::OptionBlock &option_block);
113 
114 protected:
115  bool doRun();
116  bool doInit();
117  bool resuming();
118  bool doLoopProcess();
119  bool doTranOP ();
121  bool doProcessFailedStep();
122  bool doFinish();
123  bool doHandlePredictor();
124 
125 public:
126  bool processSuccessfulDCOP();
127  bool processFailedDCOP();
128 
129  bool resetForHB();
130  bool finalVerboseOutput();
131 
132  void printStepHeader(std::ostream &os);
133  void printProgress(std::ostream &os);
134 
135  // mixed-signal specific
136  bool mixedSignalStep(double maxTimeStepFromHabanero);
138 
139  // Two Level specific
140  bool twoLevelStep();
141 
142  bool getDCOPFlag() const
143  {
144  return dcopFlag_;
145  }
146 
147  int getDCStats() { return dcStats; }
148  int getTranStats() { return tranStats; }
149 
150  void setSaveTimeSteps(bool save_time_steps)
151  {
152  saveTimeStepsFlag = save_time_steps;
153  }
154 
155 private:
156  void preMixedSignalStepDetails(double maxTimeStepFromHabanero);
157  void noopOutputs ();
158  void tranopOutputs ();
159  void tranStepOutputs ();
160 
161  void takeAnIntegrationStep_();
162 
163  bool retakeAndAcceptTimeStep( double aTimeStep );
164 
165  void logQueuedData();
166 
167  void outputFailedStepData();
168 
169 private:
170  Parallel::Machine comm_;
173  Linear::System & linearSystem_;
175  Topo::Topology & topology_;
176  IO::InitialConditionsManager & initialConditionsManager_;
177  IO::RestartMgr & restartManager_;
181  bool sensFlag_;
184 
185  // a flag to indicate of the simulation is paused
186  bool isPaused;
187  bool dcopFlag_; // true if this is a DCOP calculation.
188 
191  double endTRANtime_;
192  bool gui_; // command line arg -gui is present
193 
194  bool historyTrackingOn_; // bool to indicate if history tracking is on.
195 
196  // These are used to track the minimum estimated error over tol. of failed
197  // time steps so that if we're going to exit with a time step too small error,
198  // we can have the option of accepting whatever step had the minimum error.
202 
204  Util::ExpressionData * maxTimeStepExpression_;
205 
206  // here we store stats on the last few time steps
207  // to report if Xyce fails. A user can use this info
208  // to figure how how to make the simulation work.
209  // The number of items saved is set in the constructor
210  Util::FixedQueue<double> timeQueue_;
211  Util::FixedQueue<double> timeStepQueue_;
212  Util::FixedQueue<int> stepStatusQueue_;
213  Util::FixedQueue<double> estErrorOverTolQueue_;
214  Util::FixedQueue<int> nonlinearSolverStatusQueue_;
215  Util::FixedQueue<int> nonlinearSolverNumIterationsQueue_;
216  Util::FixedQueue<double> nonlinearSolverMaxNormQueue_;
217  Util::FixedQueue<double> nonlinearSolverMaxNormIndexQueue_;
218  // Util::FixedQueue<double> nonlinearSolverNormQueue_;
219 
220  bool firstTime;
222  double startSimTime;
224  int dcStats;
226  double exitTime; ///< Exit when it exceeds this time.
227  int exitStep; ///< Exit after taking this many steps.
228  unsigned int integrationMethod; ///< Time-integration method
229 
230 
231  // Xyce tracks how the last few timesteps have gone for error reporting
232  // if Xyce has to exit. This var specifies how many time steps (both
233  // passing and failing) to keep in its history. If it's zero, then
234  // history tracking is off.
236 
237  bool passNLStall; ///< option to pass some non-linear solver failures
238  bool saveTimeStepsFlag; ///< flag to save timestpes in data store for later use
239  bool condTestFlag; ///< flag for conductance test
240  std::vector<std::string> condTestDeviceNames; ///< names for conductance test
241 
243  N_MPDE_Manager * mpdeManager_;
244 
245  // Sensitivity data. This will need a refactor to work in transient, but for
246  // now this needs to be here to compile.
247  std::vector<double> objectiveVec_;
248  std::vector<double> dOdpVec_;
249  std::vector<double> dOdpAdjVec_;
250  std::vector<double> scaled_dOdpVec_;
251  std::vector<double> scaled_dOdpAdjVec_;
252 };
253 
254 std::vector<double>
256  double current_time,
257  double next_output_time,
258  double final_output_time,
259  double initial_output_interval,
260  const IO::IntervalVector & output_intervals);
261 
262 double
264  double current_time,
265  double next_output_time,
266  double final_output_time,
267  double initial_output_interval,
268  const IO::IntervalVector & output_intervals);
269 
270 bool
272  double current_time,
273  double next_output_time,
274  double start_time);
275 
276 bool
278  Analysis::AnalysisManager & analysis_manager,
279  IO::InitialConditionsManager & initial_conditions_manager);
280 
281 // Queries about output and restart times
282 bool
284  AnalysisManager & analysis_manager,
285  IO::RestartMgr & restart_manager,
286  double current_time,
287  double & next_restart_save_time);
288 
289 bool
290 registerTransientFactory(FactoryBlock &factory_block);
291 
292 } // namespace Analysis
293 } // namespace Xyce
294 
295 #endif // Xyce_N_ANP_Transient_h
Util::FixedQueue< double > timeQueue_
TimeIntg::TIAParams tiaParams_
IO::InitialConditionsManager & initialConditionsManager_
void notify(const StepEvent &event)
bool testRestartSaveTime(AnalysisManager &analysis_manager, IO::RestartMgr &restart_manager, double current_time, double &next_restart_save_time)
const TimeIntg::TIAParams & getTIAParams() const
bool testSaveOutputTime(Analysis::AnalysisManager &analysis_manager, IO::InitialConditionsManager &initial_conditions_manager)
Pure virtual class to augment a linear system.
std::vector< std::string > condTestDeviceNames
names for conductance test
std::vector< double > objectiveVec_
Topo::Topology & topology_
IO::RestartMgr & restartManager_
void setTIAParams(const TimeIntg::TIAParams &tia_params)
Util::FixedQueue< int > nonlinearSolverStatusQueue_
std::vector< double > dOdpAdjVec_
Util::ExpressionData * maxTimeStepExpression_
Linear::System & linearSystem_
int exitStep
Exit after taking this many steps.
OutputMgrAdapter & outputManagerAdapter_
Util::FixedQueue< int > nonlinearSolverNumIterationsQueue_
Util::ListenerAutoSubscribe< StepEvent > StepEventListener
std::vector< double > dOdpVec_
void setSaveTimeSteps(bool save_time_steps)
bool saveTimeStepsFlag
flag to save timestpes in data store for later use
bool registerTransientFactory(FactoryBlock &factory_block)
bool mixedSignalStep(double maxTimeStepFromHabanero)
Nonlinear::Manager & nonlinearManager_
The FactoryBlock contains parameters needed by the analysis creation functions.
OutputAdapter * outputAdapter_
Util::FixedQueue< double > nonlinearSolverMaxNormQueue_
void printProgress(std::ostream &os)
void preMixedSignalStepDetails(double maxTimeStepFromHabanero)
AnalysisManager & analysisManager_
bool retakeAndAcceptTimeStep(double aTimeStep)
N_MPDE_Manager * mpdeManager_
bool setTimeIntegratorOptions(const Util::OptionBlock &option_block)
unsigned int initialIntegrationMethod_
unsigned int integrationMethod
Time-integration method.
bool setAnalysisParams(const Util::OptionBlock &paramsBlock)
std::vector< double > scaled_dOdpAdjVec_
std::string maxTimeStepExpressionString_
double updateOutputTime(double current_time, double next_output_time, double final_output_time, double initial_output_interval, const IO::IntervalVector &output_intervals)
Util::FixedQueue< double > timeStepQueue_
std::vector< double > scaled_dOdpVec_
Util::FixedQueue< int > stepStatusQueue_
bool condTestFlag
flag for conductance test
TimeIntg::TIAParams & getTIAParams()
double exitTime
Exit when it exceeds this time.
Util::FixedQueue< double > nonlinearSolverMaxNormIndexQueue_
void printStepHeader(std::ostream &os)
bool passNLStall
option to pass some non-linear solver failures
Transient(AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Loader::Loader &loader, Topo::Topology &topology, IO::InitialConditionsManager &initial_conditions_manager, IO::RestartMgr &restart_manager, OutputAdapter *output_adapter=0, HB *hb_analysis=0, N_MPDE_Manager *mpde_manager=0)
Util::FixedQueue< double > estErrorOverTolQueue_
std::vector< double > computeOutputInterpolationTimes(double current_time, double next_output_time, double final_output_time, double initial_output_interval, const IO::IntervalVector &output_intervals)
bool testOutputTime(double current_time, double next_output_time, double start_time)