Rythmos_InterpolatorBase.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_INTERPOLATOR_BASE_H
00030 #define Rythmos_INTERPOLATOR_BASE_H
00031 
00032 #include "Rythmos_DataStore.hpp"
00033 #include "Rythmos_InterpolationBufferHelpers.hpp"
00034 
00035 
00036 namespace Rythmos {
00037 
00038 
00043 template<class Scalar> 
00044 class InterpolatorBase
00045   : virtual public Teuchos::Describable
00046   , virtual public Teuchos::ParameterListAcceptor
00047   , virtual public Teuchos::VerboseObject<InterpolatorBase<Scalar> >
00048 {
00049 public:
00050 
00058   virtual bool supportsCloning() const;
00059 
00072   virtual Teuchos::RCP<InterpolatorBase<Scalar> > cloneInterpolator() const;
00073 
00099   virtual void interpolate(
00100     const typename DataStore<Scalar>::DataStoreVector_t &data_in,
00101     const Array<Scalar> &t_values,
00102     typename DataStore<Scalar>::DataStoreVector_t *data_out
00103     ) const =0;
00104 
00109   virtual int order() const =0;
00110 
00111 };
00112 
00113 
00115 template<class Scalar>
00116 void assertBaseInterpolatePreconditions(
00117   const typename DataStore<Scalar>::DataStoreVector_t &data_in,
00118   const Array<Scalar> &t_values,
00119   typename DataStore<Scalar>::DataStoreVector_t *data_out
00120   );
00121 
00122 
00123 // ///////////////////////////////
00124 // Implementations
00125 
00126 
00127 template<class Scalar>
00128 bool InterpolatorBase<Scalar>::supportsCloning() const
00129 {
00130   return false;
00131 }
00132 
00133 
00134 template<class Scalar>
00135 Teuchos::RCP<InterpolatorBase<Scalar> >
00136 InterpolatorBase<Scalar>::cloneInterpolator() const
00137 {
00138   return Teuchos::null;
00139 }
00140 
00141 
00142 } // namespace Rythmos
00143 
00144 
00145 template<class Scalar>
00146 void Rythmos::assertBaseInterpolatePreconditions(
00147   const typename DataStore<Scalar>::DataStoreVector_t &data_in,
00148   const Array<Scalar> &t_values,
00149   typename DataStore<Scalar>::DataStoreVector_t *data_out
00150   )
00151 {
00152   TEST_FOR_EXCEPTION(
00153       data_in.size()==0, std::logic_error,
00154       "Error, data_in.size() == 0!\n"
00155       );
00156   Array<Scalar> time_vec;
00157   dataStoreVectorToVector<Scalar>(data_in, &time_vec, 0, 0, 0);
00158   assertTimePointsAreSorted<Scalar>(time_vec);
00159   assertTimePointsAreSorted<Scalar>(t_values);
00160   if (data_in.size() == 1) {
00161     TEST_FOR_EXCEPTION(
00162       t_values.size()>1, std::logic_error,
00163       "Error, data_in.size() == 1, but t_values.size() > 1!\n"
00164       );
00165     TEST_FOR_EXCEPTION(
00166       t_values[0]!=data_in[0].time, std::logic_error,
00167       "Error, data_in.size) == 1, but t_values[0] = " << 
00168       t_values[0] << " != " << data_in[0].time << " = data_in[0].time!\n"
00169       );
00170   }
00171   TimeRange<Scalar> range(data_in.front().time,data_in.back().time);
00172   for (int i=0; i<Teuchos::as<int>(t_values.size()) ; ++i) {
00173     TEST_FOR_EXCEPTION(
00174       !range.isInRange(t_values[i]), std::logic_error,
00175       "Error, t_values[" << i << "] = " << t_values[i] << 
00176       " is not in range of data_in = " << range << "!\n"
00177       );
00178   }
00179   TEST_FOR_EXCEPTION(
00180     data_out == 0, std::logic_error,
00181     "Error, data_out = NULL!\n"
00182     );
00183   for (int i=0; i<Teuchos::as<int>(data_in.size()) ; ++i) {
00184     TEST_FOR_EXCEPTION(
00185       data_in[i].x == Teuchos::null, std::logic_error,
00186       "Error, data_in[" << i << "].x == Teuchos::null.\n"
00187       );
00188   }
00189 }
00190 
00191 // 2007/9/16: rabartl: ToDo: Move the above function to a new file
00192 // Rythmos_InterpolatorBaseHelpers.hpp.
00193 
00194 
00195 #endif //Rythmos_INTERPOLATOR_BASE_H

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