Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_TIA_BackwardDifferentiation15.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_BackwardDifferentiation15.h,v $
27 //
28 // Purpose : This file defines the classes for the backward
29 // differentiation, order 1-5 method.
30 //
31 // Special Notes :
32 //
33 // Creator : Todd Coffey
34 //
35 // Creation Date : 2/16/04
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.54.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_BACKWARD_DIFFERENTIATION_15_H
48 #define Xyce_N_TIA_BACKWARD_DIFFERENTIATION_15_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 #include <N_ANP_fwd.h>
63 #include <N_TIA_fwd.h>
64 #include <N_TIA_DataStore.h>
65 #include <N_TIA_StepErrorControl.h>
66 #include <N_PDS_ParMap.h>
67 
68 //-----------------------------------------------------------------------------
69 // Class : N_TIA_BackwardDifferentiation15
70 // Purpose : Backward Differentiation Formula (of order 1-5)
71 // Integration Class
72 // (derived from N_TIA_TimeIntegrationMethod)
73 // Special Notes :
74 // Creator : Todd Coffey, SNL
75 // Creation Date : 2/16/04
76 //-----------------------------------------------------------------------------
78 {
79 public:
80 
81  // Destructor
83 
84  // Predict solution at next time point (BDF1-5).
85  virtual void obtainPredictor();
86 
87  // obtain residuals for transient sensitivity analysis
88  virtual void obtainSensitivityResiduals();
89 
90  // obtain final derivatives w.r.t. time for transient sensitivity analysis
91  virtual void loadFinalSensitivityDerivatives() {return;}
92 
93  // Evaluate the predictor derivative formula (BDF1-5).
94  virtual void obtainPredictorDeriv() {return;}
95 
96  // Evaluate the corrector derivative formula (BDF1-5).
97  virtual void obtainCorrectorDeriv() {return;}
98 
99  // Compute an estimate of the error in the integration step (BDF1-5).
100  virtual void updateDerivsBlock(const std::list< index_pair > & solGIDList,
101  const std::list< index_pair > & staGIDList) {return;}
102 
103  // Compute an estimate of the error in the integration step (BDF1-5).
104  virtual double computeErrorEstimate() { return sec.ck_*ds.WRMS_errorNorm(); }
105 
106  // Interpolate solution approximation at prescribed time point (BDF1-5).
107  virtual bool interpolateSolution(double timepoint,
108  N_LAS_Vector * tmpSolVectorPtr, std::vector<N_LAS_Vector*> & historyVec);
109 
110  // Interpolate MPDE solution approximation at prescribed time point (BDF1-5).
111  virtual bool interpolateMPDESolution(std::vector<double>& timepoint,
112  N_LAS_Vector * tmpSolVectorPtr);
113 
114  // Print transient output from MPDE simulation
115  virtual bool printMPDEOutputSolution(
116  N_ANP_OutputMgrAdapter & outputManagerAdapter,
117  const double time,
118  N_LAS_Vector * solnVecPtr,
119  const std::vector<double> & fastTimes );
120 
121  // Print transient output from WaMPDE simulation
122  virtual bool printWaMPDEOutputSolution(
123  N_ANP_OutputMgrAdapter & outputManagerAdapter,
124  const double time,
125  N_LAS_Vector * solnVecPtr,
126  const std::vector<double> & fastTimes,
127  const int phiGID );
128 
129  // Print output using interpolation when order is high
130  virtual bool printOutputSolution(
131  N_ANP_OutputMgrAdapter & outputManagerAdapter,
132  const double time,
133  N_LAS_Vector * solnVecPtr,
134  const bool doNotInterpolate,
135  const std::vector<double> & outputInterpolationTimes,
136  bool skipPrintLineOutput);
137 
138  // .SAVE output using interpolation when order is high
139  virtual bool saveOutputSolution(
140  N_ANP_OutputMgrAdapter & outputManagerAdapter,
141  N_LAS_Vector * solnVecPtr,
142  const double saveTime,
143  const bool doNotInterpolate);
144 
145  // Computes the step adjustment (BDF1-5).
146  virtual double computeExpoStepAdjust(double stepadjust);
147 
148  // Gets the time-integration order (BDF1-5).
149  virtual int getOrder() {return sec.currentOrder_;}
150  virtual int getUsedOrder() {return sec.usedOrder_;}
151  virtual int getNumberOfSteps () { return sec.numberOfSteps_; }
152  virtual int getNscsco () { return sec.nscsco_; }
153 
154  virtual void getInitialQnorm (N_TIA_TwoLevelError & tle);
155  virtual void setupTwoLevelError(N_TIA_TwoLevelError & tle);
156 
157  // 2/16/04 tscoffe: This is just for testing, we'll need a dynamic fcn later
158 
159  // Time-integration factory.
161  (N_TIA_TIAParams & tiaP,
162  N_TIA_StepErrorControl & secTmp ,
163  N_TIA_DataStore & dsTmp);
164 
165  // 03/08/04 tscoffe: New functions necessary for BackwardDifferentiation15
166  // Evaluate corrector residual for nonlinear solver
167  virtual void obtainResidual();
168 
169  // Evaluate corrector Jacobian for nonlinear solver
170  virtual void obtainJacobian();
171 
172  // Update history array after a successful step
173  virtual void updateHistory();
174 
175  // Restore history array after a failed step
176  virtual void restoreHistory();
177 
178  // Return max order of method (this should obey user option maxorder)
179  virtual int getMaxOrder(){ return sec.maxOrder_;}
180  //
181  // Return min order of method (this should obey user option minorder)
182  virtual int getMinOrder(){ return sec.minOrder_;}
183 
184  // Update method coefficients
185  virtual void updateCoeffs();
186 
187  // Initialize method with initial solution & step-size
188  virtual void initialize();
189 
190  // setup 2-level data.
191  virtual void setTwoLevelTimeInfo(const N_TIA_TimeIntInfo & tiInfo);
192 
193  // Reject a step (this turns back history and chooses new order & step-size)
194  virtual void rejectStep();
195 
196  // Reject a step, but only restore the history, as the new step will be
197  // imposed by an outside program.
198  virtual void rejectStepForHabanero ();
199 
200  // Complete a step (this updates history and chooses new order & step-size)
201  virtual void completeStep();
202 
203  virtual void updateStateDeriv ();
204 
205  // calculates dQ/dt component of store vector and adds it to store vector
206  virtual void updateLeadCurrent ();
207 
208 private:
209 
210  // Constructor (private).
212  N_TIA_StepErrorControl & secTmp,
213  N_TIA_DataStore & dsTmp);
214 
215  // Check whether to reduce order independent of local error test
216  virtual void checkReduceOrder();
217 
219 
220  // Used to keep track of last interpolation point in printMPDEOutputSolution
221  double timept_;
222 };
223 
224  // Computes the step addjustment(BDF1-5).
225  // 2/16/04 tscoffe: I'm not exactly sure what this routine is for...
227  double stepadjust)
228 {
229  return pow(stepadjust, 1.0 / 3.0);
230 }
231 
232 //-----------------------------------------------------------------------------
233 // Function : N_TIA_BackwardDifferentiation15::factory
234 // Purpose :
235 // Special Notes :
236 // Scope : public
237 // Creator : Todd Coffey, SNL
238 // Creation Date : 2/16/04
239 //-----------------------------------------------------------------------------
241  (N_TIA_TIAParams & tiaP,
242  N_TIA_StepErrorControl & secTmp ,
243  N_TIA_DataStore & dsTmp)
244 {
245  N_TIA_TimeIntegrationMethod * timPtr =
246  new N_TIA_BackwardDifferentiation15(tiaP,secTmp,dsTmp);
247  return timPtr;
248 }
249 
250 #endif //Xyce_N_TIA_BACKWARD_DIFFERENTIATION_15_H
251