Xyce  6.1
N_TIA_OneStep.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_TIA_OneStep.h,v $
27 //
28 // Purpose : This file defines the classes for trapezoidal method
29 // order 1-2 method.
30 //
31 // Special Notes :
32 //
33 // Creator : Ting Mei
34 //
35 // Creation Date : 10/31/07
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.35.2.1 $
41 //
42 // Revision Date : $Date: 2015/04/02 18:20:18 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_TIA_ONE_STEP_H
48 #define Xyce_N_TIA_ONE_STEP_H
49 
50 
51 // ---------- Standard Includes ----------
52 // ---------- Xyce Includes ----------
53 #include <N_TIA_DataStore.h>
54 #include <N_TIA_StepErrorControl.h>
56 #include <N_PDS_ParMap.h>
57 #include <N_UTL_IndexPair.h>
58 #include <N_UTL_Math.h>
59 
60 namespace Xyce {
61 namespace TimeIntg {
62 
63 //-----------------------------------------------------------------------------
64 // Class : OneStep
65 // Purpose : OneStep Formula Integration Class
66 // (derived from TimeIntegrationMethod)
67 // Special Notes :
68 // Creator : Ting Mei, SNL
69 // Creation Date : 10/31/07
70 //-----------------------------------------------------------------------------
72 {
73 public:
74  static const int type = 7;
75  static const char *name;
76 
77  static TimeIntegrationMethod *factory(const TIAParams &tia_params, StepErrorControl &step_error_control, DataStore &data_store);
78 
79  OneStep(
80  const TIAParams & tiaP,
81  StepErrorControl & secTmp,
82  DataStore & dsTmp) /* override */;
83 
84  ~OneStep() /* override */
85  {}
86 
87  const char *getName() const /* override */ {
88  return "Onestep: Trapezoidal";
89  }
90 
91  // Predict solution at next time point.
92  void obtainPredictor() /* override */;
93 
94  // Evaluate the predictor derivative formula.
95  void obtainPredictorDeriv() /* override */ {return;}
96 
97  // Evaluate the corrector derivative formula.
98  void obtainCorrectorDeriv() /* override */ {return;}
99 
100  // Compute an estimate of the error in the integration step.
101  void updateDerivsBlock(const std::list< IndexPair > & solGIDList,
102  const std::list< IndexPair > & staGIDList) /* override */ {return;}
103 
104  // Compute an estimate of the error in the integration step.
105  double computeErrorEstimate() const /* override */ { return sec.ck_*ds.WRMS_errorNorm() /* override */; }
106 
107  // Interpolate solution approximation at prescribed time point.
108  bool interpolateSolution(double timepoint,
109  Linear::Vector * tmpSolVectorPtr, std::vector<Linear::Vector*> & historyVec) /* override */;
110 
111  // Interpolate MPDE solution approximation at prescribed time point.
112  bool interpolateMPDESolution(std::vector<double>& timepoint,
113  Linear::Vector * tmpSolVectorPtr) /* override */;
114 
115  // Print output using interpolation when order is high
116  bool printOutputSolution(
117  Analysis::OutputMgrAdapter & outputManagerAdapter,
118  const TIAParams & tia_params,
119  const double time,
120  Linear::Vector * solnVecPtr,
121  const bool doNotInterpolate,
122  const std::vector<double> & outputInterpolationTimes,
123  bool skipPrintLineOutput ) /* override */;
124 
125  // Print transient output from MPDE simulation
127  Analysis::OutputMgrAdapter & outputManagerAdapter,
128  const double time,
129  Linear::Vector * solnVecPtr,
130  const std::vector<double> & fastTimes ) /* override */;
131 
132  // Print transient output from WaMPDE simulation
134  Analysis::OutputMgrAdapter & outputManagerAdapter,
135  const double time,
136  Linear::Vector * solnVecPtr,
137  const std::vector<double> & fastTimes,
138  const int phiGID ) /* override */;
139 
140  // .SAVE output using interpolation when order is high
141  bool saveOutputSolution(
142  Analysis::OutputMgrAdapter & outputManagerAdapter,
143  const TIAParams & tia_params,
144  Linear::Vector * solnVecPtr,
145  const double saveTime,
146  const bool doNotInterpolate) /* override */;
147 
148  // Computes the step adjustment.
149  double computeExpoStepAdjust(double stepadjust) /* override */
150  {
151  return pow(stepadjust, 1.0 / 3.0);
152  }
153 
154  // Gets the time-integration order.
155  int getOrder() const /* override */
156  {
157  return sec.currentOrder_;
158  }
159 
160  int getNumberOfSteps() const /* override */
161  {
162  return sec.numberOfSteps_;
163  }
164 
165  int getUsedOrder() const /* override */
166  {
167  return sec.usedOrder_;
168  }
169 
170  int getNscsco() const /* override */
171  {
172  return sec.nscsco_;
173  }
174 
175  int getMaxOrder() const /* override */
176  {
177  return sec.maxOrder_;
178  }
179 
180  void getInitialQnorm(TwoLevelError & tle) const /* override */;
181  void getTwoLevelError(TwoLevelError & tle) const /* override */;
182 
183  // This is for new-DAE.
184  void updateStateDeriv() /* override */;
185 
186  // calculates dQ/dt component of store vector and adds it to store vector
187  void updateLeadCurrent() /* override */;
188 
189  // calculates dQ/dt component of lead current Q vector and adds it to the lead current vector
190  void updateLeadCurrentVec() /* override */;
191 
192 
193  double partialTimeDeriv() /* override */ const;
194 
195  // Gets the leading coefficient for the specified time-integration method.
196  double getLeadingCoeff() const /* override */
197  {
198  return leadingCoeff;
199  }
200 
201  // sets the leading coefficient for the specified time-integration method.
202  void setLeadingCoeff(double & LC) /* override */
203  {
204  leadingCoeff = LC;
205  }
206 
207  // Evaluate corrector residual for nonlinear solver
208  void obtainResidual() /* override */;
209 
210  // obtain residuals for transient sensitivity analysis
211  void obtainSensitivityResiduals() /* override */;
212 
213  // obtain final derivatives w.r.t. time for transient sensitivity analysis
214  void loadFinalSensitivityDerivatives() /* override */;
215 
216  // Evaluate corrector Jacobian for nonlinear solver
217  void obtainJacobian() /* override */;
218 
219  // Update history array after a successful step
220  void updateHistory() /* override */;
221 
222  // Restore history array after a failed step
223  void restoreHistory() /* override */;
224 
225  // Update method coefficients
226  void updateCoeffs() /* override */;
227 
228  // Initialize method with initial solution & step-size
229  void initialize(const TIAParams &tia_params) /* override */;
230 
231  // setup 2-level data.
232  void setTwoLevelTimeInfo(const TimeIntInfo & tiInfo) /* override */;
233 
234  // Reject a step(this turns back history and chooses new order & step-size) /* override */
235  void rejectStep(const TIAParams &tia_params) /* override */;
236 
237  // Reject a step, but only restore the history, as the new step will be
238  // imposed by an outside program.
239  void rejectStepForHabanero() /* override */;
240 
241  // Complete a step(this updates history and chooses new order & step-size) /* override */
242  void completeStep(const TIAParams &tia_params) /* override */;
243 
244 private:
245  // Initialize arrays related to sensitivities
246  void initializeSensitivities() /* override */;
247 
248  // Predict solution at next time point.
249  void obtainSensitivityPredictors() /* override */;
250 
251  // Update sensitivity history arrays after a successful step
252  void updateSensitivityHistory() /* override */;
253 
254  // Check whether to reduce order independent of local error test
255  void checkReduceOrder() /* override */;
256 
257 private:
258  // used for second order interpolation where the last two times steps are needed.
259  // lastTimeStep is stored in StepErrorControl and the last, last time step is stored
260  // here as it's only needed by trap. Called timeStepForHistory2 as it's the
261  // time step associated with the step in xHistory[2]
263  double timept_; ///< Keep track of last interpolation point in printMPDEOutputSolution
264  DataStore & ds; ///< Reference to the TIA data-store object.
265  StepErrorControl & sec; ///< Reference to step-error control object
266  double leadingCoeff; ///< Time-integration method leading coefficient value.
267 };
268 
269 } // namespace TimeIntg
270 } // namespace Xyce
271 
272 #endif //Xyce_N_TIA_ONE_STEP_H
273 
void setLeadingCoeff(double &LC)
int getNumberOfSteps() const
bool interpolateSolution(double timepoint, Linear::Vector *tmpSolVectorPtr, std::vector< Linear::Vector * > &historyVec)
static const int type
Definition: N_TIA_OneStep.h:74
bool printOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const TIAParams &tia_params, const double time, Linear::Vector *solnVecPtr, const bool doNotInterpolate, const std::vector< double > &outputInterpolationTimes, bool skipPrintLineOutput)
double computeExpoStepAdjust(double stepadjust)
Pure virtual class to augment a linear system.
double computeErrorEstimate() const
void initialize(const TIAParams &tia_params)
void rejectStep(const TIAParams &tia_params)
bool printMPDEOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const double time, Linear::Vector *solnVecPtr, const std::vector< double > &fastTimes)
const char * getName() const
Definition: N_TIA_OneStep.h:87
void completeStep(const TIAParams &tia_params)
double getLeadingCoeff() const
DataStore & ds
Reference to the TIA data-store object.
StepErrorControl & sec
Reference to step-error control object.
bool saveOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const TIAParams &tia_params, Linear::Vector *solnVecPtr, const double saveTime, const bool doNotInterpolate)
double leadingCoeff
Time-integration method leading coefficient value.
void getInitialQnorm(TwoLevelError &tle) const
bool printWaMPDEOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const double time, Linear::Vector *solnVecPtr, const std::vector< double > &fastTimes, const int phiGID)
static TimeIntegrationMethod * factory(const TIAParams &tia_params, StepErrorControl &step_error_control, DataStore &data_store)
Definition: N_TIA_OneStep.C:90
bool interpolateMPDESolution(std::vector< double > &timepoint, Linear::Vector *tmpSolVectorPtr)
OneStep(const TIAParams &tiaP, StepErrorControl &secTmp, DataStore &dsTmp)
void updateDerivsBlock(const std::list< IndexPair > &solGIDList, const std::list< IndexPair > &staGIDList)
void loadFinalSensitivityDerivatives()
double timept_
Keep track of last interpolation point in printMPDEOutputSolution.
int getMaxOrder() const
Return max order of method (this should obey user option maxorder)
void setTwoLevelTimeInfo(const TimeIntInfo &tiInfo)
double partialTimeDeriv() const
static const char * name
Definition: N_TIA_OneStep.h:75
void getTwoLevelError(TwoLevelError &tle) const