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.84 $
41 //
42 // Revision Date : $Date: 2014/02/24 23:49:26 $
43 //
44 // Current Owner : $Author: tvrusso $
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 
54 // ---------- Xyce Includes ----------
55 #include <N_TIA_TIAParams.h>
56 #include <N_TIA_TwoLevelError.h>
57 
58 class N_LAS_MultiVector;
59 class N_LAS_Vector;
60 class N_LAS_Matrix;
61 class N_LAS_System;
62 
63 //-----------------------------------------------------------------------------
64 // Class : N_TIA_DataStore
65 // Purpose : This is the class for defining data arrays needed in the
66 // time integration algorithms.
67 // Special Notes :
68 // Creator : Buddy Watts, SNL
69 // Creation Date : 6/01/00
70 //-----------------------------------------------------------------------------
72 {
73  public:
74  N_TIA_DataStore(N_TIA_TIAParams * tiaPtr, N_LAS_System * lsPtr);
75  N_TIA_DataStore(const N_TIA_DataStore& rhs);
76  virtual ~N_TIA_DataStore();
77 
78  // TIA Arrays (pointers) for Integration Solution Process:
79  unsigned int solutionSize;
80  unsigned int stateSize;
81 
82  // temporary vectors:
83  N_LAS_Vector * tmpSolVectorPtr;
84  N_LAS_Vector * tmpStaVectorPtr;
85  N_LAS_Vector * tmpStaDerivPtr;
86  N_LAS_Vector * tmpStaDivDiffPtr;
87 
88  N_LAS_Vector * tmpStoVectorPtr;
89 
90  // Predictors
91  N_LAS_Vector * xn0Ptr;
92 
93  // Solutions:
94  N_LAS_Vector * currSolutionPtr;
95  N_LAS_Vector * lastSolutionPtr;
96  N_LAS_Vector * oldeSolutionPtr;
97  N_LAS_Vector * nextSolutionPtr;
98  N_LAS_Vector * flagSolutionPtr;
99 
100  N_LAS_Vector * savedNextSolutionPtr;
101 
102  // States:
103  N_LAS_Vector * currStatePtr;
104  N_LAS_Vector * lastStatePtr;
105  N_LAS_Vector * oldeStatePtr;
106  N_LAS_Vector * nextStatePtr;
107 
108  // Storage:
109  N_LAS_Vector * currStorePtr;
110  N_LAS_Vector * lastStorePtr;
111  N_LAS_Vector * oldeStorePtr;
112  N_LAS_Vector * nextStorePtr;
113  // for lead current calculations. F component is
114  // held in the store vector, Q component is here
117  N_LAS_Vector * oldStoreLeadCurrQCompPtr;
119 
120  // Derivatives of Solutions:
121  N_LAS_Vector * currSolutionDerivPtr;
122  N_LAS_Vector * lastSolutionDerivPtr;
123  N_LAS_Vector * oldeSolutionDerivPtr;
124  N_LAS_Vector * nextSolutionDerivPtr;
125 
126  // Derivatives of States:
127  N_LAS_Vector * currStateDerivPtr;
128  N_LAS_Vector * lastStateDerivPtr;
129  N_LAS_Vector * oldeStateDerivPtr;
130  N_LAS_Vector * nextStateDerivPtr;
131 
132  // Derivatives of Store for lead curent calculations
137 
138  // Scaled Divided Differences
139  N_LAS_Vector * currSolutionDivDiffPtr;
140  N_LAS_Vector * lastSolutionDivDiffPtr;
141  N_LAS_Vector * oldeSolutionDivDiffPtr;
142  N_LAS_Vector * nextSolutionDivDiffPtr;
143 
144  // Scaled Divided Differences
145  N_LAS_Vector * currStateDivDiffPtr;
146  N_LAS_Vector * lastStateDivDiffPtr;
147  N_LAS_Vector * oldeStateDivDiffPtr;
148  N_LAS_Vector * nextStateDivDiffPtr;
149 
150  // Error Vectors
151  N_LAS_Vector * errWtVecPtr;
152  N_LAS_Vector * absErrTolPtr;
153  N_LAS_Vector * relErrTolPtr;
154 
155  // Jacobian and RHS
156  N_LAS_Matrix * JMatrixPtr;
157  N_LAS_Vector * RHSVectorPtr;
158 #ifdef Xyce_DEBUG_DEVICE
159  N_LAS_Vector * JdxpVectorPtr; // only used in the device manager for debug purposes these days.
160 #endif
161 
162  // NonLinear Solution Vectors
163  N_LAS_Vector * newtonCorrectionPtr;
164 
165  // Mask for error norms (to allow some equations not to take part in
166  // weighted norms)
167  N_LAS_Vector * deviceMaskPtr;
168  // TVR: I toyed with the idea of having this flag here, but went with
169  // keeping it in the LAS_System instead --- we call an accessor method
170  // to set and get the flag when we create or use the mask.
171  // flag showing whether mask is trivial or not
172  // bool nonTrivialDeviceMask;
173 
174  // this is a simple vector indicating var types. Now
175  // we just handle V and I differently, but we could do more with this
176  std::vector<char> varTypeVec;
177 
178  // To remove conditionals from setErrorWtVector() we'll create
179  // lists of indexes of unknows that are handled in different ways
180  std::vector<int> indexVVars;
181  std::vector<int> indexIVars;
182  std::vector<int> indexMaskedVars;
185 
186  // limiter flag:
188 
189  // 2-level information:
190  std::vector<N_TIA_TwoLevelError> innerErrorInfoVec;
191 
192  // new-DAE data (originally from the new-DAE derrived class)
193  // Error Vectors
194  N_LAS_Vector * qErrWtVecPtr;
195 
196  // DAE formulation vectors
197  N_LAS_Vector * daeQVectorPtr;
198  N_LAS_Vector * daeFVectorPtr;
199 
200  // voltage limiting vectors
201  N_LAS_Vector * dFdxdVpVectorPtr;
202  N_LAS_Vector * dQdxdVpVectorPtr;
203 
204  // DAE formulation matrices
205  N_LAS_Matrix * dQdxMatrixPtr;
206  N_LAS_Matrix * dFdxMatrixPtr;
207 
208  // HB temporary Matvec storage vectors
209  N_LAS_Vector * dQdxVecVectorPtr;
210  N_LAS_Vector * dFdxVecVectorPtr;
211 
212  // History arrays
213  std::vector<N_LAS_Vector*> xHistory;
214  std::vector<N_LAS_Vector*> qHistory;
215  std::vector<N_LAS_Vector*> sHistory; // state history
216  std::vector<N_LAS_Vector*> stoHistory; // store history
217  std::vector<N_LAS_Vector*> stoLeadCurrQCompHistory; // store history for lead current Q component.
218 
219  // Predictors
220  N_LAS_Vector * qn0Ptr;
221  N_LAS_Vector * qpn0Ptr;
222 
223  N_LAS_Vector * sn0Ptr;
224  N_LAS_Vector * spn0Ptr;
225 
226  N_LAS_Vector * ston0Ptr;
227  N_LAS_Vector * stopn0Ptr;
228 
229  N_LAS_Vector * stoQCn0Ptr;
230  N_LAS_Vector * stoQCpn0Ptr;
231 
232  // Nonlinear solution vector:
233  N_LAS_Vector * qNewtonCorrectionPtr;
234  N_LAS_Vector * sNewtonCorrectionPtr;
235  N_LAS_Vector * stoNewtonCorrectionPtr;
237 
238  // Step-size selection temporary vectors
239  N_LAS_Vector * delta_x;
240  N_LAS_Vector * delta_q;
241 
242  // Temporary vectors for WaMPDE interpolation
243  N_LAS_Vector * tmpXn0APtr;
244  N_LAS_Vector * tmpXn0BPtr;
245 
246  // These are for MPDE fast time scale points
247  std::vector<double> timeSteps;
248  std::vector<bool> timeStepsBreakpointFlag;
249  std::vector<N_LAS_Vector*> fastTimeSolutionVec;
250  std::vector<N_LAS_Vector*> fastTimeStateVec;
251  std::vector<N_LAS_Vector*> fastTimeQVec;
252  std::vector<N_LAS_Vector*> fastTimeStoreVec;
253  //std::vector<N_LAS_Vector*> pastQVecHistory;
254 
255  // these are placeholders until the transient sensitivites are set
256  // up properly
257  std::vector<double> objectiveVec_;
258  std::vector<double> dOdpVec_;
259  std::vector<double> dOdpAdjVec_;
260  std::vector<double> scaled_dOdpVec_;
261  std::vector<double> scaled_dOdpAdjVec_;
262 
263  protected:
264 
265  private:
266 
267 
268  // DataStore Functions
269  public:
270  void initializeDataArrays();
271  void enableOrderOneStart();
272 
273  void updateSolDataArrays();
274  bool updateStateDataArrays();
275 
276  void outputSolDataArrays(std::ostream &os);
277  virtual void setConstantHistory();
278  virtual void setZeroHistory();
279  virtual void setErrorWtVector();
280  virtual double WRMS_errorNorm();
281 
282  virtual double partialErrorNormSum();
283  virtual double partialQErrorNormSum();
284 
285  virtual double partialSum_m1(int currentOrder);
286  virtual double partialSum_m2(int currentOrder);
287 
288  virtual double globalLength ();
290 
291  void computeDivDiffsBlock(const std::list<index_pair> & solGIDList,
292  const std::list<index_pair> & staGIDList);
293 
294  void printOutPointers ();
295  bool equateTmpVectors ();
297 
298  void outputPredictedSolution(std::ostream &os);
299  void outputPredictedDerivative(std::ostream &os);
300 
301  virtual void stepLinearCombo ();
302 
303  virtual double partialSum_p1(int currentOrder, int maxOrder);
304  virtual double partialSum_q1();
305 
306  virtual double delta_x_errorNorm_m1();
307  virtual double delta_x_errorNorm_m2();
308  virtual double delta_x_errorNorm_p1();
309  virtual double delta_x_errorNorm_q1();
310 
311  virtual bool getSolnVarData( const int & gid, std::vector<double> & varData );
312  virtual bool getStateVarData( const int & gid, std::vector<double> & varData );
313  virtual bool setSolnVarData( const int & gid, const std::vector<double> & varData );
314  virtual bool setStateVarData( const int & gid, const std::vector<double> & varData );
315  virtual bool getStoreVarData( const int & gid, std::vector<double> & varData );
316  virtual bool setStoreVarData( const int & gid, const std::vector<double> & varData );
317 
318  N_LAS_System * lasSysPtr;
319 
320  bool setNextSolVectorPtr (N_LAS_Vector * solVecPtr);
321  bool unsetNextSolVectorPtr ();
322 
323  bool resetAll ();
324  bool resetFastTimeData ();
325 
326  protected:
327 
329  double * dataBlockPtr;
331 
333 
334 
335  private:
336  N_TIA_DataStore();
337 
338 };
339 
340 #endif // Xyce_N_TIA_DATA_STORE_H
341