00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef Rythmos_ExplicitRK_STEPPER_H
00030 #define Rythmos_ExplicitRK_STEPPER_H
00031
00032 #include "Rythmos_Stepper.hpp"
00033 #include "Teuchos_RefCountPtr.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 #include "Thyra_ModelEvaluator.hpp"
00036 #include "Thyra_ModelEvaluatorHelpers.hpp"
00037
00038 namespace Rythmos {
00039
00041 template<class Scalar>
00042 class ExplicitRKStepper : virtual public Stepper<Scalar>
00043 {
00044 public:
00045
00046 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00047
00049 ExplicitRKStepper();
00050 ExplicitRKStepper(const Teuchos::RefCountPtr<const Thyra::ModelEvaluator<Scalar> > &model_);
00051
00053 ~ExplicitRKStepper();
00054
00056 Scalar TakeStep(Scalar dt);
00057
00059 Scalar TakeStep();
00060
00062 Teuchos::RefCountPtr<const Thyra::VectorBase<Scalar> > get_solution() const;
00063
00065 std::string description() const;
00066
00068 std::ostream& describe(
00069 std::ostream &out
00070 ,const Teuchos::EVerbosityLevel verbLevel
00071 ,const std::string leadingIndent
00072 ,const std::string indentSpacer
00073 ) const;
00074
00077 bool SetPoints(
00078 const std::vector<Scalar>& time_list
00079 ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& x_list
00080 ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& xdot_list);
00081
00083 bool GetPoints(
00084 const std::vector<Scalar>& time_list
00085 ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* x_list
00086 ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* xdot_list
00087 ,std::vector<ScalarMag>* accuracy_list) const;
00088
00090 bool SetRange(
00091 const Scalar& time_lower
00092 ,const Scalar& time_upper
00093 ,const InterpolationBuffer<Scalar> & IB);
00094
00096 bool GetNodes(std::vector<Scalar>* time_list) const;
00097
00099 bool RemoveNodes(std::vector<Scalar>& time_list) const;
00100
00102 int GetOrder() const;
00103
00104 private:
00105
00106 Teuchos::RefCountPtr<const Thyra::ModelEvaluator<Scalar> > model_;
00107 Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > solution_vector_;
00108 std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > > k_vector_;
00109 Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > ktemp_vector_;
00110
00111 int stages_;
00112 std::vector<std::vector<Scalar> > b_A;
00113 std::vector<Scalar> b_b;
00114 std::vector<Scalar> b_c;
00115
00116 Scalar t_;
00117
00118 };
00119
00120 template<class Scalar>
00121 ExplicitRKStepper<Scalar>::ExplicitRKStepper(const Teuchos::RefCountPtr<const Thyra::ModelEvaluator<Scalar> > &model)
00122 {
00123 typedef Teuchos::ScalarTraits<Scalar> ST;
00124 model_ = model;
00125 t_ = ST::zero();
00126 solution_vector_ = model_->getNominalValues().get_x()->clone_v();
00127 stages_ = 4;
00128 k_vector_.reserve(stages_);
00129 Teuchos::RefCountPtr<const Thyra::VectorSpaceBase<Scalar> >
00130 f_space = model_->get_f_space();
00131 for (int i=0 ; i<stages_ ; ++i)
00132 {
00133 k_vector_.push_back(Thyra::createMember(f_space));
00134 }
00135 ktemp_vector_ = Thyra::createMember(f_space);
00136
00137
00138 Scalar zero = ST::zero();
00139 b_A.reserve(stages_);
00140 b_b.reserve(stages_);
00141 b_c.reserve(stages_);
00142
00143
00144 b_b.push_back(zero);
00145 b_b.push_back(zero);
00146 b_b.push_back(zero);
00147 b_b.push_back(zero);
00148
00149 b_c.push_back(zero);
00150 b_c.push_back(zero);
00151 b_c.push_back(zero);
00152 b_c.push_back(zero);
00153
00154 for (int i=0 ; i<stages_ ; ++i)
00155 {
00156 b_A.push_back(b_b);
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 Scalar one = ST::one();
00221 Scalar onehalf = ST::one()/(2*ST::one());
00222 Scalar onesixth = ST::one()/(6*ST::one());
00223 Scalar onethird = ST::one()/(3*ST::one());
00224
00225
00226 b_A[0][0] = zero;
00227 b_A[0][1] = zero;
00228 b_A[0][2] = zero;
00229 b_A[0][3] = zero;
00230
00231 b_A[1][0] = onehalf;
00232 b_A[1][1] = zero;
00233 b_A[1][2] = zero;
00234 b_A[1][3] = zero;
00235
00236 b_A[2][0] = zero;
00237 b_A[2][1] = onehalf;
00238 b_A[2][2] = zero;
00239 b_A[2][3] = zero;
00240
00241 b_A[3][0] = zero;
00242 b_A[3][1] = zero;
00243 b_A[3][2] = one;
00244 b_A[3][3] = zero;
00245
00246
00247 b_b[0] = onesixth;
00248 b_b[1] = onethird;
00249 b_b[2] = onethird;
00250 b_b[3] = onesixth;
00251
00252
00253 b_c[0] = zero;
00254 b_c[1] = onehalf;
00255 b_c[2] = onehalf;
00256 b_c[3] = one;
00257
00258 }
00259
00260 template<class Scalar>
00261 ExplicitRKStepper<Scalar>::ExplicitRKStepper()
00262 {
00263 }
00264
00265 template<class Scalar>
00266 ExplicitRKStepper<Scalar>::~ExplicitRKStepper()
00267 {
00268 }
00269
00270 template<class Scalar>
00271 Scalar ExplicitRKStepper<Scalar>::TakeStep()
00272 {
00273
00274 typedef Teuchos::ScalarTraits<Scalar> ST;
00275 return(-ST::one());
00276 }
00277
00278 template<class Scalar>
00279 Scalar ExplicitRKStepper<Scalar>::TakeStep(Scalar dt)
00280 {
00281 typedef Teuchos::ScalarTraits<Scalar> ST;
00282 typedef typename Thyra::ModelEvaluatorBase::InArgs<Scalar>::ScalarMag ScalarMag;
00283
00284
00285 for (int s=0 ; s < stages_ ; ++s)
00286 {
00287 Thyra::assign(&*ktemp_vector_, *solution_vector_);
00288 for (int j=0 ; j < s ; ++j)
00289 {
00290 if (b_A[s][j] != ST::zero())
00291 Thyra::Vp_StV(&*ktemp_vector_, b_A[s][j], *k_vector_[j]);
00292 }
00293 ScalarMag ts = t_ + b_c[s]*dt;
00294 Thyra::eval_f<Scalar>(*model_,*ktemp_vector_,ts,&*k_vector_[s]);
00295 Thyra::Vt_S(&*k_vector_[s],dt);
00296
00297 }
00298
00299 for (int s=0 ; s < stages_ ; ++s)
00300 {
00301 if (b_b[s] != ST::zero())
00302 Thyra::Vp_StV(&*solution_vector_, b_b[s], *k_vector_[s]);
00303 }
00304
00305
00306 t_ = t_ + dt;
00307
00308 return(dt);
00309 }
00310
00311 template<class Scalar>
00312 Teuchos::RefCountPtr<const Thyra::VectorBase<Scalar> > ExplicitRKStepper<Scalar>::get_solution() const
00313 {
00314 return(solution_vector_);
00315 }
00316
00317 template<class Scalar>
00318 std::string ExplicitRKStepper<Scalar>::description() const
00319 {
00320 std::string name = "Rythmos::ExplicitRKStepper";
00321 return(name);
00322 }
00323
00324 template<class Scalar>
00325 std::ostream& ExplicitRKStepper<Scalar>::describe(
00326 std::ostream &out
00327 ,const Teuchos::EVerbosityLevel verbLevel
00328 ,const std::string leadingIndent
00329 ,const std::string indentSpacer
00330 ) const
00331 {
00332 if (verbLevel == Teuchos::VERB_EXTREME)
00333 {
00334 out << description() << "::describe" << std::endl;
00335 out << "model_ = " << std::endl;
00336 out << model_->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00337 out << "solution_vector_ = " << std::endl;
00338 out << solution_vector_->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00339 for (int i=0 ; i<stages_ ; ++i)
00340 {
00341 out << "k_vector_[" << i << "] = " << std::endl;
00342 out << k_vector_[i]->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00343 }
00344 out << "ktemp_vector_ = " << std::endl;
00345 out << ktemp_vector_->describe(out,verbLevel,leadingIndent,indentSpacer) << std::endl;
00346 for (int i=0 ; i<stages_ ; ++i)
00347 for (int j=0 ; j<stages_ ; ++j)
00348 out << "b_A[" << i << "][" << j << "] = " << b_A[i][j] << std::endl;
00349 for (int i=0 ; i<stages_ ; ++i)
00350 out << "b_b[" << i << "] = " << b_b[i] << std::endl;
00351 for (int i=0 ; i<stages_ ; ++i)
00352 out << "b_c[" << i << "] = " << b_c[i] << std::endl;
00353 out << "t_ = " << t_ << std::endl;
00354 }
00355 return(out);
00356 }
00357
00358 template<class Scalar>
00359 bool ExplicitRKStepper<Scalar>::SetPoints(
00360 const std::vector<Scalar>& time_list
00361 ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& x_list
00362 ,const std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >& xdot_list)
00363 {
00364 return(false);
00365 }
00366
00367 template<class Scalar>
00368 bool ExplicitRKStepper<Scalar>::GetPoints(
00369 const std::vector<Scalar>& time_list
00370 ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* x_list
00371 ,std::vector<Teuchos::RefCountPtr<Thyra::VectorBase<Scalar> > >* xdot_list
00372 ,std::vector<ScalarMag>* accuracy_list) const
00373 {
00374 return(false);
00375 }
00376
00377 template<class Scalar>
00378 bool ExplicitRKStepper<Scalar>::SetRange(
00379 const Scalar& time_lower
00380 ,const Scalar& time_upper
00381 ,const InterpolationBuffer<Scalar>& IB)
00382 {
00383 return(false);
00384 }
00385
00386 template<class Scalar>
00387 bool ExplicitRKStepper<Scalar>::GetNodes(std::vector<Scalar>* time_list) const
00388 {
00389 return(false);
00390 }
00391
00392 template<class Scalar>
00393 bool ExplicitRKStepper<Scalar>::RemoveNodes(std::vector<Scalar>& time_list) const
00394 {
00395 return(false);
00396 }
00397
00398 template<class Scalar>
00399 int ExplicitRKStepper<Scalar>::GetOrder() const
00400 {
00401 return(4);
00402 }
00403
00404 }
00405
00406 #endif //Rythmos_ExplicitRK_STEPPER_H