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_DATA_STORE_DEF_H
00030 #define Rythmos_DATA_STORE_DEF_H
00031
00032 #include "Rythmos_DataStore_decl.hpp"
00033
00034 namespace Rythmos {
00035
00036
00037 template<class Scalar>
00038 DataStore<Scalar>::DataStore()
00039 :time(-1),
00040 accuracy(-1)
00041 {}
00042
00043 template<class Scalar>
00044 DataStore<Scalar>::DataStore(
00045 Scalar &time_
00046 ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_
00047 ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &xdot_
00048 ,ScalarMag &accuracy_)
00049 {
00050 time = time_;
00051 x = x_;
00052 xdot = xdot_;
00053 accuracy = accuracy_;
00054 }
00055
00056 template<class Scalar>
00057 DataStore<Scalar>::DataStore(
00058 const DataStore<Scalar>& ds_in
00059 )
00060 {
00061 time = ds_in.time;
00062 x = ds_in.x;
00063 xdot = ds_in.xdot;
00064 accuracy = ds_in.accuracy;
00065 }
00066
00067 template<class Scalar>
00068 RCP<DataStore<Scalar> > DataStore<Scalar>::clone() const
00069 {
00070 Scalar t_out = time;
00071 RCP<VectorBase<Scalar> > x_out;
00072 if (!Teuchos::is_null(x)) {
00073 x_out = x->clone_v();
00074 }
00075 RCP<VectorBase<Scalar> > xdot_out;
00076 if (!Teuchos::is_null(xdot)) {
00077 xdot_out = xdot->clone_v();
00078 }
00079 ScalarMag accuracy_out = accuracy;
00080 RCP<DataStore<Scalar> > ds_out = Teuchos::rcp(new DataStore<Scalar>(t_out,x_out,xdot_out,accuracy_out));
00081 return ds_out;
00082 }
00083
00084 template<class Scalar>
00085 bool DataStore<Scalar>::operator< (const DataStore<Scalar>& ds) const
00086 {
00087 return( this->time < ds.time );
00088 }
00089
00090 template<class Scalar>
00091 bool DataStore<Scalar>::operator<= (const DataStore<Scalar>& ds) const
00092 {
00093 return( this->time <= ds.time );
00094 }
00095
00096 template<class Scalar>
00097 bool DataStore<Scalar>::operator< (const Scalar& t) const
00098 {
00099 return( this->time < t );
00100 }
00101
00102 template<class Scalar>
00103 bool DataStore<Scalar>::operator<= (const Scalar& t) const
00104 {
00105 return( this->time <= t );
00106 }
00107
00108 template<class Scalar>
00109 bool DataStore<Scalar>::operator> (const DataStore<Scalar>& ds) const
00110 {
00111 return( this->time > ds.time );
00112 }
00113
00114 template<class Scalar>
00115 bool DataStore<Scalar>::operator>= (const DataStore<Scalar>& ds) const
00116 {
00117 return( this->time >= ds.time );
00118 }
00119
00120 template<class Scalar>
00121 bool DataStore<Scalar>::operator> (const Scalar& t) const
00122 {
00123 return( this->time > t );
00124 }
00125
00126 template<class Scalar>
00127 bool DataStore<Scalar>::operator>= (const Scalar& t) const
00128 {
00129 return( this->time >= t );
00130 }
00131
00132 template<class Scalar>
00133 bool DataStore<Scalar>::operator== (const DataStore<Scalar>& ds) const
00134 {
00135 return( this->time == ds.time );
00136 }
00137
00138 template<class Scalar>
00139 bool DataStore<Scalar>::operator== (const Scalar& t) const
00140 {
00141 return( this->time == t );
00142 }
00143
00144 template<class Scalar>
00145 std::string DataStore<Scalar>::description() const
00146 {
00147 std::string name = "Rythmos::DataStore";
00148 return(name);
00149 }
00150
00151 template<class Scalar>
00152 void DataStore<Scalar>::describe(
00153 Teuchos::FancyOStream &out
00154 ,const Teuchos::EVerbosityLevel verbLevel
00155 ) const
00156 {
00157 if (verbLevel == Teuchos::VERB_EXTREME) {
00158 out << description() << "::describe:" << std::endl;
00159 out << "time = " << time << std::endl;
00160 out << "x = " << std::endl;
00161 x->describe(out,verbLevel);
00162 if (xdot != Teuchos::null) {
00163 out << "xdot = " << std::endl;
00164 xdot->describe(out,verbLevel);
00165 }
00166 out << "accuracy = " << accuracy << std::endl;
00167 }
00168 }
00169
00170
00171 template<class Scalar>
00172 void dataStoreVectorToVector(
00173 const typename DataStore<Scalar>::DataStoreVector_t &ds
00174 ,Array<Scalar> *time_vec
00175 ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *x_vec
00176 ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *xdot_vec
00177 ,Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> *accuracy_vec)
00178 {
00179 if(time_vec)
00180 time_vec->clear();
00181 if(x_vec)
00182 x_vec->clear();
00183 if(xdot_vec)
00184 xdot_vec->clear();
00185 if(accuracy_vec)
00186 accuracy_vec->clear();
00187 int N = ds.size();
00188 for (int i=0; i<N ; ++i) {
00189 if(time_vec)
00190 time_vec->push_back(ds[i].time);
00191 if(x_vec)
00192 x_vec->push_back(ds[i].x);
00193 if(xdot_vec)
00194 xdot_vec->push_back(ds[i].xdot);
00195 if(accuracy_vec)
00196 accuracy_vec->push_back(ds[i].accuracy);
00197 }
00198 }
00199
00200 template<class Scalar>
00201 void vectorToDataStoreVector(
00202 const Array<Scalar> &time_vec
00203 ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00204 ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00205 ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00206 ,typename DataStore<Scalar>::DataStoreVector_t *ds
00207 )
00208 {
00209 int N = time_vec.size();
00210 int Nx = x_vec.size();
00211 int Nxdot = xdot_vec.size();
00212 int Nacc = accuracy_vec.size();
00213 if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
00214 ds = NULL;
00215 return;
00216 }
00217 ds->clear();
00218 for (int i=0; i<N ; ++i) {
00219 Scalar time_temp = time_vec[i];
00220 Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
00221 Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
00222 typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
00223 DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
00224 ds->push_back(ds_tmp);
00225 }
00226 }
00227
00228 template<class Scalar>
00229 void vectorToDataStoreList(
00230 const Array<Scalar> &time_vec
00231 ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00232 ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00233 ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00234 ,typename DataStore<Scalar>::DataStoreList_t *ds)
00235 {
00236 int N = time_vec.size();
00237 int Nx = x_vec.size();
00238 int Nxdot = xdot_vec.size();
00239 int Nacc = accuracy_vec.size();
00240 if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
00241 ds = NULL;
00242 return;
00243 }
00244 ds->clear();
00245 for (int i=0; i<N ; ++i) {
00246 Scalar time_temp = time_vec[i];
00247 Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
00248 Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
00249 typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
00250 DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
00251 ds->push_back(ds_tmp);
00252 }
00253 }
00254
00255 template<class Scalar>
00256 void vectorToDataStoreList(
00257 const Array<Scalar> &time_vec
00258 ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00259 ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00260 ,typename DataStore<Scalar>::DataStoreList_t *ds)
00261 {
00262 typedef Teuchos::ScalarTraits<Scalar> ST;
00263 Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> accuracy_vec;
00264 int N = time_vec.size();
00265 accuracy_vec.reserve(N);
00266 for (int i=0 ; i<N ; ++i) {
00267 accuracy_vec.push_back(ST::zero());
00268 }
00269 vectorToDataStoreList(time_vec,x_vec,xdot_vec,accuracy_vec,ds);
00270 }
00271
00272
00273
00274
00275
00276
00277
00278 #define RYTHMOS_DATA_STORE_INSTANT(SCALAR) \
00279 \
00280 template class DataStore< SCALAR >; \
00281 \
00282 template void dataStoreVectorToVector( \
00283 const DataStore< SCALAR >::DataStoreVector_t &ds \
00284 ,Array< SCALAR > *time_vec \
00285 ,Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > *x_vec \
00286 ,Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > *xdot_vec \
00287 ,Array<Teuchos::ScalarTraits< SCALAR >::magnitudeType> *accuracy_vec \
00288 ); \
00289 \
00290 template void vectorToDataStoreVector( \
00291 const Array< SCALAR > &time_vec \
00292 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &x_vec \
00293 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &xdot_vec \
00294 ,const Array<Teuchos::ScalarTraits< SCALAR >::magnitudeType> &accuracy_vec \
00295 ,DataStore< SCALAR >::DataStoreVector_t *ds \
00296 ); \
00297 \
00298 template void vectorToDataStoreList( \
00299 const Array< SCALAR > &time_vec \
00300 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &x_vec \
00301 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &xdot_vec \
00302 ,const Array<Teuchos::ScalarTraits< SCALAR >::magnitudeType> &accuracy_vec \
00303 ,DataStore< SCALAR >::DataStoreList_t *ds \
00304 ); \
00305 \
00306 template void vectorToDataStoreList( \
00307 const Array< SCALAR > &time_vec \
00308 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &x_vec \
00309 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &xdot_vec \
00310 ,DataStore< SCALAR >::DataStoreList_t *ds \
00311 );
00312
00313 }
00314
00315 #endif // Rythmos_DATA_STORE_DEF_H
00316