OdeSolver.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/GVector.h>
  9. #include <functional>
  10. // The differential equation is dx/dt = F(t,x). The TVector template
  11. // parameter allows you to create solvers with Vector<N,Real> when the
  12. // dimension N is known at compile time or GVector<Real> when the dimension
  13. // N is known at run time. Both classes have 'int GetSize() const' that
  14. // allow OdeSolver-derived classes to query for the dimension.
  15. namespace WwiseGTE
  16. {
  17. template <typename Real, typename TVector>
  18. class OdeSolver
  19. {
  20. public:
  21. // Abstract base class.
  22. virtual ~OdeSolver() = default;
  23. protected:
  24. OdeSolver(Real tDelta, std::function<TVector(Real, TVector const&)> const& F)
  25. :
  26. mTDelta(tDelta),
  27. mFunction(F)
  28. {
  29. }
  30. public:
  31. // Member access.
  32. inline void SetTDelta(Real tDelta)
  33. {
  34. mTDelta = tDelta;
  35. }
  36. inline Real GetTDelta() const
  37. {
  38. return mTDelta;
  39. }
  40. // Estimate x(t + tDelta) from x(t) using dx/dt = F(t,x). The
  41. // derived classes implement this so that it is possible for xIn and
  42. // xOut to be the same object.
  43. virtual void Update(Real tIn, TVector const& xIn, Real& tOut, TVector& xOut) = 0;
  44. protected:
  45. Real mTDelta;
  46. std::function<TVector(Real, TVector const&)> mFunction;
  47. };
  48. }