Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_InterpolatorBaseHelpers.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef Rythmos_INTERPOLATOR_BASE_HELPERS_H
30 #define Rythmos_INTERPOLATOR_BASE_HELPERS_H
31 
32 #include "Rythmos_InterpolatorBase.hpp"
33 
34 namespace Rythmos {
35 
36 
38 template<class Scalar>
39 void interpolate(
40  InterpolatorBase<Scalar>& interp,
41  const RCP<const typename DataStore<Scalar>::DataStoreVector_t> & nodes,
42  const Array<Scalar> &t_values,
43  typename DataStore<Scalar>::DataStoreVector_t *data_out
44  )
45 {
46  interp.setNodes(nodes);
47  interp.interpolate(t_values,data_out);
48 }
49 
50 
52 template<class Scalar>
54  const typename DataStore<Scalar>::DataStoreVector_t &data_in,
55  const Array<Scalar> &t_values,
56  typename DataStore<Scalar>::DataStoreVector_t *data_out
57  )
58 {
59  TEUCHOS_TEST_FOR_EXCEPTION(
60  data_in.size()==0, std::logic_error,
61  "Error, data_in.size() == 0!\n"
62  );
63  Array<Scalar> time_vec;
64  dataStoreVectorToVector<Scalar>(data_in, &time_vec, 0, 0, 0);
65  assertTimePointsAreSorted<Scalar>(time_vec);
66  assertTimePointsAreSorted<Scalar>(t_values);
67  if (data_in.size() == 1) {
68  TEUCHOS_TEST_FOR_EXCEPTION(
69  t_values.size()>1, std::logic_error,
70  "Error, data_in.size() == 1, but t_values.size() > 1!\n"
71  );
72  TEUCHOS_TEST_FOR_EXCEPTION(
73  compareTimeValues(t_values[0],data_in[0].time)!=0, std::logic_error,
74  "Error, data_in.size) == 1, but t_values[0] = " <<
75  t_values[0] << " != " << data_in[0].time << " = data_in[0].time!\n"
76  );
77  }
78  TimeRange<Scalar> range(data_in.front().time,data_in.back().time);
79  for (int i=0; i<Teuchos::as<int>(t_values.size()) ; ++i) {
80  TEUCHOS_TEST_FOR_EXCEPTION(
81  !range.isInRange(t_values[i]), std::out_of_range,
82  "Error, t_values[" << i << "] = " << t_values[i] <<
83  " is not in range of data_in = " << range << "!\n"
84  );
85  }
86  TEUCHOS_TEST_FOR_EXCEPTION(
87  data_out == 0, std::logic_error,
88  "Error, data_out = NULL!\n"
89  );
90 }
91 
92 
93 template<class Scalar>
94 void assertNodesUnChanged(
95  const typename DataStore<Scalar>::DataStoreVector_t & nodes,
96  const typename DataStore<Scalar>::DataStoreVector_t & nodes_copy
97  )
98 {
99  typedef Teuchos::ScalarTraits<Scalar> ST;
100  int N = nodes.size();
101  int Ncopy = nodes_copy.size();
102  TEUCHOS_TEST_FOR_EXCEPTION( N != Ncopy, std::logic_error,
103  "Error! The number of nodes passed in through setNodes has changed!"
104  );
105  if (N > 0) {
106  RCP<Thyra::VectorBase<Scalar> > xdiff = nodes[0].x->clone_v();
107  RCP<Thyra::VectorBase<Scalar> > xdotdiff = xdiff->clone_v();
108  V_S(outArg(*xdiff),ST::one());
109  V_S(outArg(*xdotdiff),ST::one());
110  for (int i=0 ; i<N ; ++i) {
111  V_StVpStV(outArg(*xdiff),ST::one(),*nodes[i].x,-ST::one(),*nodes_copy[i].x);
112  if ((!Teuchos::is_null(nodes[i].xdot)) && (!Teuchos::is_null(nodes_copy[i].xdot))) {
113  V_StVpStV(outArg(*xdotdiff),ST::one(),*nodes[i].xdot,-ST::one(),*nodes_copy[i].xdot);
114  } else if (Teuchos::is_null(nodes[i].xdot) && Teuchos::is_null(nodes_copy[i].xdot)) {
115  V_S(outArg(*xdotdiff),ST::zero());
116  }
117  Scalar xdiffnorm = norm_inf(*xdiff);
118  Scalar xdotdiffnorm = norm_inf(*xdotdiff);
119  TEUCHOS_TEST_FOR_EXCEPTION(
120  ( ( nodes[i].time != nodes_copy[i].time ) ||
121  ( xdiffnorm != ST::zero() ) ||
122  ( xdotdiffnorm != ST::zero() ) ||
123  ( nodes[i].accuracy != nodes_copy[i].accuracy ) ),
124  std::logic_error,
125  "Error! The data in the nodes passed through setNodes has changed!"
126  );
127  }
128  }
129 }
130 
131 
132 } // namespace Rythmos
133 
134 
135 #endif // Rythmos_INTERPOLATOR_BASE_HELPERS_H
void assertBaseInterpolatePreconditions(const typename DataStore< Scalar >::DataStoreVector_t &data_in, const Array< Scalar > &t_values, typename DataStore< Scalar >::DataStoreVector_t *data_out)