29 #ifndef Rythmos_LINEAR_INTERPOLATOR_DEF_H
30 #define Rythmos_LINEAR_INTERPOLATOR_DEF_H
32 #include "Rythmos_LinearInterpolator_decl.hpp"
33 #include "Rythmos_InterpolatorBaseHelpers.hpp"
34 #include "Thyra_VectorStdOps.hpp"
35 #include "Thyra_VectorSpaceBase.hpp"
36 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
43 template<
class Scalar>
44 RCP<LinearInterpolator<Scalar> > linearInterpolator()
46 RCP<LinearInterpolator<Scalar> > li = rcp(
new LinearInterpolator<Scalar>() );
50 template<
class Scalar>
53 nodes_ = Teuchos::null;
54 parameterList_ = Teuchos::null;
58 template<
class Scalar>
65 template<
class Scalar>
66 RCP<InterpolatorBase<Scalar> >
69 RCP<LinearInterpolator<Scalar> >
71 if (!is_null(parameterList_))
72 interpolator->parameterList_ = parameterList(*parameterList_);
76 template<
class Scalar>
78 const RCP<
const typename DataStore<Scalar>::DataStoreVector_t> & nodes
85 template<
class Scalar>
87 const Array<Scalar> &t_values,
88 typename DataStore<Scalar>::DataStoreVector_t *data_out
93 typedef Teuchos::ScalarTraits<Scalar> ST;
95 #ifdef HAVE_RYTHMOS_DEBUG
96 assertBaseInterpolatePreconditions(*nodes_,t_values,data_out);
97 #endif // HAVE_RYTHMOS_DEBUG
100 const RCP<FancyOStream> out = this->getOStream();
101 const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
102 Teuchos::OSTab ostab(out,1,
"LI::interpolator");
103 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
104 *out <<
"nodes_:" << std::endl;
105 for (Teuchos::Ordinal i=0 ; i<(*nodes_).size() ; ++i) {
106 *out <<
"nodes_[" << i <<
"] = " << std::endl;
107 (*nodes_)[i].describe(*out,Teuchos::VERB_EXTREME);
109 *out <<
"t_values = " << std::endl;
110 for (Teuchos::Ordinal i=0 ; i<t_values.size() ; ++i) {
111 *out <<
"t_values[" << i <<
"] = " << t_values[i] << std::endl;
118 if (t_values.size() == 0) {
119 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
120 *out <<
"Returning because no time points were requested" << std::endl;
125 if ((*nodes_).size() == 1) {
128 DataStore<Scalar> DS((*nodes_)[0]);
129 data_out->push_back(DS);
130 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
131 *out <<
"Only a single node is in the buffer, so preconditions assert that this must be the point requested" << std::endl;
135 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
136 *out <<
"More than two nodes, looping through the intervals looking for points to interpolate" << std::endl;
143 for (
int i=0 ; i < as<int>((*nodes_).size())-1; ++i) {
144 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
145 *out <<
"Looking for interval containing: t_values["<<n<<
"] = " << t_values[n] << std::endl;
147 const Scalar& ti = (*nodes_)[i].time;
148 const Scalar& tip1 = (*nodes_)[i+1].time;
149 const Scalar h = tip1-ti;
153 while ( range_i.
isInRange(t_values[n]) ) {
155 if (compareTimeValues(t_values[n],ti)==0) {
156 DataStore<Scalar> DS((*nodes_)[i]);
157 data_out->push_back(DS);
158 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
159 *out <<
"Found an exact node match (on left), shallow copying." << std::endl;
160 *out <<
"Found t_values["<<n<<
"] = " << t_values[n] <<
" on boundary of interval ["<<ti<<
","<<tip1<<
"]" << std::endl;
163 else if (compareTimeValues(t_values[n],tip1)==0) {
164 DataStore<Scalar> DS((*nodes_)[i+1]);
165 data_out->push_back(DS);
166 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
167 *out <<
"Found an exact node match (on right), shallow copying." << std::endl;
168 *out <<
"Found t_values["<<n<<
"] = " << t_values[n] <<
" on boundary of interval ["<<ti<<
","<<tip1<<
"]" << std::endl;
172 if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH) ) {
173 *out <<
"Interpolating a point (creating a new vector)..." << std::endl;
174 *out <<
"Found t_values["<<n<<
"] = " << t_values[n] <<
" in interior of interval ["<<ti<<
","<<tip1<<
"]" << std::endl;
185 DataStore<Scalar> DS;
186 const Scalar& t = t_values[n];
189 RCP<const Thyra::VectorBase<Scalar> > xi = (*nodes_)[i].x;
190 RCP<const Thyra::VectorBase<Scalar> > xip1 = (*nodes_)[i+1].x;
191 RCP<const Thyra::VectorBase<Scalar> > xdoti = (*nodes_)[i].xdot;
192 RCP<const Thyra::VectorBase<Scalar> > xdotip1 = (*nodes_)[i+1].xdot;
194 const Scalar dt = t-ti;
195 const Scalar dt_over_h = dt / h;
196 const Scalar one_minus_dt_over_h = ST::one() - dt_over_h;
198 RCP<Thyra::VectorBase<Scalar> > x;
199 if (!is_null(xi) && !is_null(xip1)) {
200 x = createMember(xi->space());
201 Thyra::V_StVpStV(x.ptr(),dt_over_h,*xip1,one_minus_dt_over_h,*xi);
205 RCP<Thyra::VectorBase<Scalar> > xdot;
206 if (!is_null(xdoti) && !is_null(xdotip1)) {
207 xdot = createMember(xdoti->space());
208 Thyra::V_StVpStV(xdot.ptr(),dt_over_h,*xdotip1,one_minus_dt_over_h,*xdoti);
216 data_out->push_back(DS);
220 if (n == as<int>(t_values.size())) {
231 template<
class Scalar>
238 template<
class Scalar>
241 std::string name =
"Rythmos::LinearInterpolator";
246 template<
class Scalar>
249 const Teuchos::EVerbosityLevel verbLevel
253 if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
254 (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) )
257 out << description() <<
"::describe" << std::endl;
259 else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW))
261 else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_MEDIUM))
263 else if (as<int>(verbLevel) >= as<int>(Teuchos::VERB_HIGH))
268 template <
class Scalar>
270 RCP<ParameterList>
const& paramList
273 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
274 paramList->validateParametersAndSetDefaults(*this->getValidParameters());
275 parameterList_ = paramList;
276 Teuchos::readVerboseObjectSublist(&*parameterList_,
this);
280 template <
class Scalar>
284 return(parameterList_);
288 template <
class Scalar>
292 RCP<ParameterList> temp_param_list;
293 std::swap( temp_param_list, parameterList_ );
294 return(temp_param_list);
297 template<
class Scalar>
300 static RCP<Teuchos::ParameterList> validPL;
301 if (is_null(validPL)) {
302 RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
303 Teuchos::setupVerboseObjectSublist(&*pl);
315 #define RYTHMOS_LINEAR_INTERPOLATOR_INSTANT(SCALAR) \
317 template class LinearInterpolator< SCALAR >; \
319 template RCP<LinearInterpolator< SCALAR > > linearInterpolator();
324 #endif // Rythmos_LINEAR_INTERPOLATOR_DEF_H
void setParameterList(RCP< ParameterList > const ¶mList)
std::string description() const
virtual bool isInRange(const TimeType &t) const
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< ParameterList > getNonconstParameterList()
RCP< InterpolatorBase< Scalar > > cloneInterpolator() const
RCP< ParameterList > unsetParameterList()
Concrete implemenation of InterpolatorBase just just does simple linear interploation.
void interpolate(const Array< Scalar > &t_values, typename DataStore< Scalar >::DataStoreVector_t *data_out) const
void describe(FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void setNodes(const RCP< const typename DataStore< Scalar >::DataStoreVector_t > &nodes)
bool supportsCloning() const