29 #ifndef Rythmos_DATA_STORE_DEF_H
30 #define Rythmos_DATA_STORE_DEF_H
32 #include "Rythmos_DataStore_decl.hpp"
37 template<
class Scalar>
38 DataStore<Scalar>::DataStore()
43 template<
class Scalar>
44 DataStore<Scalar>::DataStore(
46 ,
const Teuchos::RCP<
const Thyra::VectorBase<Scalar> > &x_
47 ,
const Teuchos::RCP<
const Thyra::VectorBase<Scalar> > &xdot_
48 ,ScalarMag &accuracy_)
56 template<
class Scalar>
57 DataStore<Scalar>::DataStore(
58 const DataStore<Scalar>& ds_in
64 accuracy = ds_in.accuracy;
67 template<
class Scalar>
68 RCP<DataStore<Scalar> > DataStore<Scalar>::clone()
const
71 RCP<VectorBase<Scalar> > x_out;
72 if (!Teuchos::is_null(x)) {
75 RCP<VectorBase<Scalar> > xdot_out;
76 if (!Teuchos::is_null(xdot)) {
77 xdot_out = xdot->clone_v();
79 ScalarMag accuracy_out = accuracy;
80 RCP<DataStore<Scalar> > ds_out = Teuchos::rcp(
new DataStore<Scalar>(t_out,x_out,xdot_out,accuracy_out));
84 template<
class Scalar>
85 bool DataStore<Scalar>::operator< (
const DataStore<Scalar>& ds)
const
87 return( this->time < ds.time );
90 template<
class Scalar>
91 bool DataStore<Scalar>::operator<= (
const DataStore<Scalar>& ds)
const
93 return( this->time <= ds.time );
96 template<
class Scalar>
97 bool DataStore<Scalar>::operator< (
const Scalar& t)
const
99 return( this->time < t );
102 template<
class Scalar>
103 bool DataStore<Scalar>::operator<= (
const Scalar& t)
const
105 return( this->time <= t );
108 template<
class Scalar>
109 bool DataStore<Scalar>::operator> (
const DataStore<Scalar>& ds)
const
111 return( this->time > ds.time );
114 template<
class Scalar>
115 bool DataStore<Scalar>::operator>= (
const DataStore<Scalar>& ds)
const
117 return( this->time >= ds.time );
120 template<
class Scalar>
121 bool DataStore<Scalar>::operator> (
const Scalar& t)
const
123 return( this->time > t );
126 template<
class Scalar>
127 bool DataStore<Scalar>::operator>= (
const Scalar& t)
const
129 return( this->time >= t );
132 template<
class Scalar>
133 bool DataStore<Scalar>::operator== (
const DataStore<Scalar>& ds)
const
135 return( this->time == ds.time );
138 template<
class Scalar>
139 bool DataStore<Scalar>::operator== (
const Scalar& t)
const
141 return( this->time == t );
144 template<
class Scalar>
145 std::string DataStore<Scalar>::description()
const
147 std::string name =
"Rythmos::DataStore";
151 template<
class Scalar>
152 void DataStore<Scalar>::describe(
153 Teuchos::FancyOStream &out
154 ,
const Teuchos::EVerbosityLevel verbLevel
157 if (verbLevel == Teuchos::VERB_EXTREME) {
158 out << description() <<
"::describe:" << std::endl;
159 out <<
"time = " << time << std::endl;
160 out <<
"x = " << std::endl;
161 x->describe(out,verbLevel);
162 if (xdot != Teuchos::null) {
163 out <<
"xdot = " << std::endl;
164 xdot->describe(out,verbLevel);
166 out <<
"accuracy = " << accuracy << std::endl;
171 template<
class Scalar>
172 void dataStoreVectorToVector(
173 const typename DataStore<Scalar>::DataStoreVector_t &ds
174 ,Array<Scalar> *time_vec
175 ,Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > *x_vec
176 ,Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > *xdot_vec
177 ,Array<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType> *accuracy_vec)
186 accuracy_vec->clear();
188 for (
int i=0; i<N ; ++i) {
190 time_vec->push_back(ds[i].time);
192 x_vec->push_back(ds[i].x);
194 xdot_vec->push_back(ds[i].xdot);
196 accuracy_vec->push_back(ds[i].accuracy);
200 template<
class Scalar>
201 void vectorToDataStoreVector(
202 const Array<Scalar> &time_vec
203 ,
const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > &x_vec
204 ,
const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > &xdot_vec
205 ,
const Array<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
206 ,
typename DataStore<Scalar>::DataStoreVector_t *ds
209 int N = time_vec.size();
210 int Nx = x_vec.size();
211 int Nxdot = xdot_vec.size();
212 int Nacc = accuracy_vec.size();
213 if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
218 for (
int i=0; i<N ; ++i) {
219 Scalar time_temp = time_vec[i];
220 Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
221 Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
222 typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
223 DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
224 ds->push_back(ds_tmp);
228 template<
class Scalar>
229 void vectorToDataStoreList(
230 const Array<Scalar> &time_vec
231 ,
const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > &x_vec
232 ,
const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > &xdot_vec
233 ,
const Array<
typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
234 ,
typename DataStore<Scalar>::DataStoreList_t *ds)
236 int N = time_vec.size();
237 int Nx = x_vec.size();
238 int Nxdot = xdot_vec.size();
239 int Nacc = accuracy_vec.size();
240 if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
245 for (
int i=0; i<N ; ++i) {
246 Scalar time_temp = time_vec[i];
247 Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
248 Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
249 typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
250 DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
251 ds->push_back(ds_tmp);
255 template<
class Scalar>
256 void vectorToDataStoreList(
257 const Array<Scalar> &time_vec
258 ,
const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > &x_vec
259 ,
const Array<Teuchos::RCP<
const Thyra::VectorBase<Scalar> > > &xdot_vec
260 ,
typename DataStore<Scalar>::DataStoreList_t *ds)
262 typedef Teuchos::ScalarTraits<Scalar> ST;
263 Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> accuracy_vec;
264 int N = time_vec.size();
265 accuracy_vec.reserve(N);
266 for (
int i=0 ; i<N ; ++i) {
267 accuracy_vec.push_back(ST::zero());
269 vectorToDataStoreList(time_vec,x_vec,xdot_vec,accuracy_vec,ds);
278 #define RYTHMOS_DATA_STORE_INSTANT(SCALAR) \
280 template class DataStore< SCALAR >; \
282 template void dataStoreVectorToVector( \
283 const DataStore< SCALAR >::DataStoreVector_t &ds \
284 ,Array< SCALAR > *time_vec \
285 ,Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > *x_vec \
286 ,Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > *xdot_vec \
287 ,Array<Teuchos::ScalarTraits< SCALAR >::magnitudeType> *accuracy_vec \
290 template void vectorToDataStoreVector( \
291 const Array< SCALAR > &time_vec \
292 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &x_vec \
293 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &xdot_vec \
294 ,const Array<Teuchos::ScalarTraits< SCALAR >::magnitudeType> &accuracy_vec \
295 ,DataStore< SCALAR >::DataStoreVector_t *ds \
298 template void vectorToDataStoreList( \
299 const Array< SCALAR > &time_vec \
300 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &x_vec \
301 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &xdot_vec \
302 ,const Array<Teuchos::ScalarTraits< SCALAR >::magnitudeType> &accuracy_vec \
303 ,DataStore< SCALAR >::DataStoreList_t *ds \
306 template void vectorToDataStoreList( \
307 const Array< SCALAR > &time_vec \
308 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &x_vec \
309 ,const Array<Teuchos::RCP<const Thyra::VectorBase< SCALAR > > > &xdot_vec \
310 ,DataStore< SCALAR >::DataStoreList_t *ds \
315 #endif // Rythmos_DATA_STORE_DEF_H