Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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.37 $
41 // Revision Date : $Date: 2014/08/05 21:41:35 $
42 // Current Owner : $Author: dgbaur $
43 //-----------------------------------------------------------------------------
44 
45 #ifndef Xyce_N_ANP_Transient_h
46 #define Xyce_N_ANP_Transient_h
47 
48 #include <Teuchos_RefCountPtr.hpp>
49 using Teuchos::RefCountPtr;
50 using Teuchos::rcp;
51 
52 #include <N_ANP_fwd.h>
53 #include <N_UTL_fwd.h>
54 #include <N_PDS_fwd.h>
55 
56 #include <N_ANP_AnalysisBase.h>
57 #include <N_ANP_StepEvent.h>
58 #include <N_UTL_FixedQueue.h>
59 #include <N_UTL_Listener.h>
60 
61 namespace Xyce {
62 namespace Analysis {
63 
64 //-------------------------------------------------------------------------
65 // Class : Transient
66 // Purpose : Transient analysis class
67 // Special Notes :
68 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
69 // Creation Date : 01/24/08
70 //-------------------------------------------------------------------------
71 class Transient : public AnalysisBase, public Util::ListenerAutoSubscribe<StepEvent>
72 {
73  public:
74  Transient(AnalysisManager &analysis_manager);
75 
76  virtual ~Transient() {}
77 
78  void notify(const StepEvent &event);
79 
80  bool setAnalysisParams(const Util::OptionBlock & paramsBlock);
81 
82  bool run();
83  bool init();
84  bool loopProcess();
85  bool processSuccessfulDCOP();
86  bool processFailedDCOP();
87  bool processSuccessfulStep();
88  bool processFailedStep();
89  bool finish();
90  bool handlePredictor();
91  bool resetForHB();
92  void outputQueuedData();
93  bool finalVerboseOutput();
94 
95  void printStepHeader(std::ostream &os);
96  void printProgress(std::ostream &os);
97 
98 
99  // mixed-signal specific
100  void preStepDetails (double maxTimeStepFromHabanero);
101  bool mixedSignalStep();
102  bool finalizeStep ();
103 
104  // Two Level specific
105  bool twoLevelStep();
106 
107  void setDCOPFlag(bool flag) { dcopFlag_ = flag; }
108  bool getDCOPFlag() { return dcopFlag_; }
109 
110  int getDCStats() { return dcStats; }
111  int getTranStats() { return tranStats; }
112 
113  private:
114  Parallel::Machine comm_;
115 
116  // 05/26/09 Coffey,Schiek,Mei: We moved these functions from AnalysisManager ----v
119  std::vector<double> outputInterpolationTimes_;
120  void computeOutputInterpolationTimes_(double currTime);
121  void updateOutputTime_(double currTime);
122  bool testOutputTime_();
123 
124  void noopOutputs ();
125  void tranopOutputs ();
126  void tranStepOutputs ();
127  // 05/26/09 Coffey,Schiek,Mei: We moved these functions from AnalysisManager ----^
128 
129  void takeAnIntegrationStep_();
130 
131  bool retakeAndAcceptTimeStep( double aTimeStep );
132 
133  // a flag to indicate of the simulation is paused
134  bool isPaused;
135  bool dcopFlag_; // true if this is a DCOP calculation.
136 
137  double startDCOPtime, endTRANtime; // startTRANtime
138  bool gui_; // command line arg -gui is present
139 
140  bool historyTrackingOn_; // bool to indicate if history tracking is on.
141 
142  // These are used to track the minimum estimated error over tol. of failed
143  // time steps so that if we're going to exit with a time step too small error,
144  // we can have the option of accepting whatever step had the minimum error.
148  // Timing/loop count info
149  // int dcStats;
150  //
151  // for handling expressions given for a time dependent max time step
154  RefCountPtr<Util::ExpressionData> maxTimeStepExpressionRCPtr_;
155 
156  // here we store stats on the last few time steps
157  // to report if Xyce fails. A user can use this info
158  // to figure how how to make the simulation work.
159  // The number of items saved is set in the constructor
161  Util::FixedQueue<double> timeQueue_;
162  Util::FixedQueue<double> timeStepQueue_;
163  Util::FixedQueue<int> stepStatusQueue_;
164  Util::FixedQueue<double> estErrorOverTolQueue_;
165  Util::FixedQueue<int> nonlinearSolverStatusQueue_;
166  Util::FixedQueue<int> nonlinearSolverNumIterationsQueue_;
167  Util::FixedQueue<double> nonlinearSolverMaxNormQueue_;
168  Util::FixedQueue<double> nonlinearSolverMaxNormIndexQueue_;
169  // Util::FixedQueue<double> nonlinearSolverNormQueue_;
170 
171  // solution variable names vector, used in outputting Queued data.
172  std::vector<std::string> nameVec_;
173 
174  bool firstTime;
176  double startSimTime;
177  int dcStats;
179 
180  // Sensitivity data. This will need a refactor to work in transient, but for
181  // now this needs to be here to compile.
182  std::vector<double> objectiveVec_;
183  std::vector<double> dOdpVec_;
184  std::vector<double> dOdpAdjVec_;
185  std::vector<double> scaled_dOdpVec_;
186  std::vector<double> scaled_dOdpAdjVec_;
187 };
188 
189 } // namespace Analysis
190 } // namespace Xyce
191 
193 
194 #endif // Xyce_N_ANP_Transient_h