Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_TIA_DataStore.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2014 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_TIA_DataStore.h,v $
27 //
28 // Purpose : This file handles the class that defines the data arrays
29 // needed for 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.90.2.4 $
41 //
42 // Revision Date : $Date: 2014/09/02 22:49:49 $
43 //
44 // Current Owner : $Author: erkeite $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_TIA_DATA_STORE_H
48 #define Xyce_N_TIA_DATA_STORE_H
49 
50 // ---------- Standard Includes ----------
51 
52 #include <list>
53 #include <vector>
54 
55 // ---------- Xyce Includes ----------
56 #include <N_UTL_Misc.h>
57 #include <N_LAS_fwd.h>
58 #include <N_TIA_fwd.h>
59 #include <N_TIA_TwoLevelError.h>
60 
61 //-----------------------------------------------------------------------------
62 // Class : N_TIA_DataStore
63 // Purpose : This is the class for defining data arrays needed in the
64 // time integration algorithms.
65 // Special Notes :
66 // Creator : Buddy Watts, SNL
67 // Creation Date : 6/01/00
68 //-----------------------------------------------------------------------------
70 {
71  public:
72  N_TIA_DataStore(N_TIA_TIAParams * tiaPtr, N_LAS_System * lsPtr);
74 
75  void allocateSensitivityArrays(int numParams);
77 
78  private:
79  N_TIA_DataStore(const N_TIA_DataStore& rhs);
82 
83  public:
84  // TIA Arrays (pointers) for Integration Solution Process:
85  unsigned int solutionSize;
86  unsigned int stateSize;
87 
88  // temporary vectors:
89  N_LAS_Vector * tmpSolVectorPtr;
90  N_LAS_Vector * tmpStaVectorPtr;
91  N_LAS_Vector * tmpStaDerivPtr;
92  N_LAS_Vector * tmpStaDivDiffPtr;
93 
94  N_LAS_Vector * tmpStoVectorPtr;
95 
96  // Predictors
97  N_LAS_Vector * xn0Ptr;
98 
99  // Solutions:
100  N_LAS_Vector * currSolutionPtr;
101  N_LAS_Vector * lastSolutionPtr;
102  N_LAS_Vector * oldeSolutionPtr;
103  N_LAS_Vector * nextSolutionPtr;
104  N_LAS_Vector * flagSolutionPtr;
105 
106  N_LAS_Vector * savedNextSolutionPtr;
107 
108  // States:
109  N_LAS_Vector * currStatePtr;
110  N_LAS_Vector * lastStatePtr;
111  N_LAS_Vector * oldeStatePtr;
112  N_LAS_Vector * nextStatePtr;
113 
114  // Storage:
115  N_LAS_Vector * currStorePtr;
116  N_LAS_Vector * lastStorePtr;
117  N_LAS_Vector * oldeStorePtr;
118  N_LAS_Vector * nextStorePtr;
119  // for lead current calculations. F component is
120  // held in the store vector, Q component is here
121  N_LAS_Vector * currStoreLeadCurrQPtr;
122  N_LAS_Vector * lastStoreLeadCurrQPtr;
123  N_LAS_Vector * oldeStoreLeadCurrQPtr;
124  N_LAS_Vector * nextStoreLeadCurrQPtr;
125 
126  // sensitivity vectors:
127  std::vector<N_LAS_Vector*> sensRHSPtrVector;
128 
129  std::vector<N_LAS_Vector*> currDfdpPtrVector;
130  std::vector<N_LAS_Vector*> lastDfdpPtrVector;
131  std::vector<N_LAS_Vector*> oldeDfdpPtrVector;
132  std::vector<N_LAS_Vector*> nextDfdpPtrVector;
133 
134  std::vector<N_LAS_Vector*> currDqdpPtrVector;
135  std::vector<N_LAS_Vector*> lastDqdpPtrVector;
136  std::vector<N_LAS_Vector*> oldeDqdpPtrVector;
137  std::vector<N_LAS_Vector*> nextDqdpPtrVector;
138 
139  std::vector<N_LAS_Vector*> currDbdpPtrVector;
140  std::vector<N_LAS_Vector*> lastDbdpPtrVector;
141  std::vector<N_LAS_Vector*> oldeDbdpPtrVector;
142  std::vector<N_LAS_Vector*> nextDbdpPtrVector;
143 
144  std::vector<N_LAS_Vector*> currDXdpPtrVector;
145  std::vector<N_LAS_Vector*> lastDXdpPtrVector;
146  std::vector<N_LAS_Vector*> oldeDXdpPtrVector;
147  std::vector<N_LAS_Vector*> nextDXdpPtrVector;
148 
149  // matvecs:
150  std::vector<N_LAS_Vector*> currDQdxDXdpPtrVector;
151  std::vector<N_LAS_Vector*> lastDQdxDXdpPtrVector;
152  std::vector<N_LAS_Vector*> oldeDQdxDXdpPtrVector;
153  std::vector<N_LAS_Vector*> nextDQdxDXdpPtrVector;
154 
155  std::vector<N_LAS_Vector*> currDQdxDXdpDerivPtrVector;
156  std::vector<N_LAS_Vector*> lastDQdxDXdpDerivPtrVector;
157  std::vector<N_LAS_Vector*> oldeDQdxDXdpDerivPtrVector;
158  std::vector<N_LAS_Vector*> nextDQdxDXdpDerivPtrVector;
159 
160  // Derivatives of Solutions:
161  N_LAS_Vector * currSolutionDerivPtr;
162  N_LAS_Vector * lastSolutionDerivPtr;
163  N_LAS_Vector * oldeSolutionDerivPtr;
164  N_LAS_Vector * nextSolutionDerivPtr;
165 
166  // Derivatives of States:
167  N_LAS_Vector * currStateDerivPtr;
168  N_LAS_Vector * lastStateDerivPtr;
169  N_LAS_Vector * oldeStateDerivPtr;
170  N_LAS_Vector * nextStateDerivPtr;
171 
172  // Derivatives of Store for lead curent calculations
177 
178  // Derivatives of dq/dp for sensitivity calculations
179  std::vector<N_LAS_Vector*> currDqdpDerivPtrVector;
180  std::vector<N_LAS_Vector*> lastDqdpDerivPtrVector;
181  std::vector<N_LAS_Vector*> oldeDqdpDerivPtrVector;
182  std::vector<N_LAS_Vector*> nextDqdpDerivPtrVector;
183 
184  // Sensitivity residual matvec term:
185  N_LAS_Vector * resMatVecPtr;
186 
187  // Scaled Divided Differences
188  N_LAS_Vector * currSolutionDivDiffPtr;
189  N_LAS_Vector * lastSolutionDivDiffPtr;
190  N_LAS_Vector * oldeSolutionDivDiffPtr;
191  N_LAS_Vector * nextSolutionDivDiffPtr;
192 
193  // Scaled Divided Differences
194  N_LAS_Vector * currStateDivDiffPtr;
195  N_LAS_Vector * lastStateDivDiffPtr;
196  N_LAS_Vector * oldeStateDivDiffPtr;
197  N_LAS_Vector * nextStateDivDiffPtr;
198 
199  // Error Vectors
200  N_LAS_Vector * errWtVecPtr;
201  N_LAS_Vector * absErrTolPtr;
202  N_LAS_Vector * relErrTolPtr;
203 
204  // Jacobian and RHS
205  N_LAS_Matrix * JMatrixPtr;
206  N_LAS_Vector * RHSVectorPtr;
207 #ifdef Xyce_DEBUG_DEVICE
208  N_LAS_Vector * JdxpVectorPtr; // only used in the device manager for debug purposes these days.
209 #endif
210 
211  // NonLinear Solution Vectors
212  N_LAS_Vector * newtonCorrectionPtr;
213 
214  // Mask for error norms (to allow some equations not to take part in
215  // weighted norms)
216  N_LAS_Vector * deviceMaskPtr;
217  // TVR: I toyed with the idea of having this flag here, but went with
218  // keeping it in the LAS_System instead --- we call an accessor method
219  // to set and get the flag when we create or use the mask.
220  // flag showing whether mask is trivial or not
221  // bool nonTrivialDeviceMask;
222 
223  // this is a simple vector indicating var types. Now
224  // we just handle V and I differently, but we could do more with this
225  std::vector<char> varTypeVec;
226 
227  // To remove conditionals from setErrorWtVector() we'll create
228  // lists of indexes of unknows that are handled in different ways
229  std::vector<int> indexVVars;
230  std::vector<int> indexIVars;
231  std::vector<int> indexMaskedVars;
234 
235  // limiter flag:
237 
238  // 2-level information:
239  std::vector<N_TIA_TwoLevelError> innerErrorInfoVec;
240 
241  // new-DAE data (originally from the new-DAE derrived class)
242  // Error Vectors
243  N_LAS_Vector * qErrWtVecPtr;
244 
245  // DAE formulation vectors
246  N_LAS_Vector * daeQVectorPtr;
247  N_LAS_Vector * daeFVectorPtr;
248  N_LAS_Vector * daeBVectorPtr;
249 
250  // voltage limiting vectors
251  N_LAS_Vector * dFdxdVpVectorPtr;
252  N_LAS_Vector * dQdxdVpVectorPtr;
253 
254  // DAE formulation matrices
255  N_LAS_Matrix * dQdxMatrixPtr;
256  N_LAS_Matrix * dFdxMatrixPtr;
257 
258  // temporary stop-gap, needed for sensitivity analysis.
259  //N_LAS_Matrix * saved_dQdxMatrixPtr;
260 
261  // HB temporary Matvec storage vectors
262  N_LAS_Vector * dQdxVecVectorPtr;
263  N_LAS_Vector * dFdxVecVectorPtr;
264 
265  // History arrays
266  std::vector<N_LAS_Vector*> xHistory;
267  std::vector<N_LAS_Vector*> qHistory;
268  std::vector<N_LAS_Vector*> sHistory; // state history
269  std::vector<N_LAS_Vector*> stoHistory; // store history
270  std::vector<N_LAS_Vector*> stoLeadCurrQHistory; // store history for lead current Q component.
271 
272  // sensitivity histories
273  std::vector< std::vector<N_LAS_Vector*> > dfdpHistory;
274  std::vector< std::vector<N_LAS_Vector*> > dqdpHistory;
275  std::vector< std::vector<N_LAS_Vector*> > dbdpHistory;
276  std::vector< std::vector<N_LAS_Vector*> > dXdpHistory;
277 
278  std::vector< std::vector<N_LAS_Vector*> > dQdxdXdpHistory;
279 
280  // Predictors
281  N_LAS_Vector * qn0Ptr;
282  N_LAS_Vector * qpn0Ptr;
283 
284  N_LAS_Vector * sn0Ptr;
285  N_LAS_Vector * spn0Ptr;
286 
287  N_LAS_Vector * ston0Ptr;
288  N_LAS_Vector * stopn0Ptr;
289 
290  N_LAS_Vector * stoQn0Ptr;
291  N_LAS_Vector * stoQpn0Ptr;
292 
293  // For sensitivities
294  std::vector<N_LAS_Vector*> dfdpn0PtrVector;
295  std::vector<N_LAS_Vector*> dqdpn0PtrVector;
296  std::vector<N_LAS_Vector*> dbdpn0PtrVector;
297  std::vector<N_LAS_Vector*> dXdpn0PtrVector;
298 
299  std::vector<N_LAS_Vector*> dfdppn0PtrVector;
300  std::vector<N_LAS_Vector*> dqdppn0PtrVector;
301  std::vector<N_LAS_Vector*> dbdppn0PtrVector;
302  std::vector<N_LAS_Vector*> dXdppn0PtrVector;
303 
304  // Nonlinear solution vector:
305  N_LAS_Vector * qNewtonCorrectionPtr;
306  N_LAS_Vector * sNewtonCorrectionPtr;
307  N_LAS_Vector * stoNewtonCorrectionPtr;
309 
310  // For sensitivities
311  std::vector<N_LAS_Vector*> dfdpNewtonCorrectionPtrVector;
312  std::vector<N_LAS_Vector*> dqdpNewtonCorrectionPtrVector;
313  std::vector<N_LAS_Vector*> dbdpNewtonCorrectionPtrVector;
314  std::vector<N_LAS_Vector*> dXdpNewtonCorrectionPtrVector;
315 
316  // Step-size selection temporary vectors
317  N_LAS_Vector * delta_x;
318  N_LAS_Vector * delta_q;
319 
320  // Temporary vectors for WaMPDE interpolation
321  N_LAS_Vector * tmpXn0APtr;
322  N_LAS_Vector * tmpXn0BPtr;
323 
324  // These are for MPDE fast time scale points
325  std::vector<double> timeSteps;
326  std::vector<bool> timeStepsBreakpointFlag;
327  std::vector<N_LAS_Vector*> fastTimeSolutionVec;
328  std::vector<N_LAS_Vector*> fastTimeStateVec;
329  std::vector<N_LAS_Vector*> fastTimeQVec;
330  std::vector<N_LAS_Vector*> fastTimeStoreVec;
331 
332  std::vector<double> objectiveVec_;
333  std::vector<double> dOdpVec_;
334  std::vector<double> dOdpAdjVec_;
335  std::vector<double> scaled_dOdpVec_;
336  std::vector<double> scaled_dOdpAdjVec_;
337  std::vector<double> paramOrigVals_;
338 
339  // DataStore Functions
340  public:
341  void initializeDataArrays();
342  void enableOrderOneStart();
343 
344  void updateSolDataArrays();
345  bool updateStateDataArrays();
346 
347  void outputSolDataArrays(std::ostream &os);
348  void setConstantHistory();
350  void setZeroHistory();
351  void setErrorWtVector();
352  double WRMS_errorNorm();
353 
354  double partialErrorNormSum();
355  double partialQErrorNormSum();
356 
357  double partialSum_m1(int currentOrder);
358  double partialSum_m2(int currentOrder);
359 
360  double globalLength ();
362 
363  void computeDivDiffsBlock(const std::list<index_pair> & solGIDList,
364  const std::list<index_pair> & staGIDList);
365 
366  void printOutPointers ();
367  bool equateTmpVectors ();
369 
370  void outputPredictedSolution(std::ostream &os);
371  void outputPredictedDerivative(std::ostream &os);
372 
373  void stepLinearCombo ();
374 
375  double partialSum_p1(int currentOrder, int maxOrder);
376  double partialSum_q1();
377 
378  double delta_x_errorNorm_m1();
379  double delta_x_errorNorm_m2();
380  double delta_x_errorNorm_p1();
381  double delta_x_errorNorm_q1();
382 
383  bool getSolnVarData( const int & gid, std::vector<double> & varData );
384  bool getStateVarData( const int & gid, std::vector<double> & varData );
385  bool setSolnVarData( const int & gid, const std::vector<double> & varData );
386  bool setStateVarData( const int & gid, const std::vector<double> & varData );
387  bool getStoreVarData( const int & gid, std::vector<double> & varData );
388  bool setStoreVarData( const int & gid, const std::vector<double> & varData );
389 
390  N_LAS_System * lasSysPtr;
391 
392  bool setNextSolVectorPtr (N_LAS_Vector * solVecPtr);
393  bool unsetNextSolVectorPtr ();
394 
395  bool resetAll ();
396  bool resetFastTimeData ();
397 
398  protected:
400  double * dataBlockPtr;
402 };
403 
404 #endif // Xyce_N_TIA_DATA_STORE_H
405