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