Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_ForwardEulerStepper_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_FORWARDEULER_STEPPER_DECL_H
30 #define Rythmos_FORWARDEULER_STEPPER_DECL_H
31 
32 #include "Rythmos_StepperBase.hpp"
33 #include "Rythmos_Types.hpp"
34 #include "Rythmos_MomentoBase.hpp"
35 #include "Rythmos_StateSerializerStrategy.hpp"
36 #include "Thyra_ModelEvaluator.hpp"
37 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
38 #include "Teuchos_ConstNonconstObjectContainer.hpp"
39 
40 namespace Rythmos {
41 
46  /*
47 template<class Scalar>
48  class ForwardEulerStepperMomento :
49  virtual public MomentoBase<Scalar>,
50  virtual public Teuchos::ParameterListAcceptorDefaultBase
51 {
52  public:
53  ForwardEulerStepperMomento() {}
54  virtual ~ForwardEulerStepperMomento() {}
55 
56  void serialize(
57  const StateSerializerStrategy<Scalar>& stateSerializer,
58  std::ostream& oStream
59  ) const
60  {
61  using Teuchos::is_null;
62  TEUCHOS_ASSERT( !is_null(model_) );
63  if (is_null(solution_vector_)) {
64  solution_vector_ = Thyra::createMember(model_->get_x_space());
65  }
66  if (is_null(residual_vector_)) {
67  residual_vector_ = Thyra::createMember(model_->get_f_space());
68  }
69  if (is_null(solution_vector_old_)) {
70  solution_vector_old_ = Thyra::createMember(model_->get_x_space());
71  }
72  stateSerializer.serializeVectorBase(*solution_vector_,oStream);
73  stateSerializer.serializeVectorBase(*residual_vector_,oStream);
74  stateSerializer.serializeVectorBase(*solution_vector_old_,oStream);
75  stateSerializer.serializeScalar(t_,oStream);
76  stateSerializer.serializeScalar(t_old_,oStream);
77  stateSerializer.serializeScalar(dt_,oStream);
78  stateSerializer.serializeInt(numSteps_,oStream);
79  stateSerializer.serializeBool(isInitialized_,oStream);
80  stateSerializer.serializeBool(haveInitialCondition_,oStream);
81  RCP<ParameterList> pl = parameterList_;
82  if (Teuchos::is_null(pl)) {
83  pl = Teuchos::parameterList();
84  }
85  stateSerializer.serializeParameterList(*pl,oStream);
86  }
87 
88  void deSerialize(
89  const StateSerializerStrategy<Scalar>& stateSerializer,
90  std::istream& iStream
91  )
92  {
93  using Teuchos::outArg;
94  using Teuchos::is_null;
95  TEUCHOS_ASSERT( !is_null(model_) );
96  if (is_null(solution_vector_)) {
97  solution_vector_ = Thyra::createMember(*model_->get_x_space());
98  }
99  if (is_null(residual_vector_)) {
100  residual_vector_ = Thyra::createMember(*model_->get_f_space());
101  }
102  if (is_null(solution_vector_old_)) {
103  solution_vector_old_ = Thyra::createMember(*model_->get_x_space());
104  }
105  stateSerializer.deSerializeVectorBase(outArg(*solution_vector_),iStream);
106  stateSerializer.deSerializeVectorBase(outArg(*residual_vector_),iStream);
107  stateSerializer.deSerializeVectorBase(outArg(*solution_vector_old_),iStream);
108  stateSerializer.deSerializeScalar(outArg(t_),iStream);
109  stateSerializer.deSerializeScalar(outArg(t_old_),iStream);
110  stateSerializer.deSerializeScalar(outArg(dt_),iStream);
111  stateSerializer.deSerializeInt(outArg(numSteps_),iStream);
112  stateSerializer.deSerializeBool(outArg(isInitialized_),iStream);
113  stateSerializer.deSerializeBool(outArg(haveInitialCondition_),iStream);
114  if (is_null(parameterList_)) {
115  parameterList_ = Teuchos::parameterList();
116  }
117  stateSerializer.deSerializeParameterList(outArg(*parameterList_),iStream);
118  }
119 
120  RCP<MomentoBase<Scalar> > clone() const
121  {
122  RCP<ForwardEulerStepperMomento<Scalar> > m = rcp(new ForwardEulerStepperMomento<Scalar>());
123  m->set_solution_vector(solution_vector_);
124  m->set_residual_vector(residual_vector_);
125  m->set_solution_vector_old(solution_vector_old_);
126  m->set_t(t_);
127  m->set_t_old(t_old_);
128  m->set_dt(dt_);
129  m->set_numSteps(numSteps_);
130  m->set_isInitialized(isInitialized_);
131  m->set_haveInitialCondition(haveInitialCondition_);
132  m->set_parameterList(parameterList_);
133  if (!Teuchos::is_null(this->getMyParamList())) {
134  m->setParameterList(Teuchos::parameterList(*(this->getMyParamList())));
135  }
136  m->setModel(model_);
137  m->setBasePoint(basePoint_);
138  // How do I copy the VerboseObject data?
139  // 07/10/09 tscoffe: Its not set up in Teuchos to do this yet
140  return m;
141  }
142 
143  void set_solution_vector(const RCP<const VectorBase<Scalar> >& solution_vector )
144  {
145  solution_vector_ = Teuchos::null;
146  if (!Teuchos::is_null(solution_vector)) {
147  solution_vector_ = solution_vector->clone_v();
148  }
149  }
150  RCP<VectorBase<Scalar> > get_solution_vector() const
151  { return solution_vector_; }
152 
153  void set_residual_vector(const RCP<const VectorBase<Scalar> >& residual_vector )
154  {
155  residual_vector_ = Teuchos::null;
156  if (!Teuchos::is_null(residual_vector)) {
157  residual_vector_ = residual_vector->clone_v();
158  }
159  }
160  RCP<VectorBase<Scalar> > get_residual_vector() const
161  { return residual_vector_; }
162 
163  void set_solution_vector_old(const RCP<const VectorBase<Scalar> >& solution_vector_old )
164  {
165  solution_vector_old_ = Teuchos::null;
166  if (!Teuchos::is_null(solution_vector_old)) {
167  solution_vector_old_ = solution_vector_old->clone_v();
168  }
169  }
170  RCP<VectorBase<Scalar> > get_solution_vector_old() const
171  { return solution_vector_old_; }
172 
173  void set_t(const Scalar & t)
174  { t_ = t; }
175  Scalar get_t() const
176  { return t_; }
177 
178  void set_t_old(const Scalar & t_old)
179  { t_old_ = t_old; }
180  Scalar get_t_old() const
181  { return t_old_; }
182 
183  void set_dt(const Scalar & dt)
184  { dt_ = dt; }
185  Scalar get_dt() const
186  { return dt_; }
187 
188  void set_numSteps(const int & numSteps)
189  { numSteps_ = numSteps; }
190  int get_numSteps() const
191  { return numSteps_; }
192 
193  void set_isInitialized(const bool & isInitialized)
194  { isInitialized_ = isInitialized; }
195  bool get_isInitialized() const
196  { return isInitialized_; }
197 
198  void set_haveInitialCondition(const bool & haveInitialCondition)
199  { haveInitialCondition_ = haveInitialCondition; }
200  bool get_haveInitialCondition() const
201  { return haveInitialCondition_; }
202 
203  void set_parameterList(const RCP<const ParameterList>& pl)
204  {
205  parameterList_ = Teuchos::null;
206  if (!Teuchos::is_null(pl)) {
207  parameterList_ = Teuchos::parameterList(*pl);
208  }
209  }
210  RCP<ParameterList> get_parameterList() const
211  { return parameterList_; }
212 
213  void setParameterList(const RCP<ParameterList>& paramList)
214  { this->setMyParamList(paramList); }
215  RCP<const ParameterList> getValidParameters() const
216  { return Teuchos::null; }
217 
218  void set_model(const RCP<const Thyra::ModelEvaluator<Scalar> >& model)
219  { model_ = model; }
220  RCP<const Thyra::ModelEvaluator<Scalar> > get_model() const
221  { return model_; }
222 
223  void set_basePoint(const RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> >& basePoint)
224  { basePoint_ = basePoint; }
225  RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > get_basePoint() const
226  { return basePoint_; }
227 
228  private:
229  RCP<Thyra::VectorBase<Scalar> > solution_vector_;
230  RCP<Thyra::VectorBase<Scalar> > residual_vector_;
231  RCP<Thyra::VectorBase<Scalar> > solution_vector_old_;
232  Scalar t_;
233  Scalar t_old_;
234  Scalar dt_;
235  int numSteps_;
236  bool isInitialized_;
237  bool haveInitialCondition_;
238  RCP<ParameterList> parameterList_;
239 
240  // Objects that must be set prior to serialization and deSerialization:
241  RCP<const Thyra::ModelEvaluator<Scalar> > model_;
242  // Objects that must be set prior to calling ForwardEulerStepper::setMomento:
243  RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > basePoint_;
244 };
245 */
246 template<class Scalar>
248  virtual public MomentoBase<Scalar>,
249  virtual public Teuchos::ParameterListAcceptorDefaultBase
250 {
251  public:
253  virtual ~ForwardEulerStepperMomento();
254 
255  void serialize(
256  const StateSerializerStrategy<Scalar>& stateSerializer,
257  std::ostream& oStream
258  ) const;
259 
260  void deSerialize(
261  const StateSerializerStrategy<Scalar>& stateSerializer,
262  std::istream& iStream
263  );
264 
265  RCP<MomentoBase<Scalar> > clone() const;
266 
267  void set_solution_vector(const RCP<const VectorBase<Scalar> >& solution_vector );
268  RCP<VectorBase<Scalar> > get_solution_vector() const;
269 
270  void set_residual_vector(const RCP<const VectorBase<Scalar> >& residual_vector );
271  RCP<VectorBase<Scalar> > get_residual_vector() const;
272 
273  void set_solution_vector_old(const RCP<const VectorBase<Scalar> >& solution_vector_old );
274  RCP<VectorBase<Scalar> > get_solution_vector_old() const;
275 
276  void set_t(const Scalar & t);
277  Scalar get_t() const;
278 
279  void set_t_old(const Scalar & t_old);
280  Scalar get_t_old() const;
281 
282  void set_dt(const Scalar & dt);
283  Scalar get_dt() const;
284 
285  void set_numSteps(const int & numSteps);
286  int get_numSteps() const;
287 
288  void set_isInitialized(const bool & isInitialized);
289  bool get_isInitialized() const;
290 
291  void set_haveInitialCondition(const bool & haveInitialCondition);
292  bool get_haveInitialCondition() const;
293 
294  void set_parameterList(const RCP<const ParameterList>& pl);
295  RCP<ParameterList> get_parameterList() const;
296 
297  void setParameterList(const RCP<ParameterList>& paramList);
298  RCP<const ParameterList> getValidParameters() const;
299 
300  void set_model(const RCP<const Thyra::ModelEvaluator<Scalar> >& model);
301  RCP<const Thyra::ModelEvaluator<Scalar> > get_model() const;
302 
303  void set_basePoint(const RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> >& basePoint);
304  RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > get_basePoint() const;
305 
306  private:
307  RCP<Thyra::VectorBase<Scalar> > solution_vector_;
308  RCP<Thyra::VectorBase<Scalar> > residual_vector_;
309  RCP<Thyra::VectorBase<Scalar> > solution_vector_old_;
310  Scalar t_;
311  Scalar t_old_;
312  Scalar dt_;
313  int numSteps_;
314  bool isInitialized_;
315  bool haveInitialCondition_;
316  RCP<ParameterList> parameterList_;
317 
318  // Objects that must be set prior to serialization and deSerialization:
319  RCP<const Thyra::ModelEvaluator<Scalar> > model_;
320  // Objects that must be set prior to calling ForwardEulerStepper::setMomento:
321  RCP<const Thyra::ModelEvaluatorBase::InArgs<Scalar> > basePoint_;
322 };
323 
324 
326 template<class Scalar>
327 class ForwardEulerStepper : virtual public StepperBase<Scalar>
328 {
329  public:
330 
331  typedef Teuchos::ScalarTraits<Scalar> ST;
332  typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
333 
336 
338  bool supportsCloning() const;
339 
341  RCP<StepperBase<Scalar> > cloneStepperAlgorithm() const;
342 
344  void setModel(const RCP<const Thyra::ModelEvaluator<Scalar> >& model);
345 
347  void setNonconstModel(const RCP<Thyra::ModelEvaluator<Scalar> >& model);
348 
350  RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const;
351 
353  RCP<Thyra::ModelEvaluator<Scalar> > getNonconstModel();
354 
356  void setInitialCondition(
357  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &initialCondition
358  );
359 
361  Thyra::ModelEvaluatorBase::InArgs<Scalar> getInitialCondition() const;
362 
364  RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
365 
368 
370  Scalar takeStep(Scalar dt, StepSizeType flag);
371 
373  const StepStatus<Scalar> getStepStatus() const;
374 
376  std::string description() const;
377 
379  void describe(
380  Teuchos::FancyOStream &out,
381  const Teuchos::EVerbosityLevel verbLevel
382  ) const;
383 
386  void addPoints(
387  const Array<Scalar>& time_vec
388  ,const Array<RCP<const Thyra::VectorBase<Scalar> > >& x_vec
389  ,const Array<RCP<const Thyra::VectorBase<Scalar> > >& xdot_vec
390  );
391 
393  void getPoints(
394  const Array<Scalar>& time_vec
395  ,Array<RCP<const Thyra::VectorBase<Scalar> > >* x_vec
396  ,Array<RCP<const Thyra::VectorBase<Scalar> > >* xdot_vec
397  ,Array<ScalarMag>* accuracy_vec
398  ) const;
399 
401  void setRange(
402  const TimeRange<Scalar>& range,
404  );
405 
408 
410  void getNodes(Array<Scalar>* time_vec) const;
411 
413  void removeNodes(Array<Scalar>& time_vec);
414 
416  int getOrder() const;
417 
419 
420  void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
421 
423  RCP<Teuchos::ParameterList> getNonconstParameterList();
424 
426  RCP<Teuchos::ParameterList> unsetParameterList();
427 
429  RCP<const Teuchos::ParameterList> getValidParameters() const;
430 
434  RCP<const MomentoBase<Scalar> > getMomento() const;
435 
439  void setMomento( const Ptr<const MomentoBase<Scalar> >& momentoPtr );
440 
441  private:
442 
443  RCP<const Thyra::ModelEvaluator<Scalar> > model_;
444  RCP<Thyra::VectorBase<Scalar> > solution_vector_;
445  RCP<Thyra::VectorBase<Scalar> > residual_vector_;
446  Scalar t_;
447  Scalar dt_;
448  Scalar t_old_;
449  RCP<Thyra::VectorBase<Scalar> > solution_vector_old_;
450  Thyra::ModelEvaluatorBase::InArgs<Scalar> basePoint_;
451  int numSteps_;
452  bool haveInitialCondition_;
453 
454  RCP<Teuchos::ParameterList> parameterList_;
455  bool isInitialized_;
456 
457  // Private member functions:
458  void defaultInitializAll_();
459  void initialize_();
460  void checkConsistentState_();
461 
462 };
463 
464 // Nonmember constructor
465 template<class Scalar>
466 RCP<ForwardEulerStepper<Scalar> > forwardEulerStepper();
467 
468 // Nonmember constructor
469 template<class Scalar>
470 RCP<ForwardEulerStepper<Scalar> > forwardEulerStepper(const RCP<Thyra::ModelEvaluator<Scalar> >& model);
471 
472 } // namespace Rythmos
473 
474 #endif //Rythmos_FORWARDEULER_STEPPER_DECL_H
RCP< const MomentoBase< Scalar > > getMomento() const
Get momento object for use in restarts.
RCP< Teuchos::ParameterList > unsetParameterList()
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void removeNodes(Array< Scalar > &time_vec)
Remove interpolation nodes.
RCP< Thyra::ModelEvaluator< Scalar > > getNonconstModel()
RCP< Teuchos::ParameterList > getNonconstParameterList()
Base class for defining stepper functionality.
Concrete momento class for the ForwardEulerStepper.
void setParameterList(RCP< Teuchos::ParameterList > const &paramList)
Redefined from Teuchos::ParameterListAcceptor.
void setModel(const RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Base class for serializing Rythmos state data.
RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
RCP< const Teuchos::ParameterList > getValidParameters() const
void setInitialCondition(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &initialCondition)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getInitialCondition() const
int getOrder() const
Get order of interpolation.
Base class for an interpolation buffer.
const StepStatus< Scalar > getStepStatus() const
void setRange(const TimeRange< Scalar > &range, const InterpolationBufferBase< Scalar > &IB)
Fill data in from another interpolation buffer.
void addPoints(const Array< Scalar > &time_vec, const Array< RCP< const Thyra::VectorBase< Scalar > > > &x_vec, const Array< RCP< const Thyra::VectorBase< Scalar > > > &xdot_vec)
void getPoints(const Array< Scalar > &time_vec, Array< RCP< const Thyra::VectorBase< Scalar > > > *x_vec, Array< RCP< const Thyra::VectorBase< Scalar > > > *xdot_vec, Array< ScalarMag > *accuracy_vec) const
Get values from buffer.
void setNonconstModel(const RCP< Thyra::ModelEvaluator< Scalar > > &model)
void getNodes(Array< Scalar > *time_vec) const
Get interpolation nodes.
RCP< StepperBase< Scalar > > cloneStepperAlgorithm() const
RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
void setMomento(const Ptr< const MomentoBase< Scalar > > &momentoPtr)
Set momento object for use in restarts.
Base class for a momento object.
Scalar takeStep(Scalar dt, StepSizeType flag)