Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_Manager.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2014 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_NLS_Manager.C,v $
27 //
28 // Purpose : Body for the nonlinear solver manager class implementation
29 // which will allow for the creation and selection of NLS
30 // algorithms.
31 //
32 // Special Notes : GOF Strategy Pattern
33 //
34 // Creator : Scott A. Hutchinson, SNL, Parallel Computational Sciences
35 //
36 // Creation Date : 04/28/00
37 //
38 // Revision Information:
39 // ---------------------
40 //
41 // Revision Number: $Revision: 1.181 $
42 //
43 // Revision Date : $Date $
44 //
45 // Current Owner : $Author: tvrusso $
46 //-------------------------------------------------------------------------
47 
48 #include <Xyce_config.h>
49 
50 
51 // ---------- Xyce Includes ----------
52 #include <N_UTL_Misc.h>
53 
54 #include <N_NLS_Manager.h>
55 #include <N_NLS_NOX_Interface.h>
56 #include <N_NLS_DampedNewton.h>
57 #include <N_NLS_TwoLevelNewton.h>
58 #include <N_NLS_Sensitivity.h>
60 #include <N_NLS_NonLinInfo.h>
61 
62 #include <N_ERH_ErrorMgr.h>
63 #include <N_IO_CmdParse.h>
64 #include <N_IO_OutputMgr.h>
65 #include <N_UTL_Expression.h>
66 
67 // ---------- Trilinos Includes ----------
68 
69 #include <Teuchos_RefCountPtr.hpp>
70 
71 //-----------------------------------------------------------------------------
72 // Function : N_NLS_Manager::N_NLS_Manager
73 // Purpose : constructor
74 // Special Notes :
75 // Scope : public
76 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
77 // Creation Date : 5/01/00
78 //-----------------------------------------------------------------------------
79 N_NLS_Manager::N_NLS_Manager(N_IO_CmdParse & cp)
80  : commandLine_(cp),
81  twoLevelNewtonFlag_(false),
82  noxFlag_(false),
83  noxFlagInner_(false),
84  noxFlagTransient_(false),
85  anaIntPtr_(0x0),
86  loaderPtr_(0x0),
87  lasSysPtr_(0x0),
88  rhsVecPtr_(0x0),
89  setupSensFlag_(false),
90  nlsSensitivityPtr_(0x0),
91  outputPtr_(0x0),
92  pdsMgrPtr_(0x0),
93  nlsPtr_(0x0),
94  conductanceExtractorPtr_(0x0),
95  initializeAllFlag_(false),
96  exprPtr(0x0)
97 {
98  matrixFreeFlag_ = false;
99 }
100 
101 
102 //-----------------------------------------------------------------------------
103 // Function : N_NLS_Manager::~N_NLS_Manager
104 // Purpose : destructor
105 // Special Notes :
106 // Scope : public
107 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
108 // Creation Date : 5/01/00
109 //-----------------------------------------------------------------------------
110 
112 {
113  delete nlsPtr_;
114  nlsPtr_ = 0x0;
115 
116  if (nlsSensitivityPtr_)
117  {
118  delete nlsSensitivityPtr_;
119  nlsSensitivityPtr_ = 0x0;
120  }
121 
123  {
126  }
127 }
128 
129 //-----------------------------------------------------------------------------
130 // Function : N_NLS_Manager::registerPkgOptionsMgr
131 // Purpose :
132 // Special Notes :
133 // Scope : public
134 // Creator : Rich Schiek, 1437
135 // Creation Date : 10/21/08
136 //-----------------------------------------------------------------------------
137 bool N_NLS_Manager::registerPkgOptionsMgr( N_IO_PkgOptionsMgr *pkgOptPtr )
138 {
139  pkgOptMgrPtr_ = pkgOptPtr;
140  std::string netListFile = "";
141  if (commandLine_.getArgumentValue("netlist") != "")
142  {
143  netListFile = commandLine_.getArgumentValue("netlist");
144  }
145  pkgOptMgrPtr_->submitRegistration(
146  "NONLIN", netListFile, new N_NLS_Manager_OptionsReg( this ) );
147 
148  pkgOptMgrPtr_->submitRegistration(
149  "NONLIN-TRAN", netListFile, new N_NLS_Manager_TranOptionsReg( this ) );
150 
151  pkgOptMgrPtr_->submitRegistration(
152  "NONLIN-HB", netListFile, new N_NLS_Manager_HBOptionsReg( this ) );
153 
154  pkgOptMgrPtr_->submitRegistration(
155  "LINSOL", netListFile, new N_NLS_Manager_LSOptionsReg( this ) );
156 
157  pkgOptMgrPtr_->submitRegistration(
158  "LOCA", netListFile, new N_NLS_Manager_LocaOptionsReg( this ) );
159 
160  pkgOptMgrPtr_->submitRegistration(
161  "SENS", netListFile, new N_NLS_Manager_SensOptionsReg( this ) );
162 
163  pkgOptMgrPtr_->submitRegistration(
164  "SENSITIVITY", netListFile, new N_NLS_Manager_SensitivityOptionsReg( this ) );
165 
166  pkgOptMgrPtr_->submitRegistration(
167  "NONLIN-TWOLEVEL", netListFile, new N_NLS_Manager_TwoLvlOptionsReg( this ) );
168 
169  pkgOptMgrPtr_->submitRegistration(
170  "NONLIN-TWOLEVEL-TRAN", netListFile, new N_NLS_Manager_TwoLvlTranOptionsReg( this ) );
171 
172  pkgOptMgrPtr_->submitRegistration(
173  "TIMEINT", netListFile, new N_NLS_Manager_TimeOptionsReg( this ) );
174 
175  pkgOptMgrPtr_->submitRegistration(
176  "DCOP", netListFile, new N_NLS_Manager_DCOPRestartOptionsReg( this ) );
177 
178  pkgOptMgrPtr_->submitRegistration(
179  "IC", netListFile, new N_NLS_Manager_ICOptionsReg( this ) );
180 
181  pkgOptMgrPtr_->submitRegistration(
182  "NODESET", netListFile, new N_NLS_Manager_NodeSetOptionsReg( this ) );
183  return true;
184 }
185 
186 //-----------------------------------------------------------------------------
187 // Function : N_NLS_Manager::registerParallelMgr
188 // Purpose :
189 // Special Notes :
190 // Scope : public
191 // Creator : Eric Keiter, Sandia
192 // Creation Date :
193 //-----------------------------------------------------------------------------
194 bool N_NLS_Manager::registerParallelMgr (N_PDS_Manager * pdsMgrPtr )
195 {
196  pdsMgrPtr_ = pdsMgrPtr;
197  return (pdsMgrPtr_ != 0x0);
198 }
199 
200 //-----------------------------------------------------------------------------
201 // Function : N_NLS_Manager::setOptions
202 // Purpose : Sets the nonlinear solver options.
203 // Special Notes :
204 // Scope : public
205 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
206 // Creation Date : 9/29/00
207 //-----------------------------------------------------------------------------
208 bool N_NLS_Manager::setOptions(const N_UTL_OptionBlock & OB)
209 {
210  optionBlockMap_["dcop"] = OB;
211  outputPtr_->setEnableHomotopyFlag(true);
212  return true;
213 }
214 
215 //-----------------------------------------------------------------------------
216 // Function : N_NLS_Manager::setTranOptions
217 // Purpose : Sets the nonlinear solver options.
218 // Special Notes :
219 // Scope : public
220 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
221 // Creation Date : 9/05/01
222 //-----------------------------------------------------------------------------
223 bool N_NLS_Manager::setTranOptions(const N_UTL_OptionBlock & OB)
224 {
225  optionBlockMap_["transient"] = OB;
226  return true;
227 }
228 
229 //-----------------------------------------------------------------------------
230 // Function : N_NLS_Manager::setHBOptions
231 // Purpose : Sets the nonlinear solver options.
232 // Special Notes :
233 // Scope : public
234 // Creator : Ting Mei, SNL
235 // Creation Date : 02/03/2009
236 //-----------------------------------------------------------------------------
237 bool N_NLS_Manager::setHBOptions(const N_UTL_OptionBlock & OB)
238 {
239  optionBlockMap_["hb"] = OB;
240  return true;
241 }
242 
243 //-----------------------------------------------------------------------------
244 // Function : N_NLS_Manager::getHBOptions
245 // Purpose : Sets the nonlinear solver options.
246 // Special Notes :
247 // Scope : public
248 // Creator : Ting Mei, SNL
249 // Creation Date : 02/03/2009
250 //-----------------------------------------------------------------------------
251 bool N_NLS_Manager::getHBOptions(N_UTL_OptionBlock & HBOB)
252 {
253  HBOB = optionBlockMap_["hb"];
254  return true;
255 }
256 
257 //-----------------------------------------------------------------------------
258 // Function : N_NLS_Manager::setLinSolOptions
259 // Purpose :
260 // Special Notes :
261 // Scope : public
262 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
263 // Creation Date : 11/9/00
264 //-----------------------------------------------------------------------------
265 bool N_NLS_Manager::setLinSolOptions(const N_UTL_OptionBlock & OB)
266 {
267  optionBlockMap_["petra"] = OB;
268  return true;
269 }
270 
271 //-----------------------------------------------------------------------------
272 // Function : N_NLS_Manager::setLocaOptions
273 // Purpose :
274 // Special Notes :
275 // Scope : public
276 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
277 // Creation Date : 05/02/03
278 //-----------------------------------------------------------------------------
279 bool N_NLS_Manager::setLocaOptions(const N_UTL_OptionBlock & OB)
280 {
281  optionBlockMap_["loca"] = OB;
282  return true;
283 }
284 
285 //-----------------------------------------------------------------------------
286 // Function : N_NLS_Manager::setTwoLevelLocaOptions
287 // Purpose :
288 // Special Notes :
289 // Scope : public
290 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
291 // Creation Date : 05/02/03
292 //-----------------------------------------------------------------------------
293 bool N_NLS_Manager::setTwoLevelLocaOptions(const N_UTL_OptionBlock & OB)
294 {
295  optionBlockMap_["twolevelloca"] = OB;
296  return true;
297 }
298 
299 //-----------------------------------------------------------------------------
300 // Function : N_NLS_Manager::setTwoLevelOptions
301 // Purpose : This option setter will create a new class structure.
302 // Special Notes :
303 // Scope : public
304 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
305 // Creation Date : 10/20/02
306 //-----------------------------------------------------------------------------
307 bool N_NLS_Manager::setTwoLevelOptions(const N_UTL_OptionBlock & OB)
308 {
309  optionBlockMap_["twolevel"] = OB;
310 
311  return true;
312 }
313 
314 //-----------------------------------------------------------------------------
315 // Function : N_NLS_Manager::setTwoLevelTranOptions
316 // Purpose : This option setter will create a new class structure.
317 // Special Notes :
318 // Scope : public
319 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
320 // Creation Date : 10/20/02
321 //-----------------------------------------------------------------------------
322 bool N_NLS_Manager::setTwoLevelTranOptions(const N_UTL_OptionBlock & OB)
323 {
324  optionBlockMap_["twoleveltran"] = OB;
325 
326  return true;
327 }
328 
329 //-----------------------------------------------------------------------------
330 // Function : N_NLS_Manager::registerRHSVector
331 // Purpose :
332 // Special Notes :
333 // Scope : public
334 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
335 // Creation Date : 5/01/00
336 //-----------------------------------------------------------------------------
337 bool N_NLS_Manager::registerRHSVector(N_LAS_Vector* tmp_RHSVecPtr)
338 {
339  rhsVecPtr_ = tmp_RHSVecPtr;
340  return (rhsVecPtr_ != 0x0);
341 }
342 
343 //-----------------------------------------------------------------------------
344 // Function : N_NLS_Manager::registerLoader
345 // Purpose :
346 // Special Notes :
347 // Scope : public
348 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
349 // Creation Date : 5/01/00
350 //-----------------------------------------------------------------------------
351 bool N_NLS_Manager::registerLoader(N_LOA_Loader* tmp_LoaderPtr)
352 {
353  loaderPtr_ = tmp_LoaderPtr;
354  return (loaderPtr_ != 0x0);
355 }
356 
357 //-----------------------------------------------------------------------------
358 // Function : N_NLS_Manager::registerOutputMgr
359 // Purpose :
360 // Special Notes :
361 // Scope : public
362 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
363 // Creation Date : 9/23/03
364 //-----------------------------------------------------------------------------
365 bool N_NLS_Manager::registerOutputMgr(N_IO_OutputMgr * outputPtr)
366 {
367  outputPtr_ = outputPtr;
368  return (outputPtr_ != 0x0);
369 }
370 
371 //-----------------------------------------------------------------------------
372 // Function : N_NLS_Manager::registerLinearSystem
373 // Purpose :
374 // Special Notes :
375 // Scope : public
376 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
377 // Creation Date : 6/09/00
378 //-----------------------------------------------------------------------------
379 bool N_NLS_Manager::registerLinearSystem(N_LAS_System* tmp_LasSysPtr)
380 {
381  lasSysPtr_ = tmp_LasSysPtr;
382  return (lasSysPtr_ != 0x0);
383 }
384 
385 //-----------------------------------------------------------------------------
386 // Function : N_NLS_Manager::registerPrecondFactory
387 // Purpose :
388 // Special Notes :
389 // Scope : public
390 // Creator : Heidi Thornquist, SNL, Electrical & Microsystem Modeling
391 // Creation Date : 11/11/08
392 //-----------------------------------------------------------------------------
393 bool N_NLS_Manager::registerPrecondFactory(const RCP<N_LAS_PrecondFactory>& tmp_LasPrecPtr)
394 {
395  lasPrecPtr_ = tmp_LasPrecPtr;
396  return (!Teuchos::is_null(lasPrecPtr_));
397 }
398 
399 //-----------------------------------------------------------------------------
400 // Function : N_NLS_Manager::registerAnalysisInterface
401 // Purpose :
402 // Special Notes :
403 // Scope : public
404 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
405 // Creation Date : 5/03/00
406 //-----------------------------------------------------------------------------
408 {
409  anaIntPtr_ = tmp_anaIntPtr;
410  return (anaIntPtr_ != 0x0);
411 }
412 
413 //-----------------------------------------------------------------------------
414 // Function : N_NLS_Manager::using Nox_
415 // Purpose : This function determines if we are using NOX or not.
416 // Special Notes :
417 // Scope : private
418 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
419 // Creation Date : 10/30/02
420 //-----------------------------------------------------------------------------
422 {
423  noxFlag_ = true;
424  noxFlagInner_ = true;
425  noxFlagTransient_ = true;
426 
427  N_UTL_OptionBlock OBdcop = optionBlockMap_["dcop"];
428  N_UTL_OptionBlock OBtran = optionBlockMap_["transient"];
429 
430  // scan for changes to the dcop values of noxFlag_
431  for (std::list<N_UTL_Param>::const_iterator it_tpL = OBdcop.getParams().begin();
432  it_tpL != OBdcop.getParams().end(); ++ it_tpL)
433  {
434  if (it_tpL->uTag() == "NOX")
435  {
436  noxFlag_ = it_tpL->getImmutableValue<int>();
438  }
439  }
440 
441  // now check for a nox flag on the .options twolevel line, if it exists.
442  std::map<std::string,N_UTL_OptionBlock>::iterator obmIter = optionBlockMap_.find("twolevel") ;
443  if ( obmIter != optionBlockMap_.end() )
444  {
445  //N_UTL_OptionBlock OBtwoLevel = optionBlockMap_["twolevel"];
446  N_UTL_OptionBlock OBtwoLevel = obmIter->second;
447  for (std::list<N_UTL_Param>::const_iterator it_tpL = OBtwoLevel.getParams().begin();
448  it_tpL != OBtwoLevel.getParams().end(); ++ it_tpL)
449  {
450  if (it_tpL->uTag() == "NOX")
451  {
452  noxFlagInner_ = it_tpL->getImmutableValue<int>();
453  }
454  }
455  }
456 
457 
458  // scan for changes to the transient value for noxFlagTransient_
459  for (std::list<N_UTL_Param>::const_iterator it_tpL = OBtran.getParams().begin();
460  it_tpL != OBtran.getParams().end(); ++ it_tpL)
461  {
462  if (it_tpL->uTag() == "NOX")
463  {
464  noxFlagTransient_ = it_tpL->getImmutableValue<int>();
465  }
466  }
467 
468  obmIter = optionBlockMap_.find("hb") ;
469  if ( obmIter != optionBlockMap_.end() )
470  {
471  N_UTL_OptionBlock OBhb= obmIter->second;
472  for (std::list<N_UTL_Param>::const_iterator it_tpL = OBhb.getParams().begin();
473  it_tpL != OBhb.getParams().end(); ++ it_tpL)
474  {
475  if (it_tpL->uTag() == "NOX")
476  {
477  noxFlag_ = it_tpL->getImmutableValue<int>();
479  }
480  }
481  }
482 
483  // now check if the command line has specified nox. The command line
484  // overrides the netlist.
485  if( commandLine_.getArgumentValue( "-nox" ) == "off" )
486  {
487  noxFlag_ = false;
488  noxFlagInner_ = false;
489  noxFlagTransient_ = false;
490  }
491 
492 #ifdef Xyce_DEBUG_NONLINEAR
493  Xyce::dout() << "noxFlag is: " << (noxFlag_ ? "true" : "false") << std::endl
494  << "noxFlagTransient is: " << (noxFlagTransient_ ? "true" : "false") << std::endl;
495 #endif
496 }
497 
498 //-----------------------------------------------------------------------------
499 // Function : N_NLS_Manager::allocateSolver_
500 // Purpose : This function determines which solver to allocate, and
501 // allocates it.
502 //
503 // Right now the possibilities are:
504 //
505 // N_NLS_DampedNewton
506 // N_NLS_NOXInterface
507 // N_NLS_TwoLevelNewton
508 //
509 // Special Notes :
510 // Scope : private
511 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
512 // Creation Date : 10/28/02
513 //-----------------------------------------------------------------------------
515 {
516  bool bsuccess = true;
517  bool bs1 = true;
518 
519  // determine if we are using NOX or not.
520  usingNox_ ();
521 
522  // if ".options nonlin two-level" appeared in the netlist, then
523  // allocate the two-level solver. Otherwise allocate one of the single
524  // level solvers.
525 
526  if ( (optionBlockMap_.find( "twolevel") != optionBlockMap_.end()) ||
527  (optionBlockMap_.find("twoleveltran") != optionBlockMap_.end())
528  )
529  {
530 
531  twoLevelNewtonFlag_ = true;
533  }
534  else
535  {
536  twoLevelNewtonFlag_ = false;
537  if (noxFlag_)
538  {
539  if( nlsPtr_ != 0x0)
540  delete nlsPtr_;
542  }
543  else
544  {
545  if( nlsPtr_ != 0x0)
546  delete nlsPtr_;
548  }
549  }
550 
551  // now register everything, now that the solver class is set up.
552  bs1 = nlsPtr_->registerLinearSystem(lasSysPtr_); bsuccess = bsuccess && bs1;
553  bs1 = nlsPtr_->registerAnalysisInterface(anaIntPtr_); bsuccess = bsuccess && bs1;
554  bs1 = nlsPtr_->registerLoader(loaderPtr_); bsuccess = bsuccess && bs1;
555 
556  if (!Teuchos::is_null(lasPrecPtr_))
557  bs1 = nlsPtr_->registerPrecondFactory(lasPrecPtr_); bsuccess = bsuccess && bs1;
558 
559  bs1 = nlsPtr_->registerOutputMgr (outputPtr_); bsuccess = bsuccess && bs1;
560  bs1 = nlsPtr_->registerParallelMgr (pdsMgrPtr_); bsuccess = bsuccess && bs1;
561 
562  std::map<std::string,N_UTL_OptionBlock>::iterator obmIter = optionBlockMap_.find("dcop") ;
563 
564  if ( obmIter != optionBlockMap_.end() )
565  {
566  const N_UTL_OptionBlock OB = obmIter->second;
567  bs1 = nlsPtr_->setOptions (OB);
568  bsuccess = bsuccess && bs1;
569  }
570 
571  obmIter = optionBlockMap_.find("transient") ;
572  if ( obmIter != optionBlockMap_.end() )
573  {
574  const N_UTL_OptionBlock OB = obmIter->second;
575  bs1 = nlsPtr_->setTranOptions (OB);
576  bsuccess = bsuccess && bs1;
577  }
578 
579  obmIter = optionBlockMap_.find("hb") ;
580  if ( obmIter != optionBlockMap_.end() )
581  {
582  const N_UTL_OptionBlock OB = obmIter->second;
583  bs1 = nlsPtr_->setHBOptions (OB);
584  bsuccess = bsuccess && bs1;
585  }
586 
587  obmIter = optionBlockMap_.find("loca") ;
588  if ( obmIter != optionBlockMap_.end() )
589  {
590  const N_UTL_OptionBlock OB = obmIter->second;
591  bs1 = nlsPtr_->setLocaOptions (OB);
592  bsuccess = bsuccess && bs1;
593  }
594 
595  obmIter = optionBlockMap_.find("twolevel") ;
596  if ( obmIter != optionBlockMap_.end() )
597  {
598  const N_UTL_OptionBlock OB = obmIter->second;
599  bs1 = nlsPtr_->setTwoLevelOptions (OB);
600  bsuccess = bsuccess && bs1;
601  }
602 
603  obmIter = optionBlockMap_.find("twoleveltran") ;
604  if ( obmIter != optionBlockMap_.end() )
605  {
606  const N_UTL_OptionBlock OB = obmIter->second;
607  bs1 = nlsPtr_->setTwoLevelTranOptions (OB);
608  bsuccess = bsuccess && bs1;
609  }
610 
611  obmIter = optionBlockMap_.find("twolevelloca") ;
612  if ( obmIter != optionBlockMap_.end() )
613  {
614  const N_UTL_OptionBlock OB = obmIter->second;
615  bs1 = nlsPtr_->setTwoLevelLocaOptions (OB);
616  bsuccess = bsuccess && bs1;
617  }
618 
619  obmIter = optionBlockMap_.find("petra") ;
620  if ( obmIter != optionBlockMap_.end() )
621  {
622  const N_UTL_OptionBlock OB = obmIter->second;
623  bs1 = nlsPtr_->setPetraOptions(OB);
624  bsuccess = bsuccess && bs1;
625  }
626 
627  obmIter = optionBlockMap_.find("dcop_restart") ;
628  if ( obmIter != optionBlockMap_.end() )
629  {
630  const N_UTL_OptionBlock OB = obmIter->second;
631  bs1 = nlsPtr_->setDCOPRestartOptions(OB);
632  bsuccess = bsuccess && bs1;
633  }
634 
635  obmIter = optionBlockMap_.find("ic") ;
636  if ( obmIter != optionBlockMap_.end() )
637  {
638  const N_UTL_OptionBlock OB = obmIter->second;
639  bs1 = nlsPtr_->setICOptions(OB);
640  bsuccess = bsuccess && bs1;
641  }
642 
643  obmIter = optionBlockMap_.find("nodeset") ;
644  if ( obmIter != optionBlockMap_.end() )
645  {
646  const N_UTL_OptionBlock OB = obmIter->second;
647  bs1 = nlsPtr_->setNodeSetOptions(OB);
648  bsuccess = bsuccess && bs1;
649  }
650 
651  return bsuccess;
652 }
653 
654 //-----------------------------------------------------------------------------
655 // Function : N_NLS_Manager::initializeAll
656 // Purpose : This can only be called after the linear system
657 // (N_LAS_System) has been registered, and after all the
658 // options have been set.
659 //
660 // Special Notes : This function obtains the solution, temporary solution and
661 // rhs vectors from the LAS system class.
662 // Scope : public
663 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
664 // Creation Date : 6/12/00
665 //-----------------------------------------------------------------------------
667 {
668  bool bsuccess = true;
669  bool bs1 = true;
670  bool bs2 = true;
671 
672  bs1 = allocateSolver_ (); bsuccess = bsuccess && bs1;
674  bs2 = nlsPtr_->initializeAll(); bsuccess = bsuccess && bs2;
675 
677 
678  initializeAllFlag_ = true;
679 
680  if(conductanceExtractorPtr_ == 0x0)
681  {
684  }
685 
686  return bsuccess;
687 }
688 
689 //-----------------------------------------------------------------------------
690 // Function : N_NLS_Manager::allocateTranSolver
691 // Purpose : Allocate a different solver for transient problems if
692 // the user has requested a different one.
693 // Special Notes :
694 // Scope : public
695 // Creator : Rich Schiek, Electrical and Microsystems Modeling
696 // Creation Date : 12/22/08
697 //-----------------------------------------------------------------------------
699 {
700  bool bsuccess = true;
701  bool bs1 = true;
702 
703  // only do a reallocation if the the solver type is changing from dcop to transient
704  if( ((noxFlag_ == true) && (noxFlagTransient_ == false)) ||
705  ((noxFlag_ == false) && (noxFlagTransient_ == true)) )
706  {
707  if (noxFlagTransient_)
708  {
709  if( nlsPtr_ != 0x0)
710  delete nlsPtr_;
712  }
713  else
714  {
715  if( nlsPtr_ != 0x0)
716  delete nlsPtr_;
718  }
719 
720  // now register everything, now that the solver class is set up.
726 
730 
731  std::map<std::string,N_UTL_OptionBlock>::iterator obmIter = optionBlockMap_.find("transient") ;
732  if ( obmIter != optionBlockMap_.end() )
733  {
734  // const N_UTL_OptionBlock OB = optionBlockMap_["transient"];
735  const N_UTL_OptionBlock OB = obmIter->second;
736  bs1 = nlsPtr_->setTranOptions (OB);
737  bsuccess = bsuccess && bs1;
738  }
739 
740  initializeAllFlag_ = true;
743  }
744 }
745 
746 //-----------------------------------------------------------------------------
747 // Function : N_NLS_Manager::isFirstContinuationParam
748 // Purpose : This function returns true if is the first LOCA
749 // continuation param
750 // Special Notes :
751 // Scope : public
752 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
753 // Creation Date : 7/06/05
754 //-----------------------------------------------------------------------------
756 {
758 }
759 
760 //-----------------------------------------------------------------------------
761 // Function : N_NLS_Manager::isFirstSolveComplete
762 // Purpose : This function incdicates if the initial solve has completed
763 // Special Notes :
764 // Scope : public
765 // Creator : Dave Shirley, PSSI
766 // Creation Date : 6/22/06
767 //-----------------------------------------------------------------------------
769 {
770  return nlsPtr_->isFirstSolveComplete ();
771 }
772 
773 //-----------------------------------------------------------------------------
774 // Function : N_NLS_Manager::getContinuationStep
775 // Purpose : This function returns the value of the current LOCA
776 // continuation step.
777 // Special Notes :
778 // Scope : public
779 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
780 // Creation Date : 2/28/05
781 //-----------------------------------------------------------------------------
783 {
784  return nlsPtr_->getContinuationStep ();
785 }
786 
787 //-----------------------------------------------------------------------------
788 // Function : N_NLS_Manager::getLocaFlag
789 // Purpose :
790 // Special Notes :
791 // Scope : public
792 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
793 // Creation Date : 3/09/05
794 //-----------------------------------------------------------------------------
796 {
797  return nlsPtr_->getLocaFlag ();
798 }
799 //-----------------------------------------------------------------------------
800 // Function : N_NLS_Manager::getNumIterations
801 // Purpose : This function returns the value of the current Newton
802 // iteration.
803 // Special Notes :
804 // Scope : public
805 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
806 // Creation Date : 2/23/01
807 //-----------------------------------------------------------------------------
809 {
810  return nlsPtr_->getNumIterations();
811 }
812 
813 //-----------------------------------------------------------------------------
814 // Function : N_NLS_Manager::getCouplingMode
815 // Purpose :
816 // Special Notes :
817 // Scope : public
818 // Creator : Eric R. Keiter, Parallel Computational Sciences
819 // Creation Date : 12/05/02
820 //-----------------------------------------------------------------------------
822 {
823  return nlsPtr_->getCouplingMode ();
824 }
825 
826 //-----------------------------------------------------------------------------
827 // Function : N_NLS_Manager::getNonLinInfo
828 // Purpose :
829 // Special Notes :
830 // Scope : public
831 // Creator : Eric R. Keiter, Parallel Computational Sciences
832 // Creation Date : 12/05/02
833 //-----------------------------------------------------------------------------
835 {
836  nlInfo.newtonIter = nlsPtr_->getNumIterations();
838  nlInfo.locaFlag = nlsPtr_->getLocaFlag ();
839 
840  if (nlInfo.locaFlag)
841  {
845  }
846 }
847 
848 //-----------------------------------------------------------------------------
849 // Function : N_NLS_Manager::getMaxNormF
850 // Purpose :
851 // Special Notes :
852 // Scope : public
853 // Creator : Rich Schiek, Electrical and Mems Modeling
854 // Creation Date : 9/28/2009
855 //-----------------------------------------------------------------------------
857 {
858  return nlsPtr_->getMaxNormF();
859 }
860 
861 
862 //-----------------------------------------------------------------------------
863 // Function : N_NLS_Manager::getMaxNormFindex
864 // Purpose :
865 // Special Notes :
866 // Scope : public
867 // Creator :
868 // Creation Date :
869 //-----------------------------------------------------------------------------
871 {
872  return nlsPtr_->getMaxNormFindex ();
873 }
874 
875 //-----------------------------------------------------------------------------
876 // Function : solve
877 // Purpose :
878 // Special Notes :
879 // Scope : public
880 // Creator : Tamara Kolda, SNL, CSMR
881 // Creation Date : 1/30/02
882 //-----------------------------------------------------------------------------
884 {
885  int status = 0;
886 
887  status = nlsPtr_->solve();
888  if (status >= 0)
889  {
890  if (Teuchos::is_null(exprPtr))
891  exprPtr = Teuchos::rcp( new N_UTL_Expression (std::string("0")) );
892  exprPtr->set_accepted_time();
893  }
894 
895  return status;
896 }
897 
898 //-----------------------------------------------------------------------------
899 // Function : setAnalysisMode
900 // Purpose :
901 // Special Notes :
902 // Scope : public
903 // Creator : Tamara Kolda, SNL, CSMR
904 // Creation Date : 1/30/02
905 //-----------------------------------------------------------------------------
907 {
908  nlsPtr_->setAnalysisMode(mode);
909 }
910 
911 //-----------------------------------------------------------------------------
912 // Function : resetAll
913 // Purpose : like setAnalysisMode, but will also result in NOX
914 // resetting a few extra things.
915 // Special Notes :
916 // Scope : public
917 // Creator : Eric Keiter, SNL, 9233
918 // Creation Date : 1/30/02
919 //-----------------------------------------------------------------------------
921 {
922  nlsPtr_->resetAll (mode);
923 }
924 
925 //-----------------------------------------------------------------------------
926 // Function : getNumResidualLoads
927 // Purpose :
928 // Special Notes :
929 // Scope : public
930 // Creator : Tamara Kolda, SNL, CSMR
931 // Creation Date : 1/30/02
932 //-----------------------------------------------------------------------------
934 {
935  return nlsPtr_->getNumResidualLoads();
936 }
937 
938 //-----------------------------------------------------------------------------
939 // Function : getNumJacobianLoads
940 // Purpose :
941 // Special Notes :
942 // Scope : public
943 // Creator : Tamara Kolda, SNL, CSMR
944 // Creation Date : 1/30/02
945 //-----------------------------------------------------------------------------
947 {
948  return nlsPtr_->getNumJacobianLoads();
949 }
950 
951 //-----------------------------------------------------------------------------
952 // Function : getNumLinearSolves
953 // Purpose :
954 // Special Notes :
955 // Scope : public
956 // Creator : Tamara Kolda, SNL, CSMR
957 // Creation Date : 1/30/02
958 //-----------------------------------------------------------------------------
960 {
961  return nlsPtr_->getNumLinearSolves();
962 }
963 
964 //-----------------------------------------------------------------------------
965 // Function : getNumFailedLinearSolves()
966 // Purpose :
967 // Special Notes :
968 // Scope : public
969 // Creator : Tamara Kolda, SNL, CSMR
970 // Creation Date : 1/30/02
971 //-----------------------------------------------------------------------------
973 {
975 }
976 
977 //-----------------------------------------------------------------------------
978 // Function : getTotalNumLinearIters
979 // Purpose :
980 // Special Notes :
981 // Scope : public
982 // Creator : Scott A. Hutchinson, SNL, Computational Sciences Department
983 // Creation Date : 3/20/02
984 //-----------------------------------------------------------------------------
986 {
988 }
989 
990 //-----------------------------------------------------------------------------
991 // Function : getNumJacobianFactorizations
992 // Purpose :
993 // Special Notes :
994 // Scope : public
995 // Creator : Tamara Kolda, SNL, CSMR
996 // Creation Date : 1/30/02
997 //-----------------------------------------------------------------------------
999 {
1001 }
1002 
1003 //-----------------------------------------------------------------------------
1004 // Function : getTotalLinearSolveTime
1005 // Purpose :
1006 // Special Notes :
1007 // Scope : public
1008 // Creator : Tamara Kolda, SNL, CSMR
1009 // Creation Date : 1/30/02
1010 //-----------------------------------------------------------------------------
1012 {
1013  return nlsPtr_->getTotalLinearSolveTime();
1014 }
1015 
1016 //-----------------------------------------------------------------------------
1017 // Function : getTotalResidualLoadTime
1018 // Purpose :
1019 // Special Notes :
1020 // Scope : public
1021 // Creator : Tamara Kolda, SNL, CSMR
1022 // Creation Date : 1/30/02
1023 //-----------------------------------------------------------------------------
1025 {
1027 }
1028 
1029 //-----------------------------------------------------------------------------
1030 // Function : getTotalJacobianLoadTime
1031 // Purpose :
1032 // Special Notes :
1033 // Scope : public
1034 // Creator : Tamara Kolda, SNL, CSMR
1035 // Creation Date : 1/30/02
1036 //-----------------------------------------------------------------------------
1038 {
1040 }
1041 
1042 //-----------------------------------------------------------------------------
1043 // Function : N_NLS_Manager::setSensOptions
1044 // Purpose :
1045 // Special Notes :
1046 // Scope : public
1047 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1048 // Creation Date : 11/18/02
1049 //-----------------------------------------------------------------------------
1050 bool N_NLS_Manager::setSensOptions (const N_UTL_OptionBlock & OB)
1051 {
1052  bool bsuccess = true;
1053 
1054  optionBlockMap_["sens"] = OB;
1055  return true;
1056 
1057  return bsuccess;
1058 }
1059 
1060 //-----------------------------------------------------------------------------
1061 // Function : N_NLS_Manager::setSensitivityOptions
1062 // Purpose :
1063 // Special Notes :
1064 // Scope : public
1065 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1066 // Creation Date : 11/18/02
1067 //-----------------------------------------------------------------------------
1068 bool N_NLS_Manager::setSensitivityOptions (const N_UTL_OptionBlock & OB)
1069 {
1070  bool bsuccess = true;
1071 
1072  optionBlockMap_["sensitivity"] = OB;
1073  return true;
1074 
1075  return bsuccess;
1076 }
1077 
1078 //-----------------------------------------------------------------------------
1079 // Function : N_NLS_Manager::enableSensitivity
1080 // Purpose :
1081 // Special Notes :
1082 // Scope : public
1083 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1084 // Creation Date : 04/30/03
1085 //-----------------------------------------------------------------------------
1087 {
1088  bool bsuccess = true;
1089 
1090  if (!setupSensFlag_)
1091  {
1092  bool b1 = setupSensitivity_ ();
1093  bsuccess = bsuccess && b1;
1094  }
1095  return bsuccess;
1096 }
1097 
1098 //-----------------------------------------------------------------------------
1099 // Function : N_NLS_Manager::calcSensitivity
1100 // Purpose : This is the controller function for performing a direct
1101 // sensitivity calculation. It is generally called from
1102 // the time integration package, as only that package really
1103 // knows when to do it... (I may change this later.)
1104 // Special Notes :
1105 // Scope : public
1106 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1107 // Creation Date : 10/31/02
1108 //-----------------------------------------------------------------------------
1110  (
1111  std::vector<double> & objectiveVec,
1112  std::vector<double> & dOdpVec,
1113  std::vector<double> & dOdpAdjVec,
1114  std::vector<double> & scaled_dOdpVec,
1115  std::vector<double> & scaled_dOdpAdjVec)
1116 {
1117  bool bsuccess = true;
1118 
1119  if (!setupSensFlag_)
1120  {
1121  std::string msg = "Function N_NLS_Manager::calcSensitivity called,\n";
1122  msg += "but N_NLS_Manager::enableSensitivity must be called first.\n";
1123  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
1124  }
1125 
1126  bsuccess = nlsSensitivityPtr_->solve (objectiveVec,
1127  dOdpVec, dOdpAdjVec,
1128  scaled_dOdpVec, scaled_dOdpAdjVec);
1129 
1130  return bsuccess;
1131 }
1132 
1133 //-----------------------------------------------------------------------------
1134 // Function : N_NLS_Manager::setupSensitivity_
1135 // Purpose :
1136 // Special Notes :
1137 // Scope : private
1138 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1139 // Creation Date : 10/31/02
1140 //-----------------------------------------------------------------------------
1142 {
1143  bool bsuccess = true;
1144  bool bs1 = true;
1145 
1147  bs1 = nlsSensitivityPtr_->registerParallelMgr (pdsMgrPtr_); bsuccess = bsuccess && bs1;
1148 
1149  std::map<std::string,N_UTL_OptionBlock>::iterator obmIter = optionBlockMap_.find("sens") ;
1150  if ( obmIter != optionBlockMap_.end() )
1151  {
1152  const N_UTL_OptionBlock OB = obmIter->second;
1153  bs1 = nlsSensitivityPtr_->setOptions (OB);
1154  bsuccess = bsuccess && bs1;
1155  }
1156 
1157  obmIter = optionBlockMap_.find("sensitivity") ;
1158  if ( obmIter != optionBlockMap_.end() )
1159  {
1160  const N_UTL_OptionBlock OB = obmIter->second;
1162  bsuccess = bsuccess && bs1;
1163  }
1164 
1165  setupSensFlag_ = true;
1166 
1167  return bsuccess;
1168 }
1169 
1170 //-----------------------------------------------------------------------------
1171 // Function : N_NLS_Manager::registerTopology
1172 // Purpose :
1173 // Special Notes :
1174 // Scope : public
1175 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1176 // Creation Date : 6/09/00
1177 //-----------------------------------------------------------------------------
1178 bool N_NLS_Manager::registerTopology (N_TOP_Topology * ptr)
1179 {
1180  topPtr_ = ptr;
1181  return true;
1182 }
1183 
1184 //-----------------------------------------------------------------------------
1185 // Function : N_NLS_Manager::setReturnCodes
1186 // Purpose :
1187 // Special Notes :
1188 // Scope : public
1189 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1190 // Creation Date : 7/02/03
1191 //-----------------------------------------------------------------------------
1193 {
1194  retCodes_ = retCodeTmp;
1195  if (initializeAllFlag_)
1196  {
1198  }
1199 }
1200 
1201 //-----------------------------------------------------------------------------
1202 // Function : N_NLS_Manager::getReturnCodes
1203 // Purpose :
1204 // Special Notes :
1205 // Scope : public
1206 // Creator : Rich Schiek, Electrical and MEMS Modeling
1207 // Creation Date : 9/28/2009
1208 //-----------------------------------------------------------------------------
1210 {
1211  // the N_NLS_ReturnCodes structure is very simple, so just
1212  // return a copy of it.
1213  return retCodes_;
1214 }
1215 
1216 //-----------------------------------------------------------------------------
1217 // Function : N_NLS_Manager::setTimeOptions
1218 // Purpose :
1219 // Special Notes :
1220 // Scope : public
1221 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1222 // Creation Date : 5/29/05
1223 //-----------------------------------------------------------------------------
1224 bool N_NLS_Manager::setTimeOptions(const N_UTL_OptionBlock & OB)
1225 {
1226  bool bsuccess = true;
1227  return bsuccess;
1228 }
1229 
1230 //-----------------------------------------------------------------------------
1231 // Function : N_NLS_Manager::setDCOPRestartOptions
1232 // Purpose :
1233 // Special Notes :
1234 // Scope : public
1235 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1236 // Creation Date : 09/17/07
1237 //-----------------------------------------------------------------------------
1238 bool N_NLS_Manager::setDCOPRestartOptions (const N_UTL_OptionBlock& OB )
1239 {
1240  optionBlockMap_["dcop_restart"] = OB;
1241  return true;
1242 }
1243 
1244 //-----------------------------------------------------------------------------
1245 // Function : N_NLS_Manager::setICOptions
1246 // Purpose :
1247 // Special Notes :
1248 // Scope : public
1249 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1250 // Creation Date : 09/17/07
1251 //-----------------------------------------------------------------------------
1252 bool N_NLS_Manager::setICOptions (const N_UTL_OptionBlock& OB )
1253 {
1254  optionBlockMap_["ic"] = OB;
1255  return true;
1256 }
1257 
1258 //-----------------------------------------------------------------------------
1259 // Function : N_NLS_Manager::setNodeSetOptions
1260 // Purpose :
1261 // Special Notes :
1262 // Scope : public
1263 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1264 // Creation Date : 09/25/07
1265 //-----------------------------------------------------------------------------
1266 bool N_NLS_Manager::setNodeSetOptions (const N_UTL_OptionBlock& OB )
1267 {
1268  optionBlockMap_["nodeset"] = OB;
1269  return true;
1270 }
1271 
1272 //-----------------------------------------------------------------------------
1273 // Function : N_NLS_Manager::obtainConductances
1274 // Purpose :
1275 // Special Notes :
1276 // Scope : public
1277 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1278 // Creation Date : 03/04/06
1279 //-----------------------------------------------------------------------------
1281  const std::map<std::string,double> & inputMap,
1282  std::vector<double> & outputVector,
1283  std::vector< std::vector<double> > & jacobian
1284  )
1285 {
1286  bool bsuccess = true;
1287 
1288  bsuccess =
1289  conductanceExtractorPtr_->extract( inputMap, outputVector, jacobian );
1290 
1291  return bsuccess;
1292 }
1293 
1294 //-----------------------------------------------------------------------------
1295 // Function : N_NLS_Manager::setMatrixFreeFlag
1296 // Purpose :
1297 // Special Notes :
1298 // Scope : public
1299 // Creator : Todd Coffey, Ting Mei
1300 // Creation Date : 07/29/08
1301 //-----------------------------------------------------------------------------
1302 void N_NLS_Manager::setMatrixFreeFlag ( bool matrixFreeFlag )
1303 {
1304  matrixFreeFlag_ = matrixFreeFlag;
1305 }
1306 
1307 //-----------------------------------------------------------------------------
1308 // Function : N_NLS_Manager::obtainConductances
1309 //
1310 // Purpose : Same function as above, only this one is for ISO-devices
1311 // instead of Vsrc's.
1312 // Special Notes :
1313 // Scope : public
1314 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1315 // Creation Date : 03/04/06
1316 //-----------------------------------------------------------------------------
1318  const std::string & isoName,
1319  std::vector< std::vector<double> > & jacobian )
1320 {
1321  bool bsuccess = true;
1322 
1323  bsuccess =
1324  conductanceExtractorPtr_->extract( isoName, jacobian );
1325 
1326  return bsuccess;
1327 }