Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_TIA_TimeIntegrationMethods.C
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.C,v $
27 //
28 // Purpose : This file contains the functions which define the
29 // time integration methods classes.
30 //
31 // Special Notes :
32 //
33 // Creator : Buddy Watts
34 //
35 // Creation Date : 6/1/00
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.60 $
41 //
42 // Revision Date : $Date: 2014/02/24 23:49:27 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-----------------------------------------------------------------------------
46 
47 #include <Xyce_config.h>
48 
49 
50 // ---------- Standard Includes ----------
51 
52 #include <N_UTL_Misc.h>
53 
54 #ifdef HAVE_IOSTREAM
55 #include <iostream>
56 #else
57 #include <iostream.h>
58 #endif
59 
60 #include <stdio.h>
61 
62 // ---------- Xyce Includes ----------
64 
66 #include <N_TIA_Gear12.h>
67 #include <N_TIA_OneStep.h>
69 
70 #include <N_TIA_StepErrorControl.h>
71 #include <N_TIA_DataStore.h>
72 #include <N_TIA_TIAParams.h>
73 
74 #include <N_ERH_ErrorMgr.h>
75 
76 #include <N_LAS_MultiVector.h>
77 #include <N_LAS_Vector.h>
78 #include <N_LAS_System.h>
79 
80 // ---------- Static Initializations ----------
81 //-----------------------------------------------------------------------------
82 // Function : N_TIA_WorkingIntegrationMethod::N_TIA_WorkingIntegrationMethod
83 // Purpose : constructor
84 // Special Notes :
85 // Scope : public
86 // Creator : Buddy Watts, SNL
87 // Creation Date : 6/01/00
88 //-----------------------------------------------------------------------------
91  (N_TIA_TIAParams & tiaP,
92  N_TIA_StepErrorControl & secTmp,
93  N_TIA_DataStore & dsTmp)
94  : integMethodPtr(0),
95  tiaParams(tiaP),
96  sec(secTmp),
97  ds(dsTmp)
98 {
99  return;
100 }
101 
102 //-----------------------------------------------------------------------------
103 // Function : N_TIA_WorkingIntegrationMethod::N_TIA_WorkingIntegrationMethod
104 // Purpose : constructor
105 // Special Notes :
106 // Scope : public
107 // Creator : Buddy Watts, SNL
108 // Creation Date : 6/01/00
109 //-----------------------------------------------------------------------------
111  const unsigned int integration_method,
112  N_TIA_TIAParams & tiaP,
113  N_TIA_StepErrorControl & secTmp,
114  N_TIA_DataStore & dsTmp)
115  :
116  workingIntegMethod(integration_method),
117  integMethodPtr(0),
118  tiaParams(tiaP),
119  sec(secTmp),
120  ds(dsTmp)
121 {
122  createTimeIntegMethod(integration_method);
123  return;
124 }
125 
126 //-----------------------------------------------------------------------------
127 // Function :
128 // N_TIA_WorkingIntegrationMethod::~N_TIA_WorkingIntegrationMethod()
129 // Purpose : destructor
130 // Special Notes :
131 // Scope : public
132 // Creator : Buddy Watts, SNL
133 // Creation Date : 6/01/00
134 //-----------------------------------------------------------------------------
136 {
137  if (integMethodPtr != 0)
138  {
139  delete integMethodPtr;
140  integMethodPtr = 0;
141  }
142  return;
143 }
144 
145 //-----------------------------------------------------------------------------
146 // Function : N_TIA_WorkingIntegrationMethod::createTimeIntegMethod
147 // Purpose : Creates the time integration method class --- assigning a
148 // pointer and the Leading Coefficient value of the method.
149 // Special Notes :
150 // Scope : public
151 // Creator : Buddy Watts, SNL
152 // Creation Date : 6/01/00
153 //-----------------------------------------------------------------------------
155  const unsigned int integration_method)
156 {
157 #ifdef Xyce_DEBUG_TIME
158  Xyce::dout() << "\n ********** createTimeIntegMethod Function Called" << std::endl;
159 #endif
160 
162  char ch_msg[256];
163 
164  workingIntegMethod = integration_method;
165 
166  switch(integration_method)
167  {
168  case TIAMethod_NONE:
170  break;
173  break;
174  case TIAMethod_GEAR_12:
176  break;
177  case TIAMethod_ONESTEP:
179  break;
180 
181  // deprecated old-DAE methods:
185  default:
186  Xyce::Report::DevelFatal0() << "N_TIA_WorkingIntegrationMethod::createTimeIntegMethod. Invalid integration method "
187  << integration_method
188  << " specified";
189  break;
190  }
191 
192  if( integMethodPtr ) { delete integMethodPtr; integMethodPtr = 0; }
193 
194  integMethodPtr = pTIM;
195 
196 #ifdef Xyce_VERBOSE_TIME
197  printWorkingIntegMethod(Xyce::lout());
198 #endif
199 
200  return;
201 }
202 
203 //-----------------------------------------------------------------------------
204 // Function : N_TIA_WorkingIntegrationMethod::printWorkingIntegMethod
205 // Purpose : This function is a debug output function. It prints
206 // to the screen the current integration method.
207 // Special Notes :
208 // Scope : public
209 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
210 // Creation Date : 6/26/00
211 //-----------------------------------------------------------------------------
213 {
214  os << " Integration method = ";
215 
216  switch (workingIntegMethod)
217  {
218  case TIAMethod_NONE:
219  os << "None\n";
220  break;
222  os << "Backward Differentiation 15\n";
223  break;
224  case TIAMethod_ONESTEP:
225  os << "Onestep: Trapezoidal\n";
226  break;
227  case TIAMethod_GEAR_12:
228  os << "Gear 12\n";
229  break;
230  default:
231  Xyce::Report::DevelFatal() << "N_TIA_WorkingIntegrationMethod::printWorkingIntegMethod(): Time Integration method not specified correctly.\n";
232  break;
233  }
234 
235  os << std::endl;
236 }
237 
238 //*****************************************************************************
239 //************* Functions for Time Integration Method Base class *************
240 //*****************************************************************************
241 
242 //-----------------------------------------------------------------------------
243 // Function : N_TIA_TimeIntegrationMethod::N_TIA_TimeIntegrationMethod
244 // Purpose : constructor
245 // Special Notes :
246 // Scope : public
247 // Creator : Eric Keiter, SNL, 9233: Computational Sciences
248 // Creation Date : 9/11/00
249 //-----------------------------------------------------------------------------
250 
252  ( N_TIA_TIAParams & tiaP,
253  N_TIA_StepErrorControl & secTmp,
254  N_TIA_DataStore & dsTmp)
255  : leadingCoeff(1.0),
256  tiaParams(tiaP),
257  sec(secTmp),
258  ds(dsTmp)
259 {
260 }
261 
262 //-----------------------------------------------------------------------------
263 // Function : N_TIA_TimeIntegrationMethod::~N_TIA_TimeIntegrationMethod
264 // Purpose : destructor
265 // Special Notes :
266 // Scope : public
267 // Creator : Buddy Watts, SNL
268 // Creation Date : 6/01/00
269 //-----------------------------------------------------------------------------
271 {
272 }
273 
274 //-----------------------------------------------------------------------------
275 // Function : N_TIA_TimeIntegrationMethod::partialTimeDeriv
276 // Purpose :
277 // Special Notes :
278 // Scope : public
279 // Creator :
280 // Creation Date : 1/20/07
281 //-----------------------------------------------------------------------------
283 {
284  if (sec.currentTimeStep < 1e-30)
285  {
286  Xyce::Report::UserWarning() << "Excessively small current time step, incorrectly returning with large value";
287 
288  return (leadingCoeff * 1.e+30);
289  }
290  return (leadingCoeff / sec.currentTimeStep);
291 }
292 
293 //-----------------------------------------------------------------------------
294 // Function : N_TIA_TimeIntegrationMethod::obtainResidual
295 // Purpose : Evaluate residual for nonlinear solver
296 // Special Notes :
297 // Scope : public
298 // Creator : Todd Coffey, SNL
299 // Creation Date : 3/08/04
300 //-----------------------------------------------------------------------------
302 {
303  std::string msg = "N_TIA_ControlMethod::obtainResidual";
304  msg += " The current algorithm does not have an implemented";
305  msg += " obtainResidual function.\n";
306  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
307 }
308 
309 //-----------------------------------------------------------------------------
310 // Function : N_TIA_TimeIntegrationMethod::rejectStep
311 // Purpose : restore history & choose new step-size & order
312 // Special Notes :
313 // Scope : public
314 // Creator : Eric Keiter, SNL
315 // Creation Date : 10/25/07
316 //-----------------------------------------------------------------------------
318 {
319 }
320 
321 //-----------------------------------------------------------------------------
322 // Function : N_TIA_TimeIntegrationMethod::completeStep
323 // Purpose : update history & choose new step-size & order
324 // Special Notes :
325 // Scope : public
326 // Creator : Eric Keiter
327 // Creation Date : 10/25/07
328 //-----------------------------------------------------------------------------
330 {
333 }
334 
335 //-----------------------------------------------------------------------------
336 // Function : N_TIA_TimeIntegrationMethod::printOutputSolution()
337 // Purpose : Print output that is dumbed down in terms of order.
338 //
339 // Special Notes : This routine picks smaller time steps to approximate first
340 // order integration from the perspective of the output.
341 //
342 // For the old method classes, this function does not do
343 // any interpolation (none is possible), and just calls
344 // the output manager adapter directly.
345 //
346 // ERK: Note, the old methods (old-DAE) have all been
347 // removed from Xyce, so possibly this function isn't needed
348 // anymore.
349 //
350 // Scope : public
351 // Creator : Todd Coffey, SNL, 1414
352 // Creation Date : 11/22/05
353 //-----------------------------------------------------------------------------
355  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
356  const double time,
357  N_LAS_Vector * solnVecPtr,
358  const bool doNotInterpolate,
359  const std::vector<double> & outputInterpolationTimes,
360  bool skipPrintLineOutput )
361 {
362 #ifdef Xyce_DEBUG_TIME
363  Xyce::dout() << "Calling conventional outputs!" << std::endl;
364 #endif
365 
366  outputMgrAdapterRCPtr->tranOutput( time, *solnVecPtr,
368  ds.objectiveVec_,
371  skipPrintLineOutput);
372 
373  return true;
374 }
375 
376 
377 //-----------------------------------------------------------------------------
378 // Function : N_TIA_TimeIntegrationMethod::saveOutputSolution
379 // Purpose :
380 // Special Notes : For the old method functions (old-DAE/ODE) no interpolation
381 // is possible, so this function calls directly through to the
382 // output manager.
383 // Scope : public
384 // Creator : Eric Keiter, SNL, 1437
385 // Creation Date : 10/25/07
386 //-----------------------------------------------------------------------------
388  RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
389  N_LAS_Vector * solnVecPtr,
390  const double saveTime,
391  const bool doNotInterpolate)
392 {
393  outputMgrAdapterRCPtr->outputDCOP( *(solnVecPtr) );
394  return true;
395 }
396