29 #ifndef Rythmos_HERMITE_INTERPOLATOR_DEF_H
30 #define Rythmos_HERMITE_INTERPOLATOR_DEF_H
32 #include "Rythmos_HermiteInterpolator_decl.hpp"
33 #include "Rythmos_InterpolatorBaseHelpers.hpp"
34 #include "Thyra_VectorStdOps.hpp"
35 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
39 template<
class Scalar>
42 nodes_ = Teuchos::null;
43 parameterList_ = Teuchos::null;
46 template<
class Scalar>
48 const RCP<
const typename DataStore<Scalar>::DataStoreVector_t> & nodes
54 template<
class Scalar>
56 const Array<Scalar> &t_values
57 ,
typename DataStore<Scalar>::DataStoreVector_t *data_out )
const
62 typedef Teuchos::ScalarTraits<Scalar> ST;
63 #ifdef HAVE_RYTHMOS_DEBUG
64 assertInterpolatePreconditions((*nodes_),t_values,data_out);
65 #endif // HAVE_RYTHMOS_DEBUG
66 RCP<Teuchos::FancyOStream> out = this->getOStream();
67 Teuchos::OSTab ostab(out,1,
"HI::interpolator");
68 if ( Teuchos::as<int>(this->getVerbLevel()) >= Teuchos::as<int>(Teuchos::VERB_HIGH) ) {
69 *out <<
"(*nodes_):" << std::endl;
70 for (Teuchos::Ordinal i=0 ; i<(*nodes_).size() ; ++i) {
71 *out <<
"(*nodes_)[" << i <<
"] = " << std::endl;
72 (*nodes_)[i].describe(*out,Teuchos::VERB_EXTREME);
74 *out <<
"t_values = " << std::endl;
75 for (Teuchos::Ordinal i=0 ; i<t_values.size() ; ++i) {
76 *out <<
"t_values[" << i <<
"] = " << t_values[i] << std::endl;
78 for (Teuchos::Ordinal i=0; i<data_out->size() ; ++i) {
79 *out <<
"data_out[" << i <<
"] = " << std::endl;
80 (*data_out)[i].describe(*out,Teuchos::VERB_EXTREME);
84 if (t_values.size() == 0) {
88 if ((*nodes_).size() == 1) {
91 DataStore<Scalar> DS((*nodes_)[0]);
92 data_out->push_back(DS);
96 for (
int i=0 ; i<Teuchos::as<int>((*nodes_).size())-1 ; ++i) {
97 const Scalar& t0 = (*nodes_)[i].time;
98 const Scalar& t1 = (*nodes_)[i+1].time;
99 while ((t0 <= t_values[n]) && (t_values[n] <= t1)) {
100 const Scalar& t = t_values[n];
103 DataStore<Scalar> DS((*nodes_)[i]);
104 data_out->push_back(DS);
105 }
else if (t == t1) {
106 DataStore<Scalar> DS((*nodes_)[i+1]);
107 data_out->push_back(DS);
109 RCP<const Thyra::VectorBase<Scalar> > x0 = (*nodes_)[i ].x;
110 RCP<const Thyra::VectorBase<Scalar> > x1 = (*nodes_)[i+1].x;
111 RCP<const Thyra::VectorBase<Scalar> > xdot0 = (*nodes_)[i ].xdot;
112 RCP<const Thyra::VectorBase<Scalar> > xdot1 = (*nodes_)[i+1].xdot;
115 RCP<Thyra::VectorBase<Scalar> > tmp_vec = x0->clone_v();
116 RCP<Thyra::VectorBase<Scalar> > xdot_temp = x1->clone_v();
119 Scalar t_t0 = t - t0;
120 Scalar t_t1 = t - t1;
124 Thyra::Vt_S(xdot_temp.ptr(),Scalar(ST::one()/dt));
125 Thyra::Vp_StV(xdot_temp.ptr(),Scalar(-ST::one()/dt),*x0);
128 DataStore<Scalar> DS;
133 RCP<Thyra::VectorBase<Scalar> > x_vec = x0->clone_v();
134 Thyra::Vp_StV(x_vec.ptr(),t_t0,*xdot0);
135 tmp_t = t_t0*t_t0/dt;
136 Thyra::V_StVpStV(tmp_vec.ptr(),tmp_t,*xdot_temp,Scalar(-ST::one()*tmp_t),*xdot0);
137 Thyra::Vp_V(x_vec.ptr(),*tmp_vec);
138 tmp_t = t_t0*t_t0*t_t1/dt2;
139 Thyra::V_StVpStV(tmp_vec.ptr(),tmp_t,*xdot1,Scalar(-2*tmp_t),*xdot_temp);
140 Thyra::Vp_StV(tmp_vec.ptr(),tmp_t,*xdot0);
141 Thyra::Vp_V(x_vec.ptr(),*tmp_vec);
146 RCP<Thyra::VectorBase<Scalar> > xdot_vec = xdot0->clone_v();
148 Thyra::Vp_StV(xdot_vec.ptr(),Scalar(2*tmp_t),*xdot_temp);
149 Thyra::Vp_StV(xdot_vec.ptr(),Scalar(-2*tmp_t),*xdot0);
150 tmp_t = Scalar((2*t_t0*t_t1+t_t0*t_t0)/dt2);
151 Thyra::V_StVpStV(tmp_vec.ptr(),tmp_t,*xdot1,Scalar(-2*tmp_t),*xdot_temp);
152 Thyra::Vp_StV(tmp_vec.ptr(),tmp_t,*xdot0);
153 Thyra::Vp_V(xdot_vec.ptr(),*tmp_vec);
158 DS.accuracy = (t_t0)*(t_t0)*(t_t1)*(t_t1);
161 data_out->push_back(DS);
164 if (n == Teuchos::as<int>(t_values.size())) {
173 template<
class Scalar>
174 RCP<HermiteInterpolator<Scalar> > hermiteInterpolator()
180 template<
class Scalar>
186 template<
class Scalar>
189 std::string name =
"Rythmos::HermiteInterpolator";
193 template<
class Scalar>
195 Teuchos::FancyOStream &out
196 ,
const Teuchos::EVerbosityLevel verbLevel
199 if ( (Teuchos::as<int>(verbLevel) == Teuchos::as<int>(Teuchos::VERB_DEFAULT) ) ||
200 (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_LOW) )
203 out << description() <<
"::describe" << std::endl;
205 else if (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_LOW))
207 else if (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_MEDIUM))
209 else if (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_HIGH))
213 template <
class Scalar>
216 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
217 paramList->validateParametersAndSetDefaults(*this->getValidParameters());
218 parameterList_ = paramList;
219 Teuchos::readVerboseObjectSublist(&*parameterList_,
this);
222 template <
class Scalar>
225 return(parameterList_);
228 template <
class Scalar>
231 RCP<ParameterList> temp_param_list = parameterList_;
232 parameterList_ = Teuchos::null;
233 return(temp_param_list);
236 template<
class Scalar>
239 static RCP<Teuchos::ParameterList> validPL;
240 if (is_null(validPL)) {
241 RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
242 Teuchos::setupVerboseObjectSublist(&*pl);
248 template<
class Scalar>
250 const typename DataStore<Scalar>::DataStoreVector_t &data_in
251 ,
const Array<Scalar> &t_values
252 ,
typename DataStore<Scalar>::DataStoreVector_t *data_out
255 assertBaseInterpolatePreconditions(data_in,t_values,data_out);
256 for (
int i=0; i<Teuchos::as<int>(data_in.size()) ; ++i) {
257 TEUCHOS_TEST_FOR_EXCEPTION(
258 is_null(data_in[i].x), std::logic_error,
259 "Error, data_in[" << i <<
"].x == Teuchos::null.\n"
261 TEUCHOS_TEST_FOR_EXCEPTION(
262 is_null(data_in[i].xdot), std::logic_error,
263 "Error, data_in[" << i <<
"].xdot == Teuchos::null.\n"
274 #define RYTHMOS_HERMITE_INTERPOLATOR_INSTANT(SCALAR) \
276 template class HermiteInterpolator< SCALAR >; \
278 template RCP<HermiteInterpolator< SCALAR > > hermiteInterpolator();
283 #endif // Rythmos_HERMITE_INTERPOLATOR_DEF_H
std::string description() const
Inherited from Teuchos::Describable.
RCP< ParameterList > unsetParameterList()
int order() const
Order of interpolation:
void setNodes(const RCP< const typename DataStore< Scalar >::DataStoreVector_t > &nodes)
Store pointer to interpolation nodes.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void interpolate(const Array< Scalar > &t_values, typename DataStore< Scalar >::DataStoreVector_t *data_out) const
Interpolation:
RCP< ParameterList > getNonconstParameterList()
HermiteInterpolator()
Constructor.
RCP< const Teuchos::ParameterList > getValidParameters() const
void setParameterList(RCP< ParameterList > const ¶mList)
Redefined from ParameterListAcceptor.