Xyce  6.1
N_NLS_NOX_Interface.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_NLS_NOX_Interface.C,v $
27 //
28 // Purpose : Interface to Xyce vectors for NOX.
29 //
30 // Special Notes :
31 //
32 // Creator : Tammy Kolda, NLS, 8950
33 //
34 // Creation Date : 01/31/02
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.199 $
40 //
41 // Revision Date : $Date: 2015/09/14 18:54:20 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 #ifndef HAVE_CONFIG_H
49 #define HAVE_CONFIG_H
50 #endif
51 
52 #include <sstream>
53 
54 #include <LOCA_GlobalData.H>
55 #include <LOCA_StatusTest_Wrapper.H>
56 #include <NOX_Solver_Factory.H>
57 #include <N_ANP_AnalysisManager.h>
58 #include <N_ERH_ErrorMgr.h>
59 #include <N_IO_CmdParse.h>
60 #include <N_IO_OutputMgr.h>
61 #include <N_LAS_Builder.h>
62 #include <N_LAS_QueryUtil.h>
63 #include <N_LAS_Solver.h>
64 #include <N_LAS_System.h>
66 #include <N_NLS_LOCA_Group.h>
68 #include <N_NLS_NOX_Group.h>
69 #include <N_NLS_NOX_Interface.h>
72 #include <N_NLS_NOX_SharedSystem.h>
73 #include <N_NLS_NOX_XyceTests.h>
75 #include <N_UTL_FeatureTest.h>
76 
77 #ifdef Xyce_PARALLEL_MPI
78 #include <N_PDS_ParComm.h>
79 #else
80 #include <N_PDS_SerialComm.h>
81 #endif
82 
83 
84 // ---------- NOX Includes ----------
85 #include <LOCA.H>
86 
87 // ----------- Forward declarations -------
88 namespace Xyce {
89 namespace Nonlinear {
90 namespace N_NLS_NOX {
91 
92 //-----------------------------------------------------------------------------
93 // Function : Interface::Interface
94 // Purpose : constructor
95 // Special Notes :
96 // Scope : public
97 // Creator :
98 // Creation Date :
99 //-----------------------------------------------------------------------------
100 Interface::Interface(const IO::CmdParse & cp)
101  : Nonlinear::NonLinearSolver(cp),
102  dcParams_(Nonlinear::DC_OP),
103  transientParams_(Nonlinear::TRANSIENT),
104  hbParams_(Nonlinear::HB_MODE),
105  nlpParams_(Nonlinear::DC_NLPOISSON),
106  sharedSystemPtr_(0),
107  mode_(Nonlinear::DC_OP),
108  lastParametersMode_(Nonlinear::DC_OP),
109  parametersMode_(Nonlinear::DC_OP),
110  usemode_(true),
111  copiedGroupFlag_(false),
112  DCOPused_(false),
113  ICspecified_(false),
114  NODESETspecified_(false),
115  isFirstContinuationParam_(true),
116  firstSolveComplete_(false),
117  iParam_(0)
118 {
119 }
120 
121 //-----------------------------------------------------------------------------
122 // Function : Interface::~Interface
123 // Purpose : destructor
124 // Special Notes :
125 // Scope : public
126 // Creator :
127 // Creation Date :
128 //-----------------------------------------------------------------------------
130 {
131  delete sharedSystemPtr_;
132  if (!Teuchos::is_null(globalDataPtr_))
133  {
134  LOCA::destroyGlobalData(globalDataPtr_);
135  }
136 }
137 
138 //-----------------------------------------------------------------------------
139 // Function : Interface::setOptions
140 // Purpose : Passes option block corresponding to "NONLIN" onto
141 // nonlinear solver. These parameters set convergence
142 // tolerances, the type of method used, and so on.
143 // Special Notes :
144 // Return Type : boolean
145 //
146 // See also : setTranOptions, setAnalysisMode
147 //
148 // - Input Arguments -
149 //
150 // OB : Option block containing options corresponding to
151 // "NONLIN" in the netlist.
152 // Scope : public
153 // Creator :
154 // Creation Date :
155 //-----------------------------------------------------------------------------
156 bool Interface::setOptions(const Util::OptionBlock& OB)
157 {
158  return dcParams_.setOptions(OB);
159 }
160 
161 
162 //-----------------------------------------------------------------------------
163 // Function : Interface::setTranOptions
164 //
165 // Purpose : Passes option block corresponding to "NONLIN-TRAN" onto
166 // nonlinear solver. This affects the settings used when
167 // the mode is Transient.
168 //
169 // Special Notes :
170 // Return Type : boolean
171 //
172 // See also : setOptions, setAnalysisMode
173 //
174 // - Input Arguments -
175 // OB : Option block containing options corresponding to
176 // "NONLIN-TRAN" in the netlist.
177 // Scope : public
178 // Creator :
179 // Creation Date :
180 //-----------------------------------------------------------------------------
181 bool Interface::setTranOptions(const Util::OptionBlock& OB)
182 {
183  return transientParams_.setOptions(OB);
184 }
185 
186 //-----------------------------------------------------------------------------
187 // Function : Interface::setHBOptions
188 // Purpose :
189 // Scope : public
190 // Creator :
191 // Creation Date :
192 //-----------------------------------------------------------------------------
193 bool Interface::setHBOptions(const Util::OptionBlock& OB)
194 {
195  return hbParams_.setOptions(OB);
196 }
197 
198 
199 //-----------------------------------------------------------------------------
200 // Function : Interface::setNLPOptions
201 // Purpose :
202 // Scope : public
203 // Creator :
204 // Creation Date :
205 //-----------------------------------------------------------------------------
206 bool Interface::setNLPOptions(const Util::OptionBlock& OB)
207 {
208  return nlpParams_.setOptions(OB);
209 }
210 
211 //-----------------------------------------------------------------------------
212 // Function : Interface::setLocaOptions
213 // Purpose :
214 // Special Notes :
215 // Scope : public
216 // Creator :
217 // Creation Date :
218 //-----------------------------------------------------------------------------
219 bool Interface::setLocaOptions(const Util::OptionBlock& OB)
220 {
222  return dcParams_.setLocaOptions(OB);
223 }
224 
225 //-----------------------------------------------------------------------------
226 // Function : Interface::setDCOPRestartOptions
227 // Purpose :
228 // Special Notes :
229 // Scope : public
230 // Creator :
231 // Creation Date :
232 //-----------------------------------------------------------------------------
233 bool Interface::setDCOPRestartOptions(const Util::OptionBlock& OB)
234 {
235  DCOPspecified_ = true;
236  return true;
237 }
238 
239 //-----------------------------------------------------------------------------
240 // Function : Interface::setICOptions
241 // Purpose :
242 // Special Notes :
243 // Scope : public
244 // Creator :
245 // Creation Date :
246 //-----------------------------------------------------------------------------
247 bool Interface::setICOptions(const Util::OptionBlock& OB)
248 {
249  ICspecified_ = true;
250  return true;
251 }
252 
253 //-----------------------------------------------------------------------------
254 // Function : Interface::setNodeSetOptions
255 // Purpose :
256 // Special Notes :
257 // Scope : public
258 // Creator :
259 // Creation Date :
260 //-----------------------------------------------------------------------------
261 bool Interface::setNodeSetOptions(const Util::OptionBlock& OB)
262 {
263  NODESETspecified_ = true;
264  return true;
265 }
266 
267 //-----------------------------------------------------------------------------
268 // Function : Interface::initializeAll
269 //
270 // Purpose : Called after all register and set functions.
271 // Once the various registrations have taken place,
272 // this function sets the remaining pointers.
273 //
274 // Special Notes :
275 // Derived Notes : This function also calls the base object initializeAll.
276 //
277 // Special Notes: This function obtains the solution, temporary solution and
278 // f vectors from the LAS system class.
279 //
280 // Return Type : boolean
281 // Scope : public
282 // Creator : Eric Keiter
283 // Creation Date :
284 //-----------------------------------------------------------------------------
286 {
287  // Use the base class initialization
289  if (!initok)
290  {
291  return false;
292  }
293 
294  // Set the processor ID for printing in the nonlinear solver
295  // For now, processor 0 will output information to the screen
296  //int myPID = ((**nextSolVectorPtrPtr_).epetraObj()).Comm().MyPID();
297  int myPID = pdsMgrPtr_->getPDSComm()->procID();
298  dcParams_.setOutputOptions(myPID, 0);
300 
301  hbParams_.setOutputOptions(myPID, 0);
302 
303  // Set up the status tests
304  bool testsok = false;
305  if (NLS_MASKED_WRMS_NORMS)
306  {
307  testsok =
308  dcParams_.createStatusTests(pdsMgrPtr_->getPDSComm()->comm(), currSolVectorPtrPtr_, getLoader(), lasSysPtr_->getDeviceMaskVector()) &&
309  transientParams_.createStatusTests(pdsMgrPtr_->getPDSComm()->comm(), currSolVectorPtrPtr_, getLoader(), lasSysPtr_->getDeviceMaskVector()) &&
310  hbParams_.createStatusTests(pdsMgrPtr_->getPDSComm()->comm(), currSolVectorPtrPtr_, getLoader(), lasSysPtr_->getDeviceMaskVector());
311  nlpParams_.createStatusTests(pdsMgrPtr_->getPDSComm()->comm(), currSolVectorPtrPtr_, getLoader(), lasSysPtr_->getDeviceMaskVector());
312  }
313  else
314  {
315  testsok =
320  }
321 
322  if (!testsok)
323  return false;
324 
325  // Set up any linear solver options
326  // We only set the tolerance if adaptive forcing is being used.
327  setAZ_Tol_DC = false;
328  setAZ_Tol_Transient = false;
329  if (!(dcParams_.getNoxParams()->sublist("Direction").sublist("Newton")
330  .get("Forcing Term Method","Constant") == std::string("Constant")))
331  {
332  setAZ_Tol_DC = true;
333  }
334  if (!(transientParams_.getNoxParams()->sublist("Direction").sublist("Newton")
335  .get("Forcing Term Method", "Constant") == std::string("Constant")))
336  {
337  setAZ_Tol_Transient = true;
338  }
339  if (!(hbParams_.getNoxParams()->sublist("Direction").sublist("Newton")
340  .get("Forcing Term Method", "Constant") == std::string("Constant")))
341  {
342  setAZ_Tol_Transient = true;
343  }
344  if (!(nlpParams_.getNoxParams()->sublist("Direction").sublist("Newton")
345  .get("Forcing Term Method", "Constant") == std::string("Constant")))
346  {
347  setAZ_Tol_Transient = true;
348  }
349 
350  return true;
351 }
352 
353 //-----------------------------------------------------------------------------
354 // Function : Interface::spiceStrategy
355 //
356 // Purpose : This function attempts a stdNewton solve first, and if that
357 // fails then does gmin stepping. This is only done for DCOP
358 // calculations.
359 //
360 // Special Notes :
361 // Scope : public
362 // Creator : Eric Keiter
363 // Creation Date : 5/7/2014
364 //-----------------------------------------------------------------------------
366 {
367  groupPtr_->setNonContinuationFlag (true);
368  int isuccess = stdNewtonSolve (paramsPtr);
369 
370  if (isuccess < 0) // attempt gmin stepping.
371  {
372  int saveSolverType=paramsPtr->getNoxSolverType();
373  paramsPtr->setNoxSolverType(3);
374  groupPtr_->setNonContinuationFlag (false);
375 
376  rhsVectorPtr_->putScalar(0.0);
377  NewtonVectorPtr_->putScalar(0.0);
378  gradVectorPtr_->putScalar(0.0);
379  (*nextSolVectorPtrPtr_)->putScalar(0.0);
380 
382  groupPtr_->setX(tmpVec);
383 
385  *rhsVectorPtr_,
389  *lasSysPtr_,
390  *this);
391 
392  isuccess=gminSteppingSolve ( paramsPtr );
393  if (isuccess < 0)
394  {
395  paramsPtr->setNoxSolverType(34);
396  groupPtr_->setNonContinuationFlag (false);
397 
398  rhsVectorPtr_->putScalar(0.0);
399  NewtonVectorPtr_->putScalar(0.0);
400  gradVectorPtr_->putScalar(0.0);
401  (*nextSolVectorPtrPtr_)->putScalar(0.0);
402 
404  groupPtr_->setX(tmpVec);
405 
407  *rhsVectorPtr_,
411  *lasSysPtr_,
412  *this);
413 
414  isuccess=sourceSteppingSolve ( paramsPtr );
415  paramsPtr->setNoxSolverType(saveSolverType);
416  }
417  }
418  return isuccess;
419 
420 }
421 
422 //-----------------------------------------------------------------------------
423 // Function : Interface::opStartCont0
424 // Purpose :
425 // Special Notes : returns true if DCOP restart is being used.
426 //
427 // The "found" variable indicates if any of the nodes specified
428 // in the dcop start file were found in this circuit. If not,
429 // then don't bother with this.
430 //
431 // Scope : public
432 // Creator : Eric R. Keiter, SNL, Electrical and Microsystem Modeling
433 // Creation Date : 09/15/07
434 //-----------------------------------------------------------------------------
435 bool Interface::opStartCont0 (ParameterSet* paramsPtr, int found, int icType, IO::InitialConditionsData::NodeNamePairMap & op, const NodeNameMap & allNodes, N_PDS_Comm * pdsCommPtr)
436 {
437  bool usedOP = false;
438 
439  if (found > 0 && icType == IO::InitialConditionsData::IC_TYPE_DCOP_RESTART)
440  {
441  usedOP = true;
442  Teuchos::RCP<AugmentLinSys> als =
443  paramsPtr->createAugmentLinearSystem(lasSysPtr_, op, allNodes, pdsCommPtr);
444  groupPtr_->setAugmentLinearSystem(true, als);
445  NOX::StatusTest::StatusType status = solverPtr_->solve();
446  // Create a new solver after performing the initial op_start solve.
447  solverPtr_ = NOX::Solver::buildSolver(groupPtr_,
448  paramsPtr->getStatusTests(),
449  paramsPtr->getNoxParams());
450  firstSolveComplete_ = true;
451  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
452 
453 #ifdef Xyce_DEBUG_OP_START
454  groupPtr_->setOutputLinear (&op, &allNodes, pdsCommPtr);
455 #endif // debug op start
456 
457  }
458  return usedOP;
459 }
460 
461 
462 //-----------------------------------------------------------------------------
463 // Function : Interface::stdNewtonSolve
464 // Purpose :
465 // Special Notes : This corresponds to
466 // .options nonlin continuation=stan or
467 // .options nonlin continuation=0
468 // Scope : public
469 // Creator : Roger Pawlowski, Eric Keiter
470 // Creation Date :
471 //-----------------------------------------------------------------------------
473 {
474  bool usedIC=false;
475  bool usedNODESET=false;
476 
477  // RPP: needed for tensor method. DO NOT UNCOMMENT!
478  // This somehow breaks the one-shot test circuit.
479  // ERK: it breaks it (and probably many other circuits) b/c voltage
480  // limiting is fragile and cannot handle extra (unexpected)
481  // F-loads.
482  //groupPtr_->computeF();
483 
484  // Set up nox nonlinear solver. solverPtr is only needed for
485  // non-LOCA (i.e. just Newton's method, no continuation) solves.
486  if ( Teuchos::is_null(solverPtr_) || ((usemode_) && (lastParametersMode_ != parametersMode_)) )
487  {
488  if (DEBUG_NONLINEAR)
489  {
490  if ( Teuchos::is_null(solverPtr_) )
491  dout() << "Creating new NLS solver b/c it is 0." <<std::endl;
493  dout() << "Creating new NLS solver b/c starting next phase, post-DC." <<std::endl;
494  }
495 
496  solverPtr_ = NOX::Solver::buildSolver(groupPtr_,
497  paramsPtr->getStatusTests(),
498  paramsPtr->getNoxParams());
499  }
500  else // solverPtr is not null, and the mode didn't change since last call.
501  {
502  if (DEBUG_NONLINEAR)
503  dout() << "NOT Creating new NLS solver, just resetting." <<std::endl;
504 
505  solverPtr_->reset(groupPtr_->getX());
506  }
507 
508  // If .IC, .NODESET or .OP have been specified, then set up the
509  // augmented linear systems
510  if ((usemode_) && (mode_ != Nonlinear::TRANSIENT))
511  {
512  if (ICspecified_)
513  {
514  usedIC=icCont (paramsPtr);
515  }
516  else if (NODESETspecified_)
517  {
518  usedNODESET=nodesetCont0 (paramsPtr);
519  }
520  else
521  {
522  if (!DCOPused_) {
523  int found = 0;
524  int icType;
525  IO::InitialConditionsData::NodeNamePairMap & op = initialConditionsManager_->getICData(found, icType);
526  DCOPused_ = opStartCont0(paramsPtr, found, icType, op, outMgrPtr_->getSolutionNodeMap(), pdsMgrPtr_->getPDSComm());
528  }
529  }
530  }
531 
532  NOX::StatusTest::StatusType status = solverPtr_->solve();
533  firstSolveComplete_ = true;
534 
535  if (usedIC)
536  {
537  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
538  }
539  // Send back the correct return code
540  if (DEBUG_NONLINEAR)
541  dout() << "return code for transient params: " << transientParams_.getStatusTestReturnCode() <<std::endl
542  << "return code for hb params: " << hbParams_.getStatusTestReturnCode() << std::endl
543  << "return code for nlp params: " << nlpParams_.getStatusTestReturnCode() << std::endl
544  << "return code for dc params: " << dcParams_.getStatusTestReturnCode () << std::endl;
545 
546  return paramsPtr->getStatusTestReturnCode();
547 }
548 
549 //-----------------------------------------------------------------------------
550 // Function : Interface::naturalParameterContinuationSolve
551 // Purpose :
552 // Special Notes : This corresponds to
553 // .options nonlin continuation=nat or
554 // .options nonlin continuation=1
555 // Scope : public
556 // Creator : Roger Pawlowski, Eric Keiter
557 // Creation Date :
558 //-----------------------------------------------------------------------------
560 {
561  std::vector<std::string> pars;
562  std::string con;
563  int j, numParam = 0;
564  double value;
565  bool usedOP=false;
566  bool usedNODESET=false;
567  bool usedIC=false;
568 
569  if ((usemode_) && (mode_ != Nonlinear::TRANSIENT))
570  {
571  if (ICspecified_)
572  {
573  usedIC=icCont (paramsPtr);
574  }
575  else if (NODESETspecified_)
576  {
577  usedNODESET=nodesetCont1 (paramsPtr);
578  }
579  else
580  {
581  usedOP = opStartCont1 (paramsPtr);
582  }
583  }
584 
585  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
586 
587  // Create Parameter Vector and get the stepper parameter list.
588  LOCA::ParameterVector locaPVec;
589  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
590  Teuchos::ParameterList& stepSizeList = locaList->sublist("Step Size");
591 
592  while (paramsPtr->getVectorParam("CONPARAM", numParam, con))
593  {
594  pars.push_back(con);
595  numParam++;
596  }
597 
598  // Fail out if no parameters have been specified.
599  if ( numParam == 0 ) {
600  std::string message = "Using \"continuation=1\" requires a parameter to be set with the conparam keyword in the loca option block!";
601  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::USR_FATAL, message);
602  }
603 
604  // check if "skip df/dp" is true or false. If false, then this is probably an arclength
605  // continuation solve, and we need to make sure sensitivity arrays are allocated
606  const std::string strArg("Skip df/dp");
607  bool skipDFDP = stepperList.get(strArg, false);
608  if (!skipDFDP)
609  {
610  dsPtr_->allocateSensitivityArrays(lasSysPtr_->builder(), numParam);
611  }
612 
613  Teuchos::RCP<AugmentLinSys> als;
614 
615  std::vector<double> minValue(numParam, 0.);
616  std::vector<double> maxValue(numParam, 0.);
617  std::vector<double> initialValue(numParam, 0.);
618  std::vector<double> initialStepSize(numParam, 0.);
619  std::vector<double> minStepSize(numParam, 0.);
620  std::vector<double> maxStepSize(numParam, 0.);
621  std::vector<double> aggressiveness(numParam, 0.);
622 
623  // Check the size of params to make sure users provided all required data
624  std::vector<std::string> paramNames(0);
625  paramNames.push_back("MINVALUE");
626  paramNames.push_back("MAXVALUE");
627  paramNames.push_back("INITIALVALUE");
628  paramNames.push_back("INITIALSTEPSIZE");
629  paramNames.push_back("MINSTEPSIZE");
630  paramNames.push_back("MAXSTEPSIZE");
631  paramNames.push_back("AGGRESSIVENESS");
632 
633  for (std::size_t p = 0 ; p < paramNames.size() ; ++p) {
634  if ( paramsPtr->getVectorParamSize(paramNames[p]) != numParam) {
635  std::string msg = "The parameter \"" +
636  paramNames[p] +
637  "\" must have a list of values with size equal to the numParamber of parameters specified in \"conparam\".";
638  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, msg);
639  }
640  }
641 
642  for (iParam_=0 ; iParam_<numParam ; ++iParam_)
643  {
644  paramsPtr->getVectorParam("MINVALUE", iParam_, value);
645  minValue[iParam_] = value;
646 
647  paramsPtr->getVectorParam("MAXVALUE", iParam_, value);
648  maxValue[iParam_] = value;
649 
650  paramsPtr->getVectorParam("INITIALVALUE", iParam_, value);
651  initialValue[iParam_] = value;
652 
653  paramsPtr->getVectorParam("INITIALSTEPSIZE", iParam_, value);
654  initialStepSize[iParam_] = value;
655 
656  paramsPtr->getVectorParam("MINSTEPSIZE", iParam_, value);
657  minStepSize[iParam_] = value;
658 
659  paramsPtr->getVectorParam("MAXSTEPSIZE", iParam_, value);
660  maxStepSize[iParam_] = value;
661 
662  paramsPtr->getVectorParam("AGGRESSIVENESS", iParam_, value);
663  aggressiveness[iParam_] = value;
664 
665  locaPVec.addParameter (pars[iParam_], initialValue[iParam_]);
666 
667  }
668 
669  if (usedOP || usedNODESET)
670  {
671  const N_NLS_LOCA::Group & conLocaGrp =
672  dynamic_cast<const N_NLS_LOCA::Group&>(solverPtr_->getSolutionGroup());
673  *groupPtr_ = const_cast<N_NLS_LOCA::Group&>(conLocaGrp);
674  solverPtr_ = Teuchos::null;
675  }
676 
677  groupPtr_->setParams(locaPVec);
678 
679  LOCA::Abstract::Iterator::IteratorStatus locaStatus;
680 
681  for (iParam_=0 ; iParam_<numParam ; ++iParam_)
682  {
683  // Copy out the solution and use it in the next run
684  if (iParam_ > 0)
685  {
686  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
687  }
688 
689  stepperList.set("Continuation Parameter", pars[iParam_]);
690  stepperList.set("Initial Value", initialValue[iParam_]);
691  stepperList.set("Max Value", maxValue[iParam_]);
692  stepperList.set("Min Value", minValue[iParam_]);
693  stepSizeList.set("Initial Step Size", initialStepSize[iParam_]);
694  stepSizeList.set("Min Step Size", minStepSize[iParam_]);
695  stepSizeList.set("Max Step Size", maxStepSize[iParam_]);
696  stepSizeList.set("Aggressiveness", aggressiveness[iParam_]);
697 
698  for (j=0 ; j<iParam_ ; ++j)
699  {
700  locaPVec.setValue(pars[j], maxValue[j]);
701  }
702  for (j=iParam_ ; j<numParam ; ++j)
703  {
704  locaPVec.setValue(pars[j], initialValue[j]);
705  }
706  groupPtr_->setParams(locaPVec);
707 
708  if (iParam_==0)
709  {
710  if (!usedOP && !usedNODESET) // (usedOP and usedNODESET have already loaded F)
711  {
712  groupPtr_->computeF();
713  }
714  }
715 
716  // RPP 03/08/2006 If this is a special parameter used in voltage
717  // node resistance (Spice's GMIN stepping) then we need to
718  // intercept and handle the parameter in the solver (in the LOCA
719  // Group) - the device package does nothing for this parameter.
720  if (pars[iParam_] != "GSTEPPING")
721  {
722  // Do the continuation run
724  locaStatus = stepperPtr_->run();
725  if (usedIC || usedNODESET)
726  {
727  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
728  }
729  }
730  else
731  {
732  if (iParam_ == 0 && DCOPused_)
733  {
734  std::string message = "'.dcop input=' and gstepping are incompatible";
735  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::USR_FATAL, message);
736  }
737  Teuchos::RCP<AugmentLinSys> als =
739  groupPtr_->setAugmentLinearSystem(true, als);
740 
741  // Do the continuation run
743  locaStatus = stepperPtr_->run();
744 
745  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
746  }
747 
748  // Kick out if continuation failed
749  if (locaStatus != LOCA::Abstract::Iterator::Finished)
750  return (-1);
751 
752  // Increment Param Number Tracking
754  firstSolveComplete_ = true;
755  }
756  return (paramsPtr->getStatusTestReturnCode());
757 }
758 
759 //-----------------------------------------------------------------------------
760 // Function : Interface::mosfetContinuationSolve
761 // Purpose :
762 // Special Notes : This corresponds to
763 // .options nonlin continuation=mos or
764 // .options nonlin continuation=2
765 // Scope : public
766 // Creator : Roger Pawlowski, Eric Keiter
767 // Creation Date :
768 //-----------------------------------------------------------------------------
770 {
771  bool usedOP=false;
772  bool usedNODESET=false;
773  bool usedIC=false;
774 
775  if ((usemode_) && (mode_ != Nonlinear::TRANSIENT))
776  {
777  if (ICspecified_)
778  {
779  usedIC=icCont (paramsPtr);
780  }
781  else if (NODESETspecified_)
782  {
783  usedNODESET=nodesetCont1 (paramsPtr);
784  }
785  else
786  {
787  usedOP = opStartCont1 (paramsPtr);
788  }
789  }
790 
791  // check if use specified vector params. If so, flag a warning.
792  std::vector<std::string> pars;
793  std::string con;
794  int numParam;
795  while (paramsPtr->getVectorParam("CONPARAM", numParam, con))
796  {
797  pars.push_back(con);
798  numParam++;
799  }
800 
801  if ( numParam > 1 ) {
802  Report::UserWarning() << "Using \"continuation=2\" currently does not support vectorized loca parameters. Only the first values in each list will be used";
803  }
804 
805  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
806 
807  // Create the continuation parameter names
808  std::string gain = "mosfet:gainscale";
809  std::string nonlinear = "mosfet:nltermscale";
810 
811  // Create Parameter Vector and get the stepper parameter list.
812  LOCA::ParameterVector locaPVec;
813  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
814  Teuchos::ParameterList& predictorList = locaList->sublist("Predictor");
815  Teuchos::ParameterList& stepSizeList = locaList->sublist("Step Size");
816 
817  // Continuation solve from alpha2 (gain) = 0.0 -> 1.0
818  // with alpha1 (nlterm) = 0.0 (constant)
819  locaPVec.addParameter(gain, 0.0);
820  locaPVec.addParameter(nonlinear, 0.0);
821  groupPtr_->setParams(locaPVec);
822  stepperList.set("Continuation Parameter", gain);
823 
824  stepperList.set("Initial Value", 0.0);
825  stepperList.set("Max Value", 1.0);
826  stepperList.set("Min Value",-1.0);
827 
828  stepSizeList.set("Initial Step Size", 0.2);
829  stepSizeList.set("Min Step Size", 1.0e-4);
830  stepSizeList.set("Max Step Size", 1.0);
831  stepSizeList.set("Aggressiveness", 1.0);
832 
833  // assert the user-specified defaults, if any.
835 
836  // Initialize parameters in xyce
837  if (!usedOP && !usedNODESET) // (usedOP and usedNODESET have already loaded F)
838  {
839  groupPtr_->computeF();
840  }
841 
842  // Do the continuation run
843  iParam_ = 0;
845  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
846 
847  // Kick out if continuation failed
848  if (locaStatus != LOCA::Abstract::Iterator::Finished)
849  return (-1);
850 
851  // Increment Param Number Tracking
853  firstSolveComplete_ = true;
854 
855  // Copy out the solution and use it in the next run
856  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
857 
858  // Continuation solve from alpha1 (nlterm) = 0.0 -> 1.0
859  // with alpha2 (gain) = 1.0 (constant)
860  stepperList.set("Continuation Parameter", nonlinear);
861 
862  stepperList.set("Initial Value", 0.0);
863  stepperList.set("Max Value", 1.0);
864  stepperList.set("Min Value",-1.0);
865 
866  stepSizeList.set("Initial Step Size", 0.2);
867  stepSizeList.set("Min Step Size", 1.0e-4);
868  stepSizeList.set("Max Step Size", 1.0);
869  stepSizeList.set("Aggressiveness", 1.0);
870 
871  // assert the user-specified defaults, if any.
873 
874  locaPVec.setValue(gain, 1.0);
875  locaPVec.setValue(nonlinear, 0.0);
876  groupPtr_->setParams(locaPVec);
877 
878  // Do the continuation run
879  iParam_ = 1;
881  locaStatus = stepperPtr_->run();
882 
883  if (usedIC)
884  {
885  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
886  }
887 
888  // Return the solution status
889  if (locaStatus != LOCA::Abstract::Iterator::Finished)
890  return (-1);
891  else
892  return (paramsPtr->getStatusTestReturnCode());
893 }
894 
895 //-----------------------------------------------------------------------------
896 // Function : Interface::mosfetContinuationSolve2
897 // Purpose :
898 // Return Type :
899 // Special Notes : This corresponds to
900 // .options nonlin continuation=newmos or
901 // .options nonlin continuation=4
902 // Scope : public
903 // Creator : Roger Pawlowski, Eric Keiter
904 // Creation Date : 2/21/2004
905 //-----------------------------------------------------------------------------
907 {
908  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
909 
910  // Create the continuation parameter names
911  std::string gain = "mosfet:gainscale";
912  std::string nonlinear = "mosfet:nltermscale";
913  std::string size = "mosfet:sizescale";
914 
915  // Create Parameter Vector and get the stepper parameter list.
916  LOCA::ParameterVector locaPVec;
917  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
918 
919  // Continuation solve from alpha2 (gain) = 0.0 -> 1.0
920  // with alpha1 (nlterm) = 0.0 (constant)
921  // sizeScale = 0.0 (constant)
922  locaPVec.addParameter(gain, 0.0);
923  locaPVec.addParameter(nonlinear, 0.0);
924  locaPVec.addParameter(size, 0.0);
925  groupPtr_->setParams(locaPVec);
926  stepperList.set("Continuation Parameter", gain);
927  stepperList.set("Initial Value", 0.0);
928  stepperList.set("Max Value", 1.0);
929 
930  // Initialize parameters in xyce
931  groupPtr_->computeF();
932 
933  // Do the continuation run
935  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
936 
937  // Kick out if continuation failed
938  if (locaStatus != LOCA::Abstract::Iterator::Finished)
939  return (-1);
940 
941  // Increment Param Number Tracking
943  firstSolveComplete_ = true;
944 
945  // Copy out the solution and use it in the next run
946  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
947 
948  // Continuation solve from alpha1 (nlterm) = 0.0 -> 1.0
949  // with alpha2 (gain) = 1.0 (constant)
950  // with size (scale) = 0.0 (constant)
951  stepperList.set("Continuation Parameter", nonlinear);
952  stepperList.set("Initial Value", 0.0);
953  stepperList.set("Max Value", 1.0);
954  locaPVec.setValue(gain, 1.0);
955  locaPVec.setValue(nonlinear, 0.0);
956  locaPVec.setValue(size, 0.0);
957  groupPtr_->setParams(locaPVec);
958 
959  // Do the continuation run
961  locaStatus = stepperPtr_->run();
962 
963  // Kick out if continuation failed
964  if (locaStatus != LOCA::Abstract::Iterator::Finished)
965  return (-1);
966 
967  // Copy out the solution and use it in the next run
968  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
969 
970  // Continuation solve from alpha1 (nlterm) = 1.0 -> 1.0
971  // with alpha2 (gain) = 1.0 (constant)
972  // with size (scale) = 0.0 -> 1.0
973  stepperList.set("Continuation Parameter", size);
974  stepperList.set("Initial Value", 0.0);
975  stepperList.set("Max Value", 1.0);
976  locaPVec.setValue(gain, 1.0);
977  locaPVec.setValue(nonlinear, 1.0);
978  locaPVec.setValue(size, 0.0);
979  groupPtr_->setParams(locaPVec);
980 
981  // Do the continuation run
983  locaStatus = stepperPtr_->run();
984 
985  // Return the solution status
986  if (locaStatus != LOCA::Abstract::Iterator::Finished)
987  return (-1);
988  else
989  return (paramsPtr->getStatusTestReturnCode());
990 }
991 
992 //-----------------------------------------------------------------------------
993 // Function : Interface::mosfetContinuationSolve3
994 // Purpose : (5) Mosfet:BSIM3:Inverter specific continuation
995 // Special Notes : This corresponds to
996 // .options nonlin continuation=bsim3inv1 or
997 // .options nonlin continuation=5
998 // Scope : public
999 // Creator : Roger Pawlowski, Eric Keiter
1000 // Creation Date : 2/25/2004
1001 //-----------------------------------------------------------------------------
1003 {
1004  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1005 
1006  // Create the continuation parameter names
1007  //std::string gain = "mosfet:gainscale";
1008  std::string nonlinear = "mosfet:nltermscale";
1009  std::string size = "mosfet:sizescale";
1010 
1011  // Create Parameter Vector and get the stepper parameter list.
1012  LOCA::ParameterVector locaPVec;
1013  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1014 
1015  // Continuation solve from alpha2 (gain) = 0.0 -> 1.0
1016  // with alpha1 (nlterm) = 0.0 (constant)
1017  // sizeScale = 0.0 (constant)
1018  //locaPVec.addParameter(gain, 0.0);
1019  locaPVec.addParameter(nonlinear, 0.0);
1020  locaPVec.addParameter(size, 0.0);
1021  groupPtr_->setParams(locaPVec);
1022  stepperList.set("Continuation Parameter", nonlinear);
1023  stepperList.set("Initial Value", 0.0);
1024  stepperList.set("Max Value", 1.0);
1025 
1026  // Initialize parameters in xyce
1027  groupPtr_->computeF();
1028 
1029  // Do the continuation run
1031  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
1032 
1033  // Kick out if continuation failed
1034  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1035  return (-1);
1036 
1037  // Increment Param Number Tracking
1038  isFirstContinuationParam_ = false;
1039  firstSolveComplete_ = true;
1040 
1041  // Copy out the solution and use it in the next run
1042  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
1043 
1044  // Continuation solve from alpha1 (nlterm) = 0.0 -> 1.0
1045  // with alpha2 (gain) = 1.0 (constant)
1046  // with size (scale) = 0.0 (constant)
1047  stepperList.set("Continuation Parameter", size);
1048  stepperList.set("Initial Value", 0.0);
1049  stepperList.set("Max Value", 1.0);
1050  //locaPVec.setValue(gain, 1.0);
1051  locaPVec.setValue(nonlinear, 1.0);
1052  locaPVec.setValue(size, 0.0);
1053  groupPtr_->setParams(locaPVec);
1054 
1055  // Do the continuation run
1057  locaStatus = stepperPtr_->run();
1058 
1059  // Return the solution status
1060  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1061  return (-1);
1062  else
1063  return (paramsPtr->getStatusTestReturnCode());
1064 }
1065 
1066 //-----------------------------------------------------------------------------
1067 // Function : Interface::mosfetContinuationSolve4
1068 // Purpose : (6) Mosfet:BSIM3:Inverter specific continuation
1069 // Special Notes : This corresponds to
1070 // .options nonlin continuation=bsim3inv2 or
1071 // .options nonlin continuation=6
1072 // Scope : public
1073 // Creator : Roger Pawlowski, Eric Keiter
1074 // Creation Date : 2/25/2004
1075 //-----------------------------------------------------------------------------
1077 {
1078  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1079 
1080  // Create the continuation parameter names
1081  std::string gain = "mosfet:gainscale";
1082  std::string nonlinear = "mosfet:nltermscale";
1083  std::string size = "mosfet:sizescale";
1084 
1085  // Create Parameter Vector and get the stepper parameter list.
1086  LOCA::ParameterVector locaPVec;
1087  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1088 
1089  // Continuation solve
1090  locaPVec.addParameter(gain, 1.0);
1091  locaPVec.addParameter(nonlinear, 1.0);
1092  locaPVec.addParameter(size, 0.0);
1093  groupPtr_->setParams(locaPVec);
1094  stepperList.set("Continuation Parameter", size);
1095  stepperList.set("Initial Value", 0.0);
1096  stepperList.set("Max Value", 1.0);
1097 
1098  // Initialize parameters in xyce
1099  groupPtr_->computeF();
1100 
1101  // Do the continuation run
1103  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
1104 
1105  // Return the solution status
1106  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1107  return (-1);
1108  else
1109  {
1110  firstSolveComplete_ = true;
1111  return (paramsPtr->getStatusTestReturnCode());
1112  }
1113 }
1114 
1115 //-----------------------------------------------------------------------------
1116 // Function : Interface::mosfetContinuationSolve5
1117 // Purpose :
1118 // Return Type :
1119 // Special Notes : This corresponds to
1120 // .options nonlin continuation=test or
1121 // .options nonlin continuation=8
1122 // Scope : public
1123 // Creator : Roger Pawlowski, Eric Keiter
1124 // Creation Date : 2/25/2004
1125 //-----------------------------------------------------------------------------
1127 {
1128  // Get some initial objects
1129  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1130  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1131  LOCA::ParameterVector locaPVec;
1132 
1133  // Create storage for continuation objects
1134  int numHomotopyContinuationRuns = 1;
1135  std::vector<std::string> names(numHomotopyContinuationRuns);
1136  std::vector<double> initialVal(numHomotopyContinuationRuns);
1137  std::vector<double> finalVal(numHomotopyContinuationRuns);
1138  std::vector<double> minVal(numHomotopyContinuationRuns);
1139  std::vector<double> maxVal(numHomotopyContinuationRuns);
1140 
1141  // Set up continuation steps
1142  // ***************************************************
1143  // Changes vals below for continuation
1144  // ***************************************************
1145  names[0] = "mosfet:gainscale";
1146  //names[1] = "mosfet:nltermscale";
1147  //names[2] = "mosfet:sizescale";
1148  //names[2] = "mosfet:l";
1149  initialVal[0] = 0.0;
1150  //initialVal[1] = 0.0;
1151  //initialVal[2] = 0.0;
1152  finalVal[0] = 1.0;
1153  //finalVal[1] = 1.0;
1154  //finalVal[2] = 1.0;
1155  // ***************************************************
1156  std::string n1 = "mosfet:nltermscale";
1157  locaPVec.addParameter(n1, 0.0);
1158  //std::string n2 = "mosfet:sizescale";
1159  //locaPVec.addParameter(n2, 0.0);
1160  // ***************************************************
1161  // ***************************************************
1162 
1163  // Ste up max/min bounds
1164  for (int i = 0; i < names.size(); ++i) {
1165  if (finalVal[i] > initialVal[i]) {
1166  minVal[i] = initialVal[i];
1167  maxVal[i] = finalVal[i];
1168  }
1169  else {
1170  minVal[i] = finalVal[i];
1171  maxVal[i] = initialVal[i];
1172  }
1173  }
1174 
1175  // Initialize loca parameter vector
1176  for (int i = 0; i < names.size(); ++i)
1177  locaPVec.addParameter(names[i], initialVal[i]);
1178 
1179  LOCA::Abstract::Iterator::IteratorStatus locaStatus;
1180 
1181  LOCA::StatusTest::Wrapper test(paramsPtr->getStatusTests());
1182 
1183  // Loop over the number of homotopy steps
1184  for (int hs = 0; hs < names.size(); ++hs) {
1185  for (int i = 0; i < names.size(); ++i) {
1186  if (i >= hs)
1187  locaPVec.setValue(names[i], initialVal[i]);
1188  else
1189  locaPVec.setValue(names[i], finalVal[i]);
1190  }
1191  groupPtr_->setParams(locaPVec);
1192  stepperList.set("Continuation Parameter", names[hs]);
1193  stepperList.set("Initial Value", initialVal[hs]);
1194  stepperList.set("Min Value", minVal[hs]);
1195  stepperList.set("Max Value", maxVal[hs]);
1196 
1197  // Initialize parameters in xyce
1198  groupPtr_->computeF();
1199 
1200  // Do the continuation run
1202  locaStatus = stepperPtr_->run();
1203 
1204  // Kick out if continuation failed
1205  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1206  return (-1);
1207 
1208  // Increment Param Number Tracking
1209  isFirstContinuationParam_ = false;
1210  firstSolveComplete_ = true;
1211 
1212  // Copy out the solution and use it in the next run
1213  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
1214  }
1215 
1216  // Return converged solver code
1217  return (paramsPtr->getStatusTestReturnCode());
1218 }
1219 
1220 //-----------------------------------------------------------------------------
1221 // Function : Interface::mosfetContinuationSolve6
1222 // Purpose :
1223 // Special Notes : This corresponds to
1224 // .options nonlin continuation=power or
1225 // .options nonlin continuation=10
1226 // Scope : public
1227 // Creator : Roger Pawlowski, Eric Keiter
1228 // Creation Date : 2/25/2004
1229 //-----------------------------------------------------------------------------
1231 {
1232  // Get some initial objects
1233  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1234  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1235  LOCA::ParameterVector locaPVec;
1236 
1237  // Create storage for continuation objects
1238  int numHomotopyContinuationRuns = 4;
1239  std::vector<std::string> names(numHomotopyContinuationRuns);
1240  std::vector<double> initialVal(numHomotopyContinuationRuns);
1241  std::vector<double> finalVal(numHomotopyContinuationRuns);
1242  std::vector<double> minVal(numHomotopyContinuationRuns);
1243  std::vector<double> maxVal(numHomotopyContinuationRuns);
1244 
1245  // Set up continuation steps
1246  // ***************************************************
1247  // Changes vals below for continuation
1248  // ***************************************************
1249  names[0] = stepperList.get("Power Node", "VA:V0");
1250  names[1] = "mosfet:gainscale";
1251  names[2] = "mosfet:nltermscale";
1252  names[3] = "mosfet:sizescale";
1253  initialVal[0] = 0.0;
1254  initialVal[1] = 0.0;
1255  initialVal[2] = 0.0;
1256  initialVal[3] = 0.0;
1257  finalVal[0] = 1.0;
1258  finalVal[1] = 1.0;
1259  finalVal[2] = 1.0;
1260  finalVal[3] = 1.0;
1261  // ***************************************************
1262  //std::string n1 = "mosfet:nltermscale";
1263  //locaPVec.addParameter(n1, 0.0);
1264  //std::string n2 = "mosfet:sizescale";
1265  //locaPVec.addParameter(n2, 0.0);
1266  // ***************************************************
1267  // ***************************************************
1268 
1269  // Set up max/min bounds
1270  for (int i = 0; i < names.size(); ++i) {
1271  if (finalVal[i] > initialVal[i]) {
1272  minVal[i] = initialVal[i];
1273  maxVal[i] = finalVal[i];
1274  }
1275  else {
1276  minVal[i] = finalVal[i];
1277  maxVal[i] = initialVal[i];
1278  }
1279  }
1280 
1281  // Initialize loca parameter vector
1282  for (int i = 0; i < names.size(); ++i)
1283  locaPVec.addParameter(names[i], initialVal[i]);
1284 
1285  LOCA::Abstract::Iterator::IteratorStatus locaStatus;
1286 
1287  // Loop over the number of homotopy steps
1288  for (int hs = 0; hs < names.size(); ++hs) {
1289  for (int i = 0; i < names.size(); ++i) {
1290  if (i >= hs)
1291  locaPVec.setValue(names[i], initialVal[i]);
1292  else
1293  locaPVec.setValue(names[i], finalVal[i]);
1294  }
1295  groupPtr_->setParams(locaPVec);
1296  stepperList.set("Continuation Parameter", names[hs]);
1297  stepperList.set("Initial Value", initialVal[hs]);
1298  stepperList.set("Min Value", minVal[hs]);
1299  stepperList.set("Max Value", maxVal[hs]);
1300 
1301  // Initialize parameters in xyce
1302  groupPtr_->computeF();
1303 
1304  // Do the continuation run
1306  locaStatus = stepperPtr_->run();
1307 
1308  // Kick out if continuation failed
1309  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1310  return (-1);
1311 
1312  firstSolveComplete_ = true;
1313 
1314  // Copy out the solution and use it in the next run
1315  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
1316  }
1317 
1318  // Return converged solver code
1319  return (paramsPtr->getStatusTestReturnCode());
1320 }
1321 
1322 //-----------------------------------------------------------------------------
1323 // Function : Interface::blockGainscaleMosfetSolve
1324 // Purpose :
1325 // Special Notes : This corresponds to
1326 // .options nonlin continuation=blockgain or
1327 // .options nonlin continuation=7
1328 // Scope : public
1329 // Creator : Roger Pawlowski, Eric Keiter
1330 // Creation Date :
1331 //-----------------------------------------------------------------------------
1333 {
1334  // Get some initial objects
1335  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1336  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1337  LOCA::ParameterVector locaPVec;
1338 
1339  // Create storage for continuation objects
1340  int numGainBlocks = nonlinearEquationLoader_->getHomotopyBlockSize();
1341  int numHomotopyContinuationRuns = 1 + numGainBlocks;
1342  std::vector<std::string> names(numHomotopyContinuationRuns);
1343  std::vector<double> initialVal(numHomotopyContinuationRuns);
1344  std::vector<double> finalVal(numHomotopyContinuationRuns);
1345  std::vector<double> minVal(numHomotopyContinuationRuns);
1346  std::vector<double> maxVal(numHomotopyContinuationRuns);
1347 
1348  // Set up continuation steps
1349  // ***************************************************
1350  // Changes vals below for continuation
1351  // ***************************************************
1352  for (int i = 0; i < numGainBlocks; ++i) {
1353  std::stringstream s;
1354  s << i;
1355  names[i] = "mosfet:gainscale_block_" + s.str();
1356  initialVal[i] = 0.0;
1357  finalVal[i] = 1.0;
1358  }
1359  names[numHomotopyContinuationRuns - 1] = "mosfet:nltermscale";
1360  initialVal[numHomotopyContinuationRuns - 1] = 0.0;
1361  finalVal[numHomotopyContinuationRuns - 1] = 1.0;
1362  // ***************************************************
1363  // ***************************************************
1364 
1365  // Ste up max/min bounds
1366  for (int i = 0; i < names.size(); ++i) {
1367  if (finalVal[i] > initialVal[i]) {
1368  minVal[i] = initialVal[i];
1369  maxVal[i] = finalVal[i];
1370  }
1371  else {
1372  minVal[i] = finalVal[i];
1373  maxVal[i] = initialVal[i];
1374  }
1375  }
1376 
1377  // Initialize loca parameter vector
1378  for (int i = 0; i < names.size(); ++i)
1379  locaPVec.addParameter(names[i], initialVal[i]);
1380 
1381  LOCA::Abstract::Iterator::IteratorStatus locaStatus;
1382 
1383  // Loop over the number of homotopy steps
1384  for (int hs = 0; hs < names.size(); ++hs) {
1385  for (int i = 0; i < names.size(); ++i) {
1386  if (i >= hs)
1387  locaPVec.setValue(names[i], initialVal[i]);
1388  else
1389  locaPVec.setValue(names[i], finalVal[i]);
1390  }
1391  groupPtr_->setParams(locaPVec);
1392  stepperList.set("Continuation Parameter", names[hs]);
1393  stepperList.set("Initial Value", initialVal[hs]);
1394  stepperList.set("Min Value", minVal[hs]);
1395  stepperList.set("Max Value", maxVal[hs]);
1396 
1397  // Initialize parameters in xyce
1398  groupPtr_->computeF();
1399 
1400  // Do the continuation run
1402  locaStatus = stepperPtr_->run();
1403 
1404  // Kick out if continuation failed
1405  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1406  return (-1);
1407 
1408  // Increment Param Number Tracking
1409  isFirstContinuationParam_ = false;
1410  firstSolveComplete_ = true;
1411 
1412  // Copy out the solution and use it in the next run
1413  groupPtr_->copy(*(stepperPtr_->getSolutionGroup()));
1414  }
1415 
1416  // Return converged solver code
1417  return (paramsPtr->getStatusTestReturnCode());
1418 }
1419 
1420 //-----------------------------------------------------------------------------
1421 // Function : Interface::gminSteppingSolve
1422 // Purpose :
1423 // Special Notes : This corresponds to
1424 // .options nonlin continuation=gmin or
1425 // .options nonlin continuation=3
1426 // Scope : public
1427 // Creator : Roger Pawlowski, Eric Keiter
1428 // Creation Date :
1429 //-----------------------------------------------------------------------------
1431 {
1432  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1433 
1434  // Create the continuation parameter names
1435  std::string gmin = "GSTEPPING";
1436 
1437  // Create Parameter Vector and get the stepper parameter list.
1438  LOCA::ParameterVector locaPVec;
1439  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1440  Teuchos::ParameterList& predictorList = locaList->sublist("Predictor");
1441  Teuchos::ParameterList& stepSizeList = locaList->sublist("Step Size");
1442 
1443  // Continuation solve using Gmin stepping.
1444  locaPVec.addParameter(gmin, 0.0);
1445  groupPtr_->setParams(locaPVec);
1446  stepperList.set("Continuation Parameter", gmin);
1447  stepperList.set("Continuation Method", "Natural");
1448 
1449  stepSizeList.set("Method", "Adaptive");
1450  predictorList.set("Method", "Constant");
1451 
1452  stepperList.set("Initial Value", 4.0);
1453  stepperList.set("Min Value", -4.0);
1454  paramsPtr->set_gstepping_min_value (-4.0);
1455  stepperList.set("Max Value", 4.0);
1456 
1457  stepSizeList.set("Initial Step Size", -2.0);
1458  stepSizeList.set("Min Step Size", 1.0e-6);
1459  stepSizeList.set("Max Step Size", 1.0e+12);
1460  stepSizeList.set("Aggressiveness", 0.01);
1461 
1462  stepperList.set("Max Steps", 400);
1463  stepperList.set("Max Nonlinear Iterations", 20);
1464 
1465  // the following set of if-statemtents call functions that
1466  // allocate augmented linear systems for various scenarios.
1467  // It is important that the augmented systems get allocated
1468  // after the paramter (above) have been set.
1469  bool usedOP=false;
1470  bool usedNODESET=false;
1471  bool usedIC=false;
1472 
1473  if ((usemode_) && (mode_ != Nonlinear::TRANSIENT))
1474  {
1475  if (ICspecified_)
1476  {
1477  usedIC=icCont3 (paramsPtr);
1478  }
1479  else if (NODESETspecified_)
1480  {
1481  usedNODESET=nodesetCont1 (paramsPtr);
1482  }
1483  else
1484  {
1485  usedOP = opStartCont1 (paramsPtr);
1486  }
1487  }
1488 
1489  // Initialize parameters in xyce
1490  if (!usedOP && !usedNODESET) // (usedOP and usedNODESET have already loaded F)
1491  {
1492  groupPtr_->computeF();
1493  }
1494 
1495  // Do the continuation run
1496  iParam_ = 0;
1497  if (iParam_ == 0 && DCOPused_)
1498  {
1499  std::string message = "'.dcop input=' and gstepping are incompatible";
1500  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::USR_FATAL, message);
1501  }
1502  if (!usedIC)
1503  {
1504  Teuchos::RCP<AugmentLinSys> als =
1506  groupPtr_->setAugmentLinearSystem(true, als);
1507  }
1508 
1509  // Do the continuation run
1511  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
1512 
1513  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
1514 
1515  // Kick out if continuation failed
1516  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1517  return (-1);
1518  else
1519  return (paramsPtr->getStatusTestReturnCode());
1520 }
1521 
1522 //-----------------------------------------------------------------------------
1523 // Function : Interface::pseudoTransientSolve
1524 // Purpose :
1525 // Special Notes : This corresponds to
1526 // .options nonlin continuation=pseudo or
1527 // .options nonlin continuation=9
1528 // Scope :
1529 // Creator :
1530 // Creation Date :
1531 //-----------------------------------------------------------------------------
1533 {
1534  Teuchos::RCP<NOX::StatusTest::Combo> ctest =
1535  Teuchos::rcp(new NOX::StatusTest::Combo(NOX::StatusTest::Combo::OR));
1536 
1537  Teuchos::RCP<Teuchos::ParameterList> locaList =
1538  paramsPtr->getLocaParams();
1539  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1540  Teuchos::ParameterList& stepSizeList = locaList->sublist("Step Size");
1541  double initialStepSize =
1542  stepSizeList.get("Initial Step Size", 1.0e-3);
1543  double minStepSize = stepSizeList.get("Min Step Size", 1.0e-12);
1544  double maxStepSize = stepSizeList.get("Max Step Size", 1.0e4);
1545  Teuchos::RCP<Teuchos::ParameterList> noxList =
1546  paramsPtr->getNoxParams();
1547 
1548  // Create Pseudo Transient status tests.
1549  //paramsPtr->getStatusTests()
1550  Teuchos::RCP<NOX::StatusTest::MaxIters> mi =
1551  Teuchos::rcp(new NOX::StatusTest::MaxIters(stepperList.get("Max Steps", 200)));
1552  Teuchos::RCP<NOX::StatusTest::FiniteValue> fv =
1553  Teuchos::rcp(new NOX::StatusTest::FiniteValue);
1554  Teuchos::RCP<PseudoTransientTest> pt =
1555  Teuchos::rcp(new PseudoTransientTest(maxStepSize, 1.0e-8));
1556 
1557  ctest->addStatusTest(mi);
1558  ctest->addStatusTest(fv);
1559  ctest->addStatusTest(pt);
1560 
1561  // First solve - pseudo transient
1562 
1563  Teuchos::RCP<AugmentLinSys> als =
1565 
1566  solverPtr_ = Teuchos::rcp(new PseudoTransientBased(als,
1567  groupPtr_,
1568  ctest,
1569  noxList,
1570  initialStepSize,
1571  minStepSize,
1572  maxStepSize));
1573 
1574  NOX::StatusTest::StatusType status = solverPtr_->solve();
1575  firstSolveComplete_ = true;
1576 
1577  // RPP 3/7/2006: We don't care if pseudo transient solve fails the
1578  // solve() call above. This is just to get an inital guess for
1579  // the corrector step in the next solve. So we don't check the
1580  // status at this point.
1581 
1582  // Turn off pseudo transient in groups. (this is also done in the
1583  // pseudo transient solver, but just being safe - groups could be
1584  // different).
1585  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
1586 
1587  // Second solve is the correct steady state solve
1588  solverPtr_ = NOX::Solver::buildSolver(groupPtr_,
1589  paramsPtr->getStatusTests(),
1590  paramsPtr->getNoxParams());
1591  status = solverPtr_->solve();
1592 
1593  // Send back the correct return code
1594  return (paramsPtr->getStatusTestReturnCode());
1595 }
1596 
1597 //-----------------------------------------------------------------------------
1598 // Function : Interface::artificialParameterHomotopy
1599 // Purpose :
1600 // Special Notes : This corresponds to
1601 // .options nonlin continuation=art or
1602 // .options nonlin continuation=33
1603 // Scope :
1604 // Creator :
1605 // Creation Date :
1606 //-----------------------------------------------------------------------------
1608 {
1609 #ifdef Xyce_NOX_LOCA_ARTIFICIAL_HOMOTOPY_SUPPORT
1610  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1611  Teuchos::ParameterList& locaUtilsList = locaList->sublist("Utilities");
1612 
1613  Teuchos::RCP<LOCA::Homotopy::Group> hGrp =
1614  Teuchos::rcp(new LOCA::Homotopy::Group(*locaList, globalDataPtr_, groupPtr_, 1.0, 0.0));
1615 
1616  hGrp->computeF();
1617 
1618  locaList->sublist("Predictor").set("Secant", 0.999);
1619  locaList->sublist("Stepper").set("Max Value", 0.999);
1620 
1622 
1623  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
1624  firstSolveComplete_ = true;
1625 
1626  Teuchos::RCP<LOCA::Homotopy::Group> hGrp2 =
1627  Teuchos::rcp(new LOCA::Homotopy::Group(*locaList, globalDataPtr_, groupPtr_, 0.1, 1.0));
1628 
1629  locaList->sublist("Predictor").set("Secant", 0.999);
1630  locaList->sublist("Stepper").set("Initial Value", 0.999);
1631  locaList->sublist("Stepper").set("Max Value", 1.0);
1632  locaList->sublist("Step Size").set("Method", "Constant");
1633  locaList->sublist("Step Size").set("Initial Step Size", 0.0001);
1634  locaList->sublist("Step Size").set("Min Step Size", 0.0001);
1635 
1637 
1638  locaStatus = stepperPtr_->run();
1639 
1640  // Return the solution status
1641  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1642  return (-1);
1643  else
1644  return (paramsPtr->getStatusTestReturnCode());
1645 
1646 #else
1647  Report::UserFatal0() << "Nonlinear Solver (NOX::Interface) Artificial parameter continuation requires "
1648  << "building xyce with the define: -DXyce_NOX_LOCA_ARTIFICIAL_HOMOTOPY_SUPPORT to "
1649  << "allow LOCA to augment the diagonal of Jacobian! Either rebuild Xyce or do not "
1650  << "run Xyce with \"continuation=33\"";
1651  return -1;
1652 #endif
1653 }
1654 
1655 //-----------------------------------------------------------------------------
1656 // Function : Interface::sourceSteppingSolve
1657 // Purpose :
1658 // Special Notes : This corresponds to
1659 // .options nonlin continuation=sourcestep or
1660 // .options nonlin continuation=34
1661 // Scope : public
1662 // Creator : Tom Russo
1663 // Creation Date :
1664 //-----------------------------------------------------------------------------
1666 {
1667  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
1668 
1669  // Create the continuation parameter names
1670  std::string vsrcscale = "VSRCSCALE";
1671 
1672  // Create Parameter Vector and get the stepper parameter list.
1673  LOCA::ParameterVector locaPVec;
1674  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
1675  Teuchos::ParameterList& predictorList = locaList->sublist("Predictor");
1676  Teuchos::ParameterList& stepSizeList = locaList->sublist("Step Size");
1677 
1678  // Continuation solve using source stepping.
1679  locaPVec.addParameter(vsrcscale, 0.0);
1680  groupPtr_->setParams(locaPVec);
1681  stepperList.set("Continuation Parameter", vsrcscale);
1682  stepperList.set("Continuation Method", "Natural");
1683 
1684  stepSizeList.set("Method", "Adaptive");
1685  predictorList.set("Method", "Constant");
1686 
1687  stepperList.set("Initial Value", 0.0);
1688  stepperList.set("Min Value", -1.0);
1689  stepperList.set("Max Value", 1.0);
1690 
1691  stepSizeList.set("Initial Step Size", 0.2);
1692  stepSizeList.set("Min Step Size", 1.0e-4);
1693  stepSizeList.set("Max Step Size", 0.2);
1694  stepSizeList.set("Aggressiveness", 1.0);
1695 
1696  stepperList.set("Max Steps", 400);
1697  stepperList.set("Max Nonlinear Iterations", 20);
1698 
1699  // the following set of if-statemtents call functions that
1700  // allocate augmented linear systems for various scenarios.
1701  // It is important that the augmented systems get allocated
1702  // after the paramter (above) have been set.
1703  bool usedOP=false;
1704  bool usedNODESET=false;
1705  bool usedIC=false;
1706 
1707  if ((usemode_) && (mode_ != Nonlinear::TRANSIENT))
1708  {
1709  if (ICspecified_)
1710  {
1711  usedIC=icCont3 (paramsPtr);
1712  }
1713  else if (NODESETspecified_)
1714  {
1715  usedNODESET=nodesetCont1 (paramsPtr);
1716  }
1717  else
1718  {
1719  usedOP = opStartCont1 (paramsPtr);
1720  }
1721  }
1722 
1723  // Initialize parameters in xyce
1724  if (!usedOP && !usedNODESET) // (usedOP and usedNODESET have already loaded F)
1725  {
1726  groupPtr_->computeF();
1727  }
1728 
1729  // Do the continuation run
1731  LOCA::Abstract::Iterator::IteratorStatus locaStatus = stepperPtr_->run();
1732 
1733  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
1734 
1735  // Kick out if continuation failed
1736  if (locaStatus != LOCA::Abstract::Iterator::Finished)
1737  return (-1);
1738  else
1739  return (paramsPtr->getStatusTestReturnCode());
1740 }
1741 
1742 //-----------------------------------------------------------------------------
1743 // Function : Interface::solve
1744 //
1745 // Purpose : Reset all the counters and parameters and solve the
1746 // nonlinear problem for this time step. The solution is
1747 // stored in nextSolVector (obtained from the N_LAS_System
1748 // registered above by registerLinearSystem).
1749 //
1750 // Special Notes : Should not be called until *after* initializeAll() has
1751 // been called.
1752 //
1753 // Return Type : Integer - postive for sucess, negative for failure.
1754 // Special Notes :
1755 // Scope : public
1756 // Creator : Roger Pawlowski, SNL 9233
1757 // Creation Date :
1758 //-----------------------------------------------------------------------------
1760 {
1761 
1762  try
1763  {
1764  // For base object
1766 
1767  if (DEBUG_NONLINEAR)
1769 
1770  // Setup the status tests
1771  if (Teuchos::is_null(locaStatusTestPtr_))
1772  {
1774  Teuchos::rcp(new LOCA::StatusTest::Wrapper(dcParams_.getStatusTests()));
1776  Teuchos::rcp(new LOCA::StatusTest::Wrapper(transientParams_.getStatusTests()));
1778  Teuchos::rcp(new LOCA::StatusTest::Wrapper(hbParams_.getStatusTests()));
1780  Teuchos::rcp(new LOCA::StatusTest::Wrapper(nlpParams_.getStatusTests()));
1781  }
1782 
1783  // Pick the parameter set to use.
1784  ParameterSet* paramsPtr;
1785  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
1786  {
1787  paramsPtr = &transientParams_;
1791  }
1792  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
1793  {
1794  paramsPtr = &hbParams_;
1798  }
1799  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
1800  {
1801  paramsPtr = &nlpParams_;
1805  }
1806  else
1807  {
1808  paramsPtr = &dcParams_;
1812  }
1813 
1814  if (Teuchos::is_null(globalDataPtr_))
1815  {
1816  globalDataPtr_ = LOCA::createGlobalData(paramsPtr->getAllParams());
1817  }
1818 
1819  // set the xyce return codes:
1820  paramsPtr->setStatusTestReturnCodes(retCodes_);
1821 
1822  // Set up the shared system (we have to redo this every time because
1823  // the object pointed to by nextSolVectorPtrPtr may have changed.
1824  //delete sharedSystemPtr_;
1825  if (sharedSystemPtr_ == 0)
1827  *rhsVectorPtr_,
1830  *gradVectorPtr_,
1831  *lasSysPtr_,
1832  *this);
1833  else
1835  *rhsVectorPtr_,
1838  *gradVectorPtr_,
1839  *lasSysPtr_,
1840  *this);
1841 
1842  //////////////////////////////////////////////////////////////////////////
1843  // erkeite: Group handling required by 2-level Newton:
1844  // Reset up the corresponding group as well
1845  if (nlsTmpPtr==0)
1846  {
1847  if (Teuchos::is_null(groupPtr_))
1848  {
1849  groupPtr_ = Teuchos::rcp(new N_NLS_LOCA::Group(globalDataPtr_,
1851  getLoader(),
1852  *outMgrPtr_,
1854  );
1855  }
1856  else
1857  {
1859  groupPtr_->setX(tmpVec);
1860  }
1861  }
1862  else
1863  {
1864  copiedGroupFlag_ = true;
1865  Interface * nlsOtherPtr = dynamic_cast<Interface*>(nlsTmpPtr);
1866  groupPtr_ = nlsOtherPtr->getSolutionGroup();
1867  }
1868  // End of block needed by 2-level Newton.
1869  //////////////////////////////////////////////////////////////////////////
1870 
1871  int solverType = paramsPtr->getNoxSolverType();
1872  bool continuationSpecified = paramsPtr->getContinuationSpecifiedFlag();
1873 
1874  if ((mode_ == Nonlinear::DC_OP || mode_ == Nonlinear::DC_SWEEP) && !continuationSpecified)
1875  {
1876  return spiceStrategy(paramsPtr);
1877  }
1878  else
1879  {
1880 
1881  // Setting the nonContinuation flag is required to prevent incorrect
1882  // Device::DeviceMgr::setParam calls.
1883  if (solverType==0)
1884  {
1885  groupPtr_->setNonContinuationFlag (true);
1886  }
1887  else
1888  {
1889  groupPtr_->setNonContinuationFlag (false);
1890  }
1891 
1892  if (DEBUG_NONLINEAR)
1893  dout() << "solverType is " << solverType << std::endl;
1894 
1895  // (0) Standard Newton Method Solve (includes line search and
1896  // trust region based methods
1897  if (solverType == 0)
1898  {
1899  return stdNewtonSolve(paramsPtr);
1900  }
1901  // (1) Natural Parameter Continuation
1902  else if (solverType == 1)
1903  {
1904  return naturalParameterContinuationSolve ( paramsPtr );
1905  }
1906  // (2) Mosfet specific continuation
1907  else if (solverType == 2)
1908  {
1909  return mosfetContinuationSolve ( paramsPtr );
1910  }
1911  else if (solverType == 3) // GMIN stepping, simple specification
1912  {
1913  return gminSteppingSolve ( paramsPtr );
1914  }
1915  // (4) Mosfet specific continuation (ERK, new 2/21/2004)
1916  else if (solverType == 4)
1917  {
1918  return mosfetContinuationSolve2 (paramsPtr);
1919  }
1920  // (5) Mosfet:BSIM3:Inverter specific continuation (RPP, new 2/25/2004)
1921  else if (solverType == 5)
1922  {
1923  return mosfetContinuationSolve3 (paramsPtr);
1924  }
1925  // (6) Mosfet:BSIM3:Inverter specific continuation (RPP, new 2/25/2004)
1926  else if (solverType == 6)
1927  {
1928  return mosfetContinuationSolve4 (paramsPtr);
1929  } // Block gainscale
1930  else if (solverType == 7)
1931  {
1932  return blockGainscaleMosfetSolve ( paramsPtr );
1933  } // Test suite
1934  else if (solverType == 8)
1935  {
1936  return mosfetContinuationSolve5 (paramsPtr);
1937  } // Pseudo Transient
1938  else if (solverType == 9)
1939  {
1940  return pseudoTransientSolve( paramsPtr );
1941  } // continuation = 4 + power node
1942  else if (solverType == 10)
1943  {
1944  return mosfetContinuationSolve6 (paramsPtr);
1945  }
1946  else if (solverType == 33) // artificial parameter
1947  {
1948  return artificialParameterHomotopy (paramsPtr);
1949  }
1950  else if (solverType == 34) // source stepping, simple specification
1951  {
1952  return sourceSteppingSolve ( paramsPtr );
1953  }// End of if (solverType == )
1954  }
1955  } // try
1956  catch (const char* error_msg) {
1957  std::string nox_error = "NOX Error";
1958  std::string err_msg = std::string(error_msg);
1959  if (err_msg == nox_error) {
1960  const std::string message =
1961  "Caught a NOX Exception in Interface::solve()!";
1962  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, message);
1963  }
1964  else // Otherwise, rethrow...
1965  throw;
1966  }
1967 #ifndef Xyce_CHARON
1968  catch (const std::exception& e) {
1969  dout() << e.what() << std::endl;
1970  const std::string message =
1971  "Caught std::exception in Interface::solve()!";
1972  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, message);
1973  }
1974  catch (...) {
1975  const std::string message =
1976  "Caught Unknown Exception in Interface::solve()!";
1977  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL, message);
1978  }
1979 #endif
1980 
1981  // Should never get this far
1982  return -1;
1983 }
1984 
1985 
1986 //-----------------------------------------------------------------------------
1987 // Function : Interface::opStartCont1
1988 // Purpose :
1989 // Special Notes : returns true if DCOP restart is being used.
1990 //
1991 // The "found" variable indicates if any of the nodes specified
1992 // in the dcop start file were found in this circuit. If not,
1993 // then don't bother with this.
1994 //
1995 // Scope : public
1996 // Creator : Eric R. Keiter, SNL, Electrical and Microsystem Modeling
1997 // Creation Date : 09/15/07
1998 //-----------------------------------------------------------------------------
2000 {
2001  bool usedOP(false);
2002 
2003 #ifdef Xyce_DEBUG_OP_START
2004  dout() << "NOX_Interface: Inside continuation=1 OP_START code (case 2)" << std::endl;
2005 #endif
2006  if (!DCOPused_)
2007  {
2008  int found = 0;
2009  int icType;
2010  IO::InitialConditionsData::NodeNamePairMap & op = initialConditionsManager_->getICData(found, icType);
2011  const NodeNameMap & allNodes = outMgrPtr_->getSolutionNodeMap();
2012  N_PDS_Comm * pdsCommPtr = pdsMgrPtr_->getPDSComm();
2013 
2014  if (found > 0 && icType == IO::InitialConditionsData::IC_TYPE_DCOP_RESTART)
2015  {
2016  DCOPused_ = true;
2017  usedOP = true;
2018  // Set up nox nonlinear solver
2019  if (Teuchos::is_null(solverPtr_))
2020  {
2021  solverPtr_ = NOX::Solver::buildSolver(groupPtr_,
2022  paramsPtr->getStatusTests(),
2023  paramsPtr->getNoxParams());
2024  }
2025 
2026  Teuchos::RCP<AugmentLinSys> als =
2027  paramsPtr->createAugmentLinearSystem(lasSysPtr_, op, allNodes, pdsCommPtr);
2028 
2029  groupPtr_->setAugmentLinearSystem(true, als);
2030  NOX::StatusTest::StatusType status = solverPtr_->solve();
2031 
2032  firstSolveComplete_ = true;
2033  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
2035 
2036 #ifdef Xyce_DEBUG_OP_START
2037  // DNS: Uncommenting this will set debug output of linear system for every step
2038 #ifdef Xyce_PARALLEL_MPI
2039  groupPtr_->setOutputLinear (&op, &allNodes, pdsCommPtr);
2040 #else
2041  groupPtr_->setOutputLinear (&op, &allNodes);
2042 #endif
2043 #endif // debug op start
2044 
2045  }
2046  }
2047  return usedOP;
2048 }
2049 
2050 //-----------------------------------------------------------------------------
2051 // Function : Interface::icCont
2052 // Purpose :
2053 // Special Notes : returns true if IC is being used.
2054 //
2055 // The "found" variable indicates if any of the nodes specified
2056 // in the dcop start file were found in this circuit. If not,
2057 // then don't bother with this.
2058 //
2059 // Scope : public
2060 // Creator : Eric R. Keiter, SNL, Electrical and Microsystem Modeling
2061 // Creation Date : 09/15/07
2062 //-----------------------------------------------------------------------------
2064 {
2065  bool usedIC(false);
2066 
2067 #ifdef Xyce_DEBUG_IC
2068  dout() << "NOX_Interface: Inside continuation=0 .IC code." << std::endl;
2069 #endif
2070  int found = 0;
2071  int icType;
2072  IO::InitialConditionsData::NodeNamePairMap & op = initialConditionsManager_->getICData(found, icType);
2073 
2074  usedIC = (icType==IO::InitialConditionsData::IC_TYPE_IC && found > 0);
2075  if (usedIC)
2076  {
2077  bool useGminStepping=false;
2078  Teuchos::RCP<AugmentLinSys> als =
2079  paramsPtr->createAugmentLinearSystem(lasSysPtr_, op, useGminStepping);
2080  groupPtr_->setAugmentLinearSystem(true, als);
2081  }
2082  return usedIC;
2083 }
2084 
2085 //-----------------------------------------------------------------------------
2086 // Function : Interface::icCont3
2087 // Purpose : IC with gmin stepping
2088 // Special Notes : returns true if IC is being used.
2089 //
2090 // The "found" variable indicates if any of the nodes specified
2091 // in the dcop start file were found in this circuit. If not,
2092 // then don't bother with this.
2093 //
2094 // Scope : public
2095 // Creator : Eric R. Keiter, SNL
2096 // Creation Date : 04/29/2012
2097 //-----------------------------------------------------------------------------
2099 {
2100  bool usedIC(false);
2101 
2102 #ifdef Xyce_DEBUG_IC
2103  dout() << "NOX_Interface: Inside continuation=3 .IC code." << std::endl;
2104 #endif
2105  int found = 0;
2106  int icType;
2107  IO::InitialConditionsData::NodeNamePairMap & op = initialConditionsManager_->getICData(found, icType);
2108 
2109  usedIC = (icType==IO::InitialConditionsData::IC_TYPE_IC && found > 0);
2110  if (usedIC)
2111  {
2112  bool useGminStepping=true;
2113  Teuchos::RCP<AugmentLinSys> als =
2114  paramsPtr->createAugmentLinearSystem(lasSysPtr_, op, useGminStepping);
2115  groupPtr_->setAugmentLinearSystem(true, als);
2116  }
2117  return usedIC;
2118 }
2119 
2120 //-----------------------------------------------------------------------------
2121 // Function : Interface::nodesetCont0
2122 // Purpose :
2123 // Special Notes : returns true if is being used.
2124 // Scope : public
2125 // Creator : Eric R. Keiter, SNL, Electrical and Microsystem Modeling
2126 // Creation Date : 09/15/07
2127 //-----------------------------------------------------------------------------
2129 {
2130  bool usedNODESET(false);
2131 
2132 #ifdef Xyce_DEBUG_IC
2133  dout() << "NOX_Interface: Inside continuation=0 .NODESET code (case 1)" << std::endl;
2134 #endif
2135  int found = 0;
2136  int icType;
2137  IO::InitialConditionsData::NodeNamePairMap & op = initialConditionsManager_->getICData(found, icType);
2138 
2139  usedNODESET = (icType==IO::InitialConditionsData::IC_TYPE_NODESET && found > 0);
2140  if (usedNODESET)
2141  {
2142  Teuchos::RCP<AugmentLinSys> als =
2143  paramsPtr->createAugmentLinearSystem(lasSysPtr_, op);
2144 
2145  groupPtr_->setAugmentLinearSystem(true, als);
2146  NOX::StatusTest::StatusType status = solverPtr_->solve();
2147 
2148  // Create a reset solver after performing the initial nodeset solve.
2149  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
2150  solverPtr_->reset(groupPtr_->getX());
2152  firstSolveComplete_ = true;
2153  }
2154  return usedNODESET;
2155 }
2156 
2157 
2158 //-----------------------------------------------------------------------------
2159 // Function : Interface::nodesetCont1
2160 // Purpose :
2161 // Special Notes : returns true if .NODESET is being used.
2162 // Scope : public
2163 // Creator : Eric R. Keiter, SNL, Electrical and Microsystem Modeling
2164 // Creation Date : 09/15/07
2165 //-----------------------------------------------------------------------------
2167 {
2168  bool usedNODESET(false);
2169 
2170 #ifdef Xyce_DEBUG_IC
2171  dout() << "NOX_Interface: Inside continuation=1 .NODESET code (case 2)" << std::endl;
2172 #endif
2173 
2174  int found = 0;
2175  int icType;
2176  IO::InitialConditionsData::NodeNamePairMap & op = initialConditionsManager_->getICData(found, icType);
2177 
2178  usedNODESET = (icType==IO::InitialConditionsData::IC_TYPE_NODESET && found > 0);
2179  if (usedNODESET)
2180  {
2181  // Set up nox nonlinear solver
2182  if (Teuchos::is_null(solverPtr_))
2183  {
2184  solverPtr_ = NOX::Solver::buildSolver(groupPtr_,
2185  paramsPtr->getStatusTests(),
2186  paramsPtr->getNoxParams());
2187  }
2188 
2189  Teuchos::RCP<AugmentLinSys> als =
2190  paramsPtr->createAugmentLinearSystem(lasSysPtr_, op);
2191 
2192  groupPtr_->setAugmentLinearSystem(true, als);
2193  NOX::StatusTest::StatusType status = solverPtr_->solve();
2194 
2195  firstSolveComplete_ = true;
2196  groupPtr_->setAugmentLinearSystem(false, Teuchos::null);
2198  }
2199  return usedNODESET;
2200 }
2201 
2202 //-----------------------------------------------------------------------------
2203 // Function : Interface::takeFirstSolveStep
2204 // Purpose : same as Interface::solve, except that solverPtr_->iterate is
2205 // called instead of solverPtr_->solve.
2206 // Special Notes :
2207 // Scope : public
2208 // Creator :
2209 // Creation Date :
2210 //-----------------------------------------------------------------------------
2212 {
2213  // For base object
2215 
2216  // Pick the parameter set to use.
2217  ParameterSet* paramsPtr;
2218  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2219  paramsPtr = &transientParams_;
2220  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2221  paramsPtr = &hbParams_;
2222  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2223  paramsPtr = &nlpParams_;
2224  else
2225  paramsPtr = &dcParams_;
2226 
2227  // set the xyce return codes:
2228  paramsPtr->setStatusTestReturnCodes(retCodes_);
2229 
2230  if (Teuchos::is_null(globalDataPtr_))
2231  globalDataPtr_ = LOCA::createGlobalData(paramsPtr->getAllParams());
2232 
2233  // Set up the shared system (we have to redo this every time because
2234  // the object pointed to by nextSolVectorPtrPtr may have changed.
2235  delete sharedSystemPtr_;
2236  sharedSystemPtr_ = new SharedSystem(**nextSolVectorPtrPtr_,
2237  *rhsVectorPtr_,
2240  *gradVectorPtr_,
2241  *lasSysPtr_,
2242  *this);
2243 
2244  // Reset up the corresponding group as well
2245  //delete groupPtr_;
2246  if (nlsTmpPtr==0)
2247  {
2248  if (Teuchos::is_null(groupPtr_))
2249  {
2250  dout() << "takeFirstSolveStep: allocating a new group!" << std::endl;
2251  groupPtr_ = Teuchos::rcp(new N_NLS_LOCA::Group(globalDataPtr_,
2252  *sharedSystemPtr_,
2253  getLoader(),
2254  *outMgrPtr_,
2255  getAnalysisManager()));
2256  }
2257  else
2258  {
2259  dout() << "takeFirstSolveStep: using the old group!" << std::endl;
2261  groupPtr_->setX(tmpVec);
2262  }
2263  }
2264  else
2265  {
2266  dout() << "takeFirstSolveStep: copying over the passed group!" << std::endl;
2267  copiedGroupFlag_ = true;
2268  Interface * nlsOtherPtr = dynamic_cast<Interface*>(nlsTmpPtr);
2269  groupPtr_ = nlsOtherPtr->getSolutionGroup();
2270  }
2271 
2272  // Set up solver
2273  if (Teuchos::is_null(solverPtr_))
2274  solverPtr_ = NOX::Solver::buildSolver(groupPtr_,
2275  paramsPtr->getStatusTests(),
2276  paramsPtr->getNoxParams());
2277  else
2278  solverPtr_->reset(groupPtr_->getX());
2279 
2280  // Solve
2281  NOX::StatusTest::StatusType status = solverPtr_->step();
2282 
2283  // Return the solution status
2284  return (status == NOX::StatusTest::Converged) ? 1 : -1;
2285 }
2286 
2287 //-----------------------------------------------------------------------------
2288 // Function : Interface::takeOneSolveStep
2289 // Purpose : same as Interface::takeFirstSolveStep, except that none of the
2290 // set up stuff (like allocating the solverPtr) is done here.
2291 // Special Notes :
2292 // Scope : public
2293 // Creator :
2294 // Creation Date :
2295 //-----------------------------------------------------------------------------
2297 {
2298  // Solve
2299  NOX::StatusTest::StatusType status = solverPtr_->step();
2300 
2301  // Return the solution status
2302  return (status == NOX::StatusTest::Converged) ? 1 : -1;
2303 }
2304 
2305 //-----------------------------------------------------------------------------
2306 // Function : Interface::getNumIterations
2307 // Purpose :
2308 // Special Notes :
2309 // Return Type : Integer (current number of nonlinear iterations)
2310 // Scope : public
2311 // Creator :
2312 // Creation Date :
2313 //-----------------------------------------------------------------------------
2315 {
2316  // Pick the parameter set to use.
2317  const ParameterSet* paramsPtr;
2318  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2319  paramsPtr = &transientParams_;
2320  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2321  paramsPtr = &hbParams_;
2322  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2323  paramsPtr = &nlpParams_;
2324  else
2325  paramsPtr = &dcParams_;
2326 
2327  int solverType = paramsPtr->getNoxSolverType();
2328 
2329  if ((!Teuchos::is_null(solverPtr_)) && (solverType == 0))
2330  return solverPtr_->getNumIterations();
2331  else if ((!Teuchos::is_null(solverPtr_)) && (solverType == 1))
2332  return solverPtr_->getNumIterations();
2333  else if ((!Teuchos::is_null(solverPtr_)) && (solverType == 9))
2334  return solverPtr_->getNumIterations();
2335  else if ((!Teuchos::is_null(stepperPtr_)) && (solverType != 0))
2336  {
2337  return stepperPtr_->getSolver()->getNumIterations();
2338  }
2339 
2340  // Sometimes this is called before solve() itself, in which calse
2341  // the solverPtr_ has not yet been initialized, so we just return 0.
2342  return 0;
2343 }
2344 
2345 //-----------------------------------------------------------------------------
2346 // Function : Interface::getMaxNormF() const
2347 // Purpose :
2348 // Special Notes :
2349 // Return Type : double (norm of F)
2350 // Scope : public
2351 // Creator :
2352 // Creation Date :
2353 //-----------------------------------------------------------------------------
2355 {
2356  // Pick the parameter set to use.
2357  const ParameterSet* paramsPtr;
2358  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2359  {
2360  paramsPtr = &transientParams_;
2361  }
2362  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2363  {
2364  paramsPtr = &hbParams_;
2365  }
2366  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2367  {
2368  paramsPtr = &nlpParams_;
2369  }
2370  else
2371  {
2372  paramsPtr = &dcParams_;
2373  }
2374 
2375  double maxNormF = paramsPtr->getMaxNormF();
2376  return maxNormF;
2377 }
2378 
2379 
2380 //-----------------------------------------------------------------------------
2381 // Function : Interface::getMaxNormFindex() const
2382 // Purpose :
2383 // Special Notes :
2384 // Return Type : int (vector index norm of F)
2385 // Scope : public
2386 // Creator :
2387 // Creation Date :
2388 //-----------------------------------------------------------------------------
2390 {
2391  // Pick the parameter set to use.
2392  const ParameterSet* paramsPtr;
2393  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2394  {
2395  paramsPtr = &transientParams_;
2396  }
2397  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2398  {
2399  paramsPtr = &hbParams_;
2400  }
2401  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2402  {
2403  paramsPtr = &nlpParams_;
2404  }
2405  else
2406  {
2407  paramsPtr = &dcParams_;
2408  }
2409 
2410  int maxNormFindex = paramsPtr->getMaxNormFindex();
2411  return maxNormFindex;
2412 }
2413 
2414 //-----------------------------------------------------------------------------
2415 // Function : Interface::getDebugLevel
2416 // Purpose :
2417 // Special Notes :
2418 // Scope : public
2419 // Creator : Eric Keiter, SNL
2420 // Creation Date : 9/17/2007
2421 //-----------------------------------------------------------------------------
2423 {
2424  const ParameterSet* paramsPtr;
2425  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2426  {
2427  paramsPtr = &transientParams_;
2428  }
2429  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2430  {
2431  paramsPtr = &hbParams_;
2432  }
2433  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2434  {
2435  paramsPtr = &nlpParams_;
2436  }
2437  else
2438  {
2439  paramsPtr = &dcParams_;
2440  }
2441 
2442  return (paramsPtr->getDebugLevel());
2443 }
2444 
2445 //-----------------------------------------------------------------------------
2446 // Function : Interface::getScreenOutputFlag
2447 // Purpose :
2448 // Special Notes :
2449 // Scope : public
2450 // Creator : Eric Keiter, SNL
2451 // Creation Date : 9/17/2007
2452 //-----------------------------------------------------------------------------
2454 {
2455  const ParameterSet* paramsPtr;
2456  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2457  {
2458  paramsPtr = &transientParams_;
2459  }
2460  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2461  {
2462  paramsPtr = &hbParams_;
2463  }
2464  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2465  {
2466  paramsPtr = &nlpParams_;
2467  }
2468  else
2469  {
2470  paramsPtr = &dcParams_;
2471  }
2472 
2473  return (paramsPtr->getScreenOutputFlag());
2474 }
2475 
2476 //-----------------------------------------------------------------------------
2477 // Function : Interface::getDebugMinTime
2478 // Purpose :
2479 // Special Notes :
2480 // Scope : public
2481 // Creator : Eric Keiter, SNL
2482 // Creation Date : 9/17/2007
2483 //-----------------------------------------------------------------------------
2485 {
2486  const ParameterSet* paramsPtr;
2487  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2488  {
2489  paramsPtr = &transientParams_;
2490  }
2491  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2492  {
2493  paramsPtr = &hbParams_;
2494  }
2495  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2496  {
2497  paramsPtr = &nlpParams_;
2498  }
2499  else
2500  {
2501  paramsPtr = &dcParams_;
2502  }
2503 
2504  return (paramsPtr->getDebugMinTime());
2505 }
2506 
2507 //-----------------------------------------------------------------------------
2508 // Function : Interface::getDebugMaxTime
2509 // Purpose :
2510 // Special Notes :
2511 // Scope : public
2512 // Creator : Eric Keiter, SNL
2513 // Creation Date : 9/17/2007
2514 //-----------------------------------------------------------------------------
2516 {
2517  const ParameterSet* paramsPtr;
2518  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2519  {
2520  paramsPtr = &transientParams_;
2521  }
2522  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2523  {
2524  paramsPtr = &hbParams_;
2525  }
2526  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2527  {
2528  paramsPtr = &nlpParams_;
2529  }
2530  else
2531  {
2532  paramsPtr = &dcParams_;
2533  }
2534 
2535  return (paramsPtr->getDebugMaxTime());
2536 }
2537 
2538 //-----------------------------------------------------------------------------
2539 // Function : Interface::getDebugMinTimeStep
2540 // Purpose :
2541 // Special Notes :
2542 // Scope : public
2543 // Creator : Eric Keiter, SNL
2544 // Creation Date : 9/17/2007
2545 //-----------------------------------------------------------------------------
2547 {
2548  const ParameterSet* paramsPtr;
2549  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2550  {
2551  paramsPtr = &transientParams_;
2552  }
2553  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2554  {
2555  paramsPtr = &hbParams_;
2556  }
2557  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2558  {
2559  paramsPtr = &nlpParams_;
2560  }
2561  else
2562  {
2563  paramsPtr = &dcParams_;
2564  }
2565 
2566  return (paramsPtr->getDebugMinTimeStep());
2567 }
2568 
2569 //-----------------------------------------------------------------------------
2570 // Function : Interface::getDebugMaxTimeStep
2571 // Purpose :
2572 // Special Notes :
2573 // Scope : public
2574 // Creator : Eric Keiter, SNL
2575 // Creation Date : 9/17/2007
2576 //-----------------------------------------------------------------------------
2578 {
2579  const ParameterSet* paramsPtr;
2580  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2581  {
2582  paramsPtr = &transientParams_;
2583  }
2584  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2585  {
2586  paramsPtr = &hbParams_;
2587  }
2588  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2589  {
2590  paramsPtr = &nlpParams_;
2591  }
2592  else
2593  {
2594  paramsPtr = &dcParams_;
2595  }
2596 
2597  return (paramsPtr->getDebugMaxTimeStep());
2598 }
2599 
2600 //-----------------------------------------------------------------------------
2601 // Function : Interface::getMMFormat
2602 // Purpose :
2603 // Special Notes :
2604 // Scope : public
2605 // Creator : Eric Keiter, SNL
2606 // Creation Date : 3/2/2011
2607 //-----------------------------------------------------------------------------
2609 {
2610  return false;
2611 }
2612 
2613 //-----------------------------------------------------------------------------
2614 // Function : Interface::isFirstContinuationParam
2615 // Purpose :
2616 // Special Notes :
2617 // Scope : public
2618 // Creator :
2619 // Creation Date :
2620 //-----------------------------------------------------------------------------
2622 {
2624 }
2625 
2626 //-----------------------------------------------------------------------------
2627 // Function : Interface::isFirstSolveComplete
2628 // Purpose :
2629 // Special Notes :
2630 // Scope : public
2631 // Creator :
2632 // Creation Date :
2633 //-----------------------------------------------------------------------------
2635 {
2636  return firstSolveComplete_;
2637 }
2638 
2639 //-----------------------------------------------------------------------------
2640 // Function : Interface::getContinuationStep
2641 // Purpose :
2642 // Special Notes :
2643 // Scope : public
2644 // Creator :
2645 // Creation Date :
2646 //-----------------------------------------------------------------------------
2648 {
2649  if (!Teuchos::is_null(stepperPtr_))
2650  {
2651  return stepperPtr_->getStepNumber();
2652  }
2653  return 0;
2654 }
2655 
2656 //-----------------------------------------------------------------------------
2657 // Function : Interface::getContinuationStep
2658 // Purpose :
2659 // Special Notes :
2660 // Scope : public
2661 // Creator :
2662 // Creation Date :
2663 //-----------------------------------------------------------------------------
2665 {
2666  return iParam_;
2667 }
2668 
2669 //-----------------------------------------------------------------------------
2670 // Function : Interface::setAnalysisMode
2671 //
2672 // Purpose : Specify the analysis mode to be used by the nonlinear
2673 // solver in the next call to solve(). This *may* affect
2674 // the parameters used by the solver.
2675 //
2676 // See Also : setOptions, setTranOptions
2677 //
2678 // - Input Arguments -
2679 //
2680 // mode : Mode to be used in the next nonlinear solve.
2681 // Special Notes :
2682 // Scope : public
2683 // Creator :
2684 // Creation Date :
2685 //-----------------------------------------------------------------------------
2687 {
2688  mode_ = mode;
2689 }
2690 
2691 //-----------------------------------------------------------------------------
2692 // Function : Interface::resetAll
2693 // Purpose : This is used when Xyce is doing a STEP loop, and
2694 // needs to act like it is at the beginning of a transient
2695 // simulation again, for the next parameter in the STEP loop.
2696 // Special Notes :
2697 // Scope : public
2698 // Creator : Eric Keiter
2699 // Creation Date :
2700 //-----------------------------------------------------------------------------
2702 {
2703  setAnalysisMode(mode);
2704 }
2705 
2706 //-----------------------------------------------------------------------------
2707 // Function : Interface::copySolnVectors()
2708 //
2709 // Purpose : To be called at the beginning of each nonlinear
2710 // iteration. It equates the tmp and next vectors as
2711 // well as some special hidden vectors.
2712 //
2713 // See Also : setX0_
2714 // Special Notes :
2715 // Scope : public
2716 // Creator :
2717 // Creation Date :
2718 //-----------------------------------------------------------------------------
2720 {
2722  return true;
2723 }
2724 
2725 //-----------------------------------------------------------------------------
2726 // Function : Interface::computeF()
2727 // Purpose :
2728 // Special Notes :
2729 // Scope : public
2730 // Creator :
2731 // Creation Date :
2732 //-----------------------------------------------------------------------------
2734 {
2736 }
2737 
2738 //-----------------------------------------------------------------------------
2739 // Function : Interface::computeNewton
2740 // Purpose : Set up the parameters for the linear solver and then
2741 // call newton_()
2742 // Special Notes :
2743 // Scope : public
2744 // Creator :
2745 // Creation Date :
2746 //-----------------------------------------------------------------------------
2747 bool Interface::computeNewton(Teuchos::ParameterList& params)
2748 {
2750  {
2751  lasSolverPtr_->setTolerance(params.get("Tolerance", 1.0e-12));
2752  }
2754  {
2755  lasSolverPtr_->setTolerance(params.get("Tolerance", 1.0e-12));
2756  }
2757 
2759 }
2760 
2761 //-----------------------------------------------------------------------------
2762 // Function : Interface::computeJacobian()
2763 // Purpose :
2764 // Special Notes :
2765 // Scope : public
2766 // Creator :
2767 // Creation Date :
2768 //-----------------------------------------------------------------------------
2770 {
2771  bool status = Nonlinear::NonLinearSolver::jacobian_();
2772  return status;
2773 }
2774 
2775 //-----------------------------------------------------------------------------
2776 // Function : Interface::applyJacobian(const N_LAS_Vector& input, N_LAS_Vector& result)
2777 // Purpose :
2778 // Special Notes :
2779 // Scope : public
2780 // Creator :
2781 // Creation Date :
2782 //-----------------------------------------------------------------------------
2783 bool Interface::applyJacobian(const Linear::Vector& input, Linear::Vector& result)
2784 {
2785  return Nonlinear::NonLinearSolver::applyJacobian(input,result);
2786 }
2787 
2788 //-----------------------------------------------------------------------------
2789 // Function : Interface::computeGradient()
2790 // Purpose :
2791 // Special Notes :
2792 // Scope : public
2793 // Creator :
2794 // Creation Date :
2795 //-----------------------------------------------------------------------------
2797 {
2798  bool status = Nonlinear::NonLinearSolver::gradient_();
2799  return status;
2800 }
2801 
2802 //-----------------------------------------------------------------------------
2803 // Function : Interface::computeDfDpMulti
2804 // Purpose :
2805 // Special Notes :
2806 // Scope : public
2807 // Creator :
2808 // Creation Date :
2809 //-----------------------------------------------------------------------------
2811  (const std::vector< int > & paramIDs,
2812  NOX::Abstract::MultiVector & dfdp,
2813  bool isValidF)
2814 {
2815  // this could be cleaner:
2816  ParameterSet* paramsPtr;
2817  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2818  {
2819  paramsPtr = &transientParams_;
2820  }
2821  else if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2822  {
2823  paramsPtr = &hbParams_;
2824  }
2825  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2826  {
2827  paramsPtr = &nlpParams_;
2828  }
2829  else
2830  {
2831  paramsPtr = &dcParams_;
2832  }
2833 
2834  Teuchos::RCP<Teuchos::ParameterList> locaList = paramsPtr->getLocaParams();
2835  Teuchos::ParameterList& stepperList = locaList->sublist("Stepper");
2836  const std::string strArg("Skip df/dp");
2837  bool skipDFDP = stepperList.get(strArg, false);
2838 
2839  if (!skipDFDP)
2840  {
2841  // get the separate df/dp, dq/dp and db/dp
2842  int difference = SENS_FWD;
2843  bool forceFD = false;
2844  //bool forceFD = true;
2845  double sqrtEta = 1.0e-8;
2846 
2847  // populate the paramNameVec.
2848  LOCA::ParameterVector locaPVec = groupPtr_->getParams();
2849 
2850  int size = locaPVec.length();
2851  std::vector<std::string> paramNameVec(size);
2852 
2853  for (int i = 0; i < locaPVec.length(); ++i)
2854  {
2855  int index = paramIDs[i];
2856  paramNameVec[i] = locaPVec.getLabel(index);
2857  }
2858 
2859  loadSensitivityResiduals (difference, forceFD, sqrtEta, netlistFilename_,
2860  *dsPtr_, *nonlinearEquationLoader_, paramNameVec, getAnalysisManager());
2861 
2862  // get the complete residual (i.e. assemble the 3 vectors)
2863  nonlinearEquationLoader_->loadSensitivityResiduals();
2864 
2865  // now copy residuals back out into the NOX multivector, dfdp.
2866  std::vector<Linear::Vector *> & sensRHSPtrVector = dsPtr_->sensRHSPtrVector;
2867  for (int i = 0; i < locaPVec.length(); ++i)
2868  {
2869  // NOTE: LOCA stores f in dfdp[0], so the indexing for derivatives in dfdp starts at 1.
2870  int index = paramIDs[i];
2871  NOX::Abstract::Vector *DFDP = &dfdp[index+1];
2872  DFDP->init(0.0);
2873 
2874  Linear::Vector & tmp = *(sensRHSPtrVector[index]);
2875  Vector tmpNox(tmp, *lasSysPtr_);
2876  (*DFDP) = tmpNox;
2877  DFDP->scale(-1.0);
2878 
2879  // debug output:
2880  //DFDP->print(std::cout);
2881  }
2882  }
2883 
2884  return true;
2885 }
2886 
2887 //-----------------------------------------------------------------------------
2888 // Function : Interface::getSolutionGroup
2889 // Purpose :
2890 // Special Notes :
2891 // Scope : public
2892 // Creator :
2893 // Creation Date :
2894 //-----------------------------------------------------------------------------
2895 Teuchos::RCP<N_NLS_LOCA::Group> Interface::getSolutionGroup ()
2896 {
2897  return groupPtr_;
2898 }
2899 
2900 //-----------------------------------------------------------------------------
2901 // Function : Interface::getLoader
2902 //
2903 // Purpose : LOCA needs access to loader to set parameters
2904 //
2905 // Special Notes :
2906 // Scope : public
2907 // Creator :
2908 // Creation Date :
2909 //-----------------------------------------------------------------------------
2911 {
2912  return *nonlinearEquationLoader_;
2913 }
2914 
2915 //-----------------------------------------------------------------------------
2916 // Function : Interface::resetStepper
2917 // Purpose :
2918 // Special Notes :
2919 // Scope : public
2920 // Creator :
2921 // Creation Date :
2922 //-----------------------------------------------------------------------------
2923 void Interface::resetStepper(const Teuchos::RCP<LOCA::GlobalData>& gd,
2924  const Teuchos::RCP<LOCA::MultiContinuation::AbstractGroup>& initialGuess,
2925  const Teuchos::RCP<NOX::StatusTest::Generic>& test,
2926  const Teuchos::RCP<Teuchos::ParameterList>& p)
2927 {
2928  stepperPtr_ =
2929  Teuchos::rcp(new LOCA::Stepper(gd, initialGuess, test, p));
2930 }
2931 
2932 //-----------------------------------------------------------------------------
2933 // Function : Interface::getLocaFlag
2934 // Purpose :
2935 // Special Notes :
2936 // Scope : public
2937 // Creator :
2938 // Creation Date :
2939 //-----------------------------------------------------------------------------
2941 {
2942  // Pick the parameter set to use.
2943  const ParameterSet* paramsPtr;
2944  bool retCode;
2945 
2946  if ((usemode_) && (mode_ == Nonlinear::TRANSIENT))
2947  {
2948  firstSolveComplete_ = false;
2949  paramsPtr = &transientParams_;
2950  int solverType = paramsPtr->getNoxSolverType();
2951  retCode = false;
2952  if (solverType != 0) retCode = true;
2953  }
2954  else
2955  {
2956  if ((usemode_) && (mode_ == Nonlinear::HB_MODE))
2957  {
2958  paramsPtr = &hbParams_;
2959  }
2960  else if ((usemode_) && (mode_ == Nonlinear::DC_NLPOISSON))
2961  {
2962  paramsPtr = &nlpParams_;
2963  }
2964  else
2965  {
2966  paramsPtr = &dcParams_;
2967  }
2968 
2969  if (DCOPused_)
2970  {
2971  retCode = firstSolveComplete_;
2972  }
2973  else
2974  {
2975  int solverType = paramsPtr->getNoxSolverType();
2976  retCode=false;
2977  if (solverType != 0) retCode = true;
2978  }
2979  }
2980 
2981  return retCode;
2982 }
2983 
2984 }}} // namespace N_NLS_NOX
bool loadSensitivityResiduals(int difference, bool forceFD_, double sqrtEta_, std::string &netlistFilename_, TimeIntg::DataStore &ds, Loader::NonlinearEquationLoader &nonlinearEquationLoader_, const std::vector< std::string > &paramNameVec_, const Analysis::AnalysisManager &analysisManager_)
Xyce::Nonlinear::AnalysisMode lastParametersMode_
bool setLocaOptions(const Xyce::Util::OptionBlock &OB)
bool setOptions(const Xyce::Util::OptionBlock &OB)
bool setOutputOptions(int myPID, int outputProcess)
bool opStartCont0(ParameterSet *paramsPtr, int found, int icType, Xyce::IO::InitialConditionsData::NodeNamePairMap &op, const Xyce::NodeNameMap &allNodes, N_PDS_Comm *pdsCommPtr)
void setAnalysisMode(Xyce::Nonlinear::AnalysisMode mode)
void reset(Xyce::Linear::Vector &x, Xyce::Linear::Vector &f, Xyce::Linear::Matrix &jacobian, Xyce::Linear::Vector &newton, Xyce::Linear::Vector &gradient, Xyce::Linear::System &lasSys, Interface &interface)
int mosfetContinuationSolve6(ParameterSet *paramsPtr)
Pure virtual class to augment a linear system.
bool setHBOptions(const Xyce::Util::OptionBlock &OB)
Teuchos::RCP< Teuchos::ParameterList > getLocaParams()
int mosfetContinuationSolve2(ParameterSet *paramsPtr)
int spiceStrategy(ParameterSet *paramsPtr)
bool setOptions(const Xyce::Util::OptionBlock &OB)
bool createStatusTests(Parallel::Machine comm, Xyce::Linear::Vector **currSolnVectorPtrPtr, Xyce::Loader::NonlinearEquationLoader &nonlinear_equation_loader, Xyce::Linear::Vector *maskVectorPtr=0)
Only used when NLS_MASKED_WRMS_NORMS.
bool nodesetCont1(ParameterSet *paramsPtr)
Teuchos::RCP< NOX::Solver::Generic > solverPtr_
Teuchos::RCP< LOCA::Stepper > stepperPtr_
virtual bool applyJacobian(const Linear::Vector &input, Linear::Vector &result)
Teuchos::RCP< LOCA::StatusTest::Wrapper > locaTransientStatusTestPtr_
void allocateSensitivityArrays(Linear::Builder &builder, int numParams)
int stdNewtonSolve(ParameterSet *paramsPtr)
Teuchos::RCP< Teuchos::ParameterList > getNoxParams()
int mosfetContinuationSolve(ParameterSet *paramsPtr)
bool computeNewton(Teuchos::ParameterList &p)
Teuchos::RCP< LOCA::StatusTest::Wrapper > locaDC_NLPStatusTestPtr_
const T & value(const ParameterBase &entity, const Descriptor &descriptor)
Returns the value of the parameter for the entity.
Definition: N_DEV_Pars.h:1224
bool setLocaOptions(const Xyce::Util::OptionBlock &OB, bool saveCopy=true)
int blockGainscaleMosfetSolve(ParameterSet *paramsPtr)
int naturalParameterContinuationSolve(ParameterSet *paramsPtr)
NOX::Abstract::Vector & scale(double gamma)
int solve(Xyce::Nonlinear::NonLinearSolver *nlsTmpPtr=NULL)
int mosfetContinuationSolve3(ParameterSet *paramsPtr)
Teuchos::RCP< LOCA::StatusTest::Wrapper > locaDCOpStatusTestPtr_
bool setTranOptions(const Xyce::Util::OptionBlock &OB)
Teuchos::RCP< LOCA::StatusTest::Wrapper > locaHBStatusTestPtr_
bool computeDfDpMulti(const std::vector< int > &paramIDs, NOX::Abstract::MultiVector &dfdp, bool isValidF)
bool icCont(ParameterSet *paramsPtr)
int pseudoTransientSolve(ParameterSet *paramsPtr)
bool getVectorParam(const std::string &, int, double &)
Teuchos::RCP< N_NLS_LOCA::Group > getSolutionGroup()
const Analysis::AnalysisManager & getAnalysisManager() const
void setDebugFlags(int output_step_number, double time)
Teuchos::RCP< AugmentLinSys > createAugmentLinearSystem(Xyce::Linear::System *ls) const
bool opStartCont1(ParameterSet *paramsPtr)
Teuchos::RCP< LOCA::StatusTest::Wrapper > locaStatusTestPtr_
Teuchos::RCP< NOX::StatusTest::Generic > getStatusTests()
Xyce::Nonlinear::AnalysisMode parametersMode_
void setStatusTestReturnCodes(const Xyce::Nonlinear::ReturnCodes &retCodesTmp)
void resetAll(Xyce::Nonlinear::AnalysisMode mode)
int artificialParameterHomotopy(ParameterSet *paramsPtr)
Interface(const Xyce::IO::CmdParse &cp)
int takeFirstSolveStep(Xyce::Nonlinear::NonLinearSolver *nlsTmpPtr=NULL)
Loader::NonlinearEquationLoader * nonlinearEquationLoader_
bool applyJacobian(const Xyce::Linear::Vector &input, Xyce::Linear::Vector &result)
bool setNodeSetOptions(const Xyce::Util::OptionBlock &OB)
bool setDCOPRestartOptions(const Xyce::Util::OptionBlock &OB)
int gminSteppingSolve(ParameterSet *paramsPtr)
Xyce::Loader::NonlinearEquationLoader & getLoader() const
IO::InitialConditionsManager * initialConditionsManager_
bool setICOptions(const Xyce::Util::OptionBlock &OB)
int sourceSteppingSolve(ParameterSet *paramsPtr)
int mosfetContinuationSolve5(ParameterSet *paramsPtr)
Teuchos::RCP< Teuchos::ParameterList > getAllParams()
bool icCont3(ParameterSet *paramsPtr)
Teuchos::RCP< N_NLS_LOCA::Group > groupPtr_
bool nodesetCont0(ParameterSet *paramsPtr)
bool setNLPOptions(const Xyce::Util::OptionBlock &OB)
int getVectorParamSize(const std::string &vectorName)
Xyce::Nonlinear::AnalysisMode mode_
int mosfetContinuationSolve4(ParameterSet *paramsPtr)
Teuchos::RCP< LOCA::GlobalData > globalDataPtr_
void resetStepper(const Teuchos::RCP< LOCA::GlobalData > &gd, const Teuchos::RCP< LOCA::MultiContinuation::AbstractGroup > &initialGuess, const Teuchos::RCP< NOX::StatusTest::Generic > &test, const Teuchos::RCP< Teuchos::ParameterList > &p)