Xyce  6.1
N_NLS_LOCA_StepSizeControl.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_LOCA_StepSizeControl.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator :
33 //
34 // Creation Date :
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.9 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:29 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
49 
50 #include "LOCA_Continuation_ExtendedGroup.H"
51 #include "LOCA_Stepper.H"
52 #include "NOX_Solver_Generic.H"
53 #include "LOCA_Utils.H"
54 #include "LOCA_MultiContinuation_AbstractStrategy.H"
55 #include "LOCA_MultiContinuation_ExtendedVector.H"
56 #include "LOCA_NewStepper.H"
57 
58 namespace Xyce {
59 namespace Nonlinear {
60 namespace N_NLS_LOCA {
61 
63  maxStepSize(0.0),
64  minStepSize(0.0),
65  agrValue(0.0)
66 {
67 
68 }
69 
71 {
72 }
73 
74 NOX::Abstract::Group::ReturnType
75 StepSizeControl::reset(NOX::Parameter::List& params)
76 {
77  maxStepSize = params.getParameter("Max Step Size", 1.0e+12);
78  minStepSize = params.getParameter("Min Step Size", 1.0e-12);
79  startStepSize = params.getParameter("Initial Step Size", 1.0);
80  failedFactor = params.getParameter("Failed Step Reduction Factor", 0.5);
81  successFactor = params.getParameter("Successful Step Increase Factor", 1.26);
82  prevStepSize = 0.0;
83  isFirstStep = true;
84  agrValue = params.getParameter("Aggressiveness", 0.0);
85 
86  return NOX::Abstract::Group::Ok;
87 }
88 
89 NOX::Abstract::Group::ReturnType
91  LOCA::Continuation::ExtendedGroup& curGroup,
92  const LOCA::Continuation::ExtendedVector& predictor,
93  const NOX::Solver::Generic& solver,
94  const LOCA::Abstract::Iterator::StepStatus& stepStatus,
95  const LOCA::Stepper& stepper,
96  double& stepSize)
97 {
98  // If this is the first step, set step size to initial value
99  if (isFirstStep) {
100  double dpds = predictor.getParam();
101  if (dpds != 0.0) {
102  startStepSize /= dpds;
103  maxStepSize /= dpds;
104  minStepSize /= dpds;
105  }
106  isFirstStep = false;
107  stepSize = startStepSize;
108  prevStepSize = 0.0;
109  }
110  else {
111 
112  // A failed nonlinear solve cuts the step size in half
113  if (stepStatus == LOCA::Abstract::Iterator::Unsuccessful) {
114  stepSize *= failedFactor;
115  }
116  else {
117 
118  double ds_ratio = curGroup.getStepSizeScaleFactor();
119  startStepSize *= ds_ratio;
120  maxStepSize *= ds_ratio;
121  minStepSize *= ds_ratio;
122 
123  // Get maximum number of nonlinear iterations from stepper parameters
124  const NOX::Parameter::List& p = LOCA::Utils::getSublist("Stepper");
125  double maxNonlinearSteps
126  = static_cast<double>(p.getParameter("Max Nonlinear Iterations", 15));
127 
128  // Get number of nonlinear iterations in last step
129  double numNonlinearSteps =
130  static_cast<double>(solver.getNumIterations());
131 
132  // Save successful stepsize as previous
133  prevStepSize = stepSize;
134 
135  // adapive step size control
136  double factor = (maxNonlinearSteps - numNonlinearSteps)
137  / (maxNonlinearSteps);
138 
139  stepSize *= (1.0 + agrValue * factor * factor);
140 
141  stepSize *= ds_ratio;
142  }
143  }
144 
145  // Clip step size to be within prescribed bounds
146  NOX::Abstract::Group::ReturnType res = clipStepSize(stepSize);
147 
148  return res;
149 }
150 
151 NOX::Abstract::Group::ReturnType
153  LOCA::MultiContinuation::AbstractStrategy& curGroup,
154  const LOCA::MultiContinuation::ExtendedVector& predictor,
155  const NOX::Solver::Generic& solver,
156  const LOCA::Abstract::Iterator::StepStatus& stepStatus,
157  const LOCA::NewStepper& stepper,
158  double& stepSize)
159 {
160  // If this is the first step, set step size to initial value
161  if (isFirstStep) {
162  double dpds = predictor.getScalar(0);
163  if (dpds != 0.0) {
164  startStepSize /= dpds;
165  maxStepSize /= dpds;
166  minStepSize /= dpds;
167  }
168  isFirstStep = false;
169  stepSize = startStepSize;
170  prevStepSize = 0.0;
171  }
172  else {
173 
174  // A failed nonlinear solve cuts the step size in half
175  if (stepStatus == LOCA::Abstract::Iterator::Unsuccessful) {
176  stepSize *= failedFactor;
177  }
178  else {
179 
180  double ds_ratio = curGroup.getStepSizeScaleFactor();
181  startStepSize *= ds_ratio;
182  maxStepSize *= ds_ratio;
183  minStepSize *= ds_ratio;
184 
185  // Get maximum number of nonlinear iterations from stepper parameters
186  const NOX::Parameter::List& p = LOCA::Utils::getSublist("Stepper");
187  double maxNonlinearSteps
188  = static_cast<double>(p.getParameter("Max Nonlinear Iterations", 15));
189 
190  // Get number of nonlinear iterations in last step
191  double numNonlinearSteps =
192  static_cast<double>(solver.getNumIterations());
193 
194  // Save successful stepsize as previous
195  prevStepSize = stepSize;
196 
197  // adapive step size control
198  double factor = (maxNonlinearSteps - numNonlinearSteps)
199  / (maxNonlinearSteps);
200 
201  stepSize *= (1.0 + agrValue * factor * factor);
202 
203  stepSize *= ds_ratio;
204  }
205  }
206 
207  // Clip step size to be within prescribed bounds
208  NOX::Abstract::Group::ReturnType res = clipStepSize(stepSize);
209 
210  return res;
211 }
212 
213 
214 NOX::Abstract::Group::ReturnType
216 {
217  NOX::Abstract::Group::ReturnType res = NOX::Abstract::Group::Ok;
218 
219  // Compute sign of step size
220  double signStep = 1.0;
221  if (stepSize < 0.0)
222  signStep = -1.0;
223 
224  // Clip the step size if above the bounds
225  if (fabs(stepSize) > maxStepSize)
226  stepSize = signStep*maxStepSize;
227 
228  // Clip step size at minimum, signal for failed run
229  if (fabs(stepSize) < minStepSize) {
230  res = NOX::Abstract::Group::Failed;
231  stepSize = signStep*minStepSize;
232  if (LOCA::Utils::doPrint(LOCA::Utils::Error)) {
233  cout << "\n\tStep size reached minimum step size bound"
234  << endl;
235  }
236  }
237 
238  return res;
239 }
240 
241 double
243  return prevStepSize;
244 }
245 
246 double
248  return startStepSize;
249 }
250 
251 }}} // namespace N_NLS_LOCA
double successFactor
Factor by which step size is increased after a successful step.
Pure virtual class to augment a linear system.
bool isFirstStep
Flag indicating if this is the first step.
virtual NOX::Abstract::Group::ReturnType compute(LOCA::Continuation::ExtendedGroup &curGroup, const LOCA::Continuation::ExtendedVector &predictor, const NOX::Solver::Generic &solver, const LOCA::Abstract::Iterator::StepStatus &stepStatus, const LOCA::Stepper &stepper, double &stepSize)
virtual NOX::Abstract::Group::ReturnType clipStepSize(double &stepSize)
double agrValue
Stores the aggressiveness factor .
virtual NOX::Abstract::Group::ReturnType reset(NOX::Parameter::List &params)
double failedFactor
Factor by which step size is reduced after a failed step.