Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.21.2.1 $
41 //
42 // Revision Date : $Date: 2014/09/02 22:49:49 $
43 //
44 // Current Owner : $Author: erkeite $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_TIA_ONE_STEP_H
48 #define Xyce_N_TIA_ONE_STEP_H
49 
50 
51 // ---------- Standard Includes ----------
52 #ifdef HAVE_CMATH
53 #include <cmath>
54 #else
55 #include <math.h>
56 #endif
57 
58 #include <Teuchos_RefCountPtr.hpp>
59 using Teuchos::RefCountPtr;
60 using Teuchos::rcp;
61 
62 // ---------- Xyce Includes ----------
63 #include <N_TIA_DataStore.h>
64 #include <N_TIA_StepErrorControl.h>
66 #include <N_PDS_ParMap.h>
67 
68 //-----------------------------------------------------------------------------
69 // Class : N_TIA_OneStep
70 // Purpose : OneStep Formula Integration Class
71 // (derived from N_TIA_TimeIntegrationMethod)
72 // Special Notes :
73 // Creator : Ting Mei, SNL
74 // Creation Date : 10/31/07
75 //-----------------------------------------------------------------------------
77 {
78 public:
79 
80  // Destructor
82 
83  // Predict solution at next time point.
84  virtual void obtainPredictor();
85 
86  // Predict solution at next time point.
87  virtual void obtainSensitivityPredictors();
88 
89  // Evaluate the predictor derivative formula.
90  virtual void obtainPredictorDeriv() {return;}
91 
92  // Evaluate the corrector derivative formula.
93  virtual void obtainCorrectorDeriv() {return;}
94 
95  // Compute an estimate of the error in the integration step.
96  virtual void updateDerivsBlock(const std::list< index_pair > & solGIDList,
97  const std::list< index_pair > & staGIDList) {return;}
98 
99  // Compute an estimate of the error in the integration step.
100  virtual double computeErrorEstimate() { return sec.ck_*ds.WRMS_errorNorm(); }
101 
102  // Interpolate solution approximation at prescribed time point.
103  virtual bool interpolateSolution(double timepoint,
104  N_LAS_Vector * tmpSolVectorPtr, std::vector<N_LAS_Vector*> & historyVec);
105 
106  // Interpolate MPDE solution approximation at prescribed time point.
107  virtual bool interpolateMPDESolution(std::vector<double>& timepoint,
108  N_LAS_Vector * tmpSolVectorPtr);
109 
110  // Print transient output from MPDE simulation
111  virtual bool printMPDEOutputSolution(
112  N_ANP_OutputMgrAdapter & outputManagerAdapter,
113  const double time,
114  N_LAS_Vector * solnVecPtr,
115  const std::vector<double> & fastTimes );
116 
117  // Print transient output from WaMPDE simulation
118  virtual bool printWaMPDEOutputSolution(
119  N_ANP_OutputMgrAdapter & outputManagerAdapter,
120  const double time,
121  N_LAS_Vector * solnVecPtr,
122  const std::vector<double> & fastTimes,
123  const int phiGID );
124 
125  // Print output using interpolation when order is high
126  virtual bool printOutputSolution(
127  N_ANP_OutputMgrAdapter & outputManagerAdapter,
128  const double time,
129  N_LAS_Vector * solnVecPtr,
130  const bool doNotInterpolate,
131  const std::vector<double> & outputInterpolationTimes,
132  bool skipPrintLineOutput );
133 
134  // .SAVE output using interpolation when order is high
135  virtual bool saveOutputSolution(
136  N_ANP_OutputMgrAdapter & outputManagerAdapter,
137  N_LAS_Vector * solnVecPtr,
138  const double saveTime,
139  const bool doNotInterpolate);
140 
141  // Computes the step adjustment.
142  virtual double computeExpoStepAdjust(double stepadjust);
143 
144  // Gets the time-integration order.
145  virtual int getOrder() {return sec.currentOrder_;}
146  virtual int getUsedOrder() {return sec.usedOrder_;}
147  virtual int getNumberOfSteps () { return sec.numberOfSteps_; }
148  virtual int getNscsco () { return sec.nscsco_; }
149 
150  virtual void getInitialQnorm (N_TIA_TwoLevelError & tle);
151  virtual void setupTwoLevelError(N_TIA_TwoLevelError & tle);
152 
153  // 2/16/04 tscoffe: This is just for testing, we'll need a dynamic fcn later
154 
155  // Time-integration factory.
157  (N_TIA_TIAParams & tiaP,
158  N_TIA_StepErrorControl & secTmp ,
159  N_TIA_DataStore & dsTmp);
160 
161  // 03/08/04 tscoffe: New functions necessary for OneStep
162  // Evaluate corrector residual for nonlinear solver
163  virtual void obtainResidual();
164 
165  // obtain residuals for transient sensitivity analysis
166  virtual void obtainSensitivityResiduals();
167 
168  // obtain final derivatives w.r.t. time for transient sensitivity analysis
169  virtual void loadFinalSensitivityDerivatives();
170 
171  // Evaluate corrector Jacobian for nonlinear solver
172  virtual void obtainJacobian();
173 
174  // Update history array after a successful step
175  virtual void updateHistory();
176 
177  // Update sensitivity history arrays after a successful step
178  virtual void updateSensitivityHistory();
179 
180  // Restore history array after a failed step
181  virtual void restoreHistory();
182 
183  // Return max order of method (this should obey user option maxorder)
184  virtual int getMaxOrder(){ return sec.maxOrder_;}
185 
186  // Update method coefficients
187  virtual void updateCoeffs();
188 
189  // Initialize method with initial solution & step-size
190  virtual void initialize();
191 
192  // Initialize arrays related to sensitivities
193  virtual void initializeSensitivities();
194 
195  // setup 2-level data.
196  virtual void setTwoLevelTimeInfo(const N_TIA_TimeIntInfo & tiInfo);
197 
198  // Reject a step (this turns back history and chooses new order & step-size)
199  virtual void rejectStep();
200 
201  // Reject a step, but only restore the history, as the new step will be
202  // imposed by an outside program.
203  virtual void rejectStepForHabanero ();
204 
205  // Complete a step (this updates history and chooses new order & step-size)
206  virtual void completeStep();
207 
208  virtual void updateStateDeriv ();
209 
210  // calculates dQ/dt component of store vector and adds it to store vector
211  virtual void updateLeadCurrent ();
212 
213 private:
214 
215  // Constructor (private).
217  N_TIA_StepErrorControl & secTmp,
218  N_TIA_DataStore & dsTmp);
219 
220  // Check whether to reduce order independent of local error test
221  virtual void checkReduceOrder();
222 
224 
225  // Used to keep track of last interpolation point in printMPDEOutputSolution
226  double timept_;
227 
228  // used for second order interpolation where the last two times steps are needed.
229  // lastTimeStep is stored in StepErrorControl and the last, last time step is stored
230  // here as it's only needed by trap. Called timeStepForHistory2 as it's the
231  // time step associated with the step in xHistory[2]
233 };
234 
235  // Computes the step addjustment.
236  // 2/16/04 tscoffe: I'm not exactly sure what this routine is for...
238  double stepadjust)
239 {
240  return pow(stepadjust, 1.0 / 3.0);
241 }
242 
243 //-----------------------------------------------------------------------------
244 // Function : N_TIA_OneStep::factory
245 // Purpose :
246 // Special Notes :
247 // Scope : public
248 // Creator : Ting Mei, SNL
249 // Creation Date : 10/31/07
250 //-----------------------------------------------------------------------------
252  (N_TIA_TIAParams & tiaP,
253  N_TIA_StepErrorControl & secTmp ,
254  N_TIA_DataStore & dsTmp)
255 {
256  N_TIA_TimeIntegrationMethod * timPtr =
257  new N_TIA_OneStep(tiaP,secTmp,dsTmp);
258  return timPtr;
259 }
260 
261 #endif //Xyce_N_TIA_ONE_STEP_H
262