Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_TIA_Assembler.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2014 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_TIA_Assembler.C,v $
27 // Purpose :
28 // Special Notes :
29 // Creator : Eric Keiter
30 // Creation Date : 1/1/07
31 //
32 // Revision Information:
33 // ---------------------
34 // Revision Number: $Revision: 1.27 $
35 // Revision Date : $Date: 2014/02/24 23:49:27 $
36 // Current Owner : $Author: tvrusso $
37 //-----------------------------------------------------------------------------
38 #include <Xyce_config.h>
39 
40 // ---------- Standard Includes ----------
41 
42 // ---------- Xyce Includes ----------
43 #include <N_TIA_Assembler.h>
45 #include <N_LOA_NonlinearEquationLoader.h>
46 #include <N_TIA_DataStore.h>
47 
48 #include <N_LOA_Loader.h>
49 
50 #include <N_UTL_Timer.h>
51 
52 #include <N_PDS_Manager.h>
53 #include <N_PDS_Comm.h>
54 
55 #include <N_LAS_Vector.h>
56 #include <N_LAS_Matrix.h>
57 
58 //-----------------------------------------------------------------------------
59 // Function : N_TIA_Assembler::N_TIA_Assembler::
60 // Purpose : constructor
61 // Special Notes :
62 // Scope : public
63 // Creator : Eric R. Keiter,SNL, Computational Sciences
64 // Creation Date : 01/30/07
65 //-----------------------------------------------------------------------------
67  N_LOA_Loader & loader,
69  N_PDS_Manager & pds,
70  bool daeStateDerivFlag
71  )
72 : ds_(ds),
73  loader_(loader),
74  wim_(wim),
75  pdsMgr(pds),
76  residualTimerPtr_(0),
77  jacobianTimerPtr_(0),
78  daeStateDerivFlag_(daeStateDerivFlag)
79 {
80  residualTimerPtr_ = new N_UTL_Timer(*(pdsMgr.getPDSComm()));
81  jacobianTimerPtr_ = new N_UTL_Timer(*(pdsMgr.getPDSComm()));
82 }
83 
84 //-----------------------------------------------------------------------------
85 // Function : N_TIA_Assembler::~N_TIA_Assembler::
86 // Purpose : destructor
87 // Special Notes :
88 // Scope : public
89 // Creator : Eric R. Keiter,SNL, Computational Sciences
90 // Creation Date : 01/30/07
91 //-----------------------------------------------------------------------------
92 
94 {
95  if (residualTimerPtr_ != 0) delete residualTimerPtr_;
96  if (jacobianTimerPtr_ != 0) delete jacobianTimerPtr_;
97 }
98 
99 //-----------------------------------------------------------------------------
100 // Function : N_TIA_DAE_Assembler::N_TIA_DAE_Assembler::
101 // Purpose : constructor
102 // Special Notes :
103 // Scope : public
104 // Creator : Eric R. Keiter,SNL, Computational Sciences
105 // Creation Date : 01/30/07
106 //-----------------------------------------------------------------------------
109  N_LOA_Loader & loader,
111  N_PDS_Manager & pds,
112  bool daeStateDerivFlag
113  )
114  : N_TIA_Assembler(ds,loader,wim,pds,daeStateDerivFlag)
115 {
116 
117 }
118 
119 //-----------------------------------------------------------------------------
120 // Function : N_TIA_DAE_Assembler::~N_TIA_DAE_Assembler::
121 // Purpose : destructor
122 // Special Notes :
123 // Scope : public
124 // Creator : Eric R. Keiter,SNL, Computational Sciences
125 // Creation Date : 01/30/07
126 //-----------------------------------------------------------------------------
127 
129 {
130 }
131 
132 //-----------------------------------------------------------------------------
133 // Function : N_TIA_DAE_Assembler::loadRHS
134 //
135 // Purpose : This function manages the various function calls necessary
136 // to assemble the new-DAE form of the residual (RHS).
137 //
138 // Special Notes : All the contributions to the RHS come (in the new DAE
139 // form) from the device package, as Q, F, and B. The
140 // RHS needs dQdt + F - B. As dQdt is determined by the
141 // time integration package, the final summation should be
142 // managed from here.
143 //
144 // Scope : public
145 // Creator : Eric R. Keiter,SNL, Computational Sciences
146 // Creation Date : 03/04/04
147 //-----------------------------------------------------------------------------
149 {
150  bool bsuccess = true;
151  bool tmpBool = true;
152 
153  // Start the timer...
154  residualTimerPtr_->resetStartTime();
155 
156  ds_.daeQVectorPtr->putScalar(0.0);
157  ds_.daeFVectorPtr->putScalar(0.0);
158 
159  ds_.dFdxdVpVectorPtr->putScalar(0.0);
160  ds_.dQdxdVpVectorPtr->putScalar(0.0);
161  ds_.dQdxMatrixPtr->put(0.0);
162  ds_.dFdxMatrixPtr->put(0.0);
163 
164  // Update the state. Note - underneath this call, most of the calculations
165  // pertaining to the currents, conductances, etc. will happen.
166  tmpBool = loader_.updateState
167  ((ds_.nextSolutionPtr),
168  (ds_.currSolutionPtr),
169  (ds_.lastSolutionPtr),
170  (ds_.nextStatePtr),
171  (ds_.currStatePtr),
172  (ds_.lastStatePtr),
173  (ds_.nextStorePtr),
174  (ds_.currStorePtr),
175  (ds_.lastStorePtr)
176  );
177 
178  bsuccess = bsuccess && tmpBool;
179 
180  if (daeStateDerivFlag_)
181  {
183  }
184 
185  // first load the 2 components: Q and F
186  // (there is no longer a separate B vector for indep sources)
187  tmpBool = loader_.loadDAEVectors
188  ((ds_.nextSolutionPtr),
189  (ds_.currSolutionPtr),
190  (ds_.lastSolutionPtr),
191  (ds_.nextStatePtr),
192  (ds_.currStatePtr),
193  (ds_.lastStatePtr),
195  (ds_.nextStorePtr),
196  (ds_.currStorePtr),
197  (ds_.lastStorePtr),
199  (ds_.daeQVectorPtr),
200  (ds_.daeFVectorPtr),
202  (ds_.dQdxdVpVectorPtr) );
203  bsuccess = bsuccess && tmpBool;
205  // Now determine dQdt:
206  // now sum them all together, to create the total.
207  // f(x) is given by:
208  //
209  // f(x) = dQ/dt + F(x) = 0
210  //
211  // Note, the nonlinear solver is expecting the RHS vector to
212  // contain -f(x). Or, possibly -f(x) + J*dx, if voltage
213  // limiting is on.
215 
216  // Update the total load time
217  residualTime_ = residualTimerPtr_->elapsedTime();
218 
219  return bsuccess;
220 }
221 
222 //-----------------------------------------------------------------------------
223 // Function : N_TIA_DAE_Assembler::loadJacobian
224 //
225 // Purpose : This function manages the various function calls necessary
226 // to assemble the new-DAE form of the Jacobian.
227 //
228 // Special Notes : All the contributions to the Jacobian
229 // come (in the new DAE form)
230 // from the device package, as dQdx and dFdx.
231 //
232 // The Jacobian is:
233 //
234 // J = df/dx = d(dQdt)/dx + dF/dx
235 //
236 // As dQdt is determined by the time integration package,
237 // the final summation should be managed from here.
238 //
239 // Scope : public
240 // Creator : Eric R. Keiter,SNL, Computational Sciences
241 // Creation Date : 03/04/04
242 //-----------------------------------------------------------------------------
244 {
245  bool bsuccess = true;
246  bool tmpBool = true;
247 
248  // Start the timer...
249  jacobianTimerPtr_->resetStartTime();
250 
251 #if 0
252  // This put(0) isn't needed anymore, as it is handled down in the
253  // obtainJacobian method.
254  ds_.JMatrixPtr->put(0.0);
255 #endif
256 
257 #if 0
258  // don't put these here! In the MPDE case they are loaded
259  // during the vector load.
260  ds_.dQdxMatrixPtr->put(0.0);
261  ds_.dFdxMatrixPtr->put(0.0);
262 #endif
263 
264  // first load the 2 components: dQdx and dFdx
265  tmpBool = loader_.loadDAEMatrices
266  ((ds_.nextSolutionPtr),
267  (ds_.nextStatePtr),
269  (ds_.nextStorePtr),
270  (ds_.dQdxMatrixPtr),
271  (ds_.dFdxMatrixPtr));
272  bsuccess = bsuccess && tmpBool;
273 
274  // Now determine the d(dQdt)/dx stuff:
275 
276  // now sum them all together, to create the total:
277  // J = alpha/dt * dQ/dx + dF/dx
279 
280  // Update the total load time
281  jacobianTime_ = jacobianTimerPtr_->elapsedTime();
282 
283  return bsuccess;
284 }
285 
286 //-----------------------------------------------------------------------------
287 // Function : N_TIA_DAE_Assembler::applyJacobian
288 //
289 // Purpose :
290 // Special Notes :
291 // Scope : public
292 // Creator : Todd Coffey, Ting Mei
293 // Creation Date : 07/29/08
294 //-----------------------------------------------------------------------------
295 bool N_TIA_DAE_Assembler::applyJacobian (const N_LAS_Vector& input, N_LAS_Vector& result)
296 {
297  bool bsuccess = true;
298  bool tmpBool = true;
299 
300  // Start the timer...
301  jacobianTimerPtr_->resetStartTime();
302 
303  // first load the 2 components: dQdx and dFdx
304  tmpBool = loader_.applyDAEMatrices
305  ((ds_.nextSolutionPtr),
306  (ds_.nextStatePtr),
308  (ds_.nextStorePtr),
309  input,
312  bsuccess = bsuccess && tmpBool;
313 
314  // Now determine the d(dQdt)/dx stuff:
315 
316  // now sum them all together, to create the total:
317  // J = alpha/dt * dQ/dx + dF/dx
318  wim_.applyJacobian(input, result);
319 
320  // Update the total load time
321  jacobianTime_ = jacobianTimerPtr_->elapsedTime();
322 
323  return bsuccess;
324 }
325