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.63.2.1 $
43 //
44 // Revision Date : $Date: 2014/09/02 22:49:49 $
45 //
46 // Current Owner : $Author: erkeite $
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_UTL_Misc.h>
70 #include <N_ANP_fwd.h>
71 #include <N_IO_fwd.h>
72 #include <N_PDS_fwd.h>
73 #include <N_TIA_fwd.h>
74 #include <N_LAS_fwd.h>
75 
76 //-----------------------------------------------------------------------------
77 // Class : N_TIA_TimeIntegrationMethod
78 //
79 // Purpose : This is the integration methods base class, from which
80 // specific integration methods (such as BDF15, trap, etc) are
81 // derrived.
82 //
83 // Special Notes :
84 // Creator : Buddy Watts, SNL
85 // Creation Date : 6/01/00
86 //-----------------------------------------------------------------------------
87 
89 {
90 public:
91 
92  // Default constructor.
94  N_TIA_StepErrorControl & secTmp,
95  N_TIA_DataStore & dsTmp);
96 
97  // Destructor
99 
100  // Predict solution at next time point (abstract).
101  virtual void obtainPredictor() = 0;
102 
103  // Evaluate the predictor derivative formula (abstract).
104  virtual void obtainPredictorDeriv() = 0;
105 
106  // Evaluate the corrector derivative formula (abstract).
107  virtual void obtainCorrectorDeriv() = 0;
108 
109  // Compute an estimate of the error in the integration step (abstract).
110  virtual void updateDerivsBlock(const std::list<index_pair> & solGIDList,
111  const std::list<index_pair> & staGIDList) = 0;
112 
113  // Compute an estimate of the error in the integration step (abstract).
114  virtual double computeErrorEstimate() = 0;
115 
116  // Interpolate solution, state or store approximation at prescribed time point (abstract).
117  virtual bool interpolateSolution(double timepoint,
118  N_LAS_Vector * tmpSolVectorPtr, std::vector<N_LAS_Vector*> & historyVec) = 0;
119 
120  // Print output using interpolation when order is high
121  virtual bool printOutputSolution(
122  N_ANP_OutputMgrAdapter & outputManagerAdapter,
123  const double time,
124  N_LAS_Vector * solnVecPtr,
125  const bool doNotInterpolate,
126  const std::vector<double> &outputInterpolationTimes,
127  bool skipPrintLineOutput );
128 
129  // Print MPDE output using local interpolation methods
130  virtual bool printMPDEOutputSolution(
131  N_ANP_OutputMgrAdapter & outputManagerAdapter,
132  const double time,
133  N_LAS_Vector * solnVecPtr,
134  const std::vector<double>& fastTimes );
135 
136  // Print WaMPDE output using local interpolation methods
137  virtual bool printWaMPDEOutputSolution(
138  N_ANP_OutputMgrAdapter & outputManagerAdapter,
139  const double time,
140  N_LAS_Vector * solnVecPtr,
141  const std::vector<double>& fastTimes,
142  const int phiGID );
143 
144  // .SAVE output using interpolation when order is high
145  virtual bool saveOutputSolution(
146  N_ANP_OutputMgrAdapter & outputManagerAdapter,
147  N_LAS_Vector * solnVecPtr,
148  const double saveTime,
149  const bool doNotInterpolate);
150 
151  // Computes the step addjustment.
152  virtual double computeExpoStepAdjust(double stepadjust) = 0;
153 
154  // Gets the time-integration order (abstract).
155  virtual int getOrder() = 0;
156  virtual int getNumberOfSteps () { return 0; }
157  virtual int getUsedOrder () = 0;
158  virtual int getNscsco () { return 0; }
159 
160  virtual void getInitialQnorm (N_TIA_TwoLevelError & tle) = 0;
161  virtual void setupTwoLevelError(N_TIA_TwoLevelError & tle) = 0;
162 
163  // This is for new-DAE.
164  virtual void updateStateDeriv () {}
165 
166  // calculates dQ/dt component of store vector and adds it to store vector
167  virtual void updateLeadCurrent () {}
168 
169  // Returns the current partial time derivative for either the solution or
170  // state vector.
171  virtual double partialTimeDeriv();
172 
173  // Gets the leading coefficient for the specified time-integration method.
174  virtual double getLeadingCoeff() { return leadingCoeff; }
175 
176  // sets the leading coefficient for the specified time-integration method.
177  virtual void setLeadingCoeff(double & LC) { leadingCoeff = LC; }
178 
179  // 03/08/04 tscoffe: New functions necessary for BackwardDifferentiation15
180  // Evaluate residual for nonlinear solver
181  virtual void obtainResidual();
182 
183  // obtain residuals for transient sensitivity analysis
184  virtual void obtainSensitivityResiduals();
185 
186  // obtain final derivatives w.r.t. time for transient sensitivity analysis
187  virtual void loadFinalSensitivityDerivatives();
188 
189  // Evaluate Jacobian for nonlinear solver
190  virtual void obtainJacobian();
191 
192  // Apply Jacobian for nonlinear solver
193  virtual void applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result);
194 
195  // Update history array after a successful step
196  virtual void updateHistory();
197 
198  // Restore history array after a failed step
199  virtual void restoreHistory();
200 
201  // Return max order of method (this should obey user option maxorder)
202  virtual int getMaxOrder();
203 
204  // Update method coefficients
205  virtual void updateCoeffs();
206 
207  // Initialize method with initial solution & step-size
208  virtual void initialize();
209 
210  // setup 2-level data.
211  virtual void setTwoLevelTimeInfo(const N_TIA_TimeIntInfo & tiInfo);
212 
213  // Reject a step (this turns back history and chooses new order & step-size)
214  virtual void rejectStep();
215 
216  virtual void rejectStepForHabanero () {};
217 
218  // Complete a step (this updates history and chooses new order & step-size)
219  virtual void completeStep();
220 
221 protected:
222 private :
223 
224 public :
225 
226  // Reference to the TIA data-store object.
228 
229  // Reference to step-error control object.
231 
232  // Time-integration method leading coefficient value.
233  double leadingCoeff;
234 
235  // Reference to TIA params object.
237 };
238 
239 //-----------------------------------------------------------------------------
240 // Class : N_TIA_WorkingIntegrationMethod
241 // Purpose : This class provides a way for obtaining a specific
242 // working integration method and its associated data items.
243 // Special Notes :
244 // Creator : Buddy Watts, SNL
245 // Creation Date : 6/01/00
246 //-----------------------------------------------------------------------------
248 {
249  public:
250 
251  // Default constructor.
253  N_TIA_StepErrorControl & secTmp,
254  N_TIA_DataStore & dsTmp);
255 
256  // Constructor
258  const unsigned int integMethod, N_TIA_TIAParams & tiaP,
259  N_TIA_StepErrorControl & secTmp,
260  N_TIA_DataStore & dsTmp);
261 
262  // Destructor
264 
265  // Method which creates a time-integration method.
266  void createTimeIntegMethod(const unsigned int integMethod);
267 
268  // Output the current time-integration method.
269  void printWorkingIntegMethod(std::ostream &os);
270 
271  // Current integration method flag.
272  unsigned int workingIntegMethod;
273 
274  // accessors to the integration method object functions:
276 
281  void updateDerivsBlock ( const std::list<index_pair> & solGIDList, const std::list<index_pair> & staGIDList)
282  { integMethodPtr->updateDerivsBlock (solGIDList, staGIDList); }
283 
284  int getOrder() { return integMethodPtr->getOrder(); }
287  int getNscsco () { return integMethodPtr->getNscsco(); }
293  void initialize() { return integMethodPtr->initialize(); }
295  void rejectStep() { return integMethodPtr->rejectStep(); }
303  void applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result)
304  { return integMethodPtr->applyJacobian(input, result); }
305 
307  N_ANP_OutputMgrAdapter & outputManagerAdapter,
308  const double time,
309  N_LAS_Vector * solnVecPtr,
310  const std::vector<double>& fastTimes )
311  {
313  outputManagerAdapter, time, solnVecPtr, fastTimes );
314  }
315 
317  N_ANP_OutputMgrAdapter & outputManagerAdapter,
318  const double time,
319  N_LAS_Vector * solnVecPtr,
320  const std::vector<double>& fastTimes,
321  const int phiGID )
322  {
324  outputManagerAdapter, time, solnVecPtr, fastTimes, phiGID );
325  }
326 
328  N_ANP_OutputMgrAdapter & outputManagerAdapter,
329  const double time,
330  N_LAS_Vector * solnVecPtr,
331  const bool doNotInterpolate,
332  const std::vector<double> &outputInterpolationTimes,
333  bool skipPrintLineOutput )
334  {
336  outputManagerAdapter, time, solnVecPtr, doNotInterpolate, outputInterpolationTimes, skipPrintLineOutput) ;
337  }
338 
340  N_ANP_OutputMgrAdapter & outputManagerAdapter,
341  N_LAS_Vector * solnVecPtr,
342  const double saveTime,
343  const bool doNotInterpolate)
344  {
346  outputManagerAdapter, solnVecPtr, saveTime, doNotInterpolate);
347  }
348 
349  // TIA params object.
351 
352  // Reference to the TIA data-store object.
354 
355  // Reference to step-error control object.
357 
358  private:
359  // Pointer to the integration method.
361 };
362 
363 //-----------------------------------------------------------------------------
364 // Function : N_TIA_TimeIntegrationMethod::obtainJacobian
365 // Purpose : Evaluate Jacobian for nonlinear solver
366 // Special Notes :
367 // Scope : public
368 // Creator : Todd Coffey, SNL
369 // Creation Date : 3/08/04
370 //-----------------------------------------------------------------------------
372 {
373 }
374 
375 //-----------------------------------------------------------------------------
376 // Function : N_TIA_TimeIntegrationMethod::applyJacobian
377 // Purpose : Apply Jacobian for nonlinear solver
378 // Special Notes :
379 // Scope : public
380 // Creator : Todd Coffey, Ting Mei
381 // Creation Date : 7/29/08
382 //-----------------------------------------------------------------------------
383 inline void N_TIA_TimeIntegrationMethod::applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result)
384 {
385 }
386 
387 //-----------------------------------------------------------------------------
388 // Function : N_TIA_TimeIntegrationMethod::updateHistory
389 // Purpose : Update history array after a successful step
390 // Special Notes :
391 // Scope : public
392 // Creator : Todd Coffey, SNL
393 // Creation Date : 3/08/04
394 //-----------------------------------------------------------------------------
396 {
397 }
398 
399 //-----------------------------------------------------------------------------
400 // Function : N_TIA_TimeIntegrationMethod::restoreHistory
401 // Purpose : Restore history array after a failed step
402 // Special Notes :
403 // Scope : public
404 // Creator : Todd Coffey, SNL
405 // Creation Date : 3/08/04
406 //-----------------------------------------------------------------------------
408 {
409 }
410 
411 //-----------------------------------------------------------------------------
412 // Function : N_TIA_TimeIntegrationMethod::getMaxOrder
413 // Purpose : Return max order of method (this should obey user option maxorder)
414 // Special Notes :
415 // Scope : public
416 // Creator : Todd Coffey, SNL
417 // Creation Date : 3/08/04
418 //-----------------------------------------------------------------------------
420 {
421  return -1;
422 }
423 
424 //-----------------------------------------------------------------------------
425 // Function : N_TIA_TimeIntegrationMethod::updateCoeffs
426 // Purpose : Update method coefficients
427 // Special Notes :
428 // Scope : public
429 // Creator : Todd Coffey, SNL
430 // Creation Date : 3/08/04
431 //-----------------------------------------------------------------------------
433 {
434 }
435 
436 //-----------------------------------------------------------------------------
437 // Function : N_TIA_TimeIntegrationMethod::initialize
438 // Purpose : Initialize method with initial solution & step-size
439 // Special Notes :
440 // Scope : public
441 // Creator : Todd Coffey, SNL
442 // Creation Date : 3/09/04
443 //-----------------------------------------------------------------------------
445 {
446 }
447 
448 //-----------------------------------------------------------------------------
449 // Function : N_TIA_TimeIntegrationMethod::setTwoLevelTimeInfo
450 // Purpose :
451 // Special Notes :
452 // Scope : public
453 // Creator : Eric Keiter, SNL
454 // Creation Date : 3/01/07
455 //-----------------------------------------------------------------------------
457 {
458 }
459 
460 //-----------------------------------------------------------------------------
461 // Function : N_TIA_TimeIntegrationMethod::printMPDEOutputSolution()
462 // Purpose : Use local time integration algorithm interpolants to
463 // print transient MPDE output.
464 // Scope : public
465 // Creator : Todd Coffey, SNL, 1414
466 // Creation Date : 12/05/06
467 //-----------------------------------------------------------------------------
469  N_ANP_OutputMgrAdapter & outputManagerAdapter,
470  const double time,
471  N_LAS_Vector * solnVecPtr,
472  const std::vector<double>& fastTimes )
473 {
474  return false;
475 }
476 
477 //-----------------------------------------------------------------------------
478 // Function : N_TIA_TimeIntegrationMethod::printWaMPDEOutputSolution()
479 // Purpose : Use local time integration algorithm interpolants to
480 // print transient WaMPDE output.
481 // Scope : public
482 // Creator : Todd Coffey, SNL, 1414
483 // Creation Date : 12/15/06
484 //-----------------------------------------------------------------------------
486  N_ANP_OutputMgrAdapter & outputManagerAdapter,
487  const double time,
488  N_LAS_Vector * solnVecPtr,
489  const std::vector<double>& fastTimes,
490  const int phiGID )
491 {
492  return false;
493 }
494 
495 #endif // Xyce_N_TIA_TIME_INTEG_METH_H
496