Rythmos - Transient Integration for Differential Equations  Version of the Day
Rythmos_ThetaStepper_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_THETA_STEPPER_DECL_H
30 #define Rythmos_THETA_STEPPER_DECL_H
31 
32 #include "Rythmos_ConfigDefs.h"
33 #ifdef HAVE_RYTHMOS_EXPERIMENTAL
34 
35 #include "Rythmos_StepperBase.hpp"
36 #include "Rythmos_DataStore.hpp"
37 #include "Rythmos_LinearInterpolator.hpp"
38 #include "Rythmos_InterpolatorAcceptingObjectBase.hpp"
39 #include "Rythmos_InterpolatorBaseHelpers.hpp"
40 #include "Rythmos_SingleResidualModelEvaluator.hpp"
41 #include "Rythmos_SolverAcceptingStepperBase.hpp"
42 #include "Rythmos_StepperHelpers.hpp"
43 
44 #include "Thyra_VectorBase.hpp"
45 #include "Thyra_ModelEvaluator.hpp"
46 #include "Thyra_ModelEvaluatorHelpers.hpp"
47 #include "Thyra_AssertOp.hpp"
48 #include "Thyra_NonlinearSolverBase.hpp"
49 #include "Thyra_TestingTools.hpp"
50 
51 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
52 #include "Teuchos_as.hpp"
53 
54 
55 namespace {
56  const std::string ThetaStepperType_name = "Theta Stepper Type";
57  const std::string ThetaStepperType_default = "Implicit Euler";
58 
59  const std::string PredictorOrder_name = "Predictor Order";
60  const int PredictorOrder_default = 2;
61 }
62 
63 namespace Rythmos {
64 
65 enum ThetaStepperType
66 {
67  ImplicitEuler = 0,
68  Trapezoid,
69  INVALID_THETA_STEPPER_TYPE
70 };
71 
72 
76 template<class Scalar>
77 class ThetaStepper :
78  virtual public SolverAcceptingStepperBase<Scalar>,
79  virtual public InterpolatorAcceptingObjectBase<Scalar>
80 {
81 public:
82 
84  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
85 
88 
90  ThetaStepper();
91 
92  bool isImplicit() const;
93 
96 
98  void setInterpolator(const RCP<InterpolatorBase<Scalar> >& interpolator);
99 
101  RCP<InterpolatorBase<Scalar> >
102  getNonconstInterpolator();
103 
105  RCP<const InterpolatorBase<Scalar> >
106  getInterpolator() const;
107 
109  RCP<InterpolatorBase<Scalar> > unSetInterpolator();
111 
113 
116 
118  void setSolver(
119  const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver
120  );
121 
123  RCP<Thyra::NonlinearSolverBase<Scalar> >
124  getNonconstSolver();
125 
127  RCP<const Thyra::NonlinearSolverBase<Scalar> >
128  getSolver() const;
129 
131 
134 
136  bool supportsCloning() const;
137 
145  RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const;
146 
148  void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> >& model);
149 
151  void setNonconstModel(const RCP<Thyra::ModelEvaluator<Scalar> >& model);
152 
154  RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const;
155 
157  RCP<Thyra::ModelEvaluator<Scalar> > getNonconstModel();
158 
160  void setInitialCondition(
161  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
162  );
163 
165  Thyra::ModelEvaluatorBase::InArgs<Scalar> getInitialCondition() const;
166 
168  Scalar takeStep(Scalar dt, StepSizeType flag);
169 
171  const StepStatus<Scalar> getStepStatus() const;
172 
174 
177 
179  RCP<const Thyra::VectorSpaceBase<Scalar> >
180  get_x_space() const;
181 
183  void addPoints(
184  const Array<Scalar>& time_vec,
185  const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec,
186  const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec
187  );
188 
190  TimeRange<Scalar> getTimeRange() const;
191 
193  void getPoints(
194  const Array<Scalar>& time_vec,
195  Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec,
196  Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec,
197  Array<ScalarMag>* accuracy_vec
198  ) const;
199 
201  void getNodes(Array<Scalar>* time_vec) const;
202 
204  void removeNodes(Array<Scalar>& time_vec);
205 
207  int getOrder() const;
208 
210 
213 
215  void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
216 
218  RCP<Teuchos::ParameterList> getNonconstParameterList();
219 
221  RCP<Teuchos::ParameterList> unsetParameterList();
222 
224  RCP<const Teuchos::ParameterList> getValidParameters() const;
225 
227 
230 
232  void describe(
233  Teuchos::FancyOStream &out,
234  const Teuchos::EVerbosityLevel verbLevel
235  ) const;
236 
238 
239 private:
240 
241  // ///////////////////////
242  // Private date members
243 
244  bool isInitialized_;
245  bool haveInitialCondition_;
246  RCP<const Thyra::ModelEvaluator<Scalar> > model_;
247  RCP<Thyra::NonlinearSolverBase<Scalar> > solver_;
248 
249  Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
250 
251  RCP<Thyra::VectorBase<Scalar> > x_;
252  RCP<Thyra::VectorBase<Scalar> > x_old_;
253  RCP<Thyra::VectorBase<Scalar> > x_pre_;
254 
255  RCP<Thyra::VectorBase<Scalar> > x_dot_;
256  RCP<Thyra::VectorBase<Scalar> > x_dot_old_;
257  RCP<Thyra::VectorBase<Scalar> > x_dot_really_old_;
258  RCP<Thyra::VectorBase<Scalar> > x_dot_base_;
259 
260  Scalar t_;
261  Scalar t_old_;
262 
263  Scalar dt_;
264  Scalar dt_old_;
265  int numSteps_;
266 
267  ThetaStepperType thetaStepperType_;
268  Scalar theta_;
269  int predictor_corrector_begin_after_step_;
270  int default_predictor_order_;
271 
272  RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_;
273 
274  RCP<Teuchos::ParameterList> parameterList_;
275 
276  RCP<InterpolatorBase<Scalar> > interpolator_;
277 
278 
279  // //////////////////////////
280  // Private member functions
281 
282  void defaultInitializeAll_();
283  void initialize_();
284  void obtainPredictor_();
285 };
286 
287 
292 template<class Scalar>
293 RCP<ThetaStepper<Scalar> >
294 thetaStepper(
295  const RCP<Thyra::ModelEvaluator<Scalar> >& model,
296  const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
297  RCP<Teuchos::ParameterList>& parameterList
298  );
299 
300 } // namespace Rythmos
301 
302 #endif // HAVE_RYTHMOS_EXPERIMENTAL
303 
304 #endif //Rythmos_THETA_STEPPER_DECL_H