Xyce  6.1
N_LOA_NonlinearEquationLoader.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_LOA_NonlinearEquationLoader.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 05/26/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.38.2.1 $
40 //
41 // Revision Date : $Date: 2015/11/20 00:37:50 $
42 //
43 // Current Owner : $Author: tmei $
44 //-----------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 // ---------- Xyce Includes ----------
49 #include <N_DEV_Algorithm.h>
50 #include <N_DEV_DeviceMgr.h>
51 #include <N_DEV_ExternDevice.h>
52 #include <N_ERH_ErrorMgr.h>
53 #include <N_LAS_Matrix.h>
54 #include <N_LAS_Vector.h>
55 #include <N_LOA_Loader.h>
57 #include <N_PDS_MPI.h>
58 #include <N_PDS_Serial.h>
59 #include <N_TIA_DataStore.h>
61 #include <N_UTL_BreakPoint.h>
62 #include <N_UTL_Timer.h>
63 
64 namespace Xyce {
65 namespace Loader {
66 
67 //-----------------------------------------------------------------------------
68 // Function : NonlinearEquationLoader::NonlinearEquationLoader
69 // Purpose : constructor
70 // Special Notes :
71 // Scope : public
72 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
73 // Creation Date : 5/27/00
74 //-----------------------------------------------------------------------------
77  Loader & loader,
78  Device::DeviceMgr & device_manager,
80  bool daeStateDerivFlag)
81  : ds_(ds),
82  loader_(loader),
83  deviceManager_(device_manager),
84  wim_(wim),
85  residualTimerPtr_(0),
86  jacobianTimerPtr_(0),
87  daeStateDerivFlag_(daeStateDerivFlag)
88 {
89  residualTimerPtr_ = new Util::Timer();
90  jacobianTimerPtr_ = new Util::Timer();
91 }
92 
93 //-----------------------------------------------------------------------------
94 // Function : NonlinearEquationLoader::~NonlinearEquationLoader
95 // Purpose : destructor
96 // Special Notes :
97 // Scope : public
98 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
99 // Creation Date : 5/27/00
100 //-----------------------------------------------------------------------------
102 {
103  delete residualTimerPtr_;
104  delete jacobianTimerPtr_;
105 }
106 
107 bool
109 {
111 }
112 
113 void
115  std::string & name,
116  std::vector<double> & dfdpVec,
117  std::vector<double> & dqdpVec,
118  std::vector<double> & dbdpVec,
119  std::vector<int> & FindicesVec,
120  std::vector<int> & QindicesVec,
121  std::vector<int> & BindicesVec) const
122 {
123  return deviceManager_.getAnalyticSensitivities(name, dfdpVec, dqdpVec, dbdpVec, FindicesVec, QindicesVec, BindicesVec);
124 }
125 
126 bool NonlinearEquationLoader::setParam(std::string & name, double val, bool overrideOriginal)
127 {
128  return deviceManager_.setParam(name, val, overrideOriginal);
129 }
130 
131 bool NonlinearEquationLoader::getParamAndReduce(Parallel::Machine comm, const std::string & name, double & val) const
132 {
133  return Device::getParamAndReduce(comm, deviceManager_, name, val);
134 }
135 
136 //-----------------------------------------------------------------------------
137 // Function : NonlinearEquationLoader::loadRHS
138 //
139 // Purpose : This function manages the various function calls necessary
140 // to assemble the DAE form of the residual (RHS).
141 //
142 // Special Notes : All the contributions to the RHS come (in the new DAE
143 // form) from the device package, as Q, F, and B. The
144 // RHS needs dQdt + F - B. As dQdt is determined by the
145 // time integration package, the final summation should be
146 // managed from here.
147 //
148 // Scope : public
149 // Creator : Eric R. Keiter,SNL, Computational Sciences
150 // Creation Date : 03/04/04
151 //-----------------------------------------------------------------------------
153 {
154  // Stats::StatTop _residualStat("Residual Load");
155  // Stats::TimeBlock _residualTimer(_residualStat);
156 
157  bool bsuccess = true;
158  bool tmpBool = true;
159 
160  // Start the timer...
161  residualTimerPtr_->resetStartTime();
162 
163  ds_.daeQVectorPtr->putScalar(0.0);
164  ds_.daeFVectorPtr->putScalar(0.0);
165  ds_.daeBVectorPtr->putScalar(0.0);
166 
167  ds_.dFdxdVpVectorPtr->putScalar(0.0);
168  ds_.dQdxdVpVectorPtr->putScalar(0.0);
169 
170  // Update the state. Note - underneath this call, most of the calculations
171  // pertaining to the currents, conductances, etc. will happen.
172  {
173 // Stats::StatTop _deviceResidualStat("Device Load");
174 // Stats::TimeBlock _deviceResidualTimer(_deviceResidualStat);
175 
176  tmpBool = loader_.updateState(
185  ds_.lastStorePtr);
186 
187  bsuccess = bsuccess && tmpBool;
188 
189  if (daeStateDerivFlag_)
190  {
192  }
193 
194  // first load the 2 components: Q, F and B
195  tmpBool = loader_.loadDAEVectors(
219 
220  bsuccess = bsuccess && tmpBool;
221  }
222 
223 
225 
226  // Now determine dQdt:
227  // now sum them all together, to create the total.
228  // f(x) is given by:
229  //
230  // f(x) = dQ/dt + F(x) - B(t)= 0
231  //
232  // Note, the nonlinear solver is expecting the RHS vector to
233  // contain -f(x). Or, possibly -f(x) + J*dx, if voltage
234  // limiting is on.
235 
236  {
237 // Stats::StatTop _timeResidualStat("Time Integrator Assembler");
238 // Stats::TimeBlock _timeResidualTimer(_timeResidualStat);
239 
241  }
242 
243  // Update the total load time
244  residualTime_ = residualTimerPtr_->elapsedTime();
245 
246  return bsuccess;
247 }
248 
249 
250 //-----------------------------------------------------------------------------
251 // Function : NonlinearEquationLoader::loadJacobian
252 //
253 // Purpose : This function manages the various function calls necessary
254 // to assemble the DAE form of the Jacobian.
255 //
256 // Special Notes : All the contributions to the Jacobian
257 // come (in the new DAE form)
258 // from the device package, as dQdx and dFdx.
259 //
260 // The Jacobian is:
261 //
262 // J = df/dx = d(dQdt)/dx + dF/dx
263 //
264 // As dQdt is determined by the time integration package,
265 // the final summation should be managed from here.
266 //
267 // Scope : public
268 // Creator : Eric R. Keiter,SNL, Computational Sciences
269 // Creation Date : 03/04/04
270 //-----------------------------------------------------------------------------
272 {
273  // Stats::StatTop _jacobianStat("Jacobian Load");
274  // Stats::TimeBlock _jacobianTimer(_jacobianStat.getTop());
275 
276  bool bsuccess = true;
277  bool tmpBool = true;
278 
279  // Start the timer...
280  jacobianTimerPtr_->resetStartTime();
281 
282  ds_.dQdxMatrixPtr->put(0.0);
283  ds_.dFdxMatrixPtr->put(0.0);
284 
285  // first load the 2 components: dQdx and dFdx
286  {
287 // Stats::StatTop _deviceJacobianStat("Device Load");
288 // Stats::TimeBlock _deviceJacobianTimer(_deviceJacobianStat);
289 
290  tmpBool = loader_.loadDAEMatrices(
297  bsuccess = bsuccess && tmpBool;
298  }
299 
300  // Now determine the d(dQdt)/dx stuff:
301 
302  {
303 // Stats::StatTop _timeJacobianStat("Time Integrator Assembler");
304 // Stats::TimeBlock _timeJacobianTimer(_timeJacobianStat);
305 
306  // now sum them all together, to create the total:
307  // J = alpha/dt * dQ/dx + dF/dx
309  }
310 
311  // Update the total load time
312  jacobianTime_ = jacobianTimerPtr_->elapsedTime();
313 
314  return bsuccess;
315 }
316 
317 
318 //-----------------------------------------------------------------------------
319 // Function : NonlinearEquationLoader::applyJacobian
320 //
321 // Purpose :
322 // Special Notes :
323 // Scope : public
324 // Creator : Todd Coffey, Ting Mei
325 // Creation Date : 07/29/08
326 //-----------------------------------------------------------------------------
328  const Linear::Vector& input,
329  Linear::Vector& result)
330 {
331  bool bsuccess = true;
332  bool tmpBool = true;
333 
334  // Start the timer...
335  jacobianTimerPtr_->resetStartTime();
336 
337  // first load the 2 components: dQdx and dFdx
338  tmpBool = loader_.applyDAEMatrices(
343  input,
346  bsuccess = bsuccess && tmpBool;
347 
348  // Now determine the d(dQdt)/dx stuff:
349 
350  // now sum them all together, to create the total:
351  // J = alpha/dt * dQ/dx + dF/dx
352  wim_.applyJacobian(input, result);
353 
354  // Update the total load time
355  jacobianTime_ = jacobianTimerPtr_->elapsedTime();
356 
357  return bsuccess;
358 }
359 
360 
361 //-----------------------------------------------------------------------------
362 // Function : NonlinearEquationLoader::loadSensitivityResiduals
363 //
364 // Purpose : This function manages the various function calls necessary
365 // to assemble the DAE form of the sensitivity residual (RHS).
366 //
367 // Special Notes : All the contributions to the vector come (in the new DAE
368 // form) from the device package, as dQp, dFp, and dBdp.
369 //
370 // Scope : public
371 // Creator : Eric R. Keiter, SNL
372 // Creation Date :
373 //-----------------------------------------------------------------------------
375 {
376  bool bsuccess = true;
378  return bsuccess;
379 }
380 
381 //-----------------------------------------------------------------------------
382 // Function : NonlinearEquationLoader::loadSensitivityResiduals
383 //
384 // Purpose : This function manages the various function calls necessary
385 // to assemble the DAE form of the sensitivity residual (RHS).
386 //
387 // Special Notes : All the contributions to the vector come (in the new DAE
388 // form) from the device package, as dQp, dFp, and dBdp.
389 //
390 // Scope : public
391 // Creator : Eric R. Keiter, SNL
392 // Creation Date : 09/02/2014
393 //-----------------------------------------------------------------------------
395 {
396  bool bsuccess = true;
398  return bsuccess;
399 }
400 
401 //-----------------------------------------------------------------------------
402 // Function : NonlinearEquationLoader::isLinearSystem
403 // Purpose :
404 // Special Notes :
405 // Scope : public
406 // Creator : Todd Coffey, SNL
407 // Creation Date : 07/29/08
408 //-----------------------------------------------------------------------------
410 {
412 }
413 
414 //-----------------------------------------------------------------------------
415 // Function : NonlinearEquationLoader::enablePDEContinuation
416 // Purpose :
417 // Special Notes :
418 // Scope : public
419 // Creator : Todd Coffey, SNL
420 // Creation Date : 07/29/08
421 //-----------------------------------------------------------------------------
423 {
425 }
426 
427 //-----------------------------------------------------------------------------
428 // Function : NonlinearEquationLoader::disablePDEContinuation
429 // Purpose :
430 // Special Notes :
431 // Scope : public
432 // Creator : Todd Coffey, SNL
433 // Creation Date : 07/29/08
434 //-----------------------------------------------------------------------------
436 {
438 }
439 
440 //-----------------------------------------------------------------------------
441 // Function : NonlinearEquationLoader::getNumInterfaceNodes
442 // Purpose :
443 // Special Notes :
444 // Scope : public
445 // Creator : Todd Coffey, SNL
446 // Creation Date : 07/29/08
447 //-----------------------------------------------------------------------------
449  (std::vector<int> & numINodes)
450 {
451  deviceManager_.getNumInterfaceNodes (numINodes);
452 }
453 
454 //-----------------------------------------------------------------------------
455 // Function : NonlinearEquationLoader::loadCouplingRHS
456 // Purpose :
457 // Special Notes :
458 // Scope : public
459 // Creator : Todd Coffey, SNL
460 // Creation Date : 07/29/08
461 //-----------------------------------------------------------------------------
463  (int iSubProblem, int iCouple, Linear::Vector * dfdvPtr)
464 {
465  return deviceManager_.loadCouplingRHS (iSubProblem, iCouple, dfdvPtr);
466 }
467 
468 //-----------------------------------------------------------------------------
469 // Function : NonlinearEquationLoader::calcCouplingTerms
470 // Purpose :
471 // Special Notes :
472 // Scope : public
473 // Creator : Todd Coffey, SNL
474 // Creation Date : 07/29/08
475 //-----------------------------------------------------------------------------
477  (int iSubProblem, int iCouple, const Linear::Vector * dxdvPtr)
478 {
479  return deviceManager_.calcCouplingTerms (iSubProblem, iCouple, dxdvPtr);
480 }
481 
482 //-----------------------------------------------------------------------------
483 // Function : NonlinearEquationLoader::getHomotopyBlockSize
484 // Purpose :
485 // Special Notes :
486 // Scope : public
487 // Creator : Todd Coffey, SNL
488 // Creation Date : 07/29/08
489 //-----------------------------------------------------------------------------
491 {
493 }
494 
495 //-----------------------------------------------------------------------------
496 // Function : NonlinearEquationLoader::homotopyStepSuccess
497 // Purpose :
498 // Special Notes :
499 // Scope : public
500 // Creator : Eric R. Keiter, SNL
501 // Creation Date : 03/20/06
502 //-----------------------------------------------------------------------------
504  const std::vector<std::string> & paramNames,
505  const std::vector<double> & paramVals)
506 {
507  const Device::InstanceVector &extern_devices = deviceManager_.getDevices(Device::ExternDevice::Traits::modelType());
508 
509  for (Device::InstanceVector::const_iterator it = extern_devices.begin(); it != extern_devices.end(); ++it)
510  {
511  Device::ExternDevice::Instance &extern_device = static_cast<Device::ExternDevice::Instance &>(*(*it));
512 
513  extern_device.homotopyStepSuccess (paramNames, paramVals);
514  }
515 }
516 
517 //-----------------------------------------------------------------------------
518 // Function : NonlinearEquationLoader::homotopyStepFailure
519 // Purpose :
520 // Special Notes :
521 // Scope : public
522 // Creator : Eric R. Keiter, SNL
523 // Creation Date : 03/30/06
524 //-----------------------------------------------------------------------------
526 {
527  const Device::InstanceVector &extern_devices = deviceManager_.getDevices(Device::ExternDevice::Traits::modelType());
528 
529  for (Device::InstanceVector::const_iterator it = extern_devices.begin(); it != extern_devices.end(); ++it)
530  {
531  Device::ExternDevice::Instance &extern_device = static_cast<Device::ExternDevice::Instance &>(*(*it));
532 
533  extern_device.homotopyStepFailure ();
534  }
535 }
536 
537 //-----------------------------------------------------------------------------
538 // Function : NonlinearEquationLoader::allDevsConverged
539 // Purpose : Check whether any device has taken an action that renders
540 // normal convergence checks invalid (i.e. that the current
541 // step must be assumed unconverged).
542 // Special Notes :
543 // Scope : public
544 // Creator : Todd Coffey, SNL
545 // Creation Date : 07/29/08
546 //-----------------------------------------------------------------------------
547 bool NonlinearEquationLoader::allDevicesConverged(Parallel::Machine comm)
548 {
549  return deviceManager_.allDevicesConverged(comm);
550 }
551 
552 //-----------------------------------------------------------------------------
553 // Function : NonlinearEquationLoader::innerDevsConverged
554 // Purpose :
555 // Special Notes :
556 // Scope : public
557 // Creator : Todd Coffey, SNL
558 // Creation Date : 07/29/08
559 //-----------------------------------------------------------------------------
561 {
562  return Device::devicesConverged(comm, deviceManager_.getDevices(Device::ExternDevice::Traits::modelType()));
563 }
564 
565 //-----------------------------------------------------------------------------
566 // Function : NonlinearEquationLoader::getVoltageLimiterStatus
567 // Purpose : voltage limiter toggle functions
568 // Special Notes :
569 // Scope : public
570 // Creator : Eric Keiter, SNL
571 // Creation Date : 6/22/2015
572 //-----------------------------------------------------------------------------
574 {
576 }
577 
578 //-----------------------------------------------------------------------------
579 // Function : NonlinearEquationLoader::setVoltageLimiterStatus
580 // Purpose :
581 // Special Notes :
582 // Scope : public
583 // Creator : Eric Keiter, SNL
584 // Creation Date : 6/22/2015
585 //-----------------------------------------------------------------------------
587 {
588  return deviceManager_.setVoltageLimiterStatus(voltageLimterStatus);
589 }
590 
591 } // namespace Loader
592 } // namespace Xyce
bool setParam(const std::string &name, double val, bool overrideOriginal=false)
Linear::Vector * lastSolutionPtr
Linear::Vector * nextLeadCurrentQPtr
void getAnalyticSensitivities(std::string &name, std::vector< double > &dfdpVec, std::vector< double > &dqdpVec, std::vector< double > &dbdpVec, std::vector< int > &FindicesVec, std::vector< int > &QindicesVec, std::vector< int > &BindicesVec)
bool loadCouplingRHS(int iSubProblem, int iCouple, Linear::Vector *dfdvPtr)
Linear::Vector * lastLeadDeltaVPtr
Pure virtual class to augment a linear system.
const InstanceVector & getDevices(ModelTypeId model_type_id) const
TimeIntg::WorkingIntegrationMethod & wim_
virtual bool loadDAEVectors(Linear::Vector *nextSolVectorPtr, Linear::Vector *currSolVectorPtr, Linear::Vector *lastSolVectorPtr, Linear::Vector *nextStaVectorPtr, Linear::Vector *currStaVectorPtr, Linear::Vector *lastStaVectorPtr, Linear::Vector *StaDerivVectorPtr, Linear::Vector *nextStoVectorPtr, Linear::Vector *currStoVectorPtr, Linear::Vector *lastStoVectorPtr, Linear::Vector *stoLeadCurrQVectorPtr, Linear::Vector *nextLeadFVectorPtr, Linear::Vector *currLeadFVectorPtr, Linear::Vector *lastLeadFVectorPtr, Linear::Vector *nextLeadQVectorPtr, Linear::Vector *nextJunctionVVectorPtr, Linear::Vector *currJunctionVVectorPtr, Linear::Vector *lastJunctionVVectorPtr, Linear::Vector *QVectorPtr, Linear::Vector *FVectorPtr, Linear::Vector *BVectorPtr, Linear::Vector *dFdxdVpVectorPtr, Linear::Vector *dQdxdVpVectorPtr)
Definition: N_LOA_Loader.h:122
bool applyJacobian(const Linear::Vector &input, Linear::Vector &result)
virtual bool applyDAEMatrices(Linear::Vector *tmpSolVectorPtr, Linear::Vector *tmpStaVectorPtr, Linear::Vector *tmpStaDerivVectorPtr, Linear::Vector *tmpStoVectorPtr, const Linear::Vector &tmpVecVectorPtr, Linear::Vector *tmpdQdxVecVectorPtr, Linear::Vector *tmpdFdxVecVectorPtr)
Definition: N_LOA_Loader.h:177
Linear::Vector * currStorePtr
Linear::Vector * lastStatePtr
bool getParamAndReduce(Parallel::Machine comm, const std::string &name, double &val) const
Linear::Vector * nextLeadDeltaVPtr
Linear::Vector * currStatePtr
bool setParam(std::string &name, double val, bool overrideOriginal=false)
Linear::Vector * daeQVectorPtr
Device::DeviceMgr & deviceManager_
Definition: N_ANP_HB.C:2199
Linear::Vector * lastLeadCurrentPtr
bool calcCouplingTerms(int iSubProblem, int iCouple, const Linear::Vector *dxdvPtr)
NonlinearEquationLoader(TimeIntg::DataStore &ds, Loader &loader, Device::DeviceMgr &device_manager, TimeIntg::WorkingIntegrationMethod &wim, bool daeStateDerivFlag)
Linear::Vector * daeFVectorPtr
void getAnalyticSensitivities(std::string &name, std::vector< double > &dfdpVec, std::vector< double > &dqdpVec, std::vector< double > &dbdpVec, std::vector< int > &FindicesVec, std::vector< int > &QindicesVec, std::vector< int > &BindicesVec) const
Linear::Matrix * dFdxMatrixPtr
int getHomotopyBlockSize() const
Linear::Vector * nextStatePtr
bool allDevicesConverged(Parallel::Machine comm) const
Linear::Vector * dFdxdVpVectorPtr
virtual bool loadDAEMatrices(Linear::Vector *tmpSolVectorPtr, Linear::Vector *tmpStaVectorPtr, Linear::Vector *tmpStaDerivVectorPtr, Linear::Vector *tmpStoVectorPtr, Linear::Matrix *tmpdQdxMatrixPtr, Linear::Matrix *tmpdFdxMatrixPtr)
Definition: N_LOA_Loader.h:110
virtual bool updateState(Linear::Vector *nextSolVectorPtr, Linear::Vector *currSolVectorPtr, Linear::Vector *lastSolVectorPtr, Linear::Vector *nextStaVectorPtr, Linear::Vector *currStaVectorPtr, Linear::Vector *lastStaVectorPtr, Linear::Vector *nextStoVectorPtr, Linear::Vector *currStoVectorPtr, Linear::Vector *lastStoVectorPtr)
Definition: N_LOA_Loader.h:189
Linear::Vector * currLeadDeltaVPtr
void homotopyStepSuccess(const std::vector< std::string > &paramNames, const std::vector< double > &paramVals)
void setVoltageLimiterStatus(bool voltageLimterStatus)
void setVoltageLimiterStatus(bool voltageLimterStatus)
bool devicesConverged(Parallel::Machine comm, const InstanceVector &extern_devices)
Linear::Vector * nextSolutionPtr
Linear::Vector * nextStorePtr
Linear::Vector * dQdxdVpVectorPtr
Linear::Vector * currLeadCurrentPtr
Linear::Vector * lastStorePtr
bool getParamAndReduce(Parallel::Machine comm, const DeviceMgr &device_manager, const std::string &name, double &val)
bool analyticSensitivitiesAvailable(const std::string &name)
Linear::Vector * dQdxVecVectorPtr
Linear::Vector * currSolutionPtr
void getNumInterfaceNodes(std::vector< int > &numINodes)
void applyJacobian(const Linear::Vector &input, Linear::Vector &result)
Linear::Vector * dFdxVecVectorPtr
Linear::Vector * nextStoreLeadCurrQPtr
std::vector< DeviceInstance * > InstanceVector
Definition: N_DEV_fwd.h:193
Linear::Vector * nextStateDerivPtr
Loader::Loader & loader_
Definition: N_ANP_AC.C:963
Linear::Matrix * dQdxMatrixPtr
Device::DeviceMgr & deviceManager_
Device manager.
Linear::Vector * daeBVectorPtr
Linear::Vector * nextLeadCurrentPtr