Xyce  6.1
N_NLS_NLParams.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_NLParams.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 07/13/01
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.88 $
40 //
41 // Revision Date : $Date: 2015/05/15 13:55:05 $
42 //
43 // Current Owner : $Author $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 #include <N_ERH_ErrorMgr.h>
49 #include <N_IO_CmdParse.h>
50 #include <N_IO_PkgOptionsMgr.h>
51 #include <N_UTL_Param.h>
52 #include <N_NLS_DampedNewton.h>
53 #include <N_NLS_NLParams.h>
54 #include <N_NLS_NonLinearSolver.h>
55 #include <N_NLS_TwoLevelNewton.h>
56 #include <N_UTL_FeatureTest.h>
57 #include <N_UTL_OptionBlock.h>
58 
59 namespace Xyce {
60 namespace Nonlinear {
61 
62 //-----------------------------------------------------------------------------
63 // Function : NLParams::NLParams
64 // Purpose : constructor
65 // Special Notes :
66 // Scope : public
67 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
68 // Creation Date : 5/09/00
69 //-----------------------------------------------------------------------------
70 NLParams::NLParams(AnalysisMode mode, const IO::CmdParse & cp)
71  : commandLine_(&cp),
72  modeToggled_(true),
73  printParamsFlag_(true),
74  debugLevel_(1),
75  debugMinTimeStep_(0),
76  debugMaxTimeStep_(Util::MachineDependentParams::IntMax()),
77  debugMinTime_(0.0),
78  debugMaxTime_(Util::MachineDependentParams::DoubleMax()),
79  screenOutputFlag_(false),
80  maskingFlag_(false),
81  analysisMode_(mode)
82 {
83  // Set default update norm tolerance
85 
86  // Set default small update norm tolerance
88 
89  // Set default residual norm tolerance
90  resetRHSTol();
91 
92  // Set default absolute tolerance value for use in weighted norm
93  resetAbsTol();
94 
95  // Set default relative tolerance value for use in weighted norm
96  resetRelTol();
97 
99 
101  resetDirection();
102  resetNLStrategy();
107  resetNormLevel();
108  resetLinearOpt();
113 
114  // Set the default parameters for transient, if the specified mode
115  // is TRANSIENT.
116  // The defaults set in the NLParams constructor are for DC_OP,
117  // so the transient ones should be reset here.
118  if (mode==TRANSIENT)
119  {
122  setMaxSearchStep(2);
123  setMaxNewtonStep(20);
124  setDeltaXTol(0.33);
125  setForcingFlag(false);
126  setAbsTol(1.0e-06);
127  setRelTol(1.0e-02);
128  setRHSTol(1.0e-02);
129  }
130 
131  if (mode == HB_MODE)
132  {
135  setAbsTol(1.0e-9);
136  setRHSTol(1.0e-4);
137  }
138 
139 
141 }
142 
143 //-----------------------------------------------------------------------------
144 // Function : NLParams::NLParams
145 // Purpose : copy constructor
146 // Special Notes :
147 // Scope : public
148 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
149 // Creation Date : 5/09/00
150 //-----------------------------------------------------------------------------
152  : commandLine_(right.commandLine_),
153  absTol_(right.absTol_),
154  relTol_(right.relTol_),
155  INForcingFlag_(right.INForcingFlag_),
156  eta_(right.eta_),
157  normLevel_(right.normLevel_),
158  linearOptimization_(right.linearOptimization_),
159  modeToggled_(right.modeToggled_),
160  printParamsFlag_(right.printParamsFlag_),
161  analysisMode_(right.analysisMode_),
162  maxNewtonStep_(right.maxNewtonStep_),
163  maxSearchStep_(right.maxSearchStep_),
164  nlStrategy_(right.nlStrategy_),
165  searchMethod_(right.searchMethod_),
166  direction_(right.direction_),
167  deltaXTol_(right.deltaXTol_),
168  RHSTol_(right.RHSTol_),
169  constraintBT_(right.constraintBT_),
170  globalBTMax_(right.globalBTMax_),
171  globalBTMin_(right.globalBTMin_),
172  globalBTChange_(right.globalBTChange_),
173  debugLevel_(right.debugLevel_),
174  debugMinTimeStep_(right.debugMinTimeStep_),
175  debugMaxTimeStep_(right.debugMaxTimeStep_),
176  debugMinTime_(right.debugMinTime_),
177  debugMaxTime_(right.debugMaxTime_)
178 {
179 }
180 
181 //-----------------------------------------------------------------------------
182 // Function : NLParams::~NLParams
183 // Purpose : destructor
184 // Special Notes :
185 // Scope : public
186 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
187 // Creation Date : 5/09/00
188 //-----------------------------------------------------------------------------
190 {
191 // delete lasSolverPtr;
192 }
193 
194 //-----------------------------------------------------------------------------
195 // Function : NLParams::setOptions
196 // Purpose : This function takes an .options statement option block,
197 // and uses it to set the various parameters of
198 // the NLParams class.
199 //
200 // Special Notes : This was originally in DampedNewton, but it makes
201 // more sense to have it here.
202 //
203 // Scope : public
204 // Creator : Eric R. Keiter, SNL, Computational Sciences
205 // Creation Date : 10/20/02
206 //-----------------------------------------------------------------------------
207 
208 bool NLParams::setOptions (const Util::OptionBlock & OB)
209 {
210  for (Util::ParamList::const_iterator it_tpL = OB.begin();
211  it_tpL != OB.end(); ++ it_tpL)
212  {
213  if (it_tpL->uTag() == "ABSTOL")
214  {
215  setAbsTol(it_tpL->getImmutableValue<double>());
216  }
217  else if (it_tpL->uTag() == "RELTOL")
218  {
219  setRelTol(it_tpL->getImmutableValue<double>());
220  }
221  else if (it_tpL->uTag() == "DELTAXTOL")
222  {
223  setDeltaXTol(it_tpL->getImmutableValue<double>());
224  }
225  else if (it_tpL->uTag() == "SMALLUPDATETOL")
226  {
227  setSmallUpdateTol(it_tpL->getImmutableValue<double>());
228  }
229  else if (it_tpL->uTag() == "ENFORCEDEVICECONV")
230  {
231  setEnforceDeviceConvFlag(it_tpL->getImmutableValue<double>());
232  }
233  else if (it_tpL->uTag() == "RHSTOL")
234  {
235  setRHSTol(it_tpL->getImmutableValue<double>());
236  }
237  else if (it_tpL->uTag() == "MAXSTEP")
238  {
239  setMaxNewtonStep(it_tpL->getImmutableValue<int>());
240  }
241  else if (it_tpL->uTag() == "LINOPT")
242  {
243  setLinearOpt(it_tpL->getImmutableValue<int>());
244  }
245  else if (it_tpL->uTag() == "CONSTRAINTBT")
246  {
247  setConstraintBT(it_tpL->getImmutableValue<int>());
248  }
249  else if (it_tpL->uTag() == "CONSTRAINTMAX")
250  {
251  setGlobalBTMax(it_tpL->getImmutableValue<double>());
252  }
253  else if (it_tpL->uTag() == "CONSTRAINTMIN")
254  {
255  setGlobalBTMin(it_tpL->getImmutableValue<double>());
256  }
257  else if (it_tpL->uTag() == "CONSTRAINTCHANGE")
258  {
259  setGlobalBTChange(it_tpL->getImmutableValue<double>());
260  }
261  else if (it_tpL->uTag() == "NLSTRATEGY")
262  {
263  setNLStrategy(it_tpL->getImmutableValue<int>());
264  }
265  else if (it_tpL->uTag() == "SEARCHMETHOD")
266  {
267  setSearchMethod(it_tpL->getImmutableValue<int>());
268  }
269  else if (it_tpL->uTag() == "MAXSEARCHSTEP")
270  {
271  setMaxSearchStep(it_tpL->getImmutableValue<int>());
272  }
273  else if (it_tpL->uTag() == "IN_FORCING")
274  {
275  setForcingFlag(it_tpL->getImmutableValue<int>());
276  }
277  else if (it_tpL->uTag() == "NORMLVL")
278  {
279  setNormLevel(it_tpL->getImmutableValue<int>());
280  }
281  else if (it_tpL->uTag() == "NOX")
282  {
283  // do nothing.
284  }
285  else if (it_tpL->uTag() == "MATRIXMARKET")
286  {
287  if (DEBUG_NONLINEAR)
288  {
289  setMMFormat (static_cast<bool>(it_tpL->getImmutableValue<double>()));
290  }
291  }
292  else if (it_tpL->uTag() == "DEBUGLEVEL")
293  {
294  if (DEBUG_NONLINEAR)
295  {
296  setDebugLevel(it_tpL->getImmutableValue<int>());
297  }
298  }
299  else if (it_tpL->uTag() == "DEBUGMINTIMESTEP")
300  {
301  if (DEBUG_NONLINEAR)
302  {
303  setDebugMinTimeStep(it_tpL->getImmutableValue<int>());
304  }
305  }
306  else if (it_tpL->uTag() == "DEBUGMAXTIMESTEP")
307  {
308  if (DEBUG_NONLINEAR)
309  {
310  setDebugMaxTimeStep(it_tpL->getImmutableValue<int>());
311  }
312  }
313  else if (it_tpL->uTag() == "DEBUGMINTIME")
314  {
315  if (DEBUG_NONLINEAR)
316  {
317  setDebugMinTime(it_tpL->getImmutableValue<double>());
318  }
319  }
320  else if (it_tpL->uTag() == "DEBUGMAXTIME")
321  {
322  if (DEBUG_NONLINEAR)
323  {
324  setDebugMaxTime(it_tpL->getImmutableValue<double>());
325  }
326  }
327  else if (it_tpL->uTag() == "SCREENOUTPUT")
328  {
329  if (DEBUG_NONLINEAR)
330  {
331  setScreenOutputFlag (static_cast<bool>(it_tpL->getImmutableValue<double>()));
332  }
333  }
334  else if (NLS_MASKED_WRMS_NORMS && it_tpL->uTag() == "USEMASKING")
335  {
336  setMaskingFlag(static_cast<bool>(it_tpL->getImmutableValue<double>()));
337  }
338  else
339  {
340  std::string tmp = it_tpL->uTag() +
341  " is not a recognized nonlinear solver option.\n";
342  N_ERH_ErrorMgr::report (N_ERH_ErrorMgr::USR_FATAL_0, tmp);
343  }
344  }
345 
347 
348  return true;
349 }
350 
351 //-----------------------------------------------------------------------------
352 // Function : NLParams::printParams
353 // Purpose : Print out the nonlinear solver parameter values.
354 // Special Notes :
355 // Scope : public
356 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
357 // Creation Date : 01/16/01
358 //-----------------------------------------------------------------------------
359 void NLParams::printParams(std::ostream &os)
360 {
361  os << "\n" << std::endl
362  << Xyce::section_divider << std::endl;
363  os << "\n***** Nonlinear solver options:\n" << std::endl
364  << "\tabsTol:\t\t\t" << getAbsTol() << std::endl
365  << "\trelTol:\t\t\t" << getRelTol() << std::endl
366  << "\tdeltaXTol (weighted):\t" << getDeltaXTol() << std::endl
367  << "\tRHSTol:\t\t\t" << getRHSTol() << std::endl
368  << "\tSmall Update Tol:\t" << getSmallUpdateTol() << std::endl
369  << "\tmax NL Steps:\t\t" << getMaxNewtonStep() << std::endl;
370 
371  if (analysisMode_ == DC_OP)
372  os << "\tAnalysis Mode:\t\t" << analysisMode_ << "\t(DC Op)" << std::endl;
373  else if (analysisMode_ == DC_SWEEP)
374  os << "\tAnalysis Mode:\t\t" << analysisMode_ << "\t(DC Sweep)" << std::endl;
375  else if (analysisMode_ == TRANSIENT)
376  os << "\tAnalysis Mode:\t\t" << analysisMode_ << "\t(Transient)" << std::endl;
377 
378  NLStrategy strategy = getNLStrategy();
379  if (strategy == NEWTON)
380  os << "\tNL Strategy:\t\t" << strategy << "\t(None => Newton)" << std::endl;
381  else if (strategy == GRADIENT)
382  os << "\tNL Strategy:\t\t" << strategy << "\t(Gradient)" << std::endl;
383  else if (strategy == NEWTON_GRADIENT)
384  os << "\tNL Strategy:\t\t" << strategy << "\t(Newton/Gradient)" << std::endl;
385  else if (strategy == MOD_NEWTON)
386  os << "\tNL Strategy:\t\t" << strategy << "\t(Modified-Newton)" << std::endl;
387  else if (strategy == MOD_NEWTON_GRADIENT)
388  os << "\tNL Strategy:\t\t" << strategy << "\t(Modified-Newton/Gradient)" << std::endl;
389 
390  LineSearchMethod searchMethod = getSearchMethod();
391  if (searchMethod == FULL)
392  os << "\tsearch method:\t\t" << searchMethod << "\t(None => Full Newton Steps)" << std::endl;
393 
394  else if (searchMethod == DIVIDE)
395  os << "\tsearch method:\t\t" << searchMethod << "\t(Divide)" << std::endl;
396 
397  else if (searchMethod == BACKTRACK)
398  os << "\tsearch method:\t\t" << searchMethod << "\t(Backtrack)" << std::endl;
399 
400  else if (searchMethod == SIMPLE_BACKTRACK)
401  os << "\tsearch method:\t\t" << searchMethod << "\t(Simple Backtrack)" << std::endl;
402 
403  else if (searchMethod == BANK_ROSE)
404  os << "\tsearch method:\t\t" << searchMethod << "\t(Bank and Rose Algorithm)" << std::endl;
405 
406  else if (searchMethod == DESCENT)
407  os << "\tsearch method:\t\t" << searchMethod << "\t(Line Search)" << std::endl;
408 
409  os << "\tmax search steps:\t" << getMaxSearchStep() << std::endl
410  << "\tinexact-Newton forcing:\t" << getForcingFlag() << std::endl
411  << "\tnorm level:\t\t" << getNormLevel() << std::endl
412  << "\tlinear optimization:\t" << getLinearOpt() << std::endl
413  << "\tconstraint backtrack:\t" << getConstraintBT() << std::endl;
414 
415  if (DEBUG_NONLINEAR)
416  {
417  os << "\tdebugLevel:\t\t" << getDebugLevel () <<std::endl
418  << "\tdebugMinTimeStep:\t" << getDebugMinTimeStep () <<std::endl
419  << "\tdebugMaxTimeStep:\t" << getDebugMaxTimeStep () <<std::endl;
420  }
421 
422  os << Xyce::section_divider << "\n" << std::endl;
423 }
424 
425 //-----------------------------------------------------------------------------
426 // Function : NLParams::operator=
427 // Purpose : "=" operator.
428 // Special Notes :
429 // Scope : public
430 // Creator : Eric R. Keiter, SNL, Computational Sciences
431 // Creation Date : 09/05/01
432 //-----------------------------------------------------------------------------
434 {
435  if (this != &right)
436  {
437  commandLine_ = right.commandLine_;
438  nlStrategy_ = right.nlStrategy_;
440  direction_ = right.direction_;
441  deltaXTol_ = right.deltaXTol_;
442  RHSTol_ = right.RHSTol_;
443  absTol_ = right.absTol_;
444  relTol_ = right.relTol_;
448  eta_ = right.eta_;
449  normLevel_ = right.normLevel_;
450 
452 
454 
456  globalBTMax_ = right.globalBTMax_;
457  globalBTMin_ = right.globalBTMin_;
459 
460  // Debug output options:
461  debugLevel_ = right.debugLevel_;
466  }
467 
468  return *this;
469 }
470 
471 //-----------------------------------------------------------------------------
472 // Function : NLParams::setCmdLineOptions
473 // Purpose :
474 // Special Notes :
475 // Scope : public
476 // Creator : Eric R. Keiter, SNL, Computational Sciences
477 // Creation Date : 05/24/05
478 //-----------------------------------------------------------------------------
479 
481 {
482  // set (or override) debug levels based on command line options
483  if (DEBUG_NONLINEAR && commandLine_->argExists( "-ndl" ))
484  setDebugLevel(commandLine_->getArgumentIntValue("-ndl", getDebugLevel()));
485 
486  return true;
487 }
488 
489 void
491  IO::PkgOptionsMgr& options_manager)
492 {
493  Util::ParamMap &parameters = options_manager.addOptionsMetadataMap("NONLIN");
494 
495  parameters.insert(Util::ParamMap::value_type("NLSTRATEGY", Util::Param("NLSTRATEGY", 0)));
496  parameters.insert(Util::ParamMap::value_type("SEARCHMETHOD", Util::Param("SEARCHMETHOD", 0)));
497  parameters.insert(Util::ParamMap::value_type("NOX", Util::Param("NOX", 1)));
498  parameters.insert(Util::ParamMap::value_type("ABSTOL", Util::Param("ABSTOL", 1.0E-12)));
499  parameters.insert(Util::ParamMap::value_type("RELTOL", Util::Param("RELTOL", 1.0E-3)));
500  parameters.insert(Util::ParamMap::value_type("DELTAXTOL", Util::Param("DELTAXTOL", 1.0)));
501  parameters.insert(Util::ParamMap::value_type("SMALLUPDATETOL", Util::Param("SMALLUPDATETOL", 1.0e-6)));
502  parameters.insert(Util::ParamMap::value_type("RHSTOL", Util::Param("RHSTOL", 1.0E-6)));
503  parameters.insert(Util::ParamMap::value_type("MAXSTEP", Util::Param("MAXSTEP", 200)));
504  parameters.insert(Util::ParamMap::value_type("MAXSEARCHSTEP", Util::Param("MAXSEARCHSTEP", 0)));
505  parameters.insert(Util::ParamMap::value_type("NORMLVL", Util::Param("NORMLVL", 2)));
506  parameters.insert(Util::ParamMap::value_type("LINOPT", Util::Param("LINOPT", 0)));
507  parameters.insert(Util::ParamMap::value_type("CONSTRAINTBT", Util::Param("CONSTRAINTBT", 0)));
508  parameters.insert(Util::ParamMap::value_type("CONSTRAINTMAX", Util::Param("CONSTRAINTMAX", Util::MachineDependentParams::DoubleMax())));
509  parameters.insert(Util::ParamMap::value_type("CONSTRAINTMIN", Util::Param("CONSTRAINTMIN", -Util::MachineDependentParams::DoubleMax())));
510  parameters.insert(Util::ParamMap::value_type("CONSTRAINTCHANGE", Util::Param("CONSTRAINTCHANGE", 0.0)));
511  parameters.insert(Util::ParamMap::value_type("IN_FORCING", Util::Param("IN_FORCING", 0)));
512  parameters.insert(Util::ParamMap::value_type("AZ_TOL", Util::Param("AZ_TOL", 1.0E-12)));
513  parameters.insert(Util::ParamMap::value_type("DLSDEBUG", Util::Param("DLSDEBUG", 0)));
514  parameters.insert(Util::ParamMap::value_type("MATRIXMARKET", Util::Param("MATRIXMARKET", 0)));
515  parameters.insert(Util::ParamMap::value_type("DEBUGLEVEL", Util::Param("DEBUGLEVEL", 1)));
516  parameters.insert(Util::ParamMap::value_type("DEBUGMINTIMESTEP", Util::Param("DEBUGMINTIMESTEP", 0)));
517  parameters.insert(Util::ParamMap::value_type("DEBUGMAXTIMESTEP", Util::Param("DEBUGMAXTIMESTEP", 99999999)));
518  parameters.insert(Util::ParamMap::value_type("DEBUGMINTIME", Util::Param("DEBUGMINTIME", 0.0)));
519  parameters.insert(Util::ParamMap::value_type("DEBUGMAXTIME", Util::Param("DEBUGMAXTIME", 1.0E99)));
520  parameters.insert(Util::ParamMap::value_type("SCREENOUTPUT", Util::Param("SCREENOUTPUT", 0)));
521  parameters.insert(Util::ParamMap::value_type("USEMASKING", Util::Param("USEMASKING", 0)));
522  parameters.insert(Util::ParamMap::value_type("RECOVERYSTEPTYPE", Util::Param("RECOVERYSTEPTYPE", 0)));
523  parameters.insert(Util::ParamMap::value_type("RECOVERYSTEP", Util::Param("RECOVERYSTEP", 1.0)));
524  parameters.insert(Util::ParamMap::value_type("MEMORY", Util::Param("MEMORY", 400)));
525  parameters.insert(Util::ParamMap::value_type("CONTINUATION", Util::Param("CONTINUATION", 0)));
526  parameters.insert(Util::ParamMap::value_type("ENFORCEDEVICECONV", Util::Param("ENFORCEDEVICECONV", 1)));
527 }
528 
529 } // namespace Nonlinear
530 } // namespace Xyce
531 
void setForcingFlag(bool flag)
void setSearchMethod(LineSearchMethod method)
void setGlobalBTMin(double value)
Pure virtual class to augment a linear system.
static void populateMetadata(IO::PkgOptionsMgr &options_manager)
double getSmallUpdateTol() const
void setDebugMinTime(double value)
unsigned getMaxNewtonStep() const
void setMaxSearchStep(unsigned maxSearchStep)
void setSmallUpdateTol(double Tolerance)
void setScreenOutputFlag(bool bval)
void setEnforceDeviceConvFlag(bool flag)
void setNLStrategy(NLStrategy strategy)
void setConstraintBT(bool flag)
NLParams(AnalysisMode mode, const IO::CmdParse &cp)
void setDebugMinTimeStep(int value)
void setGlobalBTChange(double value)
LineSearchMethod getSearchMethod() const
void setDeltaXTol(double Tolerance)
NLParams & operator=(const NLParams &right)
LineSearchMethod searchMethod_
void setRelTol(double Tolerance)
void setDebugLevel(int value)
void setMaskingFlag(bool bval)
void setDebugMaxTimeStep(int value)
void setNormLevel(int level)
void setAbsTol(double Tolerance)
void setGlobalBTMax(double value)
const IO::CmdParse * commandLine_
void setMMFormat(bool value)
double getDeltaXTol() const
void printParams(std::ostream &os)
void setLinearOpt(bool flag)
void setMaxNewtonStep(unsigned maxNewtonStep)
NLStrategy getNLStrategy() const
bool setOptions(const Util::OptionBlock &OB)
void setRHSTol(double Tolerance)
void setDebugMaxTime(double value)
unsigned getMaxSearchStep() const