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 "Rythmos_Types.hpp"
00033 #include "Thyra_VectorBase.hpp"
00034 #include "Teuchos_RCP.hpp"
00035 #include "Teuchos_Describable.hpp"
00036 
00037 namespace Rythmos {
00038 
00039 template<class Scalar>
00040 class DataStore : virtual public Teuchos::Describable
00041 {
00042 
00043   public:
00044 
00045     typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00046 
00048     ~DataStore() {};
00049 
00051     DataStore();
00052 
00054     DataStore(Scalar& time_
00055       ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& x_
00056       ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdot_
00057       ,ScalarMag& accuracy_);
00058 
00060     DataStore(const DataStore<Scalar>& ds_in);
00061 
00063     Scalar time;
00064 
00066     Teuchos::RCP<const Thyra::VectorBase<Scalar> > x;
00067 
00069     Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot;
00070 
00072     ScalarMag accuracy;
00073 
00075     bool operator< (const DataStore<Scalar>& ds) const;
00076 
00078     bool operator<= (const DataStore<Scalar>& ds) const;
00079 
00081     bool operator< (const Scalar& t) const;
00082 
00084     bool operator<= (const Scalar& t) const;
00085 
00087     bool operator> (const DataStore<Scalar>& ds) const;
00088 
00090     bool operator>= (const DataStore<Scalar>& ds) const;
00091 
00093     bool operator> (const Scalar& t) const;
00094 
00096     bool operator>= (const Scalar& t) const;
00097 
00099     bool operator== (const DataStore<Scalar>& ds) const;
00100 
00102     bool operator== (const Scalar& t) const;
00103 
00105     typedef Array<DataStore<Scalar> > DataStoreVector_t;
00106 
00108     typedef Array<const DataStore<Scalar> > constDataStoreVector_t;
00109 
00111     typedef std::list<DataStore<Scalar> > DataStoreList_t;
00112 
00114     typedef std::list<const DataStore<Scalar> > constDataStoreList_t;
00115 
00117 
00118     std::string description() const;
00119 
00122     void describe(
00123       Teuchos::FancyOStream       &out
00124       ,const Teuchos::EVerbosityLevel      verbLevel
00125       ) const;
00126 };
00127 
00128 
00129 // This is a helper function to convert a vector of DataStore objects to vectors of t,x,xdot,accuracy
00130 template<class Scalar>
00131 void dataStoreVectorToVector(
00132       const typename DataStore<Scalar>::DataStoreVector_t &ds
00133       ,Array<Scalar> *time_vec
00134       ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *x_vec
00135       ,Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > *xdot_vec
00136       ,Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> *accuracy_vec);
00137 
00138 // This is a helper function to convert vectors of t,x,xdot,accuracy to a vector of DataStore objects
00139 template<class Scalar>
00140 void vectorToDataStoreVector(
00141       const Array<Scalar> &time_vec
00142       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00143       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00144       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00145       ,typename DataStore<Scalar>::DataStoreVector_t *ds);
00146 
00147 // This is a helper function to convert vectors of t,x,xdot,[accuracy] to a list of DataStore objects
00148 template<class Scalar>
00149 void vectorToDataStoreList(
00150       const Array<Scalar> &time_vec
00151       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00152       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00153       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00154       ,typename DataStore<Scalar>::DataStoreList_t *ds);
00155 
00156 template<class Scalar>
00157 void vectorToDataStoreList(
00158       const Array<Scalar> &time_vec
00159       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00160       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00161       ,typename DataStore<Scalar>::DataStoreList_t *ds);
00162 
00163 // DataStore definitions:
00164 template<class Scalar>
00165 DataStore<Scalar>::DataStore()
00166   :time(-1),
00167    accuracy(-1)
00168 {}
00169 
00170 template<class Scalar>
00171 DataStore<Scalar>::DataStore(
00172   Scalar &time_
00173   ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &x_
00174   ,const Teuchos::RCP<const Thyra::VectorBase<Scalar> > &xdot_
00175   ,ScalarMag &accuracy_)
00176 {
00177   time = time_;
00178   x = x_;
00179   xdot = xdot_;
00180   accuracy = accuracy_;
00181 }
00182 
00183 template<class Scalar>
00184 DataStore<Scalar>::DataStore(
00185     const DataStore<Scalar>& ds_in
00186     )
00187 {
00188   time = ds_in.time;
00189   x = ds_in.x;
00190   xdot = ds_in.xdot;
00191   accuracy = ds_in.accuracy;
00192 }
00193 
00194 template<class Scalar>
00195 bool DataStore<Scalar>::operator< (const DataStore<Scalar>& ds) const
00196 { 
00197   return( this->time < ds.time ); 
00198 }
00199 
00200 template<class Scalar>
00201 bool DataStore<Scalar>::operator<= (const DataStore<Scalar>& ds) const
00202 { 
00203   return( this->time <= ds.time ); 
00204 }
00205 
00206 template<class Scalar>
00207 bool DataStore<Scalar>::operator< (const Scalar& t) const
00208 { 
00209   return( this->time < t ); 
00210 }
00211 
00212 template<class Scalar>
00213 bool DataStore<Scalar>::operator<= (const Scalar& t) const
00214 { 
00215   return( this->time <= t ); 
00216 }
00217 
00218 template<class Scalar>
00219 bool DataStore<Scalar>::operator> (const DataStore<Scalar>& ds) const
00220 { 
00221   return( this->time > ds.time ); 
00222 }
00223 
00224 template<class Scalar>
00225 bool DataStore<Scalar>::operator>= (const DataStore<Scalar>& ds) const
00226 { 
00227   return( this->time >= ds.time ); 
00228 }
00229 
00230 template<class Scalar>
00231 bool DataStore<Scalar>::operator> (const Scalar& t) const
00232 { 
00233   return( this->time > t ); 
00234 }
00235 
00236 template<class Scalar>
00237 bool DataStore<Scalar>::operator>= (const Scalar& t) const
00238 { 
00239   return( this->time >= t ); 
00240 }
00241 
00242 template<class Scalar>
00243 bool DataStore<Scalar>::operator== (const DataStore<Scalar>& ds) const
00244 { 
00245   return( this->time == ds.time ); 
00246 }
00247 
00248 template<class Scalar>
00249 bool DataStore<Scalar>::operator== (const Scalar& t) const
00250 { 
00251   return( this->time == t ); 
00252 }
00253 
00254 template<class Scalar>
00255 std::string DataStore<Scalar>::description() const
00256 {
00257   std::string name = "Rythmos::DataStore";
00258   return(name);
00259 }
00260 
00261 template<class Scalar>
00262 void DataStore<Scalar>::describe(
00263       Teuchos::FancyOStream                &out
00264       ,const Teuchos::EVerbosityLevel      verbLevel
00265       ) const
00266 {
00267   if (verbLevel == Teuchos::VERB_EXTREME) {
00268     out << description() << "::describe:" << std::endl;
00269     out << "time = " << time << std::endl;
00270     out << "x = " << std::endl;
00271     x->describe(out,verbLevel);
00272     if (xdot != Teuchos::null) {
00273       out << "xdot = " << std::endl;
00274       xdot->describe(out,verbLevel);
00275     }
00276     out << "accuracy = " << accuracy << std::endl;
00277   }
00278 }
00279 
00280 // DataStore Helper Function definitions:
00281 template<class Scalar>
00282 void dataStoreVectorToVector(
00283       const typename 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<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> *accuracy_vec)
00288 {
00289   if(time_vec)
00290     time_vec->clear();
00291   if(x_vec)
00292     x_vec->clear();
00293   if(xdot_vec)
00294     xdot_vec->clear();
00295   if(accuracy_vec)
00296     accuracy_vec->clear();
00297   int N = ds.size();
00298   for (int i=0; i<N ; ++i) {
00299     if(time_vec)
00300       time_vec->push_back(ds[i].time);
00301     if(x_vec)
00302       x_vec->push_back(ds[i].x);
00303     if(xdot_vec)
00304       xdot_vec->push_back(ds[i].xdot);
00305     if(accuracy_vec)
00306       accuracy_vec->push_back(ds[i].accuracy);
00307   }
00308 }
00309 
00310 template<class Scalar>
00311 void vectorToDataStoreVector(
00312       const Array<Scalar> &time_vec
00313       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00314       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00315       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00316       ,typename DataStore<Scalar>::DataStoreVector_t *ds
00317       ) 
00318 {
00319   int N = time_vec.size();
00320   int Nx = x_vec.size();
00321   int Nxdot = xdot_vec.size();
00322   int Nacc = accuracy_vec.size();
00323   if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
00324     ds = NULL;
00325     return;
00326   }
00327   ds->clear();
00328   for (int i=0; i<N ; ++i) {
00329     Scalar time_temp = time_vec[i];
00330     Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
00331     Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
00332     typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
00333     DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
00334     ds->push_back(ds_tmp);
00335   }
00336 }
00337 
00338 template<class Scalar>
00339 void vectorToDataStoreList(
00340       const Array<Scalar> &time_vec
00341       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00342       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00343       ,const Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> &accuracy_vec
00344       ,typename DataStore<Scalar>::DataStoreList_t *ds) 
00345 {
00346   int N = time_vec.size();
00347   int Nx = x_vec.size();
00348   int Nxdot = xdot_vec.size();
00349   int Nacc = accuracy_vec.size();
00350   if ( (N != Nx) || (N != Nxdot) || (N != Nacc) ) {
00351     ds = NULL;
00352     return;
00353   }
00354   ds->clear();
00355   for (int i=0; i<N ; ++i) {
00356     Scalar time_temp = time_vec[i];
00357     Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_temp = x_vec[i];
00358     Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_temp = xdot_vec[i];
00359     typename Teuchos::ScalarTraits<Scalar>::magnitudeType accuracy_temp = accuracy_vec[i];
00360     DataStore<Scalar> ds_tmp(time_temp,x_temp,xdot_temp,accuracy_temp);
00361     ds->push_back(ds_tmp);
00362   }
00363 }
00364 
00365 template<class Scalar>
00366 void vectorToDataStoreList(
00367       const Array<Scalar> &time_vec
00368       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &x_vec
00369       ,const Array<Teuchos::RCP<const Thyra::VectorBase<Scalar> > > &xdot_vec
00370       ,typename DataStore<Scalar>::DataStoreList_t *ds) 
00371 {
00372   typedef Teuchos::ScalarTraits<Scalar> ST;
00373   Array<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> accuracy_vec;
00374   int N = time_vec.size();
00375   accuracy_vec.reserve(N);
00376   for (int i=0 ; i<N ; ++i) {
00377     accuracy_vec.push_back(ST::zero());
00378   }
00379   vectorToDataStoreList(time_vec,x_vec,xdot_vec,accuracy_vec,ds);
00380 }
00381 
00382 
00383 } // namespace Rythmos
00384 
00385 #endif // Rythmos_DATA_STORE_H
00386 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends

Generated on Tue Oct 20 10:24:09 2009 for Rythmos - Transient Integration for Differential Equations by  doxygen 1.6.1