Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_FirstOrderErrorStepControlStrategy_def.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef Rythmos_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_DEF_H
30 #define Rythmos_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_DEF_H
31 
32 #include "Rythmos_FirstOrderErrorStepControlStrategy_decl.hpp"
33 #include "Thyra_VectorStdOps.hpp"
34 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
35 
36 namespace Rythmos {
37 
38 // Static members
39 
40 
41 template<class Scalar>
42 const std::string
43 FirstOrderErrorStepControlStrategy<Scalar>::initialStepSizeName_
44 = "Initial Step Size";
45 
46 template<class Scalar>
47 const double
48 FirstOrderErrorStepControlStrategy<Scalar>::initialStepSizeDefault_
49 = 1.0;
50 
51 
52 template<class Scalar>
53 const std::string
54 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeName_
55 = "Min Step Size";
56 
57 template<class Scalar>
58 const double
59 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeDefault_
60 = std::numeric_limits<Scalar>::min();
61 
62 
63 template<class Scalar>
64 const std::string
65 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeName_
66 = "Max Step Size";
67 
68 template<class Scalar>
69 const double
70 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeDefault_
71 = std::numeric_limits<Scalar>::max();
72 
73 
74 template<class Scalar>
75 const std::string
76 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeIncreaseFactorName_
77 = "Max Step Size Increase Factor";
78 
79 template<class Scalar>
80 const double
81 FirstOrderErrorStepControlStrategy<Scalar>::maxStepSizeIncreaseFactorDefault_
82 = 1.5;
83 
84 
85 template<class Scalar>
86 const std::string
87 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeDecreaseFactorName_
88 = "Min Step Size Decrease Factor";
89 
90 template<class Scalar>
91 const double
92 FirstOrderErrorStepControlStrategy<Scalar>::minStepSizeDecreaseFactorDefault_
93 = 0.5;
94 
95 
96 template<class Scalar>
97 const std::string
98 FirstOrderErrorStepControlStrategy<Scalar>::maxStepFailuresName_
99 = "Maximum Number of Step Failures";
100 
101 template<class Scalar>
102 const int
103 FirstOrderErrorStepControlStrategy<Scalar>::maxStepFailuresDefault_
104 = 100;
105 
106 
107 template<class Scalar>
108 const std::string
109 FirstOrderErrorStepControlStrategy<Scalar>::errorRelativeToleranceName_
110 = "Error Relative Tolerance";
111 
112 template<class Scalar>
113 const double
114 FirstOrderErrorStepControlStrategy<Scalar>::errorRelativeToleranceDefault_
115 = 1.0e-06;
116 
117 
118 template<class Scalar>
119 const std::string
120 FirstOrderErrorStepControlStrategy<Scalar>::errorAbsoluteToleranceName_
121 = "Error Absolute Tolerance";
122 
123 template<class Scalar>
124 const double
125 FirstOrderErrorStepControlStrategy<Scalar>::errorAbsoluteToleranceDefault_
126 = 1.0e-12;
127 
128 
129 // Constructors
130 
131 template<class Scalar>
132 void FirstOrderErrorStepControlStrategy<Scalar>::setStepControlState_(
133  StepControlStrategyState newState)
134 {
135  if (stepControlState_ == UNINITIALIZED) {
136  TEUCHOS_TEST_FOR_EXCEPT(newState != BEFORE_FIRST_STEP);
137  } else if (stepControlState_ == BEFORE_FIRST_STEP) {
138  TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
139  } else if (stepControlState_ == MID_STEP) {
140  TEUCHOS_TEST_FOR_EXCEPT(newState != AFTER_CORRECTION);
141  } else if (stepControlState_ == AFTER_CORRECTION) {
142  TEUCHOS_TEST_FOR_EXCEPT(newState != READY_FOR_NEXT_STEP);
143  } else if (stepControlState_ == READY_FOR_NEXT_STEP) {
144  TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
145  }
146  stepControlState_ = newState;
147 }
148 
149 template<class Scalar>
151 {
152  return(stepControlState_);
153 }
154 
155 template<class Scalar>
157  : stepControlState_(UNINITIALIZED),
158  initialStepSize_(initialStepSizeDefault_),
159  stepSizeType_(STEP_TYPE_VARIABLE),
160  minStepSize_(minStepSizeDefault_),
161  maxStepSize_(maxStepSizeDefault_),
162  maxStepSizeIncreaseFactor_(maxStepSizeIncreaseFactorDefault_),
163  minStepSizeDecreaseFactor_(minStepSizeDecreaseFactorDefault_),
164  numStepFailures_(0),
165  maxStepFailures_(maxStepFailuresDefault_),
166  maxOrder_(1),
167  errorRelativeTolerance_(errorRelativeToleranceDefault_),
168  errorAbsoluteTolerance_(errorAbsoluteToleranceDefault_),
169  solveStatus_(0)
170 {}
171 
172 template<class Scalar>
174  const StepperBase<Scalar>& stepper)
175 {
176  using Teuchos::as;
177  //typedef Teuchos::ScalarTraits<Scalar> ST; // unused
178  using Thyra::createMember;
179 
180  RCP<Teuchos::FancyOStream> out = this->getOStream();
181  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
182  const bool doTrace = (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH));
183  Teuchos::OSTab ostab(out,1,"initialize");
184 
185  if (doTrace) {
186  *out << "\nEntering " << this->Teuchos::Describable::description()
187  << "::initialize()...\n";
188  }
189 
190  if (is_null(errWtVec_))
191  errWtVec_ = createMember(stepper.get_x_space());
192  setStepControlState_(BEFORE_FIRST_STEP);
193 
194  if (doTrace) {
195  *out << "\nLeaving " << this->Teuchos::Describable::description()
196  << "::initialize()...\n";
197  }
198 }
199 
200 template<class Scalar>
202  const StepperBase<Scalar>& stepper,
203  const Scalar& stepSize,
204  const StepSizeType& stepSizeType)
205 {
206  typedef Teuchos::ScalarTraits<Scalar> ST;
207  TEUCHOS_TEST_FOR_EXCEPTION(
208  !((stepControlState_ == UNINITIALIZED) ||
209  (stepControlState_ == BEFORE_FIRST_STEP) ||
210  (stepControlState_ == READY_FOR_NEXT_STEP) ||
211  (stepControlState_ == MID_STEP)), std::logic_error,
212  "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
213  << ") for FirstOrderErrorStepControlStrategy<Scalar>::setRequestedStepSize()\n");
214 
215  TEUCHOS_TEST_FOR_EXCEPTION(
216  ((stepSizeType == STEP_TYPE_FIXED) && (stepSize == ST::zero())),
217  std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
218  "but requested step size == 0!\n");
219 
220  TEUCHOS_TEST_FOR_EXCEPTION(
221  ((stepSizeType == STEP_TYPE_FIXED) && (stepSize < minStepSize_)),
222  std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
223  "and (stepSize="<<stepSize<<") < (minStepSize="<<minStepSize_<<")!\n");
224 
225  TEUCHOS_TEST_FOR_EXCEPTION(
226  ((stepSizeType == STEP_TYPE_FIXED) && (stepSize > maxStepSize_)),
227  std::logic_error, "Error, step size type == STEP_TYPE_FIXED, "
228  "and (stepSize="<<stepSize<<") > (maxStepSize="<<maxStepSize_<<")!\n");
229 
230  if (stepControlState_ == UNINITIALIZED) initialize(stepper);
231  requestedStepSize_ = stepSize;
232  stepSizeType_ = stepSizeType;
233 }
234 
235 template<class Scalar>
237  const StepperBase<Scalar>& /* stepper */, Scalar* stepSize,
238  StepSizeType* stepSizeType, int* /* order */)
239 {
240  TEUCHOS_TEST_FOR_EXCEPTION(!((stepControlState_ == BEFORE_FIRST_STEP) ||
241  (stepControlState_ == MID_STEP) ||
242  (stepControlState_ == READY_FOR_NEXT_STEP) ),
243  std::logic_error,
244  "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
245  << ") for FirstOrderErrorStepControlStrategy<Scalar>::nextStepSize()\n");
246 
247  if (stepControlState_ == BEFORE_FIRST_STEP) {
248  if (initialStepSize_ == initialStepSizeDefault_)
249  initialStepSize_ = requestedStepSize_;
250  nextStepSize_ = initialStepSize_;
251  }
252 
253  stepSizeType_ = *stepSizeType;
254  if (stepSizeType_ == STEP_TYPE_FIXED)
255  currentStepSize_ = requestedStepSize_;
256  else // STEP_TYPE_VARIABLE
257  currentStepSize_ = nextStepSize_;
258 
259  // Limit the step size to the requested step size
260  currentStepSize_ = std::min(requestedStepSize_, currentStepSize_);
261 
262  *stepSize = currentStepSize_;
263  setStepControlState_(MID_STEP);
264 }
265 
266 template<class Scalar>
268  const StepperBase<Scalar>& /* stepper */
269  ,const RCP<const Thyra::VectorBase<Scalar> >& soln
270  ,const RCP<const Thyra::VectorBase<Scalar> >& dx
271  ,int solveStatus)
272 {
273  TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != MID_STEP, std::logic_error,
274  "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
275  << ") for FirstOrderErrorStepControlStrategy<Scalar>::setCorrection()\n");
276  x_ = soln;
277  dx_ = dx;
278  solveStatus_ = solveStatus;
279  setStepControlState_(AFTER_CORRECTION);
280 }
281 
282 template<class Scalar>
284  const StepperBase<Scalar>& /* stepper */, Scalar* /* value */)
285 {
286  TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
287  std::logic_error,
288  "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
289  << ") for FirstOrderErrorStepControlStrategy<Scalar>::completeStep()\n");
290 
291  // Let's construct the weight here for now. We will replace with it
292  // with a errWtVecSet() in the future.
293  Thyra::abs(*x_, Teuchos::ptrFromRef(*errWtVec_));
294  Thyra::Vt_S(Teuchos::ptrFromRef(*errWtVec_), errorRelativeTolerance_);
295  Thyra::Vp_S(Teuchos::ptrFromRef(*errWtVec_), errorAbsoluteTolerance_);
296  reciprocal(*errWtVec_, Teuchos::ptrFromRef(*errWtVec_));
297  typedef Teuchos::ScalarTraits<Scalar> ST;
298  // We square w because of how weighted norm_2 is computed.
299  Vt_StV(Teuchos::ptrFromRef(*errWtVec_), ST::one(), *errWtVec_);
300  // divide by N to get RMS norm
301  int N = x_->space()->dim();
302  Vt_S(Teuchos::ptrFromRef(*errWtVec_), Teuchos::as<Scalar>(1.0/N));
303  double wrms = norm_2(*errWtVec_,(*dx_));
304  stepSizeFactor_ = sqrt(2.0/wrms); // Factor for 1st order. See
305  // Gresho and Sani, "Incompressible
306  // Flow and the Finite Element Method",
307  // Vol. 1, 1998, p. 268.
308  bool return_status = true;
309  // If the error is too large (stepSizeFactor_ too small) OR
310  // the solve failed, reduce the step size and try again.
311  if ( (stepSizeFactor_ < minStepSizeDecreaseFactor_) || solveStatus_ < 0 )
312  return_status = false;
313 
314  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
315  if ( Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ||
316  (return_status == false &&
317  Teuchos::as<int>(verbLevel) != Teuchos::as<int>(Teuchos::VERB_NONE)) ) {
318  RCP<Teuchos::FancyOStream> out = this->getOStream();
319  Teuchos::OSTab ostab(out,1,"acceptStep");
320  *out << "\n wrms = " << wrms << "\n"
321  << " stepSizeFactor_ = " << stepSizeFactor_ << "\n"
322  << " solveStatus_ = " << solveStatus_ << "\n"
323  << " minStepSizeDecreaseFactor_ = " << minStepSizeDecreaseFactor_
324  << "\n";
325  }
326 
327  return(return_status);
328 }
329 
330 template<class Scalar>
332  const StepperBase<Scalar>& /* stepper */)
333 {
334  TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
335  std::logic_error,
336  "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
337  << ") for FirstOrderErrorStepControlStrategy<Scalar>::completeStep()\n");
338 
339  setStepControlState_(READY_FOR_NEXT_STEP);
340 
341  using Teuchos::as;
342 
343  RCP<Teuchos::FancyOStream> out = this->getOStream();
344  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
345  Teuchos::OSTab ostab(out,1,"rejectStep");
346 
347  numStepFailures_ ++;
348  if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) )
349  *out << "numStepFailures_ = " << numStepFailures_ << "\n";
350  if (numStepFailures_ > maxStepFailures_) {
351  *out << "Rythmos_FirstOrderErrorStepControlStrategy::rejectStep(...): "
352  << "Error: Too many step failures "
353  << "(numStepFailures="<<numStepFailures_
354  <<") > (maxStepFailures="<<maxStepFailures_<<")\n";
355  return (REP_ERR_FAIL);
356  }
357 
358  // Fail if we are running with fixed stepsize.
359  if (stepSizeType_ == STEP_TYPE_FIXED) {
360  if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) ) {
361  *out << "Rythmos_FirstOrderErrorStepControl::rejectStep(...): "
362  << "Error: Step failure with fixed step size.\n";
363  }
364  return (REP_ERR_FAIL);
365  }
366 
367  nextStepSize_ = currentStepSize_*
368  std::max(stepSizeFactor_, minStepSizeDecreaseFactor_);
369  nextStepSize_ = std::max(nextStepSize_, minStepSize_);
370  nextStepSize_ = std::min(nextStepSize_, maxStepSize_);
371 
372  AttemptedStepStatusFlag return_status = PREDICT_AGAIN;
373 
374  if ( as<int>(verbLevel) != as<int>(Teuchos::VERB_NONE) ) {
375  *out << "Rythmos_FirstOrderErrorStepControl::rejectStep(...): Step failure.\n"
376  << " Current step size is "<< currentStepSize_ <<".\n"
377  << " Reducing next step size to "<< nextStepSize_ <<".\n";
378  }
379 
380  return(return_status);
381 }
382 
383 template<class Scalar>
385  const StepperBase<Scalar>& /* stepper */)
386 {
387  TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
388  std::logic_error,
389  "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
390  << ") for FirstOrderErrorStepControlStrategy<Scalar>::completeStep()\n");
391 
392  // Only update the time step if we are NOT running constant stepsize.
393  if (stepSizeType_ == STEP_TYPE_VARIABLE) {
394  // Only increase stepSize_ if no recent step failures.
395  if (numStepFailures_ == 0) {
396  nextStepSize_ *= std::max(minStepSizeDecreaseFactor_,
397  std::min(stepSizeFactor_, maxStepSizeIncreaseFactor_));
398  } else {
399  // Keep nextStepSize_ constant until we have no recent step failures.
400  nextStepSize_ = currentStepSize_;
401  numStepFailures_ = std::max(numStepFailures_-1,0);
402  }
403  }
404  nextStepSize_ = std::max(nextStepSize_, minStepSize_);
405  nextStepSize_ = std::min(nextStepSize_, maxStepSize_);
406 
407  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
408  if ( Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ) {
409  RCP<Teuchos::FancyOStream> out = this->getOStream();
410  Teuchos::OSTab ostab(out,1,"completeStep_");
411  *out << "nextStepSize_ = " << nextStepSize_ << "\n";
412  *out << "numStepFailures_ = " << numStepFailures_ << "\n";
413  }
414  setStepControlState_(READY_FOR_NEXT_STEP);
415 }
416 
417 template<class Scalar>
419  Teuchos::FancyOStream &out,
420  const Teuchos::EVerbosityLevel verbLevel
421  ) const
422 {
423 
424  using Teuchos::as;
425 
426  if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
427  (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) ) {
428  out << this->description() << "::describe" << "\n";
429  }
430  if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
431  out << "requestedStepSize_ = " << requestedStepSize_ << "\n";
432  out << "currentStepSize_ = " << currentStepSize_ << "\n";
433  out << "nextStepSize_ = " << nextStepSize_ << "\n";
434  out << "stepSizeType_ = " << stepSizeType_ << "\n";
435  out << "numStepFailures_ = " << numStepFailures_ << "\n";
436  }
437 }
438 
439 template<class Scalar>
441  RCP<Teuchos::ParameterList> const& paramList)
442 {
443  using Teuchos::as;
444  // typedef Teuchos::ScalarTraits<Scalar> ST; // unused
445 
446  TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
447  paramList->validateParameters(*this->getValidParameters(),0);
448  parameterList_ = paramList;
449  Teuchos::readVerboseObjectSublist(&*parameterList_,this);
450 
451  initialStepSize_ = parameterList_->get(initialStepSizeName_,
452  initialStepSizeDefault_);
453  minStepSize_ = parameterList_->get(minStepSizeName_, minStepSizeDefault_);
454  maxStepSize_ = parameterList_->get(maxStepSizeName_, maxStepSizeDefault_);
455  TEUCHOS_TEST_FOR_EXCEPTION(
456  !(minStepSize_ <= maxStepSize_), std::logic_error,
457  "Error: (minStepSize="<<minStepSize_
458  <<") > (maxStepSize="<<maxStepSize_<<")\n");
459  TEUCHOS_TEST_FOR_EXCEPTION(
460  !((minStepSize_ <= initialStepSize_) && (initialStepSize_ <= maxStepSize_)),
461  std::logic_error,
462  "Error: Initial Step Size is not within min/max range.\n"
463  << " (minStepSize="<<minStepSize_
464  <<") > (initialStepSize="<<initialStepSize_<<") or \n"
465  << " (maxStepSize="<<maxStepSize_
466  <<") < (initialStepSize="<<initialStepSize_<<")\n");
467 
468  maxStepSizeIncreaseFactor_ =
469  parameterList_->get(maxStepSizeIncreaseFactorName_,
470  maxStepSizeIncreaseFactorDefault_);
471  TEUCHOS_TEST_FOR_EXCEPTION(
472  !(maxStepSizeIncreaseFactor_ > 0.0), std::logic_error,
473  "Error: (maxStepSizeIncreaseFactor="
474  <<maxStepSizeIncreaseFactor_<<") <= 0.0\n");
475 
476  minStepSizeDecreaseFactor_ =
477  parameterList_->get(minStepSizeDecreaseFactorName_,
478  minStepSizeDecreaseFactorDefault_);
479  TEUCHOS_TEST_FOR_EXCEPTION(
480  !(minStepSizeDecreaseFactor_ > 0.0), std::logic_error,
481  "Error: (minStepSizeDecreaseFactor="
482  <<minStepSizeDecreaseFactor_<<") <= 0.0\n");
483 
484  TEUCHOS_TEST_FOR_EXCEPTION(
485  !(minStepSizeDecreaseFactor_ < maxStepSizeIncreaseFactor_),
486  std::logic_error, "Error: "
487  "(minStepSizeDecreaseFactor="<<minStepSizeDecreaseFactor_<<") >="
488  "(maxStepSizeIncreaseFactor="<<maxStepSizeIncreaseFactor_<<")\n");
489 
490  maxStepFailures_ = parameterList_->get(maxStepFailuresName_,
491  maxStepFailuresDefault_);
492  TEUCHOS_TEST_FOR_EXCEPTION(
493  !(maxStepFailures_ >= 0), std::logic_error,
494  "Error: (maxStepFailures="<<maxStepFailures_<<") < 0\n");
495 
496  errorRelativeTolerance_ = parameterList_->get(errorRelativeToleranceName_,
497  errorRelativeToleranceDefault_);
498  TEUCHOS_TEST_FOR_EXCEPTION(
499  !(errorRelativeTolerance_ >= 0.0), std::logic_error,
500  "Error: (errorRelativeTolerance="<<errorRelativeTolerance_<<") < 0.0\n");
501 
502  errorAbsoluteTolerance_ = parameterList_->get(errorAbsoluteToleranceName_,
503  errorAbsoluteToleranceDefault_);
504  TEUCHOS_TEST_FOR_EXCEPTION(
505  !(errorAbsoluteTolerance_ >= 0.0), std::logic_error,
506  "Error: (errorAbsoluteTolerance="<<errorAbsoluteTolerance_<<") < 0.0\n");
507 
508  RCP<Teuchos::FancyOStream> out = this->getOStream();
509  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
510  Teuchos::OSTab ostab(out,1,"setParameterList");
511  out->precision(15);
512 
513  if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
514  *out << "minStepSize_ = " << minStepSize_ <<"\n";
515  *out << "maxStepSize_ = " << maxStepSize_ <<"\n";
516  *out << "maxStepSizeIncreaseFactor_ = " << maxStepSizeIncreaseFactor_<<"\n";
517  *out << "minStepSizeDecreaseFactor_ = " << minStepSizeDecreaseFactor_<<"\n";
518  *out << "maxStepFailures_ = " << maxStepFailures_ <<"\n";
519  *out << "errorRelativeTolerance_ = " << errorRelativeTolerance_ <<"\n";
520  *out << "errorAbsoluteTolerance_ = " << errorAbsoluteTolerance_ <<"\n";
521  }
522 }
523 
524 template<class Scalar>
525 RCP<const Teuchos::ParameterList>
527 {
528  static RCP<Teuchos::ParameterList> validPL;
529  if (is_null(validPL)) {
530  RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
531 
532  pl->set(initialStepSizeName_,initialStepSizeDefault_, "Initial step size.");
533  pl->set(minStepSizeName_, minStepSizeDefault_, "Minimum step size.");
534  pl->set(maxStepSizeName_, maxStepSizeDefault_, "Maximum step size.");
535  pl->set(maxStepSizeIncreaseFactorName_, maxStepSizeIncreaseFactorDefault_,
536  "The maximum factor to increase the step size after a successful step.");
537  pl->set(minStepSizeDecreaseFactorName_, minStepSizeDecreaseFactorDefault_,
538  "The minimum allowable factor to decrease the step size. If the "
539  "stepSizeFactor_ is below this, the current step is considered a "
540  "failure and retried with `" + minStepSizeDecreaseFactorName_ +
541  "' applied.");
542  pl->set(maxStepFailuresName_, maxStepFailuresDefault_,
543  "The maximum number of step failures before exiting with an error. "
544  "The number of failure steps are carried between successful steps.");
545  pl->set(errorRelativeToleranceName_, errorRelativeToleranceDefault_,
546  "The allowable relative change in the error (the difference between "
547  "the solution at the end of the step and the predicted solution) for "
548  "each step to pass. The stepper solution status is also used to "
549  "determine pass/fail.");
550  pl->set(errorAbsoluteToleranceName_, errorAbsoluteToleranceDefault_,
551  "The allowable absolute change in the error (the difference between "
552  "the solution at the end of the step and the predicted solution) for "
553  "each step to pass. The stepper solution status is also used to "
554  "determine pass/fail.");
555 
556  Teuchos::setupVerboseObjectSublist(&*pl);
557  validPL = pl;
558  }
559  return (validPL);
560 }
561 
562 template<class Scalar>
563 RCP<Teuchos::ParameterList>
565 {
566  RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
567  parameterList_ = Teuchos::null;
568  return(temp_param_list);
569 }
570 
571 template<class Scalar>
572 RCP<Teuchos::ParameterList>
574 {
575  return(parameterList_);
576 }
577 
578 template<class Scalar>
580  const StepperBase<Scalar>& stepper)
581 {
582  if (stepControlState_ == UNINITIALIZED) initialize(stepper);
583 }
584 
585 template<class Scalar>
587 {
588  return true;
589 }
590 
591 
592 template<class Scalar>
593 RCP<StepControlStrategyBase<Scalar> >
595 {
596  RCP<FirstOrderErrorStepControlStrategy<Scalar> >
597  stepControl = rcp(new FirstOrderErrorStepControlStrategy<Scalar>());
598 
599  if (!is_null(parameterList_)) {
600  stepControl->setParameterList(parameterList_);
601  }
602 
603  return stepControl;
604 }
605 
606 template<class Scalar>
608 {
609  TEUCHOS_TEST_FOR_EXCEPTION(
610  stepControlState_ == UNINITIALIZED, std::logic_error,
611  "Error, attempting to call getMaxOrder before initialization!\n"
612  );
613  return(maxOrder_);
614 }
615 
616 //
617 // Explicit Instantiation macro
618 //
619 // Must be expanded from within the Rythmos namespace!
620 //
621 
622 #define RYTHMOS_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_INSTANT(SCALAR) \
623  template class FirstOrderErrorStepControlStrategy< SCALAR >;
624 
625 
626 } // namespace Rythmos
627 #endif // Rythmos_FIRSTORDERERROR_STEP_CONTROL_STRATEGY_DEF_H
Base class for defining stepper functionality.
void setParameterList(RCP< Teuchos::ParameterList > const &paramList)
void nextStepSize(const StepperBase< Scalar > &stepper, Scalar *stepSize, StepSizeType *stepSizeType, int *order)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setCorrection(const StepperBase< Scalar > &stepper, const RCP< const Thyra::VectorBase< Scalar > > &soln, const RCP< const Thyra::VectorBase< Scalar > > &ee, int solveStatus)
virtual RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const =0
Return the space for x and x_dot.
Step Control Strategy for first-order time integration.
AttemptedStepStatusFlag rejectStep(const StepperBase< Scalar > &stepper)
bool acceptStep(const StepperBase< Scalar > &stepper, Scalar *LETValue)
RCP< StepControlStrategyBase< Scalar > > cloneStepControlStrategyAlgorithm() const
void setRequestedStepSize(const StepperBase< Scalar > &stepper, const Scalar &stepSize, const StepSizeType &stepSizeType)