Xyce  6.1
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-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_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.218.2.1 $
42 //
43 // Revision Date : $Date $
44 //
45 // Current Owner : $Author: tvrusso $
46 //-------------------------------------------------------------------------
47 
48 #include <Xyce_config.h>
49 
50 // ---------- Xyce Includes ----------
51 
52 #include <N_ERH_ErrorMgr.h>
53 #include <N_IO_CmdParse.h>
54 #include <N_IO_OutputMgr.h>
55 #include <N_IO_PkgOptionsMgr.h>
57 #include <N_NLS_DampedNewton.h>
58 #include <N_NLS_Manager.h>
59 #include <N_NLS_NOX_Interface.h>
60 #include <N_NLS_NonLinInfo.h>
61 #include <N_NLS_Sensitivity.h>
62 #include <N_NLS_TwoLevelNewton.h>
63 #include <N_TIA_DataStore.h>
64 #include <N_UTL_Expression.h>
65 #include <N_UTL_FeatureTest.h>
66 
67 // ---------- Trilinos Includes ----------
68 
69 namespace Xyce {
70 namespace Nonlinear {
71 
72 namespace
73 {
74 
75 struct Manager_OptionsReg : public IO::PkgOptionsReg
76 {
77  Manager_OptionsReg( Manager & manager )
78  : manager_(manager)
79  {}
80 
81  bool operator()( const Util::OptionBlock & options )
82  { return manager_.setOptions( options ); }
83 
84  Manager & manager_;
85 };
86 
87 struct Manager_TranOptionsReg : public IO::PkgOptionsReg
88 {
89  Manager_TranOptionsReg( Manager & manager )
90  : manager_(manager)
91  {}
92 
93  bool operator()( const Util::OptionBlock & options )
94  { return manager_.setTranOptions( options ); }
95 
96  Manager & manager_;
97 };
98 
99 struct Manager_HBOptionsReg : public IO::PkgOptionsReg
100 {
101  Manager_HBOptionsReg( Manager & manager )
102  : manager_(manager)
103  {}
104 
105  bool operator()( const Util::OptionBlock & options )
106  { return manager_.setHBOptions( options ); }
107 
108  Manager & manager_;
109 };
110 
111 
112 struct Manager_LSOptionsReg : public IO::PkgOptionsReg
113 {
114  Manager_LSOptionsReg( Manager & manager )
115  : manager_(manager)
116  {}
117 
118  bool operator()( const Util::OptionBlock & options )
119  { return manager_.setLinSolOptions( options ); }
120 
121  Manager & manager_;
122 };
123 
124 struct Manager_LocaOptionsReg : public IO::PkgOptionsReg
125 {
126  Manager_LocaOptionsReg( Manager & manager )
127  : manager_(manager)
128  {}
129 
130  bool operator()( const Util::OptionBlock & options )
131  { return manager_.setLocaOptions( options ); }
132 
133  Manager & manager_;
134 };
135 
136 struct Manager_SensOptionsReg : public IO::PkgOptionsReg
137 {
138  Manager_SensOptionsReg( Manager & manager )
139  : manager_(manager)
140  {}
141 
142  bool operator()( const Util::OptionBlock & options )
143  { return manager_.setSensOptions( options ); }
144 
145  Manager & manager_;
146 };
147 
148 struct Manager_SensitivityOptionsReg : public IO::PkgOptionsReg
149 {
150  Manager_SensitivityOptionsReg( Manager & manager )
151  : manager_(manager)
152  {}
153 
154  bool operator()( const Util::OptionBlock & options )
155  { return manager_.setSensitivityOptions( options ); }
156 
157  Manager & manager_;
158 };
159 
160 struct Manager_TwoLvlOptionsReg : public IO::PkgOptionsReg
161 {
162  Manager_TwoLvlOptionsReg( Manager & manager )
163  : manager_(manager)
164  {}
165 
166  bool operator()( const Util::OptionBlock & options )
167  { return manager_.setTwoLevelOptions( options ); }
168 
169  Manager & manager_;
170 };
171 
172 struct Manager_TwoLvlTranOptionsReg : public IO::PkgOptionsReg
173 {
174  Manager_TwoLvlTranOptionsReg( Manager & manager )
175  : manager_(manager)
176  {}
177 
178  bool operator()( const Util::OptionBlock & options )
179  { return manager_.setTwoLevelTranOptions( options ); }
180 
181  Manager & manager_;
182 };
183 
184 struct Manager_DCOPRestartOptionsReg : public IO::PkgOptionsReg
185 {
186  Manager_DCOPRestartOptionsReg( Manager & manager )
187  : manager_(manager)
188  {}
189 
190  bool operator()( const Util::OptionBlock & options )
191  { return manager_.setDCOPRestartOptions (options); }
192 
193  Manager & manager_;
194 };
195 
196 
197 struct Manager_ICOptionsReg : public IO::PkgOptionsReg
198 {
199  Manager_ICOptionsReg( Manager & manager )
200  : manager_(manager)
201  {}
202 
203  bool operator()( const Util::OptionBlock & options )
204  { return manager_.setICOptions (options); }
205 
206  Manager & manager_;
207 };
208 
209 
210 struct Manager_NodeSetOptionsReg : public IO::PkgOptionsReg
211 {
212  Manager_NodeSetOptionsReg( Manager & manager )
213  : manager_(manager)
214  {}
215 
216  bool operator()( const Util::OptionBlock & options )
217  { return manager_.setNodeSetOptions (options); }
218 
219  Manager & manager_;
220 };
221 
222 } // namespace <unnamed>
223 
224 //-----------------------------------------------------------------------------
225 // Function : registerPkgOptionsMgr
226 // Purpose :
227 // Special Notes :
228 // Scope : public
229 // Creator : Rich Schiek, 1437
230 // Creation Date : 10/21/08
231 //-----------------------------------------------------------------------------
232 bool registerPkgOptionsMgr(Manager &manager, const std::string netlist_filename, IO::PkgOptionsMgr &options_manager)
233 {
234  options_manager.submitRegistration(
235  "NONLIN", netlist_filename, new Manager_OptionsReg( manager ) );
236 
237  options_manager.submitRegistration(
238  "NONLIN-TRAN", netlist_filename, new Manager_TranOptionsReg( manager ) );
239 
240  options_manager.submitRegistration(
241  "NONLIN-HB", netlist_filename, new Manager_HBOptionsReg( manager ) );
242 
243  options_manager.submitRegistration(
244  "LINSOL", netlist_filename, new Manager_LSOptionsReg( manager ) );
245 
246  options_manager.submitRegistration(
247  "LOCA", netlist_filename, new Manager_LocaOptionsReg( manager ) );
248 
249  options_manager.submitRegistration(
250  "SENS", netlist_filename, new Manager_SensOptionsReg( manager ) );
251 
252  options_manager.submitRegistration(
253  "SENSITIVITY", netlist_filename, new Manager_SensitivityOptionsReg( manager ) );
254 
255  options_manager.submitRegistration(
256  "NONLIN-TWOLEVEL", netlist_filename, new Manager_TwoLvlOptionsReg( manager ) );
257 
258  options_manager.submitRegistration(
259  "NONLIN-TWOLEVEL-TRAN", netlist_filename, new Manager_TwoLvlTranOptionsReg( manager ) );
260 
261  options_manager.submitRegistration(
262  "DCOP", netlist_filename, new Manager_DCOPRestartOptionsReg( manager ) );
263 
264  options_manager.submitRegistration(
265  "IC", netlist_filename, new Manager_ICOptionsReg( manager ) );
266 
267  options_manager.submitRegistration(
268  "NODESET", netlist_filename, new Manager_NodeSetOptionsReg( manager ) );
269  return true;
270 }
271 
272 //-----------------------------------------------------------------------------
273 // Function : Manager::Manager
274 // Purpose : constructor
275 // Special Notes :
276 // Scope : public
277 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
278 // Creation Date : 5/01/00
279 //-----------------------------------------------------------------------------
281  const IO::CmdParse & command_line)
282  : commandLine_(command_line),
283  nonlinearSolver_(0),
284  conductanceExtractorPtr_(0),
285  nlsSensitivityPtr_(0),
286  lasPrecPtr_(0),
287  matrixFreeFlag_(false),
288  noxFlag_(false),
289  noxFlagInner_(false),
290  noxFlagTransient_(false),
291  optionBlockMap_(),
292  initializeAllFlag_(false),
293  retCodes_(),
294  exprPtr_(0)
295 {}
296 
297 
298 //-----------------------------------------------------------------------------
299 // Function : Manager::~Manager
300 // Purpose : destructor
301 // Special Notes :
302 // Scope : public
303 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
304 // Creation Date : 5/01/00
305 //-----------------------------------------------------------------------------
306 
308 {
309  delete nonlinearSolver_;
310  delete nlsSensitivityPtr_;
312  delete exprPtr_;
313 }
314 
315 //-----------------------------------------------------------------------------
316 // Function : Manager::setOptions
317 // Purpose : Sets the nonlinear solver options.
318 // Special Notes :
319 // Scope : public
320 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
321 // Creation Date : 9/29/00
322 //-----------------------------------------------------------------------------
323 bool Manager::setOptions(const Util::OptionBlock & option_block)
324 {
325  optionBlockMap_["dcop"] = option_block;
326  return true;
327 }
328 
329 //-----------------------------------------------------------------------------
330 // Function : Manager::setTranOptions
331 // Purpose : Sets the nonlinear solver options.
332 // Special Notes :
333 // Scope : public
334 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
335 // Creation Date : 9/05/01
336 //-----------------------------------------------------------------------------
337 bool Manager::setTranOptions(const Util::OptionBlock & option_block)
338 {
339  optionBlockMap_["transient"] = option_block;
340  return true;
341 }
342 
343 //-----------------------------------------------------------------------------
344 // Function : Manager::setHBOptions
345 // Purpose : Sets the nonlinear solver options.
346 // Special Notes :
347 // Scope : public
348 // Creator : Ting Mei, SNL
349 // Creation Date : 02/03/2009
350 //-----------------------------------------------------------------------------
351 bool Manager::setHBOptions(const Util::OptionBlock & option_block)
352 {
353  optionBlockMap_["hb"] = option_block;
354  return true;
355 }
356 
357 //-----------------------------------------------------------------------------
358 // Function : Manager::getHBOptions
359 // Purpose : Sets the nonlinear solver options.
360 // Special Notes :
361 // Scope : public
362 // Creator : Ting Mei, SNL
363 // Creation Date : 02/03/2009
364 //-----------------------------------------------------------------------------
365 Util::OptionBlock &
367 {
368  return optionBlockMap_["hb"];
369 }
370 
371 //-----------------------------------------------------------------------------
372 // Function : Manager::setLinSolOptions
373 // Purpose :
374 // Special Notes :
375 // Scope : public
376 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
377 // Creation Date : 11/9/00
378 //-----------------------------------------------------------------------------
379 bool Manager::setLinSolOptions(const Util::OptionBlock & option_block)
380 {
381  optionBlockMap_["petra"] = option_block;
382  return true;
383 }
384 
385 //-----------------------------------------------------------------------------
386 // Function : Manager::setLocaOptions
387 // Purpose :
388 // Special Notes :
389 // Scope : public
390 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
391 // Creation Date : 05/02/03
392 //-----------------------------------------------------------------------------
393 bool Manager::setLocaOptions(const Util::OptionBlock & option_block)
394 {
395  optionBlockMap_["loca"] = option_block;
396  return true;
397 }
398 
399 //-----------------------------------------------------------------------------
400 // Function : Manager::setTwoLevelLocaOptions
401 // Purpose :
402 // Special Notes :
403 // Scope : public
404 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
405 // Creation Date : 05/02/03
406 //-----------------------------------------------------------------------------
407 bool Manager::setTwoLevelLocaOptions(const Util::OptionBlock & option_block)
408 {
409  optionBlockMap_["twolevelloca"] = option_block;
410  return true;
411 }
412 
413 //-----------------------------------------------------------------------------
414 // Function : Manager::setTwoLevelOptions
415 // Purpose : This option setter will create a new class structure.
416 // Special Notes :
417 // Scope : public
418 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
419 // Creation Date : 10/20/02
420 //-----------------------------------------------------------------------------
421 bool Manager::setTwoLevelOptions(const Util::OptionBlock & option_block)
422 {
423  optionBlockMap_["twolevel"] = option_block;
424 
425  return true;
426 }
427 
428 //-----------------------------------------------------------------------------
429 // Function : Manager::setTwoLevelTranOptions
430 // Purpose : This option setter will create a new class structure.
431 // Special Notes :
432 // Scope : public
433 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
434 // Creation Date : 10/20/02
435 //-----------------------------------------------------------------------------
436 bool Manager::setTwoLevelTranOptions(const Util::OptionBlock & option_block)
437 {
438  optionBlockMap_["twoleveltran"] = option_block;
439 
440  return true;
441 }
442 
443 //-----------------------------------------------------------------------------
444 // Function : setReturnCodeOption
445 // Purpose :
446 // Special Notes :
447 // Scope : public
448 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
449 // Creation Date : 04/18/02
450 //-----------------------------------------------------------------------------
451 bool
453  const Util::Param & param)
454 {
455  if (param.uTag() == "NLNEARCONV" )
456  {
457  // nlNearConvFlag = static_cast<bool> (param.getImmutableValue<int>());
459  codes.nearConvergence = param.getImmutableValue<int>() ? 3 : -3;
460  setReturnCodes(codes);
461  }
462  else if (param.uTag() == "NLSMALLUPDATE" )
463  {
464  // nlSmallUpdateFlag = static_cast<bool> (param.getImmutableValue<int>());
466  codes.smallUpdate = param.getImmutableValue<int>() ? 4 : -4;
467  setReturnCodes(codes);
468  }
469  else
470  {
471  return false;
472  }
473 
474  return true;
475 }
476 
477 //-----------------------------------------------------------------------------
478 // Function : Manager::using Nox_
479 // Purpose : This function determines if we are using NOX or not.
480 // Special Notes :
481 // Scope : private
482 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
483 // Creation Date : 10/30/02
484 //-----------------------------------------------------------------------------
486 {
487  noxFlag_ = true;
488  noxFlagInner_ = true;
489  noxFlagTransient_ = true;
490 
491  const Util::OptionBlock &option_blockdcop = optionBlockMap_["dcop"];
492  const Util::OptionBlock &option_blocktran = optionBlockMap_["transient"];
493 
494  // scan for changes to the dcop values of noxFlag_
495  for (Util::ParamList::const_iterator it = option_blockdcop.begin(); it != option_blockdcop.end(); ++ it)
496  {
497  if ((*it).uTag() == "NOX")
498  {
499  noxFlag_ = (*it).getImmutableValue<int>();
501  }
502  }
503 
504  // now check for a nox flag on the .options twolevel line, if it exists.
505  OptionBlockMap::const_iterator obmIter = optionBlockMap_.find("twolevel") ;
506  if ( obmIter != optionBlockMap_.end() )
507  {
508  const Util::OptionBlock &option_blocktwoLevel = obmIter->second;
509  for (Util::ParamList::const_iterator it = option_blocktwoLevel.begin(); it != option_blocktwoLevel.end(); ++ it)
510  {
511  if ((*it).uTag() == "NOX")
512  {
513  noxFlagInner_ = (*it).getImmutableValue<int>();
514  }
515  }
516  }
517 
518 
519  // scan for changes to the transient value for noxFlagTransient_
520  for (Util::ParamList::const_iterator it = option_blocktran.begin(); it != option_blocktran.end(); ++ it)
521  {
522  if ((*it).uTag() == "NOX")
523  {
524  noxFlagTransient_ = (*it).getImmutableValue<int>();
525  }
526  }
527 
528  obmIter = optionBlockMap_.find("hb") ;
529  if ( obmIter != optionBlockMap_.end() )
530  {
531  const Util::OptionBlock &option_blockhb = obmIter->second;
532  for (Util::ParamList::const_iterator it = option_blockhb.begin(); it != option_blockhb.end(); ++ it)
533  {
534  if ((*it).uTag() == "NOX")
535  {
536  noxFlag_ = (*it).getImmutableValue<int>();
538  }
539  }
540  }
541 
542  // now check if the command line has specified nox. The command line
543  // overrides the netlist.
544  if( commandLine_.getArgumentValue( "-nox" ) == "off" )
545  {
546  noxFlag_ = false;
547  noxFlagInner_ = false;
548  noxFlagTransient_ = false;
549  }
550 
551  if (DEBUG_NONLINEAR)
552  Xyce::dout() << "noxFlag is: " << (noxFlag_ ? "true" : "false") << std::endl
553  << "noxFlagTransient is: " << (noxFlagTransient_ ? "true" : "false") << std::endl;
554 }
555 
556 //-----------------------------------------------------------------------------
557 // Function : Manager::allocateSolver
558 // Purpose : This function determines which solver to allocate, and
559 // allocates it.
560 //
561 // Right now the possibilities are:
562 //
563 // DampedNewton
564 // NOXInterface
565 // TwoLevelNewton
566 //
567 // Special Notes :
568 // Scope : private
569 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
570 // Creation Date : 10/28/02
571 //-----------------------------------------------------------------------------
572 bool
574  Analysis::AnalysisManager & analysis_manager,
575  Loader::NonlinearEquationLoader & nonlinear_equation_loader,
576  Linear::System & linear_system,
577  TimeIntg::DataStore & data_store,
578  Parallel::Manager & parallel_manager,
579  IO::InitialConditionsManager & initial_conditions_manager,
580  IO::OutputMgr & output_manager)
581 {
582  bool bsuccess = true;
583  bool bs1 = true;
584 
585  // determine if we are using NOX or not.
586  usingNox();
587 
588  // if ".options nonlin two-level" appeared in the netlist, then
589  // allocate the two-level solver. Otherwise allocate one of the single
590  // level solvers.
591 
592  if (optionBlockMap_.find("twolevel") != optionBlockMap_.end()
593  || optionBlockMap_.find("twoleveltran") != optionBlockMap_.end())
594  {
595  twoLevelNewtonFlag_ = true;
597  }
598  else
599  {
600  twoLevelNewtonFlag_ = false;
601  if (noxFlag_)
602  {
603  delete nonlinearSolver_;
605  }
606  else
607  {
608  delete nonlinearSolver_;
610  }
611  }
612 
613  // now register everything, now that the solver class is set up.
614  bs1 = nonlinearSolver_->registerLinearSystem(&linear_system); bsuccess = bsuccess && bs1;
615  bs1 = nonlinearSolver_->registerAnalysisManager(&analysis_manager); bsuccess = bsuccess && bs1;
616  bs1 = nonlinearSolver_->registerLoader(&nonlinear_equation_loader); bsuccess = bsuccess && bs1;
617  bs1 = nonlinearSolver_->registerTIADataStore(&data_store); bsuccess = bsuccess && bs1;
618 
619  if (lasPrecPtr_)
620  bs1 = nonlinearSolver_->registerPrecondFactory(lasPrecPtr_); bsuccess = bsuccess && bs1;
621 
622  bs1 = nonlinearSolver_->registerOutputMgr(&output_manager); bsuccess = bsuccess && bs1;
623  bs1 = nonlinearSolver_->registerInitialConditionsManager(&initial_conditions_manager); bsuccess = bsuccess && bs1;
624  bs1 = nonlinearSolver_->registerParallelMgr(&parallel_manager); bsuccess = bsuccess && bs1;
625 
626  OptionBlockMap::const_iterator it = optionBlockMap_.find("dcop") ;
627  if ( it != optionBlockMap_.end() )
628  {
629  const Util::OptionBlock &option_block = (*it).second;
630  bs1 = nonlinearSolver_->setOptions (option_block);
631  bsuccess = bsuccess && bs1;
632  }
633 
634  it = optionBlockMap_.find("transient") ;
635  if ( it != optionBlockMap_.end() )
636  {
637  const Util::OptionBlock &option_block = (*it).second;
638  bs1 = nonlinearSolver_->setTranOptions (option_block);
639  bsuccess = bsuccess && bs1;
640  }
641 
642  it = optionBlockMap_.find("hb") ;
643  if ( it != optionBlockMap_.end() )
644  {
645  const Util::OptionBlock &option_block = (*it).second;
646  bs1 = nonlinearSolver_->setHBOptions (option_block);
647  bsuccess = bsuccess && bs1;
648  }
649 
650  it = optionBlockMap_.find("loca") ;
651  if ( it != optionBlockMap_.end() )
652  {
653  const Util::OptionBlock &option_block = (*it).second;
654  bs1 = nonlinearSolver_->setLocaOptions (option_block);
655  bsuccess = bsuccess && bs1;
656  }
657 
658  it = optionBlockMap_.find("twolevel") ;
659  if ( it != optionBlockMap_.end() )
660  {
661  const Util::OptionBlock &option_block = (*it).second;
662  bs1 = nonlinearSolver_->setTwoLevelOptions (option_block);
663  bsuccess = bsuccess && bs1;
664  }
665 
666  it = optionBlockMap_.find("twoleveltran") ;
667  if ( it != optionBlockMap_.end() )
668  {
669  const Util::OptionBlock &option_block = (*it).second;
670  bs1 = nonlinearSolver_->setTwoLevelTranOptions (option_block);
671  bsuccess = bsuccess && bs1;
672  }
673 
674  it = optionBlockMap_.find("twolevelloca") ;
675  if ( it != optionBlockMap_.end() )
676  {
677  const Util::OptionBlock &option_block = (*it).second;
678  bs1 = nonlinearSolver_->setTwoLevelLocaOptions (option_block);
679  bsuccess = bsuccess && bs1;
680  }
681 
682  it = optionBlockMap_.find("petra") ;
683  if ( it != optionBlockMap_.end() )
684  {
685  const Util::OptionBlock &option_block = (*it).second;
686  bs1 = nonlinearSolver_->setPetraOptions(option_block);
687  bsuccess = bsuccess && bs1;
688  }
689 
690  it = optionBlockMap_.find("dcop_restart") ;
691  if ( it != optionBlockMap_.end() )
692  {
693  const Util::OptionBlock &option_block = (*it).second;
694  bs1 = nonlinearSolver_->setDCOPRestartOptions(option_block);
695  bsuccess = bsuccess && bs1;
696  }
697 
698  it = optionBlockMap_.find("ic") ;
699  if ( it != optionBlockMap_.end() )
700  {
701  const Util::OptionBlock &option_block = (*it).second;
702  bs1 = nonlinearSolver_->setICOptions(option_block);
703  bsuccess = bsuccess && bs1;
704  }
705 
706  it = optionBlockMap_.find("nodeset") ;
707  if ( it != optionBlockMap_.end() )
708  {
709  const Util::OptionBlock &option_block = (*it).second;
710  bs1 = nonlinearSolver_->setNodeSetOptions(option_block);
711  bsuccess = bsuccess && bs1;
712  }
713 
714  return bsuccess;
715 }
716 
717 //-----------------------------------------------------------------------------
718 // Function : Manager::initializeAll
719 // Purpose : This can only be called after the linear system
720 // (Linear::System) has been registered, and after all the
721 // options have been set.
722 //
723 // Special Notes : This function obtains the solution, temporary solution and
724 // rhs vectors from the LAS system class.
725 // Scope : public
726 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
727 // Creation Date : 6/12/00
728 //-----------------------------------------------------------------------------
729 bool
731  Analysis::AnalysisManager & analysis_manager,
732  Loader::NonlinearEquationLoader & nonlinear_equation_loader,
733  Linear::System & linear_system,
734  TimeIntg::DataStore & data_store,
735  Parallel::Manager & parallel_manager,
736  IO::InitialConditionsManager & initial_conditions_manager,
737  IO::OutputMgr & output_manager,
738  Topo::Topology & topology)
739 {
740  bool bsuccess = true;
741  bool bs1 = true;
742  bool bs2 = true;
743 
744  bs1 = allocateSolver(analysis_manager, nonlinear_equation_loader, linear_system, data_store, parallel_manager, initial_conditions_manager, output_manager);
745  bsuccess = bsuccess && bs1;
746 
748  bs2 = nonlinearSolver_->initializeAll(); bsuccess = bsuccess && bs2;
749 
751 
752  initializeAllFlag_ = true;
753 
755  {
757  }
758 
759  return bsuccess;
760 }
761 
762 //-----------------------------------------------------------------------------
763 // Function : Manager::allocateTranSolver
764 // Purpose : Allocate a different solver for transient problems if
765 // the user has requested a different one.
766 // Special Notes :
767 // Scope : public
768 // Creator : Rich Schiek, Electrical and Microsystems Modeling
769 // Creation Date : 12/22/08
770 //-----------------------------------------------------------------------------
771 void
773  Analysis::AnalysisManager & analysis_manager,
774  Loader::NonlinearEquationLoader & nonlinear_equation_loader,
775  Linear::System & linear_system,
776  TimeIntg::DataStore & data_store,
777  Parallel::Manager & parallel_manager,
778  IO::OutputMgr & output_manager,
779  Topo::Topology & topology)
780 {
781  bool bsuccess = true;
782  bool bs1 = true;
783 
784  // only do a reallocation if the the solver type is changing from dcop to transient
786  {
787  if (noxFlagTransient_)
788  {
789  delete nonlinearSolver_;
791  }
792  else
793  {
794  delete nonlinearSolver_;
796  }
797 
798  // now register everything, now that the solver class is set up.
799  nonlinearSolver_->registerLinearSystem(&linear_system);
800  nonlinearSolver_->registerAnalysisManager(&analysis_manager);
801  nonlinearSolver_->registerLoader(&nonlinear_equation_loader);
803  nonlinearSolver_->registerOutputMgr(&output_manager);
804  nonlinearSolver_->registerParallelMgr(&parallel_manager);
805 
809 
810  OptionBlockMap::const_iterator it = optionBlockMap_.find("transient") ;
811  if (it != optionBlockMap_.end())
812  {
813  const Util::OptionBlock &option_block = (*it).second;
814  bs1 = nonlinearSolver_->setTranOptions (option_block);
815  bsuccess = bsuccess && bs1;
816  }
817 
818  initializeAllFlag_ = true;
819 
822  }
823 }
824 
825 //-----------------------------------------------------------------------------
826 // Function : Manager::getNonLinInfo
827 // Purpose :
828 // Special Notes :
829 // Scope : public
830 // Creator : Eric R. Keiter, Parallel Computational Sciences
831 // Creation Date : 12/05/02
832 //-----------------------------------------------------------------------------
834 {
835  NonLinInfo nlInfo;
836 
840 
841  if (nlInfo.locaFlag)
842  {
846  }
847 
848  return nlInfo;
849 }
850 
851 //-----------------------------------------------------------------------------
852 // Function : solve
853 // Purpose :
854 // Special Notes :
855 // Scope : public
856 // Creator : Tamara Kolda, SNL, CSMR
857 // Creation Date : 1/30/02
858 //-----------------------------------------------------------------------------
860 {
861  int status = 0;
862 
863  status = nonlinearSolver_->solve();
864  if (status >= 0)
865  {
866  if (!exprPtr_)
867  exprPtr_ = new Util::Expression(std::string("0"));
868 
869  exprPtr_->set_accepted_time();
870  }
871 
872  return status;
873 }
874 
875 //-----------------------------------------------------------------------------
876 // Function : setAnalysisMode
877 // Purpose :
878 // Special Notes :
879 // Scope : public
880 // Creator : Tamara Kolda, SNL, CSMR
881 // Creation Date : 1/30/02
882 //-----------------------------------------------------------------------------
884 {
886 }
887 
888 //-----------------------------------------------------------------------------
889 // Function : resetAll
890 // Purpose : like setAnalysisMode, but will also result in NOX
891 // resetting a few extra things.
892 // Special Notes :
893 // Scope : public
894 // Creator : Eric Keiter, SNL, 9233
895 // Creation Date : 1/30/02
896 //-----------------------------------------------------------------------------
898 {
899  nonlinearSolver_->resetAll (mode);
900 }
901 
902 //-----------------------------------------------------------------------------
903 // Function : Manager::setSensOptions
904 // Purpose :
905 // Special Notes :
906 // Scope : public
907 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
908 // Creation Date : 11/18/02
909 //-----------------------------------------------------------------------------
910 bool Manager::setSensOptions (const Util::OptionBlock & option_block)
911 {
912  optionBlockMap_["sens"] = option_block;
913  return true;
914 }
915 
916 //-----------------------------------------------------------------------------
917 // Function : Manager::setSensitivityOptions
918 // Purpose :
919 // Special Notes :
920 // Scope : public
921 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
922 // Creation Date : 11/18/02
923 //-----------------------------------------------------------------------------
924 bool Manager::setSensitivityOptions (const Util::OptionBlock & option_block)
925 {
926  optionBlockMap_["sensitivity"] = option_block;
927  return true;
928 }
929 
930 //-----------------------------------------------------------------------------
931 // Function : Manager::enableSensitivity
932 // Purpose :
933 // Special Notes :
934 // Scope : public
935 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
936 // Creation Date : 04/30/03
937 //-----------------------------------------------------------------------------
938 bool
940  TimeIntg::DataStore & data_store,
941  Parallel::Manager & parallel_manager,
942  Topo::Topology & topology)
943 {
944  bool bsuccess = true;
945 
946  if (!nlsSensitivityPtr_)
947  {
948  Stats::StatTop _sensitivityStat("Setup");
949 
950  bool b1 = setupSensitivity(data_store, parallel_manager, topology);
951  bsuccess = bsuccess && b1;
952  }
953  return bsuccess;
954 }
955 
956 //-----------------------------------------------------------------------------
957 // Function : Manager::icSensitivity
958 // Purpose :
959 // Special Notes :
960 // Scope : public
961 // Creator : Eric R. Keiter, SNL
962 // Creation Date :
963 //-----------------------------------------------------------------------------
965  std::vector<double> & objectiveVec,
966  std::vector<double> & dOdpVec,
967  std::vector<double> & dOdpAdjVec,
968  std::vector<double> & scaled_dOdpVec,
969  std::vector<double> & scaled_dOdpAdjVec)
970 {
971  if (!nlsSensitivityPtr_)
972  {
973  Report::DevelFatal0().in("Manager::isSensitivity") << "Manager::enableSensitivity must be called first";
974  return false;
975  }
976 
977  return nlsSensitivityPtr_->icSensitivity(objectiveVec, dOdpVec, dOdpAdjVec, scaled_dOdpVec, scaled_dOdpAdjVec);
978 }
979 
980 //-----------------------------------------------------------------------------
981 // Function : Manager::calcSensitivity
982 // Purpose : This is the controller function for performing a direct
983 // sensitivity calculation. It is generally called from
984 // the time integration package, as only that package really
985 // knows when to do it... (I may change this later.)
986 // Special Notes :
987 // Scope : public
988 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
989 // Creation Date : 10/31/02
990 //-----------------------------------------------------------------------------
992  (
993  std::vector<double> & objectiveVec,
994  std::vector<double> & dOdpVec,
995  std::vector<double> & dOdpAdjVec,
996  std::vector<double> & scaled_dOdpVec,
997  std::vector<double> & scaled_dOdpAdjVec)
998 {
999  bool bsuccess = true;
1000 
1001  if (!nlsSensitivityPtr_)
1002  {
1003  Report::DevelFatal0().in("Manager::calcSensitivity") << "Manager::enableSensitivity must be called first";
1004  return false;
1005  }
1006 
1007  bsuccess = nlsSensitivityPtr_->solve(objectiveVec, dOdpVec, dOdpAdjVec, scaled_dOdpVec, scaled_dOdpAdjVec);
1008 
1009  return bsuccess;
1010 }
1011 
1012 //-----------------------------------------------------------------------------
1013 // Function : Manager::setupSensitivity
1014 // Purpose :
1015 // Special Notes :
1016 // Scope : private
1017 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
1018 // Creation Date : 10/31/02
1019 //-----------------------------------------------------------------------------
1020 bool
1022  TimeIntg::DataStore & data_store,
1023  Parallel::Manager & parallel_manager,
1024  Topo::Topology & topology)
1025 {
1026  if (nlsSensitivityPtr_)
1027  {
1028  Report::DevelFatal0().in("Manager::setupSensitivity") << "Manager::enableSensitivity may only be called once";
1029  return false;
1030  }
1031 
1032  bool bsuccess = true;
1033  bool bs1 = true;
1034 
1036  bs1 = nlsSensitivityPtr_->registerParallelMgr(&parallel_manager); bsuccess = bsuccess && bs1;
1037  bs1 = nlsSensitivityPtr_->registerTIADataStore(&data_store); bsuccess = bsuccess && bs1;
1038 
1039  OptionBlockMap::const_iterator it = optionBlockMap_.find("sens") ;
1040  if ( it != optionBlockMap_.end() )
1041  {
1042  const Util::OptionBlock &option_block = it->second;
1043  bs1 = nlsSensitivityPtr_->setOptions(option_block);
1044  bsuccess = bsuccess && bs1;
1045  }
1046 
1047  it = optionBlockMap_.find("sensitivity") ;
1048  if ( it != optionBlockMap_.end() )
1049  {
1050  const Util::OptionBlock &option_block = it->second;
1051  bs1 = nlsSensitivityPtr_->setSensitivityOptions(option_block);
1052  bsuccess = bsuccess && bs1;
1053  }
1054 
1055  return bsuccess;
1056 }
1057 
1058 //-----------------------------------------------------------------------------
1059 // Function : Manager::setReturnCodes
1060 // Purpose :
1061 // Special Notes :
1062 // Scope : public
1063 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1064 // Creation Date : 7/02/03
1065 //-----------------------------------------------------------------------------
1066 void Manager::setReturnCodes(const ReturnCodes & retCodeTmp)
1067 {
1068  retCodes_ = retCodeTmp;
1069  if (initializeAllFlag_)
1070  {
1072  }
1073 }
1074 
1075 //-----------------------------------------------------------------------------
1076 // Function : Manager::getReturnCodes
1077 // Purpose :
1078 // Special Notes :
1079 // Scope : public
1080 // Creator : Rich Schiek, Electrical and MEMS Modeling
1081 // Creation Date : 9/28/2009
1082 //-----------------------------------------------------------------------------
1084 {
1085  // the ReturnCodes structure is very simple, so just
1086  // return a copy of it.
1087  return retCodes_;
1088 }
1089 
1090 //-----------------------------------------------------------------------------
1091 // Function : Manager::setDCOPRestartOptions
1092 // Purpose :
1093 // Special Notes :
1094 // Scope : public
1095 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1096 // Creation Date : 09/17/07
1097 //-----------------------------------------------------------------------------
1098 bool Manager::setDCOPRestartOptions (const Util::OptionBlock& option_block )
1099 {
1100  optionBlockMap_["dcop_restart"] = option_block;
1101  return true;
1102 }
1103 
1104 //-----------------------------------------------------------------------------
1105 // Function : Manager::setICOptions
1106 // Purpose :
1107 // Special Notes :
1108 // Scope : public
1109 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1110 // Creation Date : 09/17/07
1111 //-----------------------------------------------------------------------------
1112 bool Manager::setICOptions (const Util::OptionBlock& option_block )
1113 {
1114  optionBlockMap_["ic"] = option_block;
1115  return true;
1116 }
1117 
1118 //-----------------------------------------------------------------------------
1119 // Function : Manager::setNodeSetOptions
1120 // Purpose :
1121 // Special Notes :
1122 // Scope : public
1123 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
1124 // Creation Date : 09/25/07
1125 //-----------------------------------------------------------------------------
1126 bool Manager::setNodeSetOptions (const Util::OptionBlock& option_block )
1127 {
1128  optionBlockMap_["nodeset"] = option_block;
1129  return true;
1130 }
1131 
1132 } // namespace Nonlinear
1133 } // namespace Xyce
bool setTranOptions(const Util::OptionBlock &option_block)
bool enableSensitivity(TimeIntg::DataStore &data_store, Parallel::Manager &parallel_manager, Topo::Topology &topology)
bool noxFlagTransient_
For 2-level newton, option for inner loop to use nox.
bool registerLoader(Loader::NonlinearEquationLoader *ptr)
virtual void setMatrixFreeFlag(bool matrixFreeFlag)
NonLinInfo getNonLinInfo() const
bool icSensitivity(std::vector< double > &objectiveVec, std::vector< double > &dOdpVec, std::vector< double > &dOdpAdjVec, std::vector< double > &scaled_dOdpVec, std::vector< double > &scaled_dOdpAdjVec)
virtual bool setTwoLevelLocaOptions(const Util::OptionBlock &OB)
Manager & manager_
Definition: N_NLS_Manager.C:84
bool setSensOptions(const Util::OptionBlock &option_block)
virtual int solve(NonLinearSolver *nlsTmpPtr=NULL)=0
bool setTwoLevelTranOptions(const Util::OptionBlock &option_block)
virtual bool setTranOptions(const Util::OptionBlock &OB)=0
virtual bool setTwoLevelOptions(const Util::OptionBlock &OB)
virtual bool setNodeSetOptions(const Util::OptionBlock &OB)
bool registerTIADataStore(TimeIntg::DataStore *tiaDSPtr)
bool calcSensitivity(std::vector< double > &objectiveVec, std::vector< double > &dOdpVec, std::vector< double > &dOdpAdjVec, std::vector< double > &scaled_dOdpVec, std::vector< double > &scaled_dOdpAdjVec)
bool registerParallelMgr(N_PDS_Manager *pdsMgrPtr)
Pure virtual class to augment a linear system.
OptionBlockMap optionBlockMap_
Use nox in transient phase of calculation.
virtual int getNumIterations() const =0
virtual void setReturnCodes(const ReturnCodes &retCodesTmp)
virtual bool setICOptions(const Util::OptionBlock &OB)
virtual bool isFirstSolveComplete() const =0
bool setTwoLevelLocaOptions(const Util::OptionBlock &option_block)
virtual bool isFirstContinuationParam() const =0
bool setLocaOptions(const Util::OptionBlock &option_block)
virtual void resetAll(AnalysisMode mode)
void setAnalysisMode(AnalysisMode mode)
virtual bool setPetraOptions(const Util::OptionBlock &OB)
ConductanceExtractor * conductanceExtractorPtr_
bool allocateSolver(Analysis::AnalysisManager &analysis_manager, Loader::NonlinearEquationLoader &nonlinear_equation_loader, Linear::System &linear_system, TimeIntg::DataStore &data_store, Parallel::Manager &parallel_manager, IO::InitialConditionsManager &initial_conditions_manager, IO::OutputMgr &output_manager)
Manager(const IO::CmdParse &command_line)
bool setNodeSetOptions(const Util::OptionBlock &option_block)
bool setLinSolOptions(const Util::OptionBlock &option_block)
void resetAll(AnalysisMode mode)
bool setSensitivityOptions(const Util::OptionBlock &option_block)
const ReturnCodes & getReturnCodes() const
bool registerInitialConditionsManager(IO::InitialConditionsManager *outPtr)
void setReturnCodes(const ReturnCodes &retCodeTmp)
virtual TwoLevelNewtonMode getCouplingMode()
bool registerPrecondFactory(const Linear::PrecondFactory *ptr)
bool icSensitivity(std::vector< double > &objectiveVec, std::vector< double > &dOdpVec, std::vector< double > &dOdpAdjVec, std::vector< double > &scaled_dOdpVec, std::vector< double > &scaled_dOdpAdjVec)
bool noxFlagInner_
Flag to determine if NOX is the solver in use.
bool setOptions(const Util::OptionBlock &OB)
TwoLevelNewtonMode twoLevelNewtonCouplingMode
bool initializeAll(Analysis::AnalysisManager &analysis_manager, Loader::NonlinearEquationLoader &nonlinear_equation_loader, Linear::System &linear_system, TimeIntg::DataStore &data_store, Parallel::Manager &parallel_manager, IO::InitialConditionsManager &initial_conditions_manager, IO::OutputMgr &output_manager, Topo::Topology &topology)
virtual int getContinuationStep() const =0
bool registerPkgOptionsMgr(Manager &manager, const std::string netlist_filename, IO::PkgOptionsMgr &options_manager)
bool setSensitivityOptions(const Util::OptionBlock &OB)
bool noxFlag_
Flag to determine if we are doing 2-level newton or not.
Util::OptionBlock & getHBOptions()
const IO::CmdParse & commandLine_
bool setICOptions(const Util::OptionBlock &option_block)
bool setHBOptions(const Util::OptionBlock &option_block)
bool setOptions(const Util::OptionBlock &option_block)
bool setupSensitivity(TimeIntg::DataStore &data_store, Parallel::Manager &parallel_manager, Topo::Topology &topology)
bool registerLinearSystem(Linear::System *ptr)
NonLinearSolver * nonlinearSolver_
bool setTwoLevelOptions(const Util::OptionBlock &option_block)
const Linear::PrecondFactory * lasPrecPtr_
Util::Expression * exprPtr_
Return Codes.
bool registerAnalysisManager(Analysis::AnalysisManager *tmp_anaIntPtr)
void allocateTranSolver(Analysis::AnalysisManager &analysis_manager, Loader::NonlinearEquationLoader &nonlinear_equation_loader, Linear::System &linear_system, TimeIntg::DataStore &data_store, Parallel::Manager &parallel_manager, IO::OutputMgr &output_manager, Topo::Topology &topology)
virtual void setAnalysisMode(AnalysisMode mode)=0
virtual bool setHBOptions(const Util::OptionBlock &OB)=0
Sensitivity * nlsSensitivityPtr_
bool initializeAllFlag_
netlist option blocks until we know which
bool registerOutputMgr(IO::OutputMgr *outPtr)
virtual bool setDCOPRestartOptions(const Util::OptionBlock &OB)
virtual bool setOptions(const Util::OptionBlock &OB)=0
virtual bool setTwoLevelTranOptions(const Util::OptionBlock &OB)
bool setDCOPRestartOptions(const Util::OptionBlock &option_block)
bool setReturnCodeOption(const Util::Param &param)
virtual bool setLocaOptions(const Util::OptionBlock &OB)