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