Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.74 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:25 $
42 //
43 // Current Owner : $Author $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 
49 // ---------- Standard Includes ----------
50 
51 // ---------- Xyce Includes ----------
52 #include <N_NLS_NLParams.h>
53 #include <N_ERH_ErrorMgr.h>
54 #include <N_NLS_NonLinearSolver.h>
55 #include <N_NLS_DampedNewton.h>
56 #include <N_UTL_Param.h>
57 #include <N_UTL_OptionBlock.h>
58 #include <N_NLS_TwoLevelNewton.h>
59 #include <N_IO_CmdParse.h>
60 
61 // ---------- Forward Declarations ----------
62 
63 // ---------- Static Initializations ----------
64 
65 //-----------------------------------------------------------------------------
66 // Function : N_NLS_NLParams::N_NLS_NLParams
67 // Purpose : constructor
68 // Special Notes :
69 // Scope : public
70 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
71 // Creation Date : 5/09/00
72 //-----------------------------------------------------------------------------
74  : commandLine_(&cp),
75  modeToggled_(true),
76 #ifdef Xyce_VERBOSE_NONLINEAR
77  printParamsFlag_(true),
78 #endif
79 #ifdef Xyce_DEBUG_NONLINEAR
80  debugLevel_(1),
81  debugMinTimeStep_(0),
82  debugMaxTimeStep_(N_UTL_MachineDependentParams::IntMax()),
83  debugMinTime_(0.0),
84  debugMaxTime_(N_UTL_MachineDependentParams::DoubleMax()),
85  screenOutputFlag_(false),
86 #endif
87  analysisMode_(mode)
88 {
89 
90 // lasSolverPtr = 0;
91  // Set defaults
92 
93  // Set default update norm tolerance
95 
96  // Set default small update norm tolerance
98 
99  // Set default residual norm tolerance
100  resetRHSTol();
101 
102  // Set default absolute tolerance value for use in weighted norm
103  resetAbsTol();
104 
105  // Set default relative tolerance value for use in weighted norm
106  resetRelTol();
107 
109 
111  resetDirection();
112  resetNLStrategy();
117  resetNormLevel();
118  resetLinearOpt();
123 
124  // Set the default parameters for transient, if the specified mode
125  // is TRANSIENT.
126  // The defaults set in the NLParams constructor are for DC_OP,
127  // so the transient ones should be reset here.
128  if (mode==TRANSIENT)
129  {
132  setMaxSearchStep(2);
133  setMaxNewtonStep(20);
134  setDeltaXTol(0.33);
135  setForcingFlag(false);
136  setAbsTol(1.0e-06);
137  setRelTol(1.0e-02);
138  setRHSTol(1.0e-02);
139  }
140 
141  if (mode == HB_MODE)
142  {
145 // setMaxSearchStep(2);
146 // setMaxNewtonStep(10);
147 // setDeltaXTol(0.33);
148 // setForcingFlag(false);
149  setAbsTol(1.0e-9);
150 // setRelTol(1.0e-02);
151  setRHSTol(1.0e-4);
152  }
153 
154 
156 }
157 
158 //-----------------------------------------------------------------------------
159 // Function : N_NLS_NLParams::N_NLS_NLParams
160 // Purpose : copy constructor
161 // Special Notes :
162 // Scope : public
163 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
164 // Creation Date : 5/09/00
165 //-----------------------------------------------------------------------------
167  : commandLine_(right.commandLine_),
168  absTol_(right.absTol_),
169  relTol_(right.relTol_),
170  INForcingFlag_(right.INForcingFlag_),
171  eta_(right.eta_),
172  normLevel_(right.normLevel_),
173  linearOptimization_(right.linearOptimization_),
174  modeToggled_(right.modeToggled_),
175 #ifdef Xyce_VERBOSE_NONLINEAR
176  printParamsFlag_(right.printParamsFlag_),
177 #endif
178  analysisMode_(right.analysisMode_),
179  maxNewtonStep_(right.maxNewtonStep_),
180  maxSearchStep_(right.maxSearchStep_),
181  nlStrategy_(right.nlStrategy_),
182  searchMethod_(right.searchMethod_),
183  direction_(right.direction_),
184  deltaXTol_(right.deltaXTol_),
185  RHSTol_(right.RHSTol_),
186  constraintBT_(right.constraintBT_),
187  globalBTMax_(right.globalBTMax_),
188  globalBTMin_(right.globalBTMin_),
189  globalBTChange_(right.globalBTChange_)
190 #ifdef Xyce_DEBUG_NONLINEAR
191  ,
192  debugLevel_(right.debugLevel_),
193  debugMinTimeStep_(right.debugMinTimeStep_),
194  debugMaxTimeStep_(right.debugMaxTimeStep_),
195  debugMinTime_(right.debugMinTime_),
196  debugMaxTime_(right.debugMaxTime_)
197 #endif
198 {
199 }
200 
201 //-----------------------------------------------------------------------------
202 // Function : N_NLS_NLParams::~N_NLS_NLParams
203 // Purpose : destructor
204 // Special Notes :
205 // Scope : public
206 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
207 // Creation Date : 5/09/00
208 //-----------------------------------------------------------------------------
210 {
211 // if (lasSolverPtr != 0) delete lasSolverPtr;
212 }
213 
214 //-----------------------------------------------------------------------------
215 // Function : N_NLS_NLParams::setOptions
216 // Purpose : This function takes an .options statement option block,
217 // and uses it to set the various parameters of
218 // the NLParams class.
219 //
220 // Special Notes : This was originally in N_NLS_DampedNewton, but it makes
221 // more sense to have it here.
222 //
223 // Scope : public
224 // Creator : Eric R. Keiter, SNL, Computational Sciences
225 // Creation Date : 10/20/02
226 //-----------------------------------------------------------------------------
227 
228 bool N_NLS_NLParams::setOptions (const N_UTL_OptionBlock & OB)
229 {
230  for (std::list<N_UTL_Param>::const_iterator it_tpL = OB.getParams().begin();
231  it_tpL != OB.getParams().end(); ++ it_tpL)
232  {
233  if (it_tpL->uTag() == "ABSTOL")
234  {
235  setAbsTol(it_tpL->getImmutableValue<double>());
236  }
237  else if (it_tpL->uTag() == "RELTOL")
238  {
239  setRelTol(it_tpL->getImmutableValue<double>());
240  }
241  else if (it_tpL->uTag() == "DELTAXTOL")
242  {
243  setDeltaXTol(it_tpL->getImmutableValue<double>());
244  }
245  else if (it_tpL->uTag() == "SMALLUPDATETOL")
246  {
247  setSmallUpdateTol(it_tpL->getImmutableValue<double>());
248  }
249  else if (it_tpL->uTag() == "ENFORCEDEVICECONV")
250  {
251  setEnforceDeviceConvFlag(it_tpL->getImmutableValue<double>());
252  }
253  else if (it_tpL->uTag() == "RHSTOL")
254  {
255  setRHSTol(it_tpL->getImmutableValue<double>());
256  }
257  else if (it_tpL->uTag() == "MAXSTEP")
258  {
259  setMaxNewtonStep(it_tpL->getImmutableValue<int>());
260  }
261  else if (it_tpL->uTag() == "LINOPT")
262  {
263  setLinearOpt(it_tpL->getImmutableValue<int>());
264  }
265  else if (it_tpL->uTag() == "CONSTRAINTBT")
266  {
267  setConstraintBT(it_tpL->getImmutableValue<int>());
268  }
269  else if (it_tpL->uTag() == "CONSTRAINTMAX")
270  {
271  setGlobalBTMax(it_tpL->getImmutableValue<double>());
272  }
273  else if (it_tpL->uTag() == "CONSTRAINTMIN")
274  {
275  setGlobalBTMin(it_tpL->getImmutableValue<double>());
276  }
277  else if (it_tpL->uTag() == "CONSTRAINTCHANGE")
278  {
279  setGlobalBTChange(it_tpL->getImmutableValue<double>());
280  }
281  else if (it_tpL->uTag() == "NLSTRATEGY")
282  {
283  setNLStrategy(it_tpL->getImmutableValue<int>());
284  }
285  else if (it_tpL->uTag() == "SEARCHMETHOD")
286  {
287  setSearchMethod(it_tpL->getImmutableValue<int>());
288  }
289  else if (it_tpL->uTag() == "MAXSEARCHSTEP")
290  {
291  setMaxSearchStep(it_tpL->getImmutableValue<int>());
292  }
293  else if (it_tpL->uTag() == "IN_FORCING")
294  {
295  setForcingFlag(it_tpL->getImmutableValue<int>());
296  }
297  else if (it_tpL->uTag() == "NORMLVL")
298  {
299  setNormLevel(it_tpL->getImmutableValue<int>());
300  }
301  else if (it_tpL->uTag() == "NOX")
302  {
303  // do nothing.
304  }
305  else if (it_tpL->uTag() == "MATRIXMARKET")
306  {
307 #ifdef Xyce_DEBUG_NONLINEAR
308  setMMFormat (static_cast<bool>(it_tpL->getImmutableValue<double>()));
309 #endif
310  }
311  else if (it_tpL->uTag() == "DEBUGLEVEL")
312  {
313 #ifdef Xyce_DEBUG_NONLINEAR
314  setDebugLevel(it_tpL->getImmutableValue<int>());
315 #endif
316  }
317  else if (it_tpL->uTag() == "DEBUGMINTIMESTEP")
318  {
319 #ifdef Xyce_DEBUG_NONLINEAR
320  setDebugMinTimeStep(it_tpL->getImmutableValue<int>());
321 #endif
322  }
323  else if (it_tpL->uTag() == "DEBUGMAXTIMESTEP")
324  {
325 #ifdef Xyce_DEBUG_NONLINEAR
326  setDebugMaxTimeStep(it_tpL->getImmutableValue<int>());
327 #endif
328  }
329  else if (it_tpL->uTag() == "DEBUGMINTIME")
330  {
331 #ifdef Xyce_DEBUG_NONLINEAR
332  setDebugMinTime(it_tpL->getImmutableValue<double>());
333 #endif
334  }
335  else if (it_tpL->uTag() == "DEBUGMAXTIME")
336  {
337 #ifdef Xyce_DEBUG_NONLINEAR
338  setDebugMaxTime(it_tpL->getImmutableValue<double>());
339 #endif
340  }
341  else if (it_tpL->uTag() == "SCREENOUTPUT")
342  {
343 #ifdef Xyce_DEBUG_NONLINEAR
344  setScreenOutputFlag (static_cast<bool>(it_tpL->getImmutableValue<double>()));
345 #endif
346  }
347  else
348  {
349  std::string tmp = it_tpL->uTag() +
350  " is not a recognized nonlinear solver option.\n";
351  N_ERH_ErrorMgr::report (N_ERH_ErrorMgr::USR_FATAL_0, tmp);
352  }
353  }
354 
356 
357  return true;
358 }
359 
360 //-----------------------------------------------------------------------------
361 // Function : N_NLS_NLParams::printParams
362 // Purpose : Print out the nonlinear solver parameter values.
363 // Special Notes :
364 // Scope : public
365 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
366 // Creation Date : 01/16/01
367 //-----------------------------------------------------------------------------
368 void N_NLS_NLParams::printParams(std::ostream &os)
369 {
370  os << "\n" << std::endl
371  << Xyce::section_divider << std::endl;
372  os << "\n***** Nonlinear solver options:\n" << std::endl
373  << "\tabsTol:\t\t\t" << getAbsTol()
374  << "\trelTol:\t\t\t" << getRelTol()
375  << "\tdeltaXTol (weighted):\t" << getDeltaXTol()
376  << "\tRHSTol:\t\t\t" << getRHSTol()
377  << "\tSmall Update Tol:\t" << getSmallUpdateTol()
378  << "\tmax NL Steps:\t\t" << getMaxNewtonStep();
379 
380  if (analysisMode_ == DC_OP)
381  os << "\tAnalysis Mode:\t\t" << analysisMode_ << "\t(DC Op)" << std::endl;
382  else if (analysisMode_ == DC_SWEEP)
383  os << "\tAnalysis Mode:\t\t" << analysisMode_ << "\t(DC Sweep)" << std::endl;
384  else if (analysisMode_ == TRANSIENT)
385  os << "\tAnalysis Mode:\t\t" << analysisMode_ << "\t(Transient)" << std::endl;
386 
387  NLStrategy strategy = getNLStrategy();
388  if (strategy == NEWTON)
389  os << "\tNL Strategy:\t\t" << strategy << "\t(None => Newton)" << std::endl;
390  else if (strategy == GRADIENT)
391  os << "\tNL Strategy:\t\t" << strategy << "\t(Gradient)" << std::endl;
392  else if (strategy == NEWTON_GRADIENT)
393  os << "\tNL Strategy:\t\t" << strategy << "\t(Newton/Gradient)" << std::endl;
394  else if (strategy == MOD_NEWTON)
395  os << "\tNL Strategy:\t\t" << strategy << "\t(Modified-Newton)" << std::endl;
396  else if (strategy == MOD_NEWTON_GRADIENT)
397  os << "\tNL Strategy:\t\t" << strategy << "\t(Modified-Newton/Gradient)" << std::endl;
398 
399  LineSearchMethod searchMethod = getSearchMethod();
400  if (searchMethod == FULL)
401  os << "\tsearch method:\t\t" << searchMethod << "\t(None => Full Newton Steps)" << std::endl;
402 
403  else if (searchMethod == DIVIDE)
404  os << "\tsearch method:\t\t" << searchMethod << "\t(Divide)" << std::endl;
405 
406  else if (searchMethod == BACKTRACK)
407  os << "\tsearch method:\t\t" << searchMethod << "\t(Backtrack)" << std::endl;
408 
409  else if (searchMethod == SIMPLE_BACKTRACK)
410  os << "\tsearch method:\t\t" << searchMethod << "\t(Simple Backtrack)" << std::endl;
411 
412  else if (searchMethod == BANK_ROSE)
413  os << "\tsearch method:\t\t" << searchMethod << "\t(Bank and Rose Algorithm)" << std::endl;
414 
415  else if (searchMethod == DESCENT)
416  os << "\tsearch method:\t\t" << searchMethod << "\t(Line Search)" << std::endl;
417 
418  os << "\tmax search steps:\t" << getMaxSearchStep()
419  << "\tinexact-Newton forcing:\t" << getForcingFlag()
420  << "\tnorm level:\t\t" << getNormLevel()
421  << "\tlinear optimization:\t" << getLinearOpt()
422  << "\tconstraint backtrack:\t" << getConstraintBT()
423 #ifdef Xyce_DEBUG_NONLINEAR
424  << "\tdebugLevel:\t\t" << getDebugLevel ()
425  << "\tdebugMinTimeStep:\t" << getDebugMinTimeStep ()
426  << "\tdebugMaxTimeStep:\t" << getDebugMaxTimeStep ()
427 #endif
428  << Xyce::section_divider << "\n" << std::endl;
429 }
430 
431 //-----------------------------------------------------------------------------
432 // Function : N_NLS_NLParams::operator=
433 // Purpose : "=" operator.
434 // Special Notes :
435 // Scope : public
436 // Creator : Eric R. Keiter, SNL, Computational Sciences
437 // Creation Date : 09/05/01
438 //-----------------------------------------------------------------------------
440 {
441  commandLine_ = right.commandLine_;
442  nlStrategy_ = right.nlStrategy_;
444  direction_ = right.direction_;
445  deltaXTol_ = right.deltaXTol_;
446  RHSTol_ = right.RHSTol_;
447  absTol_ = right.absTol_;
448  relTol_ = right.relTol_;
452  eta_ = right.eta_;
453  normLevel_ = right.normLevel_;
454 
456 
458 
460  globalBTMax_ = right.globalBTMax_;
461  globalBTMin_ = right.globalBTMin_;
463 
464 #ifdef Xyce_DEBUG_NONLINEAR
465  // Debug output options:
466  debugLevel_ = right.debugLevel_;
471 #endif
472 
473  return *this;
474 }
475 
476 //-----------------------------------------------------------------------------
477 // Function : N_NLS_NLParams::setCmdLineOptions
478 // Purpose :
479 // Special Notes :
480 // Scope : public
481 // Creator : Eric R. Keiter, SNL, Computational Sciences
482 // Creation Date : 05/24/05
483 //-----------------------------------------------------------------------------
484 
486 {
487 #ifdef Xyce_DEBUG_NONLINEAR
488  // set (or override) debug levels based on command line options
489  if ( commandLine_->argExists( "-ndl" ) )
490  {
491  setDebugLevel( atoi( commandLine_->getArgumentValue( "-ndl" ).c_str() ) );
492  }
493 #endif
494  return true;
495 }
496 
497