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.38 $
41 //
42 // Revision Date : $Date: 2015/06/05 20:49:43 $
43 //
44 // Current Owner : $Author: dgbaur $
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  Parallel::Machine comm,
143  IO::InitialConditionsManager & initial_conditions_manager,
144  const NodeNameMap & node_name_map,
145  const TIAParams & tia_params,
146  Linear::Vector * solnVecPtr,
147  const double saveTime,
148  const bool doNotInterpolate) /* override */;
149 
150  // Computes the step adjustment.
151  double computeExpoStepAdjust(double stepadjust) /* override */
152  {
153  return pow(stepadjust, 1.0 / 3.0);
154  }
155 
156  // Gets the time-integration order.
157  int getOrder() const /* override */
158  {
159  return sec.currentOrder_;
160  }
161 
162  int getNumberOfSteps() const /* override */
163  {
164  return sec.numberOfSteps_;
165  }
166 
167  int getUsedOrder() const /* override */
168  {
169  return sec.usedOrder_;
170  }
171 
172  int getNscsco() const /* override */
173  {
174  return sec.nscsco_;
175  }
176 
177  int getMaxOrder() const /* override */
178  {
179  return sec.maxOrder_;
180  }
181 
182  void getInitialQnorm(TwoLevelError & tle) const /* override */;
183  void getTwoLevelError(TwoLevelError & tle) const /* override */;
184 
185  // This is for new-DAE.
186  void updateStateDeriv() /* override */;
187 
188  // calculates dQ/dt component of store vector and adds it to store vector
189  void updateLeadCurrent() /* override */;
190 
191  // calculates dQ/dt component of lead current Q vector and adds it to the lead current vector
192  void updateLeadCurrentVec() /* override */;
193 
194 
195  double partialTimeDeriv() /* override */ const;
196 
197  // Gets the leading coefficient for the specified time-integration method.
198  double getLeadingCoeff() const /* override */
199  {
200  return leadingCoeff;
201  }
202 
203  // sets the leading coefficient for the specified time-integration method.
204  void setLeadingCoeff(double & LC) /* override */
205  {
206  leadingCoeff = LC;
207  }
208 
209  // Evaluate corrector residual for nonlinear solver
210  void obtainResidual() /* override */;
211 
212  // obtain residuals for transient sensitivity analysis
213  void obtainSensitivityResiduals() /* override */;
214 
215  // obtain final derivatives w.r.t. time for transient sensitivity analysis
216  void loadFinalSensitivityDerivatives() /* override */;
217 
218  // Evaluate corrector Jacobian for nonlinear solver
219  void obtainJacobian() /* override */;
220 
221  // Update history array after a successful step
222  void updateHistory() /* override */;
223 
224  // Restore history array after a failed step
225  void restoreHistory() /* override */;
226 
227  // Update method coefficients
228  void updateCoeffs() /* override */;
229 
230  // Initialize method with initial solution & step-size
231  void initialize(const TIAParams &tia_params) /* override */;
232 
233  // setup 2-level data.
234  void setTwoLevelTimeInfo() /* override */;
235 
236  // Reject a step(this turns back history and chooses new order & step-size) /* override */
237  void rejectStep(const TIAParams &tia_params) /* override */;
238 
239  // Reject a step, but only restore the history, as the new step will be
240  // imposed by an outside program.
241  void rejectStepForHabanero() /* override */;
242 
243  // Complete a step(this updates history and chooses new order & step-size) /* override */
244  void completeStep(const TIAParams &tia_params) /* override */;
245 
246 private:
247  // Initialize arrays related to sensitivities
248  void initializeSensitivities() /* override */;
249 
250  // Predict solution at next time point.
251  void obtainSensitivityPredictors() /* override */;
252 
253  // Update sensitivity history arrays after a successful step
254  void updateSensitivityHistory() /* override */;
255 
256  // Check whether to reduce order independent of local error test
257  void checkReduceOrder() /* override */;
258 
259 private:
260  // used for second order interpolation where the last two times steps are needed.
261  // lastTimeStep is stored in StepErrorControl and the last, last time step is stored
262  // here as it's only needed by trap. Called timeStepForHistory2 as it's the
263  // time step associated with the step in xHistory[2]
265  double timept_; ///< Keep track of last interpolation point in printMPDEOutputSolution
266  DataStore & ds; ///< Reference to the TIA data-store object.
267  StepErrorControl & sec; ///< Reference to step-error control object
268  double leadingCoeff; ///< Time-integration method leading coefficient value.
269 };
270 
271 } // namespace TimeIntg
272 } // namespace Xyce
273 
274 #endif //Xyce_N_TIA_ONE_STEP_H
275 
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.
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:91
bool saveOutputSolution(Parallel::Machine comm, IO::InitialConditionsManager &initial_conditions_manager, const NodeNameMap &node_name_map, const TIAParams &tia_params, Linear::Vector *solnVecPtr, const double saveTime, const bool doNotInterpolate)
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)
double partialTimeDeriv() const
static const char * name
Definition: N_TIA_OneStep.h:75
void getTwoLevelError(TwoLevelError &tle) const