Rythmos - Transient Integration for Differential Equations  Version of the Day
Rythmos_BackwardEulerStepper_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_BACKWARD_EULER_STEPPER_DECL_H
30 #define Rythmos_BACKWARD_EULER_STEPPER_DECL_H
31 
32 #include "Rythmos_SolverAcceptingStepperBase.hpp"
33 #include "Rythmos_StepControlStrategyAcceptingStepperBase.hpp"
34 #include "Rythmos_InterpolatorAcceptingObjectBase.hpp"
35 #include "Rythmos_SingleResidualModelEvaluator.hpp"
36 #include "Rythmos_MomentoBase.hpp"
37 
38 #include "Thyra_VectorBase.hpp"
39 #include "Thyra_ModelEvaluator.hpp"
40 #include "Thyra_NonlinearSolverBase.hpp"
41 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
42 
43 
44 namespace Rythmos {
45 
46 
52 template<class Scalar>
54  virtual public MomentoBase<Scalar>,
55  virtual public Teuchos::ParameterListAcceptorDefaultBase
56 {
57  public:
59  virtual ~BackwardEulerStepperMomento() {}
60 
61  RCP<MomentoBase<Scalar> > clone() const
62  {
63  RCP<BackwardEulerStepperMomento<Scalar> > m =
65  m->set_scaled_x_old(scaled_x_old_);
66  m->set_x_dot_old(x_dot_old_);
67  m->set_x(x_);
68  m->set_x_old(x_old_);
69  m->set_x_dot(x_dot_);
70  m->set_dx(dx_);
71  m->set_t(t_);
72  m->set_t_old(t_old_);
73  m->set_dt(dt_);
74  m->set_numSteps(numSteps_);
75  m->set_isInitialized(isInitialized_);
76  m->set_haveInitialCondition(haveInitialCondition_);
77  m->set_parameterList(parameterList_);
78  m->set_basePoint(basePoint_);
79  m->set_neModel(neModel_);
80  m->set_interpolator(interpolator_);
81  m->set_stepControl(stepControl_);
82  if (!Teuchos::is_null(this->getMyParamList())) {
83  m->setParameterList(Teuchos::parameterList(*(this->getMyParamList())));
84  }
85  // How do I copy the VerboseObject data?
86  // 07/10/09 tscoffe: Its not set up in Teuchos to do this yet
87  return m;
88  }
89 
90  void serialize(
91  const StateSerializerStrategy<Scalar>& stateSerializer,
92  std::ostream& oStream
93  ) const
94  { }
95 
96  void deSerialize(
97  const StateSerializerStrategy<Scalar>& stateSerializer,
98  std::istream& iStream
99  )
100  { }
101 
102  void set_scaled_x_old(const RCP<const VectorBase<Scalar> >& scaled_x_old )
103  {
104  scaled_x_old_ = Teuchos::null;
105  if (!Teuchos::is_null(scaled_x_old)) {
106  scaled_x_old_ = scaled_x_old->clone_v();
107  }
108  }
109  RCP<VectorBase<Scalar> > get_scaled_x_old() const
110  { return scaled_x_old_; }
111 
112  void set_x_dot_old(const RCP<const VectorBase<Scalar> >& x_dot_old )
113  {
114  x_dot_old_ = Teuchos::null;
115  if (!Teuchos::is_null(x_dot_old)) {
116  x_dot_old_ = x_dot_old->clone_v();
117  }
118  }
119  RCP<VectorBase<Scalar> > get_x_dot_old() const
120  { return x_dot_old_; }
121 
122  void set_x_old(const RCP<const VectorBase<Scalar> >& x_old )
123  {
124  x_old_ = Teuchos::null;
125  if (!Teuchos::is_null(x_old)) {
126  x_old_ = x_old->clone_v();
127  }
128  }
129  RCP<VectorBase<Scalar> > get_x_old() const
130  { return x_old_; }
131 
132  void set_x(const RCP<const VectorBase<Scalar> >& x )
133  {
134  x_ = Teuchos::null;
135  if (!Teuchos::is_null(x)) {
136  x_ = x->clone_v();
137  }
138  }
139  RCP<VectorBase<Scalar> > get_x() const
140  { return x_; }
141 
142  void set_dx(const RCP<const VectorBase<Scalar> >& dx )
143  {
144  dx_ = Teuchos::null;
145  if (!Teuchos::is_null(dx)) {
146  dx_ = dx->clone_v();
147  }
148  }
149  RCP<VectorBase<Scalar> > get_dx() const
150  { return dx_; }
151 
152  void set_x_dot(const RCP<const VectorBase<Scalar> >& x_dot )
153  {
154  x_dot_ = Teuchos::null;
155  if (!Teuchos::is_null(x_dot)) {
156  x_dot_ = x_dot->clone_v();
157  }
158  }
159  RCP<VectorBase<Scalar> > get_x_dot() const
160  { return x_dot_; }
161 
162  void set_t(const Scalar & t)
163  { t_ = t; }
164  Scalar get_t() const
165  { return t_; }
166 
167  void set_t_old(const Scalar & t_old)
168  { t_old_ = t_old; }
169  Scalar get_t_old() const
170  { return t_old_; }
171 
172  void set_dt(const Scalar & dt)
173  { dt_ = dt; }
174  Scalar get_dt() const
175  { return dt_; }
176 
177  void set_numSteps(const int & numSteps)
178  { numSteps_ = numSteps; }
179  int get_numSteps() const
180  { return numSteps_; }
181 
182  void set_newtonConvergenceStatus(const int & newtonConvergenceStatus)
183  { newtonConvergenceStatus_ = newtonConvergenceStatus; }
184  int get_newtonConvergenceStatus() const
185  { return newtonConvergenceStatus_; }
186 
187  void set_isInitialized(const bool & isInitialized)
188  { isInitialized_ = isInitialized; }
189  bool get_isInitialized() const
190  { return isInitialized_; }
191 
192  void set_haveInitialCondition(const bool & haveInitialCondition)
193  { haveInitialCondition_ = haveInitialCondition; }
194  bool get_haveInitialCondition() const
195  { return haveInitialCondition_; }
196 
197  void set_parameterList(const RCP<const ParameterList>& pl)
198  {
199  parameterList_ = Teuchos::null;
200  if (!Teuchos::is_null(pl)) {
201  parameterList_ = Teuchos::parameterList(*pl);
202  }
203  }
204  RCP<ParameterList> get_parameterList() const
205  { return parameterList_; }
206 
207  void set_basePoint(Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint)
208  { basePoint_ = basePoint; };
209  Thyra::ModelEvaluatorBase::InArgs<Scalar> get_basePoint() const
210  { return basePoint_; }
211 
212  void set_neModel(const RCP<Rythmos::SingleResidualModelEvaluator<Scalar> >& neModel)
213  {
214  neModel_ = Teuchos::null;
215  if (!Teuchos::is_null(neModel)) {
216  neModel_ = Teuchos::rcp(new Rythmos::SingleResidualModelEvaluator<Scalar>);
217  }
218  }
219  RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > get_neModel() const
220  { return neModel_; }
221 
222  void set_interpolator(const RCP<InterpolatorBase<Scalar> >& interpolator)
223  {
224  interpolator_ = Teuchos::null;
225  if (!Teuchos::is_null(interpolator)) {
226  TEUCHOS_ASSERT(interpolator->supportsCloning());
227  interpolator_ = interpolator->cloneInterpolator();
228  }
229  }
230  RCP<InterpolatorBase<Scalar> > get_interpolator() const
231  { return interpolator_; }
232 
233  void set_stepControl(const RCP<StepControlStrategyBase<Scalar> >& stepControl)
234  {
235  stepControl_ = Teuchos::null;
236  if (!Teuchos::is_null(stepControl)) {
237  TEUCHOS_ASSERT(stepControl->supportsCloning());
238  stepControl_ = stepControl->cloneStepControlStrategyAlgorithm();
239  }
240  }
241  RCP<StepControlStrategyBase<Scalar> > get_stepControl() const
242  { return stepControl_; }
243 
244  void setParameterList(const RCP<ParameterList>& paramList)
245  { this->setMyParamList(paramList); }
246  RCP<const ParameterList> getValidParameters() const
247  { return Teuchos::null; }
248 
249  private:
250  RCP<Thyra::VectorBase<Scalar> > scaled_x_old_;
251  RCP<Thyra::VectorBase<Scalar> > x_old_;
252  RCP<Thyra::VectorBase<Scalar> > x_dot_old_;
253  RCP<Thyra::VectorBase<Scalar> > x_;
254  RCP<Thyra::VectorBase<Scalar> > x_dot_;
255  RCP<Thyra::VectorBase<Scalar> > dx_;
256  Scalar t_;
257  Scalar t_old_;
258  Scalar dt_;
259  int numSteps_;
260  int newtonConvergenceStatus_;
261  bool isInitialized_;
262  bool haveInitialCondition_;
263  RCP<Teuchos::ParameterList> parameterList_;
264  Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
265  RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_;
266  RCP<InterpolatorBase<Scalar> > interpolator_;
267  RCP<StepControlStrategyBase<Scalar> > stepControl_;
268 
269 };
270 
271 
282 template<class Scalar>
284  virtual public SolverAcceptingStepperBase<Scalar>,
285  virtual public StepControlStrategyAcceptingStepperBase<Scalar>,
286  virtual public InterpolatorAcceptingObjectBase<Scalar>
287 {
288 public:
289 
291  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
292 
295 
298 
301  const RCP<Thyra::ModelEvaluator<Scalar> >& model,
302  const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
303  );
304 
306 
309 
311  void setInterpolator(const RCP<InterpolatorBase<Scalar> >& interpolator);
312 
314  RCP<InterpolatorBase<Scalar> > getNonconstInterpolator();
315 
317  RCP<const InterpolatorBase<Scalar> > getInterpolator() const;
318 
320  RCP<InterpolatorBase<Scalar> > unSetInterpolator();
321 
323 
326 
328  void setStepControlStrategy(
329  const RCP<StepControlStrategyBase<Scalar> >& stepControlStrategy
330  );
331 
333  RCP<StepControlStrategyBase<Scalar> >
334  getNonconstStepControlStrategy();
335 
337  RCP<const StepControlStrategyBase<Scalar> >
338  getStepControlStrategy() const;
339 
341 
344 
346  void setSolver(
347  const RCP<Thyra::NonlinearSolverBase<Scalar> > &solver
348  );
349 
351  RCP<Thyra::NonlinearSolverBase<Scalar> >
352  getNonconstSolver();
353 
355  RCP<const Thyra::NonlinearSolverBase<Scalar> >
356  getSolver() const;
357 
359 
362 
364  bool supportsCloning() const;
365 
373  RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const;
374 
376  bool isImplicit() const;
377 
379  void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> >& model);
380 
382  void setNonconstModel(const RCP<Thyra::ModelEvaluator<Scalar> >& model);
383 
385  RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const;
386 
388  RCP<Thyra::ModelEvaluator<Scalar> > getNonconstModel();
389 
391  void setInitialCondition(
392  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
393  );
394 
396  Thyra::ModelEvaluatorBase::InArgs<Scalar> getInitialCondition() const;
397 
399  Scalar takeStep(Scalar dt, StepSizeType flag);
400 
402  const StepStatus<Scalar> getStepStatus() const;
403 
405 
408 
410  RCP<const Thyra::VectorSpaceBase<Scalar> >
411  get_x_space() const;
412 
414  void addPoints(
415  const Array<Scalar>& time_vec,
416  const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec,
417  const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec
418  );
419 
421  TimeRange<Scalar> getTimeRange() const;
422 
424  void getPoints(
425  const Array<Scalar>& time_vec,
426  Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec,
427  Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec,
428  Array<ScalarMag>* accuracy_vec
429  ) const;
430 
432  void getNodes(Array<Scalar>* time_vec) const;
433 
435  void removeNodes(Array<Scalar>& time_vec);
436 
438  int getOrder() const;
439 
441 
444 
446  void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
447 
449  RCP<Teuchos::ParameterList> getNonconstParameterList();
450 
452  RCP<Teuchos::ParameterList> unsetParameterList();
453 
455  RCP<const Teuchos::ParameterList> getValidParameters() const;
456 
458 
461 
463  void describe(
464  Teuchos::FancyOStream &out,
465  const Teuchos::EVerbosityLevel verbLevel
466  ) const;
467 
469 
472 
476  RCP<const MomentoBase<Scalar> > getMomento() const;
477 
480  void setMomento(
481  const Ptr<const MomentoBase<Scalar> >& momentoPtr,
482  const RCP<Thyra::ModelEvaluator<Scalar> >& model,
483  const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
484  );
485 
487 
488 
489 private:
490 
491  // ///////////////////////
492  // Private date members
493 
494  bool isInitialized_;
495  bool haveInitialCondition_;
496  RCP<const Thyra::ModelEvaluator<Scalar> > model_;
497  RCP<Thyra::NonlinearSolverBase<Scalar> > solver_;
498  RCP<Thyra::VectorBase<Scalar> > x_old_;
499  RCP<Thyra::VectorBase<Scalar> > scaled_x_old_;
500  RCP<Thyra::VectorBase<Scalar> > x_dot_old_;
501 
502  Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
503  RCP<Thyra::VectorBase<Scalar> > x_;
504  RCP<Thyra::VectorBase<Scalar> > x_dot_;
505  RCP<Thyra::VectorBase<Scalar> > dx_;
506  Scalar t_;
507  Scalar t_old_;
508 
509  Scalar dt_;
510  int numSteps_;
511 
512  RCP<Rythmos::SingleResidualModelEvaluator<Scalar> > neModel_;
513 
514  RCP<Teuchos::ParameterList> parameterList_;
515 
516  RCP<InterpolatorBase<Scalar> > interpolator_;
517  RCP<StepControlStrategyBase<Scalar> > stepControl_;
518 
519  int newtonConvergenceStatus_;
520 
521 
522  // //////////////////////////
523  // Private member functions
524 
525  void defaultInitializeAll_();
526  void initialize_();
527  void checkConsistentState_();
528  void obtainPredictor_();
529 
530 };
531 
532 
537 template<class Scalar>
538 RCP<BackwardEulerStepper<Scalar> >
539 backwardEulerStepper();
540 
541 
546 template<class Scalar>
547 RCP<BackwardEulerStepper<Scalar> >
548 backwardEulerStepper(
549  const RCP<Thyra::ModelEvaluator<Scalar> >& model,
550  const RCP<Thyra::NonlinearSolverBase<Scalar> >& solver
551  );
552 
553 
554 } // namespace Rythmos
555 
556 
557 #endif //Rythmos_BACKWARD_EULER_STEPPER_DECL_H
Simple concrete stepper subclass implementing an implicit backward Euler method.
Mix-in interface for stepper objects that accept a step control strategy object to be used for evalua...
Base strategy class for interpolation functionality.
Base class for serializing Rythmos state data.
The member functions in the StepControlStrategyBase move you between these states in the following fa...
Mix-in interface for objects that accept an interpolator object.
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Concrete momento class for the BackwardEulerStepper.
Decorator subclass for a steady-state version of a DAE for single-residual time stepper methods...
Mix-in interface all implicit stepper objects that accept a nonlinear solver to be used to compute th...
Base class for a momento object.