Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_TIA_DataStore.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_DataStore.C,v $
27 //
28 // Purpose : This file creates & initializes the data arrays needed for
29 // the time integration algorithms.
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.152.2.9 $
41 //
42 // Revision Date : $Date: 2014/09/03 11:14:50 $
43 //
44 // Current Owner : $Author: erkeite $
45 //-----------------------------------------------------------------------------
46 
47 #include <Xyce_config.h>
48 
49 
50 // ---------- Standard Includes ----------
51 #include <iostream>
52 
53 #include <N_TIA_DataStore.h>
54 
55 #include <N_LAS_Builder.h>
56 #include <N_LAS_Matrix.h>
57 #include <N_LAS_MultiVector.h>
58 #include <N_LAS_System.h>
59 #include <N_LAS_Vector.h>
60 #include <N_TIA_TIAParams.h>
61 #include <N_UTL_DeleteList.h>
62 #include <N_UTL_fwd.h>
63 
64 //-----------------------------------------------------------------------------
65 // Function : N_TIA_DataStore::N_TIA_DataStore
66 // Purpose : constructor
67 // Special Notes :
68 // Scope : public
69 // Creator : Buddy Watts, SNL
70 // Creation Date : 6/01/00
71 //-----------------------------------------------------------------------------
72 N_TIA_DataStore::N_TIA_DataStore(N_TIA_TIAParams * tiaPtr, N_LAS_System * lsPtr)
73  : limiterFlag(false),
74  lasSysPtr(lsPtr),
75  solutionSize(tiaPtr->solutionSize),
76  stateSize(tiaPtr->stateSize),
77  tiaParamsPtr_(tiaPtr),
78  nextSolPtrSwitched(false),
79  tmpSolVectorPtr(0),
80  tmpStaVectorPtr(0),
81  tmpStaDerivPtr(0),
82  tmpStaDivDiffPtr(0),
83  tmpStoVectorPtr(0),
84  xn0Ptr (0),
85  currSolutionPtr(0),
86  lastSolutionPtr(0),
87  oldeSolutionPtr(0),
88  nextSolutionPtr(0),
89  flagSolutionPtr(0),
90  savedNextSolutionPtr(0),
91  currStatePtr(0),
92  lastStatePtr(0),
93  oldeStatePtr(0),
94  nextStatePtr(0),
95  currStorePtr(0),
96  lastStorePtr(0),
97  oldeStorePtr(0),
98  nextStorePtr(0),
99  currStoreLeadCurrQPtr(0),
100  lastStoreLeadCurrQPtr(0),
101  oldeStoreLeadCurrQPtr(0),
102  nextStoreLeadCurrQPtr(0),
103  currStoreLeadCurrQDerivPtr(0),
104  lastStoreLeadCurrQDerivPtr(0),
105  oldeStoreLeadCurrQDerivPtr(0),
106  nextStoreLeadCurrQDerivPtr(0),
107  currSolutionDerivPtr(0),
108  lastSolutionDerivPtr(0),
109  oldeSolutionDerivPtr(0),
110  nextSolutionDerivPtr(0),
111  currStateDerivPtr(0),
112  lastStateDerivPtr(0),
113  oldeStateDerivPtr(0),
114  nextStateDerivPtr(0),
115  resMatVecPtr(0),
116  currSolutionDivDiffPtr(0),
117  lastSolutionDivDiffPtr(0),
118  oldeSolutionDivDiffPtr(0),
119  nextSolutionDivDiffPtr(0),
120  currStateDivDiffPtr(0),
121  lastStateDivDiffPtr(0),
122  oldeStateDivDiffPtr(0),
123  nextStateDivDiffPtr(0),
124  errWtVecPtr(0),
125  absErrTolPtr(0),
126  relErrTolPtr(0),
127  JMatrixPtr(0),
128  RHSVectorPtr(0),
129 #ifdef Xyce_DEBUG_DEVICE
130  JdxpVectorPtr(0),
131 #endif
132  newtonCorrectionPtr(0),
133  deviceMaskPtr(0),
134  indexVecsInitialized(false),
135 
136  qErrWtVecPtr(0),
137  daeQVectorPtr(0),
138  daeFVectorPtr(0),
139  daeBVectorPtr(0),
140  dQdxMatrixPtr(0),
141  dFdxMatrixPtr(0),
142  //saved_dQdxMatrixPtr(0),
143  dQdxVecVectorPtr(0),
144  dFdxVecVectorPtr(0),
145  dFdxdVpVectorPtr(0),
146  dQdxdVpVectorPtr(0),
147  qn0Ptr(0),
148  qpn0Ptr(0),
149  sn0Ptr(0),
150  spn0Ptr(0),
151  ston0Ptr(0),
152  stopn0Ptr(0),
153  qNewtonCorrectionPtr(0),
154  sNewtonCorrectionPtr(0),
155  stoNewtonCorrectionPtr(0),
156  stoLeadCurrQNewtonCorrectionPtr(0),
157  delta_x(0),
158  delta_q(0),
159  tmpXn0APtr(0),
160  tmpXn0BPtr(0)
161 {
162  // temporary vectors:
163  tmpSolVectorPtr = lasSysPtr->builder().createVector();
164  tmpStaVectorPtr = lasSysPtr->builder().createStateVector();
165  tmpStaDerivPtr = lasSysPtr->builder().createStateVector();
166  tmpStaDivDiffPtr = lasSysPtr->builder().createStateVector();
167  tmpStoVectorPtr = lasSysPtr->builder().createStoreVector();
168 
169  xn0Ptr = lasSysPtr->builder().createVector();
170 
171  // solution vectors:
172  currSolutionPtr = lasSysPtr->builder().createVector();
173  lastSolutionPtr = lasSysPtr->builder().createVector();
174  nextSolutionPtr = lasSysPtr->builder().createVector();
175  flagSolutionPtr = lasSysPtr->builder().createVector();
176 
177  // state vectors:
178  currStatePtr = lasSysPtr->builder().createStateVector();
179  lastStatePtr = lasSysPtr->builder().createStateVector();
180  nextStatePtr = lasSysPtr->builder().createStateVector();
181 
182  // store vectors:
183  currStorePtr = lasSysPtr->builder().createStoreVector();
184  lastStorePtr = lasSysPtr->builder().createStoreVector();
185  nextStorePtr = lasSysPtr->builder().createStoreVector();
186  currStoreLeadCurrQPtr = lasSysPtr->builder().createStoreVector();
187  lastStoreLeadCurrQPtr = lasSysPtr->builder().createStoreVector();
188  nextStoreLeadCurrQPtr = lasSysPtr->builder().createStoreVector();
189 
190  // solution derivative vectors:
191  currSolutionDerivPtr = lasSysPtr->builder().createVector();
192  lastSolutionDerivPtr = lasSysPtr->builder().createVector();
193  nextSolutionDerivPtr = lasSysPtr->builder().createVector();
194 
195  // state derivative vectors:
196  currStateDerivPtr = lasSysPtr->builder().createStateVector();
197  lastStateDerivPtr = lasSysPtr->builder().createStateVector();
198  nextStateDerivPtr = lasSysPtr->builder().createStateVector();
199 
200  // store derivative vec for lead currents.
201  currStoreLeadCurrQDerivPtr = lasSysPtr->builder().createStoreVector();
202  lastStoreLeadCurrQDerivPtr = lasSysPtr->builder().createStoreVector();
203  nextStoreLeadCurrQDerivPtr = lasSysPtr->builder().createStoreVector();
204 
205  // solution scaled divided differences:
206  currSolutionDivDiffPtr = lasSysPtr->builder().createVector();
207  lastSolutionDivDiffPtr = lasSysPtr->builder().createVector();
208  nextSolutionDivDiffPtr = lasSysPtr->builder().createVector();
209 
210  // state scaled divided differences:
211  currStateDivDiffPtr = lasSysPtr->builder().createStateVector();
212  lastStateDivDiffPtr = lasSysPtr->builder().createStateVector();
213  nextStateDivDiffPtr = lasSysPtr->builder().createStateVector();
214 
215  // error vectors:
216  errWtVecPtr = lasSysPtr->builder().createVector();
217  absErrTolPtr = lasSysPtr->builder().createVector();
218  relErrTolPtr = lasSysPtr->builder().createVector();
219 
220  errWtVecPtr->putScalar(1.0);
221 
222  deviceMaskPtr = lasSysPtr->builder().createVector();
223  deviceMaskPtr->putScalar(1.0);
224 
227 
228  // nonlinear solution vectors:
229  newtonCorrectionPtr = lasSysPtr->builder().createVector();
230 
231  // new-DAE stuff:
232  // Error Vectors
233  qErrWtVecPtr = lasSysPtr->builder().createVector();
234 
235  // DAE formulation vectors
236  daeQVectorPtr = lasSysPtr->builder().createVector();
237  daeFVectorPtr = lasSysPtr->builder().createVector();
238  daeBVectorPtr = lasSysPtr->builder().createVector();
239 
240  // DAE formulation matrices
241  dQdxMatrixPtr = lasSysPtr->builder().createMatrix();
242  dFdxMatrixPtr = lasSysPtr->builder().createMatrix();
243  //saved_dQdxMatrixPtr = lasSysPtr->builder().createMatrix();
244 
245  dQdxVecVectorPtr = lasSysPtr->builder().createVector();
246  dFdxVecVectorPtr = lasSysPtr->builder().createVector();
247 
248  // History arrays
249  int sizeOfHistory = tiaParamsPtr_->maxOrder+1;
250  for (int i=0;i<sizeOfHistory;++i)
251  {
252  xHistory.push_back(lasSysPtr->builder().createVector());
253  qHistory.push_back(lasSysPtr->builder().createVector());
254  sHistory.push_back(lasSysPtr->builder().createStateVector());
255  stoHistory.push_back(lasSysPtr->builder().createStoreVector());
256  stoLeadCurrQHistory.push_back(lasSysPtr->builder().createStoreVector());
257  }
258 
259  // Predictors
260  qn0Ptr = lasSysPtr->builder().createVector();
261  qpn0Ptr = lasSysPtr->builder().createVector();
262  sn0Ptr = lasSysPtr->builder().createStateVector();
263  spn0Ptr = lasSysPtr->builder().createStateVector();
264  ston0Ptr = lasSysPtr->builder().createStoreVector();
265  stopn0Ptr = lasSysPtr->builder().createStoreVector();
266  stoQn0Ptr = lasSysPtr->builder().createStoreVector();
267  stoQpn0Ptr = lasSysPtr->builder().createStoreVector();
268 
269  // Nonlinear solution vector:
270  qNewtonCorrectionPtr = lasSysPtr->builder().createVector();
271  sNewtonCorrectionPtr = lasSysPtr->builder().createStateVector();
272  stoNewtonCorrectionPtr = lasSysPtr->builder().createStoreVector();
273  stoLeadCurrQNewtonCorrectionPtr = lasSysPtr->builder().createStoreVector();
274 
275  // Step-size selection temporary vectors
276  delta_x = lasSysPtr->builder().createVector();
277  delta_q = lasSysPtr->builder().createVector();
278 
279  // Temporary vector for MPDE & WaMPDE interpolation
280  tmpXn0APtr = lasSysPtr->builder().createVector();
281  tmpXn0BPtr = lasSysPtr->builder().createVector();
282 }
283 
284 //-----------------------------------------------------------------------------
285 // Function : N_TIA_DataStore::N_TIA_DataStore
286 // Purpose : destructor
287 // Special Notes :
288 // Scope : public
289 // Creator : Buddy Watts, SNL
290 // Creation Date : 6/01/00
291 //-----------------------------------------------------------------------------
293 {
294  delete tmpSolVectorPtr;
295  delete tmpStaVectorPtr;
296  delete tmpStaDerivPtr;
297  delete tmpStaDivDiffPtr;
298  delete tmpStoVectorPtr;
299  delete xn0Ptr;
300 
301  delete currSolutionPtr;
302  delete lastSolutionPtr;
303 
304  delete nextSolutionPtr;
305  delete flagSolutionPtr;
306 
307  delete currStatePtr;
308  delete lastStatePtr;
309 
310  delete nextStatePtr;
311 
312  delete currStorePtr;
313  delete lastStorePtr;
314  delete nextStorePtr;
315  delete currStoreLeadCurrQPtr;
316  delete lastStoreLeadCurrQPtr;
317  delete nextStoreLeadCurrQPtr;
321 
322  delete currSolutionDerivPtr;
323  delete lastSolutionDerivPtr;
324 
325  delete nextSolutionDerivPtr;
326 
327  delete currStateDerivPtr;
328  delete lastStateDerivPtr;
329 
330  delete nextStateDerivPtr;
331 
332  delete currSolutionDivDiffPtr;
333  delete lastSolutionDivDiffPtr;
334 
335  delete nextSolutionDivDiffPtr;
336 
337  delete currStateDivDiffPtr;
338  delete lastStateDivDiffPtr;
339 
340  delete nextStateDivDiffPtr;
341 
342  delete errWtVecPtr;
343  delete absErrTolPtr;
344  delete relErrTolPtr;
345 
346  delete deviceMaskPtr;
347 
348  delete newtonCorrectionPtr;
349 
350  //new-DAE:
351  // Error Vectors
352  delete qErrWtVecPtr;
353 
354  // DAE formulation vectors
355  delete daeQVectorPtr;
356  delete daeFVectorPtr;
357  delete daeBVectorPtr;
358 
359  // DAE formulation matrices
360  delete dQdxMatrixPtr;
361  delete dFdxMatrixPtr;
362  //delete saved_dQdxMatrixPtr;
363 
364  // HB temporary vectors
365  delete dQdxVecVectorPtr;
366  delete dFdxVecVectorPtr;
367 
368  Xyce::deleteList(xHistory.begin(), xHistory.end());
369  Xyce::deleteList(qHistory.begin(), qHistory.end());
370  Xyce::deleteList(sHistory.begin(), sHistory.end());
371  Xyce::deleteList(stoHistory.begin(), stoHistory.end());
372  Xyce::deleteList(stoLeadCurrQHistory.begin(), stoLeadCurrQHistory.end());
373 
374  delete qn0Ptr;
375  delete qpn0Ptr;
376  delete sn0Ptr;
377  delete spn0Ptr;
378  delete ston0Ptr;
379  delete stopn0Ptr;
380  delete stoQn0Ptr;
381  delete stoQpn0Ptr;
382 
383  // Nonlinear solution vector:
384  delete qNewtonCorrectionPtr;
385  delete sNewtonCorrectionPtr;
386  delete stoNewtonCorrectionPtr;
388 
389  // Step-size selection temporary vectors
390  delete delta_x;
391  delete delta_q;
392 
393  // Temporary vector for WaMPDE interpolation
394  delete tmpXn0APtr;
395  delete tmpXn0BPtr;
396 
397  // Delete data in the fast time storage for HB and MPDE
398  Xyce::deleteList(fastTimeSolutionVec.begin(), fastTimeSolutionVec.end());
399  Xyce::deleteList(fastTimeStateVec.begin(), fastTimeStateVec.end());
400  Xyce::deleteList(fastTimeQVec.begin(), fastTimeQVec.end());
401  Xyce::deleteList(fastTimeStoreVec.begin(), fastTimeStoreVec.end());
402 
403  // delete the sensitivity related stuff, if necessary
405 }
406 
407 //-----------------------------------------------------------------------------
408 // Function : N_TIA_DataStore::deleteSensitivityArrays
409 // Purpose :
410 // Special Notes :
411 // Scope : public
412 // Creator : Eric Keiter, SNL
413 // Creation Date : 8/6/2014
414 //-----------------------------------------------------------------------------
416 {
417  int numParams = currDfdpPtrVector.size();
418 
419  if (resMatVecPtr != 0) delete resMatVecPtr;
420 
421  for (int ip=0;ip<numParams;++ip)
422  {
423  delete sensRHSPtrVector[ip];
424 
425  delete currDfdpPtrVector[ip];
426  delete lastDfdpPtrVector[ip];
427  delete nextDfdpPtrVector[ip];
428 
429  delete currDqdpPtrVector[ip];
430  delete lastDqdpPtrVector[ip];
431  delete nextDqdpPtrVector[ip];
432 
433  delete currDbdpPtrVector[ip];
434  delete lastDbdpPtrVector[ip];
435  delete nextDbdpPtrVector[ip];
436 
437  delete currDXdpPtrVector[ip];
438  delete lastDXdpPtrVector[ip];
439  delete nextDXdpPtrVector[ip];
440 
441  delete currDQdxDXdpPtrVector[ip];
442  delete lastDQdxDXdpPtrVector[ip];
443  delete nextDQdxDXdpPtrVector[ip];
444 
445  delete currDQdxDXdpDerivPtrVector[ip];
446  delete lastDQdxDXdpDerivPtrVector[ip];
447  delete nextDQdxDXdpDerivPtrVector[ip];
448 
449  delete currDqdpDerivPtrVector[ip];
450  delete lastDqdpDerivPtrVector[ip];
451  delete nextDqdpDerivPtrVector[ip];
452 
453  // predictors:
454  delete dfdpn0PtrVector[ip];
455  delete dqdpn0PtrVector[ip];
456  delete dbdpn0PtrVector[ip];
457  delete dXdpn0PtrVector[ip];
458 
459  delete dfdppn0PtrVector[ip];
460  delete dqdppn0PtrVector[ip];
461  delete dbdppn0PtrVector[ip];
462  delete dXdppn0PtrVector[ip];
463 
464  // newton correction:
469 
470  // history
471  int sizeOfHistory = tiaParamsPtr_->maxOrder+1;
472  for (int i=0;i<sizeOfHistory;++i)
473  {
474  delete dfdpHistory[ip][i];
475  delete dqdpHistory[ip][i];
476  delete dbdpHistory[ip][i];
477  delete dXdpHistory[ip][i];
478  delete dQdxdXdpHistory[ip][i];
479  }
480  dfdpHistory[ip].clear();
481  dqdpHistory[ip].clear();
482  dbdpHistory[ip].clear();
483  dXdpHistory[ip].clear();
484  dQdxdXdpHistory[ip].clear();
485  }
486 
487  sensRHSPtrVector.clear();
488 
489  currDfdpPtrVector.clear();
490  lastDfdpPtrVector.clear();
491  nextDfdpPtrVector.clear();
492 
493  currDqdpPtrVector.clear();
494  lastDqdpPtrVector.clear();
495  nextDqdpPtrVector.clear();
496 
497  currDbdpPtrVector.clear();
498  lastDbdpPtrVector.clear();
499  nextDbdpPtrVector.clear();
500 
501  currDXdpPtrVector.clear();
502  lastDXdpPtrVector.clear();
503  nextDXdpPtrVector.clear();
504 
505  currDQdxDXdpPtrVector.clear();
506  lastDQdxDXdpPtrVector.clear();
507  nextDQdxDXdpPtrVector.clear();
508 
512 
513  currDqdpDerivPtrVector.clear();
514  lastDqdpDerivPtrVector.clear();
515  nextDqdpDerivPtrVector.clear();
516 
517 
518  // predictors:
519  dfdpn0PtrVector.clear();
520  dqdpn0PtrVector.clear();
521  dbdpn0PtrVector.clear();
522  dXdpn0PtrVector.clear();
523 
524  dfdppn0PtrVector.clear();
525  dqdppn0PtrVector.clear();
526  dbdppn0PtrVector.clear();
527  dXdppn0PtrVector.clear();
528 
529  // newton correction:
534 
535  // history
536  dfdpHistory.clear();
537  dqdpHistory.clear();
538  dbdpHistory.clear();
539  dXdpHistory.clear();
540  dQdxdXdpHistory.clear();
541 }
542 
543 //-----------------------------------------------------------------------------
544 // Function : N_TIA_DataStore::allocateSensitivityArrays
545 // Purpose :
546 // Special Notes :
547 // Scope : public
548 // Creator : Eric Keiter, SNL
549 // Creation Date : 8/6/2014
550 //-----------------------------------------------------------------------------
552 {
553  N_LAS_Builder & bld_ = lasSysPtr->builder();
554 
555  resMatVecPtr = bld_.createVector();
556 
557  sensRHSPtrVector.resize(numParams);
558 
559  currDfdpPtrVector.resize(numParams);
560  lastDfdpPtrVector.resize(numParams);
561  oldeDfdpPtrVector.resize(numParams);
562  nextDfdpPtrVector.resize(numParams);
563 
564  currDqdpPtrVector.resize(numParams);
565  lastDqdpPtrVector.resize(numParams);
566  oldeDqdpPtrVector.resize(numParams);
567  nextDqdpPtrVector.resize(numParams);
568 
569  currDbdpPtrVector.resize(numParams);
570  lastDbdpPtrVector.resize(numParams);
571  oldeDbdpPtrVector.resize(numParams);
572  nextDbdpPtrVector.resize(numParams);
573 
574  currDXdpPtrVector.resize(numParams);
575  lastDXdpPtrVector.resize(numParams);
576  oldeDXdpPtrVector.resize(numParams);
577  nextDXdpPtrVector.resize(numParams);
578 
579  currDQdxDXdpPtrVector.resize(numParams);
580  lastDQdxDXdpPtrVector.resize(numParams);
581  oldeDQdxDXdpPtrVector.resize(numParams);
582  nextDQdxDXdpPtrVector.resize(numParams);
583 
584  currDQdxDXdpDerivPtrVector.resize(numParams);
585  lastDQdxDXdpDerivPtrVector.resize(numParams);
586  oldeDQdxDXdpDerivPtrVector.resize(numParams);
587  nextDQdxDXdpDerivPtrVector.resize(numParams);
588 
589  currDqdpDerivPtrVector.resize(numParams);
590  lastDqdpDerivPtrVector.resize(numParams);
591  oldeDqdpDerivPtrVector.resize(numParams);
592  nextDqdpDerivPtrVector.resize(numParams);
593 
594 
595  // predictors:
596  dfdpn0PtrVector.resize(numParams);
597  dqdpn0PtrVector.resize(numParams);
598  dbdpn0PtrVector.resize(numParams);
599  dXdpn0PtrVector.resize(numParams);
600 
601  dfdppn0PtrVector.resize(numParams);
602  dqdppn0PtrVector.resize(numParams);
603  dbdppn0PtrVector.resize(numParams);
604  dXdppn0PtrVector.resize(numParams);
605 
606  // newton correction:
607  dfdpNewtonCorrectionPtrVector.resize(numParams);
608  dqdpNewtonCorrectionPtrVector.resize(numParams);
609  dbdpNewtonCorrectionPtrVector.resize(numParams);
610  dXdpNewtonCorrectionPtrVector.resize(numParams);
611 
612  // history
613  dfdpHistory.resize(numParams);
614  dqdpHistory.resize(numParams);
615  dbdpHistory.resize(numParams);
616  dXdpHistory.resize(numParams);
617  dQdxdXdpHistory.resize(numParams);
618 
619  for (int ip=0;ip<numParams;++ip)
620  {
621  sensRHSPtrVector[ip] = bld_.createVector();
622 
623  currDfdpPtrVector[ip] = bld_.createVector();
624  lastDfdpPtrVector[ip] = bld_.createVector();
625  nextDfdpPtrVector[ip] = bld_.createVector();
626 
627  currDqdpPtrVector[ip] = bld_.createVector();
628  lastDqdpPtrVector[ip] = bld_.createVector();
629  nextDqdpPtrVector[ip] = bld_.createVector();
630 
631  currDbdpPtrVector[ip] = bld_.createVector();
632  lastDbdpPtrVector[ip] = bld_.createVector();
633  nextDbdpPtrVector[ip] = bld_.createVector();
634 
635  currDXdpPtrVector[ip] = bld_.createVector();
636  lastDXdpPtrVector[ip] = bld_.createVector();
637  nextDXdpPtrVector[ip] = bld_.createVector();
638 
639  currDQdxDXdpPtrVector[ip] = bld_.createVector();
640  lastDQdxDXdpPtrVector[ip] = bld_.createVector();
641  nextDQdxDXdpPtrVector[ip] = bld_.createVector();
642 
643  currDQdxDXdpDerivPtrVector[ip] = bld_.createVector();
644  lastDQdxDXdpDerivPtrVector[ip] = bld_.createVector();
645  nextDQdxDXdpDerivPtrVector[ip] = bld_.createVector();
646 
647  currDqdpDerivPtrVector[ip] = bld_.createVector();
648  lastDqdpDerivPtrVector[ip] = bld_.createVector();
649  nextDqdpDerivPtrVector[ip] = bld_.createVector();
650 
651  // predictors:
652  dfdpn0PtrVector[ip] = bld_.createVector();
653  dqdpn0PtrVector[ip] = bld_.createVector();
654  dbdpn0PtrVector[ip] = bld_.createVector();
655  dXdpn0PtrVector[ip] = bld_.createVector();
656 
657  dfdppn0PtrVector[ip] = bld_.createVector();
658  dqdppn0PtrVector[ip] = bld_.createVector();
659  dbdppn0PtrVector[ip] = bld_.createVector();
660  dXdppn0PtrVector[ip] = bld_.createVector();
661 
662  // newton correction:
663  dfdpNewtonCorrectionPtrVector[ip] = bld_.createVector();
664  dqdpNewtonCorrectionPtrVector[ip] = bld_.createVector();
665  dbdpNewtonCorrectionPtrVector[ip] = bld_.createVector();
666  dXdpNewtonCorrectionPtrVector[ip] = bld_.createVector();
667 
668  // history
669  int sizeOfHistory = tiaParamsPtr_->maxOrder+1;
670  for (int i=0;i<sizeOfHistory;++i)
671  {
672  dfdpHistory[ip].push_back(bld_.createVector());
673  dqdpHistory[ip].push_back(bld_.createVector());
674  dbdpHistory[ip].push_back(bld_.createVector());
675  dXdpHistory[ip].push_back(bld_.createVector());
676  dQdxdXdpHistory[ip].push_back(bld_.createVector());
677  }
678  }
679 }
680 
681 // ----------------------------------------------------------------------------
682 // ----------------------- DataStore Class Functions -------------------------
683 // ----------------------------------------------------------------------------
684 
685 //-----------------------------------------------------------------------------
686 // Function : N_TIA_DataStore::printOutPointers
687 // Purpose :
688 // Special Notes :
689 // Scope : public
690 // Creator : Eric Keiter, SNL
691 // Creation Date : 6/23/00
692 //-----------------------------------------------------------------------------
694 {
695  Xyce::dout() << "olde ptr = " << oldeSolutionPtr << std::endl;
696  Xyce::dout() << "last ptr = " << lastSolutionPtr << std::endl;
697  Xyce::dout() << "curr ptr = " << currSolutionPtr << std::endl;
698  Xyce::dout() << "next ptr = " << nextSolutionPtr << std::endl;
699 }
700 
701 //-----------------------------------------------------------------------------
702 // Function : N_TIA_DataStore::setConstantHistory
703 // Purpose : This function is called after the operating point
704 // calculation has been called. Once the operating point
705 // solution has been obtained, the code should regard that
706 // solution as having been the existing constant solution since
707 // the dawn of time.
708 // Special Notes : The most recent solution, etc., are in the "next" vectors.
709 // Scope : public
710 // Creator : Eric Keiter, SNL
711 // Creation Date : 6/23/00
712 //-----------------------------------------------------------------------------
714 {
715 #ifdef Xyce_DEBUG_TIME
716  Xyce::dout() << "\nN_TIA_DataStore::setConstantHistory" << std::endl;
717 #endif
718 
719  // Solutions:
722 
723  // Derivative of Solutions:
726 
727  // Scaled Divided Differences of solutions:
730 
731  // States:
732  *(lastStatePtr) = *(nextStatePtr);
733  *(currStatePtr) = *(nextStatePtr);
734 
735  // Stores:
736  *(lastStorePtr) = *(nextStorePtr);
737  *(currStorePtr) = *(nextStorePtr);
738 
741 
742  // Derivative of States:
745 
746  // lead current derivative info in store
749 
750  // Scaled Divided Differences of states:
753 
755 }
756 
757 //-----------------------------------------------------------------------------
758 // Function : N_TIA_DataStore::setConstantSensitivityHistory
759 // Purpose :
760 // Special Notes : The most recent solution, etc., are in the "next" vectors.
761 // Scope : public
762 // Creator : Eric Keiter, SNL
763 // Creation Date : 8/28/2014
764 //-----------------------------------------------------------------------------
766 {
767  // Sensitivities:
768  for (int ip=0;ip<nextDfdpPtrVector.size();++ip)
769  {
770  *(lastDfdpPtrVector[ip]) = *(nextDfdpPtrVector[ip]);
771  *(currDfdpPtrVector[ip]) = *(nextDfdpPtrVector[ip]);
772 
773  *(lastDqdpPtrVector[ip]) = *(nextDqdpPtrVector[ip]);
774  *(currDqdpPtrVector[ip]) = *(nextDqdpPtrVector[ip]);
775 
776  *(lastDbdpPtrVector[ip]) = *(nextDbdpPtrVector[ip]);
777  *(currDbdpPtrVector[ip]) = *(nextDbdpPtrVector[ip]);
778 
781 
782  *(lastDXdpPtrVector[ip]) = *(nextDXdpPtrVector[ip]);
783  *(currDXdpPtrVector[ip]) = *(nextDXdpPtrVector[ip]);
784 
787 
790  }
791 }
792 
793 //-----------------------------------------------------------------------------
794 // Function : N_TIA_DataStore::resetAll
795 //
796 // Purpose : This function resets everything so that a transient loop
797 // can be started from the beginning.
798 //
799 // Special Notes : This function was needed for HB.
800 //
801 // Scope : public
802 // Creator : T. Mei, SNL
803 // Creation Date : 02/26/09
804 //-----------------------------------------------------------------------------
806 {
809 
810  return true;
811 }
812 
813 //-----------------------------------------------------------------------------
814 // Function : N_TIA_DataStore::resetFastTimeData
815 //
816 // Purpose : This function deletes the information from all the vectors
817 // that store fast time data for HB and MPDE
818 //
819 // Special Notes : This function was needed for HB.
820 //
821 // Scope : public
822 // Creator : Heidi Thornquist, SNL
823 // Creation Date : 06/05/13
824 //-----------------------------------------------------------------------------
826 {
827  // Clear the time step vectors
828  timeSteps.clear();
829  timeStepsBreakpointFlag.clear();
830 
831  // Delete any stored up any solution or state info
832  Xyce::deleteList(fastTimeSolutionVec.begin(), fastTimeSolutionVec.end());
833  Xyce::deleteList(fastTimeStateVec.begin(), fastTimeStateVec.end());
834  Xyce::deleteList(fastTimeQVec.begin(), fastTimeQVec.end());
835  Xyce::deleteList(fastTimeStoreVec.begin(), fastTimeStoreVec.end());
836 
837  fastTimeSolutionVec.clear();
838  fastTimeStateVec.clear();
839  fastTimeQVec.clear();
840  fastTimeStoreVec.clear();
841 
842  return true;
843 }
844 
845 
846 
847 //-----------------------------------------------------------------------------
848 // Function : N_TIA_DataStore::updateSolDataArrays
849 // Purpose : Update the necessary integration data arrays for
850 // preparation of the next integration step. This is done after
851 // a successful step has been taken.
852 // Special Notes :
853 // Scope : public
854 // Creator : Buddy Watts, SNL
855 // Creation Date : 6/01/00
856 //-----------------------------------------------------------------------------
858 {
859 #ifdef Xyce_DEBUG_TIME
860  if (tiaParamsPtr_->debugLevel > 1)
861  {
862  Xyce::dout() << "\nN_TIA_DataStore::updateSolDataArrays " << std::endl;
863  }
864 #endif
865 
866  // if the next solution has been switched out (probably because of NOX),
867  // then reset it
869 
870  // Solutions:
875 
876  // Derivative of Solutions:
881 
882  // Scaled Divided Differences of solutions:
887 
888  // States:
893 
894  // Stores:
903 
904  // Derivative of States:
909 
910  // lead curent component of store
915 
916  // Scaled Divided Differences of states:
921 
922  // Sensitivities, if they were requested:
923  int iparamSizeF = currDfdpPtrVector.size();
924  for (int ip=0;ip<iparamSizeF;++ip)
925  {
930  }
931 
932  int iparamSizeQ = currDqdpPtrVector.size();
933  for (int ip=0;ip<iparamSizeQ;++ip)
934  {
939  }
940 
941  int iparamSizeQderiv = currDqdpDerivPtrVector.size();
942  for (int ip=0;ip<iparamSizeQderiv;++ip)
943  {
948  }
949 
950  int iparamSizeB = currDbdpPtrVector.size();
951  for (int ip=0;ip<iparamSizeB;++ip)
952  {
957  }
958 
959  int iparamSizeX = currDXdpPtrVector.size();
960  for (int ip=0;ip<iparamSizeX;++ip)
961  {
966  }
967 
968  int iparamSizeQX = currDQdxDXdpPtrVector.size();
969  for (int ip=0;ip<iparamSizeQX;++ip)
970  {
975  }
976 
977 
978  int iparamSizeQXd = currDQdxDXdpDerivPtrVector.size();
979  for (int ip=0;ip<iparamSizeQXd;++ip)
980  {
985  }
986 
987  // copy contents of "curr" into "next". This is to insure
988  // that at a minimum, the initial guess for the Newton solve
989  // will at least be the results of the previous Newton solve.
991  *(nextStatePtr) = *(currStatePtr);
992  *(nextStorePtr) = *(currStorePtr);
993 
994  return;
995 }
996 
997 //-----------------------------------------------------------------------------
998 // Function : N_TIA_DataStore::updateStateDataArrays
999 //
1000 //
1001 // Purpose : Same as updateSolDataArrays, but this function only
1002 // advances the state vector, and leaves the
1003 // solution alone.
1004 //
1005 // Special Notes : The main usage of this function is LOCA.
1006 // After each continuation step, LOCA needs to call
1007 // this function. LOCA keeps track of solution vectors
1008 // on its own, which is why updateSolDataArrays
1009 // is inappropriate for LOCA.
1010 //
1011 // This is necessary for voltage limiting to be
1012 // consistent with LOCA.
1013 //
1014 // Scope : public
1015 // Creator : Eric R. Keiter, SNL, 9233.
1016 // Creation Date : 3/06/05
1017 //-----------------------------------------------------------------------------
1019 {
1020 #ifdef Xyce_DEBUG_TIME
1021  Xyce::dout() << "\nN_TIA_DataStore::updateStateDataArrays " << std::endl;
1022 #endif
1023  // States:
1028 
1029  // Stores:
1034 
1035  // q component of lead current
1040 
1041  // Derivative of States:
1046 
1047  // Scaled Divided Differences of states:
1052 
1053 
1054  // Now, make the "next" stuff the same as the "curr" stuff.
1055  // This is done because at the end of the tranop, but before
1056  // the transient phase starts, the function setConstantHistory
1057  // will be called. When it is called, the most recent values
1058  // for state variables need to be in the "next" vectors.
1059  //
1060  // As long as LOCA solves are never used for transient, and only
1061  // for DC and tranop solves, this is OK. This is, of course,
1062  // a bit of a kludge.
1063  *(nextStatePtr) = *(currStatePtr);
1064  *(nextStorePtr) = *(currStorePtr);
1065 
1066  return true;
1067 }
1068 
1069 #ifndef OLD_PLOT
1070 //-----------------------------------------------------------------------------
1071 // Function : N_TIA_DataStore::outputSolDataArrays
1072 // Purpose :
1073 // Special Notes :
1074 // Scope : public
1075 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1076 // Creation Date : 6/29/00
1077 //-----------------------------------------------------------------------------
1079 {
1080  char tmp[256];
1081  os << std::endl
1082  << Xyce::section_divider << std::endl
1083  << std::endl
1084  << " Solution Vectors:\n Current Last Olde Error" << std::endl;
1085 
1086  for (unsigned int k = 0; k < solutionSize; ++k)
1087  {
1088  os << (*(currSolutionPtr))[k] << (*(lastSolutionPtr))[k] << (*(oldeSolutionPtr))[k] << (*(newtonCorrectionPtr))[k] << std::endl;
1089  }
1090 
1091  os << Xyce::section_divider << std::endl;
1092 }
1093 
1094 #else
1095 
1096 //-----------------------------------------------------------------------------
1097 // Function : N_TIA_DataStore::outputSolDataArrays
1098 // Purpose :
1099 // Special Notes :
1100 // Scope : public
1101 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1102 // Creation Date : 6/29/00
1103 //-----------------------------------------------------------------------------
1104 void N_TIA_DataStore::outputSolDataArrays(std::ostream &os)
1105 {
1106  for (unsigned int k = 0; k < solutionSize; ++k)
1107  {
1108  os << "\t" << (*(currSolutionPtr))[0][k] << std::endl;
1109  }
1110  os << std::endl;
1111 }
1112 
1113 #endif
1114 
1115 //-----------------------------------------------------------------------------
1116 // Function : N_TIA_DataStore::enableOrderOneStart
1117 // Purpose : Initialize arrays for "re-starting" integration at order 1.
1118 // Special Notes :
1119 // Scope : public
1120 // Creator : Buddy Watts, SNL
1121 // Creation Date : 6/01/00
1122 //-----------------------------------------------------------------------------
1124 {
1125  // solution vectors:
1128 
1129  nextSolutionDerivPtr->putScalar(0.0);
1130  currSolutionDerivPtr->putScalar(0.0);
1131  currSolutionDivDiffPtr->putScalar(0.0);
1132 
1133  // state vectors:
1136 
1137  nextStateDerivPtr->putScalar(0.0);
1138  currStateDerivPtr->putScalar(0.0);
1139  currStateDivDiffPtr->putScalar(0.0);
1140 
1141  // store vectors:
1146  nextStoreLeadCurrQDerivPtr->putScalar(0.0);
1147  currStoreLeadCurrQDerivPtr->putScalar(0.0);
1148 
1149  // sensitivities
1150  int iparamSizeF = currDfdpPtrVector.size();
1151  for (int ip=0;ip<iparamSizeF;++ip)
1152  {
1153  *(oldeDfdpPtrVector[ip]) = *(currDfdpPtrVector[ip]);
1154  *(lastDfdpPtrVector[ip]) = *(currDfdpPtrVector[ip]);
1155  currDfdpPtrVector[ip]->putScalar(0.0);
1156  nextDfdpPtrVector[ip]->putScalar(0.0);
1157  }
1158 
1159  int iparamSizeQ = currDqdpPtrVector.size();
1160  for (int ip=0;ip<iparamSizeQ;++ip)
1161  {
1162  *(oldeDqdpPtrVector[ip]) = *(currDqdpPtrVector[ip]);
1163  *(lastDqdpPtrVector[ip]) = *(currDqdpPtrVector[ip]);
1164  currDqdpPtrVector[ip]->putScalar(0.0);
1165  nextDqdpPtrVector[ip]->putScalar(0.0);
1166  }
1167 
1168  int iparamSizeQd = currDqdpDerivPtrVector.size();
1169  for (int ip=0;ip<iparamSizeQ;++ip)
1170  {
1173  currDqdpDerivPtrVector[ip]->putScalar(0.0);
1174  nextDqdpDerivPtrVector[ip]->putScalar(0.0);
1175  }
1176 
1177  int iparamSizeB = currDbdpPtrVector.size();
1178  for (int ip=0;ip<iparamSizeB;++ip)
1179  {
1180  *(oldeDbdpPtrVector[ip]) = *(currDbdpPtrVector[ip]);
1181  *(lastDbdpPtrVector[ip]) = *(currDbdpPtrVector[ip]);
1182  currDbdpPtrVector[ip]->putScalar(0.0);
1183  nextDbdpPtrVector[ip]->putScalar(0.0);
1184  }
1185 
1186  int iparamSizeX = currDXdpPtrVector.size();
1187  for (int ip=0;ip<iparamSizeX;++ip)
1188  {
1189  *(oldeDXdpPtrVector[ip]) = *(currDXdpPtrVector[ip]);
1190  *(lastDXdpPtrVector[ip]) = *(currDXdpPtrVector[ip]);
1191  currDXdpPtrVector[ip]->putScalar(0.0);
1192  nextDXdpPtrVector[ip]->putScalar(0.0);
1193  }
1194 
1195  int iparamSizeQX = currDQdxDXdpPtrVector.size();
1196  for (int ip=0;ip<iparamSizeQX;++ip)
1197  {
1200  currDQdxDXdpPtrVector[ip]->putScalar(0.0);
1201  nextDQdxDXdpPtrVector[ip]->putScalar(0.0);
1202  }
1203 
1204 
1205  int iparamSizeQXd = currDQdxDXdpDerivPtrVector.size();
1206  for (int ip=0;ip<iparamSizeQX;++ip)
1207  {
1210  currDQdxDXdpDerivPtrVector[ip]->putScalar(0.0);
1211  nextDQdxDXdpDerivPtrVector[ip]->putScalar(0.0);
1212  }
1213 
1214 }
1215 
1216 //-----------------------------------------------------------------------------
1217 // Function : N_TIA_DataStore::outputPredictedSolution
1218 // Purpose : Set ErrorEstimate array values to zero.
1219 // Special Notes :
1220 // Scope : public
1221 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1222 // Creation Date : 6/27/00
1223 //-----------------------------------------------------------------------------
1225 {
1226  os << Xyce::subsection_divider << std::endl;
1227 
1228  os << " Predicted Solution:" << std::endl;
1229 
1230  for (unsigned int k = 0; k< solutionSize; ++k)
1231  {
1232  os << (*(nextSolutionPtr))[k] << std::endl;
1233  }
1234 
1235  os << Xyce::subsection_divider << std::endl;
1236 }
1237 
1238 //-----------------------------------------------------------------------------
1239 // Function : N_TIA_DataStore::outputPredictedDerivative
1240 // Purpose : Set ErrorEstimate array values to zero.
1241 // Special Notes :
1242 // Scope : public
1243 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1244 // Creation Date : 6/27/00
1245 //-----------------------------------------------------------------------------
1247 {
1248  os << Xyce::subsection_divider << std::endl;
1249 
1250  os << " Predicted Derivative:" << std::endl;
1251 
1252  for (unsigned int k = 0; k < solutionSize; ++k)
1253  {
1254  os << (*(nextSolutionDerivPtr))[k] << std::endl;
1255  }
1256 
1257  os << Xyce::subsection_divider << std::endl;
1258 }
1259 
1260 //-----------------------------------------------------------------------------
1261 // Function : N_TIA_DataStore::partialErrorNormSum
1262 // Purpose : Needed by 2-level solves.
1263 //
1264 // Special Notes : A weighted RMS norm is this:
1265 //
1266 // norm = sqrt ( 1/n * sum (x/w)^2 )
1267 //
1268 // What this function returns is: sum (x/w)^2
1269 //
1270 // It will later be summed with other patial sums
1271 // to get the complete WRMS value.
1272 //
1273 // Scope : public
1274 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1275 // Creation Date : 03/15/06
1276 //-----------------------------------------------------------------------------
1278 {
1279  double errorNorm = 0.0;
1280  newtonCorrectionPtr->wRMSNorm(*errWtVecPtr, &errorNorm);
1281  double sum = errorNorm*errorNorm;
1282  double length = newtonCorrectionPtr->globalLength();
1283 
1284  sum *= length;
1285 
1286  return sum;
1287 }
1288 
1289 //-----------------------------------------------------------------------------
1290 // Function : N_TIA_DataStore::globalLength
1291 // Purpose : Needed by 2-level solves.
1292 // Special Notes :
1293 // Scope : public
1294 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1295 // Creation Date : 03/15/06
1296 //-----------------------------------------------------------------------------
1298 {
1299  return newtonCorrectionPtr->globalLength();
1300 }
1301 
1302 //-----------------------------------------------------------------------------
1303 // Function : N_TIA_DataStore::computeDividedDifferences
1304 // Purpose : Compute the scaled (by current stepsize) divided difference
1305 // approximation to the derivative.
1306 // Special Notes :
1307 // Scope : public
1308 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1309 // Creation Date : 6/27/00
1310 //-----------------------------------------------------------------------------
1312 {
1313  // First do the solution divided difference:
1314  nextSolutionDivDiffPtr->linearCombo(1.0, *(nextSolutionPtr), -1.0, *(currSolutionPtr));
1315 
1316  // Now do the state divided difference:
1317  nextStateDivDiffPtr->linearCombo(1.0, *(nextStatePtr), -1.0, *(currStatePtr));
1318 
1319  return;
1320 }
1321 
1322 //-----------------------------------------------------------------------------
1323 // Function : N_TIA_DataStore::computeDivDiffsBlock
1324 // Purpose : Compute the scaled (by current stepsize) divided difference
1325 // approximation to the derivative. This is the same as
1326 // the function "computeDividedDifferences", except that
1327 // the operation is only performed on a sub-block of the
1328 // vectors.
1329 //
1330 // Special Notes : Not done yet...
1331 // Scope : public
1332 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1333 // Creation Date : 01/10/01
1334 //-----------------------------------------------------------------------------
1336  const std::list<index_pair> & solGIDList,
1337  const std::list<index_pair> & staGIDList)
1338 {}
1339 
1340 //-----------------------------------------------------------------------------
1341 // Function : N_TIA_DataStore::equateTmpVectors
1342 // Purpose : This function equates the 6 temporary vectors with
1343 // their "next" vector equivalents. This function
1344 // is neccessary for the nonlinear solver damping loop.
1345 // Special Notes :
1346 // Scope : public
1347 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1348 // Creation Date : 01/24/02
1349 //-----------------------------------------------------------------------------
1351 {
1352  // next solution vector:
1354 
1355  // next state vector:
1356  *(tmpStaVectorPtr) = *(nextStatePtr);
1357 
1358  // next store vector:
1359  *(tmpStoVectorPtr) = *(nextStorePtr);
1360 
1361  // next state divided difference vector:
1363 
1364  // next state derivative vector:
1366 
1367  return true;
1368 }
1369 
1370 //-----------------------------------------------------------------------------
1371 // Function : N_TIA_DataStore::usePreviousSolAsPredictor
1372 // Purpose :
1373 // Special Notes :
1374 // Scope : public
1375 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1376 // Creation Date : 6/28/01
1377 //-----------------------------------------------------------------------------
1379 {
1380  bool bsuccess = true;
1381 
1383  *(nextStatePtr) = *(currStatePtr);
1384  *(nextStorePtr) = *(currStorePtr);
1385 
1386  return bsuccess;
1387 }
1388 
1389 //-----------------------------------------------------------------------------
1390 // Function : N_TIA_DataStore::setNextSolVectorPtr
1391 // Purpose :
1392 // Special Notes : Only needed for NOX, and other solvers that prefer to
1393 // own the solution vector.
1394 //
1395 // Scope : public
1396 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1397 // Creation Date : 4/22/03
1398 //-----------------------------------------------------------------------------
1399 bool N_TIA_DataStore::setNextSolVectorPtr (N_LAS_Vector * solVecPtr)
1400 {
1401  // only save the old pointer if it hasn't been switched yet.
1402  if (!nextSolPtrSwitched)
1403  {
1405  nextSolPtrSwitched = true;
1406  }
1407  nextSolutionPtr = solVecPtr;
1408 
1409  return true;
1410 }
1411 
1412 //-----------------------------------------------------------------------------
1413 // Function : N_TIA_DataStore::unsetNextSolVectorPtr
1414 // Purpose :
1415 // Special Notes : This also copies over the solution, in addition to the
1416 // pointer.
1417 //
1418 // This is only called when it is time to rotate the
1419 // pointers for the next time step. If we have been
1420 // running with NOX, or with some other solver that prefers
1421 // to own the solution vector, this is neccessary, and the
1422 // switch flag should be set. Otherwise, not.
1423 //
1424 // Basically, if we've been running with NOX, then the next
1425 // solution vector ptr has probably been switched out at least
1426 // once. We need to maintain the history, so we make a
1427 // copy of this switched solution vector, and the
1428 // restore the old pointer.
1429 //
1430 // This is kludgy, but will have to do for now.
1431 //
1432 // Scope : public
1433 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1434 // Creation Date : 4/22/03
1435 //-----------------------------------------------------------------------------
1437 {
1438  if (nextSolPtrSwitched)
1439  {
1442  nextSolPtrSwitched = false;
1443  }
1444 
1445  return true;
1446 }
1447 
1448 //-----------------------------------------------------------------------------
1449 // Function : N_TIA_DataStore::setZeroHistory
1450 // Purpose : Sets everything to zero.
1451 // Special Notes :
1452 // Scope : public
1453 // Creator : Eric Keiter, SNL
1454 // Creation Date : 1/24/07
1455 //-----------------------------------------------------------------------------
1457 {
1458 #ifdef Xyce_DEBUG_TIME
1459  Xyce::dout() << "\nN_TIA_DataStore::setZeroHistory" << std::endl;
1460 #endif
1461  // Solutions:
1462  nextSolutionPtr->putScalar(0.0);
1463  nextSolutionDerivPtr->putScalar(0.0);
1464  nextSolutionDivDiffPtr->putScalar(0.0);
1465 
1466  // States:
1467  nextStatePtr->putScalar(0.0);
1468  nextStateDerivPtr->putScalar(0.0);
1469  nextStateDivDiffPtr->putScalar(0.0);
1470  nextStorePtr->putScalar(0.0);
1471  nextStoreLeadCurrQPtr->putScalar(0.0);
1472 
1473  for (int ip=0;ip<nextDfdpPtrVector.size();++ip)
1474  {
1475  nextDfdpPtrVector[ip]->putScalar(0.0);
1476  nextDqdpPtrVector[ip]->putScalar(0.0);
1477  nextDqdpDerivPtrVector[ip]->putScalar(0.0);
1478  nextDbdpPtrVector[ip]->putScalar(0.0);
1479  nextDXdpPtrVector[ip]->putScalar(0.0);
1480  nextDQdxDXdpPtrVector[ip]->putScalar(0.0);
1481  nextDQdxDXdpDerivPtrVector[ip]->putScalar(0.0);
1482  }
1483 
1484  qErrWtVecPtr->putScalar(0.0);
1485 
1486  // DAE formulation vectors
1487  daeQVectorPtr->putScalar(0.0);
1488  daeFVectorPtr->putScalar(0.0);
1489  daeBVectorPtr->putScalar(0.0);
1490 
1491  // Predictors
1492  xn0Ptr->putScalar(0.0);
1493  qn0Ptr->putScalar(0.0);
1494  qpn0Ptr->putScalar(0.0);
1495  sn0Ptr->putScalar(0.0);
1496  spn0Ptr->putScalar(0.0);
1497  stoQn0Ptr->putScalar(0.0);
1498  stoQpn0Ptr->putScalar(0.0);
1499 
1500  for (int ip=0;ip<dfdpn0PtrVector.size();++ip)
1501  {
1502  dfdpn0PtrVector[ip]->putScalar(0.0);
1503  dqdpn0PtrVector[ip]->putScalar(0.0);
1504  dbdpn0PtrVector[ip]->putScalar(0.0);
1505  dXdpn0PtrVector[ip]->putScalar(0.0);
1506 
1507  dfdppn0PtrVector[ip]->putScalar(0.0);
1508  dqdppn0PtrVector[ip]->putScalar(0.0);
1509  dbdppn0PtrVector[ip]->putScalar(0.0);
1510  dXdppn0PtrVector[ip]->putScalar(0.0);
1511  }
1512 
1513  // Nonlinear solution vector:
1514  qNewtonCorrectionPtr->putScalar(0.0);
1515  sNewtonCorrectionPtr->putScalar(0.0);
1516  stoNewtonCorrectionPtr->putScalar(0.0);
1517  stoLeadCurrQNewtonCorrectionPtr->putScalar(0.0);
1518 
1519  for (int ip=0;ip<dfdpNewtonCorrectionPtrVector.size();++ip)
1520  {
1521  dfdpNewtonCorrectionPtrVector[ip]->putScalar(0.0);
1522  dqdpNewtonCorrectionPtrVector[ip]->putScalar(0.0);
1523  dbdpNewtonCorrectionPtrVector[ip]->putScalar(0.0);
1524  dXdpNewtonCorrectionPtrVector[ip]->putScalar(0.0);
1525  }
1526 
1527  // Step-size selection temporary vectors
1528  delta_x->putScalar(0.0);
1529  delta_q->putScalar(0.0);
1530 
1531  // Temporary vector for WaMPDE interpolation
1532  tmpXn0APtr->putScalar(0.0);
1533  tmpXn0BPtr->putScalar(0.0);
1534 
1535  // This just sets the "oldDAE" history vectors to zero.
1536  setConstantHistory ();
1537 
1538  // new-DAE history:
1539  int sizeOfHistory = xHistory.size();
1540  for (int i = 0; i < sizeOfHistory; ++i)
1541  {
1542  xHistory[i]->putScalar(0.0);
1543  qHistory[i]->putScalar(0.0);
1544  sHistory[i]->putScalar(0.0);
1545  stoHistory[i]->putScalar(0.0);
1546  stoLeadCurrQHistory[i]->putScalar(0.0);
1547 
1548  for (int ip=0;ip<dfdpHistory.size();++ip)
1549  {
1550  std::vector<N_LAS_Vector *> dfdp = dfdpHistory[ip];
1551  std::vector<N_LAS_Vector *> dqdp = dqdpHistory[ip];
1552  std::vector<N_LAS_Vector *> dbdp = dbdpHistory[ip];
1553  std::vector<N_LAS_Vector *> dXdp = dXdpHistory[ip];
1554  std::vector<N_LAS_Vector *> dQdxdXdp = dQdxdXdpHistory[ip];
1555 
1556  dfdp[i]->putScalar(0.0);
1557  dqdp[i]->putScalar(0.0);
1558  dbdp[i]->putScalar(0.0);
1559  dXdp[i]->putScalar(0.0);
1560  dQdxdXdp[i]->putScalar(0.0);
1561  }
1562  }
1563 }
1564 
1565 //-----------------------------------------------------------------------------
1566 // Function : N_TIA_DataStore::setErrorWtVector_
1567 // Purpose : Set the Error Weight Vector (defined in terms of the
1568 // solution approximation and error tolerances).
1569 // Special Notes :
1570 // Scope : public
1571 // Creator : Eric Keiter, SNL,Parallel Computational Sciences
1572 // Creation Date : 5/25/05
1573 //-----------------------------------------------------------------------------
1575 {
1576  // to avoid several conditionals within a loop we traverse many times, we'll
1577  // presort the variables into types so we can loop without also making conditional
1578  // checks
1579  if( ! indexVecsInitialized )
1580  {
1581  // figure out which unknowns are V's, I's or masked.
1582  numVVars = 0;
1583  numIVars = 0;
1584  numMaskedVars = 0;
1585 
1586  bool nTDMF=lasSysPtr->getNonTrivialDeviceMaskFlag();
1587 
1588  // first count how many of each type we have
1589  for (int k = 0; k < solutionSize; ++k)
1590  {
1591  if (nTDMF && (*(deviceMaskPtr))[k] == 0.0)
1592  {
1593  numMaskedVars++;
1594  }
1595  else if( (tiaParamsPtr_->fastTests == true) && (varTypeVec[k] == 'I') )
1596  {
1597  // we only count I vars if we're doing fast tests, otherwise we treat them as v vars
1598  numIVars++;
1599  }
1600  else
1601  {
1602  numVVars++;
1603  }
1604  }
1605 
1606  // set up our storage
1607  indexVVars.resize(numVVars);
1608  indexIVars.resize(numIVars);
1610 
1611  // now fill the index arrays
1612  for (int k = 0, currI = 0, currV = 0, currM = 0 ; k < solutionSize; ++k)
1613  {
1614  if (nTDMF && (*(deviceMaskPtr))[k] == 0.0)
1615  {
1616  indexMaskedVars[currM] = k;
1617  currM++;
1618  }
1619  else if( (tiaParamsPtr_->fastTests == true) && (varTypeVec[k] == 'I') )
1620  {
1621  indexIVars[currI] = k;
1622  currI++;
1623  }
1624  else
1625  {
1626  indexVVars[currV] = k;
1627  currV++;
1628  }
1629  }
1630 
1631  indexVecsInitialized = true;
1632  }
1633 
1634 #ifdef Xyce_DEBUG_TIME
1635  char tmp[256];
1636 
1637  if (tiaParamsPtr_->debugLevel > 1)
1638  {
1639  Xyce::dout() << Xyce::section_divider << std::endl
1640  << "N_TIA_DataStore::setErrorWtVector" << std::endl << std::endl
1641  << " errorWtVector currSolution relErrorTol absErrorTol" << std::endl
1642  << " -------------- -------------- -------------- --------------" << std::endl;
1643  }
1644 #endif
1645 
1646  if (tiaParamsPtr_->newLte == true)
1647 // if (tiaParamsPtr_->integrationMethod == 7 && tiaParamsPtr_->newLte == true)
1648  {
1649  double currMaxValue = 0.0;
1650  currSolutionPtr->infNorm(&currMaxValue);
1651 
1652  errWtVecPtr->putScalar(currMaxValue);
1653 
1654 #ifdef Xyce_DEBUG_TIME
1655  if (tiaParamsPtr_->debugLevel > 0)
1656  {
1657  std::vector<int> index(1, -1);
1658  currSolutionPtr->infNormIndex( &index[0] );
1659  Xyce::dout() << "currMaxValue = " << currMaxValue << ", currMaxValueIndex = " << index[0] << std::endl;
1660  }
1661 #endif // Xyce_DEBUG_TIME
1662  }
1663  else
1664  {
1665  errWtVecPtr->absValue(*currSolutionPtr);
1666 
1667 #ifdef Xyce_DEBUG_TIME
1668  if (tiaParamsPtr_->debugLevel > 0)
1669  {
1670  double currMaxValue = 0.0;
1671  currSolutionPtr->infNorm(&currMaxValue);
1672  std::vector<int> index(1, -1);
1673  currSolutionPtr->infNormIndex( &index[0] );
1674  Xyce::dout() << "currMaxValueoldLte = " << currMaxValue << ", currMaxValueIndex = " << index[0] << std::endl;
1675  }
1676 #endif
1677  }
1678 
1679  qErrWtVecPtr->absValue(*daeQVectorPtr);
1680 
1681  if( tiaParamsPtr_->fastTests == true )
1682  {
1683  // Voltage variables
1684  for (int k = 0; k < numVVars; ++k)
1685  {
1686 // errWtVecPtr->putScalar(currMaxValue);
1688  {
1689  (*(errWtVecPtr))[indexVVars[k]] = N_UTL_MachineDependentParams::MachineBig();
1690  (*(qErrWtVecPtr))[indexVVars[k]] = N_UTL_MachineDependentParams::MachineBig();
1691  }
1692  else
1693  {
1694  (*(errWtVecPtr))[indexVVars[k]] = (*(relErrTolPtr))[indexVVars[k]] * (*(errWtVecPtr))[indexVVars[k]] + (*(absErrTolPtr))[indexVVars[k]];
1696  }
1697  }
1698 
1699 
1700  // Current variables
1701  for (int k = 0; k < numIVars; ++k)
1702  {
1703 // errWtVecPtr->absValue(*currSolutionPtr);
1705  {
1706  (*(errWtVecPtr))[indexIVars[k]] = N_UTL_MachineDependentParams::MachineBig();
1707  (*(qErrWtVecPtr))[indexIVars[k]] = N_UTL_MachineDependentParams::MachineBig();
1708  }
1709  else
1710  {
1711  (*(errWtVecPtr))[indexIVars[k]] = (*(errWtVecPtr))[indexIVars[k]] + (*(absErrTolPtr))[indexIVars[k]];
1712  (*(qErrWtVecPtr))[indexIVars[k]] = (*(qErrWtVecPtr))[indexIVars[k]] + (*(absErrTolPtr))[indexIVars[k]];
1713  }
1714  }
1715 
1716  // Masked variables
1717  for (int k = 0; k < numMaskedVars; ++k)
1718  {
1719  (*(errWtVecPtr))[indexMaskedVars[k]] = (*(qErrWtVecPtr))[indexMaskedVars[k]] = N_UTL_MachineDependentParams::MachineBig();
1720  }
1721  }
1722  else
1723  {
1724  // Voltage variables
1725  for (int k = 0; k < numVVars; ++k)
1726  {
1727 // errWtVecPtr->putScalar(currMaxValue);
1728  (*(errWtVecPtr))[indexVVars[k]] = (*(relErrTolPtr))[indexVVars[k]] * (*(errWtVecPtr))[indexVVars[k]] + (*(absErrTolPtr))[indexVVars[k]];
1730  }
1731 
1732  // Current variables
1733  // if fastTests == false, then I vars are treated with V vars above.
1734 
1735  // Masked variables
1736  for (int k = 0; k < numMaskedVars; ++k)
1737  {
1738  (*(errWtVecPtr))[indexMaskedVars[k]] = (*(qErrWtVecPtr))[indexMaskedVars[k]] = N_UTL_MachineDependentParams::MachineBig();
1739  }
1740 
1741  }
1742 
1743 #ifdef Xyce_DEBUG_TIME
1744  for (int k = 0; k < solutionSize; ++k)
1745  {
1746  if (tiaParamsPtr_->debugLevel > 1)
1747  {
1748  sprintf(tmp,"%16.6e%16.6e%16.6e%16.6e",
1749  (*(errWtVecPtr)) [k],
1750  (*(currSolutionPtr)) [k],
1751  (*(relErrTolPtr)) [k],
1752  (*(absErrTolPtr)) [k]);
1753 
1754  Xyce::dout() << tmp << std::endl;
1755  }
1756  }
1757 #endif
1758 
1759 #ifdef Xyce_DEBUG_TIME
1760  if (tiaParamsPtr_->debugLevel > 1)
1761  {
1762  Xyce::dout() << "" << std::endl
1763  << Xyce::section_divider << std::endl;
1764  }
1765 #endif
1766  return;
1767 }
1768 
1769 //-----------------------------------------------------------------------------
1770 // Function : N_TIA_DataStore::WRMS_errorNorm
1771 // Purpose :
1772 // Special Notes :
1773 // Scope : public
1774 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1775 // Creation Date : 5/25/05
1776 //-----------------------------------------------------------------------------
1778 {
1779  double errorNorm = 0.0, qErrorNorm = 0.0;
1780  newtonCorrectionPtr->wRMSNorm(*errWtVecPtr, &errorNorm);
1781  qNewtonCorrectionPtr->wRMSNorm(*qErrWtVecPtr, &qErrorNorm);
1782 
1783 #ifdef Xyce_DEBUG_TIME
1784  if (tiaParamsPtr_->debugLevel > 1)
1785  {
1786  Xyce::dout() << "N_TIA_DataStore::errorNorm = " << errorNorm << std::endl;
1787  Xyce::dout() << "N_TIA_DataStore::qErrorNorm = " << qErrorNorm << std::endl;
1788  }
1789 #endif
1790 
1791  // This is for handling the total errorNorm for 2-level solves.
1792  //
1793  // Note: This version of the function assumes that the error norm
1794  // and q-error norm are the same size. (they have to be...)
1795  if ( !(innerErrorInfoVec.empty()) )
1796  {
1797  double upperSize = newtonCorrectionPtr->globalLength();
1798  int sumSize = innerErrorInfoVec.size();
1799 
1800  double totalSize = upperSize;
1801  double totalSum = errorNorm*errorNorm*upperSize;
1802  double totalQSum = qErrorNorm*qErrorNorm*upperSize;
1803 
1804  for (int i=0;i<sumSize;++i)
1805  {
1806  double innerSum = innerErrorInfoVec[i].xErrorSum;
1807  double innerQSum = innerErrorInfoVec[i].qErrorSum;
1808  double innerSize = innerErrorInfoVec[i].innerSize;
1809 
1810 #ifdef Xyce_DEBUG_TIME
1811  Xyce::dout() << "DSdae:innerSum["<<i<<"] = " << innerSum <<std::endl;
1812  Xyce::dout() << "DSdae:innerQSum["<<i<<"] = " << innerQSum <<std::endl;
1813  Xyce::dout() << "DSdae:innerSize["<<i<<"] = " << innerSize <<std::endl;
1814 #endif
1815 
1816  totalSize += innerSize;
1817  totalSum += innerSum;
1818  totalQSum += innerQSum;
1819  }
1820 
1821  double recip = 1.0/totalSize;
1822  errorNorm = sqrt(recip*totalSum);
1823  qErrorNorm = sqrt(recip*totalQSum);
1824 
1825 #ifdef Xyce_DEBUG_TIME
1826  Xyce::dout() << "DSdae:upperSize = " << upperSize << std::endl;
1827  Xyce::dout() << "DSdae:totalSum = " << totalSum << std::endl;
1828  Xyce::dout() << "DSdae:totalQSum = " << totalQSum << std::endl;
1829  Xyce::dout() << "DSdae:totalSize = " << totalSize << std::endl;
1830  Xyce::dout() << "DSdae:2-level errorNorm = " << errorNorm << std::endl;
1831  Xyce::dout() << "DSdae:2-level qErrorNorm = " << qErrorNorm << std::endl;
1832 #endif
1833  }
1834 
1835 #ifndef Xyce_USE_Q_NORM
1836  //errorNorm = errorNorm;
1837 #else
1838  errorNorm = sqrt(0.5*errorNorm*errorNorm+0.5*qErrorNorm*qErrorNorm);
1839 #endif
1840  return errorNorm;
1841 }
1842 
1843 //-----------------------------------------------------------------------------
1844 // Function : N_TIA_DataStore::partialQErrorNormSum
1845 // Purpose : Needed by 2-level solves. This is the Q-vector version
1846 // of this function.
1847 //
1848 // Special Notes : A weighted RMS norm is this:
1849 //
1850 // norm = sqrt ( 1/n * sum (x/w)^2 )
1851 //
1852 // What this function returns is: sum (x/w)^2
1853 //
1854 // It will later be summed with other patial sums
1855 // to get the complete WRMS value.
1856 //
1857 // Scope : public
1858 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1859 // Creation Date : 03/15/06
1860 //-----------------------------------------------------------------------------
1862 {
1863  double qErrorNorm = 0.0;
1864  qNewtonCorrectionPtr->wRMSNorm(*qErrWtVecPtr, &qErrorNorm);
1865  double sum = qErrorNorm*qErrorNorm;
1866  double length = qNewtonCorrectionPtr->globalLength();
1867  sum *= length;
1868 
1869  return sum;
1870 }
1871 
1872 //-----------------------------------------------------------------------------
1873 // Function : N_TIA_DataStore::partialSum_m1
1874 // Purpose : Needed by 2-level solves.
1875 //
1876 // Special Notes : A weighted RMS norm is this:
1877 //
1878 // norm = sqrt ( 1/n * sum (x/w)^2 )
1879 //
1880 // What this function returns is: sum (x/w)^2
1881 //
1882 // It will later be summed with other patial sums
1883 // to get the complete WRMS value.
1884 //
1885 // Scope : public
1886 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1887 // Creation Date : 03/15/07
1888 //-----------------------------------------------------------------------------
1889 double N_TIA_DataStore::partialSum_m1 (int currentOrder)
1890 {
1891  double sum = 0.0;
1892 
1893  if (currentOrder>1)
1894  {
1895  delta_x->linearCombo(1.0,*(xHistory[currentOrder]),1.0,*newtonCorrectionPtr);
1896  double norm = 0.0;
1897  delta_x->wRMSNorm(*errWtVecPtr, &norm);
1898  sum = norm*norm;
1899  double length = newtonCorrectionPtr->globalLength();
1900  sum *= length;
1901  }
1902 
1903  return sum;
1904 }
1905 
1906 //-----------------------------------------------------------------------------
1907 // Function : N_TIA_DataStore::partialSum_m2
1908 // Purpose : Needed by 2-level solves.
1909 //
1910 // Special Notes : A weighted RMS norm is this:
1911 //
1912 // norm = sqrt ( 1/n * sum (x/w)^2 )
1913 //
1914 // What this function returns is: sum (x/w)^2
1915 //
1916 // It will later be summed with other patial sums
1917 // to get the complete WRMS value.
1918 //
1919 // Scope : public
1920 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1921 // Creation Date : 03/15/07
1922 //-----------------------------------------------------------------------------
1923 double N_TIA_DataStore::partialSum_m2 (int currentOrder)
1924 {
1925  double sum = 0.0;
1926 
1927  if (currentOrder>2)
1928  {
1929  delta_x->linearCombo(1.0,*(xHistory[currentOrder]),1.0,*newtonCorrectionPtr);
1930  delta_x->linearCombo(1.0,*(xHistory[currentOrder-1]),1.0,*delta_x);
1931  double norm = 0.0;
1932  delta_x->wRMSNorm(*errWtVecPtr, &norm);
1933  sum = norm*norm;
1934  double length = newtonCorrectionPtr->globalLength();
1935  sum *= length;
1936  }
1937 
1938  return sum;
1939 }
1940 
1941 //-----------------------------------------------------------------------------
1942 // Function : N_TIA_DataStore::partialSum_p1
1943 // Purpose : Needed by 2-level solves.
1944 //
1945 // Special Notes : A weighted RMS norm is this:
1946 //
1947 // norm = sqrt ( 1/n * sum (x/w)^2 )
1948 //
1949 // What this function returns is: sum (x/w)^2
1950 //
1951 // It will later be summed with other patial sums
1952 // to get the complete WRMS value.
1953 //
1954 // Scope : public
1955 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1956 // Creation Date : 03/15/07
1957 //-----------------------------------------------------------------------------
1958 double N_TIA_DataStore::partialSum_p1 (int currentOrder, int maxOrder)
1959 {
1960  double sum = 0.0;
1961 
1962  if (currentOrder<maxOrder)
1963  {
1964  delta_x->linearCombo(1.0,*newtonCorrectionPtr,-1.0,*(xHistory[currentOrder+1]));
1965  double norm = 0.0;
1966  delta_x->wRMSNorm(*errWtVecPtr, &norm);
1967  sum = norm*norm;
1968  double length = newtonCorrectionPtr->globalLength();
1969  sum *= length;
1970  }
1971 
1972  return sum;
1973 }
1974 
1975 //-----------------------------------------------------------------------------
1976 // Function : N_TIA_DataStore::partialSum_q1
1977 // Purpose : Needed by 2-level solves.
1978 //
1979 // Special Notes : A weighted RMS norm is this:
1980 //
1981 // norm = sqrt ( 1/n * sum (x/w)^2 )
1982 //
1983 // What this function returns is: sum (x/w)^2
1984 //
1985 // It will later be summed with other patial sums
1986 // to get the complete WRMS value.
1987 //
1988 // Scope : public
1989 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1990 // Creation Date : 03/15/07
1991 //-----------------------------------------------------------------------------
1993 {
1994  double sum = 0.0;
1995 
1996  double norm = 0.0;
1997  (qHistory[1])->wRMSNorm(*qErrWtVecPtr, &norm);
1998 
1999  sum = norm*norm;
2000  double length = qNewtonCorrectionPtr->globalLength();
2001  sum *= length;
2002 
2003  return sum;
2004 }
2005 
2006 //-----------------------------------------------------------------------------
2007 // Function : N_TIA_DataStore::delta_x_errorNorm_m1
2008 // Purpose :
2009 // Special Notes :
2010 // Scope : public
2011 // Creator : Eric Keiter
2012 // Creation Date : 03/15/07
2013 //-----------------------------------------------------------------------------
2015 {
2016  double errorNorm = 0.0;
2017  delta_x->wRMSNorm(*errWtVecPtr, &errorNorm);
2018 
2019  // This is for handling the total errorNorm for 2-level solves.
2020  // It really should get a separate overloaded function.
2021  if ( !(innerErrorInfoVec.empty()) )
2022  {
2023  double upperSize = newtonCorrectionPtr->globalLength();
2024  int sumSize = innerErrorInfoVec.size();
2025 
2026  double totalSize = upperSize;
2027  double totalSum = errorNorm*errorNorm*upperSize;
2028 
2029  for (int i=0;i<sumSize;++i)
2030  {
2031  double innerSum = innerErrorInfoVec[i].xErrorSum_m1;
2032  double innerSize = innerErrorInfoVec[i].innerSize;
2033 
2034  totalSize += innerSize;
2035  totalSum += innerSum;
2036  }
2037 
2038  double recip = 1.0/totalSize;
2039  errorNorm = sqrt(recip*totalSum);
2040  }
2041 
2042  return errorNorm;
2043 }
2044 
2045 //-----------------------------------------------------------------------------
2046 // Function : N_TIA_DataStore::delta_x_errorNorm_m2
2047 // Purpose :
2048 // Special Notes :
2049 // Scope : public
2050 // Creator : Eric Keiter
2051 // Creation Date : 03/15/07
2052 //-----------------------------------------------------------------------------
2054 {
2055  double errorNorm = 0.0;
2056  delta_x->wRMSNorm(*errWtVecPtr, &errorNorm);
2057 
2058  // This is for handling the total errorNorm for 2-level solves.
2059  // It really should get a separate overloaded function.
2060  if ( !(innerErrorInfoVec.empty()) )
2061  {
2062  double upperSize = newtonCorrectionPtr->globalLength();
2063  int sumSize = innerErrorInfoVec.size();
2064 
2065  double totalSize = upperSize;
2066  double totalSum = errorNorm*errorNorm*upperSize;
2067 
2068  for (int i=0;i<sumSize;++i)
2069  {
2070  double innerSum = innerErrorInfoVec[i].xErrorSum_m2;
2071  double innerSize = innerErrorInfoVec[i].innerSize;
2072 
2073  totalSize += innerSize;
2074  totalSum += innerSum;
2075  }
2076 
2077  double recip = 1.0/totalSize;
2078  errorNorm = sqrt(recip*totalSum);
2079  }
2080 
2081  return errorNorm;
2082 }
2083 
2084 //-----------------------------------------------------------------------------
2085 // Function : N_TIA_DataStore::delta_x_errorNorm_p1
2086 // Purpose :
2087 // Special Notes :
2088 // Scope : public
2089 // Creator : Eric Keiter
2090 // Creation Date : 03/15/07
2091 //-----------------------------------------------------------------------------
2093 {
2094  double errorNorm = 0.0;
2095  delta_x->wRMSNorm(*errWtVecPtr, &errorNorm);
2096 
2097  // This is for handling the total errorNorm for 2-level solves.
2098  // It really should get a separate overloaded function.
2099  if ( !(innerErrorInfoVec.empty()) )
2100  {
2101  double upperSize = newtonCorrectionPtr->globalLength();
2102  int sumSize = innerErrorInfoVec.size();
2103 
2104  double totalSize = upperSize;
2105  double totalSum = errorNorm*errorNorm*upperSize;
2106 
2107  for (int i=0;i<sumSize;++i)
2108  {
2109  double innerSum = innerErrorInfoVec[i].xErrorSum_p1;
2110  double innerSize = innerErrorInfoVec[i].innerSize;
2111 
2112  totalSize += innerSize;
2113  totalSum += innerSum;
2114  }
2115 
2116  double recip = 1.0/totalSize;
2117  errorNorm = sqrt(recip*totalSum);
2118  }
2119 
2120  return errorNorm;
2121 }
2122 
2123 //-----------------------------------------------------------------------------
2124 // Function : N_TIA_DataStore::delta_x_errorNorm_q1
2125 // Purpose :
2126 // Special Notes :
2127 // Scope : public
2128 // Creator : Eric Keiter
2129 // Creation Date : 03/15/07
2130 //-----------------------------------------------------------------------------
2132 {
2133  double errorNorm = 0.0;
2134  (qHistory[1])->wRMSNorm(*qErrWtVecPtr, &errorNorm);
2135 
2136  // This is for handling the total errorNorm for 2-level solves.
2137  // It really should get a separate overloaded function.
2138  if ( !(innerErrorInfoVec.empty()) )
2139  {
2140  double upperSize = newtonCorrectionPtr->globalLength();
2141  int sumSize = innerErrorInfoVec.size();
2142 
2143  double totalSize = upperSize;
2144  double totalSum = errorNorm*errorNorm*upperSize;
2145 
2146  for (int i=0;i<sumSize;++i)
2147  {
2148  double innerSum = innerErrorInfoVec[i].q1HistorySum;
2149  double innerSize = innerErrorInfoVec[i].innerSize;
2150 
2151  totalSize += innerSize;
2152  totalSum += innerSum;
2153  }
2154 
2155  double recip = 1.0/totalSize;
2156  errorNorm = sqrt(recip*totalSum);
2157  }
2158 
2159  return errorNorm;
2160 }
2161 
2162 //-----------------------------------------------------------------------------
2163 // Function : N_TIA_DataStore::stepLinearCombo
2164 // Purpose : setup the newtonCorrection vectors.
2165 // Special Notes :
2166 // Scope : public
2167 // Creator : Eric Keiter
2168 // Creation Date : 02/20/07
2169 //-----------------------------------------------------------------------------
2171 {
2172  // 03/16/04 tscoffe: update the newton correction. Note: this should be
2173  // available from NOX, but for now I'm going to do the difference anyway.
2174  newtonCorrectionPtr->linearCombo (1.0,*nextSolutionPtr,-1.0,*xn0Ptr);
2175 
2176  // We need to compute the correction in Q here
2177  // I'm assuming dsDaePtr_->daeQVectorPtr will be fresh from the end of the
2178  // nonlinear solve.
2179  qNewtonCorrectionPtr->linearCombo (1.0,*daeQVectorPtr,-1.0,*qn0Ptr);
2180 
2181  // We also need a State correction between the time steps
2182  sNewtonCorrectionPtr->linearCombo (1.0,*nextStatePtr,-1.0,*sn0Ptr);
2183 
2184  // We also need a Store correction between the time steps
2185  stoNewtonCorrectionPtr->linearCombo (1.0,*nextStorePtr,-1.0,*ston0Ptr);
2187 
2188  // correction on sensitivities:
2189  for (int ip=0;ip<dfdpNewtonCorrectionPtrVector.size();++ip)
2190  {
2191  (dfdpNewtonCorrectionPtrVector[ip])->linearCombo (1.0,*(nextDfdpPtrVector[ip]),-1.0,*(dfdpn0PtrVector[ip]));
2192  (dqdpNewtonCorrectionPtrVector[ip])->linearCombo (1.0,*(nextDqdpPtrVector[ip]),-1.0,*(dqdpn0PtrVector[ip]));
2193  (dbdpNewtonCorrectionPtrVector[ip])->linearCombo (1.0,*(nextDbdpPtrVector[ip]),-1.0,*(dbdpn0PtrVector[ip]));
2194  (dXdpNewtonCorrectionPtrVector[ip])->linearCombo (1.0,*(nextDXdpPtrVector[ip]),-1.0,*(dXdpn0PtrVector[ip]));
2195  }
2196 
2197 #ifdef Xyce_DEBUG_TIME
2198  if (tiaParamsPtr_->debugLevel > 1)
2199  {
2200  Xyce::dout() << "\n newtonCorrection: \n" << std::endl;
2201  newtonCorrectionPtr->printPetraObject(Xyce::dout());
2202  Xyce::dout() << std::endl;
2203  Xyce::dout() << "\n qNewtonCorrection: \n" << std::endl;
2204  qNewtonCorrectionPtr->printPetraObject(Xyce::dout());
2205  Xyce::dout() << "\n sNewtonCorrection: \n" << std::endl;
2206  sNewtonCorrectionPtr->printPetraObject(Xyce::dout());
2207  Xyce::dout() << std::endl;
2208  }
2209 #endif // Xyce_DEBUG_TIME
2210 
2211  return;
2212 }
2213 
2214 //-----------------------------------------------------------------------------
2215 // Function : N_TIA_DataStore::getSolnVarData
2216 // Purpose :
2217 // Special Notes :
2218 // Scope : public
2219 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
2220 // Creation Date : 7/27/06
2221 //-----------------------------------------------------------------------------
2222 bool N_TIA_DataStore::getSolnVarData( const int & gid,
2223  std::vector<double> & varData )
2224 {
2225  varData.resize(23);
2226  int i=0;
2227  varData[i++] = tmpSolVectorPtr->getElementByGlobalIndex( gid );
2228  varData[i++] = currSolutionPtr->getElementByGlobalIndex( gid );
2229  varData[i++] = lastSolutionPtr->getElementByGlobalIndex( gid );
2230  varData[i++] = nextSolutionPtr->getElementByGlobalIndex( gid );
2231  varData[i++] = currSolutionDerivPtr->getElementByGlobalIndex( gid );
2232  varData[i++] = lastSolutionDerivPtr->getElementByGlobalIndex( gid );
2233  varData[i++] = nextSolutionDerivPtr->getElementByGlobalIndex( gid );
2234  varData[i++] = currSolutionDivDiffPtr->getElementByGlobalIndex( gid );
2235  varData[i++] = lastSolutionDivDiffPtr->getElementByGlobalIndex( gid );
2236  varData[i++] = nextSolutionDivDiffPtr->getElementByGlobalIndex( gid );
2237  varData[i++] = errWtVecPtr->getElementByGlobalIndex( gid );
2238  varData[i++] = absErrTolPtr->getElementByGlobalIndex( gid );
2239  varData[i++] = relErrTolPtr->getElementByGlobalIndex( gid );
2240  varData[i++] = newtonCorrectionPtr->getElementByGlobalIndex( gid );
2241  varData[i++] = qErrWtVecPtr->getElementByGlobalIndex ( gid );
2242  varData[i++] = daeQVectorPtr->getElementByGlobalIndex ( gid );
2243  varData[i++] = daeFVectorPtr->getElementByGlobalIndex ( gid );
2244  varData[i++] = daeBVectorPtr->getElementByGlobalIndex ( gid );
2245  varData[i++] = xn0Ptr->getElementByGlobalIndex ( gid );
2246  varData[i++] = qn0Ptr->getElementByGlobalIndex ( gid );
2247  varData[i++] = qpn0Ptr->getElementByGlobalIndex ( gid );
2248  varData[i++] = dFdxdVpVectorPtr->getElementByGlobalIndex ( gid );
2249  varData[i++] = dQdxdVpVectorPtr->getElementByGlobalIndex ( gid );
2250  return true;
2251 }
2252 
2253 //-----------------------------------------------------------------------------
2254 // Function : N_TIA_DataStore::getStateVarData
2255 // Purpose :
2256 // Special Notes :
2257 // Scope : public
2258 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
2259 // Creation Date : 7/27/06
2260 //-----------------------------------------------------------------------------
2261 bool N_TIA_DataStore::getStateVarData( const int & gid,
2262  std::vector<double> & varData )
2263 {
2264  int i=0;
2265  varData.resize( 14 );
2266  varData[i++] = tmpStaVectorPtr->getElementByGlobalIndex( gid );
2267  varData[i++] = tmpStaDerivPtr->getElementByGlobalIndex( gid );
2268  varData[i++] = tmpStaDivDiffPtr->getElementByGlobalIndex( gid );
2269  varData[i++] = currStatePtr->getElementByGlobalIndex( gid );
2270  varData[i++] = lastStatePtr->getElementByGlobalIndex( gid );
2271  varData[i++] = nextStatePtr->getElementByGlobalIndex( gid );
2272  varData[i++] = currStateDerivPtr->getElementByGlobalIndex( gid );
2273  varData[i++] = lastStateDerivPtr->getElementByGlobalIndex( gid );
2274  varData[i++] = nextStateDerivPtr->getElementByGlobalIndex( gid );
2275  varData[i++] = currStateDivDiffPtr->getElementByGlobalIndex( gid );
2276  varData[i++] = lastStateDivDiffPtr->getElementByGlobalIndex( gid );
2277  varData[i++] = nextStateDivDiffPtr->getElementByGlobalIndex( gid );
2278  varData[i++] = sn0Ptr->getElementByGlobalIndex( gid );
2279  varData[i++] = spn0Ptr->getElementByGlobalIndex( gid );
2280  return true;
2281 }
2282 
2283 
2284 //-----------------------------------------------------------------------------
2285 // Function : N_TIA_DataStore::getStoreVarData
2286 // Purpose :
2287 // Special Notes :
2288 // Scope : public
2289 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
2290 // Creation Date :
2291 //-----------------------------------------------------------------------------
2292 bool N_TIA_DataStore::getStoreVarData( const int & gid,
2293  std::vector<double> & varData )
2294 {
2295  int i=0;
2296  varData.resize( 6 );
2297  varData[i++] = tmpStoVectorPtr->getElementByGlobalIndex( gid );
2298  varData[i++] = currStorePtr->getElementByGlobalIndex( gid );
2299  varData[i++] = lastStorePtr->getElementByGlobalIndex( gid );
2300  varData[i++] = nextStorePtr->getElementByGlobalIndex( gid );
2301  varData[i++] = ston0Ptr->getElementByGlobalIndex( gid );
2302  varData[i++] = stopn0Ptr->getElementByGlobalIndex( gid );
2303  return true;
2304 }
2305 
2306 //-----------------------------------------------------------------------------
2307 // Function : N_TIA_DataStore::setSolnVarData
2308 // Purpose :
2309 // Special Notes :
2310 // Scope : public
2311 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
2312 // Creation Date : 7/27/06
2313 //-----------------------------------------------------------------------------
2314 bool N_TIA_DataStore::setSolnVarData( const int & gid,
2315  const std::vector<double> & varData )
2316 {
2317  int i=0;
2318  tmpSolVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2319  currSolutionPtr->setElementByGlobalIndex ( gid, varData[i++] );
2320  lastSolutionPtr->setElementByGlobalIndex ( gid, varData[i++] );
2321  nextSolutionPtr->setElementByGlobalIndex ( gid, varData[i++] );
2322  currSolutionDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2323  lastSolutionDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2324  nextSolutionDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2325  currSolutionDivDiffPtr->setElementByGlobalIndex( gid, varData[i++] );
2326  lastSolutionDivDiffPtr->setElementByGlobalIndex( gid, varData[i++] );
2327  nextSolutionDivDiffPtr->setElementByGlobalIndex( gid, varData[i++] );
2328  errWtVecPtr->setElementByGlobalIndex ( gid, varData[i++] );
2329  absErrTolPtr->setElementByGlobalIndex ( gid, varData[i++] );
2330  relErrTolPtr->setElementByGlobalIndex ( gid, varData[i++] );
2331  newtonCorrectionPtr->setElementByGlobalIndex ( gid, varData[i++] );
2332  qErrWtVecPtr->setElementByGlobalIndex ( gid, varData[i++] );
2333  daeQVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2334  daeFVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2335  daeBVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2336  xn0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2337  qn0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2338  qpn0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2339  dFdxdVpVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2340  dQdxdVpVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2341  return true;
2342 }
2343 
2344 //-----------------------------------------------------------------------------
2345 // Function : N_TIA_DataStore::setStateVarData
2346 // Purpose :
2347 // Special Notes :
2348 // Scope : public
2349 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
2350 // Creation Date : 7/27/06
2351 //-----------------------------------------------------------------------------
2352 bool N_TIA_DataStore::setStateVarData( const int & gid,
2353  const std::vector<double> & varData )
2354 {
2355  int i=0;
2356  tmpStaVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2357  tmpStaDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2358  tmpStaDivDiffPtr->setElementByGlobalIndex ( gid, varData[i++] );
2359  currStatePtr->setElementByGlobalIndex ( gid, varData[i++] );
2360  lastStatePtr->setElementByGlobalIndex ( gid, varData[i++] );
2361  nextStatePtr->setElementByGlobalIndex ( gid, varData[i++] );
2362  currStateDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2363  lastStateDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2364  nextStateDerivPtr->setElementByGlobalIndex ( gid, varData[i++] );
2365  currStateDivDiffPtr->setElementByGlobalIndex( gid, varData[i++] );
2366  lastStateDivDiffPtr->setElementByGlobalIndex( gid, varData[i++] );
2367  nextStateDivDiffPtr->setElementByGlobalIndex( gid, varData[i++] );
2368 
2369  sn0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2370  spn0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2371  return true;
2372 }
2373 
2374 //-----------------------------------------------------------------------------
2375 // Function : N_TIA_DataStore::setStoreVarData
2376 // Purpose :
2377 // Special Notes :
2378 // Scope : public
2379 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
2380 // Creation Date : 7/27/06
2381 //-----------------------------------------------------------------------------
2382 bool N_TIA_DataStore::setStoreVarData( const int & gid,
2383  const std::vector<double> & varData )
2384 {
2385  int i=0;
2386  tmpStoVectorPtr->setElementByGlobalIndex ( gid, varData[i++] );
2387  currStorePtr->setElementByGlobalIndex ( gid, varData[i++] );
2388  lastStorePtr->setElementByGlobalIndex ( gid, varData[i++] );
2389  nextStorePtr->setElementByGlobalIndex ( gid, varData[i++] );
2390  ston0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2391  stopn0Ptr->setElementByGlobalIndex ( gid, varData[i++] );
2392  return true;
2393 }
2394