GteOdeImplicitEuler.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteGMatrix.h>
12 
13 // The TVector template parameter allows you to create solvers with
14 // Vector<N,Real> when the dimension N is known at compile time or
15 // GVector<Real> when the dimension N is known at run time. Both classes
16 // have 'int GetSize() const' that allow OdeSolver-derived classes to query
17 // for the dimension. The TMatrix parameter must be either Matrix<N,N,Real>
18 // or GMatrix<Real> accordingly.
19 //
20 // The function F(t,x) has input t, a scalar, and input x, an N-vector.
21 // The first derivative matrix with respect to x is DF(t,x), an
22 // N-by-N matrix. Entry DF(r,c) is the derivative of F[r] with
23 // respect to x[c].
24 
25 namespace gte
26 {
27 
28 template <typename Real, typename TVector, typename TMatrix>
29 class OdeImplicitEuler : public OdeSolver<Real,TVector>
30 {
31 public:
32  // Construction and destruction.
33  virtual ~OdeImplicitEuler();
34  OdeImplicitEuler(Real tDelta,
35  std::function<TVector(Real, TVector const&)> const& F,
36  std::function<TMatrix(Real, TVector const&)> const& DF);
37 
38  // Estimate x(t + tDelta) from x(t) using dx/dt = F(t,x). You may allow
39  // xIn and xOut to be the same object.
40  virtual void Update(Real tIn, TVector const& xIn, Real& tOut,
41  TVector& xOut);
42 
43 private:
44  std::function<TMatrix(Real, TVector const&)> mDerivativeFunction;
45 };
46 
47 
48 template <typename Real, typename TVector, typename TMatrix>
50 {
51 }
52 
53 template <typename Real, typename TVector, typename TMatrix>
55  std::function<TVector(Real, TVector const&)> const& F,
56  std::function<TMatrix(Real, TVector const&)> const& DF)
57  :
58  OdeSolver<Real, TVector>(tDelta, F),
60 {
61 }
62 
63 template <typename Real, typename TVector, typename TMatrix>
65  TVector const& xIn, Real& tOut, TVector& xOut)
66 {
67  TVector fVector = this->mFunction(tIn, xIn);
68  TMatrix dfMatrix = mDerivativeFunction(tIn, xIn);
69  TMatrix dgMatrix = TMatrix::Identity() - this->mTDelta * dfMatrix;
70  TMatrix dgInverse = Inverse(dgMatrix);
71  fVector = dgInverse * fVector;
72  tOut = tIn + this->mTDelta;
73  xOut = xIn + this->mTDelta * fVector;
74 }
75 
76 
77 }
OdeImplicitEuler(Real tDelta, std::function< TVector(Real, TVector const &)> const &F, std::function< TMatrix(Real, TVector const &)> const &DF)
std::function< TVector(Real, TVector const &)> mFunction
Definition: GteOdeSolver.h:46
std::function< TMatrix(Real, TVector const &)> mDerivativeFunction
virtual void Update(Real tIn, TVector const &xIn, Real &tOut, TVector &xOut)
Quaternion< Real > Inverse(Quaternion< Real > const &d)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01