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.63.2.1 $
41 //
42 // Revision Date : $Date: 2014/09/02 22:49:49 $
43 //
44 // Current Owner : $Author: erkeite $
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 
65 #include <N_ANP_OutputMgrAdapter.h>
66 #include <N_ERH_ErrorMgr.h>
67 #include <N_LAS_MultiVector.h>
68 #include <N_LAS_System.h>
69 #include <N_LAS_Vector.h>
71 #include <N_TIA_DataStore.h>
72 #include <N_TIA_Gear12.h>
74 #include <N_TIA_OneStep.h>
75 #include <N_TIA_StepErrorControl.h>
76 #include <N_TIA_TIAParams.h>
77 
78 
79 // ---------- Static Initializations ----------
80 //-----------------------------------------------------------------------------
81 // Function : N_TIA_WorkingIntegrationMethod::N_TIA_WorkingIntegrationMethod
82 // Purpose : constructor
83 // Special Notes :
84 // Scope : public
85 // Creator : Buddy Watts, SNL
86 // Creation Date : 6/01/00
87 //-----------------------------------------------------------------------------
90  (N_TIA_TIAParams & tiaP,
91  N_TIA_StepErrorControl & secTmp,
92  N_TIA_DataStore & dsTmp)
93  : integMethodPtr(0),
94  tiaParams(tiaP),
95  sec(secTmp),
96  ds(dsTmp)
97 {
98  return;
99 }
100 
101 //-----------------------------------------------------------------------------
102 // Function : N_TIA_WorkingIntegrationMethod::N_TIA_WorkingIntegrationMethod
103 // Purpose : constructor
104 // Special Notes :
105 // Scope : public
106 // Creator : Buddy Watts, SNL
107 // Creation Date : 6/01/00
108 //-----------------------------------------------------------------------------
110  const unsigned int integration_method,
111  N_TIA_TIAParams & tiaP,
112  N_TIA_StepErrorControl & secTmp,
113  N_TIA_DataStore & dsTmp)
114  :
115  workingIntegMethod(integration_method),
116  integMethodPtr(0),
117  tiaParams(tiaP),
118  sec(secTmp),
119  ds(dsTmp)
120 {
121  createTimeIntegMethod(integration_method);
122  return;
123 }
124 
125 //-----------------------------------------------------------------------------
126 // Function :
127 // N_TIA_WorkingIntegrationMethod::~N_TIA_WorkingIntegrationMethod()
128 // Purpose : destructor
129 // Special Notes :
130 // Scope : public
131 // Creator : Buddy Watts, SNL
132 // Creation Date : 6/01/00
133 //-----------------------------------------------------------------------------
135 {
136  if (integMethodPtr != 0)
137  {
138  delete integMethodPtr;
139  integMethodPtr = 0;
140  }
141  return;
142 }
143 
144 //-----------------------------------------------------------------------------
145 // Function : N_TIA_WorkingIntegrationMethod::createTimeIntegMethod
146 // Purpose : Creates the time integration method class --- assigning a
147 // pointer and the Leading Coefficient value of the method.
148 // Special Notes :
149 // Scope : public
150 // Creator : Buddy Watts, SNL
151 // Creation Date : 6/01/00
152 //-----------------------------------------------------------------------------
154  const unsigned int integration_method)
155 {
156 #ifdef Xyce_DEBUG_TIME
157  Xyce::dout() << "\n ********** createTimeIntegMethod Function Called" << std::endl;
158 #endif
159 
161  char ch_msg[256];
162 
163  workingIntegMethod = integration_method;
164 
165  switch(integration_method)
166  {
167  case TIAMethod_NONE:
169  break;
172  break;
173  case TIAMethod_GEAR_12:
175  break;
176  case TIAMethod_ONESTEP:
178  break;
179 
180  // deprecated old-DAE methods:
184  default:
185  Xyce::Report::DevelFatal0() << "N_TIA_WorkingIntegrationMethod::createTimeIntegMethod. Invalid integration method "
186  << integration_method
187  << " specified";
188  break;
189  }
190 
191  if( integMethodPtr ) { delete integMethodPtr; integMethodPtr = 0; }
192 
193  integMethodPtr = pTIM;
194 
195 #ifdef Xyce_VERBOSE_TIME
196  printWorkingIntegMethod(Xyce::lout());
197 #endif
198 
199  return;
200 }
201 
202 //-----------------------------------------------------------------------------
203 // Function : N_TIA_WorkingIntegrationMethod::printWorkingIntegMethod
204 // Purpose : This function is a debug output function. It prints
205 // to the screen the current integration method.
206 // Special Notes :
207 // Scope : public
208 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
209 // Creation Date : 6/26/00
210 //-----------------------------------------------------------------------------
212 {
213  os << " Integration method = ";
214 
215  switch (workingIntegMethod)
216  {
217  case TIAMethod_NONE:
218  os << "None\n";
219  break;
221  os << "Backward Differentiation 15\n";
222  break;
223  case TIAMethod_ONESTEP:
224  os << "Onestep: Trapezoidal\n";
225  break;
226  case TIAMethod_GEAR_12:
227  os << "Gear 12\n";
228  break;
229  default:
230  Xyce::Report::DevelFatal() << "N_TIA_WorkingIntegrationMethod::printWorkingIntegMethod(): Time Integration method not specified correctly.\n";
231  break;
232  }
233 
234  os << std::endl;
235 }
236 
237 //*****************************************************************************
238 //************* Functions for Time Integration Method Base class *************
239 //*****************************************************************************
240 
241 //-----------------------------------------------------------------------------
242 // Function : N_TIA_TimeIntegrationMethod::N_TIA_TimeIntegrationMethod
243 // Purpose : constructor
244 // Special Notes :
245 // Scope : public
246 // Creator : Eric Keiter, SNL, 9233: Computational Sciences
247 // Creation Date : 9/11/00
248 //-----------------------------------------------------------------------------
249 
251  ( N_TIA_TIAParams & tiaP,
252  N_TIA_StepErrorControl & secTmp,
253  N_TIA_DataStore & dsTmp)
254  : leadingCoeff(1.0),
255  tiaParams(tiaP),
256  sec(secTmp),
257  ds(dsTmp)
258 {
259 }
260 
261 //-----------------------------------------------------------------------------
262 // Function : N_TIA_TimeIntegrationMethod::~N_TIA_TimeIntegrationMethod
263 // Purpose : destructor
264 // Special Notes :
265 // Scope : public
266 // Creator : Buddy Watts, SNL
267 // Creation Date : 6/01/00
268 //-----------------------------------------------------------------------------
270 {
271 }
272 
273 //-----------------------------------------------------------------------------
274 // Function : N_TIA_TimeIntegrationMethod::partialTimeDeriv
275 // Purpose :
276 // Special Notes :
277 // Scope : public
278 // Creator :
279 // Creation Date : 1/20/07
280 //-----------------------------------------------------------------------------
282 {
283  if (sec.currentTimeStep < 1e-30)
284  {
285  Xyce::Report::UserWarning() << "Excessively small current time step, incorrectly returning with large value";
286 
287  return (leadingCoeff * 1.e+30);
288  }
289  return (leadingCoeff / sec.currentTimeStep);
290 }
291 
292 //-----------------------------------------------------------------------------
293 // Function : N_TIA_TimeIntegrationMethod::obtainResidual
294 // Purpose : Evaluate residual for nonlinear solver
295 // Special Notes :
296 // Scope : public
297 // Creator : Todd Coffey, SNL
298 // Creation Date : 3/08/04
299 //-----------------------------------------------------------------------------
301 {
302  std::string msg = "N_TIA_ControlMethod::obtainResidual";
303  msg += " The current algorithm does not have an implemented";
304  msg += " obtainResidual function.\n";
305  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
306 }
307 
308 //-----------------------------------------------------------------------------
309 // Function : N_TIA_TimeIntegrationMethod::obtainSensitivityResiduals
310 // Purpose : Evaluate sensitivity residuals
311 // Special Notes :
312 // Scope : public
313 // Creator : Eric Keiter, SNL
314 // Creation Date :
315 //-----------------------------------------------------------------------------
317 {
318  std::string msg = "N_TIA_ControlMethod::obtainSensitivityResiduals";
319  msg += " The current algorithm does not have an implemented";
320  msg += " obtainSensitivityResiduals function.\n";
321  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
322 }
323 
324 //-----------------------------------------------------------------------------
325 // Function : N_TIA_TimeIntegrationMethod::loadFinalSensitivityDerivatives
326 // Purpose : Evaluate sensitivity residuals
327 // Special Notes :
328 // Scope : public
329 // Creator : Eric Keiter, SNL
330 // Creation Date :
331 //-----------------------------------------------------------------------------
333 {
334  std::string msg = "N_TIA_ControlMethod::loadFinalSensitivityDerivatives";
335  msg += " The current algorithm does not have an implemented";
336  msg += " loadFinalSensitivityDerivatives function.\n";
337  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
338 }
339 
340 //-----------------------------------------------------------------------------
341 // Function : N_TIA_TimeIntegrationMethod::rejectStep
342 // Purpose : restore history & choose new step-size & order
343 // Special Notes :
344 // Scope : public
345 // Creator : Eric Keiter, SNL
346 // Creation Date : 10/25/07
347 //-----------------------------------------------------------------------------
349 {
350 }
351 
352 //-----------------------------------------------------------------------------
353 // Function : N_TIA_TimeIntegrationMethod::completeStep
354 // Purpose : update history & choose new step-size & order
355 // Special Notes :
356 // Scope : public
357 // Creator : Eric Keiter
358 // Creation Date : 10/25/07
359 //-----------------------------------------------------------------------------
361 {
364 }
365 
366 //-----------------------------------------------------------------------------
367 // Function : N_TIA_TimeIntegrationMethod::printOutputSolution()
368 // Purpose : Print output that is dumbed down in terms of order.
369 //
370 // Special Notes : This routine picks smaller time steps to approximate first
371 // order integration from the perspective of the output.
372 //
373 // For the old method classes, this function does not do
374 // any interpolation (none is possible), and just calls
375 // the output manager adapter directly.
376 //
377 // ERK: Note, the old methods (old-DAE) have all been
378 // removed from Xyce, so possibly this function isn't needed
379 // anymore.
380 //
381 // Scope : public
382 // Creator : Todd Coffey, SNL, 1414
383 // Creation Date : 11/22/05
384 //-----------------------------------------------------------------------------
386  N_ANP_OutputMgrAdapter & outputManagerAdapter,
387  const double time,
388  N_LAS_Vector * solnVecPtr,
389  const bool doNotInterpolate,
390  const std::vector<double> & outputInterpolationTimes,
391  bool skipPrintLineOutput )
392 {
393 #ifdef Xyce_DEBUG_TIME
394  Xyce::dout() << "Calling conventional outputs!" << std::endl;
395 #endif
396 
397  outputManagerAdapter.tranOutput( time, *solnVecPtr,
399  ds.objectiveVec_,
402  skipPrintLineOutput);
403 
404  return true;
405 }
406 
407 
408 //-----------------------------------------------------------------------------
409 // Function : N_TIA_TimeIntegrationMethod::saveOutputSolution
410 // Purpose :
411 // Special Notes : For the old method functions (old-DAE/ODE) no interpolation
412 // is possible, so this function calls directly through to the
413 // output manager.
414 // Scope : public
415 // Creator : Eric Keiter, SNL, 1437
416 // Creation Date : 10/25/07
417 //-----------------------------------------------------------------------------
419  N_ANP_OutputMgrAdapter & outputManagerAdapter,
420  N_LAS_Vector * solnVecPtr,
421  const double saveTime,
422  const bool doNotInterpolate)
423 {
424  outputManagerAdapter.outputDCOP( *(solnVecPtr) );
425  return true;
426 }
427