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