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