Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_Interpolator.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_Interpolator_hpp
10 #define Tempus_Interpolator_hpp
11 
12 // Teuchos
13 #include "Teuchos_VerboseObject.hpp"
14 #include "Teuchos_Describable.hpp"
15 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
16 #include "Teuchos_RCP.hpp"
17 #include "Teuchos_ScalarTraits.hpp"
18 
19 // Tempus
20 #include "Tempus_SolutionState.hpp"
21 
22 #include <vector>
23 
24 namespace Tempus {
25 
26 /** \brief Base strategy class for interpolation functionality.
27  */
28 template<class Scalar>
30  : virtual public Teuchos::Describable,
31  virtual public Teuchos::ParameterListAcceptor,
32  virtual public Teuchos::VerboseObject<Interpolator<Scalar> >
33 {
34 public:
35 
36  /** \brief Store pointer to interpolation nodes
37  *
38  * This function represent a persisting relationship between the
39  * interpolation nodes and the interpolator. For simple interpolators like
40  * linear and Hermite, this is not needed, but for interpolators like cubic
41  * splines where there is some computational work in assembling the
42  * interpolant, this is important.
43  *
44  * <b>Preconditions:</b><ul>
45  * <li><tt>nodes</tt> must have unique time values and be sorted in ascending time order
46  * </ul>
47  *
48  * <b>Postconditions:</b><ul>
49  * <li>If this function is called twice and <tt>nodes</tt> is a different
50  * pointer than was previously called, then it is possible that the
51  * interpolant will be recomputed when <tt>interpolate</tt> is next called.
52  * </ul>
53  */
54  virtual void setNodes(
55  const Teuchos::RCP<const std::vector<Teuchos::RCP<SolutionState<Scalar> > > > & nodes) = 0;
56 
57  /** \brief Perform an interpolation.
58  */
59  virtual void interpolate(const Scalar& t,
60  SolutionState<Scalar>* state_out) const = 0;
61 
62  /** \brief Return the order of the interpolation.
63  */
64  virtual int order() const = 0;
65 
66 };
67 
68 /// Non-member constructor
69 template<class Scalar>
70 void interpolate(const Interpolator<Scalar>& interpolator,
71  const Scalar& t,
72  SolutionState<Scalar>* state_out)
73 {
74  interpolator.interpolate(t, state_out);
75 }
76 
77 /// Non-member constructor
78 template<class Scalar>
79 void interpolate(Interpolator<Scalar>& interpolator,
80  const Teuchos::RCP<const std::vector<Teuchos::RCP<SolutionState<Scalar> > > >& nodes,
81  const Scalar& t,
82  SolutionState<Scalar>* state_out)
83 {
84  interpolator.setNodes(nodes);
85  interpolator.interpolate(t, state_out);
86 }
87 
88 /// Helper function for comparing times
89 template <typename Scalar>
90 bool floating_compare_equals(const Scalar& a, const Scalar& b,
91  const Scalar& scale)
92 {
93  typedef Teuchos::ScalarTraits<Scalar> ST;
94  typedef typename ST::magnitudeType mag_type;
95 
96  const mag_type tol = ST::magnitude(scale)*ST::eps()*mag_type(1000.0);
97  const mag_type diff = ST::magnitude(a-b);
98 
99  return diff <= tol || diff <= ST::sfmin();
100 }
101 
102 } // namespace Tempus
103 
104 #endif //Tempus_Interpolator_hpp
virtual void setNodes(const Teuchos::RCP< const std::vector< Teuchos::RCP< SolutionState< Scalar > > > > &nodes)=0
Store pointer to interpolation nodes.
Base strategy class for interpolation functionality.
void interpolate(const Interpolator< Scalar > &interpolator, const Scalar &t, SolutionState< Scalar > *state_out)
Non-member constructor.
virtual void interpolate(const Scalar &t, SolutionState< Scalar > *state_out) const =0
Perform an interpolation.
bool floating_compare_equals(const Scalar &a, const Scalar &b, const Scalar &scale)
Helper function for comparing times.
virtual int order() const =0
Return the order of the interpolation.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...