Rythmos_DataStore.hpp

00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //                           Rythmos Package
00005 //                 Copyright (2006) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 #ifndef Rythmos_DATA_STORE_H
00030 #define Rythmos_DATA_STORE_H
00031 
00032 #include "Thyra_VectorBase.hpp"
00033 #include "Teuchos_RCP.hpp"
00034 #include "Teuchos_Describable.hpp"
00035 
00036 namespace Rythmos {
00037 
00038 template<class Scalar>
00039 class DataStore : virtual public Teuchos::Describable
00040 {
00041 
00042   public:
00043 
00044     typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00045 
00047     ~DataStore() {};
00048 
00050     DataStore() {};
00051 
00053     DataStore(Scalar& time_
00054       ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& x_
00055       ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdot_
00056       ,ScalarMag& accuracy_);
00057 
00059     DataStore(const DataStore<Scalar>& ds_in);
00060 
00062     Scalar time;
00063 
00065     Teuchos::RCP<const Thyra::VectorBase<Scalar> > x;
00066 
00068     Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot;
00069 
00071     ScalarMag accuracy;
00072 
00074     bool operator< (const DataStore<Scalar>& ds) const;
00075 
00077     bool operator<= (const DataStore<Scalar>& ds) const;
00078 
00080     bool operator< (const Scalar& t) const;
00081 
00083     bool operator<= (const Scalar& t) const;
00084 
00086     bool operator> (const DataStore<Scalar>& ds) const;
00087 
00089     bool operator>= (const DataStore<Scalar>& ds) const;
00090 
00092     bool operator> (const Scalar& t) const;
00093 
00095     bool operator>= (const Scalar& t) const;
00096 
00098     bool operator== (const DataStore<Scalar>& ds) const;
00099 
00101     bool operator== (const Scalar& t) const;
00102 
00104     typedef Array<DataStore<Scalar> > DataStoreVector_t;
00105 
00107     typedef Array<const DataStore<Scalar> > constDataStoreVector_t;
00108 
00110     typedef std::list<DataStore<Scalar> > DataStoreList_t;
00111 
00113     typedef std::list<const DataStore<Scalar> > constDataStoreList_t;
00114 
00116 
00117     std::string description() const;
00118 
00121     void describe(
00122       Teuchos::FancyOStream       &out
00123       ,const Teuchos::EVerbosityLevel      verbLevel
00124       ) const;
00125 };
00126 
00127 
00128 // This is a helper function to convert a vector of DataStore objects to vectors of t,x,xdot,accuracy
00129 template<class Scalar>
00130 void dataStoreVectorToVector(
00131       const typename DataStore<Scalar>::DataStoreVector_t &ds
00132       ,Array<Scalar> *time_vec
00133       ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *x_vec
00134       ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *xdot_vec
00135       ,Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> *accuracy_vec);
00136 
00137 // This is a helper function to convert vectors of t,x,xdot,accuracy to a vector of DataStore objects
00138 template<class Scalar>
00139 void vectorToDataStoreVector(
00140       const Array<Scalar> &time_vec
00141       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00142       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00143       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00144       ,typename DataStore<Scalar>::DataStoreVector_t *ds);
00145 
00146 // This is a helper function to convert vectors of t,x,xdot,[accuracy] to a list of DataStore objects
00147 template<class Scalar>
00148 void vectorToDataStoreList(
00149       const Array<Scalar> &time_vec
00150       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00151       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00152       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00153       ,typename DataStore<Scalar>::DataStoreList_t *ds);
00154 
00155 template<class Scalar>
00156 void vectorToDataStoreList(
00157       const Array<Scalar> &time_vec
00158       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00159       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00160       ,typename DataStore<Scalar>::DataStoreList_t *ds);
00161 
00162 // DataStore definitions:
00163 template<class Scalar>
00164 DataStore<Scalar>::DataStore(
00165   Scalar &time_
00166   ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_
00167   ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &xdot_
00168   ,ScalarMag &accuracy_)
00169 {
00170   time = time_;
00171   x = x_;
00172   xdot = xdot_;
00173   accuracy = accuracy_;
00174 }
00175 
00176 template<class Scalar>
00177 DataStore<Scalar>::DataStore(
00178     const DataStore<Scalar>& ds_in
00179     )
00180 {
00181   time = ds_in.time;
00182   x = ds_in.x;
00183   xdot = ds_in.xdot;
00184   accuracy = ds_in.accuracy;
00185 }
00186 
00187 template<class Scalar>
00188 bool DataStore<Scalar>::operator< (const DataStore<Scalar>& ds) const
00189 { 
00190   return( this->time < ds.time ); 
00191 }
00192 
00193 template<class Scalar>
00194 bool DataStore<Scalar>::operator<= (const DataStore<Scalar>& ds) const
00195 { 
00196   return( this->time <= ds.time ); 
00197 }
00198 
00199 template<class Scalar>
00200 bool DataStore<Scalar>::operator< (const Scalar& t) const
00201 { 
00202   return( this->time < t ); 
00203 }
00204 
00205 template<class Scalar>
00206 bool DataStore<Scalar>::operator<= (const Scalar& t) const
00207 { 
00208   return( this->time <= t ); 
00209 }
00210 
00211 template<class Scalar>
00212 bool DataStore<Scalar>::operator> (const DataStore<Scalar>& ds) const
00213 { 
00214   return( this->time > ds.time ); 
00215 }
00216 
00217 template<class Scalar>
00218 bool DataStore<Scalar>::operator>= (const DataStore<Scalar>& ds) const
00219 { 
00220   return( this->time >= ds.time ); 
00221 }
00222 
00223 template<class Scalar>
00224 bool DataStore<Scalar>::operator> (const Scalar& t) const
00225 { 
00226   return( this->time > t ); 
00227 }
00228 
00229 template<class Scalar>
00230 bool DataStore<Scalar>::operator>= (const Scalar& t) const
00231 { 
00232   return( this->time >= t ); 
00233 }
00234 
00235 template<class Scalar>
00236 bool DataStore<Scalar>::operator== (const DataStore<Scalar>& ds) const
00237 { 
00238   return( this->time == ds.time ); 
00239 }
00240 
00241 template<class Scalar>
00242 bool DataStore<Scalar>::operator== (const Scalar& t) const
00243 { 
00244   return( this->time == t ); 
00245 }
00246 
00247 template<class Scalar>
00248 std::string DataStore<Scalar>::description() const
00249 {
00250   std::string name = "Rythmos::DataStore";
00251   return(name);
00252 }
00253 
00254 template<class Scalar>
00255 void DataStore<Scalar>::describe(
00256       Teuchos::FancyOStream                &out
00257       ,const Teuchos::EVerbosityLevel      verbLevel
00258       ) const
00259 {
00260   if (verbLevel == Teuchos::VERB_EXTREME) {
00261     out << description() << "::describe:" << std::endl;
00262     out << "time = " << time << std::endl;
00263     out << "x = " << std::endl;
00264     x->describe(out,verbLevel);
00265     if (xdot != Teuchos::null) {
00266       out << "xdot = " << std::endl;
00267       xdot->describe(out,verbLevel);
00268     }
00269     out << "accuracy = " << accuracy << std::endl;
00270   }
00271 }
00272 
00273 // DataStore Helper Function definitions:
00274 template<class Scalar>
00275 void dataStoreVectorToVector(
00276       const typename DataStore<Scalar>::DataStoreVector_t &ds
00277       ,Array<Scalar> *time_vec
00278       ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *x_vec
00279       ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *xdot_vec
00280       ,Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> *accuracy_vec)
00281 {
00282   if(time_vec)
00283     time_vec->clear();
00284   if(x_vec)
00285     x_vec->clear();
00286   if(xdot_vec)
00287     xdot_vec->clear();
00288   if(accuracy_vec)
00289     accuracy_vec->clear();
00290   int N = ds.size();
00291   for (int i=0; i<N ; ++i) {
00292     if(time_vec)
00293       time_vec->push_back(ds[i].time);
00294     if(x_vec)
00295       x_vec->push_back(ds[i].x);
00296     if(xdot_vec)
00297       xdot_vec->push_back(ds[i].xdot);
00298     if(accuracy_vec)
00299       accuracy_vec->push_back(ds[i].accuracy);
00300   }
00301 }
00302 
00303 template<class Scalar>
00304 void vectorToDataStoreVector(
00305       const Array<Scalar> &time_vec
00306       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00307       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00308       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00309       ,typename DataStore<Scalar>::DataStoreVector_t *ds
00310       ) 
00311 {
00312   int N = time_vec.size();
00313   int Nx = x_vec.size();
00314   int Nxdot = xdot_vec.size();
00315   int Nacc = accuracy_vec.size();
00316   if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
00317     ds = NULL;
00318     return;
00319   }
00320   ds->clear();
00321   for (int i=0; i<N ; ++i) {
00322     Scalar time_temp = time_vec[i];
00323     Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
00324     Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
00325     typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
00326     DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
00327     ds->push_back(ds_tmp);
00328   }
00329 }
00330 
00331 template<class Scalar>
00332 void vectorToDataStoreList(
00333       const Array<Scalar> &time_vec
00334       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00335       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00336       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00337       ,typename DataStore<Scalar>::DataStoreList_t *ds) 
00338 {
00339   int N = time_vec.size();
00340   int Nx = x_vec.size();
00341   int Nxdot = xdot_vec.size();
00342   int Nacc = accuracy_vec.size();
00343   if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
00344     ds = NULL;
00345     return;
00346   }
00347   ds->clear();
00348   for (int i=0; i<N ; ++i) {
00349     Scalar time_temp = time_vec[i];
00350     Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
00351     Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
00352     typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
00353     DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
00354     ds->push_back(ds_tmp);
00355   }
00356 }
00357 
00358 template<class Scalar>
00359 void vectorToDataStoreList(
00360       const Array<Scalar> &time_vec
00361       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00362       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00363       ,typename DataStore<Scalar>::DataStoreList_t *ds) 
00364 {
00365   typedef Teuchos::ScalarTraits<Scalar> ST;
00366   Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> accuracy_vec;
00367   int N = time_vec.size();
00368   accuracy_vec.reserve(N);
00369   for (int i=0 ; i<N ; ++i) {
00370     accuracy_vec.push_back(ST::zero());
00371   }
00372   vectorToDataStoreList(time_vec,x_vec,xdot_vec,accuracy_vec,ds);
00373 }
00374 
00375 
00376 } // namespace Rythmos
00377 
00378 #endif // Rythmos_DATA_STORE_H
00379 

Generated on Tue Oct 20 12:46:07 2009 for Rythmos - Transient Integration for Differential Equations by doxygen 1.4.7