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_INTERPOLATION_BUFFER_APPENDER_H
00030 #define Rythmos_INTERPOLATION_BUFFER_APPENDER_H
00031
00032 #include "Rythmos_InterpolationBufferBase.hpp"
00033 #include "Rythmos_Types.hpp"
00034
00035 #include "Thyra_VectorBase.hpp"
00036
00037 #include "Teuchos_Describable.hpp"
00038 #include "Teuchos_ParameterListAcceptor.hpp"
00039 #include "Teuchos_VerboseObject.hpp"
00040 #include "Teuchos_RCP.hpp"
00041 #include "Teuchos_implicit_cast.hpp"
00042 #include "Teuchos_Assert.hpp"
00043
00044
00045 namespace Rythmos {
00046
00047 template<class Scalar>
00048 class InterpolationBufferAppenderBase
00049 : virtual public Teuchos::Describable
00050 , virtual public Teuchos::ParameterListAcceptor
00051 , virtual public Teuchos::VerboseObject<InterpolationBufferAppenderBase<Scalar> >
00052 {
00053 public:
00054
00082 virtual void import(
00083 InterpolationBufferBase<Scalar>* IB_base,
00084 const InterpolationBufferBase<Scalar>& IB_in,
00085 const TimeRange<Scalar>& range
00086 ) =0;
00087 protected:
00088 void assertImportPreconditions(
00089 const InterpolationBufferBase<Scalar>& IB_base,
00090 const InterpolationBufferBase<Scalar>& IB_in,
00091 const TimeRange<Scalar>& range
00092 ) const;
00093 };
00094
00095 template<class Scalar>
00096 void InterpolationBufferAppenderBase<Scalar>::assertImportPreconditions(
00097 const InterpolationBufferBase<Scalar>& IB_base,
00098 const InterpolationBufferBase<Scalar>& IB_in,
00099 const TimeRange<Scalar>& range
00100 ) const
00101 {
00102 TEST_FOR_EXCEPTION((range.lower() != IB_base.getTimeRange().upper()) || (range.upper() != IB_base.getTimeRange().lower()),
00103 std::logic_error,
00104 "Error, import range is not an append nor a prepend of the base interpolation buffer.\n"
00105 );
00106 TEST_FOR_EXCEPTION(range.lower() < IB_in.getTimeRange().lower(),
00107 std::logic_error,
00108 "Error, import range's lower bound does not sit inside incoming interpolation buffer's time range.\n"
00109 );
00110 TEST_FOR_EXCEPTION(IB_in.getTimeRange().upper() < range.upper(),
00111 std::logic_error,
00112 "Error, import range's upper bound does not sit inside incoming interpolation buffer's time range.\n"
00113 );
00114 }
00115
00116
00117 template<class Scalar>
00118 class InterpolationBufferAppenderDefault : virtual public InterpolationBufferAppenderBase<Scalar>
00119 {
00120 public:
00121
00122 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00123
00127 void import(
00128 InterpolationBufferBase<Scalar>* IB_base,
00129 const InterpolationBufferBase<Scalar>& IB_in,
00130 const TimeRange<Scalar>& range
00131 );
00132
00134
00135 std::string description() const;
00136
00138 void describe(
00139 Teuchos::FancyOStream &out
00140 ,const Teuchos::EVerbosityLevel verbLevel
00141 ) const;
00142
00144
00145 void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
00146
00148 RCP<Teuchos::ParameterList> getParameterList();
00149
00151 RCP<Teuchos::ParameterList> unsetParameterList();
00152
00153 private:
00154 RCP<Teuchos::ParameterList> parameterList_;
00155
00156 };
00157
00158 template<class Scalar>
00159 void InterpolationBufferAppenderDefault<Scalar>::import(
00160 InterpolationBufferBase<Scalar>* IB_base,
00161 const InterpolationBufferBase<Scalar>& IB_in,
00162 const TimeRange<Scalar>& range
00163 )
00164 {
00165 #ifdef TEUCHOS_DEBUG
00166 InterpolationBufferAppenderBase<Scalar>::assertImportPreconditions(*IB_base,IB_in,range);
00167 #endif // TEUCHOS_DEBUG
00168
00169 Array<Scalar> time_vec;
00170 Array<RCP<const Thyra::VectorBase<Scalar> > > x_vec;
00171 Array<RCP<const Thyra::VectorBase<Scalar> > > xdot_vec;
00172 Array<ScalarMag> accuracy_vec;
00173
00174 Array<Scalar> time_vec_in;
00175 IB_in.getNodes(&time_vec_in);
00176
00177 selectPointsInTimeRange(&time_vec,time_vec_in,range);
00178
00179 IB_in.getPoints(time_vec, &x_vec, &xdot_vec, &accuracy_vec);
00180 IB_base->addPoints(time_vec, x_vec, xdot_vec);
00181 }
00182
00183
00184 template<class Scalar>
00185 std::string InterpolationBufferAppenderDefault<Scalar>::description() const
00186 {
00187 std::string name = "Rythmos::InterpolationBufferAppenderDefault";
00188 return(name);
00189 }
00190
00191 template<class Scalar>
00192 void InterpolationBufferAppenderDefault<Scalar>::describe(
00193 Teuchos::FancyOStream &out
00194 ,const Teuchos::EVerbosityLevel verbLevel
00195 ) const
00196 {
00197 if ( (Teuchos::as<int>(verbLevel) == Teuchos::as<int>(Teuchos::VERB_DEFAULT) ) ||
00198 (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_LOW) )
00199 ) {
00200 out << description() << "::describe" << std::endl;
00201 }
00202 }
00203
00204 template<class Scalar>
00205 void InterpolationBufferAppenderDefault<Scalar>::setParameterList(RCP<Teuchos::ParameterList> const& paramList)
00206 {
00207 TEST_FOR_EXCEPTION(paramList==Teuchos::null,std::logic_error,"Error, paramList == Teuchos::null!\n");
00208 parameterList_ = paramList;
00209 }
00210
00211 template<class Scalar>
00212 RCP<Teuchos::ParameterList> InterpolationBufferAppenderDefault<Scalar>::getParameterList()
00213 {
00214 return(parameterList_);
00215 }
00216
00217 template<class Scalar>
00218 RCP<Teuchos::ParameterList> InterpolationBufferAppenderDefault<Scalar>::unsetParameterList()
00219 {
00220 RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
00221 parameterList_ = Teuchos::null;
00222 return(temp_param_list);
00223 }
00224
00225 template<class Scalar>
00226 class InterpolationBufferAppenderSmart : virtual public InterpolationBufferAppenderBase<Scalar>
00227 {
00228 public:
00233 void import(
00234 InterpolationBufferBase<Scalar>* IB_base,
00235 const InterpolationBufferBase<Scalar>& IB_in,
00236 const TimeRange<Scalar>& range
00237 );
00238 };
00239
00240 template<class Scalar>
00241 void InterpolationBufferAppenderSmart<Scalar>::import(
00242 InterpolationBufferBase<Scalar>* IB_base,
00243 const InterpolationBufferBase<Scalar>& IB_in,
00244 const TimeRange<Scalar>& range
00245 )
00246 {
00247 #ifdef TEUCHOS_DEBUG
00248 InterpolationBufferAppenderBase<Scalar>::assertImportPreconditions(*IB_base,IB_in,range);
00249 #endif // TEUCHOS_DEBUG
00250 if (IB_base->getOrder() >= IB_in.getOrder()) {
00251
00252
00253
00254 InterpolationBufferAppenderDefault<Scalar> defaultAppender;
00255 defaultAppender.import(IB_base,IB_in,range);
00256 } else {
00257
00258
00259
00260 TEST_FOR_EXCEPTION(
00261 true,std::logic_error,
00262 "Error, the smart interpolation buffer appender is not implemented for importing interpolation buffers with higher order interpolation into interpolation buffers with a lower order of interpolation yet.\n"
00263 );
00264
00265
00266
00267 }
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 }
00415
00416
00417 #endif //Rythmos_INTERPOLATION_BUFFER_APPENDER_H