Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_ImplicitBDFStepperRampingStepControl_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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef Rythmos_IMPLICITBDF_STEPPER_RAMPING_STEP_CONTROL_DEF_H
30 #define Rythmos_IMPLICITBDF_STEPPER_RAMPING_STEP_CONTROL_DEF_H
31 
32 #include "Rythmos_ImplicitBDFStepper.hpp"
33 #include "Rythmos_ImplicitBDFStepperErrWtVecCalc.hpp"
34 #include "Teuchos_StandardParameterEntryValidators.hpp"
35 
36 namespace Rythmos {
37 
38 template<class Scalar>
39 ImplicitBDFStepperRampingStepControl<Scalar>::
40 ImplicitBDFStepperRampingStepControl() :
41  stepControlState_(UNINITIALIZED)
42 {
43 
44 }
45 
46 template<class Scalar>
47 void ImplicitBDFStepperRampingStepControl<Scalar>::setStepControlState_(StepControlStrategyState newState)
48 {
49  if (stepControlState_ == UNINITIALIZED) {
50  TEUCHOS_TEST_FOR_EXCEPT(newState != BEFORE_FIRST_STEP);
51  } else if (stepControlState_ == BEFORE_FIRST_STEP) {
52  TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
53  } else if (stepControlState_ == MID_STEP) {
54  TEUCHOS_TEST_FOR_EXCEPT(newState != AFTER_CORRECTION);
55  } else if (stepControlState_ == AFTER_CORRECTION) {
56  TEUCHOS_TEST_FOR_EXCEPT(newState != READY_FOR_NEXT_STEP);
57  } else if (stepControlState_ == READY_FOR_NEXT_STEP) {
58  TEUCHOS_TEST_FOR_EXCEPT(newState != MID_STEP);
59  }
60  stepControlState_ = newState;
61 }
62 
63 template<class Scalar>
65 {
66  return(stepControlState_);
67 }
68 
69 template<class Scalar>
71 {
72  TEUCHOS_TEST_FOR_EXCEPT(!((stepControlState_ == BEFORE_FIRST_STEP) || (stepControlState_ == READY_FOR_NEXT_STEP)));
73 
74  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "updateCoeffs_() is not implemented!");
75 }
76 
77 template<class Scalar>
79 {
80  // Initialize can be called from the stepper when setInitialCondition is called.
81  using Teuchos::as;
82  typedef Teuchos::ScalarTraits<Scalar> ST;
83  using Thyra::createMember;
84 
85  // Set initial time:
86  TimeRange<Scalar> stepperRange = stepper.getTimeRange();
87  TEUCHOS_TEST_FOR_EXCEPTION(
88  !stepperRange.isValid(),
89  std::logic_error,
90  "Error, Stepper does not have valid time range for initialization of ImplicitBDFStepperRampingStepControl!\n"
91  );
92 
93  if (is_null(parameterList_)) {
94  RCP<Teuchos::ParameterList> emptyParameterList = Teuchos::rcp(new Teuchos::ParameterList);
95  this->setParameterList(emptyParameterList);
96  }
97 
98  if (is_null(errWtVecCalc_)) {
99  RCP<ImplicitBDFStepperErrWtVecCalc<Scalar> > IBDFErrWtVecCalc = rcp(new ImplicitBDFStepperErrWtVecCalc<Scalar>());
100  errWtVecCalc_ = IBDFErrWtVecCalc;
101  }
102 
103  stepControlState_ = UNINITIALIZED;
104 
105  requestedStepSize_ = Scalar(-1.0);
106  currentStepSize_ = initialStepSize_;
107  currentOrder_ = 1;
108  nextStepSize_ = initialStepSize_;
109  nextOrder_ = 1;
110  numberOfSteps_ = 0;
111  totalNumberOfFailedSteps_ = 0;
112  countOfConstantStepsAfterFailure_ = 0;
113 
114  if (is_null(delta_)) {
115  delta_ = createMember(stepper.get_x_space());
116  }
117  if (is_null(errWtVec_)) {
118  errWtVec_ = createMember(stepper.get_x_space());
119  }
120  V_S(delta_.ptr(),ST::zero());
121 
122  if ( doOutput_(Teuchos::VERB_HIGH) ) {
123  RCP<Teuchos::FancyOStream> out = this->getOStream();
124  Teuchos::OSTab ostab(out,1,"initialize");
125  *out << "currentOrder_ = " << currentOrder_ << std::endl;
126  *out << "numberOfSteps_ = " << numberOfSteps_ << std::endl;
127  }
128 
129  setStepControlState_(BEFORE_FIRST_STEP);
130 
131 }
132 
133 template<class Scalar>
135  const StepperBase<Scalar>& stepper
136  ,const Scalar& stepSize
137  ,const StepSizeType& stepSizeType
138  )
139 {
140  typedef Teuchos::ScalarTraits<Scalar> ST;
141 
142  TEUCHOS_TEST_FOR_EXCEPT(!((stepControlState_ == UNINITIALIZED) ||
143  (stepControlState_ == BEFORE_FIRST_STEP) ||
144  (stepControlState_ == READY_FOR_NEXT_STEP) ||
145  (stepControlState_ == MID_STEP)));
146 
147  TEUCHOS_TEST_FOR_EXCEPTION(
148  ((stepSizeType == STEP_TYPE_FIXED) && (stepSize == ST::zero())),
149  std::logic_error,
150  "Error, step size type == STEP_TYPE_FIXED, but requested step size == 0!\n"
151  );
152 
153  bool didInitialization = false;
154  if (stepControlState_ == UNINITIALIZED) {
155  initialize(stepper);
156  didInitialization = true;
157  }
158 
159  // errWtVecSet_ is called during initialize
160  if (!didInitialization) {
161  const ImplicitBDFStepper<Scalar>& implicitBDFStepper = Teuchos::dyn_cast<const ImplicitBDFStepper<Scalar> >(stepper);
162  const Thyra::VectorBase<Scalar>& xHistory = implicitBDFStepper.getxHistory(0);
163  errWtVecCalc_->errWtVecSet(&*errWtVec_,xHistory,relErrTol_,absErrTol_);
164  }
165 
166  requestedStepSize_ = stepSize;
167  stepSizeType_ = stepSizeType;
168 }
169 
170 template<class Scalar>
171 void ImplicitBDFStepperRampingStepControl<Scalar>::nextStepSize(const StepperBase<Scalar>& stepper, Scalar* stepSize, StepSizeType* stepSizeType, int* order)
172 {
173  TEUCHOS_TEST_FOR_EXCEPT(!((stepControlState_ == BEFORE_FIRST_STEP) ||
174  (stepControlState_ == MID_STEP) ||
175  (stepControlState_ == READY_FOR_NEXT_STEP) )
176  );
177 
178  if (stepControlState_ == BEFORE_FIRST_STEP) {
179  nextStepSize_ = initialStepSize_;
180  nextOrder_ = 1;
181  }
182 
183  // Now starting a step - rotate next values into current values
184  if (stepSizeType_ == STEP_TYPE_FIXED)
185  currentStepSize_ = requestedStepSize_;
186  else
187  currentStepSize_ = nextStepSize_;
188 
189  currentOrder_ = nextOrder_;
190 
191  // Limit the step size to the requested step size
192  currentStepSize_ = std::min(requestedStepSize_, currentStepSize_);
193 
194  *stepSize = currentStepSize_;
195  *stepSizeType = stepSizeType_;
196  *order = currentOrder_;
197 
198  if (stepControlState_ != MID_STEP) {
199  setStepControlState_(MID_STEP);
200  }
201 
202  // Output
203  if (doOutput_(Teuchos::VERB_MEDIUM)){
204  Teuchos::FancyOStream& out = *this->getOStream();
205  Teuchos::OSTab ostab1(out,2,"** nextStepSize_ **");
206  out << "Values returned to stepper:" << std::endl;
207  Teuchos::OSTab ostab2(out,2,"** nextStepSize_ **");
208  out << "currentStepSize_ = " << currentStepSize_ << std::endl;
209  out << "currentOrder_ = " << currentOrder_ << std::endl;
210  out << "requestedStepSize_ = " << requestedStepSize_ << std::endl;
211  }
212 
213 }
214 
215 template<class Scalar>
217  const StepperBase<Scalar>& stepper
218  ,const RCP<const Thyra::VectorBase<Scalar> >& soln
219  ,const RCP<const Thyra::VectorBase<Scalar> >& ee
220  ,int solveStatus)
221 {
222  TEUCHOS_TEST_FOR_EXCEPT(stepControlState_ != MID_STEP);
223 
224  TEUCHOS_TEST_FOR_EXCEPTION(is_null(ee), std::logic_error, "Error, ee == Teuchos::null!\n");
225 
226  ee_ = ee;
227 
228  newtonConvergenceStatus_ = solveStatus;
229 
230  if ( doOutput_(Teuchos::VERB_MEDIUM) && newtonConvergenceStatus_ < 0) {
231  RCP<Teuchos::FancyOStream> out = this->getOStream();
232  Teuchos::OSTab ostab(out,1,"setCorrection");
233  *out << "\nImplicitBDFStepperRampingStepControl::setCorrection(): Nonlinear Solver Failed!\n";
234  }
235 
236  setStepControlState_(AFTER_CORRECTION);
237 }
238 
239 template<class Scalar>
241 {
242  using Teuchos::as;
243  typedef Teuchos::ScalarTraits<Scalar> ST;
244 
245  TEUCHOS_TEST_FOR_EXCEPT(stepControlState_ != AFTER_CORRECTION);
246 
247 
248  if ( doOutput_(Teuchos::VERB_HIGH) ) {
249  RCP<Teuchos::FancyOStream> out = this->getOStream();
250  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
251  Teuchos::OSTab ostab(out,1,"acceptStep");
252  *out << "ee_ = " << std::endl;
253  ee_->describe(*out,verbLevel);
254  *out << "errWtVec_ = " << std::endl;
255  errWtVec_->describe(*out,verbLevel);
256  }
257 
258  Scalar enorm = wRMSNorm_(*errWtVec_,*ee_);
259 
260  Scalar LET = ck_ * enorm;
261 
262  if (LETValue) {
263  *LETValue = LET;
264  *LETValue = Scalar(0.0);
265  }
266 
267  if (newtonConvergenceStatus_ < 0)
268  return false;
269 
270  bool return_status = false;
271 
272  if (LET < ST::one() || !useLETToDetermineConvergence_)
273  return_status = true;
274 
275  if ( doOutput_(Teuchos::VERB_HIGH) ) {
276  RCP<Teuchos::FancyOStream> out = this->getOStream();
277  Teuchos::OSTab ostab(out,1,"acceptStep");
278  *out << "return_status = " << return_status << std::endl;
279  *out << "Local Truncation Error Check: (ck*enorm) < 1: (" << LET << ") <?= 1" << std::endl;
280  if ( doOutput_(Teuchos::VERB_EXTREME) ) {
281  *out << "ck_ = " << ck_ << std::endl;
282  *out << "enorm = " << enorm << std::endl;
283  }
284  }
285 
286  return(return_status);
287 }
288 
289 template<class Scalar>
291 {
292  TEUCHOS_TEST_FOR_EXCEPT(stepControlState_ != AFTER_CORRECTION);
293  using Teuchos::as;
294  typedef Teuchos::ScalarTraits<Scalar> ST;
295 
296  if ( doOutput_(Teuchos::VERB_HIGH) ) {
297  RCP<Teuchos::FancyOStream> out = this->getOStream();
298 
299  Teuchos::OSTab ostab1(out,2,"completeStep_");
300  *out << "\n** Begin completeStep() **" << std::endl;
301  Teuchos::OSTab ostab2(out,2,"** Begin completeStep_ **");
302  *out << "numberOfSteps_ = " << numberOfSteps_ << std::endl;
303  *out << "numConstantSteps_ = " << numConstantSteps_ << std::endl;
304  *out << "currentStepSize_ = " << currentStepSize_ << std::endl;
305  *out << "nextStepSize_ = " << nextStepSize_ << std::endl;
306  *out << "currentOrder_ = " << currentOrder_ << std::endl;
307  *out << "nextOrder_ = " << nextOrder_ << std::endl;
308  *out << "stepSizeIncreaseFactor_ = " << stepSizeIncreaseFactor_ << std::endl;
309  *out << "countOfConstantStepsAfterFailure_ = " << countOfConstantStepsAfterFailure_ << std::endl;
310  }
311 
312  numberOfSteps_ ++;
313 
314  if (countOfConstantStepsAfterFailure_ > 0) {
315  // We track the number of consecutive time step failures so that
316  // if we have a bunch of nonlinear failures, lets keep the time
317  // step constant for a while before we start to ramp again. This
318  // keeps us from oscillating between ramping and cutting step
319  // sizes and wasting resources.
320 
321  nextStepSize_ = currentStepSize_;
322  nextOrder_ = currentOrder_;
323 
324  // Decrement failure counter
325  countOfConstantStepsAfterFailure_ =
326  std::max( (countOfConstantStepsAfterFailure_ - 1), 0);
327 
328  if ( doOutput_(Teuchos::VERB_HIGH) ) {
329  RCP<Teuchos::FancyOStream> out = this->getOStream();
330  Teuchos::OSTab ostab(out,1,"completeStep_");
331  *out << "\nNext Step Size held constant due to previous failed steps!\n";
332  *out << "countOfConstantStepsAfterFailure_ = " << countOfConstantStepsAfterFailure_ << std::endl;
333  }
334 
335  }
336  else {
337 
338  // Phase 1: Constant step size at 1st order
339  if (numberOfSteps_ < numConstantSteps_) {
340  if (currentStepSize_ < initialStepSize_)
341  nextStepSize_ = std::min(initialStepSize_, currentStepSize_ * stepSizeIncreaseFactor_);
342 
343  nextOrder_ = 1;
344  }
345  // Phase 2: Constant step size, ramping the order
346  else if (currentOrder_ < maxOrder_) {
347  if (currentStepSize_ < initialStepSize_)
348  nextStepSize_ = std::min(initialStepSize_, currentStepSize_ * stepSizeIncreaseFactor_);
349  else
350  nextStepSize_ = currentStepSize_;
351 
352  nextOrder_ = currentOrder_ + 1;
353  }
354  // Phase 3: Ramping dt to max step size, highest order
355  else if ((numberOfSteps_ >= numConstantSteps_) && (currentOrder_ == maxOrder_)) {
356  nextStepSize_ = std::min(maxStepSize_, currentStepSize_ * stepSizeIncreaseFactor_);
357  nextOrder_ = maxOrder_;
358  }
359  else {
360  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
361  "RampingStepControlStrategy logic is broken. Please contact evelopers. Aborting run!");
362  }
363 
364  } // if (countOfConstantStepsAfterFailure_ > 0)
365 
366  setStepControlState_(READY_FOR_NEXT_STEP);
367 
368  if ( doOutput_(Teuchos::VERB_HIGH) ) {
369  RCP<Teuchos::FancyOStream> out = this->getOStream();
370  Teuchos::OSTab ostab1(out,2,"** completeStep_ **");
371  *out << "** End of completeStep() **" << std::endl;
372  Teuchos::OSTab ostab2(out,2,"** End completeStep_ **");
373  *out << "numberOfSteps_ = " << numberOfSteps_ << std::endl;
374  *out << "numConstantSteps_ = " << numConstantSteps_ << std::endl;
375  *out << "currentStepSize_ = " << currentStepSize_ << std::endl;
376  *out << "nextStepSize_ = " << nextStepSize_ << std::endl;
377  *out << "currentOrder_ = " << currentOrder_ << std::endl;
378  *out << "nextOrder_ = " << nextOrder_ << std::endl;
379  *out << "stepSizeIncreaseFactor_ = " << stepSizeIncreaseFactor_ << std::endl;
380  *out << "countOfConstantStepsAfterFailure_ = " << countOfConstantStepsAfterFailure_ << std::endl;
381  }
382 }
383 
384 template<class Scalar>
386 {
387  TEUCHOS_TEST_FOR_EXCEPT(stepControlState_ != AFTER_CORRECTION);
388 
389  using Teuchos::as;
390 
391  ++totalNumberOfFailedSteps_;
392  ++countOfConstantStepsAfterFailure_;
393 
394  // If time step size is already at the min time step, then quit
395  if (currentStepSize_ <= minStepSize_)
396  return (REP_ERR_FAIL);
397 
398  // Otherwise, cut the time step and keep order the same
399  nextStepSize_ = std::max(minStepSize_, (currentStepSize_ * stepSizeDecreaseFactor_) );
400 
401  setStepControlState_(READY_FOR_NEXT_STEP);
402 
403  return(PREDICT_AGAIN);
404 }
405 
406 template<class Scalar>
408  Teuchos::FancyOStream &out,
409  const Teuchos::EVerbosityLevel verbLevel
410  ) const
411 {
412 
413  using Teuchos::as;
414 
415  if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
416  (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) )
417  ) {
418  out << this->description() << "::describe" << std::endl;
419  }
420  else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW)) {
421  out << "currentStepSize_ = " << currentStepSize_ << std::endl;
422  out << "currentOrder_ = " << currentOrder_ << std::endl;
423  }
424  else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_MEDIUM)) {
425  }
426  else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH)) {
427  out << "ee_ = ";
428  if (ee_ == Teuchos::null) {
429  out << "Teuchos::null" << std::endl;
430  } else {
431  ee_->describe(out,verbLevel);
432  }
433  out << "delta_ = ";
434  if (delta_ == Teuchos::null) {
435  out << "Teuchos::null" << std::endl;
436  } else {
437  delta_->describe(out,verbLevel);
438  }
439  out << "errWtVec_ = ";
440  if (errWtVec_ == Teuchos::null) {
441  out << "Teuchos::null" << std::endl;
442  } else {
443  errWtVec_->describe(out,verbLevel);
444  }
445  }
446 }
447 
448 template<class Scalar>
450  RCP<Teuchos::ParameterList> const& paramList
451  )
452 {
453 
454  using Teuchos::as;
455  typedef Teuchos::ScalarTraits<Scalar> ST;
456 
457  TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
458 
459  parameterList_ = Teuchos::parameterList(*paramList);
460 
461  parameterList_->validateParametersAndSetDefaults(*this->getValidParameters());
462 
463  Teuchos::ParameterList& p = *parameterList_;
464 
465  numConstantSteps_ = p.get<int>("Number of Constant First Order Steps");
466  initialStepSize_ = p.get<Scalar>("Initial Step Size");
467  minStepSize_ = p.get<Scalar>("Min Step Size");
468  maxStepSize_ = p.get<Scalar>("Max Step Size");
469  stepSizeIncreaseFactor_ = p.get<Scalar>("Step Size Increase Factor");
470  stepSizeDecreaseFactor_ = p.get<Scalar>("Step Size Decrease Factor");
471 
472  minOrder_ = p.get<int>("Min Order");
473  TEUCHOS_TEST_FOR_EXCEPTION(
474  !((1 <= minOrder_) && (minOrder_ <= 5)), std::logic_error,
475  "Error, minOrder_ = " << minOrder_ << " is not in range [1,5]!\n"
476  );
477  maxOrder_ = p.get<int>("Max Order");
478  TEUCHOS_TEST_FOR_EXCEPTION(
479  !((1 <= maxOrder_) && (maxOrder_ <= 5)), std::logic_error,
480  "Error, maxOrder_ = " << maxOrder_ << " is not in range [1,5]!\n"
481  );
482 
483  absErrTol_ = p.get<Scalar>("Absolute Error Tolerance");
484  relErrTol_ = p.get<Scalar>("Relative Error Tolerance");
485 
486  {
487  std::string let_acceptance =
488  p.get<std::string>("Use LET To Determine Step Acceptance");
489  useLETToDetermineConvergence_ = (let_acceptance == "TRUE");
490 
491  // Currently the using LET for step acceptance is not supported
492  // since we can't calculate the LETValue. Once this is
493  // implemented, delete the line below.
494  TEUCHOS_TEST_FOR_EXCEPTION(useLETToDetermineConvergence_, std::logic_error,
495  "Error - the flag \"Use LET To Determine Step Acceptance\" is set to \"TRUE\" but the local error computation is currently not supported. Please set this flag to \"FALSE\" for now.");
496  }
497 
498  if ( doOutput_(Teuchos::VERB_HIGH) ) {
499  RCP<Teuchos::FancyOStream> out = this->getOStream();
500  Teuchos::OSTab ostab(out,1,"setParameterList");
501  out->precision(15);
502  *out << "minOrder_ = " << minOrder_ << std::endl;
503  *out << "maxOrder_ = " << maxOrder_ << std::endl;
504  *out << "relErrTol_ = " << relErrTol_ << std::endl;
505  *out << "absErrTol_ = " << absErrTol_ << std::endl;
506  *out << "stepSizeType = " << stepSizeType_ << std::endl;
507  *out << "stopTime_ = " << stopTime_ << std::endl;
508  }
509 
510 }
511 
512 template<class Scalar>
513 RCP<const Teuchos::ParameterList>
515 {
516  using Teuchos::RCP;
517  using Teuchos::rcp;
518  using Teuchos::ParameterList;
519 
520  static RCP<ParameterList> p;
521 
522  if (is_null(p)) {
523 
524  p = rcp(new ParameterList);
525 
526  p->set<int>("Number of Constant First Order Steps", 10, "Number of constant steps to take before handing control to variable stepper.");
527 
528  p->set<Scalar>("Initial Step Size", Scalar(1.0e-3),
529  "Initial time step size and target step size to take during the initial constant step phase (could be reduced due to step failures).");
530 
531  p->set<Scalar>("Min Step Size", Scalar(1.0e-7), "Minimum time step size.");
532 
533  p->set<Scalar>("Max Step Size", Scalar(1.0), "Maximum time step size.");
534 
535  p->set<Scalar>("Step Size Increase Factor", Scalar(1.2), "Time step growth factor used after a successful time step. dt_{n+1} = (increase factor) * dt_n");
536 
537  p->set<Scalar>("Step Size Decrease Factor", Scalar(0.5), "Time step reduction factor used for a failed time step. dt_{n+1} = (decrease factor) * dt_n");
538 
539  p->set<int>("Min Order", 1, "Minimum order to run at.");
540  p->set<int>("Max Order", 5, "Maximum order to run at.");
541 
542  p->set<Scalar>("Absolute Error Tolerance", Scalar(1.0e-5), "abstol value used in WRMS calculation.");
543  p->set<Scalar>("Relative Error Tolerance", Scalar(1.0e-3), "reltol value used in WRMS calculation.");
544 
545  Teuchos::setStringToIntegralParameter<int>(
546  "Use LET To Determine Step Acceptance",
547  "FALSE",
548  "If set to TRUE, then acceptance of step dependes on LET in addition to Nonlinear solver converging.",
549  Teuchos::tuple<std::string>("TRUE","FALSE"),
550  p.get()
551  );
552 
553  }
554 
555  return (p);
556 
557 }
558 
559 template<class Scalar>
560 RCP<Teuchos::ParameterList>
562 {
563  RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
564  parameterList_ = Teuchos::null;
565  return(temp_param_list);
566 }
567 
568 template<class Scalar>
569 RCP<Teuchos::ParameterList>
571 {
572  return(parameterList_);
573 }
574 
575 template<class Scalar>
577 {
578  if (stepControlState_ == UNINITIALIZED) {
579  initialize(stepper);
580  }
581  const ImplicitBDFStepper<Scalar>& bdfstepper = Teuchos::dyn_cast<const ImplicitBDFStepper<Scalar> >(stepper);
582  int desiredOrder = bdfstepper.getOrder();
583  TEUCHOS_TEST_FOR_EXCEPT(!((1 <= desiredOrder) && (desiredOrder <= maxOrder_)));
584  if (stepControlState_ == BEFORE_FIRST_STEP) {
585  TEUCHOS_TEST_FOR_EXCEPTION(
586  desiredOrder > 1,
587  std::logic_error,
588  "Error, this ImplicitBDF stepper has not taken a step yet, so it cannot take a step of order " << desiredOrder << " > 1!\n"
589  );
590  }
591  TEUCHOS_TEST_FOR_EXCEPT(!(desiredOrder <= currentOrder_+1));
592  currentOrder_ = desiredOrder;
593 
594  if ( doOutput_(Teuchos::VERB_EXTREME) ) {
595  RCP<Teuchos::FancyOStream> out = this->getOStream();
596  Teuchos::OSTab ostab(out,1,"setStepControlData");
597  *out << "currentOrder_ = " << currentOrder_ << std::endl;
598  }
599 }
600 
601 template<class Scalar>
603 {
604  return true;
605 }
606 
607 
608 template<class Scalar>
609 RCP<StepControlStrategyBase<Scalar> >
611 {
612 
613  RCP<ImplicitBDFStepperRampingStepControl<Scalar> > stepControl = rcp(new ImplicitBDFStepperRampingStepControl<Scalar>());
614 
615  if (!is_null(parameterList_)) {
616  stepControl->setParameterList(parameterList_);
617  }
618 
619  return stepControl;
620 }
621 
622 template<class Scalar>
623 void ImplicitBDFStepperRampingStepControl<Scalar>::setErrWtVecCalc(const RCP<ErrWtVecCalcBase<Scalar> >& errWtVecCalc)
624 {
625  TEUCHOS_TEST_FOR_EXCEPT(is_null(errWtVecCalc));
626  errWtVecCalc_ = errWtVecCalc;
627 }
628 
629 template<class Scalar>
630 RCP<const ErrWtVecCalcBase<Scalar> > ImplicitBDFStepperRampingStepControl<Scalar>::getErrWtVecCalc() const
631 {
632  return(errWtVecCalc_);
633 }
634 
635 template<class Scalar>
637  const Thyra::VectorBase<Scalar>& weight,
638  const Thyra::VectorBase<Scalar>& vector) const
639 {
640  return(norm_2(weight,vector));
641 }
642 
643 template<class Scalar>
645 {
646  TEUCHOS_TEST_FOR_EXCEPTION(
647  stepControlState_ == UNINITIALIZED, std::logic_error,
648  "Error, attempting to call getMinOrder before intiialization!\n"
649  );
650  return(minOrder_);
651 }
652 
653 template<class Scalar>
655 {
656  TEUCHOS_TEST_FOR_EXCEPTION(
657  stepControlState_ == UNINITIALIZED, std::logic_error,
658  "Error, attempting to call getMaxOrder before initialization!\n"
659  );
660  return(maxOrder_);
661 }
662 
663 template<class Scalar>
664 bool ImplicitBDFStepperRampingStepControl<Scalar>::doOutput_(Teuchos::EVerbosityLevel verbLevel)
665 {
666  Teuchos::EVerbosityLevel currentObjectVerbLevel = this->getVerbLevel();
667 
668  if ( Teuchos::as<int>(currentObjectVerbLevel) >= Teuchos::as<int>(verbLevel) )
669  return true;
670 
671  return false;
672 }
673 
674 template<class Scalar>
675 int ImplicitBDFStepperRampingStepControl<Scalar>::numberOfSteps() const
676 {
677  return numberOfSteps_;
678 }
679 
680 template<class Scalar>
681 int ImplicitBDFStepperRampingStepControl<Scalar>::numberOfFailedSteps() const
682 {
683  return totalNumberOfFailedSteps_;
684 }
685 
686 template<class Scalar>
687 Scalar ImplicitBDFStepperRampingStepControl<Scalar>::currentStepSize() const
688 {
689  return currentStepSize_;
690 }
691 
692 template<class Scalar>
693 int ImplicitBDFStepperRampingStepControl<Scalar>::currentOrder() const
694 {
695  return currentOrder_;
696 }
697 
698 
699 //
700 // Explicit Instantiation macro
701 //
702 // Must be expanded from within the Rythmos namespace!
703 //
704 
705 #define RYTHMOS_IMPLICITBDF_STEPPER_RAMPING_STEPCONTROL_INSTANT(SCALAR) \
706  template class ImplicitBDFStepperRampingStepControl< SCALAR >;
707 
708 
709 } // namespace Rythmos
710 #endif // Rythmos_IMPLICITBDF_STEPPER_RAMPING_STEP_CONTROL_DEF_H
711 
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Base class for defining stepper functionality.
void setParameterList(RCP< Teuchos::ParameterList > const &paramList)
bool acceptStep(const StepperBase< Scalar > &stepper, Scalar *LETValue)
void setRequestedStepSize(const StepperBase< Scalar > &stepper, const Scalar &stepSize, const StepSizeType &stepSizeType)
virtual RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const =0
Return the space for x and x_dot.
virtual TimeRange< Scalar > getTimeRange() const =0
Return the range of time values where interpolation calls can be performed.
void setErrWtVecCalc(const RCP< ErrWtVecCalcBase< Scalar > > &errWtVecCalc)
void setCorrection(const StepperBase< Scalar > &stepper, const RCP< const Thyra::VectorBase< Scalar > > &soln, const RCP< const Thyra::VectorBase< Scalar > > &ee, int solveStatus)
RCP< StepControlStrategyBase< Scalar > > cloneStepControlStrategyAlgorithm() const
void nextStepSize(const StepperBase< Scalar > &stepper, Scalar *stepSize, StepSizeType *stepSizeType, int *order)
const Thyra::VectorBase< Scalar > & getxHistory(int index) const
AttemptedStepStatusFlag rejectStep(const StepperBase< Scalar > &stepper)