Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_TIA_TimeIntegrationMethods.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_TimeIntegrationMethods.h,v $
27 //
28 // Purpose : This file defines the classes for the time integration
29 // methods --- the "interface base class" along with the
30 // accompanying integration methods classes which can be
31 // used in the time integration algorithm.
32 //
33 // Special Notes :
34 //
35 // Creator : Buddy Watts
36 //
37 // Creation Date : 6/1/00
38 //
39 // Revision Information:
40 // ---------------------
41 //
42 // Revision Number: $Revision: 1.60 $
43 //
44 // Revision Date : $Date: 2014/02/24 23:49:27 $
45 //
46 // Current Owner : $Author: tvrusso $
47 //-----------------------------------------------------------------------------
48 
49 #ifndef Xyce_N_TIA_TIME_INTEG_METH_H
50 #define Xyce_N_TIA_TIME_INTEG_METH_H
51 
52 // ---------- Standard Includes ----------
53 #include <iostream>
54 
55 #ifdef HAVE_CMATH
56 #include <cmath>
57 #else
58 #include <math.h>
59 #endif
60 
61 #include <list>
62 
63 #include <Teuchos_RefCountPtr.hpp>
64 using Teuchos::RefCountPtr;
65 using Teuchos::rcp;
66 
67 // ---------- Xyce Includes ----------
68 #include <N_UTL_Xyce.h>
69 #include <N_IO_fwd.h>
70 #include <N_PDS_fwd.h>
71 #include <N_TIA_DataStore.h>
72 #include <N_ANP_SweepParam.h>
74 
75 #include <N_ANP_OutputMgrAdapter.h>
76 
78 class N_TIA_TimeIntInfo;
79 class N_LAS_Vector;
80 class N_LAS_Matrix;
81 
82 //-----------------------------------------------------------------------------
83 // Class : N_TIA_TimeIntegrationMethod
84 //
85 // Purpose : This is the integration methods base class, from which
86 // specific integration methods (such as BDF15, trap, etc) are
87 // derrived.
88 //
89 // Special Notes :
90 // Creator : Buddy Watts, SNL
91 // Creation Date : 6/01/00
92 //-----------------------------------------------------------------------------
93 
95 {
96 
97 public:
98 
99  // Default constructor.
101  N_TIA_StepErrorControl & secTmp,
102  N_TIA_DataStore & dsTmp);
103 
104  // Destructor
106 
107  // Predict solution at next time point (abstract).
108  virtual void obtainPredictor() = 0;
109 
110  // Evaluate the predictor derivative formula (abstract).
111  virtual void obtainPredictorDeriv() = 0;
112 
113  // Evaluate the corrector derivative formula (abstract).
114  virtual void obtainCorrectorDeriv() = 0;
115 
116  // Compute an estimate of the error in the integration step (abstract).
117  virtual void updateDerivsBlock(const std::list<index_pair> & solGIDList,
118  const std::list<index_pair> & staGIDList) = 0;
119 
120  // Compute an estimate of the error in the integration step (abstract).
121  virtual double computeErrorEstimate() = 0;
122 
123  // Interpolate solution, state or store approximation at prescribed time point (abstract).
124  virtual bool interpolateSolution(double timepoint,
125  N_LAS_Vector * tmpSolVectorPtr, std::vector<N_LAS_Vector*> & historyVec) = 0;
126 
127  // Print output using interpolation when order is high
128  virtual bool printOutputSolution(
129  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
130  const double time,
131  N_LAS_Vector * solnVecPtr,
132  const bool doNotInterpolate,
133  const std::vector<double> &outputInterpolationTimes,
134  bool skipPrintLineOutput );
135 
136  // Print MPDE output using local interpolation methods
137  virtual bool printMPDEOutputSolution(
138  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
139  const double time,
140  N_LAS_Vector * solnVecPtr,
141  const std::vector<double>& fastTimes );
142 
143  // Print WaMPDE output using local interpolation methods
144  virtual bool printWaMPDEOutputSolution(
145  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
146  const double time,
147  N_LAS_Vector * solnVecPtr,
148  const std::vector<double>& fastTimes,
149  const int phiGID );
150 
151  // .SAVE output using interpolation when order is high
152  virtual bool saveOutputSolution(
153  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
154  N_LAS_Vector * solnVecPtr,
155  const double saveTime,
156  const bool doNotInterpolate);
157 
158  // Computes the step addjustment.
159  virtual double computeExpoStepAdjust(double stepadjust) = 0;
160 
161  // Gets the time-integration order (abstract).
162  virtual int getOrder() = 0;
163  virtual int getNumberOfSteps () { return 0; }
164  virtual int getUsedOrder () = 0;
165  virtual int getNscsco () { return 0; }
166 
167  virtual void getInitialQnorm (N_TIA_TwoLevelError & tle) = 0;
168  virtual void setupTwoLevelError(N_TIA_TwoLevelError & tle) = 0;
169 
170  // This is for new-DAE.
171  virtual void updateStateDeriv () {}
172 
173  // calculates dQ/dt component of store vector and adds it to store vector
174  virtual void updateLeadCurrent () {}
175 
176  // Returns the current partial time derivative for either the solution or
177  // state vector.
178  virtual double partialTimeDeriv();
179 
180  // Gets the leading coefficient for the specified time-integration method.
181  virtual double getLeadingCoeff() { return leadingCoeff; }
182 
183  // sets the leading coefficient for the specified time-integration method.
184  virtual void setLeadingCoeff(double & LC) { leadingCoeff = LC; }
185 
186  // 03/08/04 tscoffe: New functions necessary for BackwardDifferentiation15
187  // Evaluate residual for nonlinear solver
188  virtual void obtainResidual();
189 
190  // Evaluate Jacobian for nonlinear solver
191  virtual void obtainJacobian();
192 
193  // Apply Jacobian for nonlinear solver
194  virtual void applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result);
195 
196  // Update history array after a successful step
197  virtual void updateHistory();
198 
199  // Restore history array after a failed step
200  virtual void restoreHistory();
201 
202  // Return max order of method (this should obey user option maxorder)
203  virtual int getMaxOrder();
204 
205  // Update method coefficients
206  virtual void updateCoeffs();
207 
208  // Initialize method with initial solution & step-size
209  virtual void initialize();
210 
211  // setup 2-level data.
212  virtual void setTwoLevelTimeInfo(const N_TIA_TimeIntInfo & tiInfo);
213 
214  // Reject a step (this turns back history and chooses new order & step-size)
215  virtual void rejectStep();
216 
217  virtual void rejectStepForHabanero () {};
218 
219  // Complete a step (this updates history and chooses new order & step-size)
220  virtual void completeStep();
221 
222 protected:
223 private :
224 
225 public :
226 
227  // Reference to the TIA data-store object.
229 
230  // Reference to step-error control object.
232 
233  // Time-integration method leading coefficient value.
234  double leadingCoeff;
235 
236  // Reference to TIA params object.
238 };
239 
240 //-----------------------------------------------------------------------------
241 // Class : N_TIA_WorkingIntegrationMethod
242 // Purpose : This class provides a way for obtaining a specific
243 // working integration method and its associated data items.
244 // Special Notes :
245 // Creator : Buddy Watts, SNL
246 // Creation Date : 6/01/00
247 //-----------------------------------------------------------------------------
249 {
250  public:
251 
252  // Default constructor.
254  N_TIA_StepErrorControl & secTmp,
255  N_TIA_DataStore & dsTmp);
256 
257  // Constructor
259  const unsigned int integMethod, N_TIA_TIAParams & tiaP,
260  N_TIA_StepErrorControl & secTmp,
261  N_TIA_DataStore & dsTmp);
262 
263  // Destructor
265 
266  // Method which creates a time-integration method.
267  void createTimeIntegMethod(const unsigned int integMethod);
268 
269  // Output the current time-integration method.
270  void printWorkingIntegMethod(std::ostream &os);
271 
272  // Current integration method flag.
273  unsigned int workingIntegMethod;
274 
275  // accessors to the integration method object functions:
277 
282  void updateDerivsBlock ( const std::list<index_pair> & solGIDList, const std::list<index_pair> & staGIDList)
283  { integMethodPtr->updateDerivsBlock (solGIDList, staGIDList); }
284 
285  int getOrder() { return integMethodPtr->getOrder(); }
288  int getNscsco () { return integMethodPtr->getNscsco(); }
294  void initialize() { return integMethodPtr->initialize(); }
296  void rejectStep() { return integMethodPtr->rejectStep(); }
302  void applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result)
303  { return integMethodPtr->applyJacobian(input, result); }
304 
306  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
307  const double time,
308  N_LAS_Vector * solnVecPtr,
309  const std::vector<double>& fastTimes )
310  {
312  outputMgrAdapterRCPtr, time, solnVecPtr, fastTimes );
313  }
314 
316  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
317  const double time,
318  N_LAS_Vector * solnVecPtr,
319  const std::vector<double>& fastTimes,
320  const int phiGID )
321  {
323  outputMgrAdapterRCPtr, time, solnVecPtr, fastTimes, phiGID );
324  }
325 
327  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
328  const double time,
329  N_LAS_Vector * solnVecPtr,
330  const bool doNotInterpolate,
331  const std::vector<double> &outputInterpolationTimes,
332  bool skipPrintLineOutput )
333  {
335  outputMgrAdapterRCPtr, time, solnVecPtr, doNotInterpolate, outputInterpolationTimes, skipPrintLineOutput) ;
336  }
337 
339  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
340  N_LAS_Vector * solnVecPtr,
341  const double saveTime,
342  const bool doNotInterpolate)
343  {
345  outputMgrAdapterRCPtr, solnVecPtr, saveTime, doNotInterpolate);
346  }
347 
348  // TIA params object.
350 
351  // Reference to the TIA data-store object.
353 
354  // Reference to step-error control object.
356 
357  private:
358  // Pointer to the integration method.
360 };
361 
362 
363 
364 
365 //-----------------------------------------------------------------------------
366 // Function : N_TIA_TimeIntegrationMethod::obtainJacobian
367 // Purpose : Evaluate Jacobian for nonlinear solver
368 // Special Notes :
369 // Scope : public
370 // Creator : Todd Coffey, SNL
371 // Creation Date : 3/08/04
372 //-----------------------------------------------------------------------------
374 {
375 }
376 
377 //-----------------------------------------------------------------------------
378 // Function : N_TIA_TimeIntegrationMethod::applyJacobian
379 // Purpose : Apply Jacobian for nonlinear solver
380 // Special Notes :
381 // Scope : public
382 // Creator : Todd Coffey, Ting Mei
383 // Creation Date : 7/29/08
384 //-----------------------------------------------------------------------------
385 inline void N_TIA_TimeIntegrationMethod::applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result)
386 {
387 }
388 
389 //-----------------------------------------------------------------------------
390 // Function : N_TIA_TimeIntegrationMethod::updateHistory
391 // Purpose : Update history array after a successful step
392 // Special Notes :
393 // Scope : public
394 // Creator : Todd Coffey, SNL
395 // Creation Date : 3/08/04
396 //-----------------------------------------------------------------------------
398 {
399 }
400 
401 //-----------------------------------------------------------------------------
402 // Function : N_TIA_TimeIntegrationMethod::restoreHistory
403 // Purpose : Restore history array after a failed step
404 // Special Notes :
405 // Scope : public
406 // Creator : Todd Coffey, SNL
407 // Creation Date : 3/08/04
408 //-----------------------------------------------------------------------------
410 {
411 }
412 
413 //-----------------------------------------------------------------------------
414 // Function : N_TIA_TimeIntegrationMethod::getMaxOrder
415 // Purpose : Return max order of method (this should obey user option maxorder)
416 // Special Notes :
417 // Scope : public
418 // Creator : Todd Coffey, SNL
419 // Creation Date : 3/08/04
420 //-----------------------------------------------------------------------------
422 {
423  return -1;
424 }
425 
426 //-----------------------------------------------------------------------------
427 // Function : N_TIA_TimeIntegrationMethod::updateCoeffs
428 // Purpose : Update method coefficients
429 // Special Notes :
430 // Scope : public
431 // Creator : Todd Coffey, SNL
432 // Creation Date : 3/08/04
433 //-----------------------------------------------------------------------------
435 {
436 }
437 
438 //-----------------------------------------------------------------------------
439 // Function : N_TIA_TimeIntegrationMethod::initialize
440 // Purpose : Initialize method with initial solution & step-size
441 // Special Notes :
442 // Scope : public
443 // Creator : Todd Coffey, SNL
444 // Creation Date : 3/09/04
445 //-----------------------------------------------------------------------------
447 {
448 }
449 
450 //-----------------------------------------------------------------------------
451 // Function : N_TIA_TimeIntegrationMethod::setTwoLevelTimeInfo
452 // Purpose :
453 // Special Notes :
454 // Scope : public
455 // Creator : Eric Keiter, SNL
456 // Creation Date : 3/01/07
457 //-----------------------------------------------------------------------------
459 {
460 }
461 
462 //-----------------------------------------------------------------------------
463 // Function : N_TIA_TimeIntegrationMethod::printMPDEOutputSolution()
464 // Purpose : Use local time integration algorithm interpolants to
465 // print transient MPDE output.
466 // Scope : public
467 // Creator : Todd Coffey, SNL, 1414
468 // Creation Date : 12/05/06
469 //-----------------------------------------------------------------------------
471  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
472  const double time,
473  N_LAS_Vector * solnVecPtr,
474  const std::vector<double>& fastTimes )
475 {
476  return false;
477 }
478 
479 //-----------------------------------------------------------------------------
480 // Function : N_TIA_TimeIntegrationMethod::printWaMPDEOutputSolution()
481 // Purpose : Use local time integration algorithm interpolants to
482 // print transient WaMPDE output.
483 // Scope : public
484 // Creator : Todd Coffey, SNL, 1414
485 // Creation Date : 12/15/06
486 //-----------------------------------------------------------------------------
488  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
489  const double time,
490  N_LAS_Vector * solnVecPtr,
491  const std::vector<double>& fastTimes,
492  const int phiGID )
493 {
494  return false;
495 }
496 
497 #endif // Xyce_N_TIA_TIME_INTEG_METH_H
498