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.78.2.1 $
41 // Revision Date : $Date: 2015/04/02 18:20:06 $
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_TOP_fwd.h>
50 #include <N_UTL_fwd.h>
51 
52 #include <N_ANP_AnalysisBase.h>
53 #include <N_ANP_Factory.h>
54 #include <N_ANP_StepEvent.h>
55 #include <N_TIA_TIAParams.h>
56 #include <N_UTL_FixedQueue.h>
57 #include <N_UTL_Listener.h>
58 #include <N_UTL_OptionBlock.h>
59 
60 class N_MPDE_Manager;
61 
62 namespace Xyce {
63 namespace Analysis {
64 
65 typedef Util::ListenerAutoSubscribe<StepEvent> StepEventListener;
66 
67 //-------------------------------------------------------------------------
68 // Class : Transient
69 // Purpose : Transient analysis class
70 // Special Notes :
71 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
72 // Creation Date : 01/24/08
73 //-------------------------------------------------------------------------
74 class Transient : public AnalysisBase, public StepEventListener
75 {
76 public:
77  Transient(
78  AnalysisManager & analysis_manager,
79  Linear::System & linear_system,
80  Nonlinear::Manager & nonlinear_manager,
81  Topo::Topology & topology,
82  OutputAdapter * output_adapter = 0,
83  HB * hb_analysis = 0, // HACK TO GET US MOVING FORWARD, should pass output adapter or something
84  N_MPDE_Manager * mpde_manager = 0); // HACK TO GET US MOVING FORWARD, should pass output adapter or something
85 
86  virtual ~Transient()
87  {}
88 
89  void notify(const StepEvent &event);
90 
91  void setTIAParams(const TimeIntg::TIAParams &tia_params) {
92  tiaParams_ = tia_params;
93  }
94 
96  return tiaParams_;
97  }
98 
100  return tiaParams_;
101  }
102 
103  bool setAnalysisParams(const Util::OptionBlock & paramsBlock); // override;
104  bool setTimeIntegratorOptions(const Util::OptionBlock &option_block);
105 
106  bool doRun(); // override;
107  bool doInit(); // override;
108  bool doLoopProcess(); // override;
109  bool doProcessSuccessfulStep(); // override;
110  bool doProcessFailedStep(); // override;
111  bool doFinish(); // override;
112  bool doHandlePredictor(); // override;
113 
114  bool processSuccessfulDCOP();
115  bool processFailedDCOP();
116 
117  bool resetForHB();
118  bool finalVerboseOutput();
119 
120  void printStepHeader(std::ostream &os);
121  void printProgress(std::ostream &os);
122 
123  // mixed-signal specific
124  bool mixedSignalStep(double maxTimeStepFromHabanero);
126 
127  // Two Level specific
128  bool twoLevelStep();
129 
130  bool getDCOPFlag() const
131  {
132  return dcopFlag_;
133  }
134 
135  int getDCStats() { return dcStats; }
136  int getTranStats() { return tranStats; }
137 
138  void setSaveTimeSteps(bool save_time_steps)
139  {
140  saveTimeStepsFlag = save_time_steps;
141  }
142 
143 private:
144  void preMixedSignalStepDetails(double maxTimeStepFromHabanero);
145  void noopOutputs ();
146  void tranopOutputs ();
147  void tranStepOutputs ();
148 
149  void takeAnIntegrationStep_();
150 
151  bool retakeAndAcceptTimeStep( double aTimeStep );
152 
153  void logQueuedData();
154 
155 private:
156  Parallel::Machine comm_;
159  Linear::System & linearSystem_;
161  Topo::Topology & topology_;
164 
166 
167  bool sensFlag_;
168 
171 
172  // a flag to indicate of the simulation is paused
173  bool isPaused;
174  bool dcopFlag_; // true if this is a DCOP calculation.
175 
178  double endTRANtime_;
179  bool gui_; // command line arg -gui is present
180 
181  bool historyTrackingOn_; // bool to indicate if history tracking is on.
182 
183  // These are used to track the minimum estimated error over tol. of failed
184  // time steps so that if we're going to exit with a time step too small error,
185  // we can have the option of accepting whatever step had the minimum error.
189 
191  Util::ExpressionData * maxTimeStepExpression_;
192 
193  // here we store stats on the last few time steps
194  // to report if Xyce fails. A user can use this info
195  // to figure how how to make the simulation work.
196  // The number of items saved is set in the constructor
197  Util::FixedQueue<double> timeQueue_;
198  Util::FixedQueue<double> timeStepQueue_;
199  Util::FixedQueue<int> stepStatusQueue_;
200  Util::FixedQueue<double> estErrorOverTolQueue_;
201  Util::FixedQueue<int> nonlinearSolverStatusQueue_;
202  Util::FixedQueue<int> nonlinearSolverNumIterationsQueue_;
203  Util::FixedQueue<double> nonlinearSolverMaxNormQueue_;
204  Util::FixedQueue<double> nonlinearSolverMaxNormIndexQueue_;
205  // Util::FixedQueue<double> nonlinearSolverNormQueue_;
206 
207  bool firstTime;
209  double startSimTime;
210  int dcStats;
212  double exitTime; ///< Exit when it exceeds this time.
213  int exitStep; ///< Exit after taking this many steps.
214  unsigned int integrationMethod; ///< Time-integration method
215 
216 
217  // Xyce tracks how the last few timesteps have gone for error reporting
218  // if Xyce has to exit. This var specifies how many time steps (both
219  // passing and failing) to keep in its history. If it's zero, then
220  // history tracking is off.
222 
223  bool passNLStall; ///< option to pass some non-linear solver failures
224  bool saveTimeStepsFlag; ///< flag to save timestpes in data store for later use
225  bool condTestFlag; ///< flag for conductance test
226  std::vector<std::string> condTestDeviceNames; ///< names for conductance test
227  bool outputInterpMPDE; ///< flag for interpolating the MPDE output. Sometimes, the interpolation is the hard part.
228 
230  N_MPDE_Manager * mpdeManager_;
231 
232  // Sensitivity data. This will need a refactor to work in transient, but for
233  // now this needs to be here to compile.
234  std::vector<double> objectiveVec_;
235  std::vector<double> dOdpVec_;
236  std::vector<double> dOdpAdjVec_;
237  std::vector<double> scaled_dOdpVec_;
238  std::vector<double> scaled_dOdpAdjVec_;
239 };
240 
241 std::vector<double>
243  double current_time,
244  double next_output_time,
245  double final_output_time,
246  double initial_output_interval,
247  const IO::IntervalVector & output_intervals);
248 
249 double
251  double current_time,
252  double next_output_time,
253  double final_output_time,
254  double initial_output_interval,
255  const IO::IntervalVector & output_intervals);
256 
257 bool
259  double current_time,
260  double next_output_time,
261  double start_time);
262 
263 bool
265  const std::string & netlist_filename,
266  IO::PkgOptionsMgr & options_manager,
267  AnalysisManager & analysis_manager,
268  Linear::System & linear_system,
269  Nonlinear::Manager & nonlinear_manager,
270  Topo::Topology & topology);
271 
272 } // namespace Analysis
273 } // namespace Xyce
274 
275 #endif // Xyce_N_ANP_Transient_h
Transient(AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Topo::Topology &topology, OutputAdapter *output_adapter=0, HB *hb_analysis=0, N_MPDE_Manager *mpde_manager=0)
Util::FixedQueue< double > timeQueue_
TimeIntg::TIAParams tiaParams_
void notify(const StepEvent &event)
const TimeIntg::TIAParams & getTIAParams() const
Pure virtual class to augment a linear system.
std::vector< std::string > condTestDeviceNames
names for conductance test
std::vector< double > objectiveVec_
Topo::Topology & topology_
bool registerTransientFactory(const std::string &netlist_filename, IO::PkgOptionsMgr &options_manager, AnalysisManager &analysis_manager, Linear::System &linear_system, Nonlinear::Manager &nonlinear_manager, Topo::Topology &topology)
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 mixedSignalStep(double maxTimeStepFromHabanero)
Nonlinear::Manager & nonlinearManager_
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.
Factory for creating analysis objects.
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.
bool outputInterpMPDE
flag for interpolating the MPDE output. Sometimes, the interpolation is the hard part.
Util::FixedQueue< double > nonlinearSolverMaxNormIndexQueue_
void printStepHeader(std::ostream &os)
bool passNLStall
option to pass some non-linear solver failures
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)