Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_ImplicitBDFStepperStepControl_decl.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_IMPLICITBDF_STEPPER_STEP_CONTROL_DECL_H
30 #define Rythmos_IMPLICITBDF_STEPPER_STEP_CONTROL_DECL_H
31 
32 #include "Rythmos_ErrWtVecCalcAcceptingStepControlStrategyBase.hpp"
33 
34 namespace Rythmos {
35 
37 enum BDFactionFlag { ACTION_UNSET, ACTION_LOWER, ACTION_MAINTAIN, ACTION_RAISE };
38 
39 // Step Control Strategy object for ImplicitBDFStpper
40 //
41 // Order of calls:
42 // setRequestedStepSize()
43 // nextStepSize()
44 // optional: nextStepOrder()
45 // setCorrection
46 // acceptStep
47 // completeStep or rejectStep
48 // repeat
49 //
50 // 08/16/07 tscoffe: This order of operations must be enforced through
51 // preconditions or I need to re-think how to set up the interface for this
52 // strategy object.
53 //
54 template<class Scalar>
55 class ImplicitBDFStepperStepControl
56  : virtual public ErrWtVecCalcAcceptingStepControlStrategyBase<Scalar>
57 {
58  public:
59 
60  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
61 
65  void setRequestedStepSize(const StepperBase<Scalar>& stepper,
66  const Scalar& stepSize, const StepSizeType& stepSizeType);
67 
69  void nextStepSize(const StepperBase<Scalar>& stepper, Scalar* stepSize,
70  StepSizeType* stepSizeType, int* order);
71 
73  void setCorrection(
74  const StepperBase<Scalar>& stepper
75  ,const RCP<const Thyra::VectorBase<Scalar> >& soln
76  ,const RCP<const Thyra::VectorBase<Scalar> >& ee
77  ,int solveStatus
78  );
79 
81  bool acceptStep(const StepperBase<Scalar>& stepper, Scalar* LETValue);
82 
84  void completeStep(const StepperBase<Scalar>& stepper);
85 
87  AttemptedStepStatusFlag rejectStep(const StepperBase<Scalar>& stepper);
88 
90  StepControlStrategyState getCurrentState();
91 
93  int getMinOrder() const;
94 
96  int getMaxOrder() const;
97 
99  void setStepControlData(const StepperBase<Scalar>& stepper);
100 
102  bool supportsCloning() const;
103 
105  RCP<StepControlStrategyBase<Scalar> > cloneStepControlStrategyAlgorithm() const;
106 
108 
111 
113  void setErrWtVecCalc(const RCP<ErrWtVecCalcBase<Scalar> >& errWtVecCalc);
114 
116  RCP<const ErrWtVecCalcBase<Scalar> > getErrWtVecCalc() const;
117 
119 
120  ImplicitBDFStepperStepControl();
121 
125  void describe(
126  Teuchos::FancyOStream &out,
127  const Teuchos::EVerbosityLevel verbLevel
128  ) const;
130 
134  void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
135 
137  RCP<Teuchos::ParameterList> getNonconstParameterList();
138 
140  RCP<Teuchos::ParameterList> unsetParameterList();
141 
143  RCP<const Teuchos::ParameterList> getValidParameters() const;
144 
146 
148  void initialize(const StepperBase<Scalar>& stepper);
149 
150 
151  private:
152 
153  // Private data members
154 
155  void defaultInitializeAllData_();
156 
157  StepControlStrategyState stepControlState_;
158 
159  RCP<ErrWtVecCalcBase<Scalar> > errWtVecCalc_;
160 
161  Scalar hh_;
162  int numberOfSteps_;
163  StepSizeType stepSizeType_;
164  int minOrder_;
165  int maxOrder_;
166  int nef_;
167  bool midStep_; // true after setStepSize and nextStepSize and nextStepOrder and setCorrection and acceptStep
168  // false after rejectStep and completeStep
169  RCP<const Thyra::VectorBase<Scalar> > ee_; // Newton update
170  RCP<Thyra::VectorBase<Scalar> > errWtVec_; // error weight vector
171  RCP<Thyra::VectorBase<Scalar> > delta_;
172 
173  bool checkReduceOrderCalled_;
174 
175  RCP<Teuchos::ParameterList> parameterList_;
176 
177  Scalar time_;
178 
179  ScalarMag relErrTol_; // relative error tolerance
180  ScalarMag absErrTol_; // absolute error tolerance
181  Scalar usedStep_;
182  int currentOrder_; // Current order of integration
183  int usedOrder_; // order used in current step (used after currentOrder is updated)
184  int nscsco_;
185  Array<Scalar> alpha_; // $\alpha_j(n)=h_n/\psi_j(n)$ coefficient used in local error test
186  // note: $h_n$ = current step size, n = current time step
187  Array<Scalar> sigma_; // $\sigma_j(n) = \frac{h_n^j(j-1)!}{\psi_1(n)*\cdots *\psi_j(n)}$
188  Array<Scalar> gamma_; // $\gamma_j(n)=\sum_{l=1}^{j-1}1/\psi_l(n)$ coefficient used to
189  // calculate time derivative of history array for predictor
190  Array<Scalar> beta_; // coefficients used to evaluate predictor from history array
191  Array<Scalar> psi_; // $\psi_j(n) = t_n-t_{n-j}$ intermediary variable used to
192  // compute $\beta_j(n)$
193  Scalar alpha_s_; // $\alpha_s$ fixed-leading coefficient of this BDF method
194  Scalar alpha_0_; // $-\sum_{j=1}^k \alpha_j(n)$ coefficient used in local error test
195  Scalar cj_ ; // $-\alpha_s/h_n$ coefficient used in local error test
196  Scalar ck_ ; // local error coefficient gamma[0] = 0;
197  Scalar ck_enorm_; // ck * enorm
198 
199  bool constantStepSize_;
200  Scalar Ek_;
201  Scalar Ekm1_;
202  Scalar Ekm2_;
203  Scalar Ekp1_;
204  Scalar Est_;
205  Scalar Tk_;
206  Scalar Tkm1_;
207  Scalar Tkm2_;
208  Scalar Tkp1_;
209  int newOrder_;
210  int oldOrder_;
211  bool initialPhase_;
212  Scalar stopTime_;
213 
214  // Magic Numbers:
215  Scalar h0_safety_;
216  Scalar h0_max_factor_;
217  Scalar h_phase0_incr_;
218  Scalar h_max_inv_;
219  Scalar Tkm1_Tk_safety_;
220  Scalar Tkp1_Tk_safety_;
221  Scalar r_factor_;
222  Scalar r_safety_;
223  Scalar r_fudge_;
224  Scalar r_min_;
225  Scalar r_max_;
226  Scalar r_hincr_test_;
227  Scalar r_hincr_;
228  int max_LET_fail_;
229  Scalar minTimeStep_;
230  Scalar maxTimeStep_;
231 
232  int newtonConvergenceStatus_;
233  bool failStepIfNonlinearSolveFails_;
234 
235  // Private member functions
236 
237  Scalar wRMSNorm_(
238  const Thyra::VectorBase<Scalar>& weight,
239  const Thyra::VectorBase<Scalar>& vector
240  ) const;
241 
242  Scalar checkReduceOrder_(const StepperBase<Scalar>& stepper);
243 
244  void getFirstTimeStep_(const StepperBase<Scalar>& stepper);
245 
246  void setStepControlState_(StepControlStrategyState state);
247 
248  void updateCoeffs_();
249 
250  void setDefaultMagicNumbers_(Teuchos::ParameterList &magicNumberList);
251 
252 };
253 
254 } // namespace Rythmos
255 
256 #endif // Rythmos_IMPLICITBDF_STEPPER_STEP_CONTROL_DECL_H
257